(&self, worker_id: UnitID, unit_type: UnitType,
direction: Direction)
| 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 |
no test coverage detected