A dozen of ways to loose a unit

I’ve been categorizing and refactoring unit deaths in the game. Made this comment block in the code. Might be interesting for you to see it too:

// Killing of a unit is done in 4 big steps
// 1. KillUnit - unit is doomed to die (could be next tick, if unit is doing exchange).
// - Fire event
// - Register statistic
// 2. KillInternally - we can kill it now (exchange interactions are done)
// - Abandon old tasks
// - Create and execute Die task (exits house, shows animation, takes ~20 ticks)
// 3. KillFinalize - erase all unit data and hide it from further access
// 4. Delete - when unit has no pointers left

// KillUnit usages
//
// A L - gic_TempKillUnit (kills any selected unit)
// S G - UnitOwnerChange (from script, or capturing a wagon. Kills old and creates new)
// A/S L - ScriptingActions.UnitKill (kills any unit)
// S L - CheckAnimalIsStuck (kills any stuck unit)
// A L - Unit.HitPointsDecrease (killed by enemy)
// A L - fCondition <= 0 (any unit could die of hunger any time. training units get their condition topped manually, yet script can reset any condition back to 0)
// S - - TrainingCancel (kill wip unit)
// S U - UnitTrainingEnd (kill Blank unit)
// S L - FindPlaceForUnit fail (extra units get killed when house is destroyed)
// S L - DeleteUnit (by MapEd)
// S - - TKMUnitTaskDie (final result of Die task)
// S C - TKMUnitTaskWagonGoHouse (wagon entering house)

// A - animated death
// S - silent kill

// L - Lost
// U - Upgraded
// G - GivenAway
// C - Consumed

This entry was posted in How things work, Sidenotes. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *