Skip to content

Commit

Permalink
Remove unnecessary memory stuff from miner formulation. Remove unused…
Browse files Browse the repository at this point in the history
… imports.
  • Loading branch information
InfinityDevTech committed May 20, 2024
1 parent 61c84b4 commit addce5d
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/room/creeps/local/hauler.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
7 changes: 3 additions & 4 deletions src/room/creeps/local/source_miner.rs
Original file line number Diff line number Diff line change
@@ -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) {

Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/room/creeps/local/upgrader.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/room/creeps/organizer.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
8 changes: 3 additions & 5 deletions src/room/democracy.rs
Original file line number Diff line number Diff line change
@@ -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());
Expand Down
18 changes: 5 additions & 13 deletions src/room/planning/creep/miner.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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};

pub fn formulate_miner(room: &Room, memory: &mut ScreepsMemory, spawn: StructureSpawn) -> bool {
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());

Expand Down Expand Up @@ -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),
Expand All @@ -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());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/room/planning/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions src/room/planning/room/resources.rs
Original file line number Diff line number Diff line change
@@ -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<ScoutedSource> {
let mut planned_sources = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion src/room/tower.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use screeps::{Room, find, StructureType, StructureProperties, StructureObject};
use screeps::{Room, find};

use super::structure_cache::RoomStructureCache;

Expand Down
2 changes: 1 addition & 1 deletion src/traits/creep.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use log::info;
use screeps::{HasPosition, MoveToOptions, Position, SharedCreepProperties};
use screeps::{HasPosition, Position};

use crate::{
memory::CreepMemory,
Expand Down

0 comments on commit addce5d

Please sign in to comment.