tile content iterator with runstate tweak - returns optional runstate
This commit is contained in:
parent
012d61603a
commit
76cc6a6938
4 changed files with 12 additions and 12 deletions
|
|
@ -44,7 +44,7 @@ extern crate lazy_static;
|
||||||
//Consts
|
//Consts
|
||||||
pub const SHOW_MAPGEN: bool = false;
|
pub const SHOW_MAPGEN: bool = false;
|
||||||
pub const LOG_SPAWNING: bool = true;
|
pub const LOG_SPAWNING: bool = true;
|
||||||
pub const LOG_TICKS: bool = true;
|
pub const LOG_TICKS: bool = false;
|
||||||
|
|
||||||
#[derive(PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
pub enum RunState {
|
pub enum RunState {
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,9 @@ pub fn tile_opaque(tt: TileType) -> bool {
|
||||||
|
|
||||||
pub fn tile_cost(tt: TileType) -> f32 {
|
pub fn tile_cost(tt: TileType) -> f32 {
|
||||||
match tt {
|
match tt {
|
||||||
TileType::Road => 0.8,
|
TileType::Road => 0.5,
|
||||||
TileType::Grass => 1.1,
|
TileType::Grass => 1.1,
|
||||||
TileType::ShallowWater => 1.2,
|
TileType::ShallowWater => 1.3,
|
||||||
_ => 1.0,
|
_ => 1.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 mut doors = ecs.write_storage::<Door>();
|
||||||
let names = ecs.read_storage::<Name>();
|
let names = ecs.read_storage::<Name>();
|
||||||
let mut swap_entities: Vec<(Entity, i32, i32)> = Vec::new();
|
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() {
|
for (entity, _player, pos, viewshed) in (&entities, &mut players, &mut positions, &mut viewsheds).join() {
|
||||||
if pos.x + delta_x < 0
|
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 < 0
|
||||||
|| pos.y + delta_y > map.height - 1
|
|| 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);
|
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) {
|
if let Some(name) = names.get(potential_target) {
|
||||||
gamelog::Logger::new().append("The").item_name(&name.name).append("is in your way.").log();
|
gamelog::Logger::new().append("The").item_name(&name.name).append("is in your way.").log();
|
||||||
}
|
}
|
||||||
return None;
|
return Some(RunState::AwaitingInput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return None;
|
return None;
|
||||||
});
|
});
|
||||||
|
|
||||||
if result == RunState::Ticking {
|
if result.is_some() {
|
||||||
return result;
|
return result.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if swap_entities.len() <= 0 {
|
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 RunState::Ticking;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return RunState::AwaitingInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_item(ecs: &mut World) -> RunState {
|
fn get_item(ecs: &mut World) -> RunState {
|
||||||
|
|
|
||||||
|
|
@ -103,17 +103,17 @@ where
|
||||||
|
|
||||||
/// Calls a function on every entity within a given tile idx, with the
|
/// Calls a function on every entity within a given tile idx, with the
|
||||||
/// added ability to return a RunState mid-calc.
|
/// 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
|
where
|
||||||
F: FnMut(Entity) -> Option<RunState>,
|
F: FnMut(Entity) -> Option<RunState>,
|
||||||
{
|
{
|
||||||
let lock = SPATIAL_MAP.lock().unwrap();
|
let lock = SPATIAL_MAP.lock().unwrap();
|
||||||
for entity in lock.tile_content[idx].iter() {
|
for entity in lock.tile_content[idx].iter() {
|
||||||
if let Some(rs) = f(entity.0) {
|
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
|
/// Calls a function on every entity within a given tile idx, breaking if
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue