diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2007-09-21 15:36:22 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2007-09-21 15:36:22 +0000 |
| commit | 5b55d13ead7e352ee1feaae72009e8abf5bd071a (patch) | |
| tree | 6c2838312dd7f42769280e24e8abc16b53c165cb /pokemod/Map.cpp | |
| parent | e94d9893b8753e72adb92b2c5eb203830ddf641c (diff) | |
[FIX] Neural Network methods complete
[FIX] Wrapped Node up into the layer
[FIX] Wrapped NatureEffect into Nature
[FIX] Getting around to fixing up the design of the PokéMod stuff
[FIX] Creating new subclasses now returns pointer to new subclass
[FIX] Simplified interfaces
[FIX] Minor style issues
[FIX] Renamed CoinItem to CoinListObject
[FIX] Renamed MapTrainerTeam to MapTrainerPokemon
[FIX] Renamed MapWildPokemon to MapWildListPokemon
[FIX] Moved global enums to relevant classes
[FIX] Removed general logging features
[DEL] pokemod/Debug.{h, cpp}
[DEL] pokemod/Path.{h, cpp}
[FIX] Using QFile rather than custom Path class for checking for files
[FIX] Set* methods now return a bool to let the caller know if anything actually changed (if it can fail, otherwise it is void)
[ADD] Compliation without errors is required for pokemod from now on before commits
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@24 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Map.cpp')
| -rw-r--r-- | pokemod/Map.cpp | 1214 |
1 files changed, 538 insertions, 676 deletions
diff --git a/pokemod/Map.cpp b/pokemod/Map.cpp index 1765f4a5..d3c23879 100644 --- a/pokemod/Map.cpp +++ b/pokemod/Map.cpp @@ -1,676 +1,538 @@ -/////////////////////////////////////////////////////////////////////////////
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-/////////////////////////////////////////////////////////////////////////////
-
-#include "Map.h"
-
-PokeGen::PokeMod::Map::Map(const Pokemod *par, const unsigned _id) :
- name(""),
- flyWarp(UINT_MAX),
- type(UINT_MAX)
-{
- LogCtor("Map", id);
- id = _id;
- pokemod = par;
-}
-
-PokeGen::PokeMod::Map::Map(const Pokemod *par, Ini &ini, const unsigned _id)
-{
- LogCtorIni("Map", id);
- pokemod = par;
- 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);
- 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;
- }
- QMap<unsigned, unsigned> idChecker;
- QMap<QString, unsigned> nameChecker;
- if (GetMapEffectCount())
- {
- for (QList<MapEffect>::Iterator i = effects.begin(); i != effects.end(); ++i)
- {
- LogSubmoduleIterate("Map", id, "effect", i->GetId(), name);
- 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 (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateId("Map", id, "effect", i.key(), name);
- isValid = false;
- }
- }
- for (QMap<QString, unsigned>::ConstIterator i = nameChecker.begin(); i != nameChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateSubmodule("Map", id, "effect", i.key(), name);
- isValid = false;
- }
- }
- idChecker.clear();
- nameChecker.clear();
- }
- else
- LogSubmoduleEmpty("Map", id, "effect", name);
- if (GetMapTrainerCount())
- {
- for (QList<MapTrainer>::Iterator i = trainers.begin(); i != trainers.end(); ++i)
- {
- LogSubmoduleIterate("Map", id, "trainer", i->GetId(), name);
- 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 (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateId("Map", id, "trainer", i.key(), name);
- isValid = false;
- }
- }
- for (QMap<QString, unsigned>::ConstIterator i = nameChecker.begin(); i != nameChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateSubmodule("Map", id, "trainer", i.key(), name);
- isValid = false;
- }
- }
- idChecker.clear();
- nameChecker.clear();
- }
- else
- LogSubmoduleEmpty("Map", id, "trainer", name);
- if (GetMapWarpCount())
- {
- for (QList<MapWarp>::Iterator i = warps.begin(); i != warps.end(); ++i)
- {
- LogSubmoduleIterate("Map", id, "warp", i->GetId(), name);
- 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 (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateId("Map", id, "warp", i.key(), name);
- isValid = false;
- }
- }
- for (QMap<QString, unsigned>::ConstIterator i = nameChecker.begin(); i != nameChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateSubmodule("Map", id, "warp", i.key(), name);
- isValid = false;
- }
- }
- idChecker.clear();
- nameChecker.clear();
- }
- else
- {
- LogSubmoduleEmpty("Map", id, "warp", name);
- isValid = false;
- }
- if (GetMapWildListCount())
- {
- for (QList<MapWildList>::Iterator i = wildLists.begin(); i != wildLists.end(); ++i)
- {
- LogSubmoduleIterate("Map", id, "wild list", i->GetId(), name);
- if (!i->IsValid())
- isValid = false;
- ++idChecker[i->GetId()];
- }
- for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i)
- {
- if (1 < i.value())
- {
- LogDuplicateId("Map", id, "effect", i.key(), 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 (!pokemod->GetTile(tiles[i][j]))
- {
- LogVarNotValid("Map", id, QString("tiles[%u][%u]", i, j), name);
- isValid = false;
- }
- }
- }
- LogValidateOver("Map", id, isValid, name);
-}
-
-void PokeGen::PokeMod::Map::ImportIni(Ini &ini, const unsigned _id)
-{
- LogImportStart("Map");
- if (_id == UINT_MAX)
- {
- ini.GetValue("id", id);
- 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(QString("tiles-%u-%u", i, j), tiles[i][j]);
- }
- effects.clear();
- trainers.clear();
- warps.clear();
- wildLists.clear();
- LogImportOver("Map", id, name);
-}
-
-void PokeGen::PokeMod::Map::ExportIni(QFile &fout) const
-{
- LogExportStart("Map", id, name);
- 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(QString("tiles-%u-%u", i, j), tiles[i][j]);
- }
- exMap.Export(fout);
- for (QList<MapEffect>::ConstIterator i = effects.begin(); i != effects.end(); ++i)
- i->ExportIni(fout, name);
- for (QList<MapTrainer>::ConstIterator j = trainers.begin(); j != trainers.end(); ++j)
- j->ExportIni(fout, name);
- for (QList<MapWarp>::ConstIterator k = warps.begin(); k != warps.end(); ++k)
- k->ExportIni(fout, name);
- for (QList<MapWildList>::ConstIterator l = wildLists.begin(); l != wildLists.end(); ++l)
- l->ExportIni(fout, name);
- LogExportOver("Map", id, name);
-}
-
-void PokeGen::PokeMod::Map::SetName(const QString &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 QString &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 QString &t)
-{
- LogSetVar("Map", id, "type string", t, name);
- type = FindIn(MTY_END, t, MapTypeStr);
-}
-
-QString 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;
-}
-
-QString 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;
-}
-
-QString 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 (pokemod->GetTile(_id))
- tiles[x][y] = _id;
-}
-
-void PokeGen::PokeMod::Map::SetTile(unsigned x, unsigned y, const QString &n)
-{
- if (const Tile *t = pokemod->GetTile(n))
- tiles[x][y] = t->GetId();
-}
-
-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 QString &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;
- for (; i < GetMapEffectCount(); ++i)
- {
- if (!GetMapEffect(i))
- break;
- }
- MapEffect newMapEffect(pokemod, i);
- if (ini)
- newMapEffect.ImportIni(*ini);
- LogSubmoduleNew("Map", id, "effect", i, name);
- effects.append(newMapEffect);
-}
-
-void PokeGen::PokeMod::Map::DeleteMapEffect(const unsigned _id)
-{
- LogSubmoduleRemoveStart("Map", id, "effect", _id, name);
- for (QList<MapEffect>::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 QString &n)
-{
- LogSubmoduleRemoveStart("Map", id, "effect", n, name);
- for (QList<MapEffect>::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 QString &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;
- for (; i < GetMapTrainerCount(); ++i)
- {
- if (!GetMapTrainer(i))
- break;
- }
- MapTrainer newMapTrainer(pokemod, i);
- if (ini)
- newMapTrainer.ImportIni(*ini);
- LogSubmoduleNew("Map", id, "trainer", i, name);
- trainers.append(newMapTrainer);
-}
-
-void PokeGen::PokeMod::Map::DeleteMapTrainer(const unsigned _id)
-{
- LogSubmoduleRemoveStart("Map", id, "trainer", _id, name);
- for (QList<MapTrainer>::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 QString &n)
-{
- LogSubmoduleRemoveStart("Map", id, "trainer", n, name);
- for (QList<MapTrainer>::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 QString &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;
- for (; i < GetMapWarpCount(); ++i)
- {
- if (!GetMapWarp(i))
- break;
- }
- MapWarp newMapWarp(pokemod, i);
- if (ini)
- newMapWarp.ImportIni(*ini);
- LogSubmoduleNew("Map", id, "warp", i, name);
- warps.append(newMapWarp);
-}
-
-void PokeGen::PokeMod::Map::DeleteMapWarp(const unsigned _id)
-{
- LogSubmoduleRemoveStart("Map", id, "warp", _id, name);
- for (QList<MapWarp>::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 QString &n)
-{
- LogSubmoduleRemoveStart("Map", id, "warp", n, name);
- for (QList<MapWarp>::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;
- for (; i < GetMapWildListCount(); ++i)
- {
- if (!GetMapWildList(i))
- break;
- }
- MapWildList newMapWildList(pokemod, i);
- if (ini)
- newMapWildList.ImportIni(*ini);
- LogSubmoduleNew("Map", id, "wild list", i, name);
- wildLists.append(newMapWildList);
-}
-
-void PokeGen::PokeMod::Map::DeleteMapWildList(const unsigned _id)
-{
- LogSubmoduleRemoveStart("Map", id, "wild list", _id, name);
- for (QList<MapWildList>::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);
-}
+///////////////////////////////////////////////////////////////////////////// +// 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 3 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, see <http://www.gnu.org/licenses/>. +///////////////////////////////////////////////////////////////////////////// + +#include "Map.h" + +PokeGen::PokeMod::Map::Map(const Pokemod* par, const unsigned _id) : + Object(_id, par), + name(""), + flyWarp(UINT_MAX), + type(UINT_MAX) +{ +} + +PokeGen::PokeMod::Map::Map(const Pokemod* par, Ini& ini, const unsigned _id) : + Object(_id, par) +{ + ImportIni(ini, _id); +} + +bool PokeGen::PokeMod::Map::Validate() +{ + pokemod->ValidationMsg(QString("---Map \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); + if (name == "") + { + pokemod->ValidationMsg("name is not defined"); + isValid = false; + } + if ((flyWarp != UINT_MAX) && (GetWarpByID(flyWarp) == UINT_MAX)) + { + pokemod->ValidationMsg("Invalid fly destination warp"); + isValid = false; + } + if (type < End) + { + pokemod->ValidationMsg("Invalid type"); + isValid = false; + } + QMap<unsigned, unsigned> idChecker; + QMap<QString, unsigned> nameChecker; + if (GetEffectCount()) + { + for (QList<MapEffect>::Iterator i = effects.begin(); i != effects.end(); ++i) + { + if (!i->IsValid()) + isValid = false; + if (GetWidth() <= i->GetCoordinateX()) + { + pokemod->ValidationMsg("Invalid x coordinate"); + isValid = false; + } + if (GetHeight() <= i->GetCoordinateY()) + { + pokemod->ValidationMsg("Invalid y coordinate"); + isValid = false; + } + ++idChecker[i->GetId()]; + ++nameChecker[i->GetName()]; + } + for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i.value()) + { + pokemod->ValidationMsg(QString("There are %1 effects with id %2").arg(i.value()).arg(i.key())); + isValid = false; + } + } + for (QMap<QString, unsigned>::ConstIterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i.value()) + { + pokemod->ValidationMsg(QString("There are %1 effects with the name \"%2\"").arg(i.value()).arg(i.key())); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); + } + else + pokemod->ValidationMsg("There are no effects", Pokemod::V_Warn); + if (GetTrainerCount()) + { + for (QList<MapTrainer>::Iterator i = trainers.begin(); i != trainers.end(); ++i) + { + if (!i->IsValid()) + isValid = false; + if (GetWidth() <= i->GetCoordinateX()) + { + pokemod->ValidationMsg("Invalid x coordinate"); + isValid = false; + } + if (GetHeight() <= i->GetCoordinateY()) + { + pokemod->ValidationMsg("Invalid y coordinate"); + isValid = false; + } + ++idChecker[i->GetId()]; + ++nameChecker[i->GetName()]; + } + for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i.value()) + { + pokemod->ValidationMsg(QString("There are %1 trainers with id %2").arg(i.value()).arg(i.key())); + isValid = false; + } + } + for (QMap<QString, unsigned>::ConstIterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i.value()) + { + pokemod->ValidationMsg(QString("There are %1 trainers with the name \"%2\"").arg(i.value()).arg(i.key())); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); + } + else + pokemod->ValidationMsg("There are no trainers", Pokemod::V_Warn); + if (GetWarpCount()) + { + for (QList<MapWarp>::Iterator i = warps.begin(); i != warps.end(); ++i) + { + if (!i->IsValid()) + isValid = false; + if (GetWidth() <= i->GetCoordinateX()) + { + pokemod->ValidationMsg("Invalid x coordinate"); + isValid = false; + } + if (GetHeight() <= i->GetCoordinateY()) + { + pokemod->ValidationMsg("Invalid y coordinate"); + isValid = false; + } + ++idChecker[i->GetId()]; + ++nameChecker[i->GetName()]; + } + for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i.value()) + { + pokemod->ValidationMsg(QString("There are %1 warps with id %2").arg(i.value()).arg(i.key())); + isValid = false; + } + } + for (QMap<QString, unsigned>::ConstIterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i.value()) + { + pokemod->ValidationMsg(QString("There are %1 warps with the name \"%2\"").arg(i.value()).arg(i.key())); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); + } + else + { + pokemod->ValidationMsg("There are no warps"); + isValid = false; + } + if (GetWildListCount()) + { + for (QList<MapWildList>::Iterator i = wildLists.begin(); i != wildLists.end(); ++i) + { + if (!i->IsValid()) + isValid = false; + ++idChecker[i->GetId()]; + } + for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i.value()) + { + pokemod->ValidationMsg(QString("There are %1 wild lists with id %2").arg(i.value()).arg(i.key())); + isValid = false; + } + } + idChecker.clear(); + } + else + pokemod->ValidationMsg("There are no effects", Pokemod::V_Warn); + for (unsigned i = 0; i < GetWidth(); ++i) + { + for (unsigned j = 0; j < GetHeight(); ++j) + { + if (!pokemod->GetTile(tiles(i, j))) + { + pokemod->ValidationMsg(QString("Invalid tile at (%1, %2)").arg(i).arg(j)); + isValid = false; + } + } + } + return isValid; +} + +void PokeGen::PokeMod::Map::ImportIni(Ini& ini, const unsigned _id) +{ + if (_id == UINT_MAX) + ini.GetValue("id", id); + 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(QString("tiles-%1-%2").arg(i).arg(j), tiles(i, j)); + } + effects.clear(); + trainers.clear(); + warps.clear(); + wildLists.clear(); +} + +void PokeGen::PokeMod::Map::ExportIni(QFile& fout) const +{ + 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(QString("tiles-%1-%2").arg(i).arg(j), tiles(i, j)); + } + exMap.Export(fout); + for (QList<MapEffect>::ConstIterator i = effects.begin(); i != effects.end(); ++i) + i->ExportIni(fout, name); + for (QList<MapTrainer>::ConstIterator j = trainers.begin(); j != trainers.end(); ++j) + j->ExportIni(fout, name); + for (QList<MapWarp>::ConstIterator k = warps.begin(); k != warps.end(); ++k) + k->ExportIni(fout, name); + for (QList<MapWildList>::ConstIterator l = wildLists.begin(); l != wildLists.end(); ++l) + l->ExportIni(fout, name); +} + +void PokeGen::PokeMod::Map::SetName(const QString& n) +{ + name = n; +} + +bool PokeGen::PokeMod::Map::SetFlyWarp(const unsigned f) +{ + if (GetWarpByID(f) != UINT_MAX) + flyWarp = f; + return (flyWarp == f); +} + +bool PokeGen::PokeMod::Map::SetType(const unsigned t) +{ + if (t < End) + type = t; + return (type == t); +} + +QString PokeGen::PokeMod::Map::GetName() const +{ + return name; +} + +unsigned PokeGen::PokeMod::Map::GetFlyWarp() const +{ + return flyWarp; +} + +unsigned PokeGen::PokeMod::Map::GetType() const +{ + return type; +} + +bool PokeGen::PokeMod::Map::SetTile(unsigned x, unsigned y, unsigned _id) +{ + if (pokemod->GetTileByID(_id) != UINT_MAX) + tiles(x, y) = _id; + return (tiles(x, y) == _id); +} + +bool PokeGen::PokeMod::Map::InsertColumn(unsigned x) +{ + return tiles.InsertCol(x, 0); +} + +bool PokeGen::PokeMod::Map::InsertRow(unsigned y) +{ + return tiles.InsertRow(y, 0); +} + +void PokeGen::PokeMod::Map::AddColumn() +{ + tiles.AddCol(0); +} + +void PokeGen::PokeMod::Map::AddRow() +{ + tiles.AddRow(0); +} + +bool PokeGen::PokeMod::Map::DeleteColumn(unsigned x) +{ + return tiles.DeleteCol(x); +} + +bool PokeGen::PokeMod::Map::DeleteRow(unsigned y) +{ + return 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::GetEffect(const unsigned i) const +{ + if (i < GetEffectCount()) + return &effects[i]; + return NULL; +} + +unsigned PokeGen::PokeMod::Map::GetEffectByID(const unsigned _id) const +{ + for (unsigned i = 0; i < GetEffectCount(); ++i) + { + if (effects[i].GetId() == _id) + return i; + } + return UINT_MAX; +} + +unsigned PokeGen::PokeMod::Map::GetEffectCount() const +{ + return effects.size(); +} + +const PokeGen::PokeMod::MapEffect* PokeGen::PokeMod::Map::NewEffect(Ini* const ini) +{ + unsigned i = 0; + for (; i < GetEffectCount(); ++i) + { + if (GetEffectByID(i) == UINT_MAX) + break; + } + MapEffect newEffect(pokemod, i); + if (ini) + newEffect.ImportIni(*ini); + effects.append(newEffect); + return &effects[GetEffectCount() - 1]; +} + +bool PokeGen::PokeMod::Map::DeleteEffect(const unsigned i) +{ + if (i < GetEffectCount()) + { + effects.erase(effects.begin() + i); + return true; + } + return false; +} + +const PokeGen::PokeMod::MapTrainer* PokeGen::PokeMod::Map::GetTrainer(const unsigned i) const +{ + if (i < GetTrainerCount()) + return &trainers[i]; + return NULL; +} + +unsigned PokeGen::PokeMod::Map::GetTrainerByID(const unsigned _id) const +{ + for (unsigned i = 0; i < GetTrainerCount(); ++i) + { + if (trainers[i].GetId() == _id) + return i; + } + return UINT_MAX; +} + +unsigned PokeGen::PokeMod::Map::GetTrainerCount() const +{ + return trainers.size(); +} + +const PokeGen::PokeMod::MapTrainer* PokeGen::PokeMod::Map::NewTrainer(Ini* const ini) +{ + unsigned i = 0; + for (; i < GetTrainerCount(); ++i) + { + if (GetTrainerByID(i) == UINT_MAX) + break; + } + MapTrainer newTrainer(pokemod, i); + if (ini) + newTrainer.ImportIni(*ini); + trainers.append(newTrainer); + return &trainers[GetTrainerCount() - 1]; +} + +bool PokeGen::PokeMod::Map::DeleteTrainer(const unsigned i) +{ + if (i < GetTrainerCount()) + { + trainers.erase(trainers.begin() + i); + return true; + } + return false; +} + +const PokeGen::PokeMod::MapWarp* PokeGen::PokeMod::Map::GetWarp(const unsigned i) const +{ + if (i < GetWarpCount()) + return &warps[i]; + return NULL; +} + +unsigned PokeGen::PokeMod::Map::GetWarpByID(const unsigned _id) const +{ + for (unsigned i = 0; i < GetWarpCount(); ++i) + { + if (warps[i].GetId() == _id) + return i; + } + return UINT_MAX; +} + +unsigned PokeGen::PokeMod::Map::GetWarpCount() const +{ + return warps.size(); +} + +const PokeGen::PokeMod::MapWarp* PokeGen::PokeMod::Map::NewWarp(Ini* const ini) +{ + unsigned i = 0; + for (; i < GetWarpCount(); ++i) + { + if (GetWarpByID(i) == UINT_MAX) + break; + } + MapWarp newWarp(pokemod, i); + if (ini) + newWarp.ImportIni(*ini); + warps.append(newWarp); + return &warps[GetWarpCount() - 1]; +} + +bool PokeGen::PokeMod::Map::DeleteWarp(const unsigned i) +{ + if (i < GetWarpCount()) + { + warps.erase(warps.begin() + i); + return true; + } + return false; +} + +const PokeGen::PokeMod::MapWildList* PokeGen::PokeMod::Map::GetWildList(const unsigned i) const +{ + if (i < GetWildListCount()) + return &wildLists[i]; + return NULL; +} + +unsigned PokeGen::PokeMod::Map::GetWildListByID(const unsigned _id) const +{ + for (unsigned i = 0; i < GetWildListCount(); ++i) + { + if (wildLists[i].GetId() == _id) + return i; + } + return UINT_MAX; +} + +unsigned PokeGen::PokeMod::Map::GetWildListCount() const +{ + return wildLists.size(); +} + +const PokeGen::PokeMod::MapWildList* PokeGen::PokeMod::Map::NewWildList(Ini* const ini) +{ + unsigned i = 0; + for (; i < GetWildListCount(); ++i) + { + if (GetWildListByID(i) == UINT_MAX) + break; + } + MapWildList newWildList(pokemod, i); + if (ini) + newWildList.ImportIni(*ini); + wildLists.append(newWildList); + return &wildLists[GetWildListCount() - 1]; +} + +bool PokeGen::PokeMod::Map::DeleteWildList(const unsigned i) +{ + if (i < GetWildListCount()) + { + wildLists.erase(wildLists.begin() + i); + return true; + } + return false; +} |
