use anput::{actor::Actor, universe::Universe};
use std::error::Error;
#[derive(Debug, Default, Clone, Copy)]
struct Gold(pub usize);
fn main() -> Result<(), Box<dyn Error>> {
let mut universe = Universe::default();
let eldoria = Actor::spawn(&mut universe.simulation, ("Eldoria", Gold(1000)))?;
let thalnar = Actor::spawn(&mut universe.simulation, ("Thalnar", Gold(230)))?;
let virella = Actor::spawn(&mut universe.simulation, ("Virella", Gold(50)))?;
eldoria.add_child::<true>(&mut universe.simulation, thalnar)?;
eldoria.add_child::<true>(&mut universe.simulation, virella)?;
{
let mut collected_money = 0;
for city in eldoria.children::<true>(&universe.simulation) {
let mut gold = city.component_mut::<true, Gold>(&universe.simulation)?;
let tax = gold.0 / 10;
collected_money += tax;
gold.0 -= tax;
}
let mut gold = eldoria.component_mut::<true, Gold>(&universe.simulation)?;
gold.0 += collected_money;
}
for (name, gold) in universe.simulation.query::<true, (&&'static str, &Gold)>() {
println!("City {:?} has {} gold", name, gold.0);
}
Ok(())
}