From 3a1b9b6dc646a008b8d5c1a597d496bd0b2ce7d1 Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Sat, 6 Mar 2021 22:01:16 +0000 Subject: [PATCH] Added class GameData::EncounterType --- .../011_Data/001_PBS data/013_Encounter.rb | 2 +- .../016_PBEncounterTypes.rb | 277 ++++++++++++------ .../012_Battle/009_PokeBall_CatchEffects.rb | 4 +- .../Scripts/013_Overworld/002_PField_Field.rb | 14 +- .../013_Overworld/003_PField_Visuals.rb | 4 +- .../013_Overworld/006_PField_Battles.rb | 4 +- .../013_Overworld/007_PField_Encounters.rb | 149 +++++----- .../009_PField_RoamingPokemon.rb | 15 +- .../013_Overworld/011_PField_FieldMoves.rb | 6 +- .../015_Items/002_PItem_ItemEffects.rb | 12 +- Data/Scripts/015_Items/004_PItem_Phone.rb | 15 +- Data/Scripts/015_Items/005_PItem_PokeRadar.rb | 2 +- .../017_UI/004_PScreen_PokedexEntry.rb | 8 +- .../002_PBattle_BugContest.rb | 4 +- .../001_Debug menus/002_Debug_MenuCommands.rb | 4 +- Data/Scripts/021_Debug/004_Editor_Screens.rb | 77 ++--- .../022_Compiler/002_Compiler_CompilePBS.rb | 126 ++++---- .../022_Compiler/003_Compiler_WritePBS.rb | 16 +- 18 files changed, 402 insertions(+), 337 deletions(-) diff --git a/Data/Scripts/011_Data/001_PBS data/013_Encounter.rb b/Data/Scripts/011_Data/001_PBS data/013_Encounter.rb index 756198f9b..2163ad049 100644 --- a/Data/Scripts/011_Data/001_PBS data/013_Encounter.rb +++ b/Data/Scripts/011_Data/001_PBS data/013_Encounter.rb @@ -62,7 +62,7 @@ module GameData @map = hash[:map] @version = hash[:version] || 0 @step_chances = hash[:step_chances] - @types = hash[:types] || [] + @types = hash[:types] || {} end end end diff --git a/Data/Scripts/011_Data/002_Hardcoded data/016_PBEncounterTypes.rb b/Data/Scripts/011_Data/002_Hardcoded data/016_PBEncounterTypes.rb index 4158415ce..c48cdbca7 100644 --- a/Data/Scripts/011_Data/002_Hardcoded data/016_PBEncounterTypes.rb +++ b/Data/Scripts/011_Data/002_Hardcoded data/016_PBEncounterTypes.rb @@ -1,94 +1,195 @@ -module EncounterTypes - Land = 0 - LandDay = 1 - LandNight = 2 - LandMorning = 3 - LandAfternoon = 4 - LandEvening = 5 - Cave = 6 - CaveDay = 7 - CaveNight = 8 - CaveMorning = 9 - CaveAfternoon = 10 - CaveEvening = 11 - Water = 12 - WaterDay = 13 - WaterNight = 14 - WaterMorning = 15 - WaterAfternoon = 16 - WaterEvening = 17 - OldRod = 18 - GoodRod = 19 - SuperRod = 20 - RockSmash = 21 - HeadbuttLow = 22 - HeadbuttHigh = 23 - BugContest = 24 +module GameData + class EncounterType + attr_reader :id + attr_reader :real_name + attr_reader :type # :land, :cave, :water, :fishing, :contest, :none + attr_reader :trigger_chance + attr_reader :old_slots - Names = [ - "Land", "LandDay", "LandNight", "LandMorning", "LandAfternoon", "LandEvening", - "Cave", "CaveDay", "CaveNight", "CaveMorning", "CaveAfternoon", "CaveEvening", - "Water", "WaterDay", "WaterNight", "WaterMorning", "WaterAfternoon", "WaterEvening", - "OldRod", "GoodRod", "SuperRod", "RockSmash", "HeadbuttLow", "HeadbuttHigh", - "BugContest" - ] - Probabilities = [ - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1], - [60, 30, 5, 4, 1], - [60, 30, 5, 4, 1], - [60, 30, 5, 4, 1], - [60, 30, 5, 4, 1], - [60, 30, 5, 4, 1], - [60, 30, 5, 4, 1], - [70, 30], - [60, 20, 20], - [40, 40, 15, 4, 1], - [60, 30, 5, 4, 1], - [30, 25, 20, 10, 5, 5, 4, 1], - [30, 25, 20, 10, 5, 5, 4, 1], - [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] - ] - Chances_Per_Step = [ - 21, 21, 21, 21, 21, 21, # Lands - 5, 5, 5, 5, 5, 5, # Caves - 2, 2, 2, 2, 2, 2, # Waters - 0, 0, 0, 50, 0, 0, 21 - ] - Kinds = [ - 1, 1, 1, 1, 1, 1, # Lands - 2, 2, 2, 2, 2, 2, # Caves - 3, 3, 3, 3, 3, 3, # Waters - 0, 0, 0, 0, 0, 0, 1 - ] + DATA = {} - def self.is_land_type?(enc_type) - return self.is_normal_land_type?(enc_type) || enc_type == BugContest - end + extend ClassMethodsSymbols + include InstanceMethods - def self.is_normal_land_type?(enc_type) - return [Land, LandDay, LandNight, LandMorning, LandAfternoon, LandEvening].include?(enc_type) - end + def self.load; end + def self.save; end - def self.is_cave_type?(enc_type) - return [Cave, CaveDay, CaveNight, CaveMorning, CaveAfternoon, CaveEvening].include?(enc_type) - end - - def self.is_water_type?(enc_type) - return [Water, WaterDay, WaterNight, WaterMorning, WaterAfternoon, WaterEvening].include?(enc_type) - end - - def self.is_fishing_type?(enc_type) - return [OldRod, GoodRod, SuperRod].include?(enc_type) + def initialize(hash) + @id = hash[:id] + @real_name = hash[:id].to_s || "Unnamed" + @type = hash[:type] || :none + @trigger_chance = hash[:trigger_chance] || 0 + @old_slots = hash[:old_slots] + end end end + +GameData::EncounterType.register({ + :id => :Land, + :type => :land, + :trigger_chance => 21, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :LandDay, + :type => :land, + :trigger_chance => 21, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :LandNight, + :type => :land, + :trigger_chance => 21, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :LandMorning, + :type => :land, + :trigger_chance => 21, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :LandAfternoon, + :type => :land, + :trigger_chance => 21, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :LandEvening, + :type => :land, + :trigger_chance => 21, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :Cave, + :type => :cave, + :trigger_chance => 5, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :CaveDay, + :type => :cave, + :trigger_chance => 5, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :CaveNight, + :type => :cave, + :trigger_chance => 5, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :CaveMorning, + :type => :cave, + :trigger_chance => 5, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :CaveAfternoon, + :type => :cave, + :trigger_chance => 5, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :CaveEvening, + :type => :cave, + :trigger_chance => 5, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) + +GameData::EncounterType.register({ + :id => :Water, + :type => :water, + :trigger_chance => 2, + :old_slots => [60, 30, 5, 4, 1] +}) + +GameData::EncounterType.register({ + :id => :WaterDay, + :type => :water, + :trigger_chance => 2, + :old_slots => [60, 30, 5, 4, 1] +}) + +GameData::EncounterType.register({ + :id => :WaterNight, + :type => :water, + :trigger_chance => 2, + :old_slots => [60, 30, 5, 4, 1] +}) + +GameData::EncounterType.register({ + :id => :WaterMorning, + :type => :water, + :trigger_chance => 2, + :old_slots => [60, 30, 5, 4, 1] +}) + +GameData::EncounterType.register({ + :id => :WaterAfternoon, + :type => :water, + :trigger_chance => 2, + :old_slots => [60, 30, 5, 4, 1] +}) + +GameData::EncounterType.register({ + :id => :WaterEvening, + :type => :water, + :trigger_chance => 2, + :old_slots => [60, 30, 5, 4, 1] +}) + +GameData::EncounterType.register({ + :id => :OldRod, + :type => :fishing, + :old_slots => [70, 30] +}) + +GameData::EncounterType.register({ + :id => :GoodRod, + :type => :fishing, + :old_slots => [60, 20, 20] +}) + +GameData::EncounterType.register({ + :id => :SuperRod, + :type => :fishing, + :old_slots => [40, 40, 15, 4, 1] +}) + +GameData::EncounterType.register({ + :id => :RockSmash, + :type => :none, + :trigger_chance => 50, + :old_slots => [60, 30, 5, 4, 1] +}) + +GameData::EncounterType.register({ + :id => :HeadbuttLow, + :type => :none, + :old_slots => [30, 25, 20, 10, 5, 5, 4, 1] +}) + +GameData::EncounterType.register({ + :id => :HeadbuttHigh, + :type => :none, + :old_slots => [30, 25, 20, 10, 5, 5, 4, 1] +}) + +GameData::EncounterType.register({ + :id => :BugContest, + :type => :contest, + :trigger_chance => 21, + :old_slots => [20, 20, 10, 10, 10, 10, 5, 5, 4, 4, 1, 1] +}) diff --git a/Data/Scripts/012_Battle/009_PokeBall_CatchEffects.rb b/Data/Scripts/012_Battle/009_PokeBall_CatchEffects.rb index 98a8d25a8..abd6c8fd9 100644 --- a/Data/Scripts/012_Battle/009_PokeBall_CatchEffects.rb +++ b/Data/Scripts/012_Battle/009_PokeBall_CatchEffects.rb @@ -162,9 +162,7 @@ BallHandlers::ModifyCatchRate.add(:LEVELBALL,proc { |ball,catchRate,battle,battl BallHandlers::ModifyCatchRate.add(:LUREBALL,proc { |ball,catchRate,battle,battler,ultraBeast| multiplier = (Settings::NEW_POKE_BALL_CATCH_RATES) ? 5 : 3 - catchRate *= multiplier if $PokemonTemp.encounterType==EncounterTypes::OldRod || - $PokemonTemp.encounterType==EncounterTypes::GoodRod || - $PokemonTemp.encounterType==EncounterTypes::SuperRod + catchRate *= multiplier if GameData::EncounterType.get($PokemonTemp.encounterType).type == :fishing next [catchRate,255].min }) diff --git a/Data/Scripts/013_Overworld/002_PField_Field.rb b/Data/Scripts/013_Overworld/002_PField_Field.rb index 2883f5927..c120d7242 100644 --- a/Data/Scripts/013_Overworld/002_PField_Field.rb +++ b/Data/Scripts/013_Overworld/002_PField_Field.rb @@ -371,21 +371,21 @@ Events.onChangeDirection += proc { def pbBattleOnStepTaken(repel_active) return if $Trainer.able_pokemon_count == 0 return if !$PokemonEncounters.encounter_possible_here? - encounterType = $PokemonEncounters.encounter_type - return if encounterType < 0 - return if !$PokemonEncounters.encounter_triggered?(encounterType, repel_active) - $PokemonTemp.encounterType = encounterType - encounter = $PokemonEncounters.choose_wild_pokemon(encounterType) + encounter_type = $PokemonEncounters.encounter_type + return if !encounter_type + return if !$PokemonEncounters.encounter_triggered?(encounter_type, repel_active) + $PokemonTemp.encounterType = encounter_type + encounter = $PokemonEncounters.choose_wild_pokemon(encounter_type) encounter = EncounterModifier.trigger(encounter) if $PokemonEncounters.allow_encounter?(encounter, repel_active) if $PokemonEncounters.have_double_wild_battle? - encounter2 = $PokemonEncounters.choose_wild_pokemon(encounterType) + encounter2 = $PokemonEncounters.choose_wild_pokemon(encounter_type) encounter2 = EncounterModifier.trigger(encounter2) pbDoubleWildBattle(encounter[0], encounter[1], encounter2[0], encounter2[1]) else pbWildBattle(encounter[0], encounter[1]) end - $PokemonTemp.encounterType = -1 + $PokemonTemp.encounterType = nil $PokemonTemp.encounterTriggered = true end $PokemonTemp.forceSingleBattle = false diff --git a/Data/Scripts/013_Overworld/003_PField_Visuals.rb b/Data/Scripts/013_Overworld/003_PField_Visuals.rb index 43edc63a6..76ad71dc9 100644 --- a/Data/Scripts/013_Overworld/003_PField_Visuals.rb +++ b/Data/Scripts/013_Overworld/003_PField_Visuals.rb @@ -40,9 +40,7 @@ def pbBattleAnimation(bgm=nil,battletype=0,foe=nil) if $PokemonGlobal.surfing || $PokemonGlobal.diving location = 3 elsif $PokemonTemp.encounterType && - ($PokemonTemp.encounterType==EncounterTypes::OldRod || - $PokemonTemp.encounterType==EncounterTypes::GoodRod || - $PokemonTemp.encounterType==EncounterTypes::SuperRod) + GameData::EncounterType.get($PokemonTemp.encounterType).type == :fishing location = 3 elsif $PokemonEncounters.has_cave_encounters? location = 2 diff --git a/Data/Scripts/013_Overworld/006_PField_Battles.rb b/Data/Scripts/013_Overworld/006_PField_Battles.rb index 1b622b959..81c19047e 100644 --- a/Data/Scripts/013_Overworld/006_PField_Battles.rb +++ b/Data/Scripts/013_Overworld/006_PField_Battles.rb @@ -169,9 +169,7 @@ def pbGetEnvironment ret = :None map_metadata = GameData::MapMetadata.try_get($game_map.map_id) ret = map_metadata.battle_environment if map_metadata && map_metadata.battle_environment - if $PokemonTemp.encounterType == EncounterTypes::OldRod || - $PokemonTemp.encounterType == EncounterTypes::GoodRod || - $PokemonTemp.encounterType == EncounterTypes::SuperRod + if GameData::EncounterType.get($PokemonTemp.encounterType).type == :fishing terrainTag = pbFacingTerrainTag else terrainTag = $game_player.terrain_tag diff --git a/Data/Scripts/013_Overworld/007_PField_Encounters.rb b/Data/Scripts/013_Overworld/007_PField_Encounters.rb index 14baec796..f796369cf 100644 --- a/Data/Scripts/013_Overworld/007_PField_Encounters.rb +++ b/Data/Scripts/013_Overworld/007_PField_Encounters.rb @@ -5,18 +5,18 @@ class PokemonEncounters attr_reader :step_count def initialize - @step_chances = nil - @encounter_tables = [] + @step_chances = {} + @encounter_tables = {} @chance_accumulator = 0 end def setup(map_ID) @step_count = 0 - @step_chances = nil - @encounter_tables = [] + @step_chances = {} + @encounter_tables = {} encounter_data = GameData::Encounter.get(map_ID, $PokemonGlobal.encounter_version) if encounter_data - @step_chances = encounter_data.step_chances.clone + encounter_data.step_chances.each { |type, value| @step_chances[type] = value } @encounter_tables = Marshal.load(Marshal.dump(encounter_data.types)) end end @@ -31,7 +31,7 @@ class PokemonEncounters # Returns whether encounters for the given encounter type have been defined # for the current map. def has_encounter_type?(enc_type) - return false if enc_type < 0 + return false if !enc_type return @encounter_tables[enc_type] && @encounter_tables[enc_type].length > 0 end @@ -40,7 +40,7 @@ class PokemonEncounters # the map's BugContest encounter type to generate caught Pokémon for the other # contestants. def map_has_encounter_type?(map_ID, enc_type) - return false if enc_type < 0 + return false if !enc_type encounter_data = GameData::Encounter.get(map_ID, $PokemonGlobal.encounter_version) return false if !encounter_data return encounter_data.types[enc_type] && encounter_data.types[enc_type].length > 0 @@ -49,42 +49,39 @@ class PokemonEncounters # Returns whether land-like encounters have been defined for the current map. # Applies only to encounters triggered by moving around. def has_land_encounters? - return has_normal_land_encounters? || - has_encounter_type?(EncounterTypes::BugContest) + GameData::EncounterType.each do |enc_type| + next if ![:land, :contest].include?(enc_type.type) + return true if has_encounter_type?(enc_type.id) + end + return false end # Returns whether land-like encounters have been defined for the current map # (ignoring the Bug Catching Contest one). # Applies only to encounters triggered by moving around. def has_normal_land_encounters? - return has_encounter_type?(EncounterTypes::Land) || - has_encounter_type?(EncounterTypes::LandDay) || - has_encounter_type?(EncounterTypes::LandNight) || - has_encounter_type?(EncounterTypes::LandMorning) || - has_encounter_type?(EncounterTypes::LandAfternoon) || - has_encounter_type?(EncounterTypes::LandEvening) + GameData::EncounterType.each do |enc_type| + return true if enc_type.type == :land && has_encounter_type?(enc_type.id) + end + return false end # Returns whether cave-like encounters have been defined for the current map. # Applies only to encounters triggered by moving around. def has_cave_encounters? - return has_encounter_type?(EncounterTypes::Cave) || - has_encounter_type?(EncounterTypes::CaveDay) || - has_encounter_type?(EncounterTypes::CaveNight) || - has_encounter_type?(EncounterTypes::CaveMorning) || - has_encounter_type?(EncounterTypes::CaveAfternoon) || - has_encounter_type?(EncounterTypes::CaveEvening) + GameData::EncounterType.each do |enc_type| + return true if enc_type.type == :cave && has_encounter_type?(enc_type.id) + end + return false end # Returns whether water-like encounters have been defined for the current map. # Applies only to encounters triggered by moving around (i.e. not fishing). def has_water_encounters? - return has_encounter_type?(EncounterTypes::Water) || - has_encounter_type?(EncounterTypes::WaterDay) || - has_encounter_type?(EncounterTypes::WaterNight) || - has_encounter_type?(EncounterTypes::WaterMorning) || - has_encounter_type?(EncounterTypes::WaterAfternoon) || - has_encounter_type?(EncounterTypes::WaterEvening) + GameData::EncounterType.each do |enc_type| + return true if enc_type.type == :water && has_encounter_type?(enc_type.id) + end + return false end #============================================================================= @@ -103,8 +100,8 @@ class PokemonEncounters # Returns whether a wild encounter should happen, based on its encounter # chance. Called when taking a step and by Rock Smash. def encounter_triggered?(enc_type, repel_active = false, triggered_by_step = true) - if enc_type < 0 || enc_type > EncounterTypes::Probabilities.length - raise ArgumentError.new(_INTL("Encounter type out of range")) + if !enc_type || !GameData::EncounterType.exists?(enc_type) + raise ArgumentError.new(_INTL("Encounter type {1} does not exist", enc_type)) end return false if $game_system.encounter_disabled return false if !$Trainer @@ -211,61 +208,47 @@ class PokemonEncounters return false end + # Checks the defined encounters for the current map and returns the encounter + # type that the given time should produce. Only returns an encounter type if + # it has been defined for the current map. + def find_valid_encounter_type_for_time(base_type, time) + ret = nil + if PBDayNight.isDay?(time) + try_type = nil + if PBDayNight.isMorning?(time) + try_type = (base_type.to_s + "Morning").to_sym + elsif PBDayNight.isAfternoon?(time) + try_type = (base_type.to_s + "Afternoon").to_sym + elsif PBDayNight.isEvening?(time) + try_type = (base_type.to_s + "Evening").to_sym + end + ret = try_type if try_type && has_encounter_type?(try_type) + if !ret + try_type = (base_type.to_s + "Day").to_sym + ret = try_type if has_encounter_type?(try_type) + end + else + try_type = (base_type.to_s + "Night").to_sym + ret = try_type if has_encounter_type?(try_type) + end + return ret if ret + return (has_encounter_type?(base_type)) ? base_type : nil + end + # Returns the encounter method that the current encounter should be generated # from, depending on the player's current location. def encounter_type time = pbGetTimeNow - ret = -1 + ret = nil if $PokemonGlobal.surfing - ret = EncounterTypes::Water if has_encounter_type?(EncounterTypes::Water) - if PBDayNight.isDay?(time) - ret = EncounterTypes::WaterDay if has_encounter_type?(EncounterTypes::WaterDay) - if PBDayNight.isMorning?(time) - ret = EncounterTypes::WaterMorning if has_encounter_type?(EncounterTypes::WaterMorning) - elsif PBDayNight.isAfternoon?(time) - ret = EncounterTypes::WaterAfternoon if has_encounter_type?(EncounterTypes::WaterAfternoon) - elsif PBDayNight.isEvening?(time) - ret = EncounterTypes::WaterEvening if has_encounter_type?(EncounterTypes::WaterEvening) - end - else - ret = EncounterTypes::WaterNight if has_encounter_type?(EncounterTypes::WaterNight) + ret = find_valid_encounter_type_for_time(:Water, time) + else # Land/Cave (can have both in the same map) + if has_land_encounters? && PBTerrain.isGrass?($game_map.terrain_tag($game_player.x, $game_player.y)) + ret = :BugContest if pbInBugContest? && has_encounter_type?(:BugContest) + ret = find_valid_encounter_type_for_time(:Land, time) if !ret end - else - check_land = false - if has_cave_encounters? - check_land = PBTerrain.isGrass?($game_map.terrain_tag($game_player.x, $game_player.y)) - ret = EncounterTypes::Cave if has_encounter_type?(EncounterTypes::Cave) - if PBDayNight.isDay?(time) - ret = EncounterTypes::CaveDay if has_encounter_type?(EncounterTypes::CaveDay) - if PBDayNight.isMorning?(time) - ret = EncounterTypes::CaveMorning if has_encounter_type?(EncounterTypes::CaveMorning) - elsif PBDayNight.isAfternoon?(time) - ret = EncounterTypes::CaveAfternoon if has_encounter_type?(EncounterTypes::CaveAfternoon) - elsif PBDayNight.isEvening?(time) - ret = EncounterTypes::CaveEvening if has_encounter_type?(EncounterTypes::CaveEvening) - end - else - ret = EncounterTypes::CaveNight if has_encounter_type?(EncounterTypes::CaveNight) - end - end - # Land - if has_land_encounters? || check_land - ret = EncounterTypes::Land if has_encounter_type?(EncounterTypes::Land) - if PBDayNight.isDay?(time) - ret = EncounterTypes::LandDay if has_encounter_type?(EncounterTypes::LandDay) - if PBDayNight.isMorning?(time) - ret = EncounterTypes::LandMorning if has_encounter_type?(EncounterTypes::LandMorning) - elsif PBDayNight.isAfternoon?(time) - ret = EncounterTypes::LandAfternoon if has_encounter_type?(EncounterTypes::LandAfternoon) - elsif PBDayNight.isEvening?(time) - ret = EncounterTypes::LandEvening if has_encounter_type?(EncounterTypes::LandEvening) - end - else - ret = EncounterTypes::LandNight if has_encounter_type?(EncounterTypes::LandNight) - end - if pbInBugContest? && has_encounter_type?(EncounterTypes::BugContest) - ret = EncounterTypes::BugContest - end + if !ret && has_cave_encounters? + ret = find_valid_encounter_type_for_time(:Cave, time) end end return ret @@ -277,8 +260,8 @@ class PokemonEncounters # list for the given encounter type. Returns nil if there are none defined. # A higher chance_rolls makes this method prefer rarer encounter slots. def choose_wild_pokemon(enc_type, chance_rolls = 1) - if enc_type < 0 || enc_type > EncounterTypes::Probabilities.length - raise ArgumentError.new(_INTL("Encounter type out of range")) + if !enc_type || !GameData::EncounterType.exists?(enc_type) + raise ArgumentError.new(_INTL("Encounter type {1} does not exist", enc_type)) end enc_list = @encounter_tables[enc_type] return nil if !enc_list || enc_list.length == 0 @@ -348,8 +331,8 @@ class PokemonEncounters # Used by the Bug Catching Contest to choose what the other participants # caught. def choose_wild_pokemon_for_map(map_ID, enc_type) - if enc_type < 0 || enc_type > EncounterTypes::Probabilities.length - raise ArgumentError.new(_INTL("Encounter type out of range")) + if !enc_type || !GameData::EncounterType.exists?(enc_type) + raise ArgumentError.new(_INTL("Encounter type {1} does not exist", enc_type)) end # Get the encounter table encounter_data = GameData::Encounter.get(map_ID, $PokemonGlobal.encounter_version) @@ -443,7 +426,7 @@ def pbEncounter(enc_type) else pbWildBattle(encounter1[0], encounter1[1]) end - $PokemonTemp.encounterType = -1 + $PokemonTemp.encounterType = nil $PokemonTemp.forceSingleBattle = false EncounterModifier.triggerEncounterEnd return true diff --git a/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb b/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb index 5fe5362d7..a5257e067 100644 --- a/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb +++ b/Data/Scripts/013_Overworld/009_PField_RoamingPokemon.rb @@ -119,21 +119,18 @@ end # method that will occur in the player's current position. def pbRoamingMethodAllowed(roamer_method) enc_type = $PokemonEncounters.encounter_type + type = GameData::EncounterType.get(enc_type).type case roamer_method when 0 # Any step-triggered method (except Bug Contest) - return EncounterTypes.is_normal_land_type?(enc_type) || - EncounterTypes.is_cave_type?(enc_type) || - EncounterTypes.is_water_type?(enc_type) + return [:land, :cave, :water].include?(type) when 1 # Walking (except Bug Contest) - return EncounterTypes.is_normal_land_type?(enc_type) || - EncounterTypes.is_cave_type?(enc_type) + return [:land, :cave].include?(type) when 2 # Surfing - return EncounterTypes.is_water_type?(enc_type) + return type == :water when 3 # Fishing - return EncounterTypes.is_fishing_type?(enc_type) + return type == :fishing when 4 # Water-based - return EncounterTypes.is_water_type?(enc_type) || - EncounterTypes.is_fishing_type?(enc_type) + return [:water, :fishing].include?(type) end return false end diff --git a/Data/Scripts/013_Overworld/011_PField_FieldMoves.rb b/Data/Scripts/013_Overworld/011_PField_FieldMoves.rb index 4ca9dd865..9dcd80b88 100644 --- a/Data/Scripts/013_Overworld/011_PField_FieldMoves.rb +++ b/Data/Scripts/013_Overworld/011_PField_FieldMoves.rb @@ -545,7 +545,7 @@ def pbHeadbuttEffect(event=nil) if rand(10)>=chance pbMessage(_INTL("Nope. Nothing...")) else - enctype = (chance==1) ? EncounterTypes::HeadbuttLow : EncounterTypes::HeadbuttHigh + enctype = (chance==1) ? :HeadbuttLow : :HeadbuttHigh if !pbEncounter(enctype) pbMessage(_INTL("Nope. Nothing...")) end @@ -592,8 +592,8 @@ HiddenMoveHandlers::UseMove.add(:HEADBUTT,proc { |move,pokemon| # Rock Smash #=============================================================================== def pbRockSmashRandomEncounter - if $PokemonEncounters.encounter_triggered?(EncounterTypes::RockSmash, false, false) - pbEncounter(EncounterTypes::RockSmash) + if $PokemonEncounters.encounter_triggered?(:RockSmash, false, false) + pbEncounter(:RockSmash) end end diff --git a/Data/Scripts/015_Items/002_PItem_ItemEffects.rb b/Data/Scripts/015_Items/002_PItem_ItemEffects.rb index d02c6c05d..421596c3d 100644 --- a/Data/Scripts/015_Items/002_PItem_ItemEffects.rb +++ b/Data/Scripts/015_Items/002_PItem_ItemEffects.rb @@ -242,9 +242,9 @@ ItemHandlers::UseInField.add(:OLDROD,proc { |item| pbMessage(_INTL("Can't use that here.")) next 0 end - encounter = $PokemonEncounters.has_encounter_type?(EncounterTypes::OldRod) + encounter = $PokemonEncounters.has_encounter_type?(:OldRod) if pbFishing(encounter,1) - pbEncounter(EncounterTypes::OldRod) + pbEncounter(:OldRod) end next 1 }) @@ -256,9 +256,9 @@ ItemHandlers::UseInField.add(:GOODROD,proc { |item| pbMessage(_INTL("Can't use that here.")) next 0 end - encounter = $PokemonEncounters.has_encounter_type?(EncounterTypes::GoodRod) + encounter = $PokemonEncounters.has_encounter_type?(:GoodRod) if pbFishing(encounter,2) - pbEncounter(EncounterTypes::GoodRod) + pbEncounter(:GoodRod) end next 1 }) @@ -270,9 +270,9 @@ ItemHandlers::UseInField.add(:SUPERROD,proc { |item| pbMessage(_INTL("Can't use that here.")) next 0 end - encounter = $PokemonEncounters.has_encounter_type?(EncounterTypes::SuperRod) + encounter = $PokemonEncounters.has_encounter_type?(:SuperRod) if pbFishing(encounter,3) - pbEncounter(EncounterTypes::SuperRod) + pbEncounter(:SuperRod) end next 1 }) diff --git a/Data/Scripts/015_Items/004_PItem_Phone.rb b/Data/Scripts/015_Items/004_PItem_Phone.rb index 54a977456..cfed81bac 100644 --- a/Data/Scripts/015_Items/004_PItem_Phone.rb +++ b/Data/Scripts/015_Items/004_PItem_Phone.rb @@ -254,20 +254,11 @@ def pbEncounterSpecies(phonenum) encounter_data = GameData::Encounter.get(phonenum[6], $PokemonGlobal.encounter_version) return "" if !encounter_data enc_tables = encounter_data.types - species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::Land]) + species = pbRandomEncounterSpecies(enc_tables[:Land]) if !species - species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::Cave]) + species = pbRandomEncounterSpecies(enc_tables[:Cave]) if !species - species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::LandDay]) - if !species - species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::LandMorning]) - if !species - species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::LandNight]) - if !species - species = pbRandomEncounterSpecies(enc_tables[EncounterTypes::Water]) - end - end - end + species = pbRandomEncounterSpecies(enc_tables[:Water]) end end return "" if !species diff --git a/Data/Scripts/015_Items/005_PItem_PokeRadar.rb b/Data/Scripts/015_Items/005_PItem_PokeRadar.rb index 6cfbafbb5..4c7f0354d 100644 --- a/Data/Scripts/015_Items/005_PItem_PokeRadar.rb +++ b/Data/Scripts/015_Items/005_PItem_PokeRadar.rb @@ -150,7 +150,7 @@ end # Event handlers ################################################################################ EncounterModifier.register(proc { |encounter| - if !EncounterTypes.is_normal_land_type?($PokemonTemp.encounterType) || + if GameData::EncounterType.get($PokemonTemp.encounterType).type != :land || $PokemonGlobal.bicycle || $PokemonGlobal.partner pbPokeRadarCancel next encounter diff --git a/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb b/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb index cd5062a15..789125ee7 100644 --- a/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb +++ b/Data/Scripts/017_UI/004_PScreen_PokedexEntry.rb @@ -279,11 +279,9 @@ class PokemonPokedexInfo_Scene def pbFindEncounter(enc_types, species) return false if !enc_types - enc_types.each do |enc_type| - next if !enc_type - enc_type.each do |slot| - return true if GameData::Species.get(slot[1]).species == species - end + enc_types.each_value do |slots| + next if !slots + slots.each { |slot| return true if GameData::Species.get(slot[1]).species == species } end return false end diff --git a/Data/Scripts/019_Other battles/002_PBattle_BugContest.rb b/Data/Scripts/019_Other battles/002_PBattle_BugContest.rb index 5694967af..8ed83e1ff 100644 --- a/Data/Scripts/019_Other battles/002_PBattle_BugContest.rb +++ b/Data/Scripts/019_Other battles/002_PBattle_BugContest.rb @@ -105,9 +105,9 @@ class BugContestState end end end - enctype=EncounterTypes::BugContest + enctype = :BugContest if !$PokemonEncounters.map_has_encounter_type?(@contestMap, enctype) - enctype=EncounterTypes::Land + enctype = :Land end for cont in @contestants enc=$PokemonEncounters.choose_wild_pokemon_for_map(@contestMap,enctype) diff --git a/Data/Scripts/021_Debug/001_Debug menus/002_Debug_MenuCommands.rb b/Data/Scripts/021_Debug/001_Debug menus/002_Debug_MenuCommands.rb index 8d7100cab..33b6bc89b 100644 --- a/Data/Scripts/021_Debug/001_Debug menus/002_Debug_MenuCommands.rb +++ b/Data/Scripts/021_Debug/001_Debug menus/002_Debug_MenuCommands.rb @@ -201,7 +201,7 @@ DebugMenuCommands.register("testwildbattle", { level = pbMessageChooseNumber(_INTL("Set the wild {1}'s level.", GameData::Species.get(species).name), params) if level > 0 - $PokemonTemp.encounterType = -1 + $PokemonTemp.encounterType = nil pbWildBattle(species, level) end end @@ -231,7 +231,7 @@ DebugMenuCommands.register("testwildbattleadvanced", { next end setBattleRule(sprintf("%dv%d", size0, pkmn.length)) - $PokemonTemp.encounterType = -1 + $PokemonTemp.encounterType = nil pbWildBattleCore(*pkmn) break elsif pkmnCmd == pkmnCmds.length - 2 # Set player side size diff --git a/Data/Scripts/021_Debug/004_Editor_Screens.rb b/Data/Scripts/021_Debug/004_Editor_Screens.rb index 9ed1890e6..c7e5aa4e3 100644 --- a/Data/Scripts/021_Debug/004_Editor_Screens.rb +++ b/Data/Scripts/021_Debug/004_Editor_Screens.rb @@ -48,8 +48,8 @@ def pbEncountersEditor :id => key, :map => new_map_ID, :version => new_version, - :step_chances => [], - :types => [] + :step_chances => {}, + :types => {} } GameData::Encounter.register(encounter_hash) maps.push([new_map_ID, new_version]) @@ -73,21 +73,23 @@ def pbEncountersEditor if GameData::Encounter.exists?(new_map_ID, new_version) pbMessage(_INTL("A set of encounters for map {1} version {2} already exists.", new_map_ID, new_version)) else - types = [] - GameData::Encounter.get(this_set[0], this_set[1]).types.each_with_index do |enc_type, i| - next if !enc_type - types[i] = [] - enc_type.each { |slot| types[i].push(slot.clone) } - end # Construct encounter hash key = sprintf("%s_%d", new_map_ID, new_version).to_sym encounter_hash = { :id => key, :map => new_map_ID, :version => new_version, - :step_chances => GameData::Encounter.get(this_set[0], this_set[1]).step_chances.clone, - :types => types + :step_chances => {}, + :types => {} } + GameData::Encounter.get(this_set[0], this_set[1]).step_chances.each do |type, value| + encounter_hash[:step_chances][type] = value + end + GameData::Encounter.get(this_set[0], this_set[1]).types.each do |type, slots| + next if !type || !slots || slots.length == 0 + encounter_hash[:types][type] = [] + slots.each { |slot| encounter_hash[:types][type].push(slot.clone) } + end GameData::Encounter.register(encounter_hash) maps.push([new_map_ID, new_version]) maps.sort! { |a, b| (a[0] == b[0]) ? a[1] <=> b[1] : a[0] <=> b[0] } @@ -142,10 +144,10 @@ def pbEncounterMapVersionEditor(enc_data) commands.push(_INTL("Map ID={1}", enc_data.map)) end commands.push(_INTL("Version={1}", enc_data.version)) - enc_data.types.each_with_index do |enc_type, i| - next if !enc_type - commands.push(_INTL("{1} (x{2})", EncounterTypes::Names[i], enc_type.length)) - enc_types.push(i) + enc_data.types.each do |enc_type, slots| + next if !enc_type || !slots || slots.length == 0 + commands.push(_INTL("{1} (x{2})", enc_type.to_s, slots.length)) + enc_types.push(enc_type) end commands.push(_INTL("[Add new encounter type]")) need_refresh = false @@ -182,16 +184,16 @@ def pbEncounterMapVersionEditor(enc_data) elsif ret == commands.length - 1 # Add new encounter type new_type_commands = [] new_types = [] - EncounterTypes::Names.each_with_index do |new_type, i| - next if enc_data.types[i] - new_type_commands.push(new_type) - new_types.push(i) + GameData::EncounterType.each do |enc| + next if enc_data.types[enc.id] + new_type_commands.push(enc.real_name) + new_types.push(enc.id) end if new_type_commands.length > 0 chosen_type_cmd = pbShowCommands(nil, new_type_commands, -1) if chosen_type_cmd >= 0 new_type = new_types[chosen_type_cmd] - enc_data.step_chances[new_type] = 0 + enc_data.step_chances[new_type] = GameData::EncounterType.get(new_type).trigger_chance enc_data.types[new_type] = [] pbEncounterTypeEditor(enc_data, new_type) enc_types.push(new_type) @@ -210,10 +212,10 @@ def pbEncounterMapVersionEditor(enc_data) when 1 # Copy new_type_commands = [] new_types = [] - EncounterTypes::Names.each_with_index do |new_type, i| - next if enc_data.types[i] - new_type_commands.push(new_type) - new_types.push(i) + GameData::EncounterType.each do |enc| + next if enc_data.types[enc.id] + new_type_commands.push(enc.real_name) + new_types.push(enc.id) end if new_type_commands.length > 0 chosen_type_cmd = pbMessage(_INTL("Choose an encounter type to copy to."), @@ -222,7 +224,7 @@ def pbEncounterMapVersionEditor(enc_data) new_type = new_types[chosen_type_cmd] enc_data.step_chances[new_type] = enc_data.step_chances[this_type] enc_data.types[new_type] = [] - enc_data.types[this_type].each { |enc| enc_data.types[new_type].push(enc.clone) } + enc_data.types[this_type].each { |slot| enc_data.types[new_type].push(slot.clone) } enc_types.push(new_type) ret = enc_types.sort.index(new_type) + 2 need_refresh = true @@ -231,9 +233,9 @@ def pbEncounterMapVersionEditor(enc_data) pbMessage(_INTL("There are no unused encounter types to copy to.")) end when 2 # Delete - if pbConfirmMessage(_INTL("Delete the encounter type {1}?", EncounterTypes::Names[this_type])) - enc_data.step_chances[this_type] = nil - enc_data.types[this_type] = nil + if pbConfirmMessage(_INTL("Delete the encounter type {1}?", GameData::EncounterType.get(this_type).real_name)) + enc_data.step_chances.delete(this_type) + enc_data.types.delete(this_type) need_refresh = true end end @@ -258,9 +260,10 @@ def pbEncounterTypeEditor(enc_data, enc_type) need_refresh = true loop do if need_refresh + enc_type_name = GameData::EncounterType.get(enc_type).real_name commands.clear commands.push(_INTL("Step chance={1}%", enc_data.step_chances[enc_type] || 0)) - commands.push(_INTL("Encounter type={1}", EncounterTypes::Names[enc_type])) + commands.push(_INTL("Encounter type={1}", enc_type_name)) if enc_data.types[enc_type] && enc_data.types[enc_type].length > 0 enc_data.types[enc_type].each do |slot| commands.push(EncounterSlotProperty.format(slot)) @@ -281,24 +284,24 @@ def pbEncounterTypeEditor(enc_data, enc_type) new_type_commands = [] new_types = [] chosen_type_cmd = 0 - EncounterTypes::Names.each_with_index do |type_name, i| - next if enc_data.types[i] && i != enc_type - new_type_commands.push(type_name) - new_types.push(i) - chosen_type_cmd = new_type_commands.length - 1 if i == enc_type + GameData::EncounterType.each do |enc| + next if enc_data.types[enc.id] && enc.id != enc_type + new_type_commands.push(enc.real_name) + new_types.push(enc.id) + chosen_type_cmd = new_type_commands.length - 1 if enc.id == enc_type end chosen_type_cmd = pbShowCommands(nil, new_type_commands, -1, chosen_type_cmd) if chosen_type_cmd >= 0 && new_types[chosen_type_cmd] != enc_type new_type = new_types[chosen_type_cmd] enc_data.step_chances[new_type] = enc_data.step_chances[enc_type] - enc_data.step_chances[enc_type] = nil + enc_data.step_chances.delete(enc_type) enc_data.types[new_type] = enc_data.types[enc_type] - enc_data.types[enc_type] = nil + enc_data.types.delete(enc_type) enc_type = new_type need_refresh = true end elsif ret == commands.length - 1 # Add new encounter slot - new_slot_data = EncounterSlotProperty.set(EncounterTypes::Names[enc_type], nil) + new_slot_data = EncounterSlotProperty.set(enc_type_name, nil) if new_slot_data enc_data.types[enc_type].push(new_slot_data) need_refresh = true @@ -307,7 +310,7 @@ def pbEncounterTypeEditor(enc_data, enc_type) case pbShowCommands(nil, [_INTL("Edit"), _INTL("Copy"), _INTL("Delete"), _INTL("Cancel")], 4) when 0 # Edit old_slot_data = enc_data.types[enc_type][ret - 2] - new_slot_data = EncounterSlotProperty.set(EncounterTypes::Names[enc_type], old_slot_data.clone) + new_slot_data = EncounterSlotProperty.set(enc_type_name, old_slot_data.clone) if new_slot_data && new_slot_data != old_slot_data enc_data.types[enc_type][ret - 2] = new_slot_data need_refresh = true diff --git a/Data/Scripts/022_Compiler/002_Compiler_CompilePBS.rb b/Data/Scripts/022_Compiler/002_Compiler_CompilePBS.rb index 106b35019..c134c1b26 100644 --- a/Data/Scripts/022_Compiler/002_Compiler_CompilePBS.rb +++ b/Data/Scripts/022_Compiler/002_Compiler_CompilePBS.rb @@ -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 diff --git a/Data/Scripts/022_Compiler/003_Compiler_WritePBS.rb b/Data/Scripts/022_Compiler/003_Compiler_WritePBS.rb index d0c8ee883..1899a729e 100644 --- a/Data/Scripts/022_Compiler/003_Compiler_WritePBS.rb +++ b/Data/Scripts/022_Compiler/003_Compiler_WritePBS.rb @@ -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