MCPcopy Create free account
hub / github.com/battlecode/battlecode-2018 / ok_if_can_blueprint

Method ok_if_can_blueprint

battlecode-engine/src/world.rs:1259–1285  ·  view source on GitHub ↗
(&self, worker_id: UnitID, unit_type: UnitType,
                         direction: Direction)

Source from the content-addressed store, hash-verified

1257 }
1258
1259 fn ok_if_can_blueprint(&self, worker_id: UnitID, unit_type: UnitType,
1260 direction: Direction) -> Result<(), GameError> {
1261 let unit = self.my_unit(worker_id)?;
1262 // Players should never attempt to build a non-structure.
1263 if !unit_type.is_structure() {
1264 Err(GameError::InappropriateUnitType)?;
1265 }
1266 unit.ok_if_can_worker_act()?;
1267 let build_loc = unit.location().map_location()?.add(direction);
1268 // The build location must be unoccupied, and we must be able to sense it.
1269 if !self.is_occupiable(build_loc)? {
1270 Err(GameError::LocationNotEmpty)?;
1271 }
1272 // Structures can never be built on Mars.
1273 if build_loc.planet == Planet::Mars {
1274 Err(GameError::CannotBuildOnMars)?;
1275 }
1276 // If building a rocket, Rocketry must be unlocked.
1277 if unit_type == UnitType::Rocket && self.my_research().get_level(&unit_type) < 1 {
1278 Err(GameError::ResearchNotUnlocked { unit_type: UnitType::Rocket })?;
1279 }
1280 // Finally, the team must have sufficient karbonite.
1281 if self.karbonite() < unit_type.blueprint_cost()? {
1282 Err(GameError::InsufficientKarbonite)?;
1283 }
1284 Ok(())
1285 }
1286
1287 /// Whether the worker can blueprint a structure of the given type. The worker
1288 /// can only blueprint factories, and rockets if Rocketry has been

Callers 2

can_blueprintMethod · 0.80
blueprintMethod · 0.80

Calls 11

my_unitMethod · 0.80
is_structureMethod · 0.80
ok_if_can_worker_actMethod · 0.80
map_locationMethod · 0.80
locationMethod · 0.80
get_levelMethod · 0.80
my_researchMethod · 0.80
blueprint_costMethod · 0.80
addMethod · 0.45
is_occupiableMethod · 0.45
karboniteMethod · 0.45

Tested by

no test coverage detected