Skip to content

Commit

Permalink
Always use start location's owner information, even if it isn't expli…
Browse files Browse the repository at this point in the history
…citly marked as valid.
  • Loading branch information
tec27 committed Mar 15, 2024
1 parent da4755f commit 0ff1301
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 45 deletions.
88 changes: 44 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions broodmap/src/chk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,22 @@ mod tests {
);
}

#[test]
fn start_locations_have_owners() {
let result = assert_ok!(Chk::from_bytes(LT_CHK.into(), None));
let placed_units = assert_ok!(result.placed_units());

let start_locations = placed_units
.iter()
.filter(|u| u.unit_id == 214)
.collect::<Vec<_>>();
assert_eq!(start_locations.len(), 4);
assert_eq!(start_locations[0].owner, Some(2));
assert_eq!(start_locations[1].owner, Some(3));
assert_eq!(start_locations[2].owner, Some(0));
assert_eq!(start_locations[3].owner, Some(1));
}

const KOR_1: &[u8] = include_bytes!("../../assets/kor_encoding/1.chk");
const KOR_2: &[u8] = include_bytes!("../../assets/kor_encoding/2.chk");
const KOR_3: &[u8] = include_bytes!("../../assets/kor_encoding/3.chk");
Expand Down
9 changes: 8 additions & 1 deletion broodmap/src/chk/placed_units.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use bitflags::bitflags;
use thiserror::Error;

const START_LOCATION_ID: u16 = 214;

#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct UnitInstanceId(pub u32);

Expand Down Expand Up @@ -74,7 +76,12 @@ pub fn read_placed_units(data: &[u8]) -> Result<Vec<PlacedUnit>, PlacedUnitsErro
chunk[14..16].try_into().unwrap(),
));

let owner = if valid_data.contains(ValidUnitData::OWNER) {
// NOTE(tec27): On melee maps (and maybe others?) the start location is often marked as
// not having a valid owner, but start locations *must* have a valid owner, so we always
// utilize this field for them. The description of this value of ValidUnitData may be
// incorrect, further research is needed.
let owner = if valid_data.contains(ValidUnitData::OWNER) || unit_id == START_LOCATION_ID
{
Some(chunk[16])
} else {
None
Expand Down

0 comments on commit 0ff1301

Please sign in to comment.