Skip to content

Commit

Permalink
re-introduce trees aging
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmut committed Apr 7, 2024
1 parent d90ef82 commit 50f370e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
1 change: 0 additions & 1 deletion logic/src/screen/draw_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ pub fn hitbox_offset_square() -> PixelPosition {
mod tests {
use super::*;


#[test]
fn transparency_border_no_offset() {
let min_cell = CellIndex::new(-5, -25, -55);
Expand Down
9 changes: 8 additions & 1 deletion logic/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use robots::Robot;

use crate::screen::gui::gui_actions::GuiActions;
use crate::world::game_state::{DEFAULT_ADVANCING_FLUIDS, DEFAULT_PROFILE_ENABLED};
use crate::world::map::cell::{transition_aging_tile};
use crate::world::map::cell::{ages, transition_aging_tile};
use crate::world::map::{Cell, TileType};

type AgeInMinutes = i64;
Expand Down Expand Up @@ -187,6 +187,13 @@ impl World {
transformation.apply(&mut cell_copy);
if self.networks.add(pos_to_transform, cell_copy.tile_type) {
*cell = cell_copy;
if ages(cell.tile_type) {
self.aging_tiles.insert(pos_to_transform);
self.life.insert(pos_to_transform);
} else {
self.aging_tiles.remove(&pos_to_transform);
self.life.remove(&pos_to_transform);
}
} else {
remaining.insert(pos_to_transform);
}
Expand Down
31 changes: 31 additions & 0 deletions logic/src/world/gameplay_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ mod game_goal_state_transition_tests {
#[cfg(test)]
mod building_tests {
use crate::screen::gui::GuiActions;
use crate::world::map::cell::DEFAULT_HEALTH;
use crate::world::map::transform_cells::Transformation;
use crate::world::map::{CellIndex, TileType};
use crate::world::{TransformationTask, World};
Expand Down Expand Up @@ -189,4 +190,34 @@ mod building_tests {
world.update(GuiActions::default());
assert_eq!(world.map.get_cell(cell).tile_type, from_tile);
}

#[test]
fn test_trees_degrade() {
let mut world = World::new();
world.game_state.set_advance_every_frame();
let cell = world.map.get_ship_position().unwrap() + CellIndex::new(0, 0, 1);
let from_tile = TileType::FloorDirt;
let to_tile = TileType::TreeHealthy;
assert_eq!(world.map.get_cell(cell).tile_type, from_tile);

let gui_actions = gui_action_transform_tile(cell, to_tile);
world.update(gui_actions);
assert_eq!(world.map.get_cell(cell).tile_type, to_tile);
for _ in 0..DEFAULT_HEALTH {
world.update(GuiActions::default());
}
assert_eq!(world.map.get_cell(cell).tile_type, TileType::TreeSparse);
for _ in 0..DEFAULT_HEALTH {
world.update(GuiActions::default());
}
assert_eq!(world.map.get_cell(cell).tile_type, TileType::TreeDying);
for _ in 0..DEFAULT_HEALTH {
world.update(GuiActions::default());
}
assert_eq!(world.map.get_cell(cell).tile_type, TileType::TreeDead);
for _ in 0..DEFAULT_HEALTH {
world.update(GuiActions::default());
}
assert_eq!(world.map.get_cell(cell).tile_type, TileType::TreeDead);
}
}

0 comments on commit 50f370e

Please sign in to comment.