tile content iterator with runstate tweak - returns optional runstate

This commit is contained in:
Llywelwyn 2023-08-16 01:45:23 +01:00
parent 012d61603a
commit 76cc6a6938
4 changed files with 12 additions and 12 deletions

View file

@ -44,7 +44,7 @@ extern crate lazy_static;
//Consts
pub const SHOW_MAPGEN: bool = false;
pub const LOG_SPAWNING: bool = true;
pub const LOG_TICKS: bool = true;
pub const LOG_TICKS: bool = false;
#[derive(PartialEq, Copy, Clone)]
pub enum RunState {

View file

@ -51,9 +51,9 @@ pub fn tile_opaque(tt: TileType) -> bool {
pub fn tile_cost(tt: TileType) -> f32 {
match tt {
TileType::Road => 0.8,
TileType::Road => 0.5,
TileType::Grass => 1.1,
TileType::ShallowWater => 1.2,
TileType::ShallowWater => 1.3,
_ => 1.0,
}
}

View file

@ -288,7 +288,7 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState
let mut doors = ecs.write_storage::<Door>();
let names = ecs.read_storage::<Name>();
let mut swap_entities: Vec<(Entity, i32, i32)> = Vec::new();
let mut result = RunState::AwaitingInput;
let mut result: Option<RunState>;
for (entity, _player, pos, viewshed) in (&entities, &mut players, &mut positions, &mut viewsheds).join() {
if pos.x + delta_x < 0
@ -296,7 +296,7 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState
|| pos.y + delta_y < 0
|| pos.y + delta_y > map.height - 1
{
return result;
return RunState::AwaitingInput;
}
let destination_idx = map.xy_idx(pos.x + delta_x, pos.y + delta_y);
@ -335,14 +335,14 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState
if let Some(name) = names.get(potential_target) {
gamelog::Logger::new().append("The").item_name(&name.name).append("is in your way.").log();
}
return None;
return Some(RunState::AwaitingInput);
}
}
return None;
});
if result == RunState::Ticking {
return result;
if result.is_some() {
return result.unwrap();
}
if swap_entities.len() <= 0 {
@ -406,7 +406,7 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState
return RunState::Ticking;
}
}
return result;
return RunState::AwaitingInput;
}
fn get_item(ecs: &mut World) -> RunState {

View file

@ -103,17 +103,17 @@ where
/// Calls a function on every entity within a given tile idx, with the
/// added ability to return a RunState mid-calc.
pub fn for_each_tile_content_with_runstate<F>(idx: usize, mut f: F) -> RunState
pub fn for_each_tile_content_with_runstate<F>(idx: usize, mut f: F) -> Option<RunState>
where
F: FnMut(Entity) -> Option<RunState>,
{
let lock = SPATIAL_MAP.lock().unwrap();
for entity in lock.tile_content[idx].iter() {
if let Some(rs) = f(entity.0) {
return rs;
return Some(rs);
}
}
return RunState::AwaitingInput;
return None;
}
/// Calls a function on every entity within a given tile idx, breaking if