From c4e69d0a2e327f75cfaf6f0fb73da16e136095d1 Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Sun, 18 Oct 2020 22:08:55 +0100 Subject: [PATCH] Fixing up merge --- .../Scripts/013_Overworld/002_PField_Field.rb | 11 +- Data/Scripts/022_Compiler/002_Compiler.rb | 2 +- Data/Scripts/022_Compiler/003_Compiler_PBS.rb | 101 +++++++++++------- .../004_Compiler_MapsAndEvents.rb | 6 +- 4 files changed, 72 insertions(+), 48 deletions(-) diff --git a/Data/Scripts/013_Overworld/002_PField_Field.rb b/Data/Scripts/013_Overworld/002_PField_Field.rb index 53549cd9d..e1746b133 100644 --- a/Data/Scripts/013_Overworld/002_PField_Field.rb +++ b/Data/Scripts/013_Overworld/002_PField_Field.rb @@ -828,7 +828,7 @@ def pbCueBGM(bgm,seconds,volume=nil,pitch=nil) end def pbAutoplayOnTransition - surfbgm = pbGetMetadata(0,MetadataSurfBGM) + surfbgm = pbGetMetadata(0,Metadata::SURF_BGM) if $PokemonGlobal.surfing && surfbgm pbBGMPlay(surfbgm) else @@ -837,7 +837,7 @@ def pbAutoplayOnTransition end def pbAutoplayOnSave - surfbgm = pbGetMetadata(0,MetadataSurfBGM) + surfbgm = pbGetMetadata(0,Metadata::SURF_BGM) if $PokemonGlobal.surfing && surfbgm pbBGMPlay(surfbgm) else @@ -1124,7 +1124,7 @@ def pbFishingBegin $PokemonGlobal.fishing = true if !pbCommonEvent(FISHING_BEGIN_COMMON_EVENT) patternb = 2*$game_player.direction - 1 - meta = pbGetMetadata(0,MetadataPlayerA+$PokemonGlobal.playerID) + meta = pbGetMetadata(0,Metadata::PLAYER_A+$PokemonGlobal.playerID) num = ($PokemonGlobal.surfing) ? 7 : 6 if meta && meta[num] && meta[num]!="" charset = pbGetPlayerCharset(meta,num) @@ -1143,7 +1143,7 @@ end def pbFishingEnd if !pbCommonEvent(FISHING_END_COMMON_EVENT) patternb = 2*($game_player.direction - 2) - meta = pbGetMetadata(0,MetadataPlayerA+$PokemonGlobal.playerID) + meta = pbGetMetadata(0,Metadata::PLAYER_A+$PokemonGlobal.playerID) num = ($PokemonGlobal.surfing) ? 7 : 6 if meta && meta[num] && meta[num]!="" charset = pbGetPlayerCharset(meta,num) @@ -1308,8 +1308,7 @@ def pbRegisterPartner(trainerid,trainername,partyid=0) trainerobject = PokeBattle_Trainer.new(_INTL(trainer[0].name),trainerid) trainerobject.setForeignID($Trainer) for i in trainer[2] - i.trainerID = trainerobject.id - i.ot = trainerobject.name + i.owner = Pokemon::Owner.new_from_trainer(trainerobject) i.calcStats end $PokemonGlobal.partner = [trainerid,trainerobject.name,trainerobject.id,trainer[2]] diff --git a/Data/Scripts/022_Compiler/002_Compiler.rb b/Data/Scripts/022_Compiler/002_Compiler.rb index af2747346..65c257159 100644 --- a/Data/Scripts/022_Compiler/002_Compiler.rb +++ b/Data/Scripts/022_Compiler/002_Compiler.rb @@ -54,7 +54,7 @@ end # Compiler #=============================================================================== module Compiler - extend self + module_function def findIndex(a) index = -1 diff --git a/Data/Scripts/022_Compiler/003_Compiler_PBS.rb b/Data/Scripts/022_Compiler/003_Compiler_PBS.rb index 237b0ca4d..97485bd72 100644 --- a/Data/Scripts/022_Compiler/003_Compiler_PBS.rb +++ b/Data/Scripts/022_Compiler/003_Compiler_PBS.rb @@ -1,6 +1,8 @@ class PBTrainers; end module Compiler + module_function + #============================================================================= # Compile metadata #============================================================================= @@ -12,20 +14,22 @@ module Compiler sectionname = $~[1] if currentmap==0 if sections[currentmap][Metadata::HOME]==nil - raise _INTL("The entry Home is required in metadata.txt section [{1}]",sectionname) - end - if sections[currentmap][Metadata::PLAYER_A]==nil - raise _INTL("The entry PlayerA is required in metadata.txt section [{1}]",sectionname) + raise _INTL("The entry Home is required in metadata.txt section [{1}].",sectionname) + elsif sections[currentmap][Metadata::PLAYER_A]==nil + raise _INTL("The entry PlayerA is required in metadata.txt section [{1}].",sectionname) end end currentmap = sectionname.to_i + if sections[currentmap] + raise _INTL("Section [{1}] is defined twice in metadata.txt.\r\n{2}",currentmap,FileLineData.linereport) + end sections[currentmap] = [] else if currentmap<0 - raise _INTL("Expected a section at the beginning of the file\r\n{1}",FileLineData.linereport) + raise _INTL("Expected a section at the beginning of the file.\r\n{1}",FileLineData.linereport) end if !line[/^\s*(\w+)\s*=\s*(.*)$/] - raise _INTL("Bad line syntax (expected syntax like XXX=YYY)\r\n{1}",FileLineData.linereport) + raise _INTL("Bad line syntax (expected syntax like XXX=YYY).\r\n{1}",FileLineData.linereport) end matchData = $~ schema = nil @@ -219,7 +223,7 @@ module Compiler if currentmap>=0 for reqtype in requiredtypes.keys if !foundtypes.include?(reqtype) - raise _INTL("Required value '{1}' not given in section '{2}'\r\n{3}",reqtype,currentmap,FileLineData.linereport) + raise _INTL("Required value '{1}' not given in section [{2}].\r\n{3}",reqtype,currentmap,FileLineData.linereport) end end foundtypes.clear @@ -228,10 +232,10 @@ module Compiler types[currentmap] = [currentmap,nil,nil,false,false,[],[],[]] else if currentmap<0 - raise _INTL("Expected a section at the beginning of the file\r\n{1}",FileLineData.linereport) + raise _INTL("Expected a section at the beginning of the file.\r\n{1}",FileLineData.linereport) end if !line[/^\s*(\w+)\s*=\s*(.*)$/] - raise _INTL("Bad line syntax (expected syntax like XXX=YYY)\r\n{1}",FileLineData.linereport) + raise _INTL("Bad line syntax (expected syntax like XXX=YYY).\r\n{1}",FileLineData.linereport) end matchData = $~ schema = nil @@ -266,17 +270,17 @@ module Compiler n = type[1] for w in type[5] if !typeinames.include?(w) - raise _INTL("'{1}' is not a defined type (PBS/types.txt, {2}, Weaknesses)",w,n) + raise _INTL("'{1}' is not a defined type (PBS/types.txt, {2}, Weaknesses).",w,n) end end for w in type[6] if !typeinames.include?(w) - raise _INTL("'{1}' is not a defined type (PBS/types.txt, {2}, Resistances)",w,n) + raise _INTL("'{1}' is not a defined type (PBS/types.txt, {2}, Resistances).",w,n) end end for w in type[7] if !typeinames.include?(w) - raise _INTL("'{1}' is not a defined type (PBS/types.txt, {2}, Immunities)",w,n) + raise _INTL("'{1}' is not a defined type (PBS/types.txt, {2}, Immunities).",w,n) end end end @@ -328,6 +332,9 @@ module Compiler maxValue = 0 pbCompilerEachPreppedLine("PBS/abilities.txt") { |line,lineno| record = pbGetCsvRecord(line,lineno,[0,"vnss"]) + if movenames[record[0]] + raise _INTL("Ability ID number '{1}' is used twice.\r\n{2}",record[0],FileLineData.linereport) + end movenames[record[0]] = record[2] movedescs[record[0]] = record[3] maxValue = [maxValue,record[0]].max @@ -410,6 +417,9 @@ module Compiler pbCompilerEachCommentedLine("PBS/items.txt") { |line,lineno| linerecord = pbGetCsvRecord(line,lineno,[0,"vnssuusuuUN"]) id = linerecord[0] + if records[id] + raise _INTL("Item ID number '{1}' is used twice.\r\n{2}",id,FileLineData.linereport) + end record = [] record[ItemData::ID] = id constant = linerecord[1] @@ -468,11 +478,14 @@ module Compiler nil,nil,nil,nil,nil,PBTypes,["Physical","Special","Status"], nil,nil,nil,PBTargets,nil,nil,nil ]) + if records[lineRecord[0]] + raise _INTL("Move ID number '{1}' is used twice.\r\n{2}",lineRecord[0],FileLineData.linereport) + end if lineRecord[6]==2 && lineRecord[4]!=0 - raise _INTL("Status moves must have a base damage of 0, use either Physical or Special\r\n{1}",FileLineData.linereport) + raise _INTL("Status moves must have a base damage of 0, use either Physical or Special.\r\n{1}",FileLineData.linereport) end if lineRecord[6]!=2 && lineRecord[4]==0 - print _INTL("Warning: Physical and special moves can't have a base damage of 0, changing to a Status move\r\n{1}",FileLineData.linereport) + print _INTL("Warning: Physical and special moves can't have a base damage of 0, changing to a Status move.\r\n{1}",FileLineData.linereport) lineRecord[6] = 2 end record[MoveData::ID] = lineRecord[0] @@ -590,6 +603,14 @@ module Compiler # contents is a hash containing all the XXX=YYY lines in that section, where # the keys are the XXX and the values are the YYY (as unprocessed strings). pbEachFileSection(f) { |contents,speciesID| + # Raise an error if the species ID is 0. + if speciesID==0 + raise _INTL("A Pokémon species can't be numbered 0 (PBS/pokemon.txt).") + end + # Raise an error if the species ID has already been defined. + if speciesData[speciesID] + raise _INTL("Species ID number '{1}' is used twice.\r\n{2}",speciesID,FileLineData.linereport) + end # Create array to store compiled data in. speciesData[speciesID] = [] # Copy Type1 into Type2 if Type2 is undefined. (All species must have two @@ -606,10 +627,6 @@ module Compiler FileLineData.setSection(speciesID,key,contents[key]) # For error reporting maxValue = [maxValue,speciesID].max # Set highest species ID next if hash[key][0]<0 # Property is not to be compiled; skip it - # Raise an error if the species ID is 0. - if speciesID==0 - raise _INTL("A Pokémon species can't be numbered 0 (PBS/pokemon.txt)") - end # Skip empty optional properties, or raise an error if a required # property is empty. if !contents[key] || contents[key]=="" @@ -1012,6 +1029,9 @@ module Compiler if !line[/^\#/] && !line[/^\s*$/] if line[/^\s*\[\s*(.*)\s*\]\s*$/] sectionname = parseMove($~[1]) + if sections[sectionname] + raise _INTL("TM section [{1}] is defined twice.\r\n{2}",sectionname,FileLineData.linereport) + end sections[sectionname] = WordArray.new havesection = true else @@ -1092,13 +1112,16 @@ module Compiler mapid = line[/^\d+$/] if mapid lastmapid = mapid + if encounters[mapid.to_i] + raise _INTL("Encounters for map ID '{1}' are defined twice.\r\n{2}",mapid,FileLineData.linereport) + end if thisenc && (thisenc[1][EncounterTypes::Land] || thisenc[1][EncounterTypes::LandMorning] || thisenc[1][EncounterTypes::LandDay] || thisenc[1][EncounterTypes::LandNight] || thisenc[1][EncounterTypes::BugContest]) && thisenc[1][EncounterTypes::Cave] - raise _INTL("Can't define both Land and Cave encounters in the same area (map ID {1})",mapid) + raise _INTL("Can't define both Land and Cave encounters in the same area (map ID '{1}').",mapid) end thisenc = [EncounterTypes::EnctypeDensities.clone,[]] encounters[mapid.to_i] = thisenc @@ -1223,10 +1246,10 @@ module Compiler if line[/^\s*\[\s*(.+)\s*\]\s*$/] # Section [trainertype,trainername] or [trainertype,trainername,partyid] if oldcompilerline>0 - raise _INTL("Previous trainer not defined with as many Pokémon as expected\r\n{1}",FileLineData.linereport) + raise _INTL("Previous trainer not defined with as many Pokémon as expected.\r\n{1}",FileLineData.linereport) end if pokemonindex==-1 - raise _INTL("Started new trainer while previous trainer has no Pokémon\r\n{1}",FileLineData.linereport) + raise _INTL("Started new trainer while previous trainer has no Pokémon.\r\n{1}",FileLineData.linereport) end section = pbGetCsvRecord($~[1],lineno,[0,"esU",PBTrainers]) trainerindex += 1 @@ -1239,10 +1262,10 @@ module Compiler elsif line[/^\s*(\w+)\s*=\s*(.*)$/] # XXX=YYY lines if trainerindex<0 - raise _INTL("Expected a section at the beginning of the file\r\n{1}",FileLineData.linereport) + raise _INTL("Expected a section at the beginning of the file.\r\n{1}",FileLineData.linereport) end if oldcompilerline>0 - raise _INTL("Previous trainer not defined with as many Pokémon as expected\r\n{1}",FileLineData.linereport) + raise _INTL("Previous trainer not defined with as many Pokémon as expected.\r\n{1}",FileLineData.linereport) end settingname = $~[1] schema = trainer_info_types[settingname] @@ -1252,43 +1275,43 @@ module Compiler case settingname when "Pokemon" if record[1]>mLevel - raise _INTL("Bad level: {1} (must be 1-{2})\r\n{3}",record[1],mLevel,FileLineData.linereport) + raise _INTL("Bad level: {1} (must be 1-{2}).\r\n{3}",record[1],mLevel,FileLineData.linereport) end when "Moves" record = [record] if record.is_a?(Integer) record.compact! when "Ability" if record>5 - raise _INTL("Bad ability flag: {1} (must be 0 or 1 or 2-5)\r\n{2}",record,FileLineData.linereport) + raise _INTL("Bad ability flag: {1} (must be 0 or 1 or 2-5).\r\n{2}",record,FileLineData.linereport) end when "IV" record = [record] if record.is_a?(Integer) record.compact! for i in record next if i<=Pokemon::IV_STAT_LIMIT - raise _INTL("Bad IV: {1} (must be 0-{2})\r\n{3}", i, Pokemon::IV_STAT_LIMIT, FileLineData.linereport) + raise _INTL("Bad IV: {1} (must be 0-{2}).\r\n{3}", i, Pokemon::IV_STAT_LIMIT, FileLineData.linereport) end when "EV" record = [record] if record.is_a?(Integer) record.compact! for i in record next if i<=Pokemon::EV_STAT_LIMIT - raise _INTL("Bad EV: {1} (must be 0-{2})\r\n{3}", i, Pokemon::EV_STAT_LIMIT, FileLineData.linereport) + raise _INTL("Bad EV: {1} (must be 0-{2}).\r\n{3}", i, Pokemon::EV_STAT_LIMIT, FileLineData.linereport) end evtotal = 0 for i in 0...6 evtotal += (iPokemon::EV_LIMIT - raise _INTL("Total EVs are greater than allowed ({1})\r\n{2}", Pokemon::EV_LIMIT, FileLineData.linereport) + raise _INTL("Total EVs are greater than allowed ({1}).\r\n{2}", Pokemon::EV_LIMIT, FileLineData.linereport) end when "Happiness" if record>255 - raise _INTL("Bad happiness: {1} (must be 0-255)\r\n{2}",record,FileLineData.linereport) + raise _INTL("Bad happiness: {1} (must be 0-255).\r\n{2}",record,FileLineData.linereport) end when "Name" if record.length>Pokemon::MAX_NAME_SIZE - raise _INTL("Bad nickname: {1} (must be 1-{2} characters)\r\n{3}", record, Pokemon::MAX_NAME_SIZE, FileLineData.linereport) + raise _INTL("Bad nickname: {1} (must be 1-{2} characters).\r\n{3}", record, Pokemon::MAX_NAME_SIZE, FileLineData.linereport) end end # Record XXX=YYY setting @@ -1314,7 +1337,7 @@ module Compiler else # Old compiler - backwards compatibility is SUCH fun! if pokemonindex==-1 && oldcompilerline==0 - raise _INTL("Unexpected line format, started new trainer while previous trainer has no Pokémon\r\n{1}",FileLineData.linereport) + raise _INTL("Unexpected line format, started new trainer while previous trainer has no Pokémon.\r\n{1}",FileLineData.linereport) end if oldcompilerline==0 # Started an old trainer section oldcompilerlength = 3 @@ -1356,29 +1379,29 @@ module Compiler case i when TrainerData::LEVEL if record[i]>mLevel - raise _INTL("Bad level: {1} (must be 1-{2})\r\n{3}",record[i],mLevel,FileLineData.linereport) + raise _INTL("Bad level: {1} (must be 1-{2}).\r\n{3}",record[i],mLevel,FileLineData.linereport) end 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) + raise _INTL("Bad ability flag: {1} (must be 0 or 1 or 2-5).\r\n{2}",record[i],FileLineData.linereport) end when TrainerData::IV+3 if record[i]>31 - raise _INTL("Bad IV: {1} (must be 0-31)\r\n{2}",record[i],FileLineData.linereport) + raise _INTL("Bad IV: {1} (must be 0-31).\r\n{2}",record[i],FileLineData.linereport) end record[i] = [record[i]] 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) + 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 TrainerData::HAPPINESS+3 if record[i]>255 - raise _INTL("Bad happiness: {1} (must be 0-255)\r\n{2}",record[i],FileLineData.linereport) + raise _INTL("Bad happiness: {1} (must be 0-255).\r\n{2}",record[i],FileLineData.linereport) end 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) + raise _INTL("Bad nickname: {1} (must be 1-{2} characters).\r\n{3}", record[i], Pokemon::MAX_NAME_SIZE, FileLineData.linereport) end end end @@ -1482,10 +1505,10 @@ module Compiler rsection[schema[0]] = record end if !rsection[0] - raise _INTL("No trainer data file given in section {1}\r\n{2}",name,FileLineData.linereport) + raise _INTL("No trainer data file given in section {1}.\r\n{2}",name,FileLineData.linereport) end if !rsection[1] - raise _INTL("No trainer data file given in section {1}\r\n{2}",name,FileLineData.linereport) + raise _INTL("No trainer data file given in section {1}.\r\n{2}",name,FileLineData.linereport) end rsection[3] = rsection[0] rsection[4] = rsection[1] diff --git a/Data/Scripts/022_Compiler/004_Compiler_MapsAndEvents.rb b/Data/Scripts/022_Compiler/004_Compiler_MapsAndEvents.rb index afa2133fe..f3d67418a 100644 --- a/Data/Scripts/022_Compiler/004_Compiler_MapsAndEvents.rb +++ b/Data/Scripts/022_Compiler/004_Compiler_MapsAndEvents.rb @@ -1,4 +1,6 @@ module Compiler + module_function + #============================================================================= # Add new map files to the map tree. #============================================================================= @@ -579,7 +581,7 @@ module Compiler end push_script(firstpage.list,"setBattleRule(\"double\")") if doublebattle push_script(firstpage.list,sprintf("setBattleRule(\"backdrop\",\"%s\")",safequote(backdrop))) if backdrop - push_script(firstpage.list,sprintf("setBattleRule(\"outcomeVar\",%d)",outcomeVar)) if outcome>1 + push_script(firstpage.list,sprintf("setBattleRule(\"outcomeVar\",%d)",outcome)) if outcome>1 push_script(firstpage.list,"setBattleRule(\"canLose\")") if continue espeech = (endspeeches[0]) ? sprintf("_I(\"%s\")",safequote2(endspeeches[0])) : "nil" if battleid>0 @@ -628,7 +630,7 @@ module Compiler push_text(rematchpage.list,battles[i],1) push_script(rematchpage.list,"setBattleRule(\"double\")",1) if doublebattle push_script(rematchpage.list,sprintf("setBattleRule(\"backdrop\",%s)",safequote(backdrop)),1) if backdrop - push_script(rematchpage.list,sprintf("setBattleRule(\"outcomeVar\",%d)",outcomeVar),1) if outcome>1 + push_script(rematchpage.list,sprintf("setBattleRule(\"outcomeVar\",%d)",outcome),1) if outcome>1 push_script(rematchpage.list,"setBattleRule(\"canLose\")",1) if continue espeech = nil if endspeeches.length>0