6.2 KiB
6.2 KiB
Legacy Engine Execution Flow
This document summarizes how the legacy engine advances turns and executes
commands. It focuses on the execution pipeline, RNG seeding, and state writes
based on legacy/hwe/sammo/API/Global/ExecuteEngine.php,
legacy/hwe/sammo/TurnExecutionHelper.php, and legacy/hwe/sammo/Command/BaseCommand.php.
Entry Point: ExecuteEngine API
- Endpoint:
legacy/hwe/sammo/API/Global/ExecuteEngine.php - Session: no session required (
NO_SESSION) - Optional
serverIDguard viaUniqueConst::$serverID - Calls
TurnExecutionHelper::executeAllCommand($updated, $locked) - Returns
{ updated, locked, lastExecuted }
Global Turn Loop (TurnExecutionHelper::executeAllCommand)
- Time gate
- If
now < game_env.turntime, return without executing.
- If
- Locking
tryLock()onplockrow (type='GAME').- If locked or
isunitedin2|3, return (frozen state).
- Pre-turn maintenance
- Cache game env,
checkDelay(),updateOnline(),CheckOverhead().
- Cache game env,
- Catch-up monthly loop
- Compute
prevTurn = cutTurn(turntime, turnterm)andnextTurn = addTurn(prevTurn). - While
nextTurn <= now:executeGeneralCommandUntil(nextTurn, limitActionTime, year, month)updateTraffic()- Monthly pipeline:
runEventHandler(PreMonth)preUpdateMonthly()turnDate(nextTurn)checkStatistic()(only ifmonth == 1)runEventHandler(Month)postUpdateMonthly($monthlyRng)
- Advance
prevTurn,nextTurn, updategame_env.turntime.
- Compute
- Current partial month
turnDate(prevTurn)executeGeneralCommandUntil(now, limitActionTime, year, month)
- Post-turn maintenance
processTournament()processAuction()- Reset cache,
unlock().
limitActionTime is derived from max_execution_time (roughly 2/3 of the
configured limit). If time runs out mid-loop, it returns early and keeps
game_env.turntime at the most recent executed value.
Per-General Execution (executeGeneralCommandUntil)
For each general with turntime < targetDate (ordered by turntime, no):
- Load state
General::createObjFromDB()andKVStorageforgame_env.
- Nation command (if officer_level >= 5)
- Pull
nation_turnrow forturn_idx = 0. - Build
NationCommandwithLastTurnstored innation_env.
- Pull
- AI/autorun
- NPCs (
npc >= 2) or players pastautorun_limituseGeneralAI. - AI can replace both nation and general commands.
- NPCs (
- Preprocess triggers
- RNG seed:
hiddenSeed + 'preprocess' + year + month + generalID. preprocessCommand()merges action triggers +che_부상경감,che_병력군량소모.
- RNG seed:
- Blocked users
processBlocked()consumeskillturnand logs ifblock >= 2.
- Execute nation command
- RNG seed:
hiddenSeed + 'nationCommand' + year + month + generalID + commandKey. processNationCommand()checks conditions, term stack,run().- If
run()fails andgetAlternativeCommand()exists, it retries. - Updates
nation_envwithLastTurnresult.
- RNG seed:
- Execute general command
- Load from
general_turn(turn_idx = 0), default to휴식. - RNG seed:
hiddenSeed + 'generalCommand' + year + month + generalID + commandKey. processCommand()checks conditions, term stack,run().- Updates
killturnbased on NPC status, autorun, or휴식.
- Load from
- Queue maintenance & turntime
pullNationCommand()/pullGeneralCommand()advance queues.updateTurnTime()handles deletion/retirement and sets nextturntime.- Persist via
General::applyDB().
- LastTurn persistence
- General
LastTurnlives ingeneral.last_turnJSON. - Nation
LastTurnis stored innation_envunderturn_last_{officer_level}. LastTurn.termonly advances when the same command + arg repeats across turns.
- General
Command Semantics (BaseCommand)
- Constraints: permission/min/full conditions are evaluated via
Constraint::testAll()withgeneral/city/nation/dest*context. - Pre-turn requirement:
getPreReqTurn()usesLastTurnto accumulate term stack (addTermStack()), logging "수행중" until the term completes. - Post-turn requirement:
getPostReqTurn()usesnext_executestorage (general:next_execute, nation:nation_env) to block early execution. - Run flow:
run($rng)returnstruewhen completed;falsecan chain togetAlternativeCommand().
Turntime & Lifecycle (updateTurnTime)
- Inactivity: if
killturn <= 0:- NPC-owned characters can detach (owner -> NPC) if
deadyearnot reached. - Otherwise the general is deleted (
kill()).
- NPC-owned characters can detach (owner -> NPC) if
- Retirement: if
age >= retirementYearand not NPC,CheckHall()andrebirth()are invoked. - Scheduling: next
turntimeisaddTurn(current, turnterm)with optionalnextTurnTimeBaseoverride (aux var).
killturn, block, autorun
killturnacts as an inactivity counter; it is reset togame_env.killturnwhen a non-rest player action completes, and decremented for NPCs, autorun, rest commands, or block states.block >= 2forceskillturndecrement and logs a block message.- When
killturn <= 0, the general is converted to NPC (owner removed) or deleted depending on NPC type anddeadyear. autorun_limitis stored in generalauxand used to decide AI takeover.
Deterministic RNG Seeds
RNG uses LiteHashDRBG with UniqueConst::$hiddenSeed:
- Preprocess:
('preprocess', year, month, generalID) - Nation command:
('nationCommand', year, month, generalID, commandKey) - General command:
('generalCommand', year, month, generalID, commandKey) - Monthly:
('monthly', year, month)
These seeds make command outcomes and monthly updates reproducible for validation.
Open Questions / Follow-ups
preUpdateMonthly(),postUpdateMonthly(),turnDate(),checkStatistic()are defined outside this flow; seelegacy/hwe/func_time_event.phpfor economic updates and population calculations.updateTraffic(),checkDelay(),updateOnline()logic lives inlegacy/hwe/func.phpand related utility files.