From 28538be5164f4776e72319241be8e4aaedf37951 Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Sat, 26 Sep 2020 14:49:00 +0100 Subject: [PATCH] Fixed bug when compiling trainer comment "Outcome: X", added error messages if PBS files define the same ID numbers twice --- Data/Scripts/022_Compiler/002_Compiler_PBS.rb | 69 ++++++++++++------- .../003_Compiler_MapsAndEvents.rb | 4 +- 2 files changed, 47 insertions(+), 26 deletions(-) diff --git a/Data/Scripts/022_Compiler/002_Compiler_PBS.rb b/Data/Scripts/022_Compiler/002_Compiler_PBS.rb index c36f32120..630de4ad3 100644 --- a/Data/Scripts/022_Compiler/002_Compiler_PBS.rb +++ b/Data/Scripts/022_Compiler/002_Compiler_PBS.rb @@ -13,20 +13,22 @@ def pbCompileMetadata sectionname = $~[1] if currentmap==0 if sections[currentmap][MetadataHome]==nil - raise _INTL("The entry Home is required in metadata.txt section [{1}]",sectionname) - end - if sections[currentmap][MetadataPlayerA]==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][MetadataPlayerA]==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 @@ -354,7 +356,7 @@ def pbCompileTypes 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 @@ -363,10 +365,10 @@ def pbCompileTypes 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 @@ -401,17 +403,17 @@ def pbCompileTypes 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 @@ -463,6 +465,9 @@ def pbCompileAbilities 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 @@ -545,6 +550,9 @@ def pbCompileItems 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[ITEM_ID] = id constant = linerecord[1] @@ -603,11 +611,14 @@ def pbCompileMoves 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[MOVE_ID] = lineRecord[0] @@ -725,6 +736,14 @@ def pbCompilePokemonData # 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 @@ -741,10 +760,6 @@ def pbCompilePokemonData 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]=="" @@ -1170,6 +1185,9 @@ def pbCompileMachines 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 @@ -1269,13 +1287,16 @@ def pbCompileEncounters 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 @@ -1401,10 +1422,10 @@ def pbCompileTrainers 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 @@ -1417,10 +1438,10 @@ def pbCompileTrainers 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] @@ -1437,7 +1458,7 @@ def pbCompileTrainers 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) diff --git a/Data/Scripts/022_Compiler/003_Compiler_MapsAndEvents.rb b/Data/Scripts/022_Compiler/003_Compiler_MapsAndEvents.rb index 0ec07f932..1870de9b0 100644 --- a/Data/Scripts/022_Compiler/003_Compiler_MapsAndEvents.rb +++ b/Data/Scripts/022_Compiler/003_Compiler_MapsAndEvents.rb @@ -584,7 +584,7 @@ def pbConvertToTrainerEvent(event,trainerChecker) end pbPushScript(firstpage.list,"setBattleRule(\"double\")") if doublebattle pbPushScript(firstpage.list,sprintf("setBattleRule(\"backdrop\",\"%s\")",safequote(backdrop))) if backdrop - pbPushScript(firstpage.list,sprintf("setBattleRule(\"outcomeVar\",%d)",outcomeVar)) if outcome>1 + pbPushScript(firstpage.list,sprintf("setBattleRule(\"outcomeVar\",%d)",outcome)) if outcome>1 pbPushScript(firstpage.list,"setBattleRule(\"canLose\")") if continue espeech = (endspeeches[0]) ? sprintf("_I(\"%s\")",safequote2(endspeeches[0])) : "nil" if battleid>0 @@ -633,7 +633,7 @@ def pbConvertToTrainerEvent(event,trainerChecker) pbPushText(rematchpage.list,battles[i],1) pbPushScript(rematchpage.list,"setBattleRule(\"double\")",1) if doublebattle pbPushScript(rematchpage.list,sprintf("setBattleRule(\"backdrop\",%s)",safequote(backdrop)),1) if backdrop - pbPushScript(rematchpage.list,sprintf("setBattleRule(\"outcomeVar\",%d)",outcomeVar),1) if outcome>1 + pbPushScript(rematchpage.list,sprintf("setBattleRule(\"outcomeVar\",%d)",outcome),1) if outcome>1 pbPushScript(rematchpage.list,"setBattleRule(\"canLose\")",1) if continue espeech = nil if endspeeches.length>0