From 5b55d13ead7e352ee1feaae72009e8abf5bd071a Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 21 Sep 2007 15:36:22 +0000 Subject: [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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@24 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/MapTrainer.cpp | 914 ++++++++++++++++++++++--------------------------- 1 file changed, 408 insertions(+), 506 deletions(-) (limited to 'pokemod/MapTrainer.cpp') diff --git a/pokemod/MapTrainer.cpp b/pokemod/MapTrainer.cpp index e1c9e4fb..66b3b99b 100644 --- a/pokemod/MapTrainer.cpp +++ b/pokemod/MapTrainer.cpp @@ -1,506 +1,408 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapTrainer.cpp -// Purpose: Define a trainer for a map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri June 1 2007 23:11:28 -// 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 -// MERCHANTABILITY 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 . -///////////////////////////////////////////////////////////////////////////// - -#include "MapTrainer.h" - -PokeGen::PokeMod::MapTrainer::MapTrainer(const Pokemod *par, const unsigned _id) : - name(""), - coordinate(0, 0), - skin(""), - sight(0), - direction(UINT_MAX), - numFight(1), - ai(""), - appearFlag(0, 0), - overworldDialog(UINT_MAX), - winDialog(UINT_MAX), - loseDialog(UINT_MAX), - leadPokemon(UINT_MAX) -{ - LogCtor("MapTrainer", _id); - id = _id; - pokemod = par; -} - -PokeGen::PokeMod::MapTrainer::MapTrainer(const Pokemod *par, Ini &ini, const unsigned _id) -{ - LogCtorIni("MapTrainer", _id); - pokemod = par; - ImportIni(ini, _id); - if (id == UINT_MAX) - LogIdError("MapTrainer"); -} - -PokeGen::PokeMod::MapTrainer::~MapTrainer() -{ - LogDtor("MapTrainer", id, name); -} - -void PokeGen::PokeMod::MapTrainer::Validate() -{ - LogValidateStart("MapTrainer", id, name); - if (name == "") - { - LogVarNotSet("MapTrainer", id, "name"); - isValid = false; - } - if (!Path(pokemod->GetPath() + "skins/" + skin).DoesExist()) - { - LogVarNotValid("MapTrainer", id, "skin", name); - isValid = false; - } - if (DIR_END_NONE <= direction) - { - LogVarNotValid("MapTrainer", id, "direction", name); - isValid = false; - } - if (!numFight || (pokemod->GetMaxFight() < numFight)) - { - LogVarNotValid("MapTrainer", id, "maxFight", name); - isValid = false; - } - if (!Path(pokemod->GetPath() + "ai/" + ai).DoesExist()) - { - LogVarNotValid("MapTrainer", id, "ai", name); - isValid = false; - } - if (!pokemod->GetDialog(overworldDialog)) - { - LogVarNotValid("MapTrainer", id, "overworldDialog", name); - isValid = false; - } - if (!pokemod->GetDialog(winDialog)) - { - LogVarNotValid("MapTrainer", id, "winDialog", name); - isValid = false; - } - if (!pokemod->GetDialog(loseDialog)) - { - LogVarNotValid("MapTrainer", id, "loseDialog", name); - isValid = false; - } - if (!GetMapTrainerTeam(leadPokemon)) - { - LogVarNotValid("MapTrainer", id, "leadPokemon", name); - isValid = false; - } - if (GetMapTrainerTeamCount()) - { - QMap idChecker; - for (QList::Iterator i = team.begin(); i != team.end(); ++i) - { - LogSubmoduleIterate("MapTrainer", id, "team Pokémon", i->GetId(), name); - if (!i->IsValid()) - isValid = false; - ++idChecker[i->GetId()]; - } - for (QMap::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i) - { - if (1 < i.value()) - { - LogDuplicateId("MapTrainer", id, "team Pokémon", i.key(), name); - isValid = false; - } - } - } - else - { - LogSubmoduleEmpty("MapTrainer", id, "team Pokémon", name); - isValid = false; - } - LogValidateOver("MapTrainer", id, isValid, name); -} - -void PokeGen::PokeMod::MapTrainer::ImportIni(Ini &ini, const unsigned _id) -{ - LogImportStart("MapTrainer"); - if (_id == UINT_MAX) - { - ini.GetValue("id", id); - if (id == UINT_MAX) - LogIdNotFound("MapTrainer"); - } - else - id = _id; - unsigned i; - unsigned j; - ini.GetValue("name", name); - ini.GetValue("coordinate-x", i, 0); - ini.GetValue("coordinate-y", j, 0); - coordinate.Set(i, j); - ini.GetValue("skin", skin); - ini.GetValue("sight", sight, 0); - ini.GetValue("direction", direction); - ini.GetValue("numFight", numFight, 1); - ini.GetValue("ai", ai); - ini.GetValue("appearFlag-f", i, 0); - ini.GetValue("appearFlag-s", j, 0); - appearFlag.Set(i, j); - ini.GetValue("overworldDialog", overworldDialog); - ini.GetValue("winDialog", winDialog); - ini.GetValue("loseDialog", loseDialog); - ini.GetValue("leadPokemon", leadPokemon); - LogImportOver("MapTrainer", id, name); -} - -void PokeGen::PokeMod::MapTrainer::ExportIni(QFile &fout, const QString &map) const -{ - LogExportStart("MapTrainer", id, name); - Ini exMapTrainer("mapTrainer " + map); - exMapTrainer.AddField("id", id); - exMapTrainer.AddField("name", name); - exMapTrainer.AddField("name", name); - exMapTrainer.AddField("coordinate-x", coordinate.GetX()); - exMapTrainer.AddField("coordinate-y", coordinate.GetY()); - exMapTrainer.AddField("skin", skin); - exMapTrainer.AddField("sight", sight); - exMapTrainer.AddField("direction", direction); - exMapTrainer.AddField("numFight", numFight); - exMapTrainer.AddField("ai", ai); - exMapTrainer.AddField("appearFlag-f", appearFlag.GetFlag()); - exMapTrainer.AddField("appearFlag-s", appearFlag.GetStatus()); - exMapTrainer.AddField("overworldDialog", overworldDialog); - exMapTrainer.AddField("winDialog", winDialog); - exMapTrainer.AddField("loseDialog", loseDialog); - exMapTrainer.AddField("leadPokemon", leadPokemon); - exMapTrainer.Export(fout); - for (QList::ConstIterator i = team.begin(); i != team.end(); ++i) - i->ExportIni(fout, map, id); - LogExportOver("MapTrainer", id, name); -} - -void PokeGen::PokeMod::MapTrainer::SetName(const QString &n) -{ - LogSetVar("MapTrainer", id, "name", n); - name = n; -} - -void PokeGen::PokeMod::MapTrainer::SetCoordinate(const Point &c) -{ - LogSetVar("MapTrainer", id, "coordinate", c.GetX(), c.GetY(), name); - coordinate = c; -} - -void PokeGen::PokeMod::MapTrainer::SetCoordinate(const unsigned x, const unsigned y) -{ - LogSetVar("MapTrainer", id, "coordinate", x, y, name); - coordinate.Set(x, y); -} - -void PokeGen::PokeMod::MapTrainer::SetCoordinateX(const unsigned x) -{ - LogSetVar("MapTrainer", id, "coordinate x", x, name); - coordinate.SetX(x); -} - -void PokeGen::PokeMod::MapTrainer::SetCoordinateY(const unsigned y) -{ - LogSetVar("MapTrainer", id, "coordinate y", y, name); - coordinate.SetY(y); -} - -void PokeGen::PokeMod::MapTrainer::SetSkin(const Path &s) -{ - LogSetVar("MapTrainer", id, "skin", s, name); - skin = s.GetFilename(); - s.CopyTo(pokemod->GetPath() + "skins/" + skin); -} - -void PokeGen::PokeMod::MapTrainer::SetSight(const unsigned s) -{ - LogSetVar("MapTrainer", id, "sight", s, name); - sight = s; -} - -void PokeGen::PokeMod::MapTrainer::SetDirection(const unsigned d) -{ - LogSetVar("MapTrainer", id, "direction", d, name); - if (d < DIR_END_NONE) - direction = d; -} - -void PokeGen::PokeMod::MapTrainer::SetNumFight(const unsigned m) -{ - LogSetVar("MapTrainer", id, "maxFight", m, name); - if (m && (m <= pokemod->GetMaxFight())) - numFight = m; -} - -void PokeGen::PokeMod::MapTrainer::SetDirection(const QString &d) -{ - SetDirection(FindIn(DIR_END_NONE, d, DirectionStr)); -} - -void PokeGen::PokeMod::MapTrainer::SetAI(const Path &a) -{ - LogSetVar("MapTrainer", id, "ai", a, name); - ai = a.GetFilename(); - a.CopyTo(pokemod->GetPath() + "ai/" + ai); -} - -void PokeGen::PokeMod::MapTrainer::SetAppearFlag(const Flag &a) -{ - LogSetVar("MapTrainer", id, "appearFlag", a.GetFlag(), a.GetStatus(), name); - appearFlag = a; -} - -void PokeGen::PokeMod::MapTrainer::SetAppearFlag(const unsigned f, const unsigned s) -{ - LogSetVar("MapTrainer", id, "appearFlag", f, s, name); - appearFlag.Set(f, s); -} - -void PokeGen::PokeMod::MapTrainer::SetAppearFlagFlag(const unsigned f) -{ - LogSetVar("MapTrainer", id, "appearFlag flag", f, name); - appearFlag.SetFlag(f); -} - -void PokeGen::PokeMod::MapTrainer::SetAppearFlagStatus(const unsigned s) -{ - LogSetVar("MapTrainer", id, "appearFlag status", s, name); - if (s < FV_END) - appearFlag.SetStatus(s); -} - -void PokeGen::PokeMod::MapTrainer::SetAppearFlagStatus(const QString &s) -{ - SetAppearFlagStatus(FindIn(FV_END, s, FlagValueStr)); -} - -void PokeGen::PokeMod::MapTrainer::SetOverworldDialog(const unsigned o) -{ - LogSetVar("MapTrainer", id, "overworldDialog", o, name); - if (pokemod->GetDialog(o)) - overworldDialog = o; -} - -void PokeGen::PokeMod::MapTrainer::SetWinDialog(const unsigned w) -{ - LogSetVar("MapTrainer", id, "winDialog", w, name); - if (pokemod->GetDialog(w)) - winDialog = w; -} - -QString PokeGen::PokeMod::MapTrainer::GetName() const -{ - LogFetchVar("MapTrainer", id, "name", name); - return name; -} - -PokeGen::PokeMod::Point PokeGen::PokeMod::MapTrainer::GetCoordinate() const -{ - LogFetchVar("MapTrainer", id, "coordinate", coordinate.GetX(), coordinate.GetY(), name); - return coordinate; -} - -unsigned PokeGen::PokeMod::MapTrainer::GetCoordinateX() const -{ - LogFetchVar("MapTrainer", id, "coordinate x", coordinate.GetX(), name); - return coordinate.GetX(); -} - -unsigned PokeGen::PokeMod::MapTrainer::GetCoordinateY() const -{ - LogFetchVar("MapTrainer", id, "coordinate y", coordinate.GetY(), name); - return coordinate.GetY(); -} - -bool PokeGen::PokeMod::MapTrainer::GetSkinExists() const -{ - LogFetchVar("MapTrainer", id, "skin exists", skin, name); - return GetSkin().DoesExist(); -} - -PokeGen::PokeMod::Path PokeGen::PokeMod::MapTrainer::GetSkin() const -{ - LogFetchVar("MapTrainer", id, "skins", skin, name); - return Path(pokemod->GetPath() + "skins/" + skin); -} - -unsigned PokeGen::PokeMod::MapTrainer::GetSight() const -{ - LogFetchVar("MapTrainer", id, "sight", sight, name); - return sight; -} - -unsigned PokeGen::PokeMod::MapTrainer::GetDirection() const -{ - LogFetchVar("MapTrainer", id, "direction", direction, name); - return direction; -} - -unsigned PokeGen::PokeMod::MapTrainer::GetNumFight() const -{ - LogFetchVar("MapTrainer", id, "numFight", numFight, name); - return numFight; -} - -QString PokeGen::PokeMod::MapTrainer::GetDirectionString() const -{ - LogFetchVar("MapTrainer", id, "direction string", direction, name); - if (direction < DIR_END_NONE) - return DirectionStr[direction]; - return ""; -} - -bool PokeGen::PokeMod::MapTrainer::GetAIExists() const -{ - LogFetchVar("MapTrainer", id, "ai exists", ai, name); - return GetAI().DoesExist(); -} - -PokeGen::PokeMod::Path PokeGen::PokeMod::MapTrainer::GetAI() const -{ - LogFetchVar("MapTrainer", id, "ai", ai, name); - return Path(pokemod->GetPath() + "ai/" + ai); -} - -PokeGen::PokeMod::Flag PokeGen::PokeMod::MapTrainer::GetAppearFlag() const -{ - LogFetchVar("MapTrainer", id, "appearFlag", appearFlag.GetFlag(), appearFlag.GetStatus(), name); - return appearFlag; -} - -unsigned PokeGen::PokeMod::MapTrainer::GetAppearFlagFlag() const -{ - LogFetchVar("MapTrainer", id, "appearFlag flag", appearFlag.GetFlag(), name); - return appearFlag.GetFlag(); -} - -unsigned PokeGen::PokeMod::MapTrainer::GetAppearFlagStatus() const -{ - LogFetchVar("MapTrainer", id, "appearFlag status", appearFlag.GetStatus(), name); - return appearFlag.GetStatus(); -} - -QString PokeGen::PokeMod::MapTrainer::GetAppearFlagStatusString() const -{ - LogFetchVar("MapTrainer", id, "appearFlag status string", appearFlag.GetStatus(), name); - return appearFlag.GetStatusString(); -} - -unsigned PokeGen::PokeMod::MapTrainer::GetOverworldDialog() const -{ - LogFetchVar("MapTrainer", id, "overworlDialog", overworldDialog, name); - return overworldDialog; -} - -QString PokeGen::PokeMod::MapTrainer::GetOverworldDialogString() const -{ - LogFetchVar("MapTrainer", id, "overworldDialog string", overworldDialog, name); - if (const Dialog *d = pokemod->GetDialog(overworldDialog)) - return d->GetDialog(); - return ""; -} - -unsigned PokeGen::PokeMod::MapTrainer::GetWinDialog() const -{ - LogFetchVar("MapTrainer", id, "winDialog", winDialog, name); - return winDialog; -} - -QString PokeGen::PokeMod::MapTrainer::GetWinDialogString() const -{ - LogFetchVar("MapTrainer", id, "winDialog string", winDialog, name); - if (const Dialog *d = pokemod->GetDialog(winDialog)) - return d->GetDialog(); - return ""; -} - -unsigned PokeGen::PokeMod::MapTrainer::GetLoseDialog() const -{ - LogFetchVar("MapTrainer", id, "loseDialog", loseDialog, name); - return loseDialog; -} - -QString PokeGen::PokeMod::MapTrainer::GetLoseDialogString() const -{ - LogFetchVar("MapTrainer", id, "loseDialog string", loseDialog, name); - if (const Dialog *d = pokemod->GetDialog(loseDialog)) - return d->GetDialog(); - return ""; -} - -unsigned PokeGen::PokeMod::MapTrainer::GetLeadPokemon() const -{ - LogFetchVar("MapTrainer", id, "leadPokemon", leadPokemon, name); - return leadPokemon; -} - -QString PokeGen::PokeMod::MapTrainer::GetLeadPokemonString() const -{ - LogFetchVar("MapTrainer", id, "leadPokemon string", leadPokemon, name); - if (const MapTrainerTeam *s = GetMapTrainerTeam(leadPokemon)) - { - if (const Pokemon *p = pokemod->GetPokemon(s->GetSpecies())) - return p->GetName(); - } - return ""; -} - -const PokeGen::PokeMod::MapTrainerTeam *PokeGen::PokeMod::MapTrainer::GetMapTrainerTeam(const unsigned _id) const -{ - LogSubmoduleFetch("MapTrainer", id, "team member", _id, name); - for (unsigned i = 0; i < GetMapTrainerTeamCount(); ++i) - { - if (team[i].GetId() == _id) - return &team[i]; - } - LogSubmoduleFetchFail("MapTrainer", id, "team member", _id, name); - return NULL; -} - -unsigned PokeGen::PokeMod::MapTrainer::GetMapTrainerTeamCount() const -{ - LogSubmoduleCount("MapTrainer", id, "team member", name); - return team.size(); -} - -void PokeGen::PokeMod::MapTrainer::NewMapTrainerTeam(Ini *const ini) -{ - unsigned i = 0; - for (; i < GetMapTrainerTeamCount(); ++i) - { - if (!GetMapTrainerTeam(i)) - break; - } - MapTrainerTeam newMapTrainerTeam(pokemod, i); - if (ini) - newMapTrainerTeam.ImportIni(*ini); - LogSubmoduleNew("MapTrainer", id, "team member", i, name); - team.append(newMapTrainerTeam); -} - -void PokeGen::PokeMod::MapTrainer::DeleteMapTrainerTeam(const unsigned _id) -{ - LogSubmoduleRemoveStart("MapTrainer", id, "team member", _id, name); - for (QList::Iterator i = team.begin(); i != team.end(); ++i) - { - if (i->GetId() == _id) - { - LogSubmoduleRemoved("MapTrainer", id, "team member", _id, name); - team.erase(i); - } - } - LogSubmoduleRemoveFail("MapTrainer", id, "team member", _id, name); -} +///////////////////////////////////////////////////////////////////////////// +// Name: pokemod/MapTrainer.cpp +// Purpose: Define a trainer for a map +// Author: Ben Boeckel +// Modified by: Ben Boeckel +// Created: Fri June 1 2007 23:11:28 +// 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 +// MERCHANTABILITY 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 . +///////////////////////////////////////////////////////////////////////////// + +#include "MapTrainer.h" + +PokeGen::PokeMod::MapTrainer::MapTrainer(const Pokemod* par, const unsigned _id) : + Object(_id, par), + name(""), + coordinate(0, 0), + skin(""), + sight(0), + direction(UINT_MAX), + numFight(1), + ai(""), + appearFlag(0, 0), + overworldDialog(UINT_MAX), + winDialog(UINT_MAX), + loseDialog(UINT_MAX), + leadPokemon(UINT_MAX) +{ +} + +PokeGen::PokeMod::MapTrainer::MapTrainer(const Pokemod* par, Ini& ini, const unsigned _id) : + Object(_id, par) +{ + ImportIni(ini, _id); +} + +bool PokeGen::PokeMod::MapTrainer::Validate() +{ + pokemod->ValidationMsg(QString("------Trainer \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); + if (name == "") + { + pokemod->ValidationMsg("Name is not defined"); + isValid = false; + } + if (!QFile(pokemod->GetPath() + "skins/" + skin).exists()) + { + pokemod->ValidationMsg("Skin could't be found"); + isValid = false; + } + if (DIR_End_None <= direction) + { + pokemod->ValidationMsg("Invalid direction"); + isValid = false; + } + if (!numFight || (pokemod->GetMaxFight() < numFight)) + { + pokemod->ValidationMsg("Invalid number of Pokémon for a fight"); + isValid = false; + } + if (!QFile(pokemod->GetPath() + "ai/" + ai).exists()) + { + pokemod->ValidationMsg("AI file couldn\'t be found"); + isValid = false; + } + if (pokemod->GetDialogByID(overworldDialog) == UINT_MAX) + { + pokemod->ValidationMsg("Invalid overworld dialog"); + isValid = false; + } + if (pokemod->GetDialogByID(winDialog) == UINT_MAX) + { + pokemod->ValidationMsg("Invalid win dialog"); + isValid = false; + } + if (pokemod->GetDialogByID(loseDialog) == UINT_MAX) + { + pokemod->ValidationMsg("Invalid lose dialog"); + isValid = false; + } + if (GetPokemonCount() <= leadPokemon) + { + pokemod->ValidationMsg("Invalid lead Pokémon"); + isValid = false; + } + if (GetPokemonCount()) + { + QMap idChecker; + for (QList::Iterator i = team.begin(); i != team.end(); ++i) + { + if (!i->IsValid()) + isValid = false; + ++idChecker[i->GetId()]; + } + for (QMap::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i.value()) + { + pokemod->ValidationMsg(QString("There are %1 Pokémon with id %2").arg(i.value()).arg(i.key())); + isValid = false; + } + } + } + else + { + pokemod->ValidationMsg("There are no Pokémon"); + isValid = false; + } + return isValid; +} + +void PokeGen::PokeMod::MapTrainer::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("coordinate-x", i, 0); + ini.GetValue("coordinate-y", j, 0); + coordinate.Set(i, j); + ini.GetValue("skin", skin); + ini.GetValue("sight", sight, 0); + ini.GetValue("direction", direction); + ini.GetValue("numFight", numFight, 1); + ini.GetValue("ai", ai); + ini.GetValue("appearFlag-f", i, 0); + ini.GetValue("appearFlag-s", j, 0); + appearFlag.Set(i, j); + ini.GetValue("overworldDialog", overworldDialog); + ini.GetValue("winDialog", winDialog); + ini.GetValue("loseDialog", loseDialog); + ini.GetValue("leadPokemon", leadPokemon); +} + +void PokeGen::PokeMod::MapTrainer::ExportIni(QFile& fout, const QString& map) const +{ + Ini exMapTrainer("mapTrainer " + map); + exMapTrainer.AddField("id", id); + exMapTrainer.AddField("name", name); + exMapTrainer.AddField("name", name); + exMapTrainer.AddField("coordinate-x", coordinate.GetX()); + exMapTrainer.AddField("coordinate-y", coordinate.GetY()); + exMapTrainer.AddField("skin", skin); + exMapTrainer.AddField("sight", sight); + exMapTrainer.AddField("direction", direction); + exMapTrainer.AddField("numFight", numFight); + exMapTrainer.AddField("ai", ai); + exMapTrainer.AddField("appearFlag-f", appearFlag.GetFlag()); + exMapTrainer.AddField("appearFlag-s", appearFlag.GetStatus()); + exMapTrainer.AddField("overworldDialog", overworldDialog); + exMapTrainer.AddField("winDialog", winDialog); + exMapTrainer.AddField("loseDialog", loseDialog); + exMapTrainer.AddField("leadPokemon", leadPokemon); + exMapTrainer.Export(fout); + for (QList::ConstIterator i = team.begin(); i != team.end(); ++i) + i->ExportIni(fout, map, id); +} + +void PokeGen::PokeMod::MapTrainer::SetName(const QString& n) +{ + name = n; +} + +void PokeGen::PokeMod::MapTrainer::SetCoordinate(const unsigned x, const unsigned y) +{ + coordinate.Set(x, y); +} + +void PokeGen::PokeMod::MapTrainer::SetCoordinateX(const unsigned x) +{ + coordinate.SetX(x); +} + +void PokeGen::PokeMod::MapTrainer::SetCoordinateY(const unsigned y) +{ + coordinate.SetY(y); +} + +bool PokeGen::PokeMod::MapTrainer::SetSkin(const QString& s) +{ + int dirPos = s.lastIndexOf(PM_DEF_SEP); + int extPos = s.lastIndexOf('.'); + if ((dirPos == -1) || (extPos == -1)) + return false; + skin = s.mid(dirPos + 1, extPos - dirPos - 1); + QFile file(pokemod->GetPath() + "images/skins/" + skin + ".png"); + if (file.exists() && !file.remove()) + return false; + return QFile::copy(s, pokemod->GetPath() + "images/skins/" + skin + ".png"); +} + +void PokeGen::PokeMod::MapTrainer::SetSight(const unsigned s) +{ + sight = s; +} + +bool PokeGen::PokeMod::MapTrainer::SetDirection(const unsigned d) +{ + if (d < DIR_End_None) + direction = d; + return (direction == d); +} + +bool PokeGen::PokeMod::MapTrainer::SetNumFight(const unsigned n) +{ + if (n && (n <= pokemod->GetMaxFight())) + numFight = n; + return (numFight == n); +} + +bool PokeGen::PokeMod::MapTrainer::SetAI(const QString& a) +{ + QFile file(pokemod->GetPath() + "ai/" + name + ".png"); + if (file.exists() && file.remove()) + return QFile::copy(a, pokemod->GetPath() + "ai/" + name + ".png"); + return false; +} + +void PokeGen::PokeMod::MapTrainer::SetAppearFlag(const unsigned f, const unsigned s) +{ + appearFlag.Set(f, s); +} + +void PokeGen::PokeMod::MapTrainer::SetAppearFlagFlag(const unsigned f) +{ + appearFlag.SetFlag(f); +} + +bool PokeGen::PokeMod::MapTrainer::SetAppearFlagStatus(const unsigned s) +{ + if (s < Flag::End) + { + appearFlag.SetStatus(s); + return true; + } + return false; +} + +bool PokeGen::PokeMod::MapTrainer::SetOverworldDialog(const unsigned o) +{ + if (pokemod->GetDialogByID(o) != UINT_MAX) + overworldDialog = o; + return (overworldDialog == o); +} + +bool PokeGen::PokeMod::MapTrainer::SetWinDialog(const unsigned w) +{ + if (pokemod->GetDialogByID(w) != UINT_MAX) + winDialog = w; + return (winDialog == w); +} + +bool PokeGen::PokeMod::MapTrainer::SetLoseDialog(const unsigned l) +{ + if (pokemod->GetDialogByID(l) != UINT_MAX) + loseDialog = l; + return (loseDialog == l); +} + +bool PokeGen::PokeMod::MapTrainer::SetLeadPokemon(const unsigned l) +{ + if (l < GetPokemonCount()) + { + leadPokemon = l; + return true; + } + return false; +} + +QString PokeGen::PokeMod::MapTrainer::GetName() const +{ + return name; +} + +PokeGen::PokeMod::Point PokeGen::PokeMod::MapTrainer::GetCoordinate() const +{ + return coordinate; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetCoordinateX() const +{ + return coordinate.GetX(); +} + +unsigned PokeGen::PokeMod::MapTrainer::GetCoordinateY() const +{ + return coordinate.GetY(); +} + +QString PokeGen::PokeMod::MapTrainer::GetSkin() const +{ + return skin; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetSight() const +{ + return sight; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetDirection() const +{ + return direction; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetNumFight() const +{ + return numFight; +} + +QString PokeGen::PokeMod::MapTrainer::GetAI() const +{ + return ai; +} + +PokeGen::PokeMod::Flag PokeGen::PokeMod::MapTrainer::GetAppearFlag() const +{ + return appearFlag; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetAppearFlagFlag() const +{ + return appearFlag.GetFlag(); +} + +unsigned PokeGen::PokeMod::MapTrainer::GetAppearFlagStatus() const +{ + return appearFlag.GetStatus(); +} + +unsigned PokeGen::PokeMod::MapTrainer::GetOverworldDialog() const +{ + return overworldDialog; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetWinDialog() const +{ + return winDialog; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetLoseDialog() const +{ + return loseDialog; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetLeadPokemon() const +{ + return leadPokemon; +} + +const PokeGen::PokeMod::MapTrainerPokemon* PokeGen::PokeMod::MapTrainer::GetPokemon(const unsigned i) const +{ + if (i < GetPokemonCount()) + return &team[i]; + return NULL; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetPokemonByID(const unsigned _id) const +{ + for (unsigned i = 0; i < GetPokemonCount(); ++i) + { + if (team[i].GetId() == _id) + return i; + } + return UINT_MAX; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetPokemonCount() const +{ + return team.size(); +} + +const PokeGen::PokeMod::MapTrainerPokemon* PokeGen::PokeMod::MapTrainer::NewPokemon(Ini* const ini) +{ + unsigned i = 0; + for (; i < GetPokemonCount(); ++i) + { + if (GetPokemonByID(i) == UINT_MAX) + break; + } + MapTrainerPokemon newPokemon(pokemod, i); + if (ini) + newPokemon.ImportIni(*ini); + team.append(newPokemon); + return &team[GetPokemonCount() - 1]; +} + +bool PokeGen::PokeMod::MapTrainer::DeletePokemon(const unsigned i) +{ + if (i < GetPokemonCount()) + { + team.erase(team.begin() + i); + return true; + } + return false; +} -- cgit