Death in C3 critters is a special state which allows them to remove themselves from the world, and is a fairly simple process beginning with low energy or rarely old age triggering a flag, creating a new detritus object, removing the original critter, and the detritus object slowly decaying, giving nutrients to the world, and rarely, being edible itself (ew).
The normal logic flow in the timer script
Typically, dying is switched on by OV00 (State) being 99, and it is an early step in the normal logic flow in the timer of most C3 critters, after some maths has been done - which typically follows this pattern:
- increase age
- decrease energy
- if old enough, increase sex drive
- drown in water - lose energy rapidly
- if low on energy (sometimes also OR if too old) flag for death
- if hungry flag to get food
- if sex drive high, flag to mate
- obstacle checking - sometimes also water-shyness
- if flagged for death go to die subroutine
- if flagged to get food, get food
- if flagged to mate, mate
- if flagged to roam, roam
The logic flow in the timer script being arranged around two phases - first flagging, then checking the flags - is an example of a behaviour tree. This has the benefits of avoiding conflicts in behaviour, creating a predictable flow, allowing for lifelike complexity (flagging for multiple behaviours allows the system to choose between them with DOIF logic), while being performance friendly.
Death is the first thing checked for to encourage performance friendliness of the critter - there's no point it continuing on if it's scheduled for death - which allows other objects to carry on.
Death is explicitly hardcoded in the agent's life cycle - it is best to give yourself the wiggle room of using less than or equal to 0 for the energy object variable just in case it dips below 0 (as it might if the critter falls into water andican't get out). Keep in mind that a Boolean OR expands the circumstances in which a critter may die.
subr die_
— Detailed Breakdown
This function:
-
Switches the current agent to a "dead" version (with a different genus and sprites)
-
Stops its activity and animations
-
Optionally shows a "death" animation
-
Deletes the live agent cleanly
Step-by-Step Breakdown:
1. Save Current Position and Direction
setv va50 posl
setv va51 post
setv va52 ov10
-
Stores the hedgehog's current x/y coordinates and direction (
ov10
) for later use — either to play the animation in place or reposition the death sprite.
2. Choose a Death Sprite Based on Age
doif ov01 gt 1000
new: simp 2 10 15 "hedgehog" 50 0 2000
else
new: simp 2 10 15 "hedgehog" 50 50 2000
endi
-
Older hedgehogs get a different look than younger ones.
-
new: simp
creates a new agent to represent the dead body. -
2 10 15
is the classifier for this new, "dead" object. -
"hedgehog" 50 0/50
points to different sprites within the sprite file (adult vs. youth corpse).
3. Set Physical Attributes
accg 2
setv ov34 24
setv ov35 27
tick 4
attr 195
aero 0
-
Adjusts tick rate and physical properties to make the corpse static and inert (e.g., no air physics).
Also sets the BASE of the object in ov34 and ov35.
4. Reposition the Dead Object
setv ov10 va52
setv ov61 20
setv ov01 0
doif tmvt va50 va51 <> 1
kill targ
kill ownr
endi
mvto va50 va51
-
Moves the new corpse agent back to the hedgehog’s old location, and gives it the same x-direction as the live hedgehog.
-
If the test move fails (
tmvt ... <> 1
), it kills the agent to avoid bugs.
5. Set Pose and Animation for Death
setv vely 0
kill ownr
anim []
doif ov10 >= 0
base ov39
anim [0 1 2 3 4]
endi
doif ov10 < 0
base ov38
anim [0 1 2 3 4]
endi
-
kill ownr
removes the original live hedgehog — it's replaced by the static death object. -
Animates the death sprite using either left or right "roll-up" sequences (
ov38
orov39
). -
This lets the "corpse" play a final passive animation and exist in the world for a little while.
6. Finalise
over
retn
over
is often used to signal end of animation or processing for the agent.-
retn
ends the subroutine.
Summary:
The die_
subroutine doesn’t just delete the hedgehog—it:
-
Transitions it into a visual "dead" object
-
Plays a direction-based final animation
-
Handles resource cleanup and positioning
-
Keeps the game world consistent (dead objects may even affect the environment later, by donating some nutrients in their timer script, or being edible, as is recommended by the Creatures Development Standards).
No comments:
Post a Comment