fix: pad team names in replay log to match original WA formatting
Browse filesThe original WA pads quoted team names to the longest name width so
that [CPU X.XX] brackets align across all teams. Our replay loader
was missing this padding, causing log comparison failures with 6-team
replays where team names have different lengths.
Also adds bots2 replay test (6-team CPU torture test with custom scheme).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
crates/openwa-wormkit/src/replacements/replay.rs
CHANGED
|
@@ -700,9 +700,10 @@ unsafe fn write_replay_log(gi: *const GameInfo, log_file: &mut File) -> Result<(
|
|
| 700 |
wa_load_string(0x25),
|
| 701 |
];
|
| 702 |
|
| 703 |
-
// Find max color name length
|
| 704 |
let teams = rb(va::G_TEAM_DATA) as *const ReplayTeamEntry;
|
| 705 |
let mut max_color_len = 0usize;
|
|
|
|
| 706 |
for slot in 0..6usize {
|
| 707 |
let team = &*teams.add(slot);
|
| 708 |
if team.flag == 0 { continue; }
|
|
@@ -711,6 +712,8 @@ unsafe fn write_replay_log(gi: *const GameInfo, log_file: &mut File) -> Result<(
|
|
| 711 |
let len = c_strlen(color_names[ci]);
|
| 712 |
if len > max_color_len { max_color_len = len; }
|
| 713 |
}
|
|
|
|
|
|
|
| 714 |
}
|
| 715 |
|
| 716 |
for slot in 0..6usize {
|
|
@@ -741,10 +744,14 @@ unsafe fn write_replay_log(gi: *const GameInfo, log_file: &mut File) -> Result<(
|
|
| 741 |
let _ = s.push(' ');
|
| 742 |
}
|
| 743 |
|
| 744 |
-
// Quoted team name
|
| 745 |
let _ = s.push('"');
|
| 746 |
push_cstr(&mut s, team_name);
|
| 747 |
let _ = s.push('"');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 748 |
|
| 749 |
// Team type info
|
| 750 |
if (team_type as i32) < 0 {
|
|
|
|
| 700 |
wa_load_string(0x25),
|
| 701 |
];
|
| 702 |
|
| 703 |
+
// Find max color name length and max team name length for alignment
|
| 704 |
let teams = rb(va::G_TEAM_DATA) as *const ReplayTeamEntry;
|
| 705 |
let mut max_color_len = 0usize;
|
| 706 |
+
let mut max_name_len = 0usize;
|
| 707 |
for slot in 0..6usize {
|
| 708 |
let team = &*teams.add(slot);
|
| 709 |
if team.flag == 0 { continue; }
|
|
|
|
| 712 |
let len = c_strlen(color_names[ci]);
|
| 713 |
if len > max_color_len { max_color_len = len; }
|
| 714 |
}
|
| 715 |
+
let name_len = c_strlen(team.config_abbrev.as_ptr());
|
| 716 |
+
if name_len > max_name_len { max_name_len = name_len; }
|
| 717 |
}
|
| 718 |
|
| 719 |
for slot in 0..6usize {
|
|
|
|
| 744 |
let _ = s.push(' ');
|
| 745 |
}
|
| 746 |
|
| 747 |
+
// Quoted team name, padded to align [CPU ...] brackets
|
| 748 |
let _ = s.push('"');
|
| 749 |
push_cstr(&mut s, team_name);
|
| 750 |
let _ = s.push('"');
|
| 751 |
+
let name_len = c_strlen(team_name);
|
| 752 |
+
for _ in 0..max_name_len.saturating_sub(name_len) {
|
| 753 |
+
let _ = s.push(' ');
|
| 754 |
+
}
|
| 755 |
|
| 756 |
// Team type info
|
| 757 |
if (team_type as i32) < 0 {
|
testdata/replays/bots2.WAgame
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bb3528c8bab983236ebc2d8085698ec2a42f353426aaf31ec01d3c0246b50996
|
| 3 |
+
size 58533
|
testdata/replays/bots2_expected.log
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5a02dc3e6b935fe76b0e71dd8e9ea70c9932eb3f580c8ce740e8a9cd273e4545
|
| 3 |
+
size 10067
|