3.8 KiB
3.8 KiB
Legacy General Model and Action Stack
This document captures how General aggregates modifiers, computes stats, and
exposes trigger hooks. The main reference is legacy/hwe/sammo/General.php.
Construction and Core State
Generalbuilds from raw DB rows (general, city, nation, rank, access log).last_turnis parsed intoLastTurn, and a separateresultTurnis maintained for updates.penaltyJSON is decoded intoPenaltyKey -> valuemap.auxJSON is lazily decoded and only written when aux values change.- Rank data is tracked with:
rankVarRead(current read view)rankVarIncrease(increment queue)rankVarSet(explicit set queue)
Action Objects (iAction)
General composes action sources into a single list:
- Nation type (
buildNationTypeClass) - Officer level (
TriggerOfficerLevel) - Domestic special (
buildGeneralSpecialDomesticClass) - War special (
buildGeneralSpecialWarClass) - Personality (
buildPersonalityClass) - Crew type (
GameUnitConst::byID) - Inheritance buff (
TriggerInheritBuff) - Scenario effect (
buildScenarioEffectClass) - Items: horse / weapon / book / item (
buildItemClass)
getActionList() returns this merged list and is the core entry point for
modifiers and triggers.
Stat Computation
getStatValue() applies layered modifiers:
- Base stat from raw value
- Injury multiplier
- Cross-stat adjust (strength/intel + 1/4 of the other stat)
- Clamp to
GameConst::$maxLevel onCalcStat()from every action object- Cached by
(statName, injury, action, adjust)tuple
Convenience wrappers:
getLeadership(),getStrength(),getIntel()
Turn Reservation and LastTurn
getReservedTurn(turnIdx)reads fromgeneral_turn.- When no entry exists,
buildGeneralCommandClass(null)creates휴식. LastTurnholds{ command, arg, term, seq }and is used byBaseCommand::addTermStack()to advance multi-turn commands.applyDB()persists updated fields and writeslast_turnif it changed.
Aux and Penalty Behavior
auxis loaded on demand (unpackAux()), andsetAuxVar()writes through togeneral.auxonly when values changed.- Setting an aux value to
nulldeletes the key from JSON. - Command constraints that require aux values trigger
General::unpackAux()before evaluation. penaltyis used in bothGenerallogic (AI and permission checks) and API flows (messages, nation tools); runtime expiration is not automatic.
Trigger and Modifier Hooks
General delegates calculations and trigger lists through action objects:
- Economy/strategy:
onCalcDomestic,onCalcStrategic,onCalcNationalIncome - Combat modifiers:
onCalcStat,onCalcOpposeStat,getWarPowerMultiplier - Arbitrary actions:
onArbitraryAction(used in city conquest)
Turn-prep triggers:
getPreTurnExecuteTriggerList()merges trigger lists from every action object.TurnExecutionHelper::preprocessCommand()addsche_부상경감+che_병력군량소모on top.
Battle triggers:
getBattleInitSkillTriggerList()merges per-action battle-init triggers.getBattlePhaseSkillTriggerList()includes base phase triggers:che_필살시도,che_필살발동che_회피시도,che_회피발동che_계략시도,che_계략발동,che_계략실패- plus any action-specific additions.
Rank and Access Log Updates
increaseRankVar()/setRankVar()queue updates untilapplyDB().applyDB()updatesgeneralandrank_data, then flushes logs.checkStatChange()uses*_expthresholds to increase/decrease stats and logs level changes.
Open Questions / Follow-ups
PenaltyKeyeffects and how penalties are applied are outside this file.GeneralBaseandLazyVarAndAuxUpdatermay contain additional state conventions for new code to mirror.