Player12
An open source football management simulator
Loading...
Searching...
No Matches
MatchEngine Class Reference

#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)
 

Private Attributes

std::vector< MatchPlayer > players
 
MatchBall ball
 
const StatsConfig & statsConfig
 
Strategy homeStrategy
 
Strategy awayStrategy
 
std::mt19937 rng
 
std::mt19937 incidentRng
 
std::uint32_t matchSeed = 0
 
std::uint64_t stepCounter = 0
 
std::uint32_t stepTicks = 1
 
float refereeStrictness = 1.0f
 
float refereeDraw = 0.0f
 
MatchContext matchContext
 
float finishingPrecision = 1.0f
 
float levelShift = 0.0f
 
float levelPrecision = 1.0f
 
std::vector< PlayerMatchStats > playerStats
 
std::vector< MatchSubstitution > substitutions
 
std::vector< const Player * > homeBench
 
std::vector< const Player * > awayBench
 
std::vector< const Player * > squad
 
std::array< SetPieceDesignations, 2 > designations {}
 
bool homeAutoSubstitutions = true
 
bool awayAutoSubstitutions = true
 
int homeSubstitutionWindows = 0
 
int awaySubstitutionWindows = 0
 
std::uint32_t stoppageSequence = 0
 
std::uint64_t lastStoppageStep = 0
 
std::uint64_t manualSubstitutionStep
 
std::uint32_t homeLastWindowStoppage = 0
 
std::uint32_t awayLastWindowStoppage = 0
 
std::uint32_t homeLastAiReviewStoppage = 0
 
std::uint32_t awayLastAiReviewStoppage = 0
 
int period = 1
 
bool abandoned = false
 
std::array< int, 4 > addedMinutes {0, 0, 0, 0}
 
std::array< MatchRules::StoppageLog, 4 > stoppageLogs {}
 
MatchRules::Knockout knockout
 
bool extraTimeReached = false
 
Shootout shootout
 
float elapsedMatchMinutes = 0.0f
 
float injuryCheckTimer = 0.0f
 
PendingAdvantage pendingAdvantage
 
const Player * lastCompletedPasser = nullptr
 
const Player * lastCompletedReceiver = nullptr
 
const Player * shotAssistCandidate = nullptr
 
const Player * lastShooter = nullptr
 
bool restartIsSetPiece = false
 
float setPiecePhaseRemaining = 0.0f
 
bool setPieceHome = true
 
std::vector< Vector2F > previousPlayerPositions
 
std::vector< float > previousPlayerFacingAngles
 
Vector2F previousBallPosition
 
float previousBallZ = 0.0f
 
std::vector< MatchEvent > events
 
std::size_t undescribedEvents = 0
 
std::array< std::string, 2 > teamNames
 
MatchStats stats
 
MatchTracker tracker
 
PassDecision lastPassDecision
 
ScenarioDecision lastScenarioDecision
 
std::array< GoalkeeperControl, 2 > keepers {}
 
MatchState state = MatchState::KICK_OFF
 
TeamPhase homePhase = TeamPhase::SET_PIECE
 
TeamPhase awayPhase = TeamPhase::SET_PIECE
 
std::optional< bool > lastControlledTeamHome
 
float transitionSecondsRemaining = 0.0f
 
std::optional< std::size_t > restartTakerIndex
 
float setPieceTimer = 0.0f
 
bool goalScoredByHome = false
 
float goalCelebrationRemaining = 0.0f
 
float accumulator = 0.0f
 
float ratingRefreshTimer = 0.0f
 
double possessionStartSeconds = 0.0
 
Vector2F substepBallPosition
 
float substepBallZ = 0.0f
 
float homeFamiliarity = 1.0f
 
float awayFamiliarity = 1.0f
 
std::array< ShoutState, 2 > shouts {}
 
std::array< StrategySliders, 2 > effectiveSliders {}
 
bool slidersStale = false
 
std::array< float, 2 > underdogShares {}
 
std::array< std::array< float, 2 >, 2 > teamTalks {}
 
std::array< std::array< SlotTactic, 16 >, 2 > slotTactics {}
 
std::array< RoleProfile, 2 > keeperProfiles {}
 
std::array< std::vector< Vector2F >, 2 > slotAnchors {}
 
std::array< std::vector< PlayerInstruction >, 2 > oppositionOrders {}
 
std::array< float, 4 > targetBlends {}
 
std::array< std::uint8_t, 32 > separationOrder {}
 
std::size_t separationCount = 0
 
std::array< Vector2F, 32 > separationPositions {}
 
bool separationClear = false
 
const Player * tacticalOwner = nullptr
 
std::uint8_t tacticalFlags = 0
 
float loadSeconds = 0.0f
 
std::vector< Vector2F > loadAnchors
 
std::array< std::int8_t, 32 > markAssignments {}
 
std::vector< std::pair< PlayerID, std::uint8_t > > medicalFlags
 
std::vector< std::pair< PlayerID, float > > benchConditions
 
std::optional< std::size_t > controlledIndex
 
PlayerID controlledPlayerId = 0
 
std::array< bool, 2 > everControlled {}
 
std::array< int, 2 > controlledActions {}
 
int playHalfMinutes = 0
 
int pendingPlayHalfMinutes = 0
 
MatchPlayerInput controlInput
 
float controlActionRemaining = 0.0f
 
MatchInputAction lastInputAction = MatchInputAction::NONE
 
ControlledShot controlledShot
 
std::vector< MatchInputRecord > inputLog
 
std::size_t inputCursor = 0
 
std::vector< MatchCommandRecord > commandLog
 
std::size_t commandCursor = 0
 
std::array< std::vector< Vector2F >, 2 > formations {}
 
std::array< float, 2 > reshapeFamiliarityCost {}
 
std::array< float, 2 > reshapeSecondsRemaining {}
 
std::vector< MatchHighlight > highlights
 
std::uint64_t highlightTriggerCount = 0
 
MatchEventType lastTriggerType = MatchEventType::INFO
 
double lastTriggerSeconds = 0.0
 
float lastTriggerMinute = 0.0f
 
MatchPlaybackMode playbackMode = MatchPlaybackMode::FULL_MATCH
 
float playbackSpeed = MatchTuning::Playback::DEFAULT_SPEED
 
float highlightSpeed = MatchTuning::Playback::DEFAULT_HIGHLIGHT_SPEED
 
std::optional< MatchHighlight > scheduledHighlight
 
std::uint32_t inputRevision = 0
 
std::uint32_t scheduledRevision = 0
 
float homePossessionMinutes = 0.0f
 
float awayPossessionMinutes = 0.0f
 
float matchTimeMinutes = 0.0f
 
int homeScore = 0
 
int awayScore = 0
 
int lastUpdateStepCount = 0
 
std::uint64_t droppedSimulationSteps = 0
 

Detailed Description

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.

Member Enumeration Documentation

◆ TacticalArrival

enum class MatchEngine::TacticalArrival
strongprivate
Enumerator
MIDFIELDER 
FAR_POST 
FULLBACK 

Constructor & Destructor Documentation

◆ MatchEngine() [1/2]

MatchEngine::MatchEngine ( const Lineup &  home_lineup,
const Lineup &  away_lineup,
const Strategy &  home_strat,
const Strategy &  away_strat,
const StatsConfig &  config 
)

◆ MatchEngine() [2/2]

MatchEngine::MatchEngine ( const Lineup &  home_lineup,
const Lineup &  away_lineup,
const Strategy &  home_strat,
const Strategy &  away_strat,
const StatsConfig &  config,
uint32_t  seed 
)

Member Function Documentation

◆ accumulatePlayerLoad()

void MatchEngine::accumulatePlayerLoad ( float  dt)
private

