Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinityDevTech committed Sep 1, 2023
2 parents 2fd8ae2 + d5cc358 commit 4af1ff6
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/movement/creep.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use log::info;
use screeps::{game, Direction, HasPosition, Position};

use crate::memory::{Movement, CreepMemory};

use super::move_target::MoveTarget;

pub fn move_to(creep_name: &String, creep_memory: &mut CreepMemory, target: Position) {
let creep = game::creeps().get(creep_name.to_string()).unwrap();
match &creep_memory.movement {
Some(path) => {
move_by_path(creep_name.to_string(), path.clone(), creep_memory)
}
None => {
let target = MoveTarget {
pos: target,
range: 1,
}.find_path_to(creep.pos());
creep_memory.movement = Some(target.clone());
move_by_path(creep_name.to_string(), target, creep_memory);
}

}
}

pub fn move_by_path(creep_name: String, path: Movement, memory: &mut CreepMemory) {
let creep = game::creeps().get(creep_name).unwrap();

if creep.fatigue() > 0 {
return;
}
let serialized_path = path.path;
let serialized_vec = serialized_path.split("").filter(|x| x != &"").map(|x| x.parse::<u8>().unwrap()).collect::<Vec<u8>>();
let step_dir = num_to_dir(serialized_vec[0]);

match creep.move_direction(step_dir) {
Ok(_) => {},
Err(e) => info!("Creep move failed, {:?}", e),
};

let serialized_vec = serialized_vec[1..].to_vec();
let serialized_path = serialized_vec.iter().map(|x| x.to_string()).collect::<Vec<String>>().join("");
if serialized_vec.is_empty() {
memory.set_movement(None);
} else {
memory.set_movement(Some(Movement {
dest: path.dest,
path: serialized_path,
room: path.room,
}));
}

let mut points = vec![];
let mut cursor = (creep.pos().x().u8() as f32, creep.pos().y().u8() as f32);
for step in serialized_vec {
let dir = num_to_dir(step);
let (x, y) = dir_to_coords(dir, cursor.0, cursor.1);
points.push((x, y));
cursor = (x, y);
}
}

pub fn num_to_dir(num: u8) -> Direction {
match num {
1 => Direction::Top,
2 => Direction::TopRight,
3 => Direction::Right,
4 => Direction::BottomRight,
5 => Direction::Bottom,
6 => Direction::BottomLeft,
7 => Direction::Left,
8 => Direction::TopLeft,
_ => Direction::Top,
}
}

pub fn dir_to_coords(dir: Direction, x: f32, y: f32) -> (f32, f32) {
match dir {
Direction::Top => (x, y - 1_f32),
Direction::TopRight => (x + 1_f32, y - 1_f32),
Direction::Right => (x + 1_f32, y),
Direction::BottomRight => (x + 1_f32, y + 1_f32),
Direction::Bottom => (x, y + 1_f32),
Direction::BottomLeft => (x - 1_f32, y + 1_f32),
Direction::Left => (x - 1_f32, y),
Direction::TopLeft => (x - 1_f32, y - 1_f32),
}
}
16 changes: 16 additions & 0 deletions src/room/local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use screeps::{Room, find, HasPosition};

use crate::memory::RoomMemory;

pub fn run_rom(room: Room, _roommem: RoomMemory) {
let controller = room.controller().unwrap();
match controller.sign() {
Some(sign) => {
if sign.text() != "Ferris FTW!" {
if let Some(_creep) = controller.pos().find_closest_by_range(find::MY_CREEPS) {
}
}
},
None => todo!(),
}
}

0 comments on commit 4af1ff6

Please sign in to comment.