Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub trait Cond {
- fn is_satisfied(&self, memory: &Memory) -> bool;
- fn set_id(&mut self, id: &usize);
- fn get_id(&self) -> usize;
- fn get_name(&self) -> String;
- }
- impl PartialEq for Cond {
- fn eq(&self, other: &Cond) -> bool {
- self.get_id() == other.get_id()
- }
- }
- //ignore
- pub struct Memory {
- has_target: bool,
- target: String,
- has_weapon: bool,
- free_weapon: usize,
- player_is_dead: bool,
- }
- struct HasTarget {
- id: usize,
- }
- impl HasTarget {
- fn new() -> HasTarget {
- HasTarget {
- id: 0,
- }
- }
- }
- impl Cond for HasTarget {
- fn get_name(&self) -> String {
- "HasTarget".to_string()
- }
- fn is_satisfied(&self, memory: &Memory) -> bool {
- memory.has_target
- }
- fn set_id(&mut self, id: &usize) {
- self.id = id.clone()
- }
- fn get_id(&self) -> usize {
- self.id.clone()
- }
- }
- struct HasWeapon {
- id: usize,
- }
- impl HasWeapon {
- fn new() -> HasTarget {
- HasTarget {
- id: 0,
- }
- }
- }
- impl Cond for HasWeapon {
- fn get_name(&self) -> String {
- "HasWeapon".to_string()
- }
- fn is_satisfied(&self, memory: &Memory) -> bool {
- memory.has_weapon
- }
- fn set_id(&mut self, id: &usize) {
- self.id = id.clone()
- }
- fn get_id(&self) -> usize {
- self.id.clone()
- }
- }
- struct PlayerDead {
- id: usize,
- }
- impl PlayerDead {
- fn new() -> HasTarget {
- HasTarget {
- id: 0,
- }
- }
- }
- impl Cond for PlayerDead {
- fn get_name(&self) -> String {
- "PlayerDead".to_string()
- }
- fn is_satisfied(&self, memory: &Memory) -> bool {
- memory.player_is_dead
- }
- fn set_id(&mut self, id: &usize) {
- self.id = id.clone()
- }
- fn get_id(&self) -> usize {
- self.id.clone()
- }
- }
- fn main() {
- let mut conds: Vec<Box<Cond>> = vec![
- Box::new(PlayerDead::new()),
- Box::new(HasTarget::new()),
- Box::new(HasWeapon::new()),
- ];
- for cond in conds.iter() {
- //why are the names the same???
- println!("{}", cond.get_name());
- }
- }
Add Comment
Please, Sign In to add comment