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/Dialog.cpp | 1311 ++++++++++++++++++++++++++-------------------------- 1 file changed, 643 insertions(+), 668 deletions(-) (limited to 'pokemod/Dialog.cpp') diff --git a/pokemod/Dialog.cpp b/pokemod/Dialog.cpp index 41ed2dea..4d13515f 100644 --- a/pokemod/Dialog.cpp +++ b/pokemod/Dialog.cpp @@ -1,668 +1,643 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Dialog.cpp -// Purpose: Define a dialog in a PokéMod -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:05:56 2007 -// Copyright: ©2007 Ben Boeckel and 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 "Dialog.h" - -PokeGen::PokeMod::Dialog::Dialog(const Pokemod *par, const unsigned _id) : - dialog("") -{ - LogCtor("Dialog", _id); - id = _id; - pokemod = par; -} - -PokeGen::PokeMod::Dialog::Dialog(const Pokemod *par, Ini &ini, const unsigned _id) -{ - LogCtorIni("Dialog", _id); - pokemod = par; - ImportIni(ini, _id); - if (id == UINT_MAX) - LogIdError("Dialog"); -} - -PokeGen::PokeMod::Dialog::~Dialog() -{ - LogDtor("Dialog", id); -} - -void PokeGen::PokeMod::Dialog::Validate() -{ - LogValidateStart("Dialog", id); - if (dialog == "") - { - LogVarNotSet("Dialog", id, "dialog"); - isValid = false; - } - if (dialog.count('%') % 2) - { - Log::Write(QString("Dialog Validation: Command delimiter mismatch in %1").arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - else - { - unsigned curCmd = DC_END; - unsigned numArgs = 0; - for (long i = 0; i < dialog.length(); ++i) - { - switch (dialog.at(i).toAscii()) - { - case '%': - switch (curCmd) - { - case DC_FLIP_FLAG ... DC_EXIT: - if (numArgs != DialogCommandNumArgs[curCmd]) - { - Log::Write(QString("Dialog Validation: Invalid number of arguments (%1) for %2 (%3 wanted) in %4").arg(numArgs).arg(DialogCommandStr[curCmd]).arg(DialogCommandNumArgs[curCmd]).arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - break; - case DC_MENU: - if (!(numArgs % 2)) - { - Log::Write(QString("Dialog Validation: Argument mismatch for Menu in %1").arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - break; - case DC_END: - QString curCmdStr; - for (; (dialog.at(i) != '%') && (dialog.at(i) != '#'); ++i) - curCmdStr += dialog.at(i); - if (((curCmd = FindIn(DC_END, curCmdStr, DialogCommandAbbrStr)) == DC_END)) - { - if (curCmdStr != "") - { - Log::Write(QString("Dialog Validation: Invalid command \"%1\" in %2").arg(curCmdStr).arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - curCmd = DC_END; - } - numArgs = 0; - } - break; - case '#': - if (curCmd != DC_END) - { - QString arg; - for (; (dialog.at(i) != '%') && (dialog.at(i) != '#'); ++i) - arg += dialog.at(i); - bool okU; - bool okUL; - unsigned tempU = arg.toUInt(&okU); - unsigned long tempUL = arg.toULong(&okUL); - unsigned invError = 0; - Map *map = NULL; - ++numArgs; - switch (curCmd) - { - case DC_FLIP_FLAG: - case DC_SET_FLAG: - case DC_UNSET_FLAG: - case DC_RANDOMIZE_FLAG: - if (numArgs == 1) - { - if (!okUL) - { - Log::Write(QString("Dialog Validation: Bad flag in \"%1\" on %2").arg(DialogCommandStr[curCmd]).arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - } - break; - case DC_TEST_FLAG: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!okUL) - { - Log::Write(QString("Dialog Validation: Bad flag in \"Test Flag\" in %1").arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - break; - case 3: - case 4: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_DIALOG: - if (numArgs == 1) - { - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - } - else if (numArgs == 2) - { - if (!okU || !pokemod->GetDialog(tempU)) - invError = 2; - } - break; - case DC_YES_NO: - case DC_DELETE_MOVE: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - case 3: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_ITEM_SHOP: - if (numArgs == 1) - { - if (!(okU ? pokemod->GetStore(tempU) : pokemod->GetStore(arg))) - invError = 1; - } - break; - case DC_GIVE_ITEM: - case DC_TAKE_ITEM: - case DC_CHECK_ITEM: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!(okU ? pokemod->GetItem(tempU) : pokemod->GetItem(arg))) - invError = 2; - break; - case 3: - case 4: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_COIN_LIST: - if (numArgs == 1) - { - if (!(okU ? pokemod->GetCoinList(tempU) : pokemod->GetCoinList(arg))) - invError = 1; - } - break; - case DC_TEACH_MOVE: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!(okU ? pokemod->GetMove(tempU) : pokemod->GetMove(arg))) - invError = 2; - break; - case 3: - case 4: - case 5: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_CHECK_MOVE: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if ((arg != "Lead") && (arg != "All") && (arg != "0") && (arg != "1")) - invError = 2; - break; - case 3: - if (!(okU ? pokemod->GetMove(tempU) : pokemod->GetMove(arg))) - invError = 3; - break; - case 4: - case 5: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_GIVE_POKEMON: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!(okU ? pokemod->GetPokemon(tempU) : pokemod->GetPokemon(arg))) - invError = 2; - break; - case 3: - if ((arg != "false") && (arg != "true") && (arg != "0") && (arg != "1")) - invError = 3; - break; - case 4: - if (okUL) - { - if (pokemod->GetMaxLevel() < tempUL) - { - Log::Write(QString("Dialog Validation: Higher level than allowed in \"Give Pok�mon\" in %1").arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - } - else - invError = 4; - break; - case 5: - if (!okUL) - invError = 5; - break; - case 6: - case 7: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_TAKE_POKEMON: - case DC_VIEW_POKEMON: - case DC_CHECK_SPECIES: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!(okU ? pokemod->GetPokemon(tempU) : pokemod->GetPokemon(arg))) - invError = 2; - break; - case 3: - case 4: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_SHOW_POKEMON: - if (numArgs == 1) - { - if (!(okU ? pokemod->GetPokemon(tempU) : pokemod->GetPokemon(arg))) - invError = 1; - } - break; - case DC_GIVE_MONEY: - if (numArgs == 1) - { - if (okUL) - { - if (pokemod->GetMaxMoney() < tempUL) - { - Log::Write(QString("Dialog Validation: More money given than can be held in \"Give Money\" in %1").arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - } - else - invError = 1; - } - break; - case DC_TAKE_MONEY: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (okUL) - { - if (pokemod->GetMaxMoney() < tempUL) - { - Log::Write(QString("Dialog Validation: More money taken than can be held in \"Take Money\" in %1").arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - } - else - invError = 2; - break; - case 3: - case 4: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_MOVE_EFFECT: - case DC_CHECK_DIRECTION: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!(map = (okU ? (Map *)pokemod->GetMap(tempU) : (Map *)pokemod->GetMap(arg)))) - invError = 2; - break; - case 3: - if (map) - { - if (!(okU ? map->GetMapEffect(tempU) : map->GetMapEffect(arg))) - invError = 3; - } - else if ((arg != "Player") && (arg != "-1")) - Log::Write(QString("Dialog Validation: Unable to validate argument #3 in \"%1\" in %2").arg(DialogCommandStr[curCmd]).arg(id), PM_DEBUG_ERROR); - break; - case 4: - if ((arg != "Up") && (arg != "Down") && (arg != "Left") && (arg != "Right") && ((arg != "Random") || (curCmd == DC_CHECK_DIRECTION)) && (arg != "0") && (arg != "1") && (arg != "2") && (arg != "3") && ((arg != "4") || (curCmd == DC_CHECK_DIRECTION))) - invError = 4; - break; - case 5: - case 6: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_TURN_EFFECT: - switch (numArgs) - { - case 1: - if (!(map = (okU ? (Map *)pokemod->GetMap(tempU) : (Map *)pokemod->GetMap(arg)))) - invError = 1; - break; - case 2: - if (map) - { - if (!(okU ? map->GetMapEffect(tempU) : map->GetMapEffect(arg))) - invError = 2; - } - else if ((arg != "Player") && (arg != "-1")) - Log::Write(QString("Dialog Validation: Unable to validate argument #2 in \"Turn Effect\" in %1").arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - break; - case 3: - if ((arg != "Up") && (arg != "Down") && (arg != "Left") && (arg != "Right") && (arg != "Random") && (arg != "0") && (arg != "1") && (arg != "2") && (arg != "3") && (arg != "4")) - invError = 3; - } - break; - case DC_CHECK_ROSTER: - case DC_CHECK_LEVELS: - case DC_CHECK_MONEY: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if ((arg != "<") && (arg != ">") && (arg != "=")) - invError = 2; - break; - case 3: - if (okUL) - { - if (((curCmd == DC_CHECK_ROSTER) ? pokemod->GetMaxParty() : ((curCmd == DC_CHECK_LEVELS) ? pokemod->GetMaxLevel() : pokemod->GetMaxMoney())) < tempUL) - { - Log::Write(QString("Dialog Validation: More %1 than can be carried in \"%2\" in %3").arg((curCmd == DC_CHECK_ROSTER) ? "party members" : ((curCmd == DC_CHECK_LEVELS) ? "level" : "money")).arg(DialogCommandStr[curCmd]).arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - } - else - invError = 3; - break; - case 4: - case 5: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_CHECK_HELD_ITEMS: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - case 3: - case 4: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_TRADE: - switch (numArgs) - { - case 1: - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - case 3: - if (!(okU ? pokemod->GetPokemon(tempU) : pokemod->GetPokemon(arg))) - invError = numArgs; - case 4: - if (!okUL) - invError = 4; - break; - case 5: - case 6: - if (!okU || !pokemod->GetDialog(tempU)) - invError = numArgs; - } - break; - case DC_DAYCARE: - if (numArgs == 1) - { - if (!okUL) - invError = 1; - } - break; - case DC_BATTLE: - if (numArgs == 1) - { - if (!(map = (okU ? (Map *)pokemod->GetMap(tempU) : (Map *)pokemod->GetMap(arg)))) - invError = 1; - } - else if (numArgs == 2) - { - if (map) - { - if (!(okU ? map->GetMapTrainer(tempU) : map->GetMapTrainer(arg))) - invError = 2; - } - else - Log::Write(QString("Dialog Validation: Unable to validate argument #2 in \"Battle\" in %1").arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - } - break; - case DC_BADGE: - if (numArgs == 1) - { - if (!(okU ? pokemod->GetBadge(tempU) : pokemod->GetBadge(arg))) - invError = 1; - } - break; - case DC_WARP: - if (numArgs == 1) - { - if (!(map = (okU ? (Map *)pokemod->GetMap(tempU) : (Map *)pokemod->GetMap(arg)))) - invError = 1; - } - else if (numArgs == 2) - { - if (map) - { - if (!(okU ? map->GetMapWarp(tempU) : map->GetMapWarp(arg))) - invError = 2; - } - else - Log::Write(QString("Dialog Validation: Unable to validate argument #2 in \"Warp\" in %1").arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - } - break; - case DC_NAME: - case DC_MAP_SIGN: - if (numArgs == 1) - { - if (arg == "") - invError = 1; - } - break; - case DC_MUSIC: - case DC_SOUND_EFFECT: - if (numArgs == 1) - { - if (!Path(pokemod->GetPath() + "sound/" + arg).DoesExist()) - invError = 1; - } - break; - case DC_TIMER: - switch (numArgs) - { - case 1: - if ((arg != "Time") && (arg != "Step") && (arg != "0") && (arg != "1")) - invError = 1; - break; - case 2: - if (!okU) - invError = 2; - break; - case 3: - if (!okU || !pokemod->GetDialog(tempU)) - invError = 3; - } - break; - case DC_WILD_SCOPE: - if (numArgs == 1) - { - if (!okU) - invError = 1; - } - break; - case DC_SAFARI: - switch (numArgs) - { - case 1: - if (const Item *item = (okU ? pokemod->GetItem(tempU) : pokemod->GetItem(arg))) - { - unsigned i = 0; - unsigned j = 0; - bool temp = false; - while ((i < item->GetItemEffectCount()) || !temp) - { - if (const ItemEffect *e = item->GetItemEffect(j++)) - { - ++i; - if (e->GetEffect() == IE_BALL) - temp = true; - } - } - if (!temp) - { - Log::Write(QString("Dialog Validation: Item in argument #1 in \"Safari\" in %1 isn\'t a Pok�Ball").arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - } - else - invError = 1; - break; - case 2: - if (!okU) - invError = 2; - break; - case 3: - if (!okU || (pokemod->GetMaxParty() < tempU)) - invError = 3; - } - break; - case DC_MENU: - if (numArgs == 1) - { - if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) - invError = 1; - } - else if (numArgs % 2) - { - if (okU) - { - if (!pokemod->GetDialog(tempU)) - invError = numArgs; - } - else - invError = numArgs; - } - else if (arg == "") - invError = numArgs; - } - if (invError) - { - Log::Write(QString("Dialog Validation: Invalid argument %1 in \"%2\" in %3").arg(invError).arg(DialogCommandStr[curCmd]).arg(id), PM_DEBUG_ERROR | PM_DEBUG_VALIDATION); - isValid = false; - } - } - } - } - } - LogValidateOver("Dialog", id, isValid); -} - -void PokeGen::PokeMod::Dialog::ImportIni(Ini &ini, const unsigned _id) -{ - LogImportStart("Dialog"); - if (_id == UINT_MAX) - { - ini.GetValue("id", id); - if (id == UINT_MAX) - LogIdNotFound("Dialog"); - } - else - id = _id; - ini.GetValue("dialog", dialog); - LogImportOver("Dialog", id); -} - -void PokeGen::PokeMod::Dialog::ExportIni(QFile &fout) const -{ - LogExportStart("Dialog", id); - Ini exDialog("dialog"); - exDialog.AddField("id", id); - exDialog.AddField("dialog", dialog); - exDialog.Export(fout); - LogExportOver("Dialog", id); -} - -void PokeGen::PokeMod::Dialog::SetDialog(const QString &d) -{ - LogSetVar("Dialog", id, "dialog", d); - dialog = d; -} - -QString PokeGen::PokeMod::Dialog::GetDialog() const -{ - LogFetchVar("Dialog", id, "dialog", dialog); - return dialog; -} - -void PokeGen::PokeMod::Dialog::InsertDialogCommand(const QString &cmd, const long pos) -{ - Log::Write(QString("Dialog: Inserting dialog command %1 into %2 at %3").arg(cmd).arg(id).arg(pos), PM_DEBUG_INFO); - if (dialog.length() < pos) - { - Log::Write(QString("Dialog: Position out-of-range in %1").arg(id), PM_DEBUG_ERROR); - return; - } - dialog.insert(pos, cmd); -} +///////////////////////////////////////////////////////////////////////////// +// Name: pokemod/Dialog.cpp +// Purpose: Define a dialog in a PokéMod +// Author: Ben Boeckel +// Modified by: Ben Boeckel +// Created: Wed Feb 28 21:05:56 2007 +// Copyright: ©2007 Ben Boeckel and 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 "Dialog.h" + +PokeGen::PokeMod::Dialog::Dialog(const Pokemod* par, const unsigned _id) : + Object(_id, par), + dialog("") +{ +} + +PokeGen::PokeMod::Dialog::Dialog(const Pokemod* par, Ini& ini, const unsigned _id) : + Object(_id, par) +{ + ImportIni(ini, _id); +} + +bool PokeGen::PokeMod::Dialog::Validate() +{ + pokemod->ValidationMsg(QString("---Dialog with id %1---").arg(id), Pokemod::V_Msg); + if (dialog == "") + { + pokemod->ValidationMsg("Dialog is empty"); + isValid = false; + } + if (dialog.count('%') % 2) + { + pokemod->ValidationMsg("Command delimiter mismatch"); + isValid = false; + } + else + { + unsigned curCmd = End; + unsigned numArgs = 0; + for (long i = 0; i < dialog.length(); ++i) + { + switch (dialog.at(i).toAscii()) + { + case '%': + switch (curCmd) + { + case FlipFlag ... Exit: + if (numArgs != CommandNumArgs[curCmd]) + { + pokemod->ValidationMsg(QString("Invalid number of arguments for \"%1\". %2 given when %3 needed").arg(CommandStr[curCmd]).arg(numArgs).arg(CommandNumArgs[curCmd])); + isValid = false; + } + break; + case Menu: + if (!(numArgs % 2)) + { + pokemod->ValidationMsg("Invalid number of arguments for Menu"); + isValid = false; + } + break; + case End: + QString curCmdStr; + for (; (dialog.at(i) != '%') && (dialog.at(i) != '#'); ++i) + curCmdStr += dialog.at(i); + if (((curCmd = FindIn(End, curCmdStr, CommandAbbrStr)) == End)) + { + if (curCmdStr != "") + { + pokemod->ValidationMsg(QString("Invalid command \"%1\"").arg(curCmdStr)); + isValid = false; + } + curCmd = End; + } + numArgs = 0; + } + break; + case '#': + if (curCmd != End) + { + QString arg; + for (; (dialog.at(i) != '%') && (dialog.at(i) != '#'); ++i) + arg += dialog.at(i); + bool okU; + bool okUL; + unsigned tempU = arg.toUInt(&okU); + unsigned long tempUL = arg.toULong(&okUL); + unsigned invError = 0; + const Map* map = NULL; + ++numArgs; + switch (curCmd) + { + case FlipFlag: + case SetFlag: + case UnsetFlag: + case RandomizeFlag: + if (numArgs == 1) + { + if (!okUL) + { + pokemod->ValidationMsg(QString("Bad flag in \"%1\"").arg(CommandStr[curCmd])); + isValid = false; + } + } + break; + case TestFlag: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!okUL) + { + pokemod->ValidationMsg("Bad flag in \"Test Flag\""); + isValid = false; + } + break; + case 3: + case 4: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case DialogC: + if (numArgs == 1) + { + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + } + else if (numArgs == 2) + { + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = 2; + } + break; + case YesNo: + case DeleteMove: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + case 3: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case ItemShop: + if (numArgs == 1) + { + if (!okU || (pokemod->GetStoreByID(tempU) == UINT_MAX)) + invError = 1; + } + break; + case GiveItem: + case TakeItem: + case CheckItem: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!okU || (pokemod->GetItemByID(tempU) == UINT_MAX)) + invError = 2; + break; + case 3: + case 4: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case CoinList: + if (numArgs == 1) + { + if (!okU || (pokemod->GetCoinListByID(tempU) == UINT_MAX)) + invError = 1; + } + break; + case TeachMove: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!okU || (pokemod->GetMoveByID(tempU) == UINT_MAX)) + invError = 2; + break; + case 3: + case 4: + case 5: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case CheckMove: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if ((arg != "Lead") && (arg != "All") && (arg != "0") && (arg != "1")) + invError = 2; + break; + case 3: + if (!okU || (pokemod->GetMoveByID(tempU) == UINT_MAX)) + invError = 3; + break; + case 4: + case 5: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case GivePokemon: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!okU || (pokemod->GetPokemonByID(tempU) ==UINT_MAX)) + invError = 2; + break; + case 3: + if ((arg != "false") && (arg != "true") && (arg != "0") && (arg != "1")) + invError = 3; + break; + case 4: + if (okUL) + { + if (pokemod->GetMaxLevel() < tempUL) + { + pokemod->ValidationMsg("Higher level than allowed in \"Give Pokémon\""); + isValid = false; + } + } + else + invError = 4; + break; + case 5: + if (!okUL) + invError = 5; + break; + case 6: + case 7: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case TakePokemon: + case ViewPokemon: + case CheckSpecies: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!okU || (pokemod->GetPokemonByID(tempU) == UINT_MAX)) + invError = 2; + break; + case 3: + case 4: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case ShowPokemon: + if (numArgs == 1) + { + if (!okU || (pokemod->GetPokemonByID(tempU) == UINT_MAX)) + invError = 1; + } + break; + case GiveMoney: + if (numArgs == 1) + { + if (okUL) + { + if (pokemod->GetMaxMoney() < tempUL) + { + pokemod->ValidationMsg("More money given than can be held in \"Give Money\"", Pokemod::V_Warn); + isValid = false; + } + } + else + invError = 1; + } + break; + case TakeMoney: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (okUL) + { + if (pokemod->GetMaxMoney() < tempUL) + { + pokemod->ValidationMsg("More money taken than can be held in \"Take Money\""); + isValid = false; + } + } + else + invError = 2; + break; + case 3: + case 4: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case MoveEffect: + case CheckDirection: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!okU || !(map = pokemod->GetMap(pokemod->GetMapByID(tempU)))) + invError = 2; + break; + case 3: + if (map) + { + if (!okU || (map->GetEffectByID(tempU) == UINT_MAX)) + invError = 3; + } + else if ((arg != "Player") && (arg != "-1")) + pokemod->ValidationMsg(QString("Unable to validate argument #3 in \"%1\"").arg(CommandStr[curCmd])); + break; + case 4: + if ((arg != "Up") && (arg != "Down") && (arg != "Left") && (arg != "Right") && ((arg != "Random") || (curCmd == CheckDirection)) && (arg != "0") && (arg != "1") && (arg != "2") && (arg != "3") && ((arg != "4") || (curCmd == CheckDirection))) + invError = 4; + break; + case 5: + case 6: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case TurnEffect: + switch (numArgs) + { + case 1: + if (!okU || !(map = pokemod->GetMap(pokemod->GetMapByID(tempU)))) + invError = 1; + break; + case 2: + if (map) + { + if (!okU || (map->GetEffectByID(tempU) == UINT_MAX)) + invError = 2; + } + else if ((arg != "Player") && (arg != "-1")) + pokemod->ValidationMsg("Unable to validate argument #2 in \"Turn Effect\""); + break; + case 3: + if ((arg != "Up") && (arg != "Down") && (arg != "Left") && (arg != "Right") && (arg != "Random") && (arg != "0") && (arg != "1") && (arg != "2") && (arg != "3") && (arg != "4")) + invError = 3; + } + break; + case CheckRoster: + case CheckLevels: + case CheckMoney: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if ((arg != "<") && (arg != ">") && (arg != "=")) + invError = 2; + break; + case 3: + if (okUL) + { + if (((curCmd == CheckRoster) ? pokemod->GetMaxParty() : ((curCmd == CheckLevels) ? pokemod->GetMaxLevel() : pokemod->GetMaxMoney())) < tempUL) + { + pokemod->ValidationMsg(QString("More %1 than can be carried in \"%2\"").arg((curCmd == CheckRoster) ? "party members" : ((curCmd == CheckLevels) ? "level" : "money")).arg(CommandStr[curCmd])); + isValid = false; + } + } + else + invError = 3; + break; + case 4: + case 5: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case CheckHeldItems: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + case 3: + case 4: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case Trade: + switch (numArgs) + { + case 1: + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + case 3: + if (!okU || (pokemod->GetPokemonByID(tempU) == UINT_MAX)) + invError = numArgs; + case 4: + if (!okUL) + invError = 4; + break; + case 5: + case 6: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = numArgs; + } + break; + case Daycare: + if (numArgs == 1) + { + if (!okUL) + invError = 1; + } + break; + case Battle: + if (numArgs == 1) + { + if (!okU || !(map = pokemod->GetMap(pokemod->GetMapByID(tempU)))) + invError = 1; + } + else if (numArgs == 2) + { + if (map) + { + if (!okU || (map->GetTrainerByID(tempU) == UINT_MAX)) + invError = 2; + } + else + pokemod->ValidationMsg("Unable to validate argument #2 in \"Battle\""); + } + break; + case Badge: + if (numArgs == 1) + { + if (!okU || (pokemod->GetBadgeByID(tempU) == UINT_MAX)) + invError = 1; + } + break; + case Warp: + if (numArgs == 1) + { + if (!okU || !(map = pokemod->GetMap(pokemod->GetMapByID(tempU)))) + invError = 1; + } + else if (numArgs == 2) + { + if (map) + { + if (!okU || (map->GetWarpByID(tempU) == UINT_MAX)) + invError = 2; + } + else + pokemod->ValidationMsg("Unable to validate argument #2 in \"Warp\""); + } + break; + case Name: + case MapSign: + if (numArgs == 1) + { + if (arg == "") + invError = 1; + } + break; + case Music: + case SoundEffect: + if (numArgs == 1) + { + if (!QFile(pokemod->GetPath() + "sound/" + arg).exists()) + invError = 1; + } + break; + case Timer: + switch (numArgs) + { + case 1: + if ((arg != "Time") && (arg != "Step") && (arg != "0") && (arg != "1")) + invError = 1; + break; + case 2: + if (!okU) + invError = 2; + break; + case 3: + if (!okU || (pokemod->GetDialogByID(tempU) == UINT_MAX)) + invError = 3; + } + break; + case WildScope: + if (numArgs == 1) + { + if (!okU) + invError = 1; + } + break; + case Safari: + switch (numArgs) + { + case 1: + if (okU && (pokemod->GetItemByID(tempU) == UINT_MAX)) + { + const Item* item = pokemod->GetItem(pokemod->GetItemByID(tempU)); + unsigned i = 0; + bool temp = false; + while ((i < item->GetEffectCount()) || !temp) + { + if (const ItemEffect* e = item->GetEffect(i++)) + { + if (e->GetEffect() == ItemEffect::E_Ball) + temp = true; + } + } + if (!temp) + { + pokemod->ValidationMsg("Item in argument #1 in \"Safari\" isn\'t a PokéBall"); + isValid = false; + } + } + else + invError = 1; + break; + case 2: + if (!okU) + invError = 2; + break; + case 3: + if (!okU || (pokemod->GetMaxParty() < tempU)) + invError = 3; + } + break; + case Menu: + if (numArgs == 1) + { + if ((arg != "Call") && (arg != "Goto") && (arg != "0") && (arg != "1")) + invError = 1; + } + else if (numArgs % 2) + { + if (okU) + { + if (pokemod->GetDialogByID(tempU) == UINT_MAX) + invError = numArgs; + } + else + invError = numArgs; + } + else if (arg == "") + invError = numArgs; + } + if (invError) + { + pokemod->ValidationMsg(QString("Invalid argument #%1 in \"%2\"").arg(invError).arg(CommandStr[curCmd])); + isValid = false; + } + } + } + } + } + return isValid; +} + +void PokeGen::PokeMod::Dialog::ImportIni(Ini& ini, const unsigned _id) +{ + if (_id == UINT_MAX) + ini.GetValue("id", id); + else + id = _id; + ini.GetValue("dialog", dialog); +} + +void PokeGen::PokeMod::Dialog::ExportIni(QFile& fout) const +{ + Ini exDialog("dialog"); + exDialog.AddField("id", id); + exDialog.AddField("dialog", dialog); + exDialog.Export(fout); +} + +void PokeGen::PokeMod::Dialog::SetDialog(const QString& d) +{ + dialog = d; +} + +QString PokeGen::PokeMod::Dialog::GetDialog() const +{ + return dialog; +} + +void PokeGen::PokeMod::Dialog::InsertDialogCommand(const QString& cmd, const long pos) +{ + if (dialog.length() < pos) + return; + dialog.insert(pos, cmd); +} -- cgit