◆ addPlayerStats()

std::size_t MatchEngine::addPlayerStats ( const MatchPlayer &  matchPlayer,
bool  started 
)
private

◆ advance()

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.

◆ advanceClock()

void MatchEngine::advanceClock ( float  dt)
private

Clock, minutes played, distance, load statistics and energy.

◆ advancePlayback()

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.

◆ announceAddedTime()

void MatchEngine::announceAddedTime ( )
private

◆ applyDueCommands()

void MatchEngine::applyDueCommands ( )
private

◆ applyDueInputs()

void MatchEngine::applyDueInputs ( )
private

Applies input records due at the current step.

◆ applySanction()

void MatchEngine::applySanction ( MatchPlayer &  offender,
MatchRules::FoulSanction  sanction 
)
private

◆ applyScenario()

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.

◆ applyShout()

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).

◆ arrangeSetPiece()

void MatchEngine::arrangeSetPiece ( bool  attackingHome,
Vector2F  ballPosition 
)
private

◆ assignMarks()

void MatchEngine::assignMarks ( )
private

◆ attemptSave()

MatchEngine::SaveAttempt MatchEngine::attemptSave ( const MatchPlayer &  keeper)
private

Whether the keeper stops the shot crossing his plane in the last ball sub-step (reach and save roll only, no consequences).

◆ attemptTackle()

void MatchEngine::attemptTackle ( MatchPlayer &  carrier,
MatchPlayer &  defender,
bool  sliding 
)
private

◆ attemptTakeOn()

bool MatchEngine::attemptTakeOn ( MatchPlayer &  carrier,
MatchPlayer &  defender 
)
private

Tries to beat a jockeying defender; true if the carrier kept the ball.

◆ attribute()

float MatchEngine::attribute ( const Player *  player,
std::string_view  name 
) const
private

◆ backgroundStepTicks()

std::uint32_t MatchEngine::backgroundStepTicks ( ) const
private

Ticks of the next background-fidelity step (see MatchFidelity).

◆ beginBreak()

void MatchEngine::beginBreak ( float  seconds,
float  recovery 
)
private

Stops the clock for a break (half-time, before and in extra time).

◆ beginShootoutKick()

void MatchEngine::beginShootoutKick ( )
private

◆ beginStoppage()

void MatchEngine::beginStoppage ( )
private

◆ bestSetPieceTaker()

MatchPlayer * MatchEngine::bestSetPieceTaker ( bool  homeTeam,
bool  shooting 
)
private

◆ canSubstitute()

bool MatchEngine::canSubstitute ( bool  homeTeam) const

Whether the side can still make a substitution right now.

◆ captureInterpolationFrame()

void MatchEngine::captureInterpolationFrame ( )
private

◆ checkInjuries()

void MatchEngine::checkInjuries ( )
private

◆ checkOutOfBounds()

void MatchEngine::checkOutOfBounds ( )
private

◆ choosePassTarget()

std::optional< MatchEngine::PassOption > MatchEngine::choosePassTarget ( MatchPlayer &  passer)
private

◆ chooseReplacement()

const Player * MatchEngine::chooseReplacement ( bool  homeTeam,
PlayerRole  role,
bool  wantGoalkeeper 
) const
private

◆ clearBall()

void MatchEngine::clearBall ( MatchPlayer &  defender)
private

◆ clearBehind()

void MatchEngine::clearBehind ( MatchPlayer &  defender)
private

◆ clearFlightState()

void MatchEngine::clearFlightState ( )
private

◆ closestOutfieldPair()

std::array< MatchPlayer *, 2 > MatchEngine::closestOutfieldPair ( bool  homeTeam,
const MatchPlayer *  carrier,
Vector2F  pressurePosition 
)
private

◆ commitFoul()

void MatchEngine::commitFoul ( MatchPlayer &  offender,
MatchPlayer &  victim,
bool  ballWon,
bool  reckless 
)
private

◆ completeRestart()

void MatchEngine::completeRestart ( )
private

◆ computeEffectiveSliders()

StrategySliders MatchEngine::computeEffectiveSliders ( bool  homeTeam) const
private

◆ computeLevel()

void MatchEngine::computeLevel ( const Lineup &  home,
const Lineup &  away 
)
private

Match level from both elevens (see MatchTuning::Player).

◆ computeUnderdogShares()

void MatchEngine::computeUnderdogShares ( )
private

How clearly each side is the weaker one in [0, 1] (see Touchline).

◆ controlledAim()

Vector2F MatchEngine::controlledAim ( const MatchPlayer &  carrier) const
private

Stick direction of the controlled pass or shot (metres, unit length).

◆ controlledAssistTarget()

std::optional< Vector2F > MatchEngine::controlledAssistTarget ( const MatchPlayer &  player) const
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.

◆ controlledPassReceiver()

MatchPlayer * MatchEngine::controlledPassReceiver ( MatchPlayer &  carrier,
Vector2F  aim,
bool  throughBall 
)
private

Team-mate a controlled pass along aim goes to (nullptr: none).

◆ currentTopSpeed()

float MatchEngine::currentTopSpeed ( const MatchPlayer &  player) const
inlineprivate

Current top speed (m/s) after fatigue, sprint reserve and injury.

◆ cutsInside()

bool MatchEngine::cutsInside ( const MatchPlayer &  player) const
private

Whether a wide forward in the final third is cutting inside toward the box rather than going down the line to cross.

◆ decideAction()

void MatchEngine::decideAction ( MatchPlayer &  carrier)
private

◆ defensiveRoleShift()

float MatchEngine::defensiveRoleShift ( const MatchPlayer &  player) const
inlineprivate

Signed x shift of the role in the defensive block (normalised).

◆ deniesGoalChance()

bool MatchEngine::deniesGoalChance ( const MatchPlayer &  victim,
const MatchPlayer &  offender 
) const
private

◆ describePendingEvents()

void MatchEngine::describePendingEvents ( )
private

Writes the commentary line of the events logged since the last call.

◆ diveGoalkeeper()

void MatchEngine::diveGoalkeeper ( MatchPlayer &  keeper,
float  dt 
)
private

◆ doubleUpPenalty()

float MatchEngine::doubleUpPenalty ( const MatchPlayer &  carrier,
const MatchPlayer &  defender 
) const
private

Take-on success lost to a second defender doubling up.

◆ doubleUpPoint()

std::optional< Vector2F > MatchEngine::doubleUpPoint ( const MatchPlayer &  helper,
const MatchPlayer &  carrier,
const MatchPlayer *  firstPresser 
) const
private

Second presser's spot when doubling up on the carrier, if ordered.

◆ drawRefereeStrictness()

float MatchEngine::drawRefereeStrictness ( ) const
private

Per-match referee strictness from the draw and the context.

◆ dribbleExposureShare()

float MatchEngine::dribbleExposureShare ( ) const
private

Share of the current touch the ball is still away from the foot.

◆ dutyTaker()

MatchPlayer * MatchEngine::dutyTaker ( bool  homeTeam,
SetPieceDuty  duty 
)
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).

◆ effectiveFamiliarity()

float MatchEngine::effectiveFamiliarity ( std::size_t  team) const
private

Tactical familiarity in force: the drilled level less a reshape cost.

◆ endPeriod()

void MatchEngine::endPeriod ( )
private

◆ engageBoost()

float MatchEngine::engageBoost ( const MatchPlayer &  defender,
const MatchPlayer &  carrier 
) const
private

Multiplier of a defender's rate of engaging the carrier.

◆ ensureGoalkeeper()

void MatchEngine::ensureGoalkeeper ( bool  homeTeam)
private

◆ epochNoise()

