Fixing up merge

This commit is contained in:
Maruno17
2020-10-18 22:08:55 +01:00
parent 3c2b97c21a
commit c4e69d0a2e
4 changed files with 72 additions and 48 deletions

View File

@@ -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 += (i<record.length) ? record[i] : record[0]
end
if evtotal>Pokemon::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]