From c9afda3ab74614fb36986f96b7972c082f275eca Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 2 Jun 2007 18:12:48 +0000 Subject: Finished off all PokeMod classes, added move validations, fixed up some GUI, various other fixes git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@18 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/MapTrainer.cpp | 562 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 562 insertions(+) create mode 100644 pokemod/MapTrainer.cpp (limited to 'pokemod/MapTrainer.cpp') diff --git a/pokemod/MapTrainer.cpp b/pokemod/MapTrainer.cpp new file mode 100644 index 00000000..a42299a3 --- /dev/null +++ b/pokemod/MapTrainer.cpp @@ -0,0 +1,562 @@ +///////////////////////////////////////////////////////////////////////////// +// 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 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 +// 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, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +///////////////////////////////////////////////////////////////////////////// + +#include "MapTrainer.h" + +extern PokeGen::PokeMod::Pokemod curPokeMod; + +PokeGen::PokeMod::MapTrainer::MapTrainer(const unsigned _id) : + name(""), + coordinate(0, 0), + skin(""), + sight(0), + direction(UINT_MAX), + ai(""), + appearFlag(0, 0), + overworldDialog(UINT_MAX), + winDialog(UINT_MAX), + loseDialog(UINT_MAX), + leadPokemon(UINT_MAX) +{ + LogCtor("MapTrainer", _id); + id = _id; +} + +PokeGen::PokeMod::MapTrainer::MapTrainer(Ini &ini, const unsigned _id) +{ + LogCtorIni("MapTrainer", _id); + 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 (!skin.DoesExist()) + { + if (skin == "") + LogVarNotSet("MapTrainer", id, "skin", name); + else + LogVarNotValid("MapTrainer", id, "skin", name); + isValid = false; + } + if (DIR_END_NONE <= direction) + { + LogVarNotValid("MapTrainer", id, "direction", name); + isValid = false; + } + if (!ai.DoesExist()) + { + if (ai == "") + LogVarNotSet("MapTrainer", id, "ai", name); + else + LogVarNotValid("MapTrainer", id, "ai", name); + isValid = false; + } + if (!curPokeMod.GetDialog(overworldDialog)) + { + LogVarNotValid("MapTrainer", id, "overworldDialog", name); + isValid = false; + } + if (!curPokeMod.GetDialog(winDialog)) + { + LogVarNotValid("MapTrainer", id, "winDialog", name); + isValid = false; + } + if (!curPokeMod.GetDialog(loseDialog)) + { + LogVarNotValid("MapTrainer", id, "loseDialog", name); + isValid = false; + } + if (!GetMapTrainerTeam(leadPokemon)) + { + LogVarNotValid("MapTrainer", id, "leadPokemon", name); + isValid = false; + } + // Check if there are any Pokémon defined + if (GetMapTrainerTeamCount()) + { + // Validate each Pokémon + for (std::vector::iterator i = team.begin(); i != team.end(); ++i) + { + LogSubmoduleIterate("MapTrainer", id, "team Pokémon", i->GetId(), name); + // If a Pokémon isn't valid, neither is the ability + if (!i->IsValid()) + isValid = false; + } + } + else + { + LogSubmoduleEmpty("MapTrainer", id, "team Pokémon", name); + isValid = false; + } + LogValidateOver("MapTrainer", id, isValid, name); +} + +#ifdef PG_DEBUG_WINDOW +void PokeGen::PokeMod::MapTrainer::Validate(const wxListBox &output) +{ + LogValidateStart("MapTrainer", id, name); + if (name == "") + { + LogVarNotSet("MapTrainer", id, "name"); + output.append(ConsoleLogVarNotSet("MapTrainer", id, "name")); + isValid = false; + } + if (!skin.DoesExist()) + { + if (skin == "") + { + LogVarNotSet("MapTrainer", id, "skin", name); + output.append(ConsoleLogVarNotSet("MapTrainer", id, "skin", name)); + } + else + { + LogVarNotValid("MapTrainer", id, "skin", name); + output.append(ConsoleLogVarNotValid("MapTrainer", id, "skin", name)); + } + isValid = false; + } + if (DIR_END_NONE <= direction) + { + LogVarNotValid("MapTrainer", id, "direction", name); + output.append(ConsoleLogVarNotValid("MapTrainer", id, "direction", name)); + isValid = false; + } + if (!ai.DoesExist()) + { + if (ai == "") + { + LogVarNotSet("MapTrainer", id, "ai", name); + output.append(ConsoleLogVarNotSet("MapTrainer", id, "ai", name)); + } + else + { + LogVarNotValid("MapTrainer", id, "ai", name); + output.append(ConsoleLogVarNotValid("MapTrainer", id, "ai", name)); + } + isValid = false; + } + if (!curPokeMod.GetDialog(overworldDialog)) + { + LogVarNotValid("MapTrainer", id, "overworldDialog", name); + output.append(ConsoleLogVarNotValid("MapTrainer", id, "overworldDialog", name)); + isValid = false; + } + if (!curPokeMod.GetDialog(winDialog)) + { + LogVarNotValid("MapTrainer", id, "winDialog", name); + output.append(ConsoleLogVarNotValid("MapTrainer", id, "winDialog", name)); + isValid = false; + } + if (!curPokeMod.GetDialog(loseDialog)) + { + LogVarNotValid("MapTrainer", id, "loseDialog", name); + output.append(ConsoleLogVarNotValid("MapTrainer", id, "loseDialog", name)); + isValid = false; + } + if (!GetMapTrainerTeam(leadPokemon)) + { + LogVarNotValid("MapTrainer", id, "leadPokemon", name); + output.append(ConsoleLogVarNotValid("MapTrainer", id, "leadPokemon", name)); + isValid = false; + } + // Check if there are any Pokémon defined + if (GetMapTrainerTeamCount()) + { + // Validate each Pokémon + for (std::vector::iterator i = team.begin(); i != team.end(); ++i) + { + LogSubmoduleIterate("MapTrainer", id, "team Pokémon", i->GetId(), name); + // If a Pokémon isn't valid, neither is the ability + if (!i->IsValid()) + isValid = false; + } + } + else + { + LogSubmoduleEmpty("MapTrainer", id, "team Pokémon", name); + output.append(ConsoleLogSubmoduleEmpty("MapTrainer", id, "team Pokémon", name)); + isValid = false; + } + LogValidateOver("MapTrainer", id, isValid, name); +} +#endif + +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("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(std::ofstream &fout, const String &map) const +{ + LogExportStart("MapTrainer", id, name); + Ini exMapTrainer(map + "MapTrainer"); + 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("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 (std::vector::const_iterator i = team.begin(); i != team.end(); ++i) + i->ExportIni(fout, map, id); + LogExportOver("MapTrainer", id, name); +} + +void PokeGen::PokeMod::MapTrainer::SetName(const String &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; +} + +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::SetDirection(const String &d) +{ + SetDirection(FindIn(DIR_END_NONE, d, DirectionStr)); +} + +void PokeGen::PokeMod::MapTrainer::SetAI(const Path &a) +{ + LogSetVar("MapTrainer", id, "ai", a, name); + ai = a; +} + +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 String &s) +{ + SetAppearFlagStatus(FindIn(FV_END, s, FlagValueStr)); +} + +void PokeGen::PokeMod::MapTrainer::SetOverworldDialog(const unsigned o) +{ + LogSetVar("MapTrainer", id, "overworldDialog", o, name); + if (curPokeMod.GetDialog(o)) + overworldDialog = o; +} + +void PokeGen::PokeMod::MapTrainer::SetWinDialog(const unsigned w) +{ + LogSetVar("MapTrainer", id, "winDialog", w, name); + if (curPokeMod.GetDialog(w)) + winDialog = w; +} + +PokeGen::PokeMod::String 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(); +} + +PokeGen::PokeMod::Path PokeGen::PokeMod::MapTrainer::GetSkin() const +{ + LogFetchVar("MapTrainer", id, "skin", skin, name); + return 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; +} + +PokeGen::PokeMod::String PokeGen::PokeMod::MapTrainer::GetDirectionString() const +{ + LogFetchVar("MapTrainer", id, "direction string", direction, name); + if (direction < DIR_END_NONE) + return DirectionStr[direction]; + return ""; +} + +PokeGen::PokeMod::Path PokeGen::PokeMod::MapTrainer::GetAI() const +{ + LogFetchVar("MapTrainer", id, "ai", ai, name); + return 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(); +} + +PokeGen::PokeMod::String 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; +} + +PokeGen::PokeMod::String PokeGen::PokeMod::MapTrainer::GetOverworldDialogString() const +{ + LogFetchVar("MapTrainer", id, "overworldDialog string", overworldDialog, name); + if (const Dialog *d = curPokeMod.GetDialog(overworldDialog)) + return d->GetDialog(); + return ""; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetWinDialog() const +{ + LogFetchVar("MapTrainer", id, "winDialog", winDialog, name); + return winDialog; +} + +PokeGen::PokeMod::String PokeGen::PokeMod::MapTrainer::GetWinDialogString() const +{ + LogFetchVar("MapTrainer", id, "winDialog string", winDialog, name); + if (const Dialog *d = curPokeMod.GetDialog(winDialog)) + return d->GetDialog(); + return ""; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetLoseDialog() const +{ + LogFetchVar("MapTrainer", id, "loseDialog", loseDialog, name); + return loseDialog; +} + +PokeGen::PokeMod::String PokeGen::PokeMod::MapTrainer::GetLoseDialogString() const +{ + LogFetchVar("MapTrainer", id, "loseDialog string", loseDialog, name); + if (const Dialog *d = curPokeMod.GetDialog(loseDialog)) + return d->GetDialog(); + return ""; +} + +unsigned PokeGen::PokeMod::MapTrainer::GetLeadPokemon() const +{ + LogFetchVar("MapTrainer", id, "leadPokemon", leadPokemon, name); + return leadPokemon; +} + +PokeGen::PokeMod::String PokeGen::PokeMod::MapTrainer::GetLeadPokemonString() const +{ + LogFetchVar("MapTrainer", id, "leadPokemon string", leadPokemon, name); + if (const MapTrainerTeam *s = GetMapTrainerTeam(leadPokemon)) + { + if (const Pokemon *p = curPokeMod.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; + // Find the first unused ID in the vector + for (; i < GetMapTrainerTeamCount(); ++i) + { + if (!GetMapTrainerTeam(i)) + break; + } + MapTrainerTeam newMapTrainerTeam(i); + if (ini) + newMapTrainerTeam.ImportIni(*ini); + LogSubmoduleNew("MapTrainer", id, "team member", i, name); + team.push_back(newMapTrainerTeam); +} + +void PokeGen::PokeMod::MapTrainer::DeleteMapTrainerTeam(const unsigned _id) +{ + LogSubmoduleRemoveStart("MapTrainer", id, "team member", _id, name); + for (std::vector::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); +} -- cgit