float MatchEngine::epochNoise ( std::uint32_t  salt,
std::uint32_t  key,
std::uint32_t  epochSteps 
) const
private

Like hashNoise, but constant over windows of epochSteps steps.

◆ estimatedArrivalTime()

float MatchEngine::estimatedArrivalTime ( const MatchPlayer &  candidate,
Vector2F  pressurePosition,
const MatchPlayer *  carrier 
)
private

◆ estimateShotXG()

float MatchEngine::estimateShotXG ( const MatchPlayer &  shooter) const
private

◆ evaluatePassOption()

MatchEngine::PassOption MatchEngine::evaluatePassOption ( const MatchPlayer &  passer,
MatchPlayer &  receiver 
) const
private

◆ executeCommand()

bool MatchEngine::executeCommand ( const MatchCommandRecord &  command)
private

Performs an external tactical change (live or replayed); false when it is not allowed, in which case nothing changed.

◆ executionErrorScale()

float MatchEngine::executionErrorScale ( const MatchPlayer &  player) const
private

◆ extendRestart()

void MatchEngine::extendRestart ( float  seconds)
private

Extends the current restart delay (card, treatment, substitution).

◆ familiarityOf()

float MatchEngine::familiarityOf ( const MatchPlayer &  player) const
private

◆ findClosestPlayer()

MatchPlayer * MatchEngine::findClosestPlayer ( Vector2F  position,
bool  homeTeam,
bool  includeGoalkeeper = true 
)
private

◆ findCoverOutlet()

const MatchPlayer * MatchEngine::findCoverOutlet ( bool  defendingHome,
const MatchPlayer *  carrier 
) const
private

◆ findGoalkeeper()

MatchPlayer * MatchEngine::findGoalkeeper ( bool  homeTeam)
private

◆ findMatchPlayer()

MatchPlayer * MatchEngine::findMatchPlayer ( const Player *  player)
private

◆ findPlayerStats()

const PlayerMatchStats * MatchEngine::findPlayerStats ( PlayerID  playerId) const

◆ finishMatch()

void MatchEngine::finishMatch ( )
private

◆ finishShootoutKick()

void MatchEngine::finishShootoutKick ( MatchEventDetail  outcome)
private

◆ getActiveShout()

std::optional< MatchShout > MatchEngine::getActiveShout ( bool  homeTeam) const

The shout in force, if any.

◆ getAddedMinutes()

int MatchEngine::getAddedMinutes ( int  half) const
inline

Announced added minutes of a period 1-4 (0 until announced).

◆ getAwayGoalkeeperState()

GoalkeeperState MatchEngine::getAwayGoalkeeperState ( ) const
inline

◆ getAwayPhase()

TeamPhase MatchEngine::getAwayPhase ( ) const
inline

◆ getAwayScore()

int MatchEngine::getAwayScore ( ) const
inline

◆ getBall()

const MatchBall & MatchEngine::getBall ( ) const
inline

◆ getCommandLog()

const std::vector< MatchCommandRecord > & MatchEngine::getCommandLog ( ) const
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.

◆ getControlledActions()

int MatchEngine::getControlledActions ( bool  homeTeam) const
inline

◆ getControlledPlayer()

PlayerID MatchEngine::getControlledPlayer ( ) const

The controlled player, or 0 when the AI controls everyone.

◆ getDebugSnapshotJson()

std::string MatchEngine::getDebugSnapshotJson ( ) const

Machine-readable state for headless tests and external debug tooling.

◆ getDroppedSimulationSteps()

std::uint64_t MatchEngine::getDroppedSimulationSteps ( ) const
inline

◆ getEffectiveSliders()

StrategySliders MatchEngine::getEffectiveSliders ( bool  homeTeam) const

Strategy sliders in force: the tactics plus any fading shout.

◆ getElapsedMatchMinutes()

float MatchEngine::getElapsedMatchMinutes ( ) const
inline

Total clock minutes played so far, including both added times.

◆ getEvents()

const std::vector< MatchEvent > & MatchEngine::getEvents ( ) const
inline

◆ getFormation()

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.

◆ getFormationSlot()

std::optional< std::size_t > MatchEngine::getFormationSlot ( PlayerID  playerId) const

Slot of an outfield player on the pitch (nullopt otherwise).

◆ getGoalCelebrationDuration()

float MatchEngine::getGoalCelebrationDuration ( ) const
inline

◆ getGoalCelebrationRemaining()

float MatchEngine::getGoalCelebrationRemaining ( ) const
inline

Seconds left in the goal celebration before the kick-off restart.

◆ getGoalScoredByHome()

bool MatchEngine::getGoalScoredByHome ( ) const
inline

Whether the last scored goal was conceded by the away team's keeper.

◆ getHighlightPlaybackSpeed()

float MatchEngine::getHighlightPlaybackSpeed ( ) const
inline

◆ getHighlights()

const std::vector< MatchHighlight > & MatchEngine::getHighlights ( ) const
inline

Highlight windows of the match so far (merged when they overlap).

◆ getHomeGoalkeeperState()

GoalkeeperState MatchEngine::getHomeGoalkeeperState ( ) const
inline

Semantic goalkeeper state for each side, updated every fixed step.

◆ getHomePhase()

TeamPhase MatchEngine::getHomePhase ( ) const
inline

◆ getHomeScore()

int MatchEngine::getHomeScore ( ) const
inline

◆ getInputLog()

const std::vector< MatchInputRecord > & MatchEngine::getInputLog ( ) const
inline

Every controller change so far, step-stamped. Replaying it on a new engine with the same lineups, tactics and seed reproduces the match.

◆ getInterpolationAlpha()

float MatchEngine::getInterpolationAlpha ( ) const

Interpolation fraction between the previous and current fixed-step state, derived from the engine accumulator. In [0, 1).

◆ getKnockout()

const MatchRules::Knockout & MatchEngine::getKnockout ( ) const
inline

◆ getLastPassDecision()

const PassDecision & MatchEngine::getLastPassDecision ( ) const
inline

◆ getLastScenarioDecision()

const ScenarioDecision & MatchEngine::getLastScenarioDecision ( ) const
inline

◆ getLastUpdateStepCount()

int MatchEngine::getLastUpdateStepCount ( ) const
inline

◆ getMatchContext()

const MatchContext & MatchEngine::getMatchContext ( ) const
inline

◆ getMatchTimeMinutes()

float MatchEngine::getMatchTimeMinutes ( ) const
inline

◆ getPeriod()

int MatchEngine::getPeriod ( ) const
inline

Current period: 1 or 2, then 3 and 4 in extra time.

◆ getPlaybackMode()

MatchPlaybackMode MatchEngine::getPlaybackMode ( ) const
inline

◆ getPlaybackSpeed()

float MatchEngine::getPlaybackSpeed ( ) const
inline

◆ getPlayerCondition()

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.

◆ getPlayers()

const std::vector< MatchPlayer > & MatchEngine::getPlayers ( ) const
inline

◆ getPlayerStats()

const std::vector< PlayerMatchStats > & MatchEngine::getPlayerStats ( ) const
inline

Per-player statistics for everyone who took part (never truncated).

◆ getPlayHalfMinutes()

int MatchEngine::getPlayHalfMinutes ( ) const
inline

◆ getPreviousBallPosition()

Vector2F MatchEngine::getPreviousBallPosition ( ) const
inline

◆ getPreviousBallZ()

float MatchEngine::getPreviousBallZ ( ) const
inline

◆ getPreviousPlayerFacingAngles()

const std::vector< float > & MatchEngine::getPreviousPlayerFacingAngles ( ) const
inline

◆ getPreviousPlayerPositions()

const std::vector< Vector2F > & MatchEngine::getPreviousPlayerPositions ( ) const
inline

