///////////////////////////////////////////////////////////////////////////// // Name: pokemod/Tile.cpp // Purpose: Define a tile for the map // Author: Ben Boeckel // Modified by: Ben Boeckel // Created: Thu May 31 2007 13:52:39 // 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 // MERCHANTTile 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 "Tile.h" PokeGen::PokeMod::Tile::Tile(const Pokemod *par, const unsigned _id) : name(""), pic(""), fromUp(false), fromDown(false), fromLeft(false), fromRight(false), isWild(false), wildChance(1, 1), isWater(false), waterType(UINT_MAX), underWater(UINT_MAX), canDive(false), isCuttable(false), underCut(UINT_MAX), canHeadbutt(false), forceType(UINT_MAX), forceDirection(UINT_MAX) { LogCtor("Tile", id); id = _id; pokemod = par; } PokeGen::PokeMod::Tile::Tile(const Pokemod *par, Ini &ini, const unsigned _id) { LogCtorIni("Tile", id); pokemod = par; ImportIni(ini, _id); if (id == UINT_MAX) LogIdError("Tile"); } PokeGen::PokeMod::Tile::~Tile() { LogDtor("Tile", id, name); } void PokeGen::PokeMod::Tile::Validate() { LogValidateStart("Tile", id, name); if (name == "") { LogVarNotSet("Tile", id, "Name", name); isValid = false; } if (!pic.DoesExist()) { if (pic == "") LogVarNotSet("Tile", id, "pic", name); else LogVarNotValid("Tile", id, "pic", name); isValid = false; } if (isWater) { if (WTRT_END <= waterType) { LogVarNotValid("Tile", id, "waterType", name); isValid = false; } else if (waterType == WTRT_WHIRLPOOL) { if (!pokemod->GetTile(underWater)) { LogVarNotValid("Tile", id, "underWater", name); isValid = false; } } } if (isCuttable) { if (!pokemod->GetTile(underCut)) { LogVarNotValid("Tile", id, "underCut", name); isValid = false; } } if (forceType < FT_END) { if ((forceType == FT_SLIP) || (forceType == FT_FORCE) || (forceType == FT_PUSH)) { if (DIR_END <= forceDirection) { LogVarNotValid("Tile", id, "forceDirection", name); isValid = false; } } } else { LogVarNotValid("Tile", id, "forceType", name); isValid = false; } LogValidateOver("Tile", id, isValid, name); } #ifdef PG_DEBUG_WINDOW void PokeGen::PokeMod::Tile::Validate(const wxListBox &output) { LogValidateStart("Tile", id, name); if (name == "") { LogVarNotSet("Tile", id, "Name", name); output.Append(ConsoleLogVarNotSet("Tile", id, "Name", name)); isValid = false; } if (!pic.DoesExist()) { if (pic == "") { LogVarNotSet("Tile", id, "pic", name); output.Append(ConsoleLogVarNotSet("Tile", id, "pic", name)); } else { LogVarNotValid("Tile", id, "pic", name); output.Append(ConsoleLogVarNotValid("Tile", id, "pic", name)); } isValid = false; } if (isWater) { if (WT_END <= waterType) { LogVarNotValid("Tile", id, "waterType", name); output.Append(Console); isValid = false; } else if (waterType == WT_WHIRLPOOL) { if (!pokemod->GetTile(underWater)) { LogVarNotValid("Tile", id, "underWater", name); output.Append(Console); isValid = false; } } } if (isCuttable) { if (!pokemod->GetTile(underCut)) { LogVarNotValid("Tile", id, "underCut", name); output.Append(Console); isValid = false; } } if (forceType < FT_END) { if ((forceType == FT_SLIP) || (forceType == FT_FORCE) || (forceType == FT_PUSH)) { if (DIR_END <= forceDirection) { LogVarNotValid("Tile", id, "forceDirection", name); output.Append(Console); isValid = false; } } } else { LogVarNotValid("Tile", id, "forceType", name); output.Append(Console); isValid = false; } LogValidateOver("Tile", id, isValid, name); } #endif void PokeGen::PokeMod::Tile::ImportIni(Ini &ini, const unsigned _id) { LogImportStart("Tile"); if (_id == UINT_MAX) { ini.GetValue("id", id); if (id == UINT_MAX) LogIdNotFound("Tile"); } else id = _id; unsigned i; unsigned j; ini.GetValue("name", name); ini.GetValue("pic", pic); ini.GetValue("fromUp", fromUp, false); ini.GetValue("fromDown", fromDown, false); ini.GetValue("fromLeft", fromLeft, false); ini.GetValue("fromRight", fromRight, false); ini.GetValue("isWild", isWild, false); ini.GetValue("wildChance-n", i, 1); ini.GetValue("wildChance-d", j, 1); wildChance.Set(i, j); ini.GetValue("isWater", isWater, false); ini.GetValue("waterType", waterType); ini.GetValue("underWater", underWater); ini.GetValue("canDive", canDive, false); ini.GetValue("isCuttable", isCuttable, false); ini.GetValue("underCut", underCut); ini.GetValue("canHeadbutt", canHeadbutt, false); ini.GetValue("forceType", forceType); ini.GetValue("forceDirection", forceDirection); LogImportOver("Tile", id, name); } void PokeGen::PokeMod::Tile::ExportIni(std::ofstream &fout) const { LogExportStart("Tile", id, name); Ini exTile("Tile"); exTile.AddField("id", id); exTile.AddField("name", name); exTile.AddField("pic", pic); exTile.AddField("fromUp", fromUp); exTile.AddField("fromDown", fromDown); exTile.AddField("fromLeft", fromLeft); exTile.AddField("fromRight", fromRight); exTile.AddField("isWild", isWild); exTile.AddField("wildChance-n", wildChance.GetNum()); exTile.AddField("wildChance-d", wildChance.GetDenom()); exTile.AddField("isWater", isWater); exTile.AddField("waterType", waterType); exTile.AddField("underWater", underWater); exTile.AddField("canDive", canDive); exTile.AddField("isCuttable", isCuttable); exTile.AddField("underCut", underCut); exTile.AddField("canHeadbutt", canHeadbutt); exTile.AddField("forceType", forceType); exTile.AddField("forceDirection", forceDirection); exTile.Export(fout); LogExportOver("Tile", id, name); } void PokeGen::PokeMod::Tile::SetName(const String &n) { LogSetVar("Tile", id, "name", n); name = n; } void PokeGen::PokeMod::Tile::SetPic(const Path &p) { LogSetVar("Tile", id, "pic", p, name); pic = p; } void PokeGen::PokeMod::Tile::SetFromUp(const bool f) { LogSetVar("Tile", id, "fromUp", f, name); fromUp = f; } void PokeGen::PokeMod::Tile::SetFromDown(const bool f) { LogSetVar("Tile", id, "fromDown", f, name); fromDown = f; } void PokeGen::PokeMod::Tile::SetFromLeft(const bool f) { LogSetVar("Tile", id, "fromLeft", f, name); fromLeft = f; } void PokeGen::PokeMod::Tile::SetFromRight(const bool f) { LogSetVar("Tile", id, "fromRight", f, name); fromRight = f; } void PokeGen::PokeMod::Tile::SetIsWild(const bool i) { LogSetVar("Tile", id, "isWild", i, name); isWild = i; } void PokeGen::PokeMod::Tile::SetWildChance(const Frac &w) { LogSetVar("Tile", id, "wildChance", w.GetNum(), w.GetDenom(), name); wildChance = w; } void PokeGen::PokeMod::Tile::SetWildChance(const unsigned n, const unsigned d) { LogSetVar("Tile", id, "wildChance", n, d, name); wildChance.Set(n, d); } void PokeGen::PokeMod::Tile::SetWildChanceNumerator(const unsigned n) { LogSetVar("Tile", id, "wildChance numerator", n, name); wildChance.SetNum(n); } void PokeGen::PokeMod::Tile::SetWildChanceDenominator(const unsigned d) { LogSetVar("Tile", id, "wildChance denominator", d, name); wildChance.SetDenom(d); } void PokeGen::PokeMod::Tile::SetIsWater(const bool i) { LogSetVar("Tile", id, "isWater", i, name); isWater = i; } void PokeGen::PokeMod::Tile::SetWaterType(const unsigned w) { LogSetVar("Tile", id, "waterType", w, name); if (w < WTRT_END) waterType = w; } void PokeGen::PokeMod::Tile::SetWaterType(const String &w) { SetWaterType(FindIn(WTRT_END, w, WaterTypeStr)); } void PokeGen::PokeMod::Tile::SetUnderWater(const unsigned u) { LogSetVar("Tile", id, "underWater", u, name); if (pokemod->GetTile(u)) underWater = u; } void PokeGen::PokeMod::Tile::SetUnderWater(const String &u) { LogSetVar("Tile", id, "underWater string", u, name); if (const Tile *t = pokemod->GetTile(u)) underWater = t->GetId(); } void PokeGen::PokeMod::Tile::SetCanDive(const bool c) { LogSetVar("Tile", id, "canDive", c, name); canDive = c; } void PokeGen::PokeMod::Tile::SetIsCuttable(const bool i) { LogSetVar("Tile", id, "isCuttable", i, name); isCuttable = i; } void PokeGen::PokeMod::Tile::SetUnderCut(const unsigned u) { LogSetVar("Tile", id, "underCut", u, name); if (pokemod->GetTile(u)) underCut = u; } void PokeGen::PokeMod::Tile::SetUnderCut(const String &u) { LogSetVar("Tile", id, "underCut string", u, name); if (const Tile *t = pokemod->GetTile(u)) underCut = t->GetId(); } void PokeGen::PokeMod::Tile::SetCanHeadbutt(const bool c) { LogSetVar("Tile", id, "canHeadbutt", c, name); canHeadbutt = c; } void PokeGen::PokeMod::Tile::SetForceType(const unsigned f) { LogSetVar("Tile", id, "forceType", f, name); if (f < FT_END) forceType = f; } void PokeGen::PokeMod::Tile::SetForceType(const String &f) { SetForceType(FindIn(FT_END, f, ForceTypeStr)); } void PokeGen::PokeMod::Tile::SetForceDirection(const unsigned f) { LogSetVar("Tile", id, "forceDirection", f, name); if (f < DIR_END) forceDirection = f; } void PokeGen::PokeMod::Tile::SetForceDirection(const String &f) { SetForceType(FindIn(DIR_END, f, DirectionStr)); } PokeGen::PokeMod::String PokeGen::PokeMod::Tile::GetName() const { LogFetchVar("Tile", id, "name", name); return name; } PokeGen::PokeMod::Path PokeGen::PokeMod::Tile::GetPic() const { LogFetchVar("Tile", id, "pic", pic, name); return pic; } bool PokeGen::PokeMod::Tile::GetFromUp() const { LogFetchVar("Tile", id, "fromUp", fromUp, name); return fromUp; } bool PokeGen::PokeMod::Tile::GetFromDown() const { LogFetchVar("Tile", id, "fromDown", fromDown, name); return fromDown; } bool PokeGen::PokeMod::Tile::GetFromLeft() const { LogFetchVar("Tile", id, "fromLeft", fromLeft, name); return fromLeft; } bool PokeGen::PokeMod::Tile::GetFromRight() const { LogFetchVar("Tile", id, "fromRight", fromRight, name); return fromRight; } bool PokeGen::PokeMod::Tile::GetIsWild() const { LogFetchVar("Tile", id, "isWild", isWild, name); return isWild; } PokeGen::PokeMod::Frac PokeGen::PokeMod::Tile::GetWildChance() const { LogFetchVar("Tile", id, "wildChance", 0, name); return wildChance; } unsigned PokeGen::PokeMod::Tile::GetWildChanceNumerator() const { LogFetchVar("Tile", id, "wildChance numerator", wildChance.GetNum(), name); return wildChance.GetNum(); } unsigned PokeGen::PokeMod::Tile::GetWildChanceDenominator() const { LogFetchVar("Tile", id, "wildChance denominator", wildChance.GetDenom(), name); return wildChance.GetDenom(); } bool PokeGen::PokeMod::Tile::GetIsWater() const { LogFetchVar("Tile", id, "isWater", isWater, name); return isWater; } unsigned PokeGen::PokeMod::Tile::GetWaterType() const { LogFetchVar("Tile", id, "waterType", waterType, name); return waterType; } PokeGen::PokeMod::String PokeGen::PokeMod::Tile::GetWaterTypeString() const { LogFetchVar("Tile", id, "waterType string", waterType, name); if (waterType < WTRT_END) return WaterTypeStr[waterType]; return ""; } unsigned PokeGen::PokeMod::Tile::GetUnderWater() const { LogFetchVar("Tile", id, "underWater", underWater, name); return underWater; } PokeGen::PokeMod::String PokeGen::PokeMod::Tile::GetUnderWaterString() const { LogFetchVar("Tile", id, "underWater", underWater, name); if (const Tile *t = pokemod->GetTile(underWater)) return t->GetName(); return ""; } bool PokeGen::PokeMod::Tile::GetCanDive() const { LogFetchVar("Tile", id, "canDive", canDive, name); return canDive; } bool PokeGen::PokeMod::Tile::GetIsCuttable() const { LogFetchVar("Tile", id, "isCuttable", isCuttable, name); return isCuttable; } unsigned PokeGen::PokeMod::Tile::GetUnderCut() const { LogFetchVar("Tile", id, "underCut", underCut, name); return underCut; } PokeGen::PokeMod::String PokeGen::PokeMod::Tile::GetUnderCutString() const { LogFetchVar("Tile", id, "underCut string", underCut, name); if (const Tile *t = pokemod->GetTile(underCut)) return t->GetName(); return ""; } bool PokeGen::PokeMod::Tile::GetCanHeadbutt() const { LogFetchVar("Tile", id, "canHeadbutt", canHeadbutt, name); return canHeadbutt; } unsigned PokeGen::PokeMod::Tile::GetForceType() const { LogFetchVar("Tile", id, "forceType", forceType, name); return forceType; } PokeGen::PokeMod::String PokeGen::PokeMod::Tile::GetForceTypeString() const { LogFetchVar("Tile", id, "forceType string", forceType, name); if (forceType < FT_END) return ForceTypeStr[forceType]; return ""; } unsigned PokeGen::PokeMod::Tile::GetForceDirection() const { LogFetchVar("Tile", id, "forceDirection", forceDirection, name); return forceDirection; } PokeGen::PokeMod::String PokeGen::PokeMod::Tile::GetForceDirectionString() const { LogFetchVar("Tile", id, "forceDirection string", forceDirection, name); if (forceDirection < DIR_END) return DirectionStr[forceDirection]; return ""; }