Skip to content

Commit 43a2188

Browse files
committed
don't add non-existant things
1 parent c8edd2d commit 43a2188

1 file changed

Lines changed: 26 additions & 20 deletions

File tree

src/Battlescape/BattlescapeGenerator.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,45 +1761,51 @@ void BattlescapeGenerator::generateMap(const std::vector<MapScript*> *script)
17611761
success = addLine((MapDirection)(command->getDirection()), command->getRects());
17621762
break;
17631763
case MSC_ADDCRAFT:
1764-
craftMap = _craft->getRules()->getBattlescapeTerrainData()->getRandomMapBlock(999, 999, 0, false);
1765-
if (addCraft(craftMap, command, _craftPos))
1764+
if (_craft)
17661765
{
1767-
// by default addCraft adds blocks from group 1.
1768-
// this can be overwritten in the command by defining specific groups or blocks
1769-
// or this behaviour can be suppressed by leaving group 1 empty
1770-
// this is intentional to allow for TFTD's cruise liners/etc
1771-
// in this situation, you can end up with ANYTHING under your craft, so be careful
1772-
for (x = _craftPos.x; x < _craftPos.x + _craftPos.w; ++x)
1766+
craftMap = _craft->getRules()->getBattlescapeTerrainData()->getRandomMapBlock(999, 999, 0, false);
1767+
if (addCraft(craftMap, command, _craftPos))
17731768
{
1774-
for (y = _craftPos.y; y < _craftPos.y + _craftPos.h; ++y)
1769+
// by default addCraft adds blocks from group 1.
1770+
// this can be overwritten in the command by defining specific groups or blocks
1771+
// or this behaviour can be suppressed by leaving group 1 empty
1772+
// this is intentional to allow for TFTD's cruise liners/etc
1773+
// in this situation, you can end up with ANYTHING under your craft, so be careful
1774+
for (x = _craftPos.x; x < _craftPos.x + _craftPos.w; ++x)
17751775
{
1776-
if (_blocks[x][y])
1776+
for (y = _craftPos.y; y < _craftPos.y + _craftPos.h; ++y)
17771777
{
1778-
loadMAP(_blocks[x][y], x * 10, y * 10, _terrain, 0);
1778+
if (_blocks[x][y])
1779+
{
1780+
loadMAP(_blocks[x][y], x * 10, y * 10, _terrain, 0);
1781+
}
17791782
}
17801783
}
1784+
_craftDeployed = true;
1785+
success = true;
17811786
}
1782-
_craftDeployed = true;
1783-
success = true;
17841787
}
17851788
break;
17861789
case MSC_ADDUFO:
17871790
// as above, note that the craft and the ufo will never be allowed to overlap.
17881791
// TODO: make _ufopos a vector ;)
1789-
ufoMap = _ufo->getRules()->getBattlescapeTerrainData()->getRandomMapBlock(999, 999, 0, false);
1790-
if (addCraft(ufoMap, command, _ufoPos))
1792+
if (_ufo)
17911793
{
1792-
for (x = _ufoPos.x; x < _ufoPos.x + _ufoPos.w; ++x)
1794+
ufoMap = _ufo->getRules()->getBattlescapeTerrainData()->getRandomMapBlock(999, 999, 0, false);
1795+
if (addCraft(ufoMap, command, _ufoPos))
17931796
{
1794-
for (y = _ufoPos.y; y < _ufoPos.y + _ufoPos.h; ++y)
1797+
for (x = _ufoPos.x; x < _ufoPos.x + _ufoPos.w; ++x)
17951798
{
1796-
if (_blocks[x][y])
1799+
for (y = _ufoPos.y; y < _ufoPos.y + _ufoPos.h; ++y)
17971800
{
1798-
loadMAP(_blocks[x][y], x * 10, y * 10, _terrain, 0);
1801+
if (_blocks[x][y])
1802+
{
1803+
loadMAP(_blocks[x][y], x * 10, y * 10, _terrain, 0);
1804+
}
17991805
}
18001806
}
1807+
success = true;
18011808
}
1802-
success = true;
18031809
}
18041810
break;
18051811
case MSC_DIGTUNNEL:

0 commit comments

Comments
 (0)