diff --git a/src/Battlescape/BattlescapeGenerator.cpp b/src/Battlescape/BattlescapeGenerator.cpp index b56d6bdf3c..997f92ff09 100644 --- a/src/Battlescape/BattlescapeGenerator.cpp +++ b/src/Battlescape/BattlescapeGenerator.cpp @@ -2276,7 +2276,14 @@ void BattlescapeGenerator::generateMap(const std::vector *script, co _placedBlockRects.clear(); RuleTerrain *terrain; - terrain = pickTerrain(command->getAlternateTerrain()); + if (!command->getAlternateTerrain().empty()) { + size_t pick = RNG::generate(0, command->getAlternateTerrain().size() - 1); + terrain = pickTerrain(command->getAlternateTerrain().at(pick)); + } + else { + terrain = pickTerrain(""); + } + if (doLevels) { @@ -2998,7 +3005,14 @@ void BattlescapeGenerator::loadVerticalLevels(MapScript *command, bool repopulat MapBlock *block = _blocks[x][y]; std::vector::iterator currentLevel = _verticalLevels.begin(); - RuleTerrain *terrain = pickTerrain(command->getAlternateTerrain()); + RuleTerrain* terrain; + if (!command->getAlternateTerrain().empty()) { + size_t pick = RNG::generate(0, command->getAlternateTerrain().size() - 1); + terrain = pickTerrain(command->getAlternateTerrain().at(pick)); + } + else { + terrain = pickTerrain(""); + } int zOffset = 0; int zLevelsLeft = command->getSizeZ(); diff --git a/src/Menu/TestState.cpp b/src/Menu/TestState.cpp index e16ee01439..2dc42d138b 100644 --- a/src/Menu/TestState.cpp +++ b/src/Menu/TestState.cpp @@ -256,8 +256,14 @@ void TestState::testCase4() } for (auto &mapScript : _game->getMod()->getMapScriptsRaw()) { - for (auto &mapScriptCommand : mapScript.second) - terrainMap[mapScriptCommand->getAlternateTerrain()] += 1; + for (auto& mapScriptCommand : mapScript.second) + if (!mapScriptCommand->getAlternateTerrain().empty()) { + size_t pick = RNG::generate(0, mapScriptCommand->getAlternateTerrain().size() - 1); + terrainMap[mapScriptCommand->getAlternateTerrain().at(pick)] += 1; + } + else { + terrainMap[""]; + } } // erase false positives diff --git a/src/Mod/MapScript.cpp b/src/Mod/MapScript.cpp index c06a11ad55..d6498f4e18 100644 --- a/src/Mod/MapScript.cpp +++ b/src/Mod/MapScript.cpp @@ -29,7 +29,7 @@ namespace OpenXcom { MapScript::MapScript() : _type(MSC_UNDEFINED), _canBeSkipped(true), _sizeX(1), _sizeY(1), _sizeZ(0), _executionChances(100), _executions(1), _cumulativeFrequency(0), _label(0), - _direction(MD_NONE), _verticalGroup(MT_NSROAD), _horizontalGroup(MT_EWROAD), _crossingGroup(MT_CROSSING), _tunnelData(0), _terrain(""), _verticalLevels() + _direction(MD_NONE), _verticalGroup(MT_NSROAD), _horizontalGroup(MT_EWROAD), _crossingGroup(MT_CROSSING), _tunnelData(0), _terrain(), _verticalLevels() { } @@ -263,7 +263,7 @@ void MapScript::load(const YAML::Node& node) _executions = node["executions"].as(_executions); _ufoName = node["UFOName"].as(_ufoName); _craftName = node["craftName"].as(_craftName); - _terrain = node["terrain"].as(_terrain); + _terrain = node["terrain"].as>(_terrain); // take no chances, don't accept negative values here. _label = std::abs(node["label"].as(_label)); @@ -438,7 +438,7 @@ std::string MapScript::getCraftName() * Gets the terrain name in the case of addBlockFromTerrain or fillAreaFromTerrain * @return the terrain name. */ -std::string MapScript::getAlternateTerrain() const +std::vector MapScript::getAlternateTerrain() const { return _terrain; } diff --git a/src/Mod/MapScript.h b/src/Mod/MapScript.h index 3e94e4abc0..3ed0d0877f 100644 --- a/src/Mod/MapScript.h +++ b/src/Mod/MapScript.h @@ -179,7 +179,8 @@ class MapScript int _sizeX, _sizeY, _sizeZ, _executionChances, _executions, _cumulativeFrequency, _label; MapDirection _direction; TunnelData *_tunnelData; - std::string _ufoName, _craftName, _terrain; + std::string _ufoName, _craftName; + std::vector _terrain; std::vector _verticalLevels; /// Randomly generate a group from within the array. @@ -236,7 +237,7 @@ class MapScript /// Gets the craft's name (for addCraft) std::string getCraftName(); /// Gets alternate terrain for a command other than the one in alienDeploments - std::string getAlternateTerrain() const; + std::vector getAlternateTerrain() const; /// Gets the vertical levels for a command const std::vector &getVerticalLevels() const; /// Sets the vertical levels for a command from a base facility's vertical levels