◆ getRefereeStrictness()

float MatchEngine::getRefereeStrictness ( ) const
inline

Per-match referee strictness (1 is average).

◆ getScheduledHighlight()

const std::optional< MatchHighlight > & MatchEngine::getScheduledHighlight ( ) const
inline

The highlight window being played in HIGHLIGHTS mode, if any.

◆ getShootoutKicks()

int MatchEngine::getShootoutKicks ( bool  homeTeam) const
inline

Shootout kicks taken by a side.

◆ getShootoutScore()

int MatchEngine::getShootoutScore ( bool  homeTeam) const
inline

Shootout goals of a side (0 without a shootout).

◆ getShoutStrength()

float MatchEngine::getShoutStrength ( bool  homeTeam) const

Remaining strength of the side's shout in [0, 1] (0 when none).

◆ getSimulatedSeconds()

double MatchEngine::getSimulatedSeconds ( ) const

Simulated seconds since kick-off, including stoppages and half-time.

◆ getSimulatedSteps()

std::uint64_t MatchEngine::getSimulatedSteps ( ) const
inline

Fixed steps simulated since kick-off.

◆ getSlotRole()

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.

◆ getState()

MatchState MatchEngine::getState ( ) const
inline

◆ getStats()

const MatchStats & MatchEngine::getStats ( ) const
inline

◆ getSubstitutions()

const std::vector< MatchSubstitution > & MatchEngine::getSubstitutions ( ) const
inline

◆ getSubstitutionsUsed()

int MatchEngine::getSubstitutionsUsed ( bool  homeTeam) const

◆ getSubstitutionWindowsUsed()

int MatchEngine::getSubstitutionWindowsUsed ( bool  homeTeam) const

◆ getTacticalFamiliarity()

float MatchEngine::getTacticalFamiliarity ( bool  homeTeam) const
inline

Familiarity in force: the drilled level, less a temporary loss after a change of shape (setFormation).

◆ getTeamTalkEffect()

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).

◆ getTeamTalkModifier()

float MatchEngine::getTeamTalkModifier ( bool  homeTeam,
int  half 
) const

◆ getTieWinnerHome()

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.

◆ getTracker()

const MatchTracker & MatchEngine::getTracker ( ) const
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.

◆ getTransitionSecondsRemaining()

float MatchEngine::getTransitionSecondsRemaining ( ) const
inline

◆ goalkeeperTarget()

Vector2F MatchEngine::goalkeeperTarget ( MatchPlayer &  keeper,
const MatchPlayer *  carrier 
)
private

◆ groundLaunchSpeed()

float MatchEngine::groundLaunchSpeed ( float  distanceMetres,
float  arrivalSpeed 
)
staticprivate

Launch speed for a ground ball to arrive at arrivalSpeed.

◆ hashNoise()

float MatchEngine::hashNoise ( std::uint32_t  salt,
std::uint32_t  key 
) const
private

◆ hasShootout()

bool MatchEngine::hasShootout ( ) const
inline

True once a penalty shootout has started.

◆ headBall()

void MatchEngine::headBall ( MatchPlayer &  header)
private

◆ incidentRoll()

float MatchEngine::incidentRoll ( )
private

Uniform in [0, 1) from the referee/injury stream (portable).

◆ initializePlayers()

void MatchEngine::initializePlayers ( const Lineup &  lineup,
bool  isHomeTeam 
)
private

◆ injurePlayer()

void MatchEngine::injurePlayer ( MatchPlayer &  player,
bool  fromContact 
)
private

◆ instructionAgainst()

OppositionInstruction MatchEngine::instructionAgainst ( const MatchPlayer &  target) const
private

◆ integrateBall()

void MatchEngine::integrateBall ( float  dt)
private

Pure ball physics for one sub-step (no contacts or rules).

◆ integrateControlled()

void MatchEngine::integrateControlled ( MatchPlayer &  player,
float  dt 
)
private

Stick-driven movement of the controlled player (fine sub-steps).

◆ integrateMovements()

FM_KERNEL_CLONES void MatchEngine::integrateMovements ( std::span< const std::uint8_t >  slots,
float  dt,
bool  walking 
)
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.

◆ isAbandoned()

bool MatchEngine::isAbandoned ( ) const
inline

True when a side fell below seven players and the match was stopped.

◆ isControlled()

bool MatchEngine::isControlled ( const MatchPlayer &  player) const
private

◆ isHomePlayer()

bool MatchEngine::isHomePlayer ( const Player *  player) const
private

◆ isInAddedTime()

bool MatchEngine::isInAddedTime ( ) const

◆ isInHighlight()

bool MatchEngine::isInHighlight ( ) const

Whether the current moment lies inside a highlight window.

◆ isOffside()

bool MatchEngine::isOffside ( const MatchPlayer &  receiver,
bool  attackingHome,
float  defenderLine,
float  lineTolerance = 0.0f 
) const
private

Whether receiver stands offside against the given offside line (see offsideLine()), with an extra tolerance for misjudged lines.

◆ kickOffPosition()

Vector2F MatchEngine::kickOffPosition ( const MatchPlayer &  player) const
private

Kick-off formation spot of a player (his own half).

◆ launchBall()

void MatchEngine::launchBall ( const MatchPlayer &  kicker,
Vector2F  origin,
Vector2F  target,
float  horizontalSpeed,
float  verticalSpeed,
float  curve 
)
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.

◆ loadAttributes()

void MatchEngine::loadAttributes ( MatchPlayer &  matchPlayer,
const Player *  player 
) const
private

◆ loadCommandReplay()

void MatchEngine::loadCommandReplay ( std::vector< MatchCommandRecord >  log)

Schedules a recorded command log; a new change made during the replay discards the rest of it.

◆ loadInputReplay()

void MatchEngine::loadInputReplay ( std::vector< MatchInputRecord >  log)

Schedules a recorded input log (records applied at their steps).

◆ loftVerticalSpeed()

float MatchEngine::loftVerticalSpeed ( float  distanceMetres,
float  horizontalSpeed,
float  startHeight,
float  arrivalHeight 
)
staticprivate

Vertical launch speed so the ball is at arrivalHeight metres after distanceMetres of horizontal travel.

◆ logEvent() [1/2]

MatchEvent & MatchEngine::logEvent ( MatchEventType  type)
private

◆ logEvent() [2/2]

MatchEvent & MatchEngine::logEvent ( MatchEventType  type,
const MatchPlayer &  actor 
)
private

◆ makeSave()

void MatchEngine::makeSave ( MatchPlayer &  goalkeeper)
private

◆ matchClockRate()

float MatchEngine::matchClockRate ( ) const
inlineprivate

◆ maxSubstitutions()

int MatchEngine::maxSubstitutions ( ) const
private

Substitutions a side may make (one more in extra time).

◆ movePlayerToSlot()

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).

◆ nearestOpponentDistance()

float MatchEngine::nearestOpponentDistance ( const MatchPlayer &  player) const
private

◆ nextSwitchCandidate()

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.

◆ offsideLine()

float MatchEngine::offsideLine ( bool  attackingHome) const
private

◆ openSpaceAhead()

float MatchEngine::openSpaceAhead ( const MatchPlayer &  carrier) const
private

◆ parryShot()

void MatchEngine::parryShot ( MatchPlayer &  goalkeeper,
bool  overTheBar 
)
private

◆ passBall()

void MatchEngine::passBall ( MatchPlayer &  passer,
const PassOption &  option,
bool  forceLofted = false 
)
private

◆ passingLaneRisk()

float MatchEngine::passingLaneRisk ( const MatchPlayer &  passer,
const MatchPlayer &  receiver 
) const
private

