From 3595239f08f2bc1df32ef22ed6de9bde10ca3384 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 4 Jun 2007 01:35:20 +0000 Subject: Style cleanup, minor Matrix fixes, duplication validations, Pokemod methods git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@19 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/Map.cpp | 297 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 257 insertions(+), 40 deletions(-) (limited to 'pokemod/Map.cpp') diff --git a/pokemod/Map.cpp b/pokemod/Map.cpp index 32728d90..20db2d5d 100644 --- a/pokemod/Map.cpp +++ b/pokemod/Map.cpp @@ -26,9 +26,9 @@ extern PokeGen::PokeMod::Pokemod curPokeMod; PokeGen::PokeMod::Map::Map(const unsigned _id) : - name(""), - flyWarp(UINT_MAX), - type(UINT_MAX) + name(""), + flyWarp(UINT_MAX), + type(UINT_MAX) { LogCtor("Map", id); id = _id; @@ -50,7 +50,6 @@ PokeGen::PokeMod::Map::~Map() void PokeGen::PokeMod::Map::Validate() { LogValidateStart("Map", id, name); - // Make sure the name is set to something if (name == "") { LogVarNotSet("Map", id, "name"); @@ -66,65 +65,166 @@ void PokeGen::PokeMod::Map::Validate() LogVarNotValid("Map", id, "type", name); isValid = false; } - // Check if there are any effects defined + std::map idChecker; + std::map nameChecker; if (GetMapEffectCount()) { - // Validate each effect for (std::vector::iterator i = effects.begin(); i != effects.end(); ++i) { LogSubmoduleIterate("Map", id, "effect", i->GetId(), name); - // If an effect isn't valid, neither is the map if (!i->IsValid()) isValid = false; + if (GetWidth() <= i->GetCoordinateX()) + { + LogVarNotValid("MapEffect", i->GetId(), "x", i->GetName()); + isValid = false; + } + if (GetHeight() <= i->GetCoordinateY()) + { + LogVarNotValid("MapEffect", i->GetId(), "y", i->GetName()); + isValid = false; + } + ++idChecker[i->GetId()]; + ++nameChecker[i->GetName()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Map", id, "effect", i->first, name); + isValid = false; + } } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Map", id, "effect", i->first, name); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); } else LogSubmoduleEmpty("Map", id, "effect", name); - // Check if there are any trainers defined if (GetMapTrainerCount()) { - // Validate each trainer for (std::vector::iterator i = trainers.begin(); i != trainers.end(); ++i) { LogSubmoduleIterate("Map", id, "trainer", i->GetId(), name); - // If a trainer isn't valid, neither is the map if (!i->IsValid()) isValid = false; + if (GetWidth() <= i->GetCoordinateX()) + { + LogVarNotValid("MapTrainer", i->GetId(), "x", i->GetName()); + isValid = false; + } + if (GetHeight() <= i->GetCoordinateY()) + { + LogVarNotValid("MapTrainer", i->GetId(), "y", i->GetName()); + isValid = false; + } + ++idChecker[i->GetId()]; + ++nameChecker[i->GetName()]; } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Map", id, "trainer", i->first, name); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Map", id, "trainer", i->first, name); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); } else LogSubmoduleEmpty("Map", id, "trainer", name); - // Check if there are any warps defined if (GetMapWarpCount()) { - // Validate each warp for (std::vector::iterator i = warps.begin(); i != warps.end(); ++i) { LogSubmoduleIterate("Map", id, "warp", i->GetId(), name); - // If a warp isn't valid, neither is the map if (!i->IsValid()) isValid = false; + if (GetWidth() <= i->GetCoordinateX()) + { + LogVarNotValid("MapWarp", i->GetId(), "x", i->GetName()); + isValid = false; + } + if (GetHeight() <= i->GetCoordinateY()) + { + LogVarNotValid("MapWarp", i->GetId(), "y", i->GetName()); + isValid = false; + } + ++idChecker[i->GetId()]; + ++nameChecker[i->GetName()]; } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Map", id, "warp", i->first, name); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Map", id, "warp", i->first, name); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); } else { LogSubmoduleEmpty("Map", id, "warp", name); isValid = false; } - // Check if there are any wild lists defined if (GetMapWildListCount()) { - // Validate each wild list for (std::vector::iterator i = wildLists.begin(); i != wildLists.end(); ++i) { LogSubmoduleIterate("Map", id, "wild list", i->GetId(), name); - // If a wildList isn't valid, neither is the map if (!i->IsValid()) isValid = false; + ++idChecker[i->GetId()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Map", id, "effect", i->first, name); + isValid = false; + } } + idChecker.clear(); } else LogSubmoduleEmpty("Map", id, "effect", name); + for (unsigned i = 0; i < GetWidth(); ++i) + { + for (unsigned j = 0; j < GetHeight(); ++j) + { + if (!curPokeMod.GetTile(tiles[i][j])) + { + LogVarNotValid("Map", id, String("tiles[%u][%u]", i, j), name); + isValid = false; + } + } + } LogValidateOver("Map", id, isValid, name); } @@ -132,7 +232,6 @@ void PokeGen::PokeMod::Map::Validate() void PokeGen::PokeMod::Map::Validate(const wxListBox &output) { LogValidateStart("Map", id, name); - // Make sure the name is set to something if (name == "") { LogVarNotSet("Map", id, "Name", name); @@ -142,60 +241,148 @@ void PokeGen::PokeMod::Map::Validate(const wxListBox &output) if (!GetWarp(flyWarp)) { LogVarNotValid("Map", id, "flyWarp", name); - output.append(ConsoleLogVarNotValid("Map", id, "flyWarp", name)); + output.Append(ConsoleLogVarNotValid("Map", id, "flyWarp", name)); isValid = false; } if ((MTY_NONE < type) && (type < MTY_END)) { LogVarNotValid("Map", id, "type", name); - output.append(ConsoleLogVarNotValid("Map", id, "type", name)); + output.Append(ConsoleLogVarNotValid("Map", id, "type", name)); isValid = false; } - // Check if there are any effects defined + std::map idChecker; + std::map nameChecker; if (GetMapEffectCount()) { - // Validate each effect for (std::vector::iterator i = effects.begin(); i != effects.end(); ++i) { LogSubmoduleIterate("Map", id, "effect", i->GetId(), name); - // If an effect isn't valid, neither is the map if (!i->IsValid()) isValid = false; + if (GetWidth() <= i->GetCoordinateX()) + { + LogVarNotValid("MapEffect", i->GetId(), "x", i->GetName()); + isValid = false; + } + if (GetHeight() <= i->GetCoordinateY()) + { + LogVarNotValid("MapEffect", i->GetId(), "y", i->GetName()); + isValid = false; + } + ++idChecker[i->GetId()]; + ++nameChecker[i->GetName()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Map", id, "effect", i->first, name); + output.Append(ConsoleLogDuplicateId("Map", id, "effect", i->first, name)); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Map", id, "effect", i->first, name); + output.Append(ConsoleLogDuplicateSubmodule("Map", id, "effect", i->first, name)); + isValid = false; + } } + idChecker.clear(); + nameChecker.clear(); } else { LogSubmoduleEmpty("Map", id, "effect", id, name); output.Append(ConsoleLogSubmoduleEmptyW("Map", id, "effect", name)); } - // Check if there are any trainers defined if (GetMapTrainerCount()) { - // Validate each trainer for (std::vector::iterator i = trainers.begin(); i != trainers.end(); ++i) { LogSubmoduleIterate("Map", id, "trainer", i->GetId(), name); - // If a trainer isn't valid, neither is the map if (!i->IsValid()) isValid = false; + if (GetWidth() <= i->GetCoordinateX()) + { + LogVarNotValid("MapTrainer", i->GetId(), "x", i->GetName()); + isValid = false; + } + if (GetHeight() <= i->GetCoordinateY()) + { + LogVarNotValid("MapTrainer", i->GetId(), "y", i->GetName()); + isValid = false; + } + ++idChecker[i->GetId()]; + ++nameChecker[i->GetName()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Map", id, "trainer", i->first, name); + output.Append(ConsoleLogDuplicateId("Map", id, "trainer", i->first, name)); + isValid = false; + } } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Map", id, "trainer", i->first, name); + output.Append(ConsoleLogDuplicateSubmodule("Map", id, "trainer", i->first, name)); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); } else { LogSubmoduleEmpty("Map", id, "trainer", id, name); output.Append(ConsoleLogSubmoduleEmptyW("Map", id, "trainer", name)); } - // Check if there are any warps defined if (GetMapWarpCount()) { - // Validate each warp for (std::vector::iterator i = warps.begin(); i != warps.end(); ++i) { LogSubmoduleIterate("Map", id, "warp", i->GetId(), name); - // If a warp isn't valid, neither is the map if (!i->IsValid()) isValid = false; + if (GetWidth() <= i->GetCoordinateX()) + { + LogVarNotValid("MapWarp", i->GetId(), "x", i->GetName()); + isValid = false; + } + if (GetHeight() <= i->GetCoordinateY()) + { + LogVarNotValid("MapWarp", i->GetId(), "y", i->GetName()); + isValid = false; + } + ++idChecker[i->GetId()]; + ++nameChecker[i->GetName()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Map", id, "warp", i->first, name); + output.Append(ConsoleLogDuplicateId("Map", id, "warp", i->first, name)); + isValid = false; + } } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Map", id, "warp", i->first, name); + output.Append(ConsoleLogDuplicateSubmodule("Map", id, "warp", i->first, name)); + isValid = false; + } + } + idChecker.clear(); } else { @@ -203,23 +390,42 @@ void PokeGen::PokeMod::Map::Validate(const wxListBox &output) output.Append(ConsoleLogSubmoduleEmpty("Map", id, "warp", name)); isValid = false; } - // Check if there are any wild lists defined if (GetMapWildListCount()) { - // Validate each wild list for (std::vector::iterator i = wildLists.begin(); i != wildLists.end(); ++i) { LogSubmoduleIterate("Map", id, "wild list", i->GetId(), name); - // If a wild list isn't valid, neither is the Map if (!i->IsValid()) isValid = false; + ++idChecker[i->GetId()]; } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Map", id, "effect", i->first, name); + output.Append(ConsoleLogDuplicateId("Map", id, "effect", i->first, name)); + isValid = false; + } + } + idChecker.clear(); } else { - LogSubmoduleEmpty("Map", id, "effect", id, name); - output.Append(ConsoleLogSubmoduleEmpty("Map", id, "effect", name)); - isValid = false; + LogSubmoduleEmpty("Map", id, "wild list", id, name); + output.Append(ConsoleLogSubmoduleEmptyW("Map", id, "wild list", name)); + } + for (unsigned i = 0; i < GetWidth(); ++i) + { + for (unsigned j = 0; j < GetHeight(); ++j) + { + if (!curPokeMod.GetTile(tiles[i][j])) + { + LogVarNotValid("Map", id, String("tiles[%u][%u]", i, j), name); + output.Append(ConsoleLogVarNotValid("Map", id, String("tiles[%u][%u]", i, j), name)); + isValid = false; + } + } } LogValidateOver("Map", id, isValid, name); } @@ -231,15 +437,24 @@ void PokeGen::PokeMod::Map::ImportIni(Ini &ini, const unsigned _id) if (_id == UINT_MAX) { ini.GetValue("id", id); - // Was there an id associated with the element? if (id == UINT_MAX) LogIdNotFound("Map"); } else id = _id; + unsigned i; + unsigned j; ini.GetValue("name", name); ini.GetValue("flyWarp", flyWarp); ini.GetValue("type", type); + ini.GetValue("width", i, 0); + ini.GetValue("height", j, 0); + tiles.resize(i, j, Frac(1, 1)); + for (unsigned i = 0; i < GetWidth(); ++i) + { + for (unsigned j = 0; j < GetHeight(); ++j) + ini.GetValue(String("tiles-%u-%u", i, j), tiles[i][j]); + } effects.clear(); trainers.clear(); warps.clear(); @@ -250,12 +465,18 @@ void PokeGen::PokeMod::Map::ImportIni(Ini &ini, const unsigned _id) void PokeGen::PokeMod::Map::ExportIni(std::ofstream &fout) const { LogExportStart("Map", id, name); - // Make elements Ini exMap("Map"); exMap.AddField("id", id); exMap.AddField("name", name); exMap.AddField("flyWarp", flyWarp); exMap.AddField("type", type); + exMap.AddField("width", GetWidth()); + exMap.AddField("height", GetHeight()); + for (unsigned i = 0; i < GetWidth(); ++i) + { + for (unsigned j = 0; j < GetWidth(); ++j) + exMap.AddField(String("tiles-%u-%u", i, j), tiles[i][j]); + } exMap.Export(fout); for (std::vector::const_iterator i = effects.begin(); i != effects.end(); ++i) i->ExportIni(fout, name); @@ -419,7 +640,6 @@ unsigned PokeGen::PokeMod::Map::GetMapEffectCount() const void PokeGen::PokeMod::Map::NewMapEffect(Ini *const ini) { unsigned i = 0; - // Find the first unused ID in the vector for (; i < GetMapEffectCount(); ++i) { if (!GetMapEffect(i)) @@ -493,7 +713,6 @@ unsigned PokeGen::PokeMod::Map::GetMapTrainerCount() const void PokeGen::PokeMod::Map::NewMapTrainer(Ini *const ini) { unsigned i = 0; - // Find the first unused ID in the vector for (; i < GetMapTrainerCount(); ++i) { if (!GetMapTrainer(i)) @@ -567,7 +786,6 @@ unsigned PokeGen::PokeMod::Map::GetMapWarpCount() const void PokeGen::PokeMod::Map::NewMapWarp(Ini *const ini) { unsigned i = 0; - // Find the first unused ID in the vector for (; i < GetMapWarpCount(); ++i) { if (!GetMapWarp(i)) @@ -629,7 +847,6 @@ unsigned PokeGen::PokeMod::Map::GetMapWildListCount() const void PokeGen::PokeMod::Map::NewMapWildList(Ini *const ini) { unsigned i = 0; - // Find the first unused ID in the vector for (; i < GetMapWildListCount(); ++i) { if (!GetMapWildList(i)) -- cgit