From addce5d725c6e79d46e0d098b6f60d8a3365cb88 Mon Sep 17 00:00:00 2001 From: InfinityDevTech <47366052+InfinityDevTech@users.noreply.github.com> Date: Sun, 19 May 2024 22:43:39 -0400 Subject: [PATCH] Remove unnecessary memory stuff from miner formulation. Remove unused imports. --- src/room/creeps/local/hauler.rs | 6 +++--- src/room/creeps/local/source_miner.rs | 7 +++---- src/room/creeps/local/upgrader.rs | 3 +-- src/room/creeps/organizer.rs | 2 +- src/room/democracy.rs | 8 +++----- src/room/planning/creep/miner.rs | 18 +++++------------- src/room/planning/room/mod.rs | 2 +- src/room/planning/room/resources.rs | 4 ++-- src/room/tower.rs | 2 +- src/traits/creep.rs | 2 +- 10 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/room/creeps/local/hauler.rs b/src/room/creeps/local/hauler.rs index b027704..aa35e8b 100644 --- a/src/room/creeps/local/hauler.rs +++ b/src/room/creeps/local/hauler.rs @@ -1,17 +1,17 @@ use std::cmp::min; use screeps::{ - find, game, Creep, HasPosition, ResourceType, SharedCreepProperties, Structure, StructureObject, + find, game, Creep, HasPosition, ResourceType, SharedCreepProperties, StructureObject, }; use crate::{ - memory::{CreepMemory, Role, ScreepsMemory}, + memory::{CreepMemory, ScreepsMemory}, traits::creep::CreepExtensions, }; pub fn run_creep(creep: &Creep, memory: &mut ScreepsMemory) { let creep_memory = memory.get_creep_mut(&creep.name()); - let needs_energy = creep_memory.n_e.unwrap_or(false); + let _needs_energy = creep_memory.n_e.unwrap_or(false); if creep.store().get_free_capacity(Some(ResourceType::Energy)) > 0 { get_energy(creep, creep_memory); diff --git a/src/room/creeps/local/source_miner.rs b/src/room/creeps/local/source_miner.rs index 5afacc9..1152b33 100644 --- a/src/room/creeps/local/source_miner.rs +++ b/src/room/creeps/local/source_miner.rs @@ -1,9 +1,8 @@ use std::str::FromStr; -use log::info; -use screeps::{game, Creep, ErrorCode, HasPosition, Part, ResourceType, RoomName, SharedCreepProperties, Source}; +use screeps::{game, Creep, HasPosition, Part, ResourceType, RoomName, SharedCreepProperties, Source}; -use crate::{memory::{CreepMemory, RoomMemory, ScreepsMemory}, room::structure_cache::RoomStructureCache, traits::{creep::CreepExtensions, room::RoomExtensions}}; +use crate::{memory::{CreepMemory, RoomMemory, ScreepsMemory}, room::structure_cache::RoomStructureCache, traits::creep::CreepExtensions}; pub fn run_creep(creep: &Creep, memory: &mut ScreepsMemory, structures: &RoomStructureCache) { @@ -65,7 +64,7 @@ fn link_deposit(creep: &Creep, creep_memory: &CreepMemory, room_memory: &RoomMem } return false; } - return false; + false } fn drop_deposit(creep: &Creep, creep_memory: &mut CreepMemory, structures: &RoomStructureCache) { diff --git a/src/room/creeps/local/upgrader.rs b/src/room/creeps/local/upgrader.rs index c209539..6d6fa66 100644 --- a/src/room/creeps/local/upgrader.rs +++ b/src/room/creeps/local/upgrader.rs @@ -1,9 +1,8 @@ -use log::info; use screeps::{find, Creep, ErrorCode, HasPosition, ResourceType, SharedCreepProperties}; use crate::{memory::ScreepsMemory, room::structure_cache::RoomStructureCache, traits::creep::CreepExtensions}; -pub fn run_creep(creep: &Creep, memory: &mut ScreepsMemory, structure_cache: &RoomStructureCache) { +pub fn run_creep(creep: &Creep, memory: &mut ScreepsMemory, _structure_cache: &RoomStructureCache) { let creep_memory = memory.get_creep_mut(creep.name().as_str()); let needs_energy = creep_memory.n_e.unwrap_or(false); diff --git a/src/room/creeps/organizer.rs b/src/room/creeps/organizer.rs index 9eb5d9b..d83ed25 100644 --- a/src/room/creeps/organizer.rs +++ b/src/room/creeps/organizer.rs @@ -1,7 +1,7 @@ use log::info; use screeps::{game, Room}; -use crate::{memory::{Role, ScreepsMemory}, room::structure_cache::{self, RoomStructureCache}, traits::creep::CreepExtensions}; +use crate::{memory::{Role, ScreepsMemory}, room::structure_cache::RoomStructureCache, traits::creep::CreepExtensions}; use super::local; diff --git a/src/room/democracy.rs b/src/room/democracy.rs index dbaa11f..9c7aa9a 100644 --- a/src/room/democracy.rs +++ b/src/room/democracy.rs @@ -1,11 +1,9 @@ use log::info; -use screeps::{Part, - Room} -; +use screeps::Room; -use crate::{memory::{CreepMemory, Role, ScreepsMemory}, room::{creeps::organizer, structure_cache::RoomStructureCache}, traits::room::RoomExtensions, utils::role_to_name}; +use crate::{memory::ScreepsMemory, room::{creeps::organizer, structure_cache::RoomStructureCache}}; -use super::{creeps, planning::creep::miner::formulate_miner, tower}; +use super::{planning::creep::miner::formulate_miner, tower}; pub fn start_government(room: Room, memory: &mut ScreepsMemory) { info!("[GOVERNMENT] Starting government for room: {}", room.name()); diff --git a/src/room/planning/creep/miner.rs b/src/room/planning/creep/miner.rs index 5095415..4b3bbe2 100644 --- a/src/room/planning/creep/miner.rs +++ b/src/room/planning/creep/miner.rs @@ -1,7 +1,7 @@ use std::cmp; use log::info; -use screeps::{look, ErrorCode, HasPosition, Part, Room, StructureSpawn}; +use screeps::{Part, Room, StructureSpawn}; use crate::{memory::{CreepMemory, Role, ScreepsMemory}, traits::room::RoomExtensions, utils::role_to_name}; @@ -9,7 +9,7 @@ pub fn formulate_miner(room: &Room, memory: &mut ScreepsMemory, spawn: Structure let mut cost = 0; let mut parts = Vec::new(); - let mut room_memory = memory.get_room_mut(&room.name()); + let room_memory = memory.get_room_mut(&room.name()); let needed = room.get_target_for_miner(&room_memory.clone()); @@ -56,7 +56,9 @@ pub fn formulate_miner(room: &Room, memory: &mut ScreepsMemory, spawn: Structure let spawn_result = spawn.spawn_creep(&parts, &name); if spawn_result.is_ok() { - info!(" [Spawn] Successfully spawned a miner!"); + + info!(" [SPANWER] Spawned a new miner!"); + let cmemory = CreepMemory { r: crate::memory::Role::Miner, n_e: Some(true), @@ -66,22 +68,12 @@ pub fn formulate_miner(room: &Room, memory: &mut ScreepsMemory, spawn: Structure p: None, }; - info!(" Creating creep memory for {}", name); - memory.create_creep(&room.name_str(), &name, &cmemory); let room_memory = memory.get_room_mut(&room.name()); room_memory.creeps_manufactured += 1; - info!(" Before: {:?}", room_memory.sources.get(needed.unwrap() as usize).unwrap()); room_memory.sources.get_mut(needed.unwrap() as usize).unwrap().work_parts += parts.len() as u8 - 3; room_memory.sources.get_mut(needed.unwrap() as usize).unwrap().assigned_creeps += 1; - info!(" After: {:?}", room_memory.sources.get(needed.unwrap() as usize).unwrap()); - - memory.write_memory(); - info!(" Wrote Memory"); - - let mem_test = ScreepsMemory::init_memory(); - info!(" Memory: {:?}", mem_test.get_room(&room.name()).sources.get(needed.unwrap() as usize).unwrap()); } } diff --git a/src/room/planning/room/mod.rs b/src/room/planning/room/mod.rs index ee80479..fc1914c 100644 --- a/src/room/planning/room/mod.rs +++ b/src/room/planning/room/mod.rs @@ -27,5 +27,5 @@ pub fn plan_room(room: &Room, memory: &mut ScreepsMemory) -> bool { room_memory.sources = sources; memory.create_room(&room.name(), &room_memory); - return true; + true } \ No newline at end of file diff --git a/src/room/planning/room/resources.rs b/src/room/planning/room/resources.rs index 5f46bc0..526b8da 100644 --- a/src/room/planning/room/resources.rs +++ b/src/room/planning/room/resources.rs @@ -1,6 +1,6 @@ -use screeps::{find, look::{self, LookResult}, HasId, HasPosition, ObjectId, Room, Source, Terrain}; +use screeps::{find, look::{self, LookResult}, HasId, HasPosition, Room, Terrain}; -use crate::memory::{ScoutedSource, ScreepsMemory}; +use crate::memory::ScoutedSource; pub fn find_sources(room: &Room) -> Vec { let mut planned_sources = Vec::new(); diff --git a/src/room/tower.rs b/src/room/tower.rs index 1bd00ed..e852724 100644 --- a/src/room/tower.rs +++ b/src/room/tower.rs @@ -1,4 +1,4 @@ -use screeps::{Room, find, StructureType, StructureProperties, StructureObject}; +use screeps::{Room, find}; use super::structure_cache::RoomStructureCache; diff --git a/src/traits/creep.rs b/src/traits/creep.rs index daea5b2..b27f214 100644 --- a/src/traits/creep.rs +++ b/src/traits/creep.rs @@ -1,5 +1,5 @@ use log::info; -use screeps::{HasPosition, MoveToOptions, Position, SharedCreepProperties}; +use screeps::{HasPosition, Position}; use crate::{ memory::CreepMemory,