Skip to content

Commit 1ee698b

Browse files
committed
pathfinder.rs: tile_cost: Fixed unit_class assert
1 parent c316ae4 commit 1ee698b

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

src/core/src/pathfinder.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ pub fn max_cost() -> MovePoints {
7272
pub fn tile_cost<S: GameState>(db: &Db, state: &S, unit: &Unit, from: &ExactPos, pos: &ExactPos)
7373
-> MovePoints
7474
{
75-
let unit_type = db.unit_type(&unit.type_id);
7675
let map_pos = &pos.map_pos;
7776
let objects = state.objects_at(map_pos);
7877
let units = state.units_at(map_pos);
@@ -82,10 +81,8 @@ pub fn tile_cost<S: GameState>(db: &Db, state: &S, unit: &Unit, from: &ExactPos,
8281
for object in &objects {
8382
match object.pos.slot_id {
8483
SlotId::Id(_) => if unit.pos == object.pos {
85-
// assert_eq!(unit_type.class, UnitClass::Infantry); // TODO
86-
if unit_type.class != UnitClass::Infantry {
87-
println!("WARNING: non-infantry unit in small object: {:#?}", unit);
88-
}
84+
let unit_class = db.unit_type(&unit.type_id).class;
85+
assert_eq!(unit_class, UnitClass::Infantry);
8986
break 'unit_loop;
9087
},
9188
SlotId::TwoTiles(_) | SlotId::WholeTile => {
@@ -95,6 +92,7 @@ pub fn tile_cost<S: GameState>(db: &Db, state: &S, unit: &Unit, from: &ExactPos,
9592
}
9693
unit_cost += 1;
9794
}
95+
let unit_type = db.unit_type(&unit.type_id);
9896
let tile = state.map().tile(&pos);
9997
let mut terrain_cost = match unit_type.class {
10098
UnitClass::Infantry => match *tile {

src/core/src/unit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use ::{ReactionFireMode, MovePoints, AttackPoints, UnitId, PlayerId, ExactPos};
22

3-
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash, Clone, Debug)]
3+
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash, Clone, Copy, Debug)]
44
pub struct UnitTypeId{pub id: i32}
55

6-
#[derive(Clone, PartialEq, Debug)]
6+
#[derive(Clone, Copy, PartialEq, Debug)]
77
pub enum UnitClass {
88
Infantry,
99
Vehicle,
@@ -36,7 +36,7 @@ pub struct WeaponType {
3636
pub reaction_fire: bool,
3737
}
3838

39-
#[derive(Clone, Debug)]
39+
#[derive(Clone, Copy, Debug)]
4040
pub struct WeaponTypeId{pub id: i32}
4141

4242
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)