Skip to content

Commit

Permalink
Fix some RCL 8 issues, make haulers a little more dumb, more fun stuffs.
Browse files Browse the repository at this point in the history
  • Loading branch information
InfinityDevTech committed Oct 7, 2024
1 parent d46b561 commit 3c344a4
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ lto = true
# -O4 - optimize aggressively for performance
# -Oz - optimize aggressively for code size
# -g - leave debug info in place, allowing for more descriptive stack traces on panic
# --disable-sign-ext - prevents opcodes that the screeps servers can't load (see
# --disable-sign-ext - prevents opcoAFdes that the screeps servers can't load (see
# --signext-lowering - removes opcodes that the screeps servers can't load (see
# https://github.com/rustyscreeps/screeps-game-api/issues/391)
#wasm-opt = ["-O4", "--disable-sign-ext"]
#wasm-opt = ["-O4", "--signext-lowering"]
wasm-opt = ["-g", "--signext-lowering"]
wasm-opt = ["-O4", "--signext-lowering"]
#wasm-opt = ["-g", "--signext-lowering"]

[features]
default = ["season1"]
Expand Down
5 changes: 3 additions & 2 deletions src/combat/goals/room_reservation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub fn spawn_creep(goal: &RoomReservationGoal, cache: &mut RoomCache) -> Option<
}

let energy_storage = room.energy_capacity_available();
let should_cap = under_storage_gate(cache.rooms.get(&room.name()).unwrap(), 0.5);
let mut current_claim = 0;

let body = if energy_storage >= 1300 {
Expand All @@ -124,7 +125,7 @@ pub fn spawn_creep(goal: &RoomReservationGoal, cache: &mut RoomCache) -> Option<
let mut current_cost = 650;

while current_cost < energy_storage {
if current_cost + stamp_cost > energy_storage || current_claim >= 3 {
if current_cost + stamp_cost > energy_storage || current_claim >= 5 || should_cap && current_claim >= 2 {
break;
}

Expand Down Expand Up @@ -182,7 +183,7 @@ pub fn spawn_creep(goal: &RoomReservationGoal, cache: &mut RoomCache) -> Option<

if let Some(goal_cache) = cache.rooms.get_mut(&best_spawned) {
if let Some(storage) = &goal_cache.structures.storage {
if under_storage_gate(&goal_cache, 0.5) {
if under_storage_gate(&goal_cache, 0.1) {
return None;
} else if storage.store().get_used_capacity(Some(screeps::constants::ResourceType::Energy)) > 30_000 {
priority *= 2.0;
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub const RESERVATION_GOAL_THRESHOLD: u32 = 4000;
pub const ROOM_ENERGY_STOCKPILE: u32 = 20000;

pub fn REMOTES_FOR_RCL(room_cache: &CachedRoom) -> u8 {
if utils::under_storage_gate(room_cache, 0.5) && room_cache.rcl >= 6 {
if utils::under_storage_gate(room_cache, 1.0) && room_cache.rcl >= 6 {
return 7;
}

Expand All @@ -29,7 +29,7 @@ pub fn REMOTES_FOR_RCL(room_cache: &CachedRoom) -> u8 {
5 => 5,
6 => 5,
7 => 5,
8 => 3,
8 => 4,
_ => 0,
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/room/creeps/combat/bulldozer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ pub fn run_bulldozer(creep: &Creep, memory: &mut ScreepsMemory, cache: &mut Room
return;
}

if let Some(structures_at_pos) = room_cache.structures.structures_at_pos.get(&flag.pos().xy()) {
if !structures_at_pos.is_empty() {
let t = structure.iter().filter(|s| s.pos() == flag.pos() && s.structure_type() == *structures_at_pos.first().unwrap()).collect::<Vec<&StructureObject>>();
let structure = t.first().unwrap();

if creep.pos().is_near_to(structure.pos()) {
let _ = creep.attack(structure.as_attackable().unwrap());
return;
} else {
creep.better_move_to(memory, room_cache, structure.pos(), 1, MoveOptions::default().path_age(1));
return;
}
}
}

if let Some(spawn) = structure.iter().filter(|s| s.structure_type() == StructureType::Spawn).map(|s| (s)).next() {
if creep.pos().is_near_to(spawn.pos()) {
let _ = creep.attack(spawn.as_attackable().unwrap());
Expand Down
4 changes: 4 additions & 0 deletions src/room/creeps/combat/reserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use crate::{

#[cfg_attr(feature = "profile", screeps_timing_annotate::timing)]
pub fn run_reserver(creep: &Creep, memory: &mut ScreepsMemory, cache: &mut RoomCache) {
if creep.spawning() {
return;
}

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

let current_room = &cache.rooms.get(&creep.pos().room_name()).unwrap().room;
Expand Down
11 changes: 9 additions & 2 deletions src/room/creeps/local/hauler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,10 @@ pub fn execute_order(
let result = creep.ITwithdraw(
target.unchecked_ref::<StructureStorage>(),
order.resource,
Some(amount.try_into().unwrap_or(0)),
None
// TODO:
// Same as the offer.
//Some(amount.try_into().unwrap_or(0)),
);

cache.creeps_moving_stuff.insert(creep.name(), true);
Expand Down Expand Up @@ -551,7 +554,11 @@ pub fn execute_order(
creep.ITwithdraw(
target.unchecked_ref::<StructureStorage>(),
order.resource,
Some(amount.try_into().unwrap()),
None
// TODO:
// Make the order expand what the hauler will pick ujp if the hauler has the capacity.
// Haulers are just leaving with like, no energy.
//Some(amount.try_into().unwrap()),
)
};

Expand Down
3 changes: 2 additions & 1 deletion src/room/planning/room/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ pub fn get_rcl_7_plan() -> Vec<(i8, i8, StructureType)> {
pub fn get_rcl_8_plan() -> Vec<(i8, i8, StructureType)> {
vec![
(0, -1, StructureType::Link),
(0, 0, StructureType::Spawn),
(1, -2, StructureType::Spawn),
(0, -3, StructureType::Observer),
(0, 3, StructureType::Nuker),
(1, 4, StructureType::PowerSpawn),
Expand All @@ -434,6 +434,7 @@ pub fn get_rcl_8_plan() -> Vec<(i8, i8, StructureType)> {
(6, 1, StructureType::Extension),
(-1, -6, StructureType::Extension),
(-2, -6, StructureType::Extension),
(-4, -3, StructureType::Extension),
(-3, -6, StructureType::Extension),
(-4, -6, StructureType::Extension),
(-5, -5, StructureType::Extension),
Expand Down
4 changes: 4 additions & 0 deletions src/room/spawning/spawn_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ pub fn calculate_hauler_needs(room: &Room, memory: &mut ScreepsMemory, cache: &m
wanted_hauler_count *= 1.5;
}

if owning_cache.rcl >= 8 {
wanted_hauler_count *= 0.75;
}

let hauler_count = if wanted_hauler_count < 3.0 {
3
} else {
Expand Down

0 comments on commit 3c344a4

Please sign in to comment.