Download crates/openwa-core/src/task/missile.rs from nmarshall/wormz-a: direct link, hf CLI and curl.
- Browser
- Download file 11.8 kB
-
https://huggingface.co/nmarshall/wormz-a/resolve/main/crates/openwa-core/src/task/missile.rs
- Command line
-
hf download hf://nmarshall/wormz-a/crates/openwa-core/src/task/missile.rs
-
curl -L -o missile.rs https://huggingface.co/nmarshall/wormz-a/resolve/main/crates/openwa-core/src/task/missile.rs
11.8 kB
| use super::base::CTask; | |
| use super::game_task::CGameTask; | |
| use crate::fixed::Fixed; | |
| use crate::game::weapon::WeaponSpawnData; | |
| use crate::FieldRegistry; | |
| crate::define_addresses! { | |
| class "CTaskMissile" { | |
| /// CTaskMissile vtable - projectile entity | |
| vtable CTASK_MISSILE_VTABLE = 0x0066_4438; | |
| ctor CTASK_MISSILE_CTOR = 0x0050_7D10; | |
| } | |
| } | |
| /// CTaskMissile vtable β 12 slots. Extends CGameTask vtable with missile behavior. | |
| /// | |
| /// Vtable at Ghidra 0x664438. | |
| pub struct CTaskMissileVTable { | |
| /// HandleMessage β processes missile messages. | |
| /// thiscall + 4 stack params, RET 0x10. | |
| pub handle_message: | |
| fn(this: *mut CTaskMissile, sender: *mut CTask, msg_type: u32, size: u32, data: *const u8), | |
| /// ProcessFrame β per-frame missile update (physics, homing, detonation). | |
| /// thiscall + 1 stack param (flags), RET 0x4. | |
| pub process_frame: fn(this: *mut CTaskMissile, flags: u32), | |
| } | |
| /// Projectile / missile entity task. | |
| /// | |
| /// Extends CGameTask (0xFC bytes). One instance per airborne projectile | |
| /// (rockets, grenades, mortar shells, homing missiles, sheep, etc.). | |
| /// | |
| /// Inheritance: CTask β CGameTask β CTaskMissile. class_type = 0x0B (11). | |
| /// Constructor: `CTaskMissile__Constructor` (0x507D10, stdcall, 4 params). | |
| /// Vtable: `CTaskMissile__vtable` (0x00664438). | |
| /// | |
| /// Constructor params: | |
| /// param_1 = this | |
| /// param_2 = parent task pointer (passed to CGameTask ctor) | |
| /// param_3 = scheme weapon data (94 DWORDs from WGT blob) | |
| /// param_4 = spawn data (11 DWORDs: position, velocity, owner, pellet index) | |
| /// | |
| /// Source: Ghidra decompilation of 0x507D10 (constructor) and | |
| /// wkJellyWorm CTaskMissile.h (field layout reference). | |
| pub struct CTaskMissile { | |
| /// 0x00β0xFB: CGameTask base (pos at 0x84/0x88, speed at 0x90/0x94). | |
| pub base: CGameTask<*const CTaskMissileVTable>, | |
| // ---- 0xFCβ0x12F: missile init fields ---- | |
| /// 0xFCβ0x10F: Unknown missile flags and state | |
| pub _unknown_fc: [u8; 0x14], | |
| /// 0x110: Unknown | |
| pub _unknown_110: u32, | |
| /// 0x114: Unknown | |
| pub _unknown_114: u32, | |
| /// 0x118: Unknown β observed being set from scheme data at construction | |
| pub _unknown_118: u32, | |
| /// 0x11C: Unknown | |
| pub _unknown_11c: u32, | |
| /// 0x120: Unknown | |
| pub _unknown_120: u32, | |
| /// 0x124: Unknown | |
| pub _unknown_124: u32, | |
| /// 0x128: Position-derived launch seed. Computed by constructor as: | |
| /// `((spawn_x + spawn_y) / 256 / 20) + 0x10000`. param_1[0x4A]. | |
| pub launch_seed: u32, | |
| /// 0x12C: Object pool slot index (assigned from DDGame+0x3600 pool). | |
| /// param_1[0x4B]. | |
| pub slot_id: u32, | |
| // ---- 0x130β0x15B: spawn data (11 DWORDs, from param_4) ---- | |
| /// 0x130β0x15B: Spawn parameters copied from constructor param_4. | |
| /// See `WeaponSpawnData` for field documentation. | |
| pub spawn_params: WeaponSpawnData, | |
| // ---- 0x15Cβ0x2D3: weapon/scheme data (94 DWORDs, from param_3) ---- | |
| /// 0x15Cβ0x2D3: Weapon/scheme properties (94 DWORDs copied verbatim from param_3). | |
| /// | |
| /// The WGT scheme blob is split into two logical halves: | |
| /// [0x00..0x34] primary projectile params (β also mirrored in render_data) | |
| /// [0x34..0x5E] cluster sub-pellet params (β render_data when pellet_index > 0) | |
| /// | |
| /// Runtime-observed for bazooka: | |
| /// [0x03] = 137342 β Fixed16.16 β 2.10 (some radius/size) | |
| /// [0x05] = 100, [0x06] = 50, [0x09] = 48 | |
| /// [0x0F] gravity_pct β 100 β gravity_factor = 1.0 (β CGameTask+0x58 via render_data) | |
| /// [0x10] bounce_pct β 100 β bounce_factor = 1.0 (β CGameTask+0x5C via render_data) | |
| /// [0x12] friction_pct β 100 β friction_factor = 1.0 (β CGameTask+0x60 via render_data) | |
| /// [0x14] = 9000 | |
| /// [0x1A] missile_type β discriminator (2=Standard, 3=Homing, 4=Sheep, 5=Cluster) | |
| /// [0x1B] = 4194304 β Fixed16.16 = 64.0 | |
| /// [0x1C] render_timer β 1 for bazooka, 30 for grenade (3s fuse @ 10fps) | |
| pub weapon_data: [u32; 0x5E], | |
| // ---- 0x2D4β0x37B: render/physics parameters (42 DWORDs) ---- | |
| /// 0x2D4β0x37B: Per-projectile render and physics parameters (42 DWORDs). | |
| /// | |
| /// This is NOT a separate data block β it is a shifted copy of weapon_data: | |
| /// if spawn_params[8] == 0 (single shot): render_data[N] = weapon_data[N+3] | |
| /// if spawn_params[8] > 0 (cluster pellet): render_data[N] = weapon_data[N+52] | |
| /// | |
| /// The constructor copies 42 DWORDs from the appropriate source range | |
| /// into this region (param_1[0xB5..0xDE]). Dynamic physics values update | |
| /// some entries during flight (e.g. render_data[0x29] @ 0x37C). | |
| /// | |
| /// Key indices (relative to render_data, = weapon_data[N+3] for single shots): | |
| /// [0x0C] gravity_pct β (value << 16) / 100 β CGameTask+0x58 (gravity_factor) | |
| /// [0x0D] bounce_pct β (value << 16) / 100 β CGameTask+0x5C (bounce_factor) | |
| /// [0x0F] friction_pct β (value << 16) / 100 β CGameTask+0x60 (friction_factor) | |
| /// [0x11] = 9000 for bazooka (β also copied to post-render field at 0x37C) | |
| /// [0x17] missile_type β type discriminator (see MissileType) | |
| /// [0x18] = 4194304 β Fixed16.16 = 64.0 (sprite/render size) | |
| /// [0x19] render_timer β 1 for bazooka, 30 for grenade (3s fuse timer) | |
| pub render_data: [u32; 0x2A], | |
| // ---- 0x37Cβ0x41B: post-render physics and state ---- | |
| /// 0x37Cβ0x39F: Post-render dynamic state. render_data[0x11] is copied to | |
| /// [0x37C] by the constructor; physics updates the values each frame. | |
| pub _unknown_37c: [u8; 0x24], | |
| /// 0x3A0: Fixed16.16 launch speed magnitude (computed from initial velocity). | |
| /// Observed as 0 for bazooka β may only be populated for specific types. | |
| pub launch_speed_raw: Fixed, | |
| /// 0x3A4: Unknown | |
| pub _unknown_3a4: u32, | |
| /// 0x3A8: Homing mode enabled flag (nonzero = active homing). | |
| /// param_1[0xEA] in constructor. Set to 1 when missile_type == 3 and conditions | |
| /// are met (target acquired). | |
| pub homing_enabled: u32, | |
| /// 0x3ACβ0x3BF: Unknown homing state fields | |
| pub _unknown_3ac: [u8; 0x14], | |
| /// 0x3C0β0x3C7: Unknown | |
| pub _unknown_3c0: [u8; 8], | |
| /// 0x3C8: Horizontal direction sign (+1 or -1, determines facing/travel dir). | |
| /// param_1[0xF2] in constructor. Set to -1 for homing/sheep if initial_speed_x < 0. | |
| pub direction: i32, | |
| /// 0x3CCβ0x40B: Unknown trailing state. | |
| /// Allocation size is 0x40C; constructor zeros bytes 0x00β0x3EB. | |
| pub _unknown_3cc: [u8; 0x40], | |
| } | |
| const _: () = assert!(core::mem::size_of::<CTaskMissile>() == 0x40C); | |
| // Generate typed vtable method wrappers: handle_message(), process_frame(). | |
| bind_CTaskMissileVTable!(CTaskMissile, base.base.vtable); | |
| impl CTaskMissile { | |
| /// Missile type from `render_data[0x17]` (= weapon_data[0x1A] for single shots). | |
| /// | |
| /// Governs constructor and movement behaviour (homing, sheep walk, | |
| /// cluster splitting, etc.). | |
| pub fn missile_type(&self) -> MissileType { | |
| match self.render_data[0x17] { | |
| 2 => MissileType::Standard, | |
| 3 => MissileType::Homing, | |
| 4 => MissileType::Sheep, | |
| 5 => MissileType::Cluster, | |
| n => MissileType::Unknown(n), | |
| } | |
| } | |
| /// Spawn X as Fixed16.16. | |
| pub fn spawn_x(&self) -> Fixed { | |
| self.spawn_params.spawn_x | |
| } | |
| /// Spawn Y as Fixed16.16. | |
| pub fn spawn_y(&self) -> Fixed { | |
| self.spawn_params.spawn_y | |
| } | |
| /// Aim cursor X at time of fire, Fixed16.16. | |
| pub fn cursor_x(&self) -> Fixed { | |
| self.spawn_params.cursor_x | |
| } | |
| /// Aim cursor Y at time of fire, Fixed16.16. | |
| pub fn cursor_y(&self) -> Fixed { | |
| self.spawn_params.cursor_y | |
| } | |
| } | |
| /// Missile movement/behaviour type, encoded in `render_data[0x17]`. | |
| /// | |
| /// The constructor switches on this value to set up physics, homing, | |
| /// direction, and clustering behaviour. Corresponds to weapon_data[0x1A] | |
| /// for single-shot projectiles. | |
| pub enum MissileType { | |
| /// Standard trajectory projectile (bazooka, mortar, grenade, etc.). Value = 2. | |
| Standard, | |
| /// Homing missile β tracks nearest worm. Value = 3. | |
| Homing, | |
| /// Sheep / animal projectile β walks on terrain. Value = 4. | |
| Sheep, | |
| /// Cluster projectile β spawns sub-pellets on detonation. Value = 5. | |
| Cluster, | |
| /// Unknown type code (value 1 never observed; any other unrecognised value). | |
| Unknown(u32), | |
| } | |
| // ββ Snapshot impl ββββββββββββββββββββββββββββββββββββββββββ | |
| impl crate::snapshot::Snapshot for CTaskMissile { | |
| unsafe fn write_snapshot( | |
| &self, | |
| w: &mut dyn core::fmt::Write, | |
| indent: usize, | |
| ) -> core::fmt::Result { | |
| use crate::snapshot::{write_indent, write_raw_region}; | |
| let i = indent; | |
| let b = &self.base; // CGameTask | |
| write_indent(w, i)?; | |
| writeln!(w, "pos = ({}, {})", b.pos_x, b.pos_y)?; | |
| write_indent(w, i)?; | |
| writeln!(w, "speed = ({}, {})", b.speed_x, b.speed_y)?; | |
| write_indent(w, i)?; | |
| writeln!(w, "launch_seed = 0x{:08X}", self.launch_seed)?; | |
| write_indent(w, i)?; | |
| writeln!(w, "slot_id = {}", self.slot_id)?; | |
| let sp = &self.spawn_params; | |
| write_indent(w, i)?; | |
| writeln!(w, "spawn_params:")?; | |
| write_indent(w, i + 1)?; | |
| writeln!( | |
| w, | |
| "owner={} spawn=({}, {}) speed=({}, {})", | |
| sp.owner_id, sp.spawn_x, sp.spawn_y, sp.initial_speed_x, sp.initial_speed_y | |
| )?; | |
| write_indent(w, i + 1)?; | |
| writeln!( | |
| w, | |
| "cursor=({}, {}) pellet={} fallback=({}, {})", | |
| sp.cursor_x, sp.cursor_y, sp.pellet_index, sp.fallback_timer, sp.fallback_param | |
| )?; | |
| write_indent(w, i)?; | |
| write!(w, "weapon_data =")?; | |
| for (j, v) in self.weapon_data.iter().enumerate() { | |
| if j % 16 == 0 { | |
| writeln!(w)?; | |
| write_indent(w, i + 1)?; | |
| } | |
| write!(w, " {:08X}", v)?; | |
| } | |
| writeln!(w)?; | |
| write_indent(w, i)?; | |
| write!(w, "render_data =")?; | |
| for (j, v) in self.render_data.iter().enumerate() { | |
| if j % 16 == 0 { | |
| writeln!(w)?; | |
| write_indent(w, i + 1)?; | |
| } | |
| write!(w, " {:08X}", v)?; | |
| } | |
| writeln!(w)?; | |
| write_indent(w, i)?; | |
| writeln!(w, "launch_speed_raw = {}", self.launch_speed_raw)?; | |
| write_indent(w, i)?; | |
| writeln!(w, "homing_enabled = {}", self.homing_enabled)?; | |
| write_indent(w, i)?; | |
| writeln!(w, "direction = {}", self.direction)?; | |
| // Unknown regions | |
| write_indent(w, i)?; | |
| writeln!(w, "_unknown_fc ({} bytes):", self._unknown_fc.len())?; | |
| write_raw_region(w, self._unknown_fc.as_ptr(), self._unknown_fc.len(), i + 1)?; | |
| write_indent(w, i)?; | |
| writeln!(w, "_unknown_37c ({} bytes):", self._unknown_37c.len())?; | |
| write_raw_region( | |
| w, | |
| self._unknown_37c.as_ptr(), | |
| self._unknown_37c.len(), | |
| i + 1, | |
| )?; | |
| write_indent(w, i)?; | |
| writeln!(w, "_unknown_3cc ({} bytes):", self._unknown_3cc.len())?; | |
| write_raw_region( | |
| w, | |
| self._unknown_3cc.as_ptr(), | |
| self._unknown_3cc.len(), | |
| i + 1, | |
| )?; | |
| Ok(()) | |
| } | |
| } | |