From 3595239f08f2bc1df32ef22ed6de9bde10ca3384 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 4 Jun 2007 01:35:20 +0000 Subject: Style cleanup, minor Matrix fixes, duplication validations, Pokemod methods git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@19 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemod/Pokemon.cpp | 467 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 332 insertions(+), 135 deletions(-) (limited to 'pokemod/Pokemon.cpp') diff --git a/pokemod/Pokemon.cpp b/pokemod/Pokemon.cpp index cacd72a5..fdbf3072 100644 --- a/pokemod/Pokemon.cpp +++ b/pokemod/Pokemon.cpp @@ -25,33 +25,32 @@ extern PokeGen::PokeMod::Pokemod curPokeMod; -PokeGen::PokeMod::Pokemon::Pokemon(const unsigned _id) +PokeGen::PokeMod::Pokemon::Pokemon(const unsigned _id) : + name(""), + growth(UINT_MAX), + catchValue(0), + runChance(1, 1), + itemChance(1, 1), + pokedexNumber(UINT_MAX), + weight(0), + heightFeet(0), + heightInches(0), + pokedexEntry(""), + frontSprite(""), + backSprite(""), + listSprite(""), + genderFactor(1, 1, true), + eggSpecies(UINT_MAX), + eggSteps(0), + isDitto(false), + nidoranGroup(UINT_MAX) { LogCtor("Pokemon", id); - name = ""; for (unsigned i = 0; i < STH_END_GSC; ++i) { baseStats[i] = 0; effortValues[i] = 0; } - growth = UINT_MAX; - experienceValue = 0; - catchValue = 0; - runChance.Set(1, 1); - itemChance.Set(1, 1); - pokedexNumber = UINT_MAX; - weight = 0; - heightFeet = 0; - heightInches = 0; - pokedexEntry = ""; - frontSprite = ""; - backSprite = ""; - listSprite = ""; - genderFactor.Set(1, 1, true); - eggSpecies = UINT_MAX; - eggSteps = 0; - isDitto = false; - nidoranGroup = UINT_MAX; id = _id; } @@ -132,90 +131,183 @@ void PokeGen::PokeMod::Pokemon::Validate() LogVarNotValid("Pokemon", id, "eggSteps", name); isValid = false; } - // Check if there are any abilities defined - if (GetPokemonAbilityCount()) + std::map idChecker; + std::map nameChecker; + if (curPokeMod.IsAbilityAllowed()) { - // Validate each ability - for (std::vector::iterator i = abilities.begin(); i != abilities.end(); ++i) + if (GetPokemonAbilityCount()) { - LogSubmoduleIterate("Pokemon", id, "ability", i->GetId(), name); - // If an ability isn't valid, neither is the Pokémon - if (!i->IsValid()) - isValid = false; + for (std::vector::iterator i = abilities.begin(); i != abilities.end(); ++i) + { + LogSubmoduleIterate("Pokemon", id, "ability", i->GetId(), name); + if (!i->IsValid()) + isValid = false; + ++idChecker[i->GetId()]; + ++nameChecker[i->GetAbilityString()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Pokemon", id, "ability", i->first, name); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Pokemon", id, "ability", i->first, name); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); + } + else + { + LogSubmoduleEmpty("Pokemon", id, "ability", name); + isValid = false; } } - else - { - LogSubmoduleEmpty("Pokemon", id, "ability", name); - isValid = false; - } - // Check if there are any evolutions defined - if (GetPokemonAbilityCount()) + if (GetPokemonEvolutionCount()) { - // Validate each evolution for (std::vector::iterator i = evolutions.begin(); i != evolutions.end(); ++i) { LogSubmoduleIterate("Pokemon", id, "evolution", i->GetId(), name); - // If an evolution isn't valid, neither is the Pokémon if (!i->IsValid()) isValid = false; + ++idChecker[i->GetId()]; + ++nameChecker[i->GetSpeciesString()]; } - } - else - { - LogSubmoduleEmpty("Pokemon", id, "evolution", name); - isValid = false; - } - // Check if there are any item defined - if (GetPokemonItemCount()) - { - // Validate each item - for (std::vector::iterator i = items.begin(); i != items.end(); ++i) + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) { - LogSubmoduleIterate("Pokemon", id, "item", i->GetId(), name); - // If an item isn't valid, neither is the Pokémon - if (!i->IsValid()) + if (1 < i->second) + { + LogDuplicateId("Pokemon", id, "evolution", i->first, name); isValid = false; + } } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Pokemon", id, "evolution", i->first, name); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); } else + LogSubmoduleEmpty("Pokemon", id, "evolution", name); + if (curPokeMod.CanHoldItems()) { - LogSubmoduleEmpty("Pokemon", id, "item", name); - isValid = false; + if (GetPokemonItemCount()) + { + for (std::vector::iterator i = items.begin(); i != items.end(); ++i) + { + LogSubmoduleIterate("Pokemon", id, "item", i->GetId(), name); + if (!i->IsValid()) + isValid = false; + ++idChecker[i->GetId()]; + ++nameChecker[i->GetItemString()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Pokemon", id, "item", i->first, name); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Pokemon", id, "item", i->first, name); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); + } + else + { + LogSubmoduleEmpty("Pokemon", id, "item", name); + isValid = false; + } } - // Check if there are any move defined if (GetPokemonMoveCount()) { - // Validate each move for (std::vector::iterator i = moves.begin(); i != moves.end(); ++i) { LogSubmoduleIterate("Pokemon", id, "move", i->GetId(), name); - // If an move isn't valid, neither is the Pokémon if (!i->IsValid()) isValid = false; + ++idChecker[i->GetId()]; + ++nameChecker[i->GetMoveString()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Pokemon", id, "move", i->first, name); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Pokemon", id, "move", i->first, name); + isValid = false; + } } + idChecker.clear(); + nameChecker.clear(); } else { LogSubmoduleEmpty("Pokemon", id, "move", name); isValid = false; } - // Check if there are any natures defined - if (GetPokemonAbilityCount()) + if (curPokeMod.IsNatureAllowed()) { - // Validate each nature - for (std::vector::iterator i = natures.begin(); i != natures.end(); ++i) + if (GetPokemonNatureCount()) { - LogSubmoduleIterate("Pokemon", id, "nature", i->GetId(), name); - // If an nature isn't valid, neither is the Pokémon - if (!i->IsValid()) - isValid = false; + for (std::vector::iterator i = natures.begin(); i != natures.end(); ++i) + { + LogSubmoduleIterate("Pokemon", id, "nature", i->GetId(), name); + if (!i->IsValid()) + isValid = false; + ++idChecker[i->GetId()]; + ++nameChecker[i->GetNatureString()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Pokemon", id, "nature", i->first, name); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Pokemon", id, "nature", i->first, name); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); + } + else + { + LogSubmoduleEmpty("Pokemon", id, "nature", name); + isValid = false; } - } - else - { - LogSubmoduleEmpty("Pokemon", id, "nature", name); - isValid = false; } LogValidateOver("Pokemon", id, isValid, name); } @@ -233,7 +325,7 @@ void PokeGen::PokeMod::Pokemon::Validate(const wxListBox &output) if (name == "") { LogVarNotSet("Pokemon", id, "name", name); - output.append(ConsoleLogVarNotSet("Pokemon", id, "name", name)); + output.Append(ConsoleLogVarNotSet("Pokemon", id, "name", name)); isValid = false; } for (unsigned i = 0; i < (curPokeMod.IsSpecialSplit() ? STH_END_GSC : STH_END_RBY); ++i) @@ -241,31 +333,31 @@ void PokeGen::PokeMod::Pokemon::Validate(const wxListBox &output) if (!baseStats[i]) { LogVarNotValid("Pokemon", id, String("baseStats[%u]", i), name); - output.append(ConsoleLogVarNotValid("Pokemon", id, String("baseStats[%u]", i), name)); + output.Append(ConsoleLogVarNotValid("Pokemon", id, String("baseStats[%u]", i), name)); isValid = false; } } if (STY_END <= growth) { LogVarNotValid("Pokemon", id, "growth", name); - output.append(ConsoleLogVarNotValid("Pokemon", id, "growth", name)); + output.Append(ConsoleLogVarNotValid("Pokemon", id, "growth", name)); isValid = false; } if (curPokeMod.GetPokemonCount() <= pokedexNumber) { LogVarNotValid("Pokemon", id, "pokedexNumber", name); - output.append(ConsoleLogVarNotValid("Pokemon", id, "pokedexNumber", name)); + output.Append(ConsoleLogVarNotValid("Pokemon", id, "pokedexNumber", name)); isValid = false; } if (!weight) { LogVarNotSet("Pokemon", id, "weight", name); - output.append(ConsoleLogVarNotSetW("Pokemon", id, "weight", name)); + output.Append(ConsoleLogVarNotSetW("Pokemon", id, "weight", name)); } if (12 <= heightInches) { LogVarNotValid("Pokemon", id, "heightInches", name); - output.append(ConsoleLogVarNotValid("Pokemon", id, "heightInches", name)); + output.Append(ConsoleLogVarNotValid("Pokemon", id, "heightInches", name)); isValid = false; } if (!frontSprite.DoesExist()) @@ -273,12 +365,12 @@ void PokeGen::PokeMod::Pokemon::Validate(const wxListBox &output) if (frontSprite == "") { LogVarNotSet("Pokemon", id, "frontSprite", name); - output.append(ConsoleLogVarNotSet("Pokemon", id, "frontSprite", name)); + output.Append(ConsoleLogVarNotSet("Pokemon", id, "frontSprite", name)); } else { LogVarNotValid("Pokemon", id, "frontSprite", name); - output.append(ConsoleLogVarNotValid("Pokemon", id, "frontSprite", name)); + output.Append(ConsoleLogVarNotValid("Pokemon", id, "frontSprite", name)); } isValid = false; } @@ -287,12 +379,12 @@ void PokeGen::PokeMod::Pokemon::Validate(const wxListBox &output) if (backSprite == "") { LogVarNotSet("Pokemon", id, "backSprite", name); - output.append(ConsoleLogVarNotSet("Pokemon", id, "backSprite", name)); + output.Append(ConsoleLogVarNotSet("Pokemon", id, "backSprite", name)); } else { LogVarNotValid("Pokemon", id, "backSprite", name); - output.append(ConsoleLogVarNotValid("Pokemon", id, "backSprite", name)); + output.Append(ConsoleLogVarNotValid("Pokemon", id, "backSprite", name)); } isValid = false; } @@ -301,115 +393,220 @@ void PokeGen::PokeMod::Pokemon::Validate(const wxListBox &output) if (listSprite == "") { LogVarNotSet("Pokemon", id, "listSprite", name); - output.append(ConsoleLogVarNotSet("Pokemon", id, "listSprite", name)); + output.Append(ConsoleLogVarNotSet("Pokemon", id, "listSprite", name)); } else { LogVarNotValid("Pokemon", id, "listSprite", name); - output.append(ConsoleLogVarNotValid("Pokemon", id, "listSprite", name)); + output.Append(ConsoleLogVarNotValid("Pokemon", id, "listSprite", name)); } isValid = false; } if (!curPokeMod.GetPokemon(eggSpecies)) { LogVarNotValid("Pokemon", id, "eggSpecies", name); - output.append(ConsoleLogVarNotValidW("Pokemon", id, "eggSpecies", name)); + output.Append(ConsoleLogVarNotValidW("Pokemon", id, "eggSpecies", name)); } else if (!eggSteps) { LogVarNotValid("Pokemon", id, "eggSteps", name); - output.append(ConsoleLogVarNotValid("Pokemon", id, "eggSteps", name)); + output.Append(ConsoleLogVarNotValid("Pokemon", id, "eggSteps", name)); isValid = false; } - // Check if there are any abilities defined - if (GetPokemonAbilityCount()) + std::map idChecker; + std::map nameChecker; + if (curPokeMod.IsAbilityAllowed()) { - // Validate each ability - for (std::vector::iterator i = abilities.begin(); i != abilities.end(); ++i) + if (GetPokemonAbilityCount()) { - LogSubmoduleIterate("Pokemon", id, "ability", i->GetId(), name); - // If an ability isn't valid, neither is the Pokémon - if (!i->IsValid()) - isValid = false; + for (std::vector::iterator i = abilities.begin(); i != abilities.end(); ++i) + { + LogSubmoduleIterate("Pokemon", id, "ability", i->GetId(), name); + if (!i->IsValid()) + isValid = false; + ++idChecker[i->GetId()]; + ++nameChecker[i->GetAbilityString()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Pokemon", id, "ability", i->first, name); + output.Append(ConsoleLogDuplicateId("Pokemon", id, "ability", i->first, name)); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Pokemon", id, "ability", i->first, name); + output.Append(ConsoleLogDuplicateSubmodule("Pokemon", id, "ability", i->first, name)); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); + } + else + { + LogSubmoduleEmpty("Pokemon", id, "ability", name); + output.Append(ConsoleLogSubmoduleEmpty("Pokemon", id, "ability", name)); + isValid = false; } } - else - { - LogSubmoduleEmpty("Pokemon", id, "ability", name); - output.append(ConsoleLogSubmoduleEmpty("Pokemon", id, "ability", name)); - isValid = false; - } - // Check if there are any evolutions defined - if (GetPokemonAbilityCount()) + if (GetPokemonEvolutionCount()) { - // Validate each evolution for (std::vector::iterator i = evolutions.begin(); i != evolutions.end(); ++i) { LogSubmoduleIterate("Pokemon", id, "evolution", i->GetId(), name); - // If an evolution isn't valid, neither is the Pokémon if (!i->IsValid()) isValid = false; + ++idChecker[i->GetId()]; + ++nameChecker[i->GetSpeciesString()]; } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Pokemon", id, "evolution", i->first, name); + output.Append(ConsoleLogDuplicateId("Pokemon", id, "evolution", i->first, name)); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Pokemon", id, "evolution", i->first, name); + output.Append(ConsoleLogDuplicateSubmodule("Pokemon", id, "evolution", i->first, name)); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); } else { LogSubmoduleEmpty("Pokemon", id, "evolution", name); - output.append(ConsoleLogSubmoduleEmpty("Pokemon", id, "evolution", name)); - isValid = false; + output.Append(ConsoleLogSubmoduleEmptyW("Pokemon", id, "evolution", name)); } - // Check if there are any item defined - if (GetPokemonItemCount()) + if (curPokeMod.CanHoldItems()) { - // Validate each item - for (std::vector::iterator i = items.begin(); i != items.end(); ++i) + if (GetPokemonItemCount()) { - LogSubmoduleIterate("Pokemon", id, "item", i->GetId(), name); - // If an item isn't valid, neither is the Pokémon - if (!i->IsValid()) - isValid = false; + for (std::vector::iterator i = items.begin(); i != items.end(); ++i) + { + LogSubmoduleIterate("Pokemon", id, "item", i->GetId(), name); + if (!i->IsValid()) + isValid = false; + ++idChecker[i->GetId()]; + ++nameChecker[i->GetItemString()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Pokemon", id, "item", i->first, name); + output.Append(ConsoleLogDuplicateId("Pokemon", id, "item", i->first, name)); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Pokemon", id, "item", i->first, name); + output.Append(ConsoleLogDuplicateSubmodule("Pokemon", id, "item", i->first, name)); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); + } + else + { + LogSubmoduleEmpty("Pokemon", id, "item", name); + output.Append(ConsoleLogSubmoduleEmpty("Pokemon", id, "item", name)); + isValid = false; } } - else - { - LogSubmoduleEmpty("Pokemon", id, "item", name); - output.append(ConsoleLogSubmoduleEmpty("Pokemon", id, "item", name)); - isValid = false; - } - // Check if there are any move defined if (GetPokemonMoveCount()) { - // Validate each move for (std::vector::iterator i = moves.begin(); i != moves.end(); ++i) { LogSubmoduleIterate("Pokemon", id, "move", i->GetId(), name); - // If an move isn't valid, neither is the Pokémon if (!i->IsValid()) isValid = false; + ++idChecker[i->GetId()]; + ++nameChecker[i->GetMoveString()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Pokemon", id, "move", i->first, name); + output.Append(ConsoleLogDuplicateId("Pokemon", id, "move", i->first, name)); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Pokemon", id, "move", i->first, name); + output.Append(ConsoleLogDuplicateSubmodule("Pokemon", id, "move", i->first, name)); + isValid = false; + } } + idChecker.clear(); + nameChecker.clear(); } else { LogSubmoduleEmpty("Pokemon", id, "move", name); - output.append(ConsoleLogSubmoduleEmpty("Pokemon", id, "move", name)); + output.Append(ConsoleLogSubmoduleEmpty("Pokemon", id, "move", name)); isValid = false; } - // Check if there are any natures defined - if (GetPokemonAbilityCount()) + if (curPokeMod.IsNatureAllowed()) { - // Validate each nature - for (std::vector::iterator i = natures.begin(); i != natures.end(); ++i) + if (GetPokemonNatureCount()) { - LogSubmoduleIterate("Pokemon", id, "nature", i->GetId(), name); - // If an nature isn't valid, neither is the Pokémon - if (!i->IsValid()) - isValid = false; + for (std::vector::iterator i = natures.begin(); i != natures.end(); ++i) + { + LogSubmoduleIterate("Pokemon", id, "nature", i->GetId(), name); + if (!i->IsValid()) + isValid = false; + ++idChecker[i->GetId()]; + ++nameChecker[i->GetNatureString()]; + } + for (std::map::const_iterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateId("Pokemon", id, "nature", i->first, name); + output.Append(ConsoleLogDuplicateId("Pokemon", id, "nature", i->first, name)); + isValid = false; + } + } + for (std::map::const_iterator i = nameChecker.begin(); i != nameChecker.end(); ++i) + { + if (1 < i->second) + { + LogDuplicateSubmodule("Pokemon", id, "nature", i->first, name); + output.Append(ConsoleLogDuplicateSubmodule("Pokemon", id, "nature", i->first, name)); + isValid = false; + } + } + idChecker.clear(); + nameChecker.clear(); + } + else + { + LogSubmoduleEmpty("Pokemon", id, "nature", name); + output.Append(ConsoleLogSubmoduleEmpty("Pokemon", id, "nature", name)); + isValid = false; } - } - else - { - LogSubmoduleEmpty("Pokemon", id, "nature", name); - output.append(ConsoleLogSubmoduleEmpty("Pokemon", id, "nature", name)); - isValid = false; } LogValidateOver("Pokemon", id, isValid, name); } -- cgit