Skip to content

Commit 05385fe

Browse files
committed
add setUFO command to mapscripts
this won't go well
1 parent 0462159 commit 05385fe

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎src/Battlescape/BattlescapeGenerator.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,26 @@ void BattlescapeGenerator::generateMap(const std::vector<MapScript*> *script)
20232023
}
20242024
init();
20252025
break;
2026+
case MSC_SETUFO:
2027+
if (_game->getMod()->getUfo(command->getUFOName()))
2028+
{
2029+
ufoMap = _game->getMod()->getUfo(command->getUFOName())->getBattlescapeTerrainData()->getRandomMapBlock(999, 999, 0, false);
2030+
if (addCraft(ufoMap, command, _ufoPos))
2031+
{
2032+
for (x = _ufoPos.x; x < _ufoPos.x + _ufoPos.w; ++x)
2033+
{
2034+
for (y = _ufoPos.y; y < _ufoPos.y + _ufoPos.h; ++y)
2035+
{
2036+
if (_blocks[x][y])
2037+
{
2038+
loadMAP(_blocks[x][y], x * 10, y * 10, _terrain, 0);
2039+
}
2040+
}
2041+
}
2042+
success = true;
2043+
}
2044+
}
2045+
break;
20262046
default:
20272047
break;
20282048
}

‎src/Mod/MapScript.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ void MapScript::load(const YAML::Node& node)
7575
_type = MSC_RESIZE;
7676
_sizeX = _sizeY = 0; // defaults: don't resize anything unless specified.
7777
}
78+
else if (command == "setUFO")
79+
_type = MSC_SETUFO;
7880
else
7981
{
8082
throw Exception("Unknown command: " + command);
@@ -260,6 +262,7 @@ void MapScript::load(const YAML::Node& node)
260262

261263
_executionChances = node["executionChances"].as<int>(_executionChances);
262264
_executions = node["executions"].as<int>(_executions);
265+
_ufoName = node["UFOName"].as<std::string>(_ufoName);
263266
// take no chances, don't accept negative values here.
264267
_label = std::abs(node["label"].as<int>(_label));
265268
}
@@ -377,4 +380,13 @@ MapBlock *MapScript::getNextBlock(RuleTerrain *terrain)
377380
return 0;
378381
}
379382

383+
/**
384+
* Gets the name of the UFO in the case of "setUFO"
385+
* @return the UFO name.
386+
*/
387+
std::string MapScript::getUFOName()
388+
{
389+
return _ufoName;
390+
}
391+
380392
}

‎src/Mod/MapScript.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct TunnelData
4646
return &replacements[type];
4747
}
4848
};
49-
enum MapScriptCommand {MSC_UNDEFINED = -1, MSC_ADDBLOCK, MSC_ADDLINE, MSC_ADDCRAFT, MSC_ADDUFO, MSC_DIGTUNNEL, MSC_FILLAREA, MSC_CHECKBLOCK, MSC_REMOVE, MSC_RESIZE};
49+
enum MapScriptCommand {MSC_UNDEFINED = -1, MSC_ADDBLOCK, MSC_ADDLINE, MSC_ADDCRAFT, MSC_ADDUFO, MSC_DIGTUNNEL, MSC_FILLAREA, MSC_CHECKBLOCK, MSC_REMOVE, MSC_RESIZE, MSC_SETUFO};
5050

5151
class MapBlock;
5252
class RuleTerrain;
@@ -61,6 +61,7 @@ class MapScript
6161
int _sizeX, _sizeY, _sizeZ, _executionChances, _executions, _cumulativeFrequency, _label;
6262
MapDirection _direction;
6363
TunnelData *_tunnelData;
64+
std::string _ufoName;
6465

6566
/// Randomly generate a group from within the array.
6667
int getGroupNumber();
@@ -101,6 +102,8 @@ class MapScript
101102
TunnelData *getTunnelData() {return _tunnelData;};
102103
/// Randomly generate a block from within either the array of groups or blocks.
103104
MapBlock *getNextBlock(RuleTerrain *terrain);
105+
/// Gets the UFO's name (for setUFO)
106+
std::string getUFOName();
104107
};
105108
}
106109
#endif

0 commit comments

Comments
 (0)