◆ passingRoleBias()

float MatchEngine::passingRoleBias ( const MatchPlayer &  passer,
const MatchPlayer &  receiver,
float  progression,
float  completion 
) const
private

Pass utility added by the passer's and the receiver's roles.

◆ performControlledAction()

bool MatchEngine::performControlledAction ( MatchPlayer &  carrier)
private

Performs the controlled carrier's action; true if the ball left him.

◆ performSubstitution()

bool MatchEngine::performSubstitution ( MatchPlayer &  outgoing,
const Player *  inPlayer,
SubstitutionReason  reason 
)
private

◆ periodElapsed()

bool MatchEngine::periodElapsed ( std::uint64_t  ticks) const
private

Whether the last step crossed a multiple of ticks (a periodic job is due); every ticks steps at full fidelity.

◆ placeFormation()

void MatchEngine::placeFormation ( bool  homeTeam)
private

Base positions of a side's outfield players from its formation slots (a side short of players also sits a little deeper).

◆ placeTaker()

void MatchEngine::placeTaker ( MatchPlayer &  taker,
Vector2F  spot 
)
private

◆ planGoalkeeperDive()

void MatchEngine::planGoalkeeperDive ( bool  defendingHome,
bool  penalty 
)
private

◆ playControlledPass()

void MatchEngine::playControlledPass ( MatchPlayer &  carrier,
MatchInputAction  action 
)
private

Pass, through ball or lofted ball of the controlled carrier.

◆ possessionAnchor()

Vector2F MatchEngine::possessionAnchor ( const MatchPlayer &  player) const
inlineprivate

Formation spot while his side has the ball (role and shape shift).

◆ predictNextHighlight()

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.

◆ pressEagerness()

float MatchEngine::pressEagerness ( const MatchPlayer &  candidate,
const MatchPlayer *  carrier 
) const
inlineprivate

Seconds a role is quicker (+) or slower to close the ball down.

◆ pressStandOffShare()

float MatchEngine::pressStandOffShare ( const MatchPlayer &  presser,
const MatchPlayer &  carrier 
) const
private

Share of the presser's normal stand-off distance.

◆ randomFloat()

float MatchEngine::randomFloat ( float  minimum,
float  maximum 
)
private

Uniform in [minimum, maximum) from the play stream (portable).

◆ rawAttribute()

float MatchEngine::rawAttribute ( const Player *  player,
std::string_view  name 
) const
private

Rating of an attribute in [0, 1] before the stretch.

◆ rebalanceShape()

void MatchEngine::rebalanceShape ( bool  homeTeam,
Vector2F  vacatedBase,
std::int8_t  vacatedSlot 
)
private

◆ recordCommand()

bool MatchEngine::recordCommand ( const MatchCommandRecord &  command)
private

Logs a live change that executed (truncating any pending replay).

◆ recordHighlight()

void MatchEngine::recordHighlight ( MatchEventType  type)
private

◆ recordPassCompletion()

void MatchEngine::recordPassCompletion ( MatchPlayer &  receiver)
private

◆ refreshEffectiveSliders()

void MatchEngine::refreshEffectiveSliders ( )
private

◆ refreshRatings()

void MatchEngine::refreshRatings ( )
private

◆ refreshTacticalTargets()

void MatchEngine::refreshTacticalTargets ( float  dt)
private

Team shape and every off-ball target (see updateMovement).

◆ refreshTargetBlends()

void MatchEngine::refreshTargetBlends ( )
private

◆ removeFromPitch()

void MatchEngine::removeFromPitch ( MatchPlayer &  player)
private

◆ resetPositions()

void MatchEngine::resetPositions ( )
private

◆ resolveAerialContest()

bool MatchEngine::resolveAerialContest ( )
private

◆ resolveLooseBall()

void MatchEngine::resolveLooseBall ( )
private

Swept first-touch resolution over the last ball sub-step.

◆ resolvePossessionAndActions()

void MatchEngine::resolvePossessionAndActions ( float  dt)
private

◆ resolveShotAtGoalkeeper()

void MatchEngine::resolveShotAtGoalkeeper ( MatchPlayer &  goalkeeper)
private

◆ resolveTactics()

void MatchEngine::resolveTactics ( bool  homeTeam)
private

Reads roles and opposition instructions from a side's tactics.

◆ restartTaker()

MatchPlayer * MatchEngine::restartTaker ( )
private

◆ roleProfileOf()

const RoleProfile & MatchEngine::roleProfileOf ( const MatchPlayer &  player) const
inlineprivate

◆ runAiSubstitutions()

void MatchEngine::runAiSubstitutions ( )
private

◆ runAiSubstitutionsFor()

void MatchEngine::runAiSubstitutionsFor ( bool  homeTeam)
private

◆ runAiTouchline()

void MatchEngine::runAiTouchline ( bool  homeTeam)
private

AI managers adjust with shouts to the score late in the game.

◆ runChannel()

float MatchEngine::runChannel ( const MatchPlayer &  runner) const
private

◆ runMedicalSubstitutions()

void MatchEngine::runMedicalSubstitutions ( bool  homeTeam)
private

Takes off the side's players the medical staff limited to an hour.

◆ runPriority()

float MatchEngine::runPriority ( const MatchPlayer &  candidate,
const MatchPlayer *  carrier 
)
private

◆ scoreGoal()

void MatchEngine::scoreGoal ( bool  homeTeam)
private

◆ selectActiveSupporters()

std::array< MatchPlayer *, MatchTuning::Shape::MAX_ACTIVE_SUPPORTERS > MatchEngine::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 
)
private

◆ selectAttackingRunners()

std::array< MatchPlayer *, MatchTuning::Shape::MAX_COMMITTED_RUNNERS > MatchEngine::selectAttackingRunners ( bool  homeTeam,
const MatchPlayer *  carrier,
const MatchPlayer *  transitionSource 
)
private

◆ selectFinalThirdPlayer()

MatchPlayer * MatchEngine::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 
)
private

◆ separatePlayers()

void MatchEngine::separatePlayers ( )
private

◆ setAutoSubstitutions()

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.

◆ setControlledPhases()

void MatchEngine::setControlledPhases ( bool  attackingHome,
float  ballX 
)
private

◆ setControlledPlayer()

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.

◆ setFormation()

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.

◆ setHighlightPlaybackSpeed()

void MatchEngine::setHighlightPlaybackSpeed ( float  simulatedSecondsPerWallSecond)

Simulated seconds per wall second inside highlight windows.

◆ setKnockout()

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.

◆ setMatchContext()

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.

◆ setMedicalFlags()

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.

◆ setPlaybackMode()

void MatchEngine::setPlaybackMode ( MatchPlaybackMode  mode)

Playback mode used by advancePlayback(); FULL_MATCH by default.

◆ setPlaybackSpeed()

void MatchEngine::setPlaybackSpeed ( float  simulatedSecondsPerWallSecond)

Simulated seconds per wall second in FULL_MATCH mode (clamped).

◆ setPlayerCondition()

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.

◆ setPlayHalfMinutes()

void MatchEngine::setPlayHalfMinutes ( int  minutes)

Schedule play clock pacing independently of physics; 0 restores watch.

◆ setPossession()

void MatchEngine::setPossession ( MatchPlayer &  player)
private

◆ setRestartTaker()

void MatchEngine::setRestartTaker ( MatchPlayer *  taker)
private

◆ setStepTicks()

void MatchEngine::setStepTicks ( std::uint32_t  ticks)
private

Changes the ticks per step (the fidelity) and the per-step blends.

◆ setStrategy()

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).

◆ setTacticalFamiliarity()

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.

◆ setTeamNames()

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).

◆ setTeamTalkModifier()

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).

