diff --git a/Data/Scripts/014_Trainers/002_PTrainer_NPCTrainers.rb b/Data/Scripts/014_Trainers/002_PTrainer_NPCTrainers.rb index e56b7642a..aa5de735f 100644 --- a/Data/Scripts/014_Trainers/002_PTrainer_NPCTrainers.rb +++ b/Data/Scripts/014_Trainers/002_PTrainer_NPCTrainers.rb @@ -1,43 +1,43 @@ #=============================================================================== -# Trainers data +# Trainer data #=============================================================================== -TPSPECIES = 0 -TPLEVEL = 1 -TPITEM = 2 -TPMOVES = 3 -TPABILITY = 4 -TPGENDER = 5 -TPFORM = 6 -TPSHINY = 7 -TPNATURE = 8 -TPIV = 9 -TPHAPPINESS = 10 -TPNAME = 11 -TPSHADOW = 12 -TPBALL = 13 -TPEV = 14 -TPLOSETEXT = 15 +module TrainerData + SPECIES = 0 + LEVEL = 1 + ITEM = 2 + MOVES = 3 + ABILITY = 4 + GENDER = 5 + FORM = 6 + SHINY = 7 + NATURE = 8 + IV = 9 + HAPPINESS = 10 + NAME = 11 + SHADOW = 12 + BALL = 13 + EV = 14 + LOSETEXT = 15 -module TrainersMetadata - InfoTypes = { - "Items" => [0, "eEEEEEEE", :PBItems, :PBItems, :PBItems, :PBItems, - :PBItems, :PBItems, :PBItems, :PBItems], - "Pokemon" => [TPSPECIES, "ev", :PBSpecies,nil], # Species, level - "Item" => [TPITEM, "e", :PBItems], - "Moves" => [TPMOVES, "eEEE", :PBMoves, :PBMoves, :PBMoves, :PBMoves], - "Ability" => [TPABILITY, "u"], - "Gender" => [TPGENDER, "e", { "M" => 0, "m" => 0, "Male" => 0, "male" => 0, "0" => 0, - "F" => 1, "f" => 1, "Female" => 1, "female" => 1, "1" => 1 }], - "Form" => [TPFORM, "u"], - "Shiny" => [TPSHINY, "b"], - "Nature" => [TPNATURE, "e", :PBNatures], - "IV" => [TPIV, "uUUUUU"], - "Happiness" => [TPHAPPINESS, "u"], - "Name" => [TPNAME, "s"], - "Shadow" => [TPSHADOW, "b"], - "Ball" => [TPBALL, "u"], - "EV" => [TPEV, "uUUUUU"], - "LoseText" => [TPLOSETEXT, "s"] + SCHEMA = { + "Items" => [0, "eEEEEEEE", :PBItems, :PBItems, :PBItems, :PBItems, + :PBItems, :PBItems, :PBItems, :PBItems], + "Pokemon" => [SPECIES, "ev", :PBSpecies, nil], # Species, level + "Item" => [ITEM, "e", :PBItems], + "Moves" => [MOVES, "eEEE", :PBMoves, :PBMoves, :PBMoves, :PBMoves], + "Ability" => [ABILITY, "u"], + "Gender" => [GENDER, "e", { "M" => 0, "m" => 0, "Male" => 0, "male" => 0, "0" => 0, + "F" => 1, "f" => 1, "Female" => 1, "female" => 1, "1" => 1 }], + "Form" => [FORM, "u"], + "Shiny" => [SHINY, "b"], + "Nature" => [NATURE, "e", :PBNatures], + "IV" => [IV, "uUUUUU"], + "Happiness" => [HAPPINESS, "u"], + "Name" => [NAME, "s"], + "Shadow" => [SHADOW, "b"], + "Ball" => [BALL, "u"], + "EV" => [EV, "uUUUUU"], + "LoseText" => [LOSETEXT, "s"] } end @@ -74,47 +74,47 @@ def pbLoadTrainer(trainerid,trainername,partyid=0) opponent.setForeignID($Trainer) # Load up each Pokémon in the trainer's party for poke in trainer[3] - species = pbGetSpeciesFromFSpecies(poke[TPSPECIES])[0] - level = poke[TPLEVEL] + species = pbGetSpeciesFromFSpecies(poke[TrainerData::SPECIES])[0] + level = poke[TrainerData::LEVEL] pokemon = Pokemon.new(species,level,opponent,false) - if poke[TPFORM] - pokemon.forcedForm = poke[TPFORM] if MultipleForms.hasFunction?(pokemon.species,"getForm") - pokemon.formSimple = poke[TPFORM] + if poke[TrainerData::FORM] + pokemon.forcedForm = poke[TrainerData::FORM] if MultipleForms.hasFunction?(pokemon.species,"getForm") + pokemon.formSimple = poke[TrainerData::FORM] end - pokemon.setItem(poke[TPITEM]) if poke[TPITEM] - if poke[TPMOVES] && poke[TPMOVES].length>0 - for move in poke[TPMOVES] + pokemon.setItem(poke[TrainerData::ITEM]) if poke[TrainerData::ITEM] + if poke[TrainerData::MOVES] && poke[TrainerData::MOVES].length>0 + for move in poke[TrainerData::MOVES] pokemon.pbLearnMove(move) end else pokemon.resetMoves end - pokemon.setAbility(poke[TPABILITY] || 0) - g = (poke[TPGENDER]) ? poke[TPGENDER] : (opponent.female?) ? 1 : 0 + pokemon.setAbility(poke[TrainerData::ABILITY] || 0) + g = (poke[TrainerData::GENDER]) ? poke[TrainerData::GENDER] : (opponent.female?) ? 1 : 0 pokemon.setGender(g) - (poke[TPSHINY]) ? pokemon.makeShiny : pokemon.makeNotShiny - n = (poke[TPNATURE]) ? poke[TPNATURE] : (pokemon.species+opponent.trainertype)%(PBNatures.maxValue+1) + (poke[TrainerData::SHINY]) ? pokemon.makeShiny : pokemon.makeNotShiny + n = (poke[TrainerData::NATURE]) ? poke[TrainerData::NATURE] : (pokemon.species+opponent.trainertype)%(PBNatures.maxValue+1) pokemon.setNature(n) for i in 0...6 - if poke[TPIV] && poke[TPIV].length>0 - pokemon.iv[i] = (i0 + pokemon.iv[i] = (i0 - pokemon.ev[i] = (i0 + pokemon.ev[i] = (i=TPMOVES && i=TrainerData::MOVES && i0 + ret[TrainerData::MOVES] = moves if moves.length>0 # Remove unnecessarily nils from the end of ret ret.pop while ret.last.nil? && ret.size>0 return ret end def self.format(value) - return "-" if !value || !value[TPSPECIES] || value[TPSPECIES]<=0 - return sprintf("%s,%d",PBSpecies.getName(value[TPSPECIES]),value[TPLEVEL]) + return "-" if !value || !value[TrainerData::SPECIES] || value[TrainerData::SPECIES]<=0 + return sprintf("%s,%d",PBSpecies.getName(value[TrainerData::SPECIES]),value[TrainerData::LEVEL]) end end diff --git a/Data/Scripts/021_Debug/005_Editor_SaveData.rb b/Data/Scripts/021_Debug/005_Editor_SaveData.rb index d2a2e72eb..23b779d85 100644 --- a/Data/Scripts/021_Debug/005_Editor_SaveData.rb +++ b/Data/Scripts/021_Debug/005_Editor_SaveData.rb @@ -467,67 +467,67 @@ def pbSaveTrainerBattles end # Pokémon for poke in trainer[3] - species = getConstantName(PBSpecies,poke[TPSPECIES]) rescue pbGetSpeciesConst(poke[TPSPECIES]) rescue "" - f.write(sprintf("Pokemon = %s,%d\r\n",species,poke[TPLEVEL])) - if poke[TPNAME] && poke[TPNAME]!="" - f.write(sprintf(" Name = %s\r\n",poke[TPNAME])) + species = getConstantName(PBSpecies,poke[TrainerData::SPECIES]) rescue pbGetSpeciesConst(poke[TrainerData::SPECIES]) rescue "" + f.write(sprintf("Pokemon = %s,%d\r\n",species,poke[TrainerData::LEVEL])) + if poke[TrainerData::NAME] && poke[TrainerData::NAME]!="" + f.write(sprintf(" Name = %s\r\n",poke[TrainerData::NAME])) end - if poke[TPFORM] - f.write(sprintf(" Form = %d\r\n",poke[TPFORM])) + if poke[TrainerData::FORM] + f.write(sprintf(" Form = %d\r\n",poke[TrainerData::FORM])) end - if poke[TPGENDER] - f.write(sprintf(" Gender = %s\r\n",(poke[TPGENDER]==1) ? "female" : "male")) + if poke[TrainerData::GENDER] + f.write(sprintf(" Gender = %s\r\n",(poke[TrainerData::GENDER]==1) ? "female" : "male")) end - if poke[TPSHINY] + if poke[TrainerData::SHINY] f.write(" Shiny = yes\r\n") end - if poke[TPSHADOW] + if poke[TrainerData::SHADOW] f.write(" Shadow = yes\r\n") end - if poke[TPMOVES] && poke[TPMOVES].length>0 + if poke[TrainerData::MOVES] && poke[TrainerData::MOVES].length>0 movestring = "" - for i in 0...poke[TPMOVES].length - movename = getConstantName(PBMoves,poke[TPMOVES][i]) rescue pbGetMoveConst(poke[TPMOVES][i]) rescue nil + for i in 0...poke[TrainerData::MOVES].length + movename = getConstantName(PBMoves,poke[TrainerData::MOVES][i]) rescue pbGetMoveConst(poke[TrainerData::MOVES][i]) rescue nil next if !movename movestring.concat(",") if i>0 movestring.concat(movename) end f.write(sprintf(" Moves = %s\r\n",movestring)) if movestring!="" end - if poke[TPABILITY] - f.write(sprintf(" Ability = %d\r\n",poke[TPABILITY])) + if poke[TrainerData::ABILITY] + f.write(sprintf(" Ability = %d\r\n",poke[TrainerData::ABILITY])) end - if poke[TPITEM] && poke[TPITEM]>0 - item = getConstantName(PBItems,poke[TPITEM]) rescue pbGetItemConst(poke[TPITEM]) rescue nil + if poke[TrainerData::ITEM] && poke[TrainerData::ITEM]>0 + item = getConstantName(PBItems,poke[TrainerData::ITEM]) rescue pbGetItemConst(poke[TrainerData::ITEM]) rescue nil f.write(sprintf(" Item = %s\r\n",item)) if item end - if poke[TPNATURE] - nature = getConstantName(PBNatures,poke[TPNATURE]) rescue nil + if poke[TrainerData::NATURE] + nature = getConstantName(PBNatures,poke[TrainerData::NATURE]) rescue nil f.write(sprintf(" Nature = %s\r\n",nature)) if nature end - if poke[TPIV] && poke[TPIV].length>0 - f.write(sprintf(" IV = %d",poke[TPIV][0])) - if poke[TPIV].length>1 + if poke[TrainerData::IV] && poke[TrainerData::IV].length>0 + f.write(sprintf(" IV = %d",poke[TrainerData::IV][0])) + if poke[TrainerData::IV].length>1 for i in 1...6 - f.write(sprintf(",%d",(i0 - f.write(sprintf(" EV = %d",poke[TPEV][0])) - if poke[TPEV].length>1 + if poke[TrainerData::EV] && poke[TrainerData::EV].length>0 + f.write(sprintf(" EV = %d",poke[TrainerData::EV][0])) + if poke[TrainerData::EV].length>1 for i in 1...6 - f.write(sprintf(",%d",(i0 @trainers[(@includeNew) ? index-1 : index][3].each_with_index do |p,i| text += "\r\n" if i>0 - text += sprintf("%s Lv.%d",PBSpecies.getName(p[TPSPECIES]),p[TPLEVEL]) + text += sprintf("%s Lv.%d",PBSpecies.getName(p[TrainerData::SPECIES]),p[TrainerData::LEVEL]) end end @pkmnList.text = text diff --git a/Data/Scripts/022_Compiler/002_Compiler_PBS.rb b/Data/Scripts/022_Compiler/002_Compiler_PBS.rb index 2f7ded83f..59402554c 100644 --- a/Data/Scripts/022_Compiler/002_Compiler_PBS.rb +++ b/Data/Scripts/022_Compiler/002_Compiler_PBS.rb @@ -1388,7 +1388,7 @@ end # Compile individual trainers #=============================================================================== def pbCompileTrainers - trainer_info_types = TrainersMetadata::InfoTypes + trainer_info_types = TrainerData::SCHEMA mLevel = PBExperience.maxLevel trainerindex = -1 trainers = [] @@ -1481,8 +1481,8 @@ def pbCompileTrainers when "Pokemon" pokemonindex += 1 trainers[trainerindex][3][pokemonindex] = [] - trainers[trainerindex][3][pokemonindex][TPSPECIES] = record[0] - trainers[trainerindex][3][pokemonindex][TPLEVEL] = record[1] + trainers[trainerindex][3][pokemonindex][TrainerData::SPECIES] = record[0] + trainers[trainerindex][3][pokemonindex][TrainerData::LEVEL] = record[1] else if pokemonindex<0 raise _INTL("Pokémon hasn't been defined yet!\r\n{1}",FileLineData.linereport) @@ -1532,29 +1532,29 @@ def pbCompileTrainers for i in 0...record.length next if record[i]==nil case i - when TPLEVEL + when TrainerData::LEVEL if record[i]>mLevel raise _INTL("Bad level: {1} (must be 1-{2})\r\n{3}",record[i],mLevel,FileLineData.linereport) end - when TPABILITY+3 + when TrainerData::ABILITY+3 if record[i]>5 raise _INTL("Bad ability flag: {1} (must be 0 or 1 or 2-5)\r\n{2}",record[i],FileLineData.linereport) end - when TPIV+3 + when TrainerData::IV+3 if record[i]>31 raise _INTL("Bad IV: {1} (must be 0-31)\r\n{2}",record[i],FileLineData.linereport) end record[i] = [record[i]] - when TPEV+3 + when TrainerData::EV+3 if record[i]>Pokemon::EV_STAT_LIMIT raise _INTL("Bad EV: {1} (must be 0-{2})\r\n{3}", record[i], Pokemon::EV_STAT_LIMIT, FileLineData.linereport) end record[i] = [record[i]] - when TPHAPPINESS+3 + when TrainerData::HAPPINESS+3 if record[i]>255 raise _INTL("Bad happiness: {1} (must be 0-255)\r\n{2}",record[i],FileLineData.linereport) end - when TPNAME+3 + when TrainerData::NAME+3 if record[i].length>Pokemon::MAX_NAME_SIZE raise _INTL("Bad nickname: {1} (must be 1-{2} characters)\r\n{3}", record[i], Pokemon::MAX_NAME_SIZE, FileLineData.linereport) end @@ -1563,13 +1563,13 @@ def pbCompileTrainers # Write data to trainer array for i in 0...record.length next if record[i]==nil - if i>=TPMOVES && i=TrainerData::MOVES && i=TPMOVES+4) ? i-3 : i + d = (i>=TrainerData::MOVES+4) ? i-3 : i trainers[trainerindex][3][pokemonindex][d] = record[i] end end