NPC Transfer Activity
A. Overview
The NPC Transfer Activity script is responsible for simulating transfer offers made by non-player character (NPC) clubs to player-owning clubs, as well as handling responses to incoming transfer offers. This process involves generating transfer offers based on club activity levels, evaluating incoming offers, and finalizing transfers if conditions are met.
B. Key Functions and Their Roles
round_offer_amount($amount)
Purpose: Rounds the offer amount based on predefined rules:
If the amount is greater than £1,000,000, it rounds up to the nearest £250,000.
If the amount is less than or equal to £1,000,000, it rounds to the nearest £10,000.
Usage: Ensures that transfer offers are standardized, making them more realistic and manageable within the game's economy.
shortenFee($amount)
Purpose: Formats monetary values into a shorter, more readable format:
≥ £1,000,000: Displays as "£Xm" or "£X.Ym" (e.g., £1m, £23.5m).
≥ £1,000 but < £1,000,000: Displays as "£Xk" (e.g., £750k).
< £1,000: Displays the exact number (e.g., £500).
Usage: Enhances user experience by presenting large numbers in a concise manner within messages and interfaces.
getTransferActivityLevel($current_week)
Purpose: Determines the current transfer activity level based on the game week.
Usage: Influences the probability and volume of transfer offers NPC clubs will make, adding variability and realism to transfer windows.
getCurrentGameDate($conn)
Purpose: Retrieves the current game date details, including week, era, and season.
Usage: Essential for time-dependent operations like transfer activities, contract expirations, and other temporal events.
calculateExpectedSalary($overall_rating, $age, $club_id, $conn)
Purpose: Calculates the expected salary for a player based on their overall rating, age, and the club's rating.
Usage: Determines whether an offer is sufficient to persuade a player to accept a transfer, influencing contract negotiations.
calculateSalary($overall_rating, $age)
Purpose: Computes the actual salary to be offered in a contract based on player attributes.
Usage: Sets the financial terms of the player's contract post-transfer.
insertPlayerForClubWithStats(...)
Purpose: Inserts a new player into a club with associated stats.
Usage: Used during player generation for new clubs and potentially within transfer activities if creating new players dynamically.
updateScoutingCapacity($conn, $club_id)
Purpose: Updates the scouting capacity of a club based on the number of scouts.
Usage: Ensures that clubs have appropriate scouting resources, which can influence transfer decisions and player acquisitions.
generatePlayersForNewClub(...)
Purpose: Generates a set of players for a newly created club, ensuring a balanced squad across various positions.
Usage: Essential during the New Club Generation process to populate the club with an initial roster.
C. Workflow of NPC Transfer Activity
Initialization
Establishes database connections and includes necessary function files.
Retrieves the current game date and transfer activity level.
Fetching Position IDs
Retrieves position codes and maps them to their respective IDs for efficient querying.
Processing NPC Clubs
Iterates through all NPC users and their associated clubs.
Evaluates the number of signings made in the current season to adjust bid probabilities.
Considers club cash reserves to further modulate the likelihood of making offers.
Generating Transfer Offers
Selects target players based on manager's playing style, preferred age, and team rating.
Calculates and rounds the offer amount using round_offer_amount.
Inserts transfer offers into the database and notifies the player's club via messages.
Responding to Incoming Offers
NPCs evaluate incoming transfer offers based on offer amount relative to player value and team rating.
Decides to accept or reject offers, updating the transfer offer status accordingly and notifying the offering club.
Finalizing Accepted Transfers
Validates transfer conditions such as squad size and position constraints.
Calculates expected salaries and contract lengths.
Completes the transfer by updating club finances, player affiliations, contracts, and logging the transaction in transfer history and news.
New Club Generation
A. Overview
The New Club Generation script facilitates the creation of a new club by a user. It handles the insertion of the club into the database, generation of players, coaches, scouts, and ensuring the club meets all initial requirements such as squad size and scouting capacity.
B. Key Functions and Their Roles
B. Key Functions and Their Roles getAllPossibleAttributes($conn) Purpose: Retrieves a list of all unique skill names from the position_skills table. Usage: Essential for generating player attributes tailored to their positions. generatePlayersWithNationality(...) Purpose: Generates a specified number of players for a club with a designated nationality or randomly assigned nationalities. Usage: Ensures diversity within the club's player roster, balancing between home and foreign players. generatePlayersForNewClub($club_id, $conn, $current_era, $current_season, $current_week) Purpose: Generates a complete set of players for a newly created club, distributing players across various positions with appropriate nationalities. Usage: Populates the new club with an initial roster, adhering to squad size and positional balance. insertPlayerForClubWithStats(...) Purpose: Inserts a player into the club with associated statistics. Usage: Central to player creation during the club generation process. generateWeightedRandom($min_potential) Purpose: Generates a potential value for a player based on predefined weighted distributions. Usage: Controls the quality and growth prospects of players being generated, ensuring realistic potential distributions. insertPlayer(...) Purpose: Inserts a new player into the players table with detailed attributes and statistics. Usage: Core function for adding players to the club, integrating with other functions to assign attributes and contracts. insertPlayerContract(...) Purpose: Creates a contract for the newly inserted player, determining salary and contract length based on age and rating. Usage: Establishes the player's financial terms within the club, essential for budget management. getRandomName($nation_id, $conn) Purpose: Fetches a random first and last name from the firstnames and surnames tables based on nationality. Usage: Assigns realistic names to players, enhancing immersion and diversity. generatePotential() Purpose: Generates a potential value for a player based on probability distributions. Usage: Determines the future growth and value of players, impacting their development and marketability. generatePlayerAttributes(...) Purpose: Generates player attributes tailored to their position and potential. Usage: Assigns detailed statistics to players, influencing their performance and suitability for positions. generateDefaultAttributeForSeniors($attribute) Purpose: Provides default values for attributes not specifically assigned, ensuring completeness. Usage: Fills in any missing attributes during player generation to maintain data integrity. generateAttribute(...) Purpose: Determines individual attribute values based on player potential, age, position, and importance. Usage: Assigns realistic attribute scores to players, ensuring balanced and position-appropriate stats. createCoach(...) Purpose: Generates coaches for the club, specifying their focus areas and coaching capabilities. Usage: Populates the club with necessary coaching staff, influencing player development and team performance. createScout(...) Purpose: Generates scouts for the club, potentially affecting the club's scouting capacity and transfer activity. Usage: Enhances the club's ability to discover and recruit talent. updateScoutingCapacity($conn, $club_id) Purpose: Updates the scouting capacity based on the number of scouts. Usage: Ensures that the club's scouting resources are accurately reflected in the game's mechanics. createStadiumForClub($club_id, $club_name, $conn) Purpose: Creates a stadium for the newly formed club if one does not already exist. Usage: Provides the club with a home venue, impacting fan engagement and revenue. generateCoachesForClub.php and generate_scouts_for_club.php Purpose: Scripts to generate coaches and scouts for the club. Usage: Supplement the main club generation process by adding essential staff members. C. Workflow of New Club Generation Initialization: Starts a session and includes necessary function files. Retrieves the current game date (era, season, week) for temporal consistency. Form Handling: Processes form submissions for creating a new club, capturing details like club name and kit colors. Validates the club name against offensive words and uniqueness constraints. Database Insertion: Inserts the new club into the club table with specified colors and chairman (user ID). Updates the user's signup_status to indicate completion of the club creation process. Generating Club Roster: Calls generatePlayersForNewClub to populate the club with an initial roster of players across all positions. Ensures a balanced squad with appropriate nationalities and potential distributions. Generating Staff: Generates coaches (senior and youth) using the createCoach function, specifying their focus areas and coaching capabilities. Generates scouts using the createScout function, enhancing the club's scouting capacity. Scouting Capacity Update: Updates the club's scouting capacity based on the number of scouts assigned. Stadium Creation: Checks if the club already has a stadium; if not, creates one using createStadiumForClub. Logging and Notifications: Logs the creation of the new club in the log table. Inserts a news story about the new club's formation into the news table, enhancing user engagement and visibility within the game. Redirection: Redirects the user to the New Manager setup page after successful club creation. 3. Interactions Between NPC Transfer Activity and New Club Generation While both NPC Transfer Activity and New Club Generation operate independently, they interact through several shared components and functions: Player Generation Functions: Shared Use: Both processes utilize functions like insertPlayerForClubWithStats, insertPlayer, and generatePlayerAttributes to manage player creation and attributes. Impact: Ensures consistency in how players are generated and integrated into clubs, whether they are part of a new club or involved in transfer activities. Scouting Capacity: Shared Use: Both processes involve updating scouting capacity (updateScoutingCapacity) based on the number of scouts. Impact: Affects the likelihood and efficiency of both generating new players and NPC transfer activities, as scouting plays a crucial role in player acquisition. Contract Handling: Shared Use: Functions like insertPlayerContract are utilized in both processes to manage player contracts. Impact: Ensures that all players, regardless of how they join a club, have appropriate contracts aligned with their attributes and club finances. Database Connections and Sessions: Shared Use: Both scripts establish database connections and manage sessions to track user and club information. Impact: Facilitates seamless data flow and state management across different components of the application.
Players Before Recovery Player ID Fitness Condition (Before) Stamina 1 70 80 2 60 99 3 50 70 Recovery Calculation We assume that the function calculate_recovery($fitness_condition, $stamina) returns a base recovery value using a simple formula: Base Recovery = Stamina 10 − Fitness Condition 20 Base Recovery= 10 Stamina − 20 Fitness Condition This ensures: Players with higher stamina recover faster. Players with lower fitness recover slightly more. Recovery Results Slot 1: Multiplier = 6 Player ID Fitness Condition (Before) Base Recovery Recovery Applied (6x) Fitness Condition (After) 1 70 3.0 18.0 88 2 60 4.95 29.7 89.7 (Rounded to 89) 3 50 3.5 21.0 71 Slot 2 or 3: Multiplier = 3 Player ID Fitness Condition (Before) Base Recovery Recovery Applied (3x) Fitness Condition (After) 1 70 3.0 9.0 79 2 60 4.95 14.85 74.85 (Rounded to 75) 3 50 3.5 10.5 60.5 (Rounded to 60) Summary Slot 1 Recovery (Multiplier = 6): Faster recovery for all players. Player 1 improves from 70 to 88. Player 2 improves from 60 to 89. Player 3 improves from 50 to 71. Slot 2 or 3 Recovery (Multiplier = 3): Slower recovery. Player 1 improves from 70 to 79. Player 2 improves from 60 to 75. Player 3 improves from 50 to 60. Key Notes: Recovery depends on stamina and the fitness condition. Slot 1 applies stronger recovery, simulating a more efficient recovery period. Final fitness conditions are capped at 99 in the script. Let me know if you'd like a real-world simulation in PHP! 😊