diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2007-06-01 02:54:29 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2007-06-01 02:54:29 +0000 |
| commit | f71140fae5218ee9839ffcd4ec83abfded5124f4 (patch) | |
| tree | 9af8f2174728cedb93580411223bc59fd9a86d0a /pokemod/Map.cpp | |
| parent | 9e28e6ecd358a9801ad25914d3e8cca7b6d7f4f7 (diff) | |
| download | sigen-f71140fae5218ee9839ffcd4ec83abfded5124f4.tar.gz sigen-f71140fae5218ee9839ffcd4ec83abfded5124f4.tar.xz sigen-f71140fae5218ee9839ffcd4ec83abfded5124f4.zip | |
Added Map and Tile, added Hat class, and fixed up some other minor things
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@17 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Map.cpp')
| -rw-r--r-- | pokemod/Map.cpp | 661 |
1 files changed, 661 insertions, 0 deletions
diff --git a/pokemod/Map.cpp b/pokemod/Map.cpp new file mode 100644 index 00000000..f0349f50 --- /dev/null +++ b/pokemod/Map.cpp @@ -0,0 +1,661 @@ +/////////////////////////////////////////////////////////////////////////////
+// Name: pokemod/Map.cpp
+// Purpose: Define a map for the game
+// Author: Ben Boeckel
+// Modified by: Ben Boeckel
+// Created: Mon May 28 21:45:48 2007
+// Copyright: ©2007 Nerdy Productions
+// Licence:
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTMap or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+/////////////////////////////////////////////////////////////////////////////
+
+#include "Map.h"
+
+extern PokeGen::PokeMod::Pokemod curPokeMod;
+
+PokeGen::PokeMod::Map::Map(const unsigned _id)
+{
+ LogCtor("Map", id);
+ name = "";
+ flyWarp = 0;
+ type = 0;
+ effects.clear();
+ trainers.clear();
+ warps.clear();
+ wildLists.clear();
+ id = _id;
+}
+
+PokeGen::PokeMod::Map::Map(Ini &ini, const unsigned _id)
+{
+ LogCtorIni("Map", id);
+ ImportIni(ini, _id);
+ if (id == UINT_MAX)
+ LogIdError("Map");
+}
+
+PokeGen::PokeMod::Map::~Map()
+{
+ LogDtor("Map", id, name);
+}
+
+void PokeGen::PokeMod::Map::Validate()
+{
+ LogValidateStart("Map", id, name);
+ // Make sure the name is set to something
+ if (name == "")
+ {
+ LogVarNotSet("Map", id, "name");
+ isValid = false;
+ }
+ if (!GetMapWarp(flyWarp))
+ {
+ LogVarNotValid("Map", id, "flyWarp", name);
+ isValid = false;
+ }
+ if (type < MTY_END)
+ {
+ LogVarNotValid("Map", id, "type", name);
+ isValid = false;
+ }
+ // Check if there are any effects defined
+ if (GetMapEffectCount())
+ {
+ // Validate each effect
+ for (std::vector<MapEffect>::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;
+ }
+ }
+ else
+ LogSubmoduleEmpty("Map", id, "effect", name);
+ // Check if there are any trainers defined
+ if (GetMapTrainerCount())
+ {
+ // Validate each trainer
+ for (std::vector<MapTrainer>::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;
+ }
+ }
+ else
+ LogSubmoduleEmpty("Map", id, "trainer", name);
+ // Check if there are any warps defined
+ if (GetMapWarpCount())
+ {
+ // Validate each warp
+ for (std::vector<MapWarp>::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;
+ }
+ }
+ 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<MapWildList>::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;
+ }
+ }
+ else
+ LogSubmoduleEmpty("Map", id, "effect", name);
+ LogValidateOver("Map", id, isValid, name);
+}
+
+#ifdef PG_DEBUG_WINDOW
+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);
+ output.Append(ConsoleLogVarNotSet("Map", id, "name", name));
+ isValid = false;
+ }
+ if (!GetWarp(flyWarp))
+ {
+ LogVarNotValid("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));
+ isValid = false;
+ }
+ // Check if there are any effects defined
+ if (GetMapEffectCount())
+ {
+ // Validate each effect
+ for (std::vector<MapEffect>::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;
+ }
+ }
+ 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<MapTrainer>::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;
+ }
+ }
+ 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<MapWarp>::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;
+ }
+ }
+ else
+ {
+ LogSubmoduleEmpty("Map", id, "warp", id, name);
+ 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<MapWildList>::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;
+ }
+ }
+ else
+ {
+ LogSubmoduleEmpty("Map", id, "effect", id, name);
+ output.Append(ConsoleLogSubmoduleEmpty("Map", id, "effect", name));
+ isValid = false;
+ }
+ LogValidateOver("Map", id, isValid, name);
+}
+#endif
+
+void PokeGen::PokeMod::Map::ImportIni(Ini &ini, const unsigned _id)
+{
+ LogImportStart("Map");
+ if (_id == UINT_MAX)
+ {
+ ini.GetValue("id", id, UINT_MAX);
+ // Was there an id associated with the element?
+ if (id == UINT_MAX)
+ LogIdNotFound("Map");
+ }
+ else
+ id = _id;
+ ini.GetValue("name", name, "");
+ ini.GetValue("flyWarp", flyWarp, 0);
+ ini.GetValue("type", type, 0);
+ effects.clear();
+ trainers.clear();
+ warps.clear();
+ wildLists.clear();
+ LogImportOver("Map", id, name);
+}
+
+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.Export(fout);
+ for (std::vector<MapEffect>::const_iterator i = effects.begin(); i != effects.end(); ++i)
+ i->ExportIni(fout, name);
+ for (std::vector<MapTrainer>::const_iterator j = trainers.begin(); j != trainers.end(); ++j)
+ j->ExportIni(fout, name);
+ for (std::vector<MapWarp>::const_iterator k = warps.begin(); k != warps.end(); ++k)
+ k->ExportIni(fout, name);
+ for (std::vector<MapWildList>::const_iterator l = wildLists.begin(); l != wildLists.end(); ++l)
+ l->ExportIni(fout, name);
+ LogExportOver("Map", id, name);
+}
+
+void PokeGen::PokeMod::Map::SetName(const String &n)
+{
+ LogSetVar("Map", id, "name", n);
+ name = n;
+}
+
+void PokeGen::PokeMod::Map::SetFlyWarp(const unsigned f)
+{
+ LogSetVar("Map", id, "flyWarp", f, name);
+ if (GetMapWarp(f))
+ flyWarp = f;
+}
+
+void PokeGen::PokeMod::Map::SetFlyWarp(const String &f)
+{
+ LogSetVar("Map", id, "flyWarp string", f, name);
+ if (const MapWarp *m = GetMapWarp(f))
+ flyWarp = m->GetId();
+}
+
+void PokeGen::PokeMod::Map::SetType(const unsigned t)
+{
+ LogSetVar("Map", id, "type", t, name);
+ if (t < MTY_END)
+ type = t;
+}
+
+void PokeGen::PokeMod::Map::SetType(const String &t)
+{
+ LogSetVar("Map", id, "type string", t, name);
+ type = FindIn(MTY_END, t, MapTypeStr);
+}
+
+PokeGen::PokeMod::String PokeGen::PokeMod::Map::GetName() const
+{
+ LogFetchVar("Map", id, "name", name);
+ return name;
+}
+
+unsigned PokeGen::PokeMod::Map::GetFlyWarp() const
+{
+ LogFetchVar("Map", id, "flyWarp", flyWarp, name);
+ return flyWarp;
+}
+
+PokeGen::PokeMod::String PokeGen::PokeMod::Map::GetFlyWarpString() const
+{
+ LogFetchVar("Map", id, "flyWarp string", flyWarp, name);
+ if (const MapWarp *m = GetMapWarp(flyWarp))
+ return m->GetName();
+ return "";
+}
+
+unsigned PokeGen::PokeMod::Map::GetType() const
+{
+ LogFetchVar("Map", id, "type", type, name);
+ return type;
+}
+
+PokeGen::PokeMod::String PokeGen::PokeMod::Map::GetTypeString() const
+{
+ LogFetchVar("Map", id, "type string", type, name);
+ if (type < MTY_END)
+ return MapTypeStr[type];
+ return "";
+}
+
+void PokeGen::PokeMod::Map::SetTile(unsigned x, unsigned y, unsigned _id)
+{
+ if (curPokeMod.GetTile(_id))
+ tiles[x][y] = _id;
+}
+
+void PokeGen::PokeMod::Map::InsertColumn(unsigned x)
+{
+ tiles.InsertCol(x, 0);
+}
+
+void PokeGen::PokeMod::Map::InsertRow(unsigned y)
+{
+ tiles.InsertRow(y, 0);
+}
+
+void PokeGen::PokeMod::Map::AddColumn()
+{
+ tiles.AddCol(0);
+}
+
+void PokeGen::PokeMod::Map::AddRow()
+{
+ tiles.AddRow(0);
+}
+
+void PokeGen::PokeMod::Map::DeleteColumn(unsigned x)
+{
+ tiles.DeleteCol(x);
+}
+
+void PokeGen::PokeMod::Map::DeleteRow(unsigned y)
+{
+ tiles.DeleteRow(y);
+}
+
+unsigned PokeGen::PokeMod::Map::GetTile(unsigned x, unsigned y) const
+{
+ return tiles[x][y];
+}
+
+unsigned PokeGen::PokeMod::Map::GetWidth() const
+{
+ return tiles.GetWidth();
+}
+
+unsigned PokeGen::PokeMod::Map::GetHeight() const
+{
+ return tiles.GetHeight();
+}
+
+const PokeGen::PokeMod::MapEffect *PokeGen::PokeMod::Map::GetMapEffect(const unsigned _id) const
+{
+ LogSubmoduleFetch("Map", id, "effect", _id, name);
+ for (unsigned i = 0; i < GetMapEffectCount(); ++i)
+ {
+ if (effects[i].GetId() == _id)
+ return &effects[i];
+ }
+ LogSubmoduleFetchFail("Map", id, "effect", _id, name);
+ return NULL;
+}
+
+const PokeGen::PokeMod::MapEffect *PokeGen::PokeMod::Map::GetMapEffect(const String &n) const
+{
+ LogSubmoduleFetch("Map", id, "effect", n, name);
+ for (unsigned i = 0; i < GetMapEffectCount(); ++i)
+ {
+ if (effects[i].GetName() == n)
+ return &effects[i];
+ }
+ LogSubmoduleFetchFail("Map", id, "effect", n, name);
+ return NULL;
+}
+
+unsigned PokeGen::PokeMod::Map::GetMapEffectCount() const
+{
+ LogSubmoduleCount("Map", id, "effects", name);
+ return effects.size();
+}
+
+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))
+ break;
+ }
+ MapEffect newMapEffect(i);
+ if (ini)
+ newMapEffect.ImportIni(*ini);
+ LogSubmoduleNew("Map", id, "effect", i, name);
+ effects.push_back(newMapEffect);
+}
+
+void PokeGen::PokeMod::Map::DeleteMapEffect(const unsigned _id)
+{
+ LogSubmoduleRemoveStart("Map", id, "effect", _id, name);
+ for (std::vector<MapEffect>::const_iterator i = effects.begin(); i != effects.end(); ++i)
+ {
+ if (i->GetId() == _id)
+ {
+ LogSubmoduleRemoved("Map", id, "effect", _id, name);
+ effects.erase(i);
+ }
+ }
+ LogSubmoduleRemoveFail("Map", id, "effect", _id, name);
+}
+
+void PokeGen::PokeMod::Map::DeleteMapEffect(const String &n)
+{
+ LogSubmoduleRemoveStart("Map", id, "effect", n, name);
+ for (std::vector<MapEffect>::const_iterator i = effects.begin(); i != effects.end(); ++i)
+ {
+ if (i->GetName() == n)
+ {
+ LogSubmoduleRemoved("Map", id, "effect", n, name);
+ effects.erase(i);
+ }
+ }
+ LogSubmoduleRemoveFail("Map", id, "effect", n, name);
+}
+
+const PokeGen::PokeMod::MapTrainer *PokeGen::PokeMod::Map::GetMapTrainer(const unsigned _id) const
+{
+ LogSubmoduleFetch("Map", id, "trainer", _id, name);
+ for (unsigned i = 0; i < GetMapTrainerCount(); ++i)
+ {
+ if (trainers[i].GetId() == _id)
+ return &trainers[i];
+ }
+ LogSubmoduleFetchFail("Map", id, "trainer", _id, name);
+ return NULL;
+}
+
+const PokeGen::PokeMod::MapTrainer *PokeGen::PokeMod::Map::GetMapTrainer(const String &n) const
+{
+ LogSubmoduleFetch("Map", id, "trainer", n, name);
+ for (unsigned i = 0; i < GetMapTrainerCount(); ++i)
+ {
+ if (trainers[i].GetName() == n)
+ return &trainers[i];
+ }
+ LogSubmoduleFetchFail("Map", id, "trainer", n, name);
+ return NULL;
+}
+
+unsigned PokeGen::PokeMod::Map::GetMapTrainerCount() const
+{
+ LogSubmoduleCount("Map", id, "trainer", name);
+ return trainers.size();
+}
+
+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))
+ break;
+ }
+ MapTrainer newMapTrainer(i);
+ if (ini)
+ newMapTrainer.ImportIni(*ini);
+ LogSubmoduleNew("Map", id, "trainer", i, name);
+ trainers.push_back(newMapTrainer);
+}
+
+void PokeGen::PokeMod::Map::DeleteMapTrainer(const unsigned _id)
+{
+ LogSubmoduleRemoveStart("Map", id, "trainer", _id, name);
+ for (std::vector<MapTrainer>::const_iterator i = trainers.begin(); i != trainers.end(); ++i)
+ {
+ if (i->GetId() == _id)
+ {
+ LogSubmoduleRemoved("Map", id, "trainer", _id, name);
+ trainers.erase(i);
+ }
+ }
+ LogSubmoduleRemoveFail("Map", id, "trainer", _id, name);
+}
+
+void PokeGen::PokeMod::Map::DeleteMapTrainer(const String &n)
+{
+ LogSubmoduleRemoveStart("Map", id, "trainer", n, name);
+ for (std::vector<MapTrainer>::const_iterator i = trainers.begin(); i != trainers.end(); ++i)
+ {
+ if (i->GetName() == n)
+ {
+ LogSubmoduleRemoved("Map", id, "trainer", n, name);
+ trainers.erase(i);
+ }
+ }
+ LogSubmoduleRemoveFail("Map", id, "trainer", n, name);
+}
+
+const PokeGen::PokeMod::MapWarp *PokeGen::PokeMod::Map::GetMapWarp(const unsigned _id) const
+{
+ LogSubmoduleFetch("Map", id, "warp", _id, name);
+ for (unsigned i = 0; i < GetMapWarpCount(); ++i)
+ {
+ if (warps[i].GetId() == _id)
+ return &warps[i];
+ }
+ LogSubmoduleFetchFail("Map", id, "warp", _id, name);
+ return NULL;
+}
+
+const PokeGen::PokeMod::MapWarp *PokeGen::PokeMod::Map::GetMapWarp(const String &n) const
+{
+ LogSubmoduleFetch("Map", id, "warp", n, name);
+ for (unsigned i = 0; i < GetMapWarpCount(); ++i)
+ {
+ if (warps[i].GetName() == n)
+ return &warps[i];
+ }
+ LogSubmoduleFetchFail("Map", id, "warp", n, name);
+ return NULL;
+}
+
+unsigned PokeGen::PokeMod::Map::GetMapWarpCount() const
+{
+ LogSubmoduleCount("Map", id, "warp", name);
+ return warps.size();
+}
+
+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))
+ break;
+ }
+ MapWarp newMapWarp(i);
+ if (ini)
+ newMapWarp.ImportIni(*ini);
+ LogSubmoduleNew("Map", id, "warp", i, name);
+ warps.push_back(newMapWarp);
+}
+
+void PokeGen::PokeMod::Map::DeleteMapWarp(const unsigned _id)
+{
+ LogSubmoduleRemoveStart("Map", id, "warp", _id, name);
+ for (std::vector<MapWarp>::const_iterator i = warps.begin(); i != warps.end(); ++i)
+ {
+ if (i->GetId() == _id)
+ {
+ LogSubmoduleRemoved("Map", id, "warp", _id, name);
+ warps.erase(i);
+ }
+ }
+ LogSubmoduleRemoveFail("Map", id, "warp", _id, name);
+}
+
+void PokeGen::PokeMod::Map::DeleteMapWarp(const String &n)
+{
+ LogSubmoduleRemoveStart("Map", id, "warp", n, name);
+ for (std::vector<MapWarp>::const_iterator i = warps.begin(); i != warps.end(); ++i)
+ {
+ if (i->GetName() == n)
+ {
+ LogSubmoduleRemoved("Map", id, "warp", n, name);
+ warps.erase(i);
+ }
+ }
+ LogSubmoduleRemoveFail("Map", id, "warp", n, name);
+}
+
+const PokeGen::PokeMod::MapWildList *PokeGen::PokeMod::Map::GetMapWildList(const unsigned _id) const
+{
+ LogSubmoduleFetch("Map", id, "wild list", _id, name);
+ for (unsigned i = 0; i < GetMapWildListCount(); ++i)
+ {
+ if (wildLists[i].GetId() == _id)
+ return &wildLists[i];
+ }
+ LogSubmoduleFetchFail("Map", id, "wild list", _id, name);
+ return NULL;
+}
+
+unsigned PokeGen::PokeMod::Map::GetMapWildListCount() const
+{
+ LogSubmoduleCount("Map", id, "wild list", name);
+ return wildLists.size();
+}
+
+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))
+ break;
+ }
+ MapWildList newMapWildList(i);
+ if (ini)
+ newMapWildList.ImportIni(*ini);
+ LogSubmoduleNew("Map", id, "wild list", i, name);
+ wildLists.push_back(newMapWildList);
+}
+
+void PokeGen::PokeMod::Map::DeleteMapWildList(const unsigned _id)
+{
+ LogSubmoduleRemoveStart("Map", id, "wild list", _id, name);
+ for (std::vector<MapWildList>::const_iterator i = wildLists.begin(); i != wildLists.end(); ++i)
+ {
+ if (i->GetId() == _id)
+ {
+ LogSubmoduleRemoved("Map", id, "wild list", _id, name);
+ wildLists.erase(i);
+ }
+ }
+ LogSubmoduleRemoveFail("Map", id, "wild list", _id, name);
+}
|
