Skip to content

Commit

Permalink
Testing again
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinityDevTech committed Nov 12, 2024
1 parent cebef8b commit d13b694
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub fn game_loop() {
start_government(room, &mut memory, &mut cache);
}
memory.stats.cpu.rooms = game::cpu::get_used() - pre_room_cpu - cache.creep_cpu;
info!("[GOVERNMENT] Global government execution took {:.2} CPU for {} rooms.", game::cpu::get_used() - pre_room_cpu, game::rooms().keys().count());
info!("[GOVERNMENT] Global government execution took {:.2} CPU for {} rooms. {:.2} Overhead without creeps.", game::cpu::get_used() - pre_room_cpu, game::rooms().keys().count(), game::cpu::get_used() - pre_room_cpu - cache.creep_cpu);

if game::time() % 100 == 0 {
for room in memory.rooms.clone().keys() {
Expand Down
18 changes: 9 additions & 9 deletions src/room/cache/hauling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,6 @@ pub fn match_haulers(room_cache: &mut RoomCache, memory: &mut ScreepsMemory, roo
}
}

info!(
"[HAULING] Room {} matched {} haulers to {} orders in {:.2} CPU",
room_name,
matched_creeps.len(),
count,
game::cpu::get_used() - starting_cpu
);

// We have the output above, because we dont want to include intents from the creeps being matched.

let pre_exec_cpu = game::cpu::get_used();
Expand All @@ -535,7 +527,15 @@ pub fn match_haulers(room_cache: &mut RoomCache, memory: &mut ScreepsMemory, roo
execute_order(&creep, memory, room_cache, &haul_task);
}

info!("[HAULING] Executing {} creeps took {:.2} CPU.", size, game::cpu::get_used() - pre_exec_cpu);
info!(
"[HAULING] Room {} matched {} haulers to {} orders in {:.2} CPU. Ran {} haulers in {:.2} CPU.",
room_name,
matched_creeps.len(),
count,
game::cpu::get_used() - starting_cpu,
size,
game::cpu::get_used() - pre_exec_cpu,
);
}

//#[cfg_attr(feature = "profile", screeps_timing_annotate::timing)]
Expand Down
33 changes: 23 additions & 10 deletions src/room/creeps/local/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ pub fn run_builder(creep: &Creep, memory: &mut ScreepsMemory, cache: &mut RoomCa
}
}

pub fn _get_all_remote_csites(
pub fn get_all_remote_csites(
main_room: &RoomName,
room_cache: &RoomCache,
memory: &mut ScreepsMemory,
memory: &ScreepsMemory,
) -> Vec<ConstructionSite> {
let mut sites = Vec::new();

Expand All @@ -47,7 +47,11 @@ pub fn _get_all_remote_csites(
if let Some(cache) = room_cache.rooms.get(remote) {
let remote_sites = cache.structures.construction_sites.clone();

sites.extend(remote_sites);
for csite in remote_sites {
if csite.my() {
sites.push(csite);
}
}
}
}
}
Expand All @@ -59,13 +63,21 @@ pub fn _get_all_remote_csites(
pub fn build(creep: &Creep, memory: &mut ScreepsMemory, cache: &mut RoomCache) {
let creepmem = memory.creeps.get_mut(&creep.name()).unwrap();
let room_cache = cache.rooms.get_mut(&creepmem.owning_room).unwrap();
let sites = room_cache.structures.construction_sites.clone();
let mut sites = room_cache.structures.construction_sites.clone();
//sites.sort_by_key(|s| s.pos().get_range_to(creep.pos()));

let _owning_room = creepmem.owning_room;
//sites.append(&mut get_all_remote_csites(&owning_room, cache, memory));
let room = &creepmem.owning_room.clone();
drop(creepmem);

if creep.room().unwrap().name() != creepmem.owning_room {
let sites = if room_cache.structures.construction_sites.is_empty() {;
get_all_remote_csites(room, cache, memory)
} else {
room_cache.structures.construction_sites.clone()
};

let creepmem = memory.creeps.get_mut(&creep.name()).unwrap();

/*if creep.room().unwrap().name() != creepmem.owning_room {
let room = creepmem.owning_room;
creep.better_move_to(
Expand All @@ -77,7 +89,7 @@ pub fn build(creep: &Creep, memory: &mut ScreepsMemory, cache: &mut RoomCache) {
);
return;
}
}*/

let creepmem = memory.creeps.get_mut(&creep.name()).unwrap();
let room_cache = cache.rooms.get_mut(&creepmem.owning_room).unwrap();
Expand Down Expand Up @@ -163,7 +175,8 @@ pub fn find_energy(creep: &Creep, memory: &mut ScreepsMemory, cache: &mut RoomCa
if !under_storage_gate(room_cache, 0.7) {
if !creep.pos().is_near_to(storage.pos()) {
creep.bsay("🚚", false);
creep.better_move_to(memory, room_cache, storage.pos(), 1, MoveOptions::default());
let pos = storage.pos();
creep.better_move_to(memory, cache.rooms.get_mut(&creep.room().unwrap().name()).unwrap(), pos, 1, MoveOptions::default());
} else {
creep.bsay("🔋", false);
let _ = creep.ITwithdraw(storage, ResourceType::Energy, None);
Expand Down Expand Up @@ -202,7 +215,7 @@ pub fn find_energy(creep: &Creep, memory: &mut ScreepsMemory, cache: &mut RoomCa
creep.bsay("🚚", false);
creep.better_move_to(
memory,
room_cache,
cache.rooms.get_mut(&creep.room().unwrap().name()).unwrap(),
container.pos(),
1,
MoveOptions::default(),
Expand Down
4 changes: 2 additions & 2 deletions src/room/democracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ pub fn run_crap_planner_code(room: &Room, memory: &mut ScreepsMemory, cache: &mu
}
}

/*

for (room_name, path) in memory.rooms.get(&room.name()).unwrap().planned_paths.iter() {
if let Some(game_room) = game::rooms().get(*room_name) {
for pos in decode_pos_list(path.to_string()) {
Expand All @@ -618,7 +618,7 @@ pub fn run_crap_planner_code(room: &Room, memory: &mut ScreepsMemory, cache: &mu
let _ = game_room.ITcreate_construction_site(pos.x().u8(), pos.y().u8(), StructureType::Road, None);
}
}
}*/
}
}

for structure in get_containers() {
Expand Down

0 comments on commit d13b694

Please sign in to comment.