diff --git a/config.toml b/config.toml index 0acfd90..d96bbfc 100644 --- a/config.toml +++ b/config.toml @@ -1,9 +1,9 @@ -initial_chunk_radius = 8 +initial_chunk_radius = 5 [display] vsync = "mailbox" [spawn_counts] -dorfs = 5 +dorfs = 50 pigs = 5 rabbits = 5 \ No newline at end of file diff --git a/src/entities/livestock/rabbit.rs b/src/entities/livestock/rabbit.rs index 7cc7006..8de484c 100644 --- a/src/entities/livestock/rabbit.rs +++ b/src/entities/livestock/rabbit.rs @@ -1,19 +1,44 @@ use crate::config::GameConfig; +use crate::constants::ITILE_SIZE; use crate::constants::TILE_SIZE; use crate::constants::*; use crate::entities::shared_components::Ambulatory; use crate::game::SpawnDelay; +use crate::world::tiles::visibility::TileOcclusionEvent; +use crate::world::tiles::{TileChangedEvent, TileMap}; use crate::world::VisibleGameEntity; use bevy::prelude::*; use bevy_rand::prelude::*; use rand::RngExt; +/// How often (in seconds) a rabbit digs. +/// 5 seconds at normal speed — slow enough to observe, fast enough to test. +pub const DIG_INTERVAL_SECS: f32 = 5.0; + +/// Tracks time until next dig action. Debug component — rabbits dig to demonstrate +/// the TileChangedEvent + path invalidation pipeline. Remove or replace when +/// real digging mechanics are implemented. +#[derive(Component)] +pub struct RabbitDigTimer { + /// Seconds remaining until next dig. Reset to DIG_INTERVAL_SECS after each dig. + pub secs_remaining: f32, +} + +impl Default for RabbitDigTimer { + fn default() -> Self { + Self { + secs_remaining: DIG_INTERVAL_SECS, + } + } +} + #[derive(Bundle)] pub struct Rabbit { ambulatory: Ambulatory, sprite: Sprite, transform: Transform, visibility: Visibility, + dig_timer: RabbitDigTimer, } impl Rabbit { @@ -36,6 +61,7 @@ impl Rabbit { }, transform: Transform::from_translation(position).with_scale(Vec3::splat(PIXEL_RATIO)), visibility: Visibility::Hidden, + dig_timer: RabbitDigTimer::default(), } } } @@ -77,3 +103,34 @@ pub fn spawn_rabbits( } } } + +/// Debug system: rabbits periodically dig the floor tile beneath them. +/// +/// Removes the FloorTileData at the tile directly below the rabbit's current +/// z-level. Also clears the corresponding ChunkData bits via TileMap::remove_floor. +/// Fires TileChangedEvent so path invalidation reacts automatically. +pub fn rabbit_dig_system( + mut query: Query<(&Transform, &mut RabbitDigTimer)>, + mut tilemap: ResMut, + mut tile_changed: MessageWriter, + mut occlusion: MessageWriter, + time: Res