def pbCompileTrainers
# Trainer types
records=[]
trainernames=[]
count=0
maxValue=0
pbCompilerEachPreppedLine("PBS/trainertypes.txt"){|line,lineno|
record=pbGetCsvRecord(line,lineno,[0,"unsUSSSeUS", # ID can be 0
nil,nil,nil,nil,nil,nil,nil,{
""=>2,"Male"=>0,"M"=>0,"0"=>0,"Female"=>1,"F"=>1,"1"=>1,"Mixed"=>2,"X"=>2,"2"=>2
},nil,nil]
)
if record[3] && (record[3]<0 || record[3]>255)
raise _INTL("Bad money amount (must be from 0 through 255)\r\n{1}",FileLineData.linereport)
end
record[3]=30 if !record[3]
if record[8] && (record[8]<0 || record[8]>255)
raise _INTL("Bad skill value (must be from 0 through 255)\r\n{1}",FileLineData.linereport)
end
record[8]=record[3] if !record[8]
trainernames[record[0]]=record[2]
if records[record[0]]
raise _INTL("Two trainer types ({1} and {2}) have the same ID ({3}), which is not allowed.\r\n{4}",
records[record[0]][1],record[1],record[0],FileLineData.linereport)
end
records[record[0]]=record
maxValue=[maxValue,record[0]].max
}
count=records.compact.length
MessageTypes.setMessages(MessageTypes::TrainerTypes,trainernames)
code="class PBTrainers\r\n"
for rec in records
next if !rec
code+="#{rec[1]}=#{rec[0]}\r\n"
end
code+="\r\ndef PBTrainers.getName(id)\r\nreturn pbGetMessage(MessageTypes::TrainerTypes,id)\r\nend"
code+="\r\ndef PBTrainers.getCount\r\nreturn #{count}\r\nend"
code+="\r\ndef PBTrainers.maxValue\r\nreturn #{maxValue}\r\nend\r\nend"
eval(code)
pbAddScript(code,"PBTrainers")
File.open("Data/trainertypes.dat","wb"){|f|
Marshal.dump(records,f)
}
# Individual trainers
lines=[]
linenos=[]
lineno=1
File.open("PBS/trainers.txt","rb"){|f|
FileLineData.file="PBS/trainers.txt"
f.each_line {|line|
if lineno==1 && line[0]==0xEF && line[1]==0xBB && line[2]==0xBF
line=line[3,line.length-3]
end
line=prepline(line)
if line!=""
lines.push(line)
linenos.push(lineno)
end
lineno+=1
}
}
nameoffset=0
trainers=[]
trainernames.clear
i=0; loop do break unless i<lines.length
FileLineData.setLine(lines[i],linenos[i])
trainername=parseTrainer(lines[i])
FileLineData.setLine(lines[i+1],linenos[i+1])
nameline=strsplit(lines[i+1],/\s*,\s*/)
name=nameline[0]
raise _INTL("Trainer name too long\r\n{1}",FileLineData.linereport) if name.length>=0x10000
trainernames.push(name)
partyid=0
if nameline[1] && nameline[1]!=""
raise _INTL("Expected a number for the trainer battle ID\r\n{1}",FileLineData.linereport) if !nameline[1][/^\d+$/]
partyid=nameline[1].to_i
end
FileLineData.setLine(lines[i+2],linenos[i+2])
items=strsplit(lines[i+2],/\s*,\s*/)
items[0].gsub!(/^\s+/,"") # Number of Pokémon
raise _INTL("Expected a number for the number of Pokémon\r\n{1}",FileLineData.linereport) if !items[0][/^\d+$/]
numpoke=items[0].to_i
realitems=[]
for j in 1...items.length # Items held by Trainer
realitems.push(parseItem(items[j])) if items[j] && items[j]!=""
end
pkmn=[]
for j in 0...numpoke
FileLineData.setLine(lines[i+j+3],linenos[i+j+3])
poke=strsplit(lines[i+j+3],/\s*,\s*/)
begin
# Species
poke[TPSPECIES]=parseSpecies(poke[TPSPECIES])
rescue
raise _INTL("Expected a species name: {1}\r\n{2}",poke[0],FileLineData.linereport)
end
# Level
poke[TPLEVEL]=poke[TPLEVEL].to_i
raise _INTL("Bad level: {1} (must be from 1-{2})\r\n{3}",poke[TPLEVEL],
PBExperience::MAXLEVEL,FileLineData.linereport) if poke[TPLEVEL]<=0 || poke[TPLEVEL]>PBExperience::MAXLEVEL
# Held item
if !poke[TPITEM] || poke[TPITEM]==""
poke[TPITEM]=TPDEFAULTS[TPITEM]
else
poke[TPITEM]=parseItem(poke[TPITEM])
end
# Moves
moves=[]
for j in [TPMOVE1,TPMOVE2,TPMOVE3,TPMOVE4]
moves.push(parseMove(poke[j])) if poke[j] && poke[j]!=""
end
for j in 0...4
index=[TPMOVE1,TPMOVE2,TPMOVE3,TPMOVE4][j]
if moves[j] && moves[j]!=0
poke[index]=moves[j]
else
poke[index]=TPDEFAULTS[index]
end
end
# Ability
if !poke[TPABILITY] || poke[TPABILITY]==""
poke[TPABILITY]=TPDEFAULTS[TPABILITY]
else
poke[TPABILITY]=poke[TPABILITY].to_i
raise _INTL("Bad abilityflag: {1} (must be 0 or 1 or 2-5)\r\n{2}",poke[TPABILITY],FileLineData.linereport) if poke[TPABILITY]<0 || poke[TPABILITY]>5
end
# Gender
if !poke[TPGENDER] || poke[TPGENDER]==""
poke[TPGENDER]=TPDEFAULTS[TPGENDER]
else
if poke[TPGENDER]=="M"
poke[TPGENDER]=0
elsif poke[TPGENDER]=="F"
poke[TPGENDER]=1
else
poke[TPGENDER]=poke[TPGENDER].to_i
raise _INTL("Bad genderflag: {1} (must be M or F, or 0 or 1)\r\n{2}",poke[TPGENDER],FileLineData.linereport) if poke[TPGENDER]<0 || poke[TPGENDER]>1
end
end
# Form
if !poke[TPFORM] || poke[TPFORM]==""
poke[TPFORM]=TPDEFAULTS[TPFORM]
else
poke[TPFORM]=poke[TPFORM].to_i
raise _INTL("Bad form: {1} (must be 0 or greater)\r\n{2}",poke[TPFORM],FileLineData.linereport) if poke[TPFORM]<0
end
# Shiny
if !poke[TPSHINY] || poke[TPSHINY]==""
poke[TPSHINY]=TPDEFAULTS[TPSHINY]
elsif poke[TPSHINY]=="shiny"
poke[TPSHINY]=true
else
poke[TPSHINY]=csvBoolean!(poke[TPSHINY].clone)
end
# Nature
if !poke[TPNATURE] || poke[TPNATURE]==""
poke[TPNATURE]=TPDEFAULTS[TPNATURE]
else
poke[TPNATURE]=parseNature(poke[TPNATURE])
end
# IVs
if !poke[TPIV] || poke[TPIV]==""
poke[TPIV]=TPDEFAULTS[TPIV]
else
poke[TPIV]=poke[TPIV].to_i
raise _INTL("Bad IV: {1} (must be from 0-31)\r\n{2}",poke[TPIV],FileLineData.linereport) if poke[TPIV]<0 || poke[TPIV]>31
end
# Happiness
if !poke[TPHAPPINESS] || poke[TPHAPPINESS]==""
poke[TPHAPPINESS]=TPDEFAULTS[TPHAPPINESS]
else
poke[TPHAPPINESS]=poke[TPHAPPINESS].to_i
raise _INTL("Bad happiness: {1} (must be from 0-255)\r\n{2}",poke[TPHAPPINESS],FileLineData.linereport) if poke[TPHAPPINESS]<0 || poke[TPHAPPINESS]>255
end
# Nickname
if !poke[TPNAME] || poke[TPNAME]==""
poke[TPNAME]=TPDEFAULTS[TPNAME]
else
poke[TPNAME]=poke[TPNAME].to_s
raise _INTL("Bad nickname: {1} (must be 1-20 characters)\r\n{2}",poke[TPNAME],FileLineData.linereport) if (poke[TPNAME].to_s).length>20
end
# Shadow
if !poke[TPSHADOW] || poke[TPSHADOW]==""
poke[TPSHADOW]=TPDEFAULTS[TPSHADOW]
else
poke[TPSHADOW]=csvBoolean!(poke[TPSHADOW].clone)
end
# Ball
if !poke[TPBALL] || poke[TPBALL]==""
poke[TPBALL]=TPDEFAULTS[TPBALL]
else
poke[TPBALL]=poke[TPBALL].to_i
raise _INTL("Bad form: {1} (must be 0 or greater)\r\n{2}",poke[TPBALL],FileLineData.linereport) if poke[TPBALL]<0
end
pkmn.push(poke)
end
i+=3+numpoke
MessageTypes.setMessagesAsHash(MessageTypes::TrainerNames,trainernames)
trainers.push([trainername,name,realitems,pkmn,partyid])
nameoffset+=name.length
end
save_data(trainers,"Data/trainers.dat")
end
class PokeBattle_Trainer
def hasSkillCode(code)
c=skillCode
return true if c!=nil && c!="" && c[/#{code}/]
return false
end
end