MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / buildFacility

Method buildFacility

game/state/city/base.cpp:282–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280}
281
282void Base::buildFacility(GameState &state, StateRef<FacilityType> type, Vec2<int> pos, bool free)
283{
284 if (canBuildFacility(type, pos, free) == BuildError::NoError)
285 {
286 auto facility = mksp<Facility>(type);
287 facilities.push_back(facility);
288 facility->pos = pos;
289 if (!free)
290 {
291 if (!building)
292 {
293 LogError("Building disappeared");
294 }
295 else
296 {
297 building->owner->balance -= type->buildCost;
298 }
299 facility->buildTime = type->buildTime;
300 }
301 if (type->capacityAmount > 0)
302 {
303 ResearchTopic::LabSize size;
304 // FIXME: Make LabSize set-able outside of the facility size?
305 if (type->size > 1)
306 {
307 size = ResearchTopic::LabSize::Large;
308 }
309 else
310 {
311 size = ResearchTopic::LabSize::Small;
312 }
313 switch (type->capacityType)
314 {
315 case FacilityType::Capacity::Chemistry:
316 {
317 auto lab = mksp<Lab>();
318 lab->size = size;
319 lab->type = ResearchTopic::Type::BioChem;
320 auto id = Lab::generateObjectID(state);
321 state.research.labs[id] = lab;
322 facility->lab = {&state, id};
323 break;
324 }
325 case FacilityType::Capacity::Physics:
326 {
327 auto lab = mksp<Lab>();
328 lab->size = size;
329 lab->type = ResearchTopic::Type::Physics;
330 auto id = Lab::generateObjectID(state);
331 state.research.labs[id] = lab;
332 facility->lab = {&state, id};
333 break;
334 }
335 case FacilityType::Capacity::Workshop:
336 {
337 auto lab = mksp<Lab>();
338 lab->size = size;
339 lab->type = ResearchTopic::Type::Engineering;

Callers 3

randomlyPlaceFacilityFunction · 0.80
goToBattleMethod · 0.80
eventOccurredMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected