7 Hour Roguelike, spring 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

use rogue_engine::world::entity::{Entity, Hp, Observation, Action, ECLS_PROTAG, DamageDesc, DamageKind, ai::violence_toward};
use rogue_util::coord::V2i;
use std::rc::Rc;
macro_rules! make_entity {
($name:ident, { $( $field:tt ),* }, { $( $methods:tt )* }) => {
#[derive(Debug)]
pub struct $name {
pos: V2i,
hp: Hp,
time: usize,
$( $field ),*
}
impl Entity for $name {
fn pos(&self) -> V2i { self.pos }
fn set_pos(&mut self, pos: V2i) { self.pos = pos; }
fn next_time(&self) -> usize { self.time }
fn set_next_time(&mut self, time: usize) { self.time = time; }
fn hp(&self) -> Hp { self.hp }
fn set_hp(&mut self, hp: Hp) { self.hp = hp; }
$( $methods )*
}
}
}
make_entity!(Prowler, {}, {
fn act<'w>(&mut self, obs: &Observation<'w>) -> Action {
violence_toward(self.pos, obs, |ent| ent.borrow().class() & ECLS_PROTAG != 0, |ent| {
Rc::new(vec![DamageDesc{ kind: DamageKind::Phys, base: 6, add: 6 }])
})
}
});
impl Prowler {
pub fn new(pos: V2i) -> Self {
Prowler {
pos,
hp: 50,
time: 0,
}
}
}