adds some abstractions for readability
This commit is contained in:
parent
65564e6f4c
commit
6d80b80a82
1 changed files with 42 additions and 35 deletions
|
|
@ -87,16 +87,8 @@ impl<'a> System<'a> for EnergySystem {
|
||||||
&positions,
|
&positions,
|
||||||
!&confusion,
|
!&confusion,
|
||||||
).join() {
|
).join() {
|
||||||
let burden_modifier = if let Some(burden) = burdens.get(entity) {
|
let burden_modifier = get_burden_modifier(&burdens, entity);
|
||||||
match burden.level {
|
let overmap_mod = get_overmap_modifier(&map);
|
||||||
BurdenLevel::Burdened => SPEED_MOD_BURDENED,
|
|
||||||
BurdenLevel::Strained => SPEED_MOD_STRAINED,
|
|
||||||
BurdenLevel::Overloaded => SPEED_MOD_OVERLOADED,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
1.0
|
|
||||||
};
|
|
||||||
let overmap_mod = if map.overmap { SPEED_MOD_OVERMAP_TRAVEL } else { 1.0 };
|
|
||||||
// Every entity has a POTENTIAL equal to their speed.
|
// Every entity has a POTENTIAL equal to their speed.
|
||||||
let mut energy_potential: i32 = ((energy.speed as f32) *
|
let mut energy_potential: i32 = ((energy.speed as f32) *
|
||||||
burden_modifier *
|
burden_modifier *
|
||||||
|
|
@ -121,20 +113,12 @@ impl<'a> System<'a> for EnergySystem {
|
||||||
// has enough energy, they take a turn and decrement their energy
|
// has enough energy, they take a turn and decrement their energy
|
||||||
// by TURN_COST. If the current entity is the player, await input.
|
// by TURN_COST. If the current entity is the player, await input.
|
||||||
if energy.current >= TURN_COST {
|
if energy.current >= TURN_COST {
|
||||||
let mut my_turn = true;
|
|
||||||
energy.current -= TURN_COST;
|
energy.current -= TURN_COST;
|
||||||
if entity == *player {
|
if entity == *player {
|
||||||
*runstate = RunState::AwaitingInput;
|
*runstate = RunState::AwaitingInput;
|
||||||
} else {
|
} else if cull_turn_by_distance(&player_pos, pos) {
|
||||||
let distance = DistanceAlg::Pythagoras.distance2d(
|
continue;
|
||||||
*player_pos,
|
|
||||||
Point::new(pos.x, pos.y)
|
|
||||||
);
|
|
||||||
if distance > 20.0 {
|
|
||||||
my_turn = false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if my_turn {
|
|
||||||
turns.insert(entity, TakingTurn {}).expect("Unable to insert turn.");
|
turns.insert(entity, TakingTurn {}).expect("Unable to insert turn.");
|
||||||
if CONFIG.logging.log_ticks {
|
if CONFIG.logging.log_ticks {
|
||||||
let name = if let Some(name) = names.get(entity) {
|
let name = if let Some(name) = names.get(entity) {
|
||||||
|
|
@ -153,5 +137,28 @@ impl<'a> System<'a> for EnergySystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_burden_modifier(burdens: &ReadStorage<Burden>, entity: Entity) -> f32 {
|
||||||
|
return if let Some(burden) = burdens.get(entity) {
|
||||||
|
match burden.level {
|
||||||
|
BurdenLevel::Burdened => SPEED_MOD_BURDENED,
|
||||||
|
BurdenLevel::Strained => SPEED_MOD_STRAINED,
|
||||||
|
BurdenLevel::Overloaded => SPEED_MOD_OVERLOADED,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
1.0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_overmap_modifier(map: &ReadExpect<Map>) -> f32 {
|
||||||
|
return if map.overmap { SPEED_MOD_OVERMAP_TRAVEL } else { 1.0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cull_turn_by_distance(player_pos: &Point, pos: &Position) -> bool {
|
||||||
|
let distance = DistanceAlg::Pythagoras.distance2d(*player_pos, Point::new(pos.x, pos.y));
|
||||||
|
if distance > 20.0 {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue