Skip to content

Commit

Permalink
Back to working version with some cleaning from clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinityDevTech committed Aug 22, 2023
1 parent 419b816 commit d5cc358
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rust-analyzer.linkedProjects": [
"./Cargo.toml"
]
}
2 changes: 1 addition & 1 deletion src/building/roads.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use log::info;
use screeps::{Source, StructureSpawn, HasPosition, pathfinder::{SearchOptions, MultiRoomCostResult, self}, RoomName, LocalCostMatrix, game, StructureType, find, StructureProperties, look, ConstructionSite};
use screeps::{Source, StructureSpawn, HasPosition, pathfinder::{SearchOptions, MultiRoomCostResult, self}, RoomName, LocalCostMatrix, game, StructureType, find, StructureProperties, look};

pub fn source_to_spawn(source: &Source, spawn: &StructureSpawn) {
let opts = SearchOptions::new(road_callback).max_ops(100000000).plain_cost(2).swamp_cost(5).max_rooms(1);
Expand Down
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use movement::creep;
use screeps::ConstructionSite;
use screeps::{
constants::{Part, ResourceType},
enums::StructureObject,
find, game,
local::ObjectId,
objects::{Creep, Source, StructureController},
Expand Down Expand Up @@ -167,17 +166,14 @@ pub fn big_red_button() {
let _ = creep.suicide();
}
for room in game::rooms().values() {
match room.controller() {
Some(controller) => {
if let Some(controller) = room.controller() {
for structure in room.find(find::MY_STRUCTURES, None) {
let _ = structure.destroy();
}
for csite in room.find(find::MY_CONSTRUCTION_SITES, None) {
let _ = csite.remove();
}
let _ = controller.unclaim();
},
None => {},
}
}
let mut memory = memory::ScreepsMemory::init_memory();
Expand Down
2 changes: 1 addition & 1 deletion src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl ScreepsMemory {
pub fn init_memory() -> Self {
let memory_jsstring = screeps::raw_memory::get();
let memory_string = memory_jsstring.as_string().unwrap();
if memory_string == "" {
if memory_string.is_empty() {
let memory = ScreepsMemory {
creeps: HashMap::new(),
rooms: HashMap::new(),
Expand Down
22 changes: 11 additions & 11 deletions src/movement/creep.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use log::info;
use screeps::{game, Direction, HasPosition, Creep, RoomPosition, Position};
use screeps::{game, Direction, HasPosition, Position};

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

Expand Down Expand Up @@ -40,7 +40,7 @@ pub fn move_by_path(creep_name: String, path: Movement, memory: &mut CreepMemory

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.len() == 0 {
if serialized_vec.is_empty() {
memory.set_movement(None);
} else {
memory.set_movement(Some(Movement {
Expand All @@ -55,7 +55,7 @@ pub fn move_by_path(creep_name: String, path: Movement, memory: &mut CreepMemory
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 as f32, y as f32));
points.push((x, y));
cursor = (x, y);
}
}
Expand All @@ -76,13 +76,13 @@ pub fn num_to_dir(num: u8) -> Direction {

pub fn dir_to_coords(dir: Direction, x: f32, y: f32) -> (f32, f32) {
match dir {
Direction::Top => (x, y - 1 as f32),
Direction::TopRight => (x + 1 as f32, y - 1 as f32),
Direction::Right => (x + 1 as f32, y),
Direction::BottomRight => (x + 1 as f32, y + 1 as f32),
Direction::Bottom => (x, y + 1 as f32),
Direction::BottomLeft => (x - 1 as f32, y + 1 as f32),
Direction::Left => (x - 1 as f32, y),
Direction::TopLeft => (x - 1 as f32, y - 1 as f32),
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),
}
}
2 changes: 1 addition & 1 deletion src/movement/move_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl MoveTarget {
if pos.room_name() == cur_pos.room_name() {
match pos.get_direction_to(cur_pos) {
Some(dir) => {
steps.push(Direction::from(-dir));
steps.push(-dir);
}
None => {
warn!("Couldn't get direction to {:?} from {:?}", pos, cur_pos);
Expand Down
10 changes: 3 additions & 7 deletions src/room/local.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use screeps::{Room, find, HasPosition};

use crate::memory::{RoomMemory, self};
use crate::memory::RoomMemory;

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

},
None => {}
if let Some(_creep) = controller.pos().find_closest_by_range(find::MY_CREEPS) {
}
}
},
Expand Down

0 comments on commit d5cc358

Please sign in to comment.