-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7627467
commit 419b816
Showing
17 changed files
with
564 additions
and
197 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod roads; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use log::info; | ||
use screeps::{Source, StructureSpawn, HasPosition, pathfinder::{SearchOptions, MultiRoomCostResult, self}, RoomName, LocalCostMatrix, game, StructureType, find, StructureProperties, look, ConstructionSite}; | ||
|
||
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); | ||
let path = pathfinder::search(spawn.pos(), source.pos(), 1, Some(opts)); | ||
if !path.incomplete() { | ||
info!("Road complete"); | ||
for pos in path.path() { | ||
let room = game::rooms().get(pos.room_name()).unwrap(); | ||
if room.look_for_at_xy(look::CONSTRUCTION_SITES, pos.x().u8(), pos.y().u8()).is_empty() { | ||
match room.create_construction_site(pos.x().u8(), pos.y().u8(), StructureType::Road, None) { | ||
Ok(_) => {}, | ||
Err(e) => { | ||
println!("Error creating construction site: {:?}", e); | ||
} | ||
}; | ||
} | ||
} | ||
} else { | ||
info!("Road incomplete?"); | ||
} | ||
} | ||
|
||
pub fn road_callback(room_name: RoomName) -> MultiRoomCostResult { | ||
let mut matrix = LocalCostMatrix::new(); | ||
if let Some(room) = game::rooms().get(room_name) { | ||
for road in room.find(find::STRUCTURES, None).into_iter().filter(|s| s.structure_type() == StructureType::Road) { | ||
matrix.set(road.pos().xy(), 1); | ||
} | ||
let csites = room.find(find::CONSTRUCTION_SITES, None); | ||
for site in csites { | ||
match site.structure_type() { | ||
StructureType::Road => matrix.set(site.pos().xy(), 1), | ||
StructureType::Rampart => matrix.set(site.pos().xy(), 1), | ||
StructureType::Container => matrix.set(site.pos().xy(), 1), | ||
_ => todo!(), | ||
} | ||
} | ||
for creep in room.find(find::CREEPS, None) { | ||
matrix.set(creep.pos().xy(), 1); | ||
} | ||
} | ||
|
||
MultiRoomCostResult::CostMatrix(matrix.into()) | ||
|
||
} |
Oops, something went wrong.