Skip to content

Commit

Permalink
terrain as vector in mapScripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Finnik723 committed Jan 11, 2020
1 parent ac9fd80 commit a81e8b6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
18 changes: 16 additions & 2 deletions src/Battlescape/BattlescapeGenerator.cpp
Expand Up @@ -2276,7 +2276,14 @@ void BattlescapeGenerator::generateMap(const std::vector<MapScript*> *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)
{
Expand Down Expand Up @@ -2998,7 +3005,14 @@ void BattlescapeGenerator::loadVerticalLevels(MapScript *command, bool repopulat
MapBlock *block = _blocks[x][y];

std::vector<VerticalLevel>::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();
Expand Down
10 changes: 8 additions & 2 deletions src/Menu/TestState.cpp
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/MapScript.cpp
Expand Up @@ -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()
{
}

Expand Down Expand Up @@ -263,7 +263,7 @@ void MapScript::load(const YAML::Node& node)
_executions = node["executions"].as<int>(_executions);
_ufoName = node["UFOName"].as<std::string>(_ufoName);
_craftName = node["craftName"].as<std::string>(_craftName);
_terrain = node["terrain"].as<std::string>(_terrain);
_terrain = node["terrain"].as<std::vector<std::string>>(_terrain);
// take no chances, don't accept negative values here.
_label = std::abs(node["label"].as<int>(_label));

Expand Down Expand Up @@ -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<std::string> MapScript::getAlternateTerrain() const
{
return _terrain;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Mod/MapScript.h
Expand Up @@ -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<std::string> _terrain;
std::vector<VerticalLevel> _verticalLevels;

/// Randomly generate a group from within the array.
Expand Down Expand Up @@ -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<std::string> getAlternateTerrain() const;
/// Gets the vertical levels for a command
const std::vector<VerticalLevel> &getVerticalLevels() const;
/// Sets the vertical levels for a command from a base facility's vertical levels
Expand Down

0 comments on commit a81e8b6

Please sign in to comment.