Skip to content
Permalink
Browse files

Add error messages for invalid MCD references

Hopefully it'll make debugging for modders easier
  • Loading branch information
SupSuper committed Sep 20, 2019
1 parent 908a2fb commit 1443422d6ee80862a1d4026fb870334bd2397c6a
@@ -2811,7 +2811,7 @@ void BattlescapeGenerator::drillModules(TunnelData* data, const std::vector<SDL_
tile->setMapData(0, -1, -1, O_OBJECT);
if (floor)
{
md = _terrain->getMapDataSets()->at(floor->set)->getObjects()->at(floor->entry);
md = _terrain->getMapDataSets()->at(floor->set)->getObject(floor->entry);
tile->setMapData(md, floor->entry, floor->set, O_FLOOR);
}

@@ -2827,7 +2827,7 @@ void BattlescapeGenerator::drillModules(TunnelData* data, const std::vector<SDL_

if (nWall)
{
md = _terrain->getMapDataSets()->at(nWall->set)->getObjects()->at(nWall->entry);
md = _terrain->getMapDataSets()->at(nWall->set)->getObject(nWall->entry);
tile = _save->getTile(Position((i*10)+9, (j*10)+rect.y, data->level));
tile->setMapData(md, nWall->entry, nWall->set, O_NORTHWALL);
tile = _save->getTile(Position((i*10)+9, (j*10)+rect.y+rect.h, data->level));
@@ -2836,7 +2836,7 @@ void BattlescapeGenerator::drillModules(TunnelData* data, const std::vector<SDL_

if (corner)
{
md = _terrain->getMapDataSets()->at(corner->set)->getObjects()->at(corner->entry);
md = _terrain->getMapDataSets()->at(corner->set)->getObject(corner->entry);
tile = _save->getTile(Position((i+1)*10, (j*10)+rect.y, data->level));
if (tile->getMapData(O_NORTHWALL) == 0)
tile->setMapData(md, corner->entry, corner->set, O_NORTHWALL);
@@ -2859,7 +2859,7 @@ void BattlescapeGenerator::drillModules(TunnelData* data, const std::vector<SDL_
tile->setMapData(0, -1, -1, O_OBJECT);
if (floor)
{
md = _terrain->getMapDataSets()->at(floor->set)->getObjects()->at(floor->entry);
md = _terrain->getMapDataSets()->at(floor->set)->getObject(floor->entry);
tile->setMapData(md, floor->entry, floor->set, O_FLOOR);
}

@@ -2875,7 +2875,7 @@ void BattlescapeGenerator::drillModules(TunnelData* data, const std::vector<SDL_

if (wWall)
{
md = _terrain->getMapDataSets()->at(wWall->set)->getObjects()->at(wWall->entry);
md = _terrain->getMapDataSets()->at(wWall->set)->getObject(wWall->entry);
Tile *tile = _save->getTile(Position((i*10)+rect.x, (j*10)+9, data->level));
tile->setMapData(md, wWall->entry, wWall->set, O_WESTWALL);
tile = _save->getTile(Position((i*10)+rect.x+rect.w, (j*10)+9, data->level));
@@ -2884,7 +2884,7 @@ void BattlescapeGenerator::drillModules(TunnelData* data, const std::vector<SDL_

if (corner)
{
md = _terrain->getMapDataSets()->at(corner->set)->getObjects()->at(corner->entry);
md = _terrain->getMapDataSets()->at(corner->set)->getObject(corner->entry);
Tile *tile = _save->getTile(Position((i*10)+rect.x, (j+1)*10, data->level));
if (tile->getMapData(O_WESTWALL) == 0)
tile->setMapData(md, corner->entry, corner->set, O_WESTWALL);
@@ -1551,7 +1551,7 @@ bool TileEngine::detonate(Tile* tile)
//this trick is to follow transformed object parts (object can become a ground)
diemcd = tiles[i]->getMapData(currentpart)->getDieMCD();
if (diemcd!=0)
currentpart2 = tiles[i]->getMapData(currentpart)->getDataset()->getObjects()->at(diemcd)->getObjectType();
currentpart2 = tiles[i]->getMapData(currentpart)->getDataset()->getObject(diemcd)->getObjectType();
else
currentpart2 = currentpart;
if (tiles[i]->destroy(currentpart, _save->getObjectiveType()))
@@ -144,74 +144,74 @@ void MCDPatch::modifyData(MapDataSet *dataSet) const
{
for (std::vector<std::pair<size_t, int> >::const_iterator i = _bigWalls.begin(); i != _bigWalls.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setBigWall(i->second);
dataSet->getObject(i->first)->setBigWall(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _TUWalks.begin(); i != _TUWalks.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setTUWalk(i->second);
dataSet->getObject(i->first)->setTUWalk(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _TUFlys.begin(); i != _TUFlys.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setTUFly(i->second);
dataSet->getObject(i->first)->setTUFly(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _TUSlides.begin(); i != _TUSlides.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setTUSlide(i->second);
dataSet->getObject(i->first)->setTUSlide(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _deathTiles.begin(); i != _deathTiles.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setDieMCD(i->second);
dataSet->getObject(i->first)->setDieMCD(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _terrainHeight.begin(); i != _terrainHeight.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setTerrainLevel(i->second);
dataSet->getObject(i->first)->setTerrainLevel(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _specialTypes.begin(); i != _specialTypes.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setSpecialType(i->second, dataSet->getObjects()->at(i->first)->getObjectType());
dataSet->getObject(i->first)->setSpecialType(i->second, dataSet->getObject(i->first)->getObjectType());
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _explosives.begin(); i != _explosives.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setExplosive(i->second);
dataSet->getObject(i->first)->setExplosive(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _armors.begin(); i != _armors.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setArmor(i->second);
dataSet->getObject(i->first)->setArmor(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _flammabilities.begin(); i != _flammabilities.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setFlammable(i->second);
dataSet->getObject(i->first)->setFlammable(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _fuels.begin(); i != _fuels.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setFuel(i->second);
dataSet->getObject(i->first)->setFuel(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _HEBlocks.begin(); i != _HEBlocks.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setHEBlock(i->second);
dataSet->getObject(i->first)->setHEBlock(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _footstepSounds.begin(); i != _footstepSounds.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setFootstepSound(i->second);
dataSet->getObject(i->first)->setFootstepSound(i->second);
}
for (std::vector<std::pair<size_t, int> >::const_iterator i = _objectTypes.begin(); i != _objectTypes.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setObjectType((TilePart)i->second);
dataSet->getObject(i->first)->setObjectType((TilePart)i->second);
}
for (std::vector<std::pair<size_t, bool> >::const_iterator i = _noFloors.begin(); i != _noFloors.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setNoFloor(i->second);
dataSet->getObject(i->first)->setNoFloor(i->second);
}
for (std::vector<std::pair<size_t, bool> >::const_iterator i = _stopLOSses.begin(); i != _stopLOSses.end(); ++i)
{
dataSet->getObjects()->at(i->first)->setStopLOS(i->second);
dataSet->getObject(i->first)->setStopLOS(i->second);
}
for (std::vector<std::pair<size_t, std::vector<int> > >::const_iterator i = _LOFTS.begin(); i != _LOFTS.end(); ++i)
{
int layer = 0;
for (std::vector<int>::const_iterator j = i->second.begin(); j != i->second.end(); ++j)
{
dataSet->getObjects()->at(i->first)->setLoftID(*j, layer);
dataSet->getObject(i->first)->setLoftID(*j, layer);
++layer;
}
}
@@ -19,6 +19,7 @@
#include "MapDataSet.h"
#include "MapData.h"
#include <fstream>
#include <sstream>
#include <SDL_endian.h>
#include "../Engine/Exception.h"
#include "../Engine/SurfaceSet.h"
@@ -45,18 +46,6 @@ MapDataSet::~MapDataSet()
unloadData();
}

/**
* Loads the map data set from a YAML file.
* @param node YAML node.
*/
void MapDataSet::load(const YAML::Node &node)
{
for (YAML::const_iterator i = node.begin(); i != node.end(); ++i)
{
_name = i->as<std::string>(_name);
}
}

/**
* Gets the MapDataSet name (string).
* @return The MapDataSet name.
@@ -76,12 +65,19 @@ size_t MapDataSet::getSize() const
}

/**
* Gets the objects in this dataset.
* @return Pointer to the objects.
* Gets an object in this dataset.
* @param i Object index.
* @return Pointer to the object.
*/
std::vector<MapData*> *MapDataSet::getObjects()
MapData *MapDataSet::getObject(size_t i)
{
return &_objects;
if (i >= _objects.size())
{
std::ostringstream ss;
ss << "MCD " << _name << " has no object " << i;
throw Exception(ss.str());
}
return _objects[i];
}

/**
@@ -213,11 +209,28 @@ void MapDataSet::loadData()

if (!mapFile.eof())
{
throw Exception("Invalid MCD file");
throw Exception("Invalid MCD file " + fname);
}

mapFile.close();

// Validate MCD references
for (size_t i = 0; i < _objects.size(); ++i)
{
if (_objects[i]->getDieMCD() >= _objects.size())
{
std::ostringstream ss;
ss << "MCD " << _name << " object " << i << " has invalid DieMCD: " << _objects[i]->getDieMCD();
throw Exception(ss.str());
}
if (_objects[i]->getAltMCD() >= _objects.size())
{
std::ostringstream ss;
ss << "MCD " << _name << " object " << i << " has invalid AltMCD: " << _objects[i]->getAltMCD();
throw Exception(ss.str());
}
}

// Load terrain sprites/surfaces/PCK files into a surfaceset
_surfaceSet = new SurfaceSet(32, 40);
_surfaceSet->loadPck(FileMap::getFilePath("TERRAIN/" + _name + ".PCK"),
@@ -231,11 +244,11 @@ void MapDataSet::unloadData()
{
if (_loaded)
{
for (std::vector<MapData*>::iterator i = _objects.begin(); i != _objects.end();)
for (std::vector<MapData*>::iterator i = _objects.begin(); i != _objects.end(); ++i)
{
delete *i;
i = _objects.erase(i);
}
_objects.clear();
delete _surfaceSet;
_loaded = false;
}
@@ -46,16 +46,14 @@ class MapDataSet
public:
MapDataSet(const std::string &name);
~MapDataSet();
/// Loads the map data set from YAML.
void load(const YAML::Node& node);
/// Loads voxeldata from a DAT file.
static void loadLOFTEMPS(const std::string &filename, std::vector<Uint16> *voxelData);
/// Gets the dataset name (used for MAP generation).
std::string getName() const;
/// Gets the dataset size.
size_t getSize() const;
/// Gets the objects in this dataset.
std::vector<MapData*> *getObjects();
/// Gets an object in this dataset.
MapData *getObject(size_t i);
/// Gets the surfaces in this dataset.
SurfaceSet *getSurfaceset() const;
/// Loads the objects from an MCD file.
@@ -193,7 +193,7 @@ MapData *RuleTerrain::getMapData(unsigned int *id, int *mapDataSetID) const
*id = 0;
*mapDataSetID = 0;
}
return mdf->getObjects()->at(*id);
return mdf->getObject(*id);
}

/**
@@ -361,7 +361,7 @@ void SavedBattleGame::loadMapResources(Mod *mod)
_tiles[i]->getMapData(&mdID, &mdsID, tp);
if (mdID != -1 && mdsID != -1)
{
_tiles[i]->setMapData(_mapDataSets[mdsID]->getObjects()->at(mdID), mdID, mdsID, tp);
_tiles[i]->setMapData(_mapDataSets[mdsID]->getObject(mdID), mdID, mdsID, tp);
}
}
}
@@ -347,8 +347,8 @@ int Tile::openDoor(TilePart part, BattleUnit *unit, BattleActionType reserve)
return 4;
if (_unit && _unit != unit && _unit->getPosition() != getPosition())
return -1;
setMapData(_objects[part]->getDataset()->getObjects()->at(_objects[part]->getAltMCD()), _objects[part]->getAltMCD(), _mapDataSetID[part],
_objects[part]->getDataset()->getObjects()->at(_objects[part]->getAltMCD())->getObjectType());
setMapData(_objects[part]->getDataset()->getObject(_objects[part]->getAltMCD()), _objects[part]->getAltMCD(), _mapDataSetID[part],
_objects[part]->getDataset()->getObject(_objects[part]->getAltMCD())->getObjectType());
setMapData(0, -1, -1, part);
return 0;
}
@@ -476,7 +476,7 @@ bool Tile::destroy(TilePart part, SpecialTileType type)
setMapData(0, -1, -1, part);
if (originalPart->getDieMCD())
{
MapData *dead = originalPart->getDataset()->getObjects()->at(originalPart->getDieMCD());
MapData *dead = originalPart->getDataset()->getObject(originalPart->getDieMCD());
setMapData(dead, originalPart->getDieMCD(), originalMapDataSetID, dead->getObjectType());
}
if (originalPart->getExplosive())

0 comments on commit 1443422

Please sign in to comment.
You can’t perform that action at this time.