I want to try out rust for a change and I’m very confused.
So evidently I’m very new to rust and don’t really know what I’m doing.
Could someone please show me how to loop through the game map, get the units stability (if there is a unit) and well I know how to remove that unit?
I will build up from there, I just need one example.
Edit:
Nevermind, case closed
Yeah, sure I got the help from @Thorn0906 in a pm after asking him so props to him.
use algo::prelude::*;
use algo::messages::config::UnitInformation;
// The rust interface for UnitInformation is really annoying, so you need to
have these match blocks everywhere
fn stability(t: &UnitInformation) -> f32 {
match *t {
UnitInformation::Wall{stability, ..} => stability,
UnitInformation::Data{stability, ..} => stability,
_ => 0.0, // Remove
}
}
fn repair(state: &mut GameState) {
for x in 0..27 {
for y in 0..14 { // Just on our side of the board
let coord = xy(x, y);
if MAP_BOUNDS.in_arena(coord)
&& state.map().tile(coord).unwrap().get_wall() // This is an Option, there might not be a wall here
.map_or(false, |unit| unit.stability < stability(state.atlas().type_info(unit.unit_type.into())) * 0.5) // Is it under half health?
{
state.tile(coord).unwrap().remove_firewall();
}
}
}
}