◆ setTracking()

void MatchEngine::setTracking ( bool  on)
inline

◆ setTransitionPhases()

void MatchEngine::setTransitionPhases ( bool  attackingHome)
private

◆ setupCorner()

void MatchEngine::setupCorner ( bool  homeTeam,
bool  topCorner 
)
private

◆ setupFreeKick()

void MatchEngine::setupFreeKick ( bool  homeTeam,
Vector2F  foulPos 
)
private

◆ setupGoalKick()

void MatchEngine::setupGoalKick ( bool  homeTeam)
private

◆ setupKickOff()

void MatchEngine::setupKickOff ( bool  homeKickingOff)
private

◆ setupPenalty()

void MatchEngine::setupPenalty ( bool  homeTeam)
private

◆ setupThrowIn()

void MatchEngine::setupThrowIn ( bool  homeTeam)
private

◆ shapeControlledShot()

void MatchEngine::shapeControlledShot ( const MatchPlayer &  shooter,
float  halfGoal,
float  inset,
float &  aimY,
float &  aimZ,
float &  spread 
) const
private

The controlled shot's aim, lift and spread (strikeShot calls it).

◆ shoutShotBias()

float MatchEngine::shoutShotBias ( bool  homeTeam) const
private

Shot appetite added by a shout (positive shoots more).

◆ shoutWorkRate()

float MatchEngine::shoutWorkRate ( bool  homeTeam) const
inlineprivate

Work-rate bonus from an encouraging shout.

◆ simulateStep()

void MatchEngine::simulateStep ( float  dt)
private

◆ simulateStepBody()

void MatchEngine::simulateStepBody ( float  dt)
private

One fixed step of the simulation (simulateStep adds the commentary).

◆ simulateToEnd() [1/2]

void MatchEngine::simulateToEnd ( )

Headless: plays the rest of the match at full fidelity ("quick result" of a match the user may have been watching).

◆ simulateToEnd() [2/2]

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.

◆ slotOf()

std::size_t MatchEngine::slotOf ( const MatchPlayer &  player) const
private

◆ squadPlayerName()

std::string MatchEngine::squadPlayerName ( PlayerID  playerId) const
private

Display name of a squad player (empty when unknown).

◆ startShootout()

void MatchEngine::startShootout ( )
private

◆ startShout()

void MatchEngine::startShout ( bool  homeTeam,
MatchShout  shout 
)
private

◆ statsOf()

PlayerMatchStats & MatchEngine::statsOf ( const MatchPlayer &  matchPlayer)
private

◆ stepKinematics()

void MatchEngine::stepKinematics ( MatchPlayer &  player,
Vector2F  desired,
float  desiredSpeed,
float  topSpeed,
float  fatigue,
float  dt 
) const
inlineprivate

Acceleration, braking, lateral limit, position and facing update.

◆ stepSeconds()

float MatchEngine::stepSeconds ( ) const
private

Seconds simulated by one step at the current fidelity.

◆ stepsWithin()

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.

◆ strikeShot()

float MatchEngine::strikeShot ( const MatchPlayer &  shooter,
float  forcedXG,
bool  header,
bool  penalty,
bool  freeKick = false 
)
private

Strikes a shot at goal (aim, execution error, launch) and returns its xG; takeShot() adds the statistics and the event.

◆ submitInput()

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.

◆ substitutePlayer()

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.

◆ suggestActivePlayer()

PlayerID MatchEngine::suggestActivePlayer ( bool  homeTeam,
PlayerID  current 
) const

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.

◆ switchSeconds()

float MatchEngine::switchSeconds ( const MatchPlayer &  candidate) const
private

Seconds a team-mate needs to get to the ball (see suggestActivePlayer).

◆ takeCorner()

void MatchEngine::takeCorner ( MatchPlayer &  taker)
private

◆ takeDirectFreeKick()

void MatchEngine::takeDirectFreeKick ( MatchPlayer &  taker)
private

◆ takeSetPiece()

void MatchEngine::takeSetPiece ( MatchPlayer &  taker,
MatchState  restartState 
)
private

◆ takeShot()

void MatchEngine::takeShot ( MatchPlayer &  shooter,
float  forcedXG = -1.0f,
bool  header = false,
bool  freeKick = false 
)
private

◆ talkOf()

float MatchEngine::talkOf ( bool  homeTeam) const
inlineprivate

Current team-talk modifier of a side (by the current half).

◆ talkSwing()

float MatchEngine::talkSwing ( bool  homeTeam) const
private

Team-talk effect in [-1, 1] (see getTeamTalkEffect).

◆ teamEdge()

float MatchEngine::teamEdge ( bool  homeTeam) const
private

Team execution edge: home crowd, team talk and numerical advantage.

◆ tieLevel()

bool MatchEngine::tieLevel ( ) const
private

Level on aggregate (knockout ties).

◆ tightMarkPenalty()

float MatchEngine::tightMarkPenalty ( const MatchPlayer &  receiver) const
private

Pass utility lost to a tight marker standing next to the receiver.

◆ tightMarkPoint()

Vector2F MatchEngine::tightMarkPoint ( const MatchPlayer &  marker,
const MatchPlayer &  target,
Vector2F  current 
) const
private

Moves a marker's target tight and goal-side of his man.

◆ tightMarkTarget()

const MatchPlayer * MatchEngine::tightMarkTarget ( const MatchPlayer &  marker) const
inlineprivate

The man this player marks when he is under a tight-marking order.

◆ trackPassCompletion()

void MatchEngine::trackPassCompletion ( const MatchPlayer &  passer,
const MatchPlayer &  receiver 
)
private

◆ trackPassRelease()

void MatchEngine::trackPassRelease ( const MatchPlayer &  passer)
private

◆ trackPressures()

void MatchEngine::trackPressures ( )
private

Pressing players close to the carrier apply a pressure.

◆ trackShot()

void MatchEngine::trackShot ( const MatchPlayer &  shooter,
float  xg,
bool  setPiece,
bool  header,
bool  penalty 
)
private

◆ trackTouch()

void MatchEngine::trackTouch ( const MatchPlayer &  player)
private

◆ tryOwnGoalTouch()

bool MatchEngine::tryOwnGoalTouch ( MatchPlayer &  defender)
private

A defender's touch in front of his own goal that now and then goes toward it instead (true when it did).

◆ update()

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().

◆ updateBall()

void MatchEngine::updateBall ( float  dt)
private

Integrates the free ball in sub-steps, resolving contacts in each.

◆ updateBallInNet()

void MatchEngine::updateBallInNet ( float  dt)
private

◆ updateDribble()

bool MatchEngine::updateDribble ( const MatchPlayer &  carrier,
float  dt 
)
private

Moves the dribbled ball with its carrier; false if a heavy touch lost it.

◆ updateMatchClock()

void MatchEngine::updateMatchClock ( )
private

◆ updateMovement()

void MatchEngine::updateMovement ( float  dt)
private

◆ updatePendingAdvantage()

void MatchEngine::updatePendingAdvantage ( float  dt)
private

◆ updateRestartMovement()

void MatchEngine::updateRestartMovement ( float  dt)
private

◆ updateRestartSupport()

void MatchEngine::updateRestartSupport ( MatchPlayer &  player,
const MatchPlayer *  taker 
) const
private

◆ updateShootout()

void MatchEngine::updateShootout ( float  dt)
private

◆ updateTeamPhases()

void MatchEngine::updateTeamPhases ( )
private

◆ userRestartPassRequested()

bool MatchEngine::userRestartPassRequested ( ) const
private

◆ wasControlled()

bool MatchEngine::wasControlled ( bool  homeTeam) const
inline

