td

tower.rs at trunk
Login

tower.rs at trunk

File src/behavior/tower.rs artifact af3847699e on branch trunk


//! The `TowerBehavior` trait (TP tower modifications). The `Tower` entity lives in
//! `crate::tower`.

use crate::{
    behavior::{dyn_clone_trait, projectile::HitResponse},
    context::{ExpireContext, FireContext, HitContext, TickContext},
    enemy::Enemy,
    world::Projectile,
};

pub trait TowerBehavior: TowerClone + Send + Sync {
    // spawn-shaping: runs once at fire time, can add/modify shots
    fn on_fire(&self, _shots: &mut Vec<Projectile>, _ctx: &FireContext) {}

    // per-projectile events: &mut self so a behavior carries its own counter

    fn on_hit_enemy(
        &mut self,
        _p: &mut Projectile,
        _e: &mut Enemy,
        _c: &mut HitContext,
    ) -> HitResponse {
        HitResponse::PASS
    }
    fn on_hit_wall(&mut self, _p: &mut Projectile, _c: &mut HitContext) -> HitResponse {
        HitResponse::PASS
    }
    fn on_tick(&mut self, _p: &mut Projectile, _c: &mut TickContext) {}
    fn on_expire(&mut self, _p: &mut Projectile, _c: &mut ExpireContext) {}
}

dyn_clone_trait!(TowerClone, TowerBehavior);