|
Player12
An open source football management simulator
|
#include <match_engine.h>
Classes | |
| struct | ControlledShot |
| struct | GoalkeeperControl |
| struct | PassOption |
| struct | PendingAdvantage |
| struct | SaveAttempt |
| struct | Shootout |
| struct | ShoutState |
| struct | SlotTactic |
Public Member Functions | |
| MatchEngine (const Lineup &home_lineup, const Lineup &away_lineup, const Strategy &home_strat, const Strategy &away_strat, const StatsConfig &config) | |
| MatchEngine (const Lineup &home_lineup, const Lineup &away_lineup, const Strategy &home_strat, const Strategy &away_strat, const StatsConfig &config, uint32_t seed) | |
| void | update (float deltaTime) |
| float | advance (float seconds) |
| void | simulateToEnd () |
| void | simulateToEnd (MatchFidelity fidelity) |
| double | getSimulatedSeconds () const |
| void | setPlaybackMode (MatchPlaybackMode mode) |
| MatchPlaybackMode | getPlaybackMode () const |
| void | setPlaybackSpeed (float simulatedSecondsPerWallSecond) |
| float | getPlaybackSpeed () const |
| void | setHighlightPlaybackSpeed (float simulatedSecondsPerWallSecond) |
| float | getHighlightPlaybackSpeed () const |
| bool | advancePlayback (float wallSeconds) |
| bool | isInHighlight () const |
| const std::optional< MatchHighlight > & | getScheduledHighlight () const |
| std::optional< MatchHighlight > | predictNextHighlight (float horizonSeconds=MatchTuning::Playback::PREDICTION_HORIZON_SECONDS) const |
| const std::vector< MatchHighlight > & | getHighlights () const |
| void | setTacticalFamiliarity (bool homeTeam, float familiarity) |
| float | getTacticalFamiliarity (bool homeTeam) const |
| void | setStrategy (bool homeTeam, const Strategy &strategy) |
| void | applyShout (bool homeTeam, MatchShout shout) |
| float | getShoutStrength (bool homeTeam) const |
| std::optional< MatchShout > | getActiveShout (bool homeTeam) const |
| std::vector< Vector2F > | getFormation (bool homeTeam) const |
| bool | setFormation (bool homeTeam, std::span< const Vector2F > shape) |
| std::optional< std::size_t > | getFormationSlot (PlayerID playerId) const |
| bool | movePlayerToSlot (PlayerID playerId, std::size_t slot) |
| StrategySliders | getEffectiveSliders (bool homeTeam) const |
| void | setTeamTalkModifier (bool homeTeam, int half, float modifier) |
| float | getTeamTalkModifier (bool homeTeam, int half) const |
| float | getTeamTalkEffect (bool homeTeam) const |
| TacticalRole | getSlotRole (bool homeTeam, std::size_t slot) const |
| bool | setControlledPlayer (PlayerID playerId) |
| void | setPlayHalfMinutes (int minutes) |
| int | getPlayHalfMinutes () const |
| PlayerID | getControlledPlayer () const |
| void | submitInput (const MatchPlayerInput &input) |
| const std::vector< MatchInputRecord > & | getInputLog () const |
| void | loadInputReplay (std::vector< MatchInputRecord > log) |
| PlayerID | suggestActivePlayer (bool homeTeam, PlayerID current) const |
| PlayerID | nextSwitchCandidate (bool homeTeam, PlayerID current, PlayerID skip=0) const |
| bool | stepsWithin (float deltaSeconds) const |
| bool | wasControlled (bool homeTeam) const |
| int | getControlledActions (bool homeTeam) const |
| const std::vector< MatchCommandRecord > & | getCommandLog () const |
| void | loadCommandReplay (std::vector< MatchCommandRecord > log) |
| std::uint64_t | getSimulatedSteps () const |
| const std::vector< MatchPlayer > & | getPlayers () const |
| const MatchBall & | getBall () const |
| const std::vector< MatchEvent > & | getEvents () const |
| void | setTeamNames (std::string homeTeam, std::string awayTeam) |
| MatchState | getState () const |
| const MatchStats & | getStats () const |
| TeamPhase | getHomePhase () const |
| TeamPhase | getAwayPhase () const |
| float | getTransitionSecondsRemaining () const |
| const PassDecision & | getLastPassDecision () const |
| bool | substitutePlayer (uint32_t outPlayerId, const Player *inPlayer, std::optional< std::size_t > slot=std::nullopt) |
| bool | canSubstitute (bool homeTeam) const |
| int | getSubstitutionsUsed (bool homeTeam) const |
| int | getSubstitutionWindowsUsed (bool homeTeam) const |
| void | setAutoSubstitutions (bool home, bool away) |
| void | setMedicalFlags (PlayerID playerId, std::uint8_t flags) |
| const std::vector< MatchSubstitution > & | getSubstitutions () const |
| const std::vector< PlayerMatchStats > & | getPlayerStats () const |
| const PlayerMatchStats * | findPlayerStats (PlayerID playerId) const |
| const MatchTracker & | getTracker () const |
| void | setTracking (bool on) |
| std::optional< float > | getPlayerCondition (PlayerID playerId) const |
| bool | setPlayerCondition (PlayerID playerId, float condition) |
| int | getPeriod () const |
| int | getAddedMinutes (int half) const |
| void | setKnockout (const MatchRules::Knockout &rules) |
| const MatchRules::Knockout & | getKnockout () const |
| void | setMatchContext (const MatchContext &context) |
| const MatchContext & | getMatchContext () const |
| bool | wentToExtraTime () const |
| bool | hasShootout () const |
| int | getShootoutScore (bool homeTeam) const |
| int | getShootoutKicks (bool homeTeam) const |
| std::optional< bool > | getTieWinnerHome () const |
| bool | isInAddedTime () const |
| bool | isAbandoned () const |
| float | getRefereeStrictness () const |
| int | getHomeScore () const |
| int | getAwayScore () const |
| float | getMatchTimeMinutes () const |
| float | getElapsedMatchMinutes () const |
| int | getLastUpdateStepCount () const |
| std::uint64_t | getDroppedSimulationSteps () const |
| bool | getGoalScoredByHome () const |
| float | getGoalCelebrationRemaining () const |
| float | getGoalCelebrationDuration () const |
| float | getInterpolationAlpha () const |
| const std::vector< Vector2F > & | getPreviousPlayerPositions () const |
| const std::vector< float > & | getPreviousPlayerFacingAngles () const |
| Vector2F | getPreviousBallPosition () const |
| float | getPreviousBallZ () const |
| std::string | getDebugSnapshotJson () const |
| bool | writeDebugSnapshot (std::string_view path) const |
| GoalkeeperState | getHomeGoalkeeperState () const |
| GoalkeeperState | getAwayGoalkeeperState () const |
| bool | applyScenario (const MatchScenario &scenario, MatchState scenarioState=MatchState::PLAYING, float scenarioMatchTime=0.0f, int scenarioHomeScore=0, int scenarioAwayScore=0) |
| const ScenarioDecision & | getLastScenarioDecision () const |
Private Types | |
| enum class | TacticalArrival { MIDFIELDER , FAR_POST , FULLBACK } |
Private Member Functions | |
| float | matchClockRate () const |
| void | initializePlayers (const Lineup &lineup, bool isHomeTeam) |
| void | loadAttributes (MatchPlayer &matchPlayer, const Player *player) const |
| std::size_t | addPlayerStats (const MatchPlayer &matchPlayer, bool started) |
| PlayerMatchStats & | statsOf (const MatchPlayer &matchPlayer) |
| void | refreshRatings () |
| void | advanceClock (float dt) |
| void | accumulatePlayerLoad (float dt) |
| void | updateMatchClock () |
| void | announceAddedTime () |
| void | endPeriod () |
| void | beginBreak (float seconds, float recovery) |
| bool | tieLevel () const |
| void | finishMatch () |
| void | startShootout () |
| void | updateShootout (float dt) |
| void | beginShootoutKick () |
| void | finishShootoutKick (MatchEventDetail outcome) |
| int | maxSubstitutions () const |
| void | checkInjuries () |
| void | injurePlayer (MatchPlayer &player, bool fromContact) |
| void | removeFromPitch (MatchPlayer &player) |
| void | rebalanceShape (bool homeTeam, Vector2F vacatedBase, std::int8_t vacatedSlot) |
| void | ensureGoalkeeper (bool homeTeam) |
| void | beginStoppage () |
| void | extendRestart (float seconds) |
| void | runAiSubstitutions () |
| void | runAiSubstitutionsFor (bool homeTeam) |
| void | runMedicalSubstitutions (bool homeTeam) |
| bool | performSubstitution (MatchPlayer &outgoing, const Player *inPlayer, SubstitutionReason reason) |
| const Player * | chooseReplacement (bool homeTeam, PlayerRole role, bool wantGoalkeeper) const |
| void | commitFoul (MatchPlayer &offender, MatchPlayer &victim, bool ballWon, bool reckless) |
| void | applySanction (MatchPlayer &offender, MatchRules::FoulSanction sanction) |
| bool | deniesGoalChance (const MatchPlayer &victim, const MatchPlayer &offender) const |
| void | updatePendingAdvantage (float dt) |
| float | currentTopSpeed (const MatchPlayer &player) const |
| void | integrateMovements (std::span< const std::uint8_t > slots, float dt, bool walking) |
| void | updateRestartMovement (float dt) |
| bool | userRestartPassRequested () const |
| void | updateRestartSupport (MatchPlayer &player, const MatchPlayer *taker) const |
| void | separatePlayers () |
| Vector2F | goalkeeperTarget (MatchPlayer &keeper, const MatchPlayer *carrier) |
| void | diveGoalkeeper (MatchPlayer &keeper, float dt) |
| void | planGoalkeeperDive (bool defendingHome, bool penalty) |
| void | resolveShotAtGoalkeeper (MatchPlayer &goalkeeper) |
| bool | resolveAerialContest () |
| void | headBall (MatchPlayer &header) |
| bool | tryOwnGoalTouch (MatchPlayer &defender) |
| void | clearBehind (MatchPlayer &defender) |
| void | clearBall (MatchPlayer &defender) |
| void | parryShot (MatchPlayer &goalkeeper, bool overTheBar) |
| void | launchBall (const MatchPlayer &kicker, Vector2F origin, Vector2F target, float horizontalSpeed, float verticalSpeed, float curve) |
| void | takeSetPiece (MatchPlayer &taker, MatchState restartState) |
| void | takeCorner (MatchPlayer &taker) |
| void | takeDirectFreeKick (MatchPlayer &taker) |
| void | arrangeSetPiece (bool attackingHome, Vector2F ballPosition) |
| MatchPlayer * | bestSetPieceTaker (bool homeTeam, bool shooting) |
| MatchPlayer * | dutyTaker (bool homeTeam, SetPieceDuty duty) |
| void | placeTaker (MatchPlayer &taker, Vector2F spot) |
| MatchPlayer * | restartTaker () |
| void | setRestartTaker (MatchPlayer *taker) |
| std::size_t | slotOf (const MatchPlayer &player) const |
| float | familiarityOf (const MatchPlayer &player) const |
| float | talkOf (bool homeTeam) const |
| void | resolveTactics (bool homeTeam) |
| const RoleProfile & | roleProfileOf (const MatchPlayer &player) const |
| Vector2F | possessionAnchor (const MatchPlayer &player) const |
| float | defensiveRoleShift (const MatchPlayer &player) const |
| OppositionInstruction | instructionAgainst (const MatchPlayer &target) const |
| const MatchPlayer * | tightMarkTarget (const MatchPlayer &marker) const |
| Vector2F | tightMarkPoint (const MatchPlayer &marker, const MatchPlayer &target, Vector2F current) const |
| float | tightMarkPenalty (const MatchPlayer &receiver) const |
| float | passingRoleBias (const MatchPlayer &passer, const MatchPlayer &receiver, float progression, float completion) const |
| float | pressEagerness (const MatchPlayer &candidate, const MatchPlayer *carrier) const |
| float | engageBoost (const MatchPlayer &defender, const MatchPlayer &carrier) const |
| float | pressStandOffShare (const MatchPlayer &presser, const MatchPlayer &carrier) const |
| float | weakFootShade (const MatchPlayer &carrier) const |
| float | weakFootPressure (const MatchPlayer &carrier) const |
| std::optional< Vector2F > | doubleUpPoint (const MatchPlayer &helper, const MatchPlayer &carrier, const MatchPlayer *firstPresser) const |
| float | doubleUpPenalty (const MatchPlayer &carrier, const MatchPlayer &defender) const |
| float | talkSwing (bool homeTeam) const |
| StrategySliders | computeEffectiveSliders (bool homeTeam) const |
| void | computeUnderdogShares () |
| void | refreshEffectiveSliders () |
| float | teamEdge (bool homeTeam) const |
| float | drawRefereeStrictness () const |
| float | shoutShotBias (bool homeTeam) const |
| float | shoutWorkRate (bool homeTeam) const |
| void | runAiTouchline (bool homeTeam) |
| void | refreshTargetBlends () |
| void | assignMarks () |
| void | setStepTicks (std::uint32_t ticks) |
| std::uint32_t | backgroundStepTicks () const |
| float | stepSeconds () const |
| bool | periodElapsed (std::uint64_t ticks) const |
| float | hashNoise (std::uint32_t salt, std::uint32_t key) const |
| float | epochNoise (std::uint32_t salt, std::uint32_t key, std::uint32_t epochSteps) const |
| float | executionErrorScale (const MatchPlayer &player) const |
| void | recordPassCompletion (MatchPlayer &receiver) |
| void | captureInterpolationFrame () |
| void | simulateStep (float dt) |
| void | updateTeamPhases () |
| void | setTransitionPhases (bool attackingHome) |
| void | setControlledPhases (bool attackingHome, float ballX) |
| void | updateMovement (float dt) |
| void | refreshTacticalTargets (float dt) |
| float | estimatedArrivalTime (const MatchPlayer &candidate, Vector2F pressurePosition, const MatchPlayer *carrier) |
| std::array< MatchPlayer *, 2 > | closestOutfieldPair (bool homeTeam, const MatchPlayer *carrier, Vector2F pressurePosition) |
| float | runPriority (const MatchPlayer &candidate, const MatchPlayer *carrier) |
| std::array< MatchPlayer *, MatchTuning::Shape::MAX_COMMITTED_RUNNERS > | selectAttackingRunners (bool homeTeam, const MatchPlayer *carrier, const MatchPlayer *transitionSource) |
| float | runChannel (const MatchPlayer &runner) const |
| MatchPlayer * | selectFinalThirdPlayer (bool homeTeam, TacticalArrival arrival, const MatchPlayer *carrier, const std::array< MatchPlayer *, MatchTuning::Shape::MAX_COMMITTED_RUNNERS > &homeRunners, const std::array< MatchPlayer *, MatchTuning::Shape::MAX_COMMITTED_RUNNERS > &awayRunners) |
| std::array< MatchPlayer *, MatchTuning::Shape::MAX_ACTIVE_SUPPORTERS > | selectActiveSupporters (bool homeTeam, const MatchPlayer *carrier, const std::array< MatchPlayer *, MatchTuning::Shape::MAX_COMMITTED_RUNNERS > &runners, const MatchPlayer *midfieldArrival, const MatchPlayer *farPostRunner, const MatchPlayer *overlappingFullback) |
| const MatchPlayer * | findCoverOutlet (bool defendingHome, const MatchPlayer *carrier) const |
| void | updateBall (float dt) |
| void | integrateBall (float dt) |
| void | updateBallInNet (float dt) |
| void | resolvePossessionAndActions (float dt) |
| bool | updateDribble (const MatchPlayer &carrier, float dt) |
| float | dribbleExposureShare () const |
| bool | attemptTakeOn (MatchPlayer &carrier, MatchPlayer &defender) |
| void | resolveLooseBall () |
| void | attemptTackle (MatchPlayer &carrier, MatchPlayer &defender, bool sliding) |
| void | decideAction (MatchPlayer &carrier) |
| void | applyDueInputs () |
| bool | executeCommand (const MatchCommandRecord &command) |
| bool | recordCommand (const MatchCommandRecord &command) |
| void | applyDueCommands () |
| void | startShout (bool homeTeam, MatchShout shout) |
| void | placeFormation (bool homeTeam) |
| float | effectiveFamiliarity (std::size_t team) const |
| bool | isControlled (const MatchPlayer &player) const |
| bool | cutsInside (const MatchPlayer &player) const |
| void | integrateControlled (MatchPlayer &player, float dt) |
| bool | performControlledAction (MatchPlayer &carrier) |
| Vector2F | controlledAim (const MatchPlayer &carrier) const |
| MatchPlayer * | controlledPassReceiver (MatchPlayer &carrier, Vector2F aim, bool throughBall) |
| void | playControlledPass (MatchPlayer &carrier, MatchInputAction action) |
| void | shapeControlledShot (const MatchPlayer &shooter, float halfGoal, float inset, float &aimY, float &aimZ, float &spread) const |
| std::optional< Vector2F > | controlledAssistTarget (const MatchPlayer &player) const |
| float | switchSeconds (const MatchPlayer &candidate) const |
| void | stepKinematics (MatchPlayer &player, Vector2F desired, float desiredSpeed, float topSpeed, float fatigue, float dt) const |
| void | passBall (MatchPlayer &passer, const PassOption &option, bool forceLofted=false) |
| void | takeShot (MatchPlayer &shooter, float forcedXG=-1.0f, bool header=false, bool freeKick=false) |
| float | strikeShot (const MatchPlayer &shooter, float forcedXG, bool header, bool penalty, bool freeKick=false) |
| SaveAttempt | attemptSave (const MatchPlayer &keeper) |
| void | setPossession (MatchPlayer &player) |
| void | trackTouch (const MatchPlayer &player) |
| void | trackPassRelease (const MatchPlayer &passer) |
| void | trackPassCompletion (const MatchPlayer &passer, const MatchPlayer &receiver) |
| void | trackShot (const MatchPlayer &shooter, float xg, bool setPiece, bool header, bool penalty) |
| void | trackPressures () |
| void | clearFlightState () |
| std::optional< PassOption > | choosePassTarget (MatchPlayer &passer) |
| PassOption | evaluatePassOption (const MatchPlayer &passer, MatchPlayer &receiver) const |
| MatchPlayer * | findClosestPlayer (Vector2F position, bool homeTeam, bool includeGoalkeeper=true) |
| MatchPlayer * | findGoalkeeper (bool homeTeam) |
| MatchPlayer * | findMatchPlayer (const Player *player) |
| float | nearestOpponentDistance (const MatchPlayer &player) const |
| float | openSpaceAhead (const MatchPlayer &carrier) const |
| float | passingLaneRisk (const MatchPlayer &passer, const MatchPlayer &receiver) const |
| float | estimateShotXG (const MatchPlayer &shooter) const |
| bool | isOffside (const MatchPlayer &receiver, bool attackingHome, float defenderLine, float lineTolerance=0.0f) const |
| float | offsideLine (bool attackingHome) const |
| void | checkOutOfBounds () |
| void | scoreGoal (bool homeTeam) |
| void | makeSave (MatchPlayer &goalkeeper) |
| void | completeRestart () |
| void | setupKickOff (bool homeKickingOff) |
| void | setupThrowIn (bool homeTeam) |
| void | setupGoalKick (bool homeTeam) |
| void | setupCorner (bool homeTeam, bool topCorner) |
| void | setupFreeKick (bool homeTeam, Vector2F foulPos) |
| void | setupPenalty (bool homeTeam) |
| void | resetPositions () |
| Vector2F | kickOffPosition (const MatchPlayer &player) const |
| void | recordHighlight (MatchEventType type) |
| float | attribute (const Player *player, std::string_view name) const |
| float | rawAttribute (const Player *player, std::string_view name) const |
| void | computeLevel (const Lineup &home, const Lineup &away) |
| float | randomFloat (float minimum, float maximum) |
| float | incidentRoll () |
| bool | isHomePlayer (const Player *player) const |
| MatchEvent & | logEvent (MatchEventType type) |
| MatchEvent & | logEvent (MatchEventType type, const MatchPlayer &actor) |
| void | describePendingEvents () |
| std::string | squadPlayerName (PlayerID playerId) const |
| void | simulateStepBody (float dt) |
Static Private Member Functions | |
| static float | groundLaunchSpeed (float distanceMetres, float arrivalSpeed) |
| static float | loftVerticalSpeed (float distanceMetres, float horizontalSpeed, float startHeight, float arrivalHeight) |
Stateful, deterministic-when-seeded live match simulation in real match time: in watch mode one simulated second is one second of the match (a full match with stoppages and added time is roughly 5,900 simulated seconds). Play mode can accelerate the match clock while body/ball physics retain the same timestep; see setPlayHalfMinutes().
update() uses a fixed internal timestep, so the same seed produces the same match at different render frame rates. Home attacks toward x=1 and away attacks toward x=0. The engine is copyable, which highlight prediction uses to look ahead deterministically.
Strategies and simulation state are owned by value. Player pointers and the StatsConfig reference are borrowed: keep them alive and unchanged for the engine's lifetime, including any prediction copies and worker batches. The engine records match consequences; the career applies them afterwards. See docs/development/match-engine.md for the step order and extension map, and docs/development/player-behavior.md for movement and action selection.
|
strongprivate |
| MatchEngine::MatchEngine | ( | const Lineup & | home_lineup, |
| const Lineup & | away_lineup, | ||
| const Strategy & | home_strat, | ||
| const Strategy & | away_strat, | ||
| const StatsConfig & | config | ||
| ) |
| MatchEngine::MatchEngine | ( | const Lineup & | home_lineup, |
| const Lineup & | away_lineup, | ||
| const Strategy & | home_strat, | ||
| const Strategy & | away_strat, | ||
| const StatsConfig & | config, | ||
| uint32_t | seed | ||
| ) |
|
private |
|
private |
| float MatchEngine::advance | ( | float | seconds | ) |
Headless: advances exactly the whole fixed steps covering seconds of simulated time (never drops steps), stopping early at full time. Returns the simulated seconds advanced.
|
private |
Clock, minutes played, distance, load statistics and energy.
| bool MatchEngine::advancePlayback | ( | float | wallSeconds | ) |
Presentation helper for the live view: advances the match by wallSeconds of wall-clock time according to the playback mode. In HIGHLIGHTS mode it skips (simulates headless, never dropping steps) to the start of the next predicted highlight window and then plays the window at the highlight speed. Returns true when this call skipped ahead, so the view can cut instead of interpolating.
|
private |
|
private |
|
private |
Applies input records due at the current step.
|
private |
| bool MatchEngine::applyScenario | ( | const MatchScenario & | scenario, |
| MatchState | scenarioState = MatchState::PLAYING, |
||
| float | scenarioMatchTime = 0.0f, |
||
| int | scenarioHomeScore = 0, |
||
| int | scenarioAwayScore = 0 |
||
| ) |
Loads a fully-specified deterministic scenario and evaluates the carrier's decision exactly as the live engine would (no physics step is advanced). The renderer never calls this; it is only an explicit headless evaluation hook for the scenario suite. The optional parameters let scenario tests reproduce late-game and score-state behaviour deterministically. A controlled carrier (setControlledPlayer, already applied by a step) makes no AI decision and waits for his input.
| void MatchEngine::applyShout | ( | bool | homeTeam, |
| MatchShout | shout | ||
| ) |
A touchline shout: a temporary nudge to the side's sliders or shot appetite that fades out over MatchTuning::Touchline::SHOUT_DURATION_SECONDS. A new shout replaces the previous one; shouts in quick succession have less effect (see MatchTuning::Touchline::SHOUT_REPEAT_FADE_SECONDS).
|
private |
|
private |
|
private |
Whether the keeper stops the shot crossing his plane in the last ball sub-step (reach and save roll only, no consequences).
|
private |
|
private |
Tries to beat a jockeying defender; true if the carrier kept the ball.
|
private |
|
private |
Ticks of the next background-fidelity step (see MatchFidelity).
|
private |
Stops the clock for a break (half-time, before and in extra time).
|
private |
|
private |
|
private |
| bool MatchEngine::canSubstitute | ( | bool | homeTeam | ) | const |
Whether the side can still make a substitution right now.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Match level from both elevens (see MatchTuning::Player).
|
private |
How clearly each side is the weaker one in [0, 1] (see Touchline).
|
private |
Stick direction of the controlled pass or shot (metres, unit length).
|
private |
Movement target of the controlled player with the stick idle (meeting a pass to him, or the goal-side spot while jockeying); nullopt to stand.
|
private |
Team-mate a controlled pass along aim goes to (nullptr: none).
|
inlineprivate |
Current top speed (m/s) after fatigue, sprint reserve and injury.
|
private |
Whether a wide forward in the final third is cutting inside toward the box rather than going down the line to cross.
|
private |
|
inlineprivate |
Signed x shift of the role in the defensive block (normalised).
|
private |
|
private |
Writes the commentary line of the events logged since the last call.
|
private |
|
private |
Take-on success lost to a second defender doubling up.
|
private |
Second presser's spot when doubling up on the carrier, if ordered.
|
private |
Per-match referee strictness from the draw and the context.
|
private |
Share of the current touch the ball is still away from the foot.
|
private |
Taker of a dead-ball duty right now: the side's designated player while he is on the pitch and fit (so substitutions are followed), otherwise bestSetPieceTaker(). Long throws have no automatic specialist (nullptr).
|
private |
Tactical familiarity in force: the drilled level less a reshape cost.
|
private |
|
private |
Multiplier of a defender's rate of engaging the carrier.
|
private |
|
private |
Like hashNoise, but constant over windows of epochSteps steps.
|
private |
|
private |
|
private |
|
private |
Performs an external tactical change (live or replayed); false when it is not allowed, in which case nothing changed.
|
private |
|
private |
Extends the current restart delay (card, treatment, substitution).
|
private |
|
private |
|
private |
|
private |
|
private |
| const PlayerMatchStats * MatchEngine::findPlayerStats | ( | PlayerID | playerId | ) | const |
|
private |
|
private |
| std::optional< MatchShout > MatchEngine::getActiveShout | ( | bool | homeTeam | ) | const |
The shout in force, if any.
|
inline |
Announced added minutes of a period 1-4 (0 until announced).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Every tactical change made from outside (strategy, shout, formation, slot move, substitution, team talk), step-stamped. Replaying it with loadCommandReplay() on a new engine with the same lineups, tactics and seed reproduces the match. AI touchline decisions are not logged: they replay by themselves.
|
inline |
| PlayerID MatchEngine::getControlledPlayer | ( | ) | const |
The controlled player, or 0 when the AI controls everyone.
| std::string MatchEngine::getDebugSnapshotJson | ( | ) | const |
Machine-readable state for headless tests and external debug tooling.
|
inline |
| StrategySliders MatchEngine::getEffectiveSliders | ( | bool | homeTeam | ) | const |
Strategy sliders in force: the tactics plus any fading shout.
|
inline |
Total clock minutes played so far, including both added times.
|
inline |
| std::vector< Vector2F > MatchEngine::getFormation | ( | bool | homeTeam | ) | const |
Positions of the side's outfield slots in lineup coordinates (own goal line at x = 0, as Lineup::addOutfieldPlayer), in the lineup's order; the goalkeeper has no slot.
| std::optional< std::size_t > MatchEngine::getFormationSlot | ( | PlayerID | playerId | ) | const |
Slot of an outfield player on the pitch (nullopt otherwise).
|
inline |
|
inline |
Seconds left in the goal celebration before the kick-off restart.
|
inline |
Whether the last scored goal was conceded by the away team's keeper.
|
inline |
|
inline |
Highlight windows of the match so far (merged when they overlap).
|
inline |
Semantic goalkeeper state for each side, updated every fixed step.
|
inline |
|
inline |
|
inline |
Every controller change so far, step-stamped. Replaying it on a new engine with the same lineups, tactics and seed reproduces the match.
| float MatchEngine::getInterpolationAlpha | ( | ) | const |
Interpolation fraction between the previous and current fixed-step state, derived from the engine accumulator. In [0, 1).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Current period: 1 or 2, then 3 and 4 in extra time.
|
inline |
|
inline |
| std::optional< float > MatchEngine::getPlayerCondition | ( | PlayerID | playerId | ) | const |
Live physical condition in [0, 1] (end-of-match condition after full time) so a career simulation can carry fatigue between matches.
|
inline |
|
inline |
Per-player statistics for everyone who took part (never truncated).
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Per-match referee strictness (1 is average).
|
inline |
The highlight window being played in HIGHLIGHTS mode, if any.
|
inline |
Shootout kicks taken by a side.
|
inline |
Shootout goals of a side (0 without a shootout).
| float MatchEngine::getShoutStrength | ( | bool | homeTeam | ) | const |
Remaining strength of the side's shout in [0, 1] (0 when none).
| double MatchEngine::getSimulatedSeconds | ( | ) | const |
Simulated seconds since kick-off, including stoppages and half-time.
|
inline |
Fixed steps simulated since kick-off.
| TacticalRole MatchEngine::getSlotRole | ( | bool | homeTeam, |
| std::size_t | slot | ||
| ) | const |
Role played by an outfield slot of a side (see getFormation), resolved from the side's tactics by the slot's kick-off position.
|
inline |
|
inline |
|
inline |
| int MatchEngine::getSubstitutionsUsed | ( | bool | homeTeam | ) | const |
| int MatchEngine::getSubstitutionWindowsUsed | ( | bool | homeTeam | ) | const |
|
inline |
Familiarity in force: the drilled level, less a temporary loss after a change of shape (setFormation).
| float MatchEngine::getTeamTalkEffect | ( | bool | homeTeam | ) | const |
Team-talk effect in force for a side: the modifier of the current half at full strength for the first TacticsTuning::TALK_FULL_MINUTES of the half, fading to nothing by TALK_FADE_END_MINUTES (none in extra time). Besides execution it sharpens decisions and pressing (or blunts them, after a talk that went down badly).
| float MatchEngine::getTeamTalkModifier | ( | bool | homeTeam, |
| int | half | ||
| ) | const |
| std::optional< bool > MatchEngine::getTieWinnerHome | ( | ) | const |
Winner of a knockout tie at full time (true = this match's home side), from the aggregate score and then the shootout; empty for league matches and before full time.
|
inline |
Touch maps, pass network, pressures and the like for the match report (indexed like getPlayerStats()). On by default; background fidelity and highlight look-ahead switch it off.
|
inline |
|
private |
|
staticprivate |
Launch speed for a ground ball to arrive at arrivalSpeed.
|
private |
|
inline |
True once a penalty shootout has started.
|
private |
|
private |
Uniform in [0, 1) from the referee/injury stream (portable).
|
private |
|
private |
|
private |
|
private |
Pure ball physics for one sub-step (no contacts or rules).
|
private |
Stick-driven movement of the controlled player (fine sub-steps).
|
private |
Moves the players in slots toward their targets: the tactical target (urgent when urgentMovement is set) in play, or the restart spot (movementTarget) at a walk.
|
inline |
True when a side fell below seven players and the match was stopped.
|
private |
|
private |
| bool MatchEngine::isInAddedTime | ( | ) | const |
| bool MatchEngine::isInHighlight | ( | ) | const |
Whether the current moment lies inside a highlight window.
|
private |
Whether receiver stands offside against the given offside line (see offsideLine()), with an extra tolerance for misjudged lines.
|
private |
Kick-off formation spot of a player (his own half).
|
private |
Sends the ball from origin toward target (normalised) with a horizontal speed and vertical speed in m/s; the kicker is locked out of touching it again for a moment.
|
private |
| void MatchEngine::loadCommandReplay | ( | std::vector< MatchCommandRecord > | log | ) |
Schedules a recorded command log; a new change made during the replay discards the rest of it.
| void MatchEngine::loadInputReplay | ( | std::vector< MatchInputRecord > | log | ) |
Schedules a recorded input log (records applied at their steps).
|
staticprivate |
Vertical launch speed so the ball is at arrivalHeight metres after distanceMetres of horizontal travel.
|
private |
|
private |
|
private |
|
inlineprivate |
|
private |
Substitutions a side may make (one more in extra time).
| bool MatchEngine::movePlayerToSlot | ( | PlayerID | playerId, |
| std::size_t | slot | ||
| ) |
Moves an outfield player on the pitch to slot; the slot's occupant takes his old one (a slot left empty by a dismissal is simply taken).
|
private |
| PlayerID MatchEngine::nextSwitchCandidate | ( | bool | homeTeam, |
| PlayerID | current, | ||
| PlayerID | skip = 0 |
||
| ) | const |
The team-mate a manual switch would pick now: the best candidate by the same ranking, never current nor skip (pass the previous pick so repeated presses cycle). 0 when there is none.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Pass utility added by the passer's and the receiver's roles.
|
private |
Performs the controlled carrier's action; true if the ball left him.
|
private |
|
private |
Whether the last step crossed a multiple of ticks (a periodic job is due); every ticks steps at full fidelity.
|
private |
Base positions of a side's outfield players from its formation slots (a side short of players also sits a little deeper).
|
private |
|
private |
|
private |
Pass, through ball or lofted ball of the controlled carrier.
|
inlineprivate |
Formation spot while his side has the ball (role and shape shift).
| std::optional< MatchHighlight > MatchEngine::predictNextHighlight | ( | float | horizonSeconds = MatchTuning::Playback::PREDICTION_HORIZON_SECONDS | ) | const |
Predicts the next highlight window after the current moment by running a copy of the match up to horizonSeconds ahead. Deterministic: the live match plays out identically unless a manual change is made first.
|
inlineprivate |
Seconds a role is quicker (+) or slower to close the ball down.
|
private |
Share of the presser's normal stand-off distance.
|
private |
Uniform in [minimum, maximum) from the play stream (portable).
|
private |
Rating of an attribute in [0, 1] before the stretch.
|
private |
|
private |
Logs a live change that executed (truncating any pending replay).
|
private |
|
private |
|
private |
|
private |
|
private |
Team shape and every off-ball target (see updateMovement).
|
private |
|
private |
|
private |
|
private |
|
private |
Swept first-touch resolution over the last ball sub-step.
|
private |
|
private |
|
private |
Reads roles and opposition instructions from a side's tactics.
|
private |
|
inlineprivate |
|
private |
|
private |
|
private |
AI managers adjust with shouts to the score late in the game.
|
private |
|
private |
Takes off the side's players the medical staff limited to an hour.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
| void MatchEngine::setAutoSubstitutions | ( | bool | home, |
| bool | away | ||
| ) |
AI substitutions (fatigue, injuries, cards, game state) are enabled for both sides by default so headless matches manage themselves. A side managed by the human should disable its own.
|
private |
| bool MatchEngine::setControlledPlayer | ( | PlayerID | playerId | ) |
Play-mode seam: hands one outfield player to an external controller from the next fixed step (0 hands him back to the AI). While controlled, the player moves by the stick (at MatchTuning::Control::PHYSICS_SUBSTEPS per step, with the same acceleration, braking, turning and fatigue model) and acts only on the action button; team-mates and opponents stay AI. Set pieces and goalkeeping remain AI-driven. A controlled player who is substituted, sent off or goes in goal hands control back to the AI. Returns false (and changes nothing) for goalkeepers and players not on the pitch.
| bool MatchEngine::setFormation | ( | bool | homeTeam, |
| std::span< const Vector2F > | shape | ||
| ) |
Changes the shape: one position per slot (same size as getFormation()), clamped to the pitch. The players walk to their new spots; a real change of shape costs some tactical familiarity for a few minutes. Returns false (and changes nothing) for a wrong size or non-finite positions.
| void MatchEngine::setHighlightPlaybackSpeed | ( | float | simulatedSecondsPerWallSecond | ) |
Simulated seconds per wall second inside highlight windows.
| void MatchEngine::setKnockout | ( | const MatchRules::Knockout & | rules | ) |
Makes this a knockout match (before kick-off): level at full time, counting earlier legs, it goes to extra time and then to a penalty shootout. League matches keep the default and may end drawn.
| void MatchEngine::setMatchContext | ( | const MatchContext & | context | ) |
Sets the league character (see MatchContext) before kick-off; ignored once the match has started. Redraws the referee from the same seed.
| void MatchEngine::setMedicalFlags | ( | PlayerID | playerId, |
| std::uint8_t | flags | ||
| ) |
Medical staff instructions (MedicalFlag bits, see model/medical_centre.h) for a squad player: while his side's substitutions are automatic, a player limited to about an hour comes off at the first stoppage once he has played MedicalCentre::MINUTE_LIMIT minutes on the pitch (PlayerMatchStats::minutesPlayed: elapsed match-clock minutes, added time included, so a starter can be due a little before 60' on the second-half clock; a substitute counts from when he came on). Set before kick-off; no flags plays as before.
| void MatchEngine::setPlaybackMode | ( | MatchPlaybackMode | mode | ) |
Playback mode used by advancePlayback(); FULL_MATCH by default.
| void MatchEngine::setPlaybackSpeed | ( | float | simulatedSecondsPerWallSecond | ) |
Simulated seconds per wall second in FULL_MATCH mode (clamped).
| bool MatchEngine::setPlayerCondition | ( | PlayerID | playerId, |
| float | condition | ||
| ) |
Sets a player's condition before kick-off: a starter directly, a bench player when he comes on. False if the player is not in the squad or the match has started.
| void MatchEngine::setPlayHalfMinutes | ( | int | minutes | ) |
Schedule play clock pacing independently of physics; 0 restores watch.
|
private |
|
private |
|
private |
Changes the ticks per step (the fidelity) and the per-step blends.
| void MatchEngine::setStrategy | ( | bool | homeTeam, |
| const Strategy & | strategy | ||
| ) |
Replaces a side's tactics at any time; the sliders apply from the next step and the players re-form over a few seconds (their target response).
| void MatchEngine::setTacticalFamiliarity | ( | bool | homeTeam, |
| float | familiarity | ||
| ) |
Tactical familiarity of a side in [0, 1] (1 = fully drilled, the default). Low familiarity makes decisions noisier and positioning looser.
| void MatchEngine::setTeamNames | ( | std::string | homeTeam, |
| std::string | awayTeam | ||
| ) |
Team names used in the commentary lines (MatchEvent::description) from now on; without them the lines say "home/away side" (localised).
| void MatchEngine::setTeamTalkModifier | ( | bool | homeTeam, |
| int | half, | ||
| float | modifier | ||
| ) |
Team-talk execution modifier for one half (clamped to +-MatchTuning::Touchline::MAX_TEAM_TALK_MODIFIER): positive values make execution and decisions slightly sharper and work rate slightly higher. Logged in the command log (MatchCommandType::TEAM_TALK).
|
inline |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
The controlled shot's aim, lift and spread (strikeShot calls it).
|
private |
Shot appetite added by a shout (positive shoots more).
|
inlineprivate |
Work-rate bonus from an encouraging shout.
|
private |
|
private |
One fixed step of the simulation (simulateStep adds the commentary).
| void MatchEngine::simulateToEnd | ( | ) |
Headless: plays the rest of the match at full fidelity ("quick result" of a match the user may have been watching).
| void MatchEngine::simulateToEnd | ( | MatchFidelity | fidelity | ) |
Headless: plays the rest of the match at the given fidelity; background fixtures nobody watches pass MatchFidelity::BACKGROUND. A controlled player (play mode) always forces FULL.
|
private |
|
private |
Display name of a squad player (empty when unknown).
|
private |
|
private |
|
private |
|
inlineprivate |
Acceleration, braking, lateral limit, position and facing update.
|
private |
Seconds simulated by one step at the current fidelity.
| bool MatchEngine::stepsWithin | ( | float | deltaSeconds | ) | const |
Whether update(deltaSeconds) would simulate at least one fixed step, so a controller can sample its device exactly once per step.
|
private |
Strikes a shot at goal (aim, execution error, launch) and returns its xG; takeShot() adds the statistics and the event.
| void MatchEngine::submitInput | ( | const MatchPlayerInput & | input | ) |
Latest controller state for the controlled player; it holds until the next call and takes effect on the next fixed step. Ignored when nobody is controlled. Submitting input during a replay discards the rest of it.
| bool MatchEngine::substitutePlayer | ( | uint32_t | outPlayerId, |
| const Player * | inPlayer, | ||
| std::optional< std::size_t > | slot = std::nullopt |
||
| ) |
Replaces an on-pitch player with a bench player of the same team, who takes the outgoing player's slot or, if given, slot (its occupant then moves to the vacated one). Enforces the substitution limit (5, 6 in extra time) and windows (3, +1 in extra time, half-time excluded); returns false when the change is not allowed.
Play mode: the team-mate who should be the human's active footballer now. The ball carrier while the side has the ball (outfield only), the intended receiver of the side's pass, otherwise the player who can reach the ball first along its path (the carrier's run when defending), with a small preference for current so control does not flicker between two equally placed players. 0 when the side has nobody outfield. Const and random-free: asking never changes the match.
|
private |
Seconds a team-mate needs to get to the ball (see suggestActivePlayer).
|
private |
|
private |
|
private |
|
private |
|
inlineprivate |
Current team-talk modifier of a side (by the current half).
|
private |
Team-talk effect in [-1, 1] (see getTeamTalkEffect).
|
private |
Team execution edge: home crowd, team talk and numerical advantage.
|
private |
Level on aggregate (knockout ties).
|
private |
Pass utility lost to a tight marker standing next to the receiver.
|
private |
Moves a marker's target tight and goal-side of his man.
|
inlineprivate |
The man this player marks when he is under a tight-marking order.
|
private |
|
private |
|
private |
Pressing players close to the carrier apply a pressure.
|
private |
|
private |
|
private |
A defender's touch in front of his own goal that now and then goes toward it instead (true when it did).
| void MatchEngine::update | ( | float | deltaTime | ) |
Live update: advances deltaTime simulated seconds (wall-clock seconds times the viewer's speed; 1 = real time). Catch-up is bounded (MAX_FRAME_DELTA_SECONDS, MAX_FIXED_STEPS_PER_UPDATE) so a stalled frame never freezes the view; excess steps are dropped and counted in getDroppedSimulationSteps().
|
private |
Integrates the free ball in sub-steps, resolving contacts in each.
|
private |
|
private |
Moves the dribbled ball with its carrier; false if a heavy touch lost it.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
inline |
Play mode: whether a side was ever controlled from outside, and the passes, shots, clearances and tackles its controlled players made.
|
private |
Pressure in [0, 1] on a carrier forced onto his weaker foot.
|
private |
Presser's lateral shade onto the carrier's stronger side (normalised y; 0 without a weaker-foot order).
|
inline |
True once the match has gone into extra time.
| bool MatchEngine::writeDebugSnapshot | ( | std::string_view | path | ) | const |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Pre-match condition of bench players, applied when they come on.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
External control (play mode); an index keeps the engine copyable.
|
private |
Who was handed the controls (the slot may change hands).
|
private |
|
private |
Set-piece designations of each side (index 0 home), from the lineups.
|
private |
|
private |
Sliders in force (tactics plus shout), refreshed when they change.
|
private |
|
private |
|
private |
By side (index 0 home): ever controlled, and the actions played.
|
private |
|
private |
Shot precision factor from MatchContext::goalRateScale.
|
private |
Outfield slot positions by side (index 0 home), lineup coordinates.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Bumped by manual interventions; stale predictions are discarded.
|
private |
|
private |
Index 0 is the home keeper, 1 the away keeper.
|
private |
|
private |
Chain used for assists and key passes.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Raw attribute shift toward the reference level, and the finishing precision of the match's level.
|
private |
|
private |
Seconds and anchor positions since the last load accounting.
|
private |
|
private |
Opponent slot each outfield player marks (-1 when unassigned).
|
private |
|
private |
|
private |
|
private |
Medical staff instructions by squad player (see setMedicalFlags).
|
private |
Instructions each side (index 0 home) gives against opposing players.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
When the current carrier gained the ball (simulated seconds).
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Standard normal draw behind the referee's strictness.
|
private |
|
private |
Familiarity lost to a change of shape and the seconds it still lasts.
|
private |
|
private |
|
private |
Slot index of the restart taker (an index keeps the engine copyable).
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Positions after the last separation pass and whether it found no contact (an unchanged, contact-free field needs no new pass).
|
private |
|
private |
Shots by the attacking side shortly after a corner or attacking free kick count as set-piece shots, until the defence wins the ball or play stops.
|
private |
|
private |
|
private |
|
private |
Index 0 is the home side, 1 the away side.
|
private |
The score changed (or was set) since the sliders were computed.
|
private |
Kick-off slot positions by side (lineup coordinates): the keys that match slots to the tactics' role instructions.
|
private |
Slot roles by side (index 0 home), indexed by formation slot.
|
private |
Everyone in both matchday squads (names for the commentary).
|
private |
|
private |
|
private |
|
private |
Simulated time in fixed-step ticks (FIXED_STEP_SECONDS each).
|
private |
Ticks advanced per simulated step (1, or more in background fidelity).
|
private |
|
private |
|
private |
Ball state at the start of the current ball sub-step.
|
private |
|
private |
|
private |
|
private |
Ball situation at the last tactical refresh (event-driven refresh).
|
private |
Per-step target blends: home tactical/urgent, away tactical/urgent.
|
private |
|
private |
Team-talk modifiers by side and half.
|
private |
|
private |
|
private |
Underdog caution by side (0 = not the weaker side), from the XIs.
|
private |
Trailing events still without their commentary line.