Permalink
Browse files

pathfinder.rs: tile_cost: Fixed unit_class assert

  • Loading branch information...
ozkriff committed Aug 18, 2016
1 parent c316ae4 commit 1ee698bd632ac8810a6aaeb66431cdfa1d9a59f0
Showing with 6 additions and 8 deletions.
  1. +3 −5 src/core/src/pathfinder.rs
  2. +3 −3 src/core/src/unit.rs
@@ -72,7 +72,6 @@ pub fn max_cost() -> MovePoints {
pub fn tile_cost<S: GameState>(db: &Db, state: &S, unit: &Unit, from: &ExactPos, pos: &ExactPos)
-> MovePoints
{
let unit_type = db.unit_type(&unit.type_id);
let map_pos = &pos.map_pos;
let objects = state.objects_at(map_pos);
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,
for object in &objects {
match object.pos.slot_id {
SlotId::Id(_) => if unit.pos == object.pos {
// assert_eq!(unit_type.class, UnitClass::Infantry); // TODO
if unit_type.class != UnitClass::Infantry {
println!("WARNING: non-infantry unit in small object: {:#?}", unit);
}
let unit_class = db.unit_type(&unit.type_id).class;
assert_eq!(unit_class, UnitClass::Infantry);
break 'unit_loop;
},
SlotId::TwoTiles(_) | SlotId::WholeTile => {
@@ -95,6 +92,7 @@ pub fn tile_cost<S: GameState>(db: &Db, state: &S, unit: &Unit, from: &ExactPos,
}
unit_cost += 1;
}
let unit_type = db.unit_type(&unit.type_id);
let tile = state.map().tile(&pos);
let mut terrain_cost = match unit_type.class {
UnitClass::Infantry => match *tile {
View
@@ -1,9 +1,9 @@
use ::{ReactionFireMode, MovePoints, AttackPoints, UnitId, PlayerId, ExactPos};
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash, Clone, Debug)]
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub struct UnitTypeId{pub id: i32}
#[derive(Clone, PartialEq, Debug)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum UnitClass {
Infantry,
Vehicle,
@@ -36,7 +36,7 @@ pub struct WeaponType {
pub reaction_fire: bool,
}
#[derive(Clone, Debug)]
#[derive(Clone, Copy, Debug)]
pub struct WeaponTypeId{pub id: i32}
#[derive(Clone, Debug)]

0 comments on commit 1ee698b

Please sign in to comment.