///////////////////////////////////////////////////////////////////////////// // Name: pokemod/MapEffect.cpp // Purpose: Define an effect for a map // Author: Ben Boeckel // Modified by: Ben Boeckel // Created: Fri June 1 2007 20:23:15 // 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 "MapEffect.h" const char* PokeGen::PokeMod::MapEffect::MapEffectStr[PokeGen::PokeMod::MapEffect::E_End] = {"Item", "PC", "Strength Block", "Button", "Rock Smash", "Slot Machine", "Card Flip Game"}; const char* PokeGen::PokeMod::MapEffect::PCTypeStr[PokeGen::PokeMod::MapEffect::PC_End] = {"Item", "Pokémon", "PokéDex", "Hall of Fame", "All"}; PokeGen::PokeMod::MapEffect::MapEffect(const Pokemod* par, const unsigned _id) : Object(_id, par), name(""), coordinate(0, 0), existFlag(0, 0), skin(""), effect(UINT_MAX), val1(UINT_MAX), val2(UINT_MAX), direction(UINT_MAX), isTransparent(false), canMove(false), dialog(UINT_MAX) { } PokeGen::PokeMod::MapEffect::MapEffect(const Pokemod* par, Ini& ini, const unsigned _id) : Object(_id, par) { ImportIni(ini, _id); } bool PokeGen::PokeMod::MapEffect::Validate() { pokemod->ValidationMsg(QString("------Effect \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); if (name == "") { pokemod->ValidationMsg("Name is not defined"); isValid = false; } if (Flag::End <= existFlag.GetStatus()) { pokemod->ValidationMsg("Invalid existence flag status"); isValid = false; } if (!QFile(pokemod->GetPath() + "images/skins/" + skin + ".png").exists()) { pokemod->ValidationMsg(QString("Skin not found")); isValid = false; } if (effect < E_End) { bool ok = true; switch (effect) { case E_Item: if (pokemod->GetItemByID(val2) == UINT_MAX) ok = false; break; case E_PC: if (PC_End <= val2) ok = false; break; case E_StrengthBlock: case E_Button: if (Flag::End <= val2) ok = false; } if (!ok) { pokemod->ValidationMsg("Invalid val2"); isValid = false; } } else { pokemod->ValidationMsg("Invalid effect"); isValid = false; } if (D_End_None <= direction) { pokemod->ValidationMsg("Invalid driection"); isValid = false; } if (pokemod->GetDialogByID(dialog) == UINT_MAX) { pokemod->ValidationMsg("Invalid dialog"); isValid = false; } return isValid; } void PokeGen::PokeMod::MapEffect::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("existFlag-f", i, 0); ini.GetValue("existFlag-s", j, 0); existFlag.Set(i, j); ini.GetValue("skin", skin); ini.GetValue("effect", effect); ini.GetValue("val1", val1); ini.GetValue("val2", val2); ini.GetValue("direction", direction); ini.GetValue("isTransparent", isTransparent); ini.GetValue("canMove", canMove); ini.GetValue("dialog", dialog); } void PokeGen::PokeMod::MapEffect::ExportIni(QFile& fout, const QString& map) const { Ini exMapEffect(map + "mapEffect"); exMapEffect.AddField("id", id); exMapEffect.AddField("name", name); exMapEffect.AddField("coordinate-x", coordinate.GetX()); exMapEffect.AddField("coordinate-y", coordinate.GetY()); exMapEffect.AddField("existFlag-f", existFlag.GetFlag()); exMapEffect.AddField("existFlag-s", existFlag.GetStatus()); exMapEffect.AddField("skin", skin); exMapEffect.AddField("effect", effect); exMapEffect.AddField("val1", val1); exMapEffect.AddField("val2", val2); exMapEffect.AddField("direction", direction); exMapEffect.AddField("isTransparent", isTransparent); exMapEffect.AddField("canMove", canMove); exMapEffect.AddField("dialog", dialog); exMapEffect.Export(fout); } void PokeGen::PokeMod::MapEffect::SetName(const QString& n) { name = n; } void PokeGen::PokeMod::MapEffect::SetCoordinate(const unsigned x, const unsigned y) { coordinate.Set(x, y); } void PokeGen::PokeMod::MapEffect::SetCoordinateX(const unsigned x) { coordinate.SetX(x); } void PokeGen::PokeMod::MapEffect::SetCoordinateY(const unsigned y) { coordinate.SetY(y); } void PokeGen::PokeMod::MapEffect::SetExistFlag(const unsigned f, const unsigned s) { existFlag.Set(f, s); } void PokeGen::PokeMod::MapEffect::SetExistFlagFlag(const unsigned f) { existFlag.SetFlag(f); } bool PokeGen::PokeMod::MapEffect::SetExistFlagStatus(const unsigned s) { if (s < Flag::End) { existFlag.SetStatus(s); return true; } return false; } bool PokeGen::PokeMod::MapEffect::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"); } bool PokeGen::PokeMod::MapEffect::SetEffect(const unsigned e) { if (e < E_End) { effect = e; val1 = UINT_MAX; val2 = UINT_MAX; } return (effect == e); } bool PokeGen::PokeMod::MapEffect::SetVal1(const unsigned v1) { switch (effect) { case E_StrengthBlock: case E_Button: val1 = v1; break; } return (val1 == v1); } bool PokeGen::PokeMod::MapEffect::SetVal2(const unsigned v2) { switch (effect) { case E_Item: if (pokemod->GetItemByID(v2) != UINT_MAX) val2 = v2; break; case E_PC: if (v2 < PC_End) val2 = v2; break; case E_StrengthBlock: case E_Button: if (v2 < Flag::End) val2 = v2; break; } return (val2 == v2); } bool PokeGen::PokeMod::MapEffect::SetDirection(const unsigned d) { if (d < D_End_None) direction = d; return (direction == d); } void PokeGen::PokeMod::MapEffect::SetIsTransparent(const bool i) { isTransparent = i; } void PokeGen::PokeMod::MapEffect::SetCanMove(const bool c) { canMove = c; } bool PokeGen::PokeMod::MapEffect::SetDialog(const unsigned d) { if (pokemod->GetDialogByID(d) != UINT_MAX) dialog = d; return (dialog == d); } QString PokeGen::PokeMod::MapEffect::GetName() const { return name; } PokeGen::Point PokeGen::PokeMod::MapEffect::GetCoordinate() const { return coordinate; } unsigned PokeGen::PokeMod::MapEffect::GetCoordinateX() const { return coordinate.GetX(); } unsigned PokeGen::PokeMod::MapEffect::GetCoordinateY() const { return coordinate.GetY(); } PokeGen::Flag PokeGen::PokeMod::MapEffect::GetExistFlag() const { return existFlag; } unsigned PokeGen::PokeMod::MapEffect::GetExistFlagFlag() const { return existFlag.GetFlag(); } unsigned PokeGen::PokeMod::MapEffect::GetExistFlagStatus() const { return existFlag.GetStatus(); } QString PokeGen::PokeMod::MapEffect::GetSkin() const { return skin; } unsigned PokeGen::PokeMod::MapEffect::GetEffect() const { return effect; } unsigned PokeGen::PokeMod::MapEffect::GetVal1() const { return val1; } unsigned PokeGen::PokeMod::MapEffect::GetVal2() const { return val2; } unsigned PokeGen::PokeMod::MapEffect::GetDirection() const { return direction; } bool PokeGen::PokeMod::MapEffect::GetIsTransparent() const { return isTransparent; } bool PokeGen::PokeMod::MapEffect::GetCanMove() const { return canMove; } unsigned PokeGen::PokeMod::MapEffect::GetDialog() const { return dialog; }