paavohtl Claude Opus 4.6 (1M context) commited on
Commit
ae56671
·
1 Parent(s): a84835c

refactor: name TeamHeader.turn_action_flags, clean up fire_skip_go

Browse files

Identify TeamHeader._unknown_7c as turn_action_flags (u32 bitfield).
Skip Go toggles a bit here to mark the team's turn as skipped.
In game_version > 0x1C the bit toggles; in older versions it only sets.

fire_skip_go now accesses the field via TeamArenaRef::team_header()
instead of raw byte slicing into team_blocks_region.

Verified: headless PASS (byte-identical).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

crates/openwa-core/src/engine/ddgame.rs CHANGED
@@ -1698,8 +1698,11 @@ pub struct TeamHeader {
1698
  pub active_worm: i32,
1699
  /// 0x78: Number of worms on this team.
1700
  pub worm_count: i32,
1701
- /// 0x7C: Unknown.
1702
- pub _unknown_7c: [u8; 4],
 
 
 
1703
  /// 0x80: Alliance ID for ammo/delay table indexing (GetAmmo/AddAmmo/SubtractAmmo).
1704
  /// Teams with the same weapon_alliance share ammo pools. Distinct from
1705
  /// `alliance` at 0x70 which is used by CountTeamsByAlliance.
 
1698
  pub active_worm: i32,
1699
  /// 0x78: Number of worms on this team.
1700
  pub worm_count: i32,
1701
+ /// 0x7C: Per-team turn action flags (bitfield).
1702
+ /// Skip Go (weapon 57) toggles a bit here based on the weapon's fire_params.
1703
+ /// Bit is set to mark the team should skip; in game_version > 0x1C, toggling
1704
+ /// again clears it.
1705
+ pub turn_action_flags: u32,
1706
  /// 0x80: Alliance ID for ammo/delay table indexing (GetAmmo/AddAmmo/SubtractAmmo).
1707
  /// Teams with the same weapon_alliance share ammo pools. Distinct from
1708
  /// `alliance` at 0x70 which is used by CountTeamsByAlliance.
crates/openwa-wormkit/src/replacements/weapon.rs CHANGED
@@ -395,29 +395,30 @@ unsafe fn fire_weapon_special(
395
 
396
  /// Skip Go (subtype 19) — pure Rust replacement for 0x51E8C0.
397
  ///
398
- /// Toggles a bit in the team's arena state flags (first DWORD of each team's
399
- /// region in TeamArenaState). Bit position from weapon entry's fire_params.
400
- /// If game_version > 0x1C and bit already set: clears it. Otherwise: sets it.
401
  unsafe fn fire_skip_go(worm: *const CTaskWorm, entry: *const WeaponEntry) {
 
 
402
  use openwa_core::engine::DDGame;
403
 
404
- let ddgame = &mut *((*worm).base.base.ddgame as *mut DDGame);
405
- let game_version = (*ddgame.game_info).game_version;
406
  let team_index = (*worm).team_index as usize;
407
 
408
  let bit_index = (*entry).fire_params._data[0] & 0x1F;
409
  let bit = 1u32 << bit_index;
410
 
411
- // First DWORD of each team's region in TeamArenaState (stride 0x51C)
412
- let flags_ptr = ddgame.team_arena.team_blocks_region
413
- [team_index * 0x51C..][..4]
414
- .as_ptr() as *mut u32;
415
- let flags = *flags_ptr;
416
 
417
  if game_version > 0x1C && (flags & bit) != 0 {
418
- *flags_ptr = flags & !bit;
419
  } else {
420
- *flags_ptr = flags | bit;
421
  }
422
  }
423
 
 
395
 
396
  /// Skip Go (subtype 19) — pure Rust replacement for 0x51E8C0.
397
  ///
398
+ /// Toggles a bit in the team's `TeamHeader.turn_action_flags` (+0x7C).
399
+ /// Bit position comes from weapon entry's fire_params.
400
+ /// In game_version > 0x1C: toggles (set/clear). Otherwise: always sets.
401
  unsafe fn fire_skip_go(worm: *const CTaskWorm, entry: *const WeaponEntry) {
402
+ use openwa_core::engine::ddgame::TeamArenaRef;
403
+ use openwa_core::engine::ddgame::TeamHeader;
404
  use openwa_core::engine::DDGame;
405
 
406
+ let ddgame = (*worm).base.base.ddgame as *mut DDGame;
407
+ let game_version = (*(*ddgame).game_info).game_version;
408
  let team_index = (*worm).team_index as usize;
409
 
410
  let bit_index = (*entry).fire_params._data[0] & 0x1F;
411
  let bit = 1u32 << bit_index;
412
 
413
+ let arena_ptr = &raw mut (*ddgame).team_arena as u32;
414
+ let arena = TeamArenaRef::from_raw(arena_ptr);
415
+ let header = arena.team_header(team_index) as *const TeamHeader as *mut TeamHeader;
416
+ let flags = (*header).turn_action_flags;
 
417
 
418
  if game_version > 0x1C && (flags & bit) != 0 {
419
+ (*header).turn_action_flags = flags & !bit;
420
  } else {
421
+ (*header).turn_action_flags = flags | bit;
422
  }
423
  }
424