mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
Added class GameData::EncounterType
This commit is contained in:
@@ -876,17 +876,17 @@ module Compiler
|
||||
encounter_hash = nil
|
||||
step_chances = nil
|
||||
need_step_chances = false # Not needed for new format only
|
||||
probabilities = nil
|
||||
current_type = -1
|
||||
probabilities = nil # Not needed for new format only
|
||||
current_type = nil
|
||||
expected_lines = 0
|
||||
max_level = GameData::GrowthRate.max_level
|
||||
pbCompilerEachPreppedLine("PBS/encounters.txt") { |line, line_no|
|
||||
next if line.length == 0
|
||||
if expected_lines > 0 && line[/^\d+,/] && new_format # Species line
|
||||
values = line.split(',')
|
||||
if expected_lines > 0 && line[/^\d+,/] && new_format # Species line (new format)
|
||||
values = line.split(',').collect! { |v| v.strip }
|
||||
if !values || values.length < 3
|
||||
raise _INTL("Expected a species entry line for encounter type {1} for map '{2}', got \"{3}\" instead.\r\n{4}",
|
||||
EncounterTypes::Names[current_type], encounter_hash[:map], line, FileLineData.linereport)
|
||||
GameData::EncounterType.get(current_type).real_name, encounter_hash[:map], line, FileLineData.linereport)
|
||||
end
|
||||
values = pbGetCsvRecord(line, line_no, [0, "vevV", nil, :Species])
|
||||
values[3] = values[2] if !values[3]
|
||||
@@ -898,11 +898,11 @@ module Compiler
|
||||
raise _INTL("Minimum level is greater than maximum level: {1}\r\n{2}", line, FileLineData.linereport)
|
||||
end
|
||||
encounter_hash[:types][current_type].push(values)
|
||||
elsif expected_lines > 0 && !new_format # Expect a species line and nothing else
|
||||
values = line.split(',')
|
||||
elsif expected_lines > 0 && !new_format # Expect a species line and nothing else (old format)
|
||||
values = line.split(',').collect! { |v| v.strip }
|
||||
if !values || values.length < 2
|
||||
raise _INTL("Expected a species entry line for encounter type {1} for map '{2}', got \"{3}\" instead.\r\n{4}",
|
||||
EncounterTypes::Names[current_type], encounter_hash[:map], line, FileLineData.linereport)
|
||||
GameData::EncounterType.get(current_type).real_name, encounter_hash[:map], line, FileLineData.linereport)
|
||||
end
|
||||
values = pbGetCsvRecord(line, line_no, [0, "evV", :Species])
|
||||
values[2] = values[1] if !values[2]
|
||||
@@ -921,26 +921,25 @@ module Compiler
|
||||
raise _INTL("Can't mix old and new formats.\r\n{1}", FileLineData.linereport)
|
||||
end
|
||||
new_format = true
|
||||
values = $~[1].split(',')
|
||||
values.collect! { |v| v.strip.to_i }
|
||||
values = $~[1].split(',').collect! { |v| v.strip.to_i }
|
||||
values[1] = 0 if !values[1] || values[1] == ""
|
||||
map_number = values[0]
|
||||
map_version = values[1]
|
||||
# Add map encounter's data to records
|
||||
if encounter_hash
|
||||
encounter_hash[:types].each do |encounters|
|
||||
next if !encounters || encounters.length == 0
|
||||
encounters.each_with_index do |enc, i|
|
||||
next if !enc
|
||||
encounters.each_with_index do |other_enc, j|
|
||||
next if i == j || !other_enc
|
||||
next if enc[1] != other_enc[1] || enc[2] != other_enc[2] || enc[3] != other_enc[3]
|
||||
enc[0] += other_enc[0]
|
||||
encounters[j] = nil
|
||||
encounter_hash[:types].each_value do |slots|
|
||||
next if !slots || slots.length == 0
|
||||
slots.each_with_index do |slot, i|
|
||||
next if !slot
|
||||
slots.each_with_index do |other_slot, j|
|
||||
next if i == j || !other_slot
|
||||
next if slot[1] != other_slot[1] || slot[2] != other_slot[2] || slot[3] != other_slot[3]
|
||||
slot[0] += other_slot[0]
|
||||
slots[j] = nil
|
||||
end
|
||||
end
|
||||
encounters.compact!
|
||||
encounters.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] }
|
||||
slots.compact!
|
||||
slots.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] }
|
||||
end
|
||||
GameData::Encounter.register(encounter_hash)
|
||||
end
|
||||
@@ -949,16 +948,16 @@ module Compiler
|
||||
if GameData::Encounter::DATA[key]
|
||||
raise _INTL("Encounters for map '{1}' are defined twice.\r\n{2}", map_number, FileLineData.linereport)
|
||||
end
|
||||
step_chances = []
|
||||
step_chances = {}
|
||||
# Construct encounter hash
|
||||
encounter_hash = {
|
||||
:id => key,
|
||||
:map => map_number,
|
||||
:version => map_version,
|
||||
:step_chances => step_chances,
|
||||
:types => []
|
||||
:types => {}
|
||||
}
|
||||
current_type = -1
|
||||
current_type = nil
|
||||
need_step_chances = true
|
||||
expected_lines = 0
|
||||
elsif line[/^(\d+)$/] # Map ID line (old format)
|
||||
@@ -969,19 +968,19 @@ module Compiler
|
||||
map_number = $~[1].to_i
|
||||
# Add map encounter's data to records
|
||||
if encounter_hash
|
||||
encounter_hash[:types].each do |encounters|
|
||||
next if !encounters || encounters.length == 0
|
||||
encounters.each_with_index do |enc, i|
|
||||
next if !enc
|
||||
encounters.each_with_index do |other_enc, j|
|
||||
next if i == j || !other_enc
|
||||
next if enc[1] != other_enc[1] || enc[2] != other_enc[2] || enc[3] != other_enc[3]
|
||||
enc[0] += other_enc[0]
|
||||
encounters[j] = nil
|
||||
encounter_hash[:types].each_value do |slots|
|
||||
next if !slots || slots.length == 0
|
||||
slots.each_with_index do |slot, i|
|
||||
next if !slot
|
||||
slots.each_with_index do |other_slot, j|
|
||||
next if i == j || !other_slot
|
||||
next if slot[1] != other_slot[1] || slot[2] != other_slot[2] || slot[3] != other_slot[3]
|
||||
slot[0] += other_slot[0]
|
||||
slots[j] = nil
|
||||
end
|
||||
end
|
||||
encounters.compact!
|
||||
encounters.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] }
|
||||
slots.compact!
|
||||
slots.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] }
|
||||
end
|
||||
GameData::Encounter.register(encounter_hash)
|
||||
end
|
||||
@@ -990,16 +989,16 @@ module Compiler
|
||||
if GameData::Encounter::DATA[key]
|
||||
raise _INTL("Encounters for map '{1}' are defined twice.\r\n{2}", map_number, FileLineData.linereport)
|
||||
end
|
||||
step_chances = EncounterTypes::Chances_Per_Step.clone
|
||||
step_chances = {}
|
||||
# Construct encounter hash
|
||||
encounter_hash = {
|
||||
:id => key,
|
||||
:map => map_number,
|
||||
:version => 0,
|
||||
:step_chances => step_chances,
|
||||
:types => []
|
||||
:types => {}
|
||||
}
|
||||
current_type = -1
|
||||
current_type = nil
|
||||
need_step_chances = true
|
||||
elsif !encounter_hash # File began with something other than a map ID line
|
||||
raise _INTL("Expected a map number, got \"{1}\" instead.\r\n{2}", line, FileLineData.linereport)
|
||||
@@ -1010,50 +1009,49 @@ module Compiler
|
||||
end
|
||||
need_step_chances = false
|
||||
values = pbGetCsvRecord(line, line_no, [0, "vvv"])
|
||||
for type in 0...step_chances.length
|
||||
next if EncounterTypes::Kinds[type] == 0
|
||||
step_chances[type] = values[EncounterTypes::Kinds[type] - 1]
|
||||
GameData::EncounterType.each do |enc_type|
|
||||
case enc_type.id
|
||||
when :land, :contest then step_chances[enc_type.id] = values[0]
|
||||
when :cave then step_chances[enc_type.id] = values[1]
|
||||
when :water then step_chances[enc_type.id] = values[2]
|
||||
end
|
||||
end
|
||||
else
|
||||
# Check if line is an encounter method name or not
|
||||
values = line.split(',')
|
||||
values.collect! { |v| v.strip }
|
||||
current_type = findIndex(EncounterTypes::Names) { |val| val == values[0] }
|
||||
if current_type >= 0 # Start of a new encounter method
|
||||
values = line.split(',').collect! { |v| v.strip }
|
||||
current_type = (values[0] && !values[0].empty?) ? values[0].to_sym : nil
|
||||
if current_type && GameData::EncounterType.exists?(current_type) # Start of a new encounter method
|
||||
need_step_chances = false
|
||||
if values[1] && !values[1].empty?
|
||||
step_chances[current_type] = values[1].to_i
|
||||
elsif new_format
|
||||
step_chances[current_type] = 0
|
||||
end
|
||||
probabilities = EncounterTypes::Probabilities[current_type].clone
|
||||
step_chances[current_type] = values[1].to_i if values[1] && !values[1].empty?
|
||||
step_chances[current_type] ||= GameData::EncounterType.get(current_type).trigger_chance
|
||||
probabilities = GameData::EncounterType.get(current_type).old_slots
|
||||
expected_lines = probabilities.length
|
||||
encounter_hash[:types][current_type] = []
|
||||
else
|
||||
raise _INTL("Undefined encounter type \"{1}\" for map '{2}'.\r\n{2}",
|
||||
raise _INTL("Undefined encounter type \"{1}\" for map '{2}'.\r\n{3}",
|
||||
line, encounter_hash[:map], FileLineData.linereport)
|
||||
end
|
||||
end
|
||||
}
|
||||
if expected_lines > 0 && !new_format
|
||||
raise _INTL("Not enough encounter lines given for encounter type {1} for map '{2}' (expected {3}).\r\n{4}",
|
||||
EncounterTypes::Names[current_type], encounter_hash[:map], probabilities.length, FileLineData.linereport)
|
||||
GameData::EncounterType.get(current_type).real_name, encounter_hash[:map], probabilities.length, FileLineData.linereport)
|
||||
end
|
||||
# Add last map's encounter data to records
|
||||
if encounter_hash
|
||||
encounter_hash[:types].each do |encounters|
|
||||
next if !encounters || encounters.length == 0
|
||||
encounters.each_with_index do |enc, i|
|
||||
next if !enc
|
||||
encounters.each_with_index do |other_enc, j|
|
||||
next if i == j || !other_enc
|
||||
next if enc[1] != other_enc[1] || enc[2] != other_enc[2] || enc[3] != other_enc[3]
|
||||
enc[0] += other_enc[0]
|
||||
encounters[j] = nil
|
||||
encounter_hash[:types].each_value do |slots|
|
||||
next if !slots || slots.length == 0
|
||||
slots.each_with_index do |slot, i|
|
||||
next if !slot
|
||||
slots.each_with_index do |other_slot, j|
|
||||
next if i == j || !other_slot
|
||||
next if slot[1] != other_slot[1] || slot[2] != other_slot[2] || slot[3] != other_slot[3]
|
||||
slot[0] += other_slot[0]
|
||||
slots[j] = nil
|
||||
end
|
||||
end
|
||||
encounters.compact!
|
||||
encounters.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] }
|
||||
slots.compact!
|
||||
slots.sort! { |a, b| (a[0] == b[0]) ? a[1].to_s <=> b[1].to_s : b[0] <=> a[0] }
|
||||
end
|
||||
GameData::Encounter.register(encounter_hash)
|
||||
end
|
||||
|
||||
@@ -543,18 +543,18 @@ module Compiler
|
||||
else
|
||||
f.write(sprintf("[%03d]%s\r\n", encounter_data.map, map_name))
|
||||
end
|
||||
encounter_data.types.each_with_index do |entries, type|
|
||||
next if !entries || entries.length == 0
|
||||
encounter_data.types.each do |type, slots|
|
||||
next if !slots || slots.length == 0
|
||||
if encounter_data.step_chances[type] && encounter_data.step_chances[type] > 0
|
||||
f.write(sprintf("%s,%d\r\n", EncounterTypes::Names[type], encounter_data.step_chances[type]))
|
||||
f.write(sprintf("%s,%d\r\n", type.to_s, encounter_data.step_chances[type]))
|
||||
else
|
||||
f.write(sprintf("%s\r\n", EncounterTypes::Names[type]))
|
||||
f.write(sprintf("%s\r\n", type.to_s))
|
||||
end
|
||||
entries.each do |entry|
|
||||
if entry[2] == entry[3]
|
||||
f.write(sprintf(" %d,%s,%d\r\n", entry[0], entry[1], entry[2]))
|
||||
slots.each do |slot|
|
||||
if slot[2] == slot[3]
|
||||
f.write(sprintf(" %d,%s,%d\r\n", slot[0], slot[1], slot[2]))
|
||||
else
|
||||
f.write(sprintf(" %d,%s,%d,%d\r\n", entry[0], entry[1], entry[2], entry[3]))
|
||||
f.write(sprintf(" %d,%s,%d,%d\r\n", slot[0], slot[1], slot[2], slot[3]))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user