Skip to content

120 worked example the helis ground shadow

Alex Diakovsky edited this page Oct 2, 2026 · 2 revisions

120. Worked example: the Heli's ground shadow

Question: document 63 concluded that a live Heli casts no shadow, because the only caller of the shadow maker FUN_00409c50 it found sat in a "dying handler" at the record's +0x234. Document 118 found that hook is at +0x230 and is not a dying handler. Who calls it, and what is the shadow? (Issue #26.)

Step 1: the hook runs when the vehicle is created

The vehicle class's init FUN_0040b700 (obj, record = the type's record) calls the record's +0x230 slot on every new vehicle, before anything else is set up:

if (record->+0x230 != 0) {
    ok = record->+0x230(obj, record);
    if (ok == 0) { free the state; return 0; }
}

The slot is 0 for the Tank, Jeep and MSV, and FUN_0040eae0 for the Heli (confirmed by the one load of [ECX + 0x230] in the code, at 0x40b78c):

FUN_0040eae0(obj): FUN_00409c50(obj, &DESCRIPTOR_0x440ed8); return 1;

FUN_00409c50(owner, descriptor) makes an object of class 4 (table 0x443078) with the owner's draw descriptor replaced by the shadow's. So every Heli, from the moment it exists, has a Shadow object. Document 63's "a live Heli casts nothing" was wrong, and so was removing the shadow from the port.

Step 2: the Shadow object

Its init FUN_00409b50 links it to the owner; its tick FUN_00409bd0, every tick:

shadow->heading (+0x4c) = owner->heading;
shadow->sort (+0x50)    = owner->z - 1.0;
dx = (owner->z >> 8) * 0x55 - ...;  target x = owner->x + z * 0.332;
dy = (owner->y - (owner->z & ~0xfe) >> 1) - ...;  target y = owner->y - z / 2;     // on the ground (z = 0)
move there

The light comes from the lower left: the shadow lies 0.332 units east and 0.5 units north for each unit of height (16.6 and 25 units at the Heli's cruise height of 50), turned to the Heli's heading.

Step 3: what is drawn

Descriptor 0x440ed8 (draw callback 0x403760): two identical parts, cel 579 (effect.shadow.hard.heli_body), flags 0x10 (the translucent ground-shadow flag the soldiers' shadow has too: alpha 5/32), on a quad from x -12.75 to 13.6, y -19.55 (front) to 34.0 (tail). Two parts: where the shadow of the two overlap it is darker. The callback:

  • once the rotor's whole speed is 4 or more switches to 0x440e90, the same quad once (a lighter shadow at full spin);
  • while the owner's state +0x58 (the start-up accumulator of document 79, the landing timer of document 86) is below 1.0, pulls the two tail corners in by 18 x (1 - value): the shadow is short at the start of the start-up, grows toward the tail as the rotor spools up, and shrinks again as the Heli lands.

Chained to it (+4) is the rotor's shadow 0x440da8 (init FUN_00403610, draw FUN_004036d0): two parts (cels 589 and 605) on a bar 54.4 long, turned by the rotor angle (state+0x80), 6.8 wide for rotor modes 0 and 1 and 13.6 for 2 and 3 (half the rotor's own), and in the start-up (mode 4) a folded pair (corner set 0x440d60, not built).

Applied in the port

vehicle_shadow.json (both importers) puts a shadow table in the Heli's definition; VehicleShadow3D (game/vehicle_shadow_3d.gd), added by the view for every vehicle, draws it:

var off: Array = _cfg["offset_per_height"]
position = Vector3(vehicle.position.x + float(off[0]) * vehicle.z, 0.3, vehicle.position.y + float(off[1]) * vehicle.z)
rotation_degrees.y = -90.0 - vehicle.heading_deg
...
for i in _cfg.get("tail_points", []):
	corners[int(i)].y -= shear
var layers := 1 if shear == 0.0 and mode >= int(_cfg.get("single_layer_from_rotor_mode", 3)) and vehicle.heli_spinup_stage != 1 else 2

tools/tests/heli_shadow_check.gd checks the table (Heli only), the offset, and the layers in the start-up, at full speed and below. Port choices: the blade shadow's rotation is accumulated in the shadow node, so its phase is not the blade's; the folded start-up pair is not drawn.

Still open

  • The dying Heli: the wreck dispatcher 0x42eae0 draws 0x440ed8, the body and the stopped rotor 0x4406c0 for a dying vehicle; with the Shadow object living on, what the Shadow does when its owner becomes a wreck (its tick frees it when the owner link goes, FUN_00409bd0) is not decoded.
  • The bank/pitch "bob tables" 0x4454a0 / 0x4454d8 have no reader: the drive handler FUN_0040e0e0 uses neither (the wobble in state+0x90/0x94 is what document 63 took for a bob; it is the hover drift, built). They look like unused data.
  • The rotor's opacity: no code evidence (unchanged).

Clone this wiki locally