Play mode: whether a side was ever controlled from outside, and the passes, shots, clearances and tackles its controlled players made.

◆ weakFootPressure()

float MatchEngine::weakFootPressure ( const MatchPlayer &  carrier) const
private

Pressure in [0, 1] on a carrier forced onto his weaker foot.

◆ weakFootShade()

float MatchEngine::weakFootShade ( const MatchPlayer &  carrier) const
private

Presser's lateral shade onto the carrier's stronger side (normalised y; 0 without a weaker-foot order).

◆ wentToExtraTime()

bool MatchEngine::wentToExtraTime ( ) const
inline

True once the match has gone into extra time.

◆ writeDebugSnapshot()

bool MatchEngine::writeDebugSnapshot ( std::string_view  path) const

Member Data Documentation

◆ abandoned

bool MatchEngine::abandoned = false
private

◆ accumulator

float MatchEngine::accumulator = 0.0f
private

◆ addedMinutes

std::array<int, 4> MatchEngine::addedMinutes {0, 0, 0, 0}
private

◆ awayAutoSubstitutions

bool MatchEngine::awayAutoSubstitutions = true
private

◆ awayBench

std::vector<const Player*> MatchEngine::awayBench
private

◆ awayFamiliarity

float MatchEngine::awayFamiliarity = 1.0f
private

◆ awayLastAiReviewStoppage

std::uint32_t MatchEngine::awayLastAiReviewStoppage = 0
private

◆ awayLastWindowStoppage

std::uint32_t MatchEngine::awayLastWindowStoppage = 0
private

◆ awayPhase

TeamPhase MatchEngine::awayPhase = TeamPhase::SET_PIECE
private

◆ awayPossessionMinutes

float MatchEngine::awayPossessionMinutes = 0.0f
private

◆ awayScore

int MatchEngine::awayScore = 0
private

◆ awayStrategy

Strategy MatchEngine::awayStrategy
private

◆ awaySubstitutionWindows

int MatchEngine::awaySubstitutionWindows = 0
private

◆ ball

MatchBall MatchEngine::ball
private

◆ benchConditions

std::vector<std::pair<PlayerID, float> > MatchEngine::benchConditions
private

Pre-match condition of bench players, applied when they come on.

◆ commandCursor

std::size_t MatchEngine::commandCursor = 0
private

◆ commandLog

std::vector<MatchCommandRecord> MatchEngine::commandLog
private

◆ controlActionRemaining

float MatchEngine::controlActionRemaining = 0.0f
private

◆ controlInput

MatchPlayerInput MatchEngine::controlInput
private

◆ controlledActions

std::array<int, 2> MatchEngine::controlledActions {}
private

◆ controlledIndex

std::optional<std::size_t> MatchEngine::controlledIndex
private

External control (play mode); an index keeps the engine copyable.

◆ controlledPlayerId

PlayerID MatchEngine::controlledPlayerId = 0
private

Who was handed the controls (the slot may change hands).

◆ controlledShot

ControlledShot MatchEngine::controlledShot
private

◆ designations

std::array<SetPieceDesignations, 2> MatchEngine::designations {}
private

Set-piece designations of each side (index 0 home), from the lineups.

◆ droppedSimulationSteps

std::uint64_t MatchEngine::droppedSimulationSteps = 0
private

◆ effectiveSliders

std::array<StrategySliders, 2> MatchEngine::effectiveSliders {}
private

Sliders in force (tactics plus shout), refreshed when they change.

◆ elapsedMatchMinutes

float MatchEngine::elapsedMatchMinutes = 0.0f
private

◆ events

std::vector<MatchEvent> MatchEngine::events
private

◆ everControlled

std::array<bool, 2> MatchEngine::everControlled {}
private

By side (index 0 home): ever controlled, and the actions played.

◆ extraTimeReached

bool MatchEngine::extraTimeReached = false
private

◆ finishingPrecision

float MatchEngine::finishingPrecision = 1.0f
private

Shot precision factor from MatchContext::goalRateScale.

◆ formations

std::array<std::vector<Vector2F>, 2> MatchEngine::formations {}
private

Outfield slot positions by side (index 0 home), lineup coordinates.

◆ goalCelebrationRemaining

float MatchEngine::goalCelebrationRemaining = 0.0f
private

◆ goalScoredByHome

bool MatchEngine::goalScoredByHome = false
private

◆ highlights

std::vector<MatchHighlight> MatchEngine::highlights
private

◆ highlightSpeed

float MatchEngine::highlightSpeed = MatchTuning::Playback::DEFAULT_HIGHLIGHT_SPEED
private

◆ highlightTriggerCount

std::uint64_t MatchEngine::highlightTriggerCount = 0
private

◆ homeAutoSubstitutions

bool MatchEngine::homeAutoSubstitutions = true
private

◆ homeBench

std::vector<const Player*> MatchEngine::homeBench
private

◆ homeFamiliarity

float MatchEngine::homeFamiliarity = 1.0f
private

◆ homeLastAiReviewStoppage

std::uint32_t MatchEngine::homeLastAiReviewStoppage = 0
private

◆ homeLastWindowStoppage

std::uint32_t MatchEngine::homeLastWindowStoppage = 0
private

◆ homePhase

TeamPhase MatchEngine::homePhase = TeamPhase::SET_PIECE
private

◆ homePossessionMinutes

float MatchEngine::homePossessionMinutes = 0.0f
private

◆ homeScore

int MatchEngine::homeScore = 0
private

◆ homeStrategy

Strategy MatchEngine::homeStrategy
private

◆ homeSubstitutionWindows

int MatchEngine::homeSubstitutionWindows = 0
private

◆ incidentRng

std::mt19937 MatchEngine::incidentRng
private

◆ injuryCheckTimer

float MatchEngine::injuryCheckTimer = 0.0f
private

◆ inputCursor

std::size_t MatchEngine::inputCursor = 0
private

◆ inputLog

std::vector<MatchInputRecord> MatchEngine::inputLog
private

◆ inputRevision

std::uint32_t MatchEngine::inputRevision = 0
private

Bumped by manual interventions; stale predictions are discarded.

◆ keeperProfiles

std::array<RoleProfile, 2> MatchEngine::keeperProfiles {}
private

◆ keepers

std::array<GoalkeeperControl, 2> MatchEngine::keepers {}
private

Index 0 is the home keeper, 1 the away keeper.

◆ knockout

MatchRules::Knockout MatchEngine::knockout
private

◆ lastCompletedPasser

const Player* MatchEngine::lastCompletedPasser = nullptr
private

Chain used for assists and key passes.

◆ lastCompletedReceiver

const Player* MatchEngine::lastCompletedReceiver = nullptr
private

◆ lastControlledTeamHome

std::optional<bool> MatchEngine::lastControlledTeamHome
private

◆ lastInputAction

MatchInputAction MatchEngine::lastInputAction = MatchInputAction::NONE
private

◆ lastPassDecision

PassDecision MatchEngine::lastPassDecision
private

◆ lastScenarioDecision

ScenarioDecision MatchEngine::lastScenarioDecision
private

◆ lastShooter

const Player* MatchEngine::lastShooter = nullptr
private

◆ lastStoppageStep

std::uint64_t MatchEngine::lastStoppageStep = 0
private

◆ lastTriggerMinute

float MatchEngine::lastTriggerMinute = 0.0f
private

◆ lastTriggerSeconds

double MatchEngine::lastTriggerSeconds = 0.0
private

◆ lastTriggerType

MatchEventType MatchEngine::lastTriggerType = MatchEventType::INFO
private

◆ lastUpdateStepCount

int MatchEngine::lastUpdateStepCount = 0
private

◆ levelPrecision

