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

Method generateMap

game/state/rules/battle/battlemap.cpp:578–914  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

576} // namespace
577
578bool BattleMap::generateMap(std::vector<sp<BattleMapSector>> &sec_map, Vec3<int> &size,
579 GameState &state, GenerationSize genSize)
580{
581 // Vanilla had vertical stacking of sectors planned, but not implemented. I will implement both
582 // algorithms because I think that would be great to have. We could make it an extended game
583 // option in the future.
584 bool allow_vertical_stacking = true;
585
586 // This switch will allow larger maps, +2 in size, which vanilla never did I think, and which is
587 // required for some vertical stacking maps to actually spawn because they contain too many
588 // mandatory sectors to fit into battle size even when enlarged by 1 on the smaller side
589 bool allow_very_large_maps = true;
590
591 // This switch allows maps to spawn only one of the mandatory sectors instead of
592 // every single one
593 // This provides for vertical stacking maps to be possible without huge sizes, but may
594 // theoretically produce maps with no way to the upper layers
595 // In practice, however, every vertical-stacking map's sector with more than one vertical chunk
596 // I seen provides access to the second level
597 // So that should never be a problem
598 bool require_only_largest_mandatory_sector = true;
599
600 // Vanilla had some rules that shrunk or extended maps based on squad size.
601 // For example, 28SLUMS has max_y_size = 2, but often spawns a single block, because it's 9
602 // layers high, big enough to fit everything.
603 // OTOH, 14ACNORM has 2x2 max size, but often spawns 3x2 because it's only 2 layers high, and
604 // 2nd layer is just air (high ceiling)
605 // As we do not know them yet, I will generate maps in 3 modes for now: small, normal, big
606 // Small being a -1 on the larger side and Big being +1 or +2 on a random side.
607 // +2 is required for some maps with vertical stacking to fit all the mandatory sectors
608 // For now, this is random, in the future, this will be tied to the amount of troops
609 int size_mod =
610 genSize == GenerationSize::Small ? -1 : (genSize == GenerationSize::Normal ? 0 : 1);
611 if (genSize == GenerationSize::VeryLarge)
612 {
613 if (allow_very_large_maps)
614 {
615 size_mod++;
616 }
617 else
618 {
619 LogWarning("Cannot generate a map %s with gen size %d since generating large maps is "
620 "disabled",
621 id, (int)genSize);
622 return false;
623 }
624 }
625 // Vertical stacking is also randomized, and disabled if the map does not allow it
626 allow_vertical_stacking =
627 allow_vertical_stacking && max_battle_size.z > 1 && randBool(state.rng);
628 // This switch is only relevant if we're vertically stacking
629 require_only_largest_mandatory_sector =
630 require_only_largest_mandatory_sector && allow_vertical_stacking;
631 // However, there are maps that have too many mandatory sectors
632 // For these maps, we must set this switch, otherwise it's not possible to create a map!
633 if (!require_only_largest_mandatory_sector)
634 {
635 int remainingMapSize = max_battle_size.x * max_battle_size.y * max_battle_size.z;

Callers

nothing calls this directly

Calls 7

randBoolFunction · 0.85
randBoundsInclusiveFunction · 0.85
placeSectorFunction · 0.85
isMapCompleteFunction · 0.85
randBoundsExclusiveFunction · 0.85
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected