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

Method setRaidMissions

game/state/shared/organisation.cpp:312–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

310}
311
312void Organisation::setRaidMissions(GameState &state, StateRef<City> city)
313{
314 OrganisationRaid &rules = state.organisation_raid_rules;
315
316 std::list<StateRef<Building>> ownedBuildingsList;
317 for (const auto &b : buildings)
318 {
319 if (b->city == city)
320 {
321 ownedBuildingsList.push_back(b);
322 }
323 }
324
325 if (ownedBuildingsList.empty())
326 {
327 return;
328 }
329
330 for (const auto &org : state.organisations)
331 {
332 const StateRef<Organisation> otherOrg{&state, org.first};
333 if (isRelatedTo(otherOrg) == Relation::Hostile)
334 {
335 // every time (for every hostile org) pick a new building
336 const auto sourceBuilding = pickRandom(state.rng, ownedBuildingsList);
337 if (!sourceBuilding)
338 {
339 continue;
340 }
341
342 if (std::max(1.0f, long_term_relations[otherOrg] - current_relations[otherOrg]) >
343 randBoundsInclusive(state.rng, 0, rules.nextRaidTimer))
344 {
345 rules.nextRaidTimer = 80 - 2 * state.difficulty;
346
347 const StateRef<Building> targetBuilding = otherOrg->pickRandomBuilding(state, city);
348 if (!targetBuilding)
349 {
350 continue;
351 }
352
353 const uint64_t missionTime =
354 state.gameTime.getTicks() + randBoundsInclusive(state.rng, 50, 1250) *
355 static_cast<uint64_t>(TICKS_PER_MINUTE);
356
357 // calculate manpower available and probability of raid success
358 const float targetGuards = otherOrg->average_guards * otherOrg->average_guards *
359 targetBuilding->currentWorkforce;
360
361 // make sure it's not 0 (in case of X-Com)
362 const float guardRatio = average_guards * average_guards *
363 sourceBuilding->currentWorkforce /
364 std::max(1.0f, targetGuards);
365
366 auto &raidMissionChance = rules.neutral_low_manpower;
367 if (guardRatio > 2)
368 {
369 raidMissionChance =

Callers 1

updateEndOfDayMethod · 0.80

Calls 6

pickRandomFunction · 0.85
randBoundsInclusiveFunction · 0.85
probabilityMapRandomizerFunction · 0.85
emptyMethod · 0.80
pickRandomBuildingMethod · 0.80
getTicksMethod · 0.80

Tested by

no test coverage detected