float MatchEngine::levelPrecision = 1.0f
private

◆ levelShift

float MatchEngine::levelShift = 0.0f
private

Raw attribute shift toward the reference level, and the finishing precision of the match's level.

◆ loadAnchors

std::vector<Vector2F> MatchEngine::loadAnchors
private

◆ loadSeconds

float MatchEngine::loadSeconds = 0.0f
private

Seconds and anchor positions since the last load accounting.

◆ manualSubstitutionStep

std::uint64_t MatchEngine::manualSubstitutionStep
private
Initial value:
=
std::numeric_limits<std::uint64_t>::max()

◆ markAssignments

std::array<std::int8_t, 32> MatchEngine::markAssignments {}
private

Opponent slot each outfield player marks (-1 when unassigned).

◆ matchContext

MatchContext MatchEngine::matchContext
private

◆ matchSeed

std::uint32_t MatchEngine::matchSeed = 0
private

◆ matchTimeMinutes

float MatchEngine::matchTimeMinutes = 0.0f
private

◆ medicalFlags

std::vector<std::pair<PlayerID, std::uint8_t> > MatchEngine::medicalFlags
private

Medical staff instructions by squad player (see setMedicalFlags).

◆ oppositionOrders

std::array<std::vector<PlayerInstruction>, 2> MatchEngine::oppositionOrders {}
private

Instructions each side (index 0 home) gives against opposing players.

◆ pendingAdvantage

PendingAdvantage MatchEngine::pendingAdvantage
private

◆ pendingPlayHalfMinutes

int MatchEngine::pendingPlayHalfMinutes = 0
private

◆ period

int MatchEngine::period = 1
private

◆ playbackMode

MatchPlaybackMode MatchEngine::playbackMode = MatchPlaybackMode::FULL_MATCH
private

◆ playbackSpeed

float MatchEngine::playbackSpeed = MatchTuning::Playback::DEFAULT_SPEED
private

◆ players

std::vector<MatchPlayer> MatchEngine::players
private

◆ playerStats

std::vector<PlayerMatchStats> MatchEngine::playerStats
private

◆ playHalfMinutes

int MatchEngine::playHalfMinutes = 0
private

◆ possessionStartSeconds

double MatchEngine::possessionStartSeconds = 0.0
private

When the current carrier gained the ball (simulated seconds).

◆ previousBallPosition

Vector2F MatchEngine::previousBallPosition
private
Initial value:
static constexpr float CENTRE
Definition match_tuning.h:37

◆ previousBallZ

float MatchEngine::previousBallZ = 0.0f
private

◆ previousPlayerFacingAngles

std::vector<float> MatchEngine::previousPlayerFacingAngles
private

◆ previousPlayerPositions

std::vector<Vector2F> MatchEngine::previousPlayerPositions
private

◆ ratingRefreshTimer

float MatchEngine::ratingRefreshTimer = 0.0f
private

◆ refereeDraw

float MatchEngine::refereeDraw = 0.0f
private

Standard normal draw behind the referee's strictness.

◆ refereeStrictness

float MatchEngine::refereeStrictness = 1.0f
private

◆ reshapeFamiliarityCost

std::array<float, 2> MatchEngine::reshapeFamiliarityCost {}
private

Familiarity lost to a change of shape and the seconds it still lasts.

◆ reshapeSecondsRemaining

std::array<float, 2> MatchEngine::reshapeSecondsRemaining {}
private

◆ restartIsSetPiece

bool MatchEngine::restartIsSetPiece = false
private

◆ restartTakerIndex

std::optional<std::size_t> MatchEngine::restartTakerIndex
private

Slot index of the restart taker (an index keeps the engine copyable).

◆ rng

std::mt19937 MatchEngine::rng
private

◆ scheduledHighlight

std::optional<MatchHighlight> MatchEngine::scheduledHighlight
private

◆ scheduledRevision

std::uint32_t MatchEngine::scheduledRevision = 0
private

◆ separationClear

bool MatchEngine::separationClear = false
private

◆ separationCount

std::size_t MatchEngine::separationCount = 0
private

◆ separationOrder

std::array<std::uint8_t, 32> MatchEngine::separationOrder {}
private

◆ separationPositions

std::array<Vector2F, 32> MatchEngine::separationPositions {}
private

Positions after the last separation pass and whether it found no contact (an unchanged, contact-free field needs no new pass).

◆ setPieceHome

bool MatchEngine::setPieceHome = true
private

◆ setPiecePhaseRemaining

float MatchEngine::setPiecePhaseRemaining = 0.0f
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.

◆ setPieceTimer

float MatchEngine::setPieceTimer = 0.0f
private

◆ shootout

Shootout MatchEngine::shootout
private

◆ shotAssistCandidate

const Player* MatchEngine::shotAssistCandidate = nullptr
private

◆ shouts

std::array<ShoutState, 2> MatchEngine::shouts {}
private

Index 0 is the home side, 1 the away side.

◆ slidersStale

bool MatchEngine::slidersStale = false
private

The score changed (or was set) since the sliders were computed.

◆ slotAnchors

std::array<std::vector<Vector2F>, 2> MatchEngine::slotAnchors {}
private

Kick-off slot positions by side (lineup coordinates): the keys that match slots to the tactics' role instructions.

◆ slotTactics

std::array<std::array<SlotTactic, 16>, 2> MatchEngine::slotTactics {}
private

Slot roles by side (index 0 home), indexed by formation slot.

◆ squad

std::vector<const Player*> MatchEngine::squad
private

Everyone in both matchday squads (names for the commentary).

◆ state

MatchState MatchEngine::state = MatchState::KICK_OFF
private

◆ stats

MatchStats MatchEngine::stats
private

◆ statsConfig

const StatsConfig& MatchEngine::statsConfig
private

◆ stepCounter

std::uint64_t MatchEngine::stepCounter = 0
private

Simulated time in fixed-step ticks (FIXED_STEP_SECONDS each).

◆ stepTicks

std::uint32_t MatchEngine::stepTicks = 1
private

Ticks advanced per simulated step (1, or more in background fidelity).

◆ stoppageLogs

std::array<MatchRules::StoppageLog, 4> MatchEngine::stoppageLogs {}
private

◆ stoppageSequence

std::uint32_t MatchEngine::stoppageSequence = 0
private

◆ substepBallPosition

Vector2F MatchEngine::substepBallPosition
private
Initial value:

Ball state at the start of the current ball sub-step.

◆ substepBallZ

float MatchEngine::substepBallZ = 0.0f
private

◆ substitutions

std::vector<MatchSubstitution> MatchEngine::substitutions
private

◆ tacticalFlags

std::uint8_t MatchEngine::tacticalFlags = 0
private

◆ tacticalOwner

const Player* MatchEngine::tacticalOwner = nullptr
private

Ball situation at the last tactical refresh (event-driven refresh).

◆ targetBlends

std::array<float, 4> MatchEngine::targetBlends {}
private

Per-step target blends: home tactical/urgent, away tactical/urgent.

◆ teamNames

std::array<std::string, 2> MatchEngine::teamNames
private

◆ teamTalks

std::array<std::array<float, 2>, 2> MatchEngine::teamTalks {}
private

Team-talk modifiers by side and half.

◆ tracker

MatchTracker MatchEngine::tracker
private

◆ transitionSecondsRemaining

float MatchEngine::transitionSecondsRemaining = 0.0f
private

◆ underdogShares

std::array<float, 2> MatchEngine::underdogShares {}
private

Underdog caution by side (0 = not the weaker side), from the XIs.

◆ undescribedEvents

std::size_t MatchEngine::undescribedEvents = 0
private

Trailing events still without their commentary line.


The documentation for this class was generated from the following files: