diff --git a/Data/Scripts/001_Technical/002_Files/001_FileTests.rb b/Data/Scripts/001_Technical/002_Files/001_FileTests.rb index 6dd607919..973e9d9f6 100644 --- a/Data/Scripts/001_Technical/002_Files/001_FileTests.rb +++ b/Data/Scripts/001_Technical/002_Files/001_FileTests.rb @@ -9,7 +9,7 @@ class Dir files = [] filters = [filters] if !filters.is_a?(Array) self.chdir(dir) do - for filter in filters + filters.each do |filter| self.glob(filter) { |f| files.push(full ? (dir + "/" + f) : f) } end end @@ -22,7 +22,7 @@ class Dir # sets variables for starting files = [] subfolders = [] - for file in self.get(dir, filters, full) + self.get(dir, filters, full).each do |file| # engages in recursion to read the entire file tree if self.safe?(file) # Is a directory subfolders += self.all(file, filters, full) @@ -157,7 +157,7 @@ def canonicalize(c) pos = -1 ret = [] retstr = "" - for x in csplit + csplit.each do |x| if x == ".." if pos >= 0 ret.delete_at(pos) @@ -168,7 +168,7 @@ def canonicalize(c) pos += 1 end end - for i in 0...ret.length + ret.length.times do |i| retstr += "/" if i > 0 retstr += ret[i] end @@ -184,7 +184,7 @@ module RTP return false if nil_or_empty?(filename) eachPathFor(filename) { |path| return true if safeExists?(path) - for ext in extensions + extensions.each do |ext| return true if safeExists?(path + ext) end } @@ -203,7 +203,7 @@ module RTP return filename if nil_or_empty?(filename) eachPathFor(filename) { |path| return path if safeExists?(path) - for ext in extensions + extensions.each do |ext| file = path + ext return file if safeExists?(file) end @@ -449,7 +449,8 @@ class StringInput def gets raise IOError, 'closed stream' if @closed - if idx = @string.index(?\n, @pos) + idx = @string.index("\n", @pos) + if idx idx += 1 # "\n".size line = @string[@pos...idx] @pos = idx diff --git a/Data/Scripts/001_Technical/002_RubyUtilities.rb b/Data/Scripts/001_Technical/002_RubyUtilities.rb index 3e7076f34..6646b17c1 100644 --- a/Data/Scripts/001_Technical/002_RubyUtilities.rb +++ b/Data/Scripts/001_Technical/002_RubyUtilities.rb @@ -37,7 +37,7 @@ class String width -= bitmap.text_size("...").width string_width = 0 text = [] - for char in string.scan(/./) + string.scan(/./).each do |char| wdh = bitmap.text_size(char).width next if (wdh + string_width) > width string_width += wdh @@ -45,7 +45,7 @@ class String end text.push("...") if text.length < string.length new_string = "" - for char in text + text.each do |char| new_string += char end return new_string @@ -97,7 +97,7 @@ class Hash h = self.clone # failsafe return h if !hash.is_a?(Hash) - for key in hash.keys + hash.keys.each do |key| if self[key].is_a?(Hash) h.deep_merge!(hash[key]) else @@ -109,7 +109,7 @@ class Hash def deep_merge!(hash) return if !hash.is_a?(Hash) - for key in hash.keys + hash.keys.each do |key| if self[key].is_a?(Hash) self[key].deep_merge!(hash[key]) else @@ -139,7 +139,9 @@ class File data = "" t = Time.now File.open(source, 'rb') do |f| - while r = f.read(4096) + loop do + r = f.read(4096) + break if !r if Time.now - t > 1 Graphics.update t = Time.now diff --git a/Data/Scripts/001_Technical/003_Intl_Messages.rb b/Data/Scripts/001_Technical/003_Intl_Messages.rb index 6e593e46a..6923aaf3b 100644 --- a/Data/Scripts/001_Technical/003_Intl_Messages.rb +++ b/Data/Scripts/001_Technical/003_Intl_Messages.rb @@ -24,7 +24,7 @@ def pbSetTextMessages begin t = Time.now.to_i texts = [] - for script in $RGSS_SCRIPTS + $RGSS_SCRIPTS.each do |script| if Time.now.to_i - t >= 5 t = Time.now.to_i Graphics.update @@ -34,8 +34,8 @@ def pbSetTextMessages end if safeExists?("Data/PluginScripts.rxdata") plugin_scripts = load_data("Data/PluginScripts.rxdata") - for plugin in plugin_scripts - for script in plugin[2] + plugin_scripts.each do |plugin| + plugin[2].each do |script| if Time.now.to_i - t >= 5 t = Time.now.to_i Graphics.update @@ -50,7 +50,7 @@ def pbSetTextMessages commonevents = load_data("Data/CommonEvents.rxdata") items = [] choices = [] - for event in commonevents.compact + commonevents.compact.each do |event| if Time.now.to_i - t >= 5 t = Time.now.to_i Graphics.update @@ -58,7 +58,7 @@ def pbSetTextMessages begin neednewline = false lastitem = "" - for j in 0...event.list.size + event.list.size.times do |j| list = event.list[j] if neednewline && list.code != 401 if lastitem != "" @@ -72,7 +72,7 @@ def pbSetTextMessages lastitem += "#{list.parameters[0]}" neednewline = true elsif list.code == 102 - for k in 0...list.parameters[0].length + list.parameters[0].length.times do |k| choices.push(list.parameters[0][k]) end neednewline = false @@ -86,7 +86,7 @@ def pbSetTextMessages pbAddScriptTexts(items, list.parameters[1]) elsif list.code == 209 route = list.parameters[1] - for k in 0...route.list.size + route.list.size.times do |k| if route.list[k].code == 45 pbAddScriptTexts(items, route.list[k].parameters[0]) end @@ -110,7 +110,7 @@ def pbSetTextMessages items.concat(choices) MessageTypes.setMapMessagesAsHash(0, items) mapinfos = pbLoadMapInfos - for id in mapinfos.keys + mapinfos.keys.each do |id| if Time.now.to_i - t >= 5 t = Time.now.to_i Graphics.update @@ -120,16 +120,16 @@ def pbSetTextMessages map = load_data(filename) items = [] choices = [] - for event in map.events.values + map.events.values.each do |event| if Time.now.to_i - t >= 5 t = Time.now.to_i Graphics.update end begin - for i in 0...event.pages.size + event.pages.size.times do |i| neednewline = false lastitem = "" - for j in 0...event.pages[i].list.size + event.pages[i].list.size.times do |j| list = event.pages[i].list[j] if neednewline && list.code != 401 if lastitem != "" @@ -143,7 +143,7 @@ def pbSetTextMessages lastitem += "#{list.parameters[0]}" neednewline = true elsif list.code == 102 - for k in 0...list.parameters[0].length + list.parameters[0].length.times do |k| choices.push(list.parameters[0][k]) end neednewline = false @@ -157,7 +157,7 @@ def pbSetTextMessages pbAddScriptTexts(items, list.parameters[1]) elsif list.code == 209 route = list.parameters[1] - for k in 0...route.list.size + route.list.size.times do |k| if route.list[k].code == 45 pbAddScriptTexts(items, route.list[k].parameters[0]) end @@ -312,7 +312,7 @@ class OrderedHash < Hash def inspect str = "{" - for i in 0...@keys.length + @keys.length.times do |i| str += ", " if i > 0 str += @keys[i].inspect + "=>" + self[@keys[i]].inspect end @@ -330,7 +330,7 @@ class OrderedHash < Hash @keys |= [] @keys -= [key] end - return super(key, value) + super(key, value) end def self._load(string) @@ -338,7 +338,7 @@ class OrderedHash < Hash keysvalues = Marshal.load(string) keys = keysvalues[0] values = keysvalues[1] - for i in 0...keys.length + keys.length.times do |i| ret[keys[i]] = values[i] end return ret @@ -346,7 +346,7 @@ class OrderedHash < Hash def _dump(_depth = 100) values = [] - for key in @keys + @keys.each do |key| values.push(self[key]) end return Marshal.dump([@keys, values]) @@ -415,7 +415,7 @@ class Messages case msgs when Array f.write("[#{secname}]\r\n") - for j in 0...msgs.length + msgs.length.times do |j| next if nil_or_empty?(msgs[j]) value = Messages.normalizeValue(msgs[j]) origValue = "" @@ -431,7 +431,7 @@ class Messages when OrderedHash f.write("[#{secname}]\r\n") keys = msgs.keys - for key in keys + keys.each do |key| next if nil_or_empty?(msgs[key]) value = Messages.normalizeValue(msgs[key]) valkey = Messages.normalizeValue(key) @@ -456,12 +456,12 @@ class Messages f.write("# To localize this text for a particular language, please\r\n") f.write("# translate every second line of this file.\r\n") if origMessages.messages[0] - for i in 0...origMessages.messages[0].length + origMessages.messages[0].length.times do |i| msgs = origMessages.messages[0][i] Messages.writeObject(f, msgs, "Map#{i}", origMessages) end end - for i in 1...origMessages.messages.length + (1...origMessages.messages.length).each do |i| msgs = origMessages.messages[i] Messages.writeObject(f, msgs, i, origMessages) end @@ -471,7 +471,7 @@ class Messages def setMessages(type, array) @messages = [] if !@messages arr = [] - for i in 0...array.length + array.length.times do |i| arr[i] = (array[i]) ? array[i] : "" end @messages[type] = arr @@ -480,7 +480,7 @@ class Messages def addMessages(type, array) @messages = [] if !@messages arr = (@messages[type]) ? @messages[type] : [] - for i in 0...array.length + array.length.times do |i| arr[i] = (array[i]) ? array[i] : (arr[i]) ? arr[i] : "" end @messages[type] = arr @@ -488,7 +488,7 @@ class Messages def self.createHash(_type, array) arr = OrderedHash.new - for i in 0...array.length + array.length.times do |i| if array[i] key = Messages.stringToKey(array[i]) arr[key] = array[i] @@ -499,7 +499,7 @@ class Messages def self.addToHash(_type, array, hash) hash = OrderedHash.new if !hash - for i in 0...array.length + array.length.times do |i| if array[i] key = Messages.stringToKey(array[i]) hash[key] = array[i] @@ -738,7 +738,7 @@ def _INTL(*arg) string = arg[0] end string = string.clone - for i in 1...arg.length + (1...arg.length).each do |i| string.gsub!(/\{#{i}\}/, "#{arg[i]}") end return string @@ -754,7 +754,7 @@ def _ISPRINTF(*arg) string = arg[0] end string = string.clone - for i in 1...arg.length + (1...arg.length).each do |i| string.gsub!(/\{#{i}\:([^\}]+?)\}/) { |m| next sprintf("%" + $1, arg[i]) } @@ -769,7 +769,7 @@ end def _MAPINTL(mapid, *arg) string = MessageTypes.getFromMapHash(mapid, arg[0]) string = string.clone - for i in 1...arg.length + (1...arg.length).each do |i| string.gsub!(/\{#{i}\}/, "#{arg[i]}") end return string @@ -778,7 +778,7 @@ end def _MAPISPRINTF(mapid, *arg) string = MessageTypes.getFromMapHash(mapid, arg[0]) string = string.clone - for i in 1...arg.length + (1...arg.length).each do |i| string.gsub!(/\{#{i}\:([^\}]+?)\}/) { |m| next sprintf("%" + $1, arg[i]) } diff --git a/Data/Scripts/001_Technical/005_PluginManager.rb b/Data/Scripts/001_Technical/005_PluginManager.rb index 47e65c792..4b6287a9c 100644 --- a/Data/Scripts/001_Technical/005_PluginManager.rb +++ b/Data/Scripts/001_Technical/005_PluginManager.rb @@ -185,7 +185,7 @@ module PluginManager idx_b = order.index(b) || order.size next idx_a <=> idx_b end - for key in keys + keys.each do |key| value = options[key] case key when :name # Plugin name @@ -211,7 +211,7 @@ module PluginManager when :dependencies # Plugin dependencies dependencies = value dependencies = [dependencies] if !dependencies.is_a?(Array) || !dependencies[0].is_a?(Array) - for dep in value + value.each do |dep| case dep when String # "plugin name" if !self.installed?(dep) @@ -238,7 +238,8 @@ module PluginManager if self.installed?(dep_name) # Have plugin but lower version msg = "Plugin '#{name}' requires plugin '#{dep_name}' version #{dep_version} or higher, " + "but the installed version is #{self.version(dep_name)}." - if dep_link = self.link(dep_name) + dep_link = self.link(dep_name) + if dep_link msg += "\r\nCheck #{dep_link} for an update to plugin '#{dep_name}'." end self.error(msg) @@ -308,7 +309,7 @@ module PluginManager when :incompatibilities # Plugin incompatibilities incompats = value incompats = [incompats] if !incompats.is_a?(Array) - for incompat in incompats + incompats.each do |incompat| if self.installed?(incompat) self.error("Plugin '#{name}' is incompatible with '#{incompat}'. " + "They cannot both be used at the same time.") @@ -317,7 +318,7 @@ module PluginManager when :credits # Plugin credits value = [value] if value.is_a?(String) if value.is_a?(Array) - for entry in value + value.each do |entry| if !entry.is_a?(String) self.error("Plugin '#{name}'s credits array contains a non-string value.") else @@ -331,7 +332,7 @@ module PluginManager self.error("Invalid plugin registry key '#{key}'.") end end - for plugin in @@Plugins.values + @@Plugins.values.each do |plugin| if plugin[:incompatibilities] && plugin[:incompatibilities].include?(name) self.error("Plugin '#{plugin[:name]}' is incompatible with '#{name}'. " + "They cannot both be used at the same time.") @@ -422,7 +423,7 @@ module PluginManager while d2[-1] == "." # Turn "123." into "123" d2 = d2[0..-2] end - for i in 0...[d1.size, d2.size].max # Compare each digit in turn + [d1.size, d2.size].max.times do |i| # Compare each digit in turn c1 = d1[i] c2 = d2[i] if c1 @@ -445,7 +446,7 @@ module PluginManager message += "Error in Plugin [#{name}]:\r\n" message += "#{$!.class} occurred.\r\n" # go through message content - for line in $!.message.split("\r\n") + $!.message.split("\r\n").each do |line| next if nil_or_empty?(line) n = line[/\d+/] err = line.split(":")[-1].strip @@ -538,7 +539,7 @@ module PluginManager # be loaded (files listed in the meta file are loaded first) meta[:scripts] = [] if !meta[:scripts] # get all script files from plugin Dir - for fl in Dir.all(dir) + Dir.all(dir).each do |fl| next if !fl.include?(".rb") meta[:scripts].push(fl.gsub("#{dir}/", "")) end @@ -566,7 +567,7 @@ module PluginManager return nil if !meta[name] || !meta[name][:dependencies] og = [name] if !og # go through all dependencies - for dname in meta[name][:dependencies] + meta[name][:dependencies].each do |dname| # clean the name to a simple string dname = dname[0] if dname.is_a?(Array) && dname.length == 2 dname = dname[1] if dname.is_a?(Array) && dname.length == 3 @@ -583,10 +584,10 @@ module PluginManager #----------------------------------------------------------------------------- def self.sortLoadOrder(order, plugins) # go through the load order - for o in order + order.each do |o| next if !plugins[o] || !plugins[o][:dependencies] # go through all dependencies - for dname in plugins[o][:dependencies] + plugins[o][:dependencies].each do |dname| optional = false # clean the name to a simple string if dname.is_a?(Array) @@ -615,7 +616,7 @@ module PluginManager order = [] # Find all plugin folders that have a meta.txt and add them to the list of # plugins. - for dir in self.listAll + self.listAll.each do |dir| # skip if there is no meta file next if !safeExists?(dir + "/meta.txt") ndx = order.length @@ -646,11 +647,11 @@ module PluginManager return true if Input.press?(Input::CTRL) # analyze whether or not to push recompile mtime = File.mtime("Data/PluginScripts.rxdata") - for o in order + order.each do |o| # go through all the registered plugin scripts scr = plugins[o][:scripts] dir = plugins[o][:dir] - for sc in scr + scr.each do |sc| return true if File.mtime("#{dir}/#{sc}") > mtime end return true if File.mtime("#{dir}/meta.txt") > mtime @@ -664,14 +665,14 @@ module PluginManager Console.echo_li "Compiling plugin scripts..." scripts = [] # go through the entire order one by one - for o in order + order.each do |o| # save name, metadata and scripts array meta = plugins[o].clone meta.delete(:scripts) meta.delete(:dir) dat = [o, meta, []] # iterate through each file to deflate - for file in plugins[o][:scripts] + plugins[o][:scripts].each do |file| File.open("#{plugins[o][:dir]}/#{file}", 'rb') do |f| dat[2].push([file, Zlib::Deflate.deflate(f.read)]) end @@ -697,7 +698,7 @@ module PluginManager # load plugins scripts = load_data("Data/PluginScripts.rxdata") echoed_plugins = [] - for plugin in scripts + scripts.each do |plugin| # get the required data name, meta, script = plugin if !meta[:essentials] || !meta[:essentials].include?(Essentials::VERSION) @@ -706,7 +707,7 @@ module PluginManager # register plugin self.register(meta) # go through each script and interpret - for scr in script + script.each do |scr| # turn code into plaintext code = Zlib::Inflate.inflate(scr[1]).force_encoding(Encoding::UTF_8) # get rid of tabs diff --git a/Data/Scripts/001_Technical/006_RPG_Sprite.rb b/Data/Scripts/001_Technical/006_RPG_Sprite.rb index 2e69bbd6f..bdccfd38d 100644 --- a/Data/Scripts/001_Technical/006_RPG_Sprite.rb +++ b/Data/Scripts/001_Technical/006_RPG_Sprite.rb @@ -100,7 +100,7 @@ class SpriteAnimation sprite.bitmap.dispose end end - for sprite in @_animation_sprites + @_animation_sprites.each do |sprite| sprite.dispose end @_animation_sprites = nil @@ -116,7 +116,7 @@ class SpriteAnimation sprite.bitmap.dispose end end - for sprite in @_loop_animation_sprites + @_loop_animation_sprites.each do |sprite| sprite.dispose end @_loop_animation_sprites = nil @@ -160,7 +160,7 @@ class SpriteAnimation position = @_animation.position animation_set_sprites(@_animation_sprites, cell_data, position, quick_update) return if quick_update - for timing in @_animation.timings + @_animation.timings.each do |timing| next if timing.frame != frame_index animation_process_timing(timing, @_animation_hit) end @@ -172,7 +172,7 @@ class SpriteAnimation position = @_loop_animation.position animation_set_sprites(@_loop_animation_sprites, cell_data, position, quick_update) return if quick_update - for timing in @_loop_animation.timings + @_loop_animation.timings.each do |timing| next if timing.frame != frame_index animation_process_timing(timing, true) end @@ -192,7 +192,7 @@ class SpriteAnimation sprite_y += self.src_rect.height / 2 if position == 1 sprite_y += self.src_rect.height if position == 2 end - for i in 0..15 + 16.times do |i| sprite = sprites[i] pattern = cell_data[i, 0] if sprite == nil || pattern == nil || pattern == -1 @@ -247,12 +247,12 @@ class SpriteAnimation sx = x - self.x return if sx == 0 if @_animation_sprites != nil - for i in 0..15 + 16.times do |i| @_animation_sprites[i].x += sx end end if @_loop_animation_sprites != nil - for i in 0..15 + 16.times do |i| @_loop_animation_sprites[i].x += sx end end @@ -262,12 +262,12 @@ class SpriteAnimation sy = y - self.y return if sy == 0 if @_animation_sprites != nil - for i in 0..15 + 16.times do |i| @_animation_sprites[i].y += sy end end if @_loop_animation_sprites != nil - for i in 0..15 + 16.times do |i| @_loop_animation_sprites[i].y += sy end end @@ -376,7 +376,7 @@ module RPG end def pushAnimation(array, anim) - for i in 0...array.length + array.length.times do |i| next if array[i] && array[i].active? array[i] = anim return @@ -405,14 +405,14 @@ module RPG end def dispose_animation - for a in @animations + @animations.each do |a| a.dispose_animation if a end @animations.clear end def dispose_loop_animation - for a in @loopAnimations + @loopAnimations.each do |a| a.dispose_loop_animation if a end @loopAnimations.clear @@ -440,7 +440,7 @@ module RPG return true if @_escape_duration > 0 return true if @_collapse_duration > 0 return true if @_damage_duration > 0 - for a in @animations + @animations.each do |a| return true if a.effect? end return false @@ -481,10 +481,10 @@ module RPG dispose_damage end end - for a in @animations + @animations.each do |a| a.update end - for a in @loopAnimations + @loopAnimations.each do |a| a.update end if @_blink @@ -500,32 +500,32 @@ module RPG end def update_animation - for a in @animations + @animations.each do |a| a.update_animation if a && a.active? end end def update_loop_animation - for a in @loopAnimations + @loopAnimations.each do |a| a.update_loop_animation if a && a.active? end end def x=(x) - for a in @animations + @animations.each do |a| a.x = x if a end - for a in @loopAnimations + @loopAnimations.each do |a| a.x = x if a end super end def y=(y) - for a in @animations + @animations.each do |a| a.y = y if a end - for a in @loopAnimations + @loopAnimations.each do |a| a.y = y if a end super diff --git a/Data/Scripts/002_Save data/005_Game_SaveConversions.rb b/Data/Scripts/002_Save data/005_Game_SaveConversions.rb index 9024ccb20..64152f83f 100644 --- a/Data/Scripts/002_Save data/005_Game_SaveConversions.rb +++ b/Data/Scripts/002_Save data/005_Game_SaveConversions.rb @@ -334,20 +334,20 @@ SaveData.register_conversion(:v20_convert_pokemon_markings_variables) do display_title 'Updating format of Pokémon markings (3/4)' to_all do |save_data| variables = save_data[:variables] - for i in 0..5000 + (0..5000).each do |i| value = variables[i] next if value.nil? if value.is_a?(Array) value.each do |value2| if value2.is_a?(Pokemon) && value2.markings.is_a?(Integer) markings = [] - 6.times { |i| markings[i] = ((value2.markings & (1 << i)) == 0) ? 0 : 1 } + 6.times { |j| markings[j] = ((value2.markings & (1 << j)) == 0) ? 0 : 1 } value2.markings = markings end end elsif value.is_a?(Pokemon) && value.markings.is_a?(Integer) markings = [] - 6.times { |i| markings[i] = ((value.markings & (1 << i)) == 0) ? 0 : 1 } + 6.times { |j| markings[j] = ((value.markings & (1 << j)) == 0) ? 0 : 1 } value.markings = markings end end @@ -359,12 +359,12 @@ SaveData.register_conversion(:v20_convert_pokemon_markings_storage) do display_title 'Updating format of Pokémon markings (4/4)' to_value :storage_system do |storage| storage.instance_eval do - for box in 0...self.maxBoxes - for i in 0...self.maxPokemon(box) + self.maxBoxes.times do |box| + self.maxPokemon(box).times do |i| pkmn = self[box, i] next if !pkmn || !pkmn.markings.is_a?(Integer) markings = [] - 6.times { |i| markings[i] = ((pkmn.markings & (1 << i)) == 0) ? 0 : 1 } + 6.times { |j| markings[j] = ((pkmn.markings & (1 << j)) == 0) ? 0 : 1 } pkmn.markings = markings end end diff --git a/Data/Scripts/003_Game processing/002_Scene_Map.rb b/Data/Scripts/003_Game processing/002_Scene_Map.rb index 5149ab0c7..9a0103191 100644 --- a/Data/Scripts/003_Game processing/002_Scene_Map.rb +++ b/Data/Scripts/003_Game processing/002_Scene_Map.rb @@ -9,7 +9,7 @@ class Scene_Map def spriteset(map_id = -1) return @spritesets[map_id] if map_id > 0 && @spritesets[map_id] - for i in @spritesets.values + @spritesets.values.each do |i| return i if i.map == $game_map end return @spritesets.values[0] @@ -19,7 +19,7 @@ class Scene_Map @map_renderer = TilemapRenderer.new(Spriteset_Map.viewport) @spritesetGlobal = Spriteset_Global.new @spritesets = {} - for map in $map_factory.maps + $map_factory.maps.each do |map| @spritesets[map.map_id] = Spriteset_Map.new(map) end $map_factory.setSceneStarted(self) @@ -36,7 +36,7 @@ class Scene_Map def disposeSpritesets return if !@spritesets - for i in @spritesets.keys + @spritesets.keys.each do |i| next if !@spritesets[i] @spritesets[i].dispose @spritesets[i] = nil @@ -132,7 +132,7 @@ class Scene_Map end def updateMaps - for map in $map_factory.maps + $map_factory.maps.each do |map| map.update end $map_factory.updateMaps(self) @@ -140,11 +140,11 @@ class Scene_Map def updateSpritesets @spritesets = {} if !@spritesets - for map in $map_factory.maps + $map_factory.maps.each do |map| @spritesets[map.map_id] = Spriteset_Map.new(map) if !@spritesets[map.map_id] end keys = @spritesets.keys.clone - for i in keys + keys.each do |i| if !$map_factory.hasMap?(i) @spritesets[i].dispose if @spritesets[i] @spritesets[i] = nil diff --git a/Data/Scripts/003_Game processing/003_Interpreter.rb b/Data/Scripts/003_Game processing/003_Interpreter.rb index 70786dadf..8b5aeb87d 100644 --- a/Data/Scripts/003_Game processing/003_Interpreter.rb +++ b/Data/Scripts/003_Game processing/003_Interpreter.rb @@ -60,7 +60,7 @@ class Interpreter return end # Check all map events for one that wants to start, and set it up - for event in $game_map.events.values + $game_map.events.values.each do |event| next if !event.starting if event.trigger < 3 # Isn't autorun or parallel processing event.lock @@ -70,7 +70,7 @@ class Interpreter return end # Check all common events for one that is autorun, and set it up - for common_event in $data_common_events.compact + $data_common_events.compact.each do |common_event| next if common_event.trigger != 1 || !$game_switches[common_event.switch_id] setup(common_event.list, 0) return @@ -107,7 +107,7 @@ class Interpreter # Do nothing if any event or the player is in the middle of a move route if @move_route_waiting return if $game_player.move_route_forcing - for event in $game_map.events.values + $game_map.events.values.each do |event| return if event.move_route_forcing end $game_temp.followers.each_follower do |event, follower| @@ -386,7 +386,7 @@ class Interpreter time = time.to_i pbSetSelfSwitch(@event_id, "A", true) $PokemonGlobal.eventvars[[@map_id, @event_id]] = time - for otherevt in arg + arg.each do |otherevt| pbSetSelfSwitch(otherevt, "A", true) $PokemonGlobal.eventvars[[@map_id, otherevt]] = time end diff --git a/Data/Scripts/003_Game processing/004_Interpreter_Commands.rb b/Data/Scripts/003_Game processing/004_Interpreter_Commands.rb index d7fdbb7fa..adb95b076 100644 --- a/Data/Scripts/003_Game processing/004_Interpreter_Commands.rb +++ b/Data/Scripts/003_Game processing/004_Interpreter_Commands.rb @@ -190,7 +190,7 @@ class Interpreter @message_waiting = true # Lets parallel process events work while a message is displayed if commands cmd_texts = [] - for cmd in commands[0] + commands[0].each do |cmd| cmd_texts.push(_MAPINTL($game_map.map_id, cmd)) end command = pbMessage(message + message_end, cmd_texts, commands[1]) @@ -272,7 +272,7 @@ class Interpreter Input.update pbUpdateSceneMap # Check for input and break if there is one - for i in 1..18 + (1..18).each do |i| ret = i if Input.trigger?(i) end break if ret != 0 @@ -460,7 +460,7 @@ class Interpreter #----------------------------------------------------------------------------- def command_121 should_refresh = false - for i in @parameters[0]..@parameters[1] + (@parameters[0]..@parameters[1]).each do |i| next if $game_switches[i] == (@parameters[2] == 0) $game_switches[i] = (@parameters[2] == 0) should_refresh = true @@ -506,7 +506,7 @@ class Interpreter end end # Apply value and operation to all specified game variables - for i in @parameters[0]..@parameters[1] + (@parameters[0]..@parameters[1]).each do |i| case @parameters[2] when 0 # set next if $game_variables[i] == value @@ -573,7 +573,7 @@ class Interpreter # * Change Windowskin #----------------------------------------------------------------------------- def command_131 - for i in 0...Settings::SPEECH_WINDOWSKINS.length + Settings::SPEECH_WINDOWSKINS.length.times do |i| next if Settings::SPEECH_WINDOWSKINS[i] != @parameters[0] $PokemonSystem.textskin = i MessageConfig.pbSetSpeechFrame("Graphics/Windowskins/" + Settings::SPEECH_WINDOWSKINS[i]) diff --git a/Data/Scripts/003_Game processing/005_Event_Handlers.rb b/Data/Scripts/003_Game processing/005_Event_Handlers.rb index 80c537e81..d2efe92d3 100644 --- a/Data/Scripts/003_Game processing/005_Event_Handlers.rb +++ b/Data/Scripts/003_Game processing/005_Event_Handlers.rb @@ -39,7 +39,7 @@ class Event # proc { |sender,arg0,arg1,...| } def trigger(*arg) arglist = arg[1, arg.length] - for callback in @callbacks + @callbacks.each do |callback| if callback.arity > 2 && arg.length == callback.arity # Retrofitted for callbacks that take three or more arguments callback.call(*arg) @@ -53,7 +53,7 @@ class Event # by the code where the event occurred. The first argument is the sender of # the event, the other arguments are the event's parameters. def trigger2(*arg) - for callback in @callbacks + @callbacks.each do |callback| callback.call(*arg) end end @@ -83,7 +83,7 @@ class HandlerHash return ret if ret mod = Object.const_get(@mod) rescue nil return nil if !mod - for key in mod.constants + mod.constants.each do |key| next if mod.const_get(key) != sym ret = key.to_sym @symbolCache[sym] = ret @@ -112,7 +112,7 @@ class HandlerHash def copy(src, *dests) handler = self[src] if handler - for dest in dests + dests.each do |dest| self.add(dest, handler) end end @@ -125,7 +125,7 @@ class HandlerHash symbol = toSymbol(sym) ret = @hash[symbol] if symbol && @hash[symbol] # Symbol or string unless ret - for addif in @addIfs + @addIfs.each do |addif| return addif[1] if addif[0].call(id) end end @@ -155,7 +155,7 @@ class HandlerHash2 def [](sym) sym = sym.id if !sym.is_a?(Symbol) && sym.respond_to?("id") return @hash[sym] if sym && @hash[sym] - for add_if in @add_ifs + @add_ifs.each do |add_if| return add_if[1] if add_if[0].call(sym) end return nil @@ -178,7 +178,7 @@ class HandlerHash2 def copy(src, *dests) handler = self[src] return if !handler - for dest in dests + dests.each do |dest| self.add(dest, handler) end end @@ -209,7 +209,7 @@ class HandlerHashBasic ret = nil ret = @hash[entry] if entry && @hash[entry] unless ret - for addif in @addIfs + @addIfs.each do |addif| return addif[1] if addif[0].call(entry) end end diff --git a/Data/Scripts/003_Game processing/006_Event_OverworldEvents.rb b/Data/Scripts/003_Game processing/006_Event_OverworldEvents.rb index af8433ddb..6d91bc9de 100644 --- a/Data/Scripts/003_Game processing/006_Event_OverworldEvents.rb +++ b/Data/Scripts/003_Game processing/006_Event_OverworldEvents.rb @@ -158,14 +158,14 @@ module EncounterModifier end def self.trigger(encounter) - for prc in @@procs + @@procs.each do |prc| encounter = prc.call(encounter) end return encounter end def self.triggerEncounterEnd - for prc in @@procsEnd + @@procsEnd.each do |prc| prc.call end end diff --git a/Data/Scripts/004_Game classes/001_Game_Screen.rb b/Data/Scripts/004_Game classes/001_Game_Screen.rb index b3e1b50be..72cb6b0ab 100644 --- a/Data/Scripts/004_Game classes/001_Game_Screen.rb +++ b/Data/Scripts/004_Game classes/001_Game_Screen.rb @@ -36,7 +36,7 @@ class Game_Screen @shake_direction = 1 @shake = 0 @pictures = [nil] - for i in 1..100 + (1..100).each do |i| @pictures.push(Game_Picture.new(i)) end @weather_type = 0 @@ -125,11 +125,11 @@ class Game_Screen @shake_duration -= 1 if @shake_duration >= 1 end if $game_temp.in_battle - for i in 51..100 + (51..100).each do |i| @pictures[i].update end else - for i in 1..50 + (1..50).each do |i| @pictures[i].update end end @@ -141,7 +141,7 @@ end #=============================================================================== def pbToneChangeAll(tone, duration) $game_screen.start_tone_change(tone, duration * Graphics.frame_rate / 20) - for picture in $game_screen.pictures + $game_screen.pictures.each do |picture| picture.start_tone_change(tone, duration * Graphics.frame_rate / 20) if picture end end diff --git a/Data/Scripts/004_Game classes/004_Game_Map.rb b/Data/Scripts/004_Game classes/004_Game_Map.rb index e8d40acfd..bcffef5f0 100644 --- a/Data/Scripts/004_Game classes/004_Game_Map.rb +++ b/Data/Scripts/004_Game classes/004_Game_Map.rb @@ -59,11 +59,11 @@ class Game_Map @need_refresh = false Events.onMapCreate.trigger(self, map_id, @map, tileset) @events = {} - for i in @map.events.keys + @map.events.keys.each do |i| @events[i] = Game_Event.new(@map_id, @map.events[i], self) end @common_events = {} - for i in 1...$data_common_events.size + (1...$data_common_events.size).each do |i| @common_events[i] = Game_CommonEvent.new(i) end @scroll_direction = 2 @@ -148,7 +148,7 @@ class Game_Map def passable?(x, y, d, self_event = nil) return false if !valid?(x, y) bit = (1 << ((d / 2) - 1)) & 0x0f - for event in events.values + events.values.each do |event| next if event.tile_id <= 0 next if event == self_event next if !event.at_coordinate?(x, y) @@ -186,12 +186,12 @@ class Game_Map newy -= 1 end return false if !valid?(newx, newy) - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = data[x, y, i] terrain = GameData::TerrainTag.try_get(@terrain_tags[tile_id]) # If already on water, only allow movement to another water tile if self_event != nil && terrain.can_surf_freely - for j in [2, 1, 0] + [2, 1, 0].each do |j| facing_tile_id = data[newx, newy, j] return false if facing_tile_id == nil facing_terrain = GameData::TerrainTag.try_get(@terrain_tags[facing_tile_id]) @@ -205,7 +205,7 @@ class Game_Map return false elsif self_event != nil && self_event.x == x && self_event.y == y # Can't walk onto ledges - for j in [2, 1, 0] + [2, 1, 0].each do |j| facing_tile_id = data[newx, newy, j] return false if facing_tile_id == nil facing_terrain = GameData::TerrainTag.try_get(@terrain_tags[facing_tile_id]) @@ -225,7 +225,7 @@ class Game_Map def playerPassable?(x, y, d, self_event = nil) bit = (1 << ((d / 2) - 1)) & 0x0f - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = data[x, y, i] terrain = GameData::TerrainTag.try_get(@terrain_tags[tile_id]) passage = @passages[tile_id] @@ -254,14 +254,14 @@ class Game_Map # event there, and the tile is fully passable in all directions) def passableStrict?(x, y, d, self_event = nil) return false if !valid?(x, y) - for event in events.values + events.values.each do |event| next if event == self_event || event.tile_id < 0 || event.through next if !event.at_coordinate?(x, y) next if GameData::TerrainTag.try_get(@terrain_tags[event.tile_id]).ignore_passability return false if @passages[event.tile_id] & 0x0f != 0 return true if @priorities[event.tile_id] == 0 end - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = data[x, y, i] next if GameData::TerrainTag.try_get(@terrain_tags[tile_id]).ignore_passability return false if @passages[tile_id] & 0x0f != 0 @@ -271,7 +271,7 @@ class Game_Map end def bush?(x, y) - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = data[x, y, i] return false if GameData::TerrainTag.try_get(@terrain_tags[tile_id]).bridge && $PokemonGlobal.bridge > 0 @@ -281,7 +281,7 @@ class Game_Map end def deepBush?(x, y) - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = data[x, y, i] terrain = GameData::TerrainTag.try_get(@terrain_tags[tile_id]) return false if terrain.bridge && $PokemonGlobal.bridge > 0 @@ -291,7 +291,7 @@ class Game_Map end def counter?(x, y) - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = data[x, y, i] passage = @passages[tile_id] return true if passage & 0x80 == 0x80 @@ -301,7 +301,7 @@ class Game_Map def terrain_tag(x, y, countBridge = false) if valid?(x, y) - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = data[x, y, i] terrain = GameData::TerrainTag.try_get(@terrain_tags[tile_id]) next if terrain.id == :None || terrain.ignore_passability @@ -314,7 +314,7 @@ class Game_Map # Unused. def check_event(x, y) - for event in self.events.values + self.events.values.each do |event| return event.id if event.at_coordinate?(x, y) end end @@ -394,10 +394,10 @@ class Game_Map end def refresh - for event in @events.values + @events.values.each do |event| event.refresh end - for common_event in @common_events.values + @common_events.values.each do |common_event| common_event.refresh end @need_refresh = false @@ -406,7 +406,7 @@ class Game_Map def update # refresh maps if necessary if $map_factory - for i in $map_factory.maps + $map_factory.maps.each do |i| i.refresh if i.need_refresh end $map_factory.setCurrentMap @@ -424,11 +424,11 @@ class Game_Map @scroll_rest -= distance end # Only update events that are on-screen - for event in @events.values + @events.values.each do |event| event.update end # Update common events - for common_event in @common_events.values + @common_events.values.each do |common_event| common_event.update end # Update fog diff --git a/Data/Scripts/004_Game classes/006_Game_MapFactory.rb b/Data/Scripts/004_Game classes/006_Game_MapFactory.rb index 81f5268eb..273916d79 100644 --- a/Data/Scripts/004_Game classes/006_Game_MapFactory.rb +++ b/Data/Scripts/004_Game classes/006_Game_MapFactory.rb @@ -38,21 +38,21 @@ class PokemonMapFactory end def hasMap?(id) - for map in @maps + @maps.each do |map| return true if map.map_id == id end return false end def getMapIndex(id) - for i in 0...@maps.length + @maps.length.times do |i| return i if @maps[i].map_id == id end return -1 end def getMap(id, add = true) - for map in @maps + @maps.each do |map| return map if map.map_id == id end map = Game_Map.new @@ -69,7 +69,7 @@ class PokemonMapFactory id = $game_map.map_id conns = MapFactoryHelper.getMapConnections if conns[id] - for conn in conns[id] + conns[id].each do |conn| mapidB = nil newx = 0 newy = 0 @@ -119,7 +119,7 @@ class PokemonMapFactory id = $game_map.map_id conns = MapFactoryHelper.getMapConnections if conns[id] - for conn in conns[id] + conns[id].each do |conn| if conn[0] == id mapA = getMap(conn[0]) newdispx = ((conn[4] - conn[1]) * Game_Map::REAL_RES_X) + mapA.display_x @@ -180,7 +180,7 @@ class PokemonMapFactory return false unless map.passable?(x, y, 0, thisEvent) end # Check passability of event(s) in that spot - for event in map.events.values + map.events.values.each do |event| next if event == thisEvent || !event.at_coordinate?(x, y) return false if !event.through && event.character_name != "" end @@ -207,7 +207,7 @@ class PokemonMapFactory elsif !map.passableStrict?(x, y, 0, thisEvent) return false end - for event in map.events.values + map.events.values.each do |event| next if event == thisEvent || !event.at_coordinate?(x, y) return false if !event.through && event.character_name != "" end @@ -236,7 +236,7 @@ class PokemonMapFactory return true if mapID1 == mapID2 conns = MapFactoryHelper.getMapConnections if conns[mapID1] - for conn in conns[mapID1] + conns[mapID1].each do |conn| return true if conn[0] == mapID2 || conn[3] == mapID2 end end @@ -250,7 +250,7 @@ class PokemonMapFactory end conns = MapFactoryHelper.getMapConnections if conns[thisMapID] - for conn in conns[thisMapID] + conns[thisMapID].each do |conn| if conn[0] == otherMapID posX = conn[4] - conn[1] + otherX - thisX posY = conn[5] - conn[2] + otherY - thisY @@ -332,7 +332,7 @@ class PokemonMapFactory return [id, x, y] if getMapNoAdd(id).valid?(x, y) conns = MapFactoryHelper.getMapConnections if conns[id] - for conn in conns[id] + conns[id].each do |conn| if conn[0] == id newX = x + conn[4] - conn[1] newY = y + conn[5] - conn[2] @@ -510,7 +510,7 @@ end # Unused def updateTilesets maps = $map_factory.maps - for map in maps + maps.each do |map| map.updateTileset if map end end diff --git a/Data/Scripts/004_Game classes/007_Game_Character.rb b/Data/Scripts/004_Game classes/007_Game_Character.rb index 9442da80c..7d07e32da 100644 --- a/Data/Scripts/004_Game classes/007_Game_Character.rb +++ b/Data/Scripts/004_Game classes/007_Game_Character.rb @@ -88,8 +88,8 @@ class Game_Character end def each_occupied_tile - for i in @x...(@x + @width) - for j in (@y - @height + 1)..@y + (@x...(@x + @width)).each do |i| + ((@y - @height + 1)..@y).each do |j| yield i, j end end @@ -240,7 +240,7 @@ class Game_Character return false unless self.map.passable?(x, y, d, self) return false unless self.map.passable?(new_x, new_y, 10 - d, self) end - for event in self.map.events.values + self.map.events.values.each do |event| next if self == event || !event.at_coordinate?(new_x, new_y) || event.through return false if self != $game_player || event.character_name != "" end @@ -254,24 +254,24 @@ class Game_Character case dir when 2, 8 # Down, up y_diff = (dir == 8) ? @height - 1 : 0 - for i in start_x...(start_x + @width) + (start_x...(start_x + @width)).each do |i| return false if !passable?(i, start_y - y_diff, dir, strict) end return true when 4, 6 # Left, right x_diff = (dir == 6) ? @width - 1 : 0 - for i in (start_y - @height + 1)..start_y + ((start_y - @height + 1)..start_y).each do |i| return false if !passable?(start_x + x_diff, i, dir, strict) end return true when 1, 3 # Down diagonals # Treated as moving down first and then horizontally, because that # describes which tiles the character's feet touch - for i in start_x...(start_x + @width) + (start_x...(start_x + @width)).each do |i| return false if !passable?(i, start_y, 2, strict) end x_diff = (dir == 3) ? @width - 1 : 0 - for i in (start_y - @height + 1)..start_y + ((start_y - @height + 1)..start_y).each do |i| return false if !passable?(start_x + x_diff, i + 1, dir + 3, strict) end return true @@ -279,11 +279,11 @@ class Game_Character # Treated as moving horizontally first and then up, because that describes # which tiles the character's feet touch x_diff = (dir == 9) ? @width - 1 : 0 - for i in (start_y - @height + 1)..start_y + ((start_y - @height + 1)..start_y).each do |i| return false if !passable?(start_x + x_diff, i, dir - 3, strict) end x_offset = (dir == 9) ? 1 : -1 - for i in start_x...(start_x + @width) + (start_x...(start_x + @width)).each do |i| return false if !passable?(i + x_offset, start_y - @height + 1, 8, strict) end return true diff --git a/Data/Scripts/004_Game classes/008_Game_Event.rb b/Data/Scripts/004_Game classes/008_Game_Event.rb index 318bbfad8..b6a549c79 100644 --- a/Data/Scripts/004_Game classes/008_Game_Event.rb +++ b/Data/Scripts/004_Game classes/008_Game_Event.rb @@ -181,7 +181,7 @@ class Game_Event < Game_Character def refresh new_page = nil unless @erased - for page in @event.pages.reverse + @event.pages.reverse.each do |page| c = page.condition next if c.switch1_valid && !switchIsOn?(c.switch1_id) next if c.switch2_valid && !switchIsOn?(c.switch2_id) diff --git a/Data/Scripts/004_Game classes/009_Game_Player.rb b/Data/Scripts/004_Game classes/009_Game_Player.rb index c372dd36f..9224412a7 100644 --- a/Data/Scripts/004_Game classes/009_Game_Player.rb +++ b/Data/Scripts/004_Game classes/009_Game_Player.rb @@ -184,7 +184,7 @@ class Game_Player < Game_Character # If event is running return result if checkIfRunning && $game_system.map_interpreter.running? # All event loops - for event in $game_map.events.values + $game_map.events.values.each do |event| next if !event.name[/trainer\((\d+)\)/i] distance = $~[1].to_i # If event coordinates and triggers are consistent @@ -201,7 +201,7 @@ class Game_Player < Game_Character # If event is running return result if checkIfRunning && $game_system.map_interpreter.running? # All event loops - for event in $game_map.events.values + $game_map.events.values.each do |event| next if !event.name[/counter\((\d+)\)/i] distance = $~[1].to_i # If event coordinates and triggers are consistent @@ -219,7 +219,7 @@ class Game_Player < Game_Character ret = pbTriggeredTrainerEvents(triggers) ret.concat(pbTriggeredCounterEvents(triggers)) return false if ret.length == 0 - for event in ret + ret.each do |event| event.start end return true @@ -236,7 +236,7 @@ class Game_Player < Game_Character new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0) new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) return nil if !$game_map.valid?(new_x, new_y) - for event in $game_map.events.values + $game_map.events.values.each do |event| next if !event.at_coordinate?(new_x, new_y) next if event.jumping? || event.over_trigger? return event @@ -245,7 +245,7 @@ class Game_Player < Game_Character if $game_map.counter?(new_x, new_y) new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0) new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) - for event in $game_map.events.values + $game_map.events.values.each do |event| next if !event.at_coordinate?(new_x, new_y) next if event.jumping? || event.over_trigger? return event @@ -330,7 +330,7 @@ class Game_Player < Game_Character # If event is running return result if $game_system.map_interpreter.running? # All event loops - for event in $game_map.events.values + $game_map.events.values.each do |event| # If event coordinates and triggers are consistent next if !event.at_coordinate?(@x, @y) next if !triggers.include?(event.trigger) @@ -354,7 +354,7 @@ class Game_Player < Game_Character new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) return false if !$game_map.valid?(new_x, new_y) # All event loops - for event in $game_map.events.values + $game_map.events.values.each do |event| # If event coordinates and triggers are consistent next if !event.at_coordinate?(new_x, new_y) next if !triggers.include?(event.trigger) @@ -372,7 +372,7 @@ class Game_Player < Game_Character new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0) return false if !$game_map.valid?(new_x, new_y) # All event loops - for event in $game_map.events.values + $game_map.events.values.each do |event| # If event coordinates and triggers are consistent next if !event.at_coordinate?(new_x, new_y) next if !triggers.include?(event.trigger) @@ -395,7 +395,7 @@ class Game_Player < Game_Character # All event loops x_offset = (dir == 4) ? -1 : (dir == 6) ? 1 : 0 y_offset = (dir == 8) ? -1 : (dir == 2) ? 1 : 0 - for event in $game_map.events.values + $game_map.events.values.each do |event| next if ![1, 2].include?(event.trigger) # Player touch, event touch # If event coordinates and triggers are consistent next if !event.at_coordinate?(@x + x_offset, @y + y_offset) diff --git a/Data/Scripts/004_Game classes/011_Game_Follower.rb b/Data/Scripts/004_Game classes/011_Game_Follower.rb index 4c1211417..e2f779270 100644 --- a/Data/Scripts/004_Game classes/011_Game_Follower.rb +++ b/Data/Scripts/004_Game classes/011_Game_Follower.rb @@ -166,7 +166,7 @@ class Game_Follower < Game_Event passed_tile_checks = false bit = (1 << ((direction / 2) - 1)) & 0x0f # Check all events for ones using tiles as graphics, and see if they're passable - for event in this_map.events.values + this_map.events.values.each do |event| next if event.tile_id < 0 || event.through || !event.at_coordinate?(x, y) tile_data = GameData::TerrainTag.try_get(this_map.terrain_tags[event.tile_id]) next if tile_data.ignore_passability @@ -180,7 +180,7 @@ class Game_Follower < Game_Event end # Check if tiles at (x, y) allow passage for followe if !passed_tile_checks - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = this_map.data[x, y, i] || 0 next if tile_id == 0 tile_data = GameData::TerrainTag.try_get(this_map.terrain_tags[tile_id]) @@ -194,7 +194,7 @@ class Game_Follower < Game_Event end end # Check all events on the map to see if any are in the way - for event in this_map.events.values + this_map.events.values.each do |event| next if !event.at_coordinate?(x, y) return false if !event.through && event.character_name != "" end diff --git a/Data/Scripts/005_Sprites/003_Sprite_Character.rb b/Data/Scripts/005_Sprites/003_Sprite_Character.rb index 5c70369a0..bc6f6b450 100644 --- a/Data/Scripts/005_Sprites/003_Sprite_Character.rb +++ b/Data/Scripts/005_Sprites/003_Sprite_Character.rb @@ -28,7 +28,7 @@ class BushBitmap ret = Bitmap.new(bitmap.width, bitmap.height) charheight = ret.height / 4 cy = charheight - depth - 2 - for i in 0...4 + 4.times do |i| y = i * charheight if cy >= 0 ret.blt(0, y, bitmap, Rect.new(0, y, ret.width, cy)) diff --git a/Data/Scripts/005_Sprites/006_Spriteset_Global.rb b/Data/Scripts/005_Sprites/006_Spriteset_Global.rb index 84148a834..4321676cf 100644 --- a/Data/Scripts/005_Sprites/006_Spriteset_Global.rb +++ b/Data/Scripts/005_Sprites/006_Spriteset_Global.rb @@ -8,7 +8,7 @@ class Spriteset_Global @follower_sprites = FollowerSprites.new(Spriteset_Map.viewport) @playersprite = Sprite_Character.new(Spriteset_Map.viewport, $game_player) @picture_sprites = [] - for i in 1..100 + (1..100).each do |i| @picture_sprites.push(Sprite_Picture.new(@@viewport2, $game_screen.pictures[i])) end @timer_sprite = Sprite_Timer.new diff --git a/Data/Scripts/005_Sprites/007_Spriteset_Map.rb b/Data/Scripts/005_Sprites/007_Spriteset_Map.rb index 303e88676..d14147ed9 100644 --- a/Data/Scripts/005_Sprites/007_Spriteset_Map.rb +++ b/Data/Scripts/005_Sprites/007_Spriteset_Map.rb @@ -54,7 +54,7 @@ class Spriteset_Map @fog = AnimatedPlane.new(@@viewport1) @fog.z = 3000 @character_sprites = [] - for i in @map.events.keys.sort + @map.events.keys.sort.each do |i| sprite = Sprite_Character.new(@@viewport1, @map.events[i]) @character_sprites.push(sprite) end @@ -119,7 +119,7 @@ class Spriteset_Map @fog.tone = @map.fog_tone @panorama.update @fog.update - for sprite in @character_sprites + @character_sprites.each do |sprite| sprite.update end if self.map != $game_map diff --git a/Data/Scripts/005_Sprites/008_Sprite_AnimationSprite.rb b/Data/Scripts/005_Sprites/008_Sprite_AnimationSprite.rb index 3493dcb8a..16f577874 100644 --- a/Data/Scripts/005_Sprites/008_Sprite_AnimationSprite.rb +++ b/Data/Scripts/005_Sprites/008_Sprite_AnimationSprite.rb @@ -56,29 +56,24 @@ class Spriteset_Map return sprite end - def addUserSprite(sprite) - for i in 0...@usersprites.length - if @usersprites[i] == nil || @usersprites[i].disposed? - @usersprites[i] = sprite - return - end + def addUserSprite(new_sprite) + @usersprites.each_with_index do |sprite, i| + next if sprite && !sprite.disposed? + @usersprites[i] = new_sprite + return end - @usersprites.push(sprite) + @usersprites.push(new_sprite) end def dispose _animationSprite_dispose - for i in 0...@usersprites.length - @usersprites[i].dispose - end + @usersprites.each { |sprite| sprite.dispose } @usersprites.clear end def update @@viewport3.tone.set(0, 0, 0, 0) _animationSprite_update - for i in 0...@usersprites.length - @usersprites[i].update if !@usersprites[i].disposed? - end + @usersprites.each { |sprite| sprite.update if !sprite.disposed? } end end diff --git a/Data/Scripts/005_Sprites/009_Sprite_DynamicShadows.rb b/Data/Scripts/005_Sprites/009_Sprite_DynamicShadows.rb index 18b50d4e7..37f6edfb6 100644 --- a/Data/Scripts/005_Sprites/009_Sprite_DynamicShadows.rb +++ b/Data/Scripts/005_Sprites/009_Sprite_DynamicShadows.rb @@ -135,14 +135,14 @@ class Sprite_Character < RPG::Sprite if character.is_a?(Game_Event) && shadows.length > 0 params = XPML_read(map, "Shadow", @character, 4) if params != nil - for i in 0...shadows.size - @ombrelist.push(Sprite_Shadow.new(viewport, @character, shadows[i])) + shadows.each do |shadow| + @ombrelist.push(Sprite_Shadow.new(viewport, @character, shadows)) end end end if character.is_a?(Game_Player) && shadows.length > 0 - for i in 0...shadows.size - @ombrelist.push(Sprite_Shadow.new(viewport, $game_player, shadows[i])) + shadows.each do |shadow| + @ombrelist.push(Sprite_Shadow.new(viewport, $game_player, shadow)) end end update @@ -157,11 +157,7 @@ class Sprite_Character < RPG::Sprite def update shadow_update - if @ombrelist.length > 0 - for i in 0...@ombrelist.size - @ombrelist[i].update - end - end + @ombrelist.each { |ombre| ombre.update } end end @@ -187,7 +183,7 @@ class Spriteset_Map @shadows = [] warn = false map = $game_map if !map - for k in map.events.keys.sort + map.events.keys.sort.each do |k| ev = map.events[k] warn = true if (ev.list != nil && ev.list.length > 0 && ev.list[0].code == 108 && @@ -199,7 +195,7 @@ class Spriteset_Map p "Warning : At least one event on this map uses the obsolete way to add shadows" end shadow_initialize(map) - for sprite in @character_sprites + @character_sprites.each do |sprite| sprite.setShadows(map, @shadows) end $scene.spritesetGlobal.playersprite.setShadows(map, @shadows) @@ -230,11 +226,11 @@ end def XPML_read(map, markup, event, max_param_number = 0) parameter_list = nil return nil if !event || event.list == nil - for i in 0...event.list.size + event.list.size.times do |i| if event.list[i].code == 108 && event.list[i].parameters[0].downcase == "begin " + markup.downcase parameter_list = [] if parameter_list == nil - for j in (i + 1)...event.list.size + ((i + 1)...event.list.size).each do |j| if event.list[j].code == 108 parts = event.list[j].parameters[0].split if parts.size != 1 && parts[0].downcase != "begin" diff --git a/Data/Scripts/005_Sprites/010_ParticleEngine.rb b/Data/Scripts/005_Sprites/010_ParticleEngine.rb index 18e9ea8a7..46598246c 100644 --- a/Data/Scripts/005_Sprites/010_ParticleEngine.rb +++ b/Data/Scripts/005_Sprites/010_ParticleEngine.rb @@ -31,7 +31,7 @@ class Particle_Engine def dispose return if disposed? - for particle in @effect + @effect.each do |particle| next if particle.nil? particle.dispose end @@ -80,13 +80,12 @@ class Particle_Engine def update if @firsttime @firsttime = false - for event in @map.events.values + @map.events.values.each do |event| remove_effect(event) add_effect(event) end end - for i in 0...@effect.length - particle = @effect[i] + @effect.each_with_index do |particle, i| next if particle.nil? if particle.event.pe_refresh event = particle.event @@ -217,7 +216,7 @@ class ParticleEffect_Event < ParticleEffect @zoffset = zOffset @bmwidth = 32 @bmheight = 32 - for i in 0...@maxparticless + @maxparticless.times do |i| @particlex[i] = -@xoffset @particley[i] = -@yoffset @particles[i] = ParticleSprite.new(@viewport) @@ -275,7 +274,7 @@ class ParticleEffect_Event < ParticleEffect end end particleZ = selfZ + @zoffset - for i in 0...@maxparticless + @maxparticless.times do |i| @particles[i].z = particleZ if @particles[i].y <= @ytop @particles[i].y = @startingy + @yoffset @@ -347,10 +346,10 @@ class ParticleEffect_Event < ParticleEffect end def dispose - for particle in @particles + @particles.each do |particle| particle.dispose end - for bitmap in @bitmaps.values + @bitmaps.values.each do |bitmap| bitmap.dispose end @particles.clear @@ -388,7 +387,7 @@ class Particle_Engine::Teleport < ParticleEffect_Event setParameters([1, 1, 1, 10, rand(360), 1, -64, Graphics.height, -64, Graphics.width, 0, 3, -8, -15, 20, 0]) initParticles("wideportal", 250) - for i in 0...@maxparticless + @maxparticless.times do |i| @particles[i].ox = 16 @particles[i].oy = 16 end @@ -447,7 +446,7 @@ class Particle_Engine::SootSmoke < ParticleEffect_Event setParameters([0, 0, 0, 30, 0, 0.5, -64, Graphics.height, -64, Graphics.width, 0.5, 0.10, -5, -15, 5, 80]) initParticles("smoke", 100, 0) - for i in 0...@maxparticless + @maxparticless.times do |i| @particles[i].blend_type = rand(6) < 3 ? 1 : 2 end end @@ -472,7 +471,7 @@ class Particle_Engine::FixedTeleport < ParticleEffect_Event setParameters([1, 0, 1, 10, rand(360), 1, -Graphics.height, Graphics.height, 0, Graphics.width, 0, 3, -8, -15, 20, 0]) initParticles("wideportal", 250) - for i in 0...@maxparticless + @maxparticless.times do |i| @particles[i].ox = 16 @particles[i].oy = 16 end @@ -488,7 +487,7 @@ class Particle_Engine::StarTeleport < ParticleEffect_Event setParameters([0, 0, 1, 10, 0, 1, -Graphics.height, Graphics.height, 0, Graphics.width, 0, 3, -8, -15, 10, 0]) initParticles("star", 250) - for i in 0...@maxparticless + @maxparticless.times do |i| @particles[i].ox = 48 @particles[i].oy = 48 end @@ -503,7 +502,7 @@ class Particle_Engine::Smokescreen < ParticleEffect_Event setParameters([0, 0, 0, 250, 0, 0.2, -64, Graphics.height, -64, Graphics.width, 0.8, 0.8, -5, -15, 5, 80]) initParticles(nil, 100) - for i in 0...@maxparticless + @maxparticless.times do |i| rnd = rand(3) @opacity[i] = (rnd == 0) ? 1 : 100 filename = (rnd == 0) ? "explosionsmoke" : "smoke" @@ -555,7 +554,7 @@ class Particle_Engine::Splash < ParticleEffect_Event def update super - for i in 0...@maxparticless + @maxparticless.times do |i| @particles[i].opacity = 50 @particles[i].update end diff --git a/Data/Scripts/005_Sprites/011_PictureEx.rb b/Data/Scripts/005_Sprites/011_PictureEx.rb index 58219e2d1..d6c908047 100644 --- a/Data/Scripts/005_Sprites/011_PictureEx.rb +++ b/Data/Scripts/005_Sprites/011_PictureEx.rb @@ -142,7 +142,7 @@ class PictureEx def totalDuration ret = 0 - for process in @processes + @processes.each do |process| dur = process[1] + process[2] ret = dur if dur > ret end @@ -186,7 +186,7 @@ class PictureEx end def adjustPosition(xOffset, yOffset) - for process in @processes + @processes.each do |process| next if process[0] != Processes::XY process[5] += xOffset process[6] += yOffset @@ -345,8 +345,7 @@ class PictureEx def update procEnded = false @frameUpdates.clear - for i in 0...@processes.length - process = @processes[i] + @processes.each_with_index do |process, i| # Decrease delay of processes that are scheduled to start later if process[1] >= 0 # Set initial values if the process will start this frame @@ -465,8 +464,8 @@ end #=============================================================================== def setPictureSprite(sprite, picture, iconSprite = false) return if picture.frameUpdates.length == 0 - for i in 0...picture.frameUpdates.length - case picture.frameUpdates[i] + picture.frameUpdates.each do |type| + case type when Processes::XY, Processes::DeltaXY sprite.x = picture.x.round sprite.y = picture.y.round diff --git a/Data/Scripts/005_Sprites/012_Interpolators.rb b/Data/Scripts/005_Sprites/012_Interpolators.rb index cf929def4..358aa0fd3 100644 --- a/Data/Scripts/005_Sprites/012_Interpolators.rb +++ b/Data/Scripts/005_Sprites/012_Interpolators.rb @@ -25,7 +25,7 @@ class Interpolator @frames = frames @step = 0 @sprite = sprite - for item in items + items.each do |item| case item[0] when ZOOM_X @tweensteps[item[0]] = [sprite.zoom_x, item[1] - sprite.zoom_x] @@ -52,7 +52,7 @@ class Interpolator def update if @tweening t = @step.to_f / @frames - for i in 0...@tweensteps.length + @tweensteps.length.times do |i| item = @tweensteps[i] next if !item case i diff --git a/Data/Scripts/006_Map renderer/001_TilemapRenderer.rb b/Data/Scripts/006_Map renderer/001_TilemapRenderer.rb index 888975206..9965c82a4 100644 --- a/Data/Scripts/006_Map renderer/001_TilemapRenderer.rb +++ b/Data/Scripts/006_Map renderer/001_TilemapRenderer.rb @@ -572,9 +572,9 @@ class TilemapRenderer end_y = [end_y, map.height - map_display_y_tile - 1].min next if start_x > end_x || start_y > end_y || end_x < 0 || end_y < 0 # Update all tile sprites representing this map - for i in start_x..end_x + (start_x..end_x).each do |i| tile_x = i + map_display_x_tile - for j in start_y..end_y + (start_y..end_y).each do |j| tile_y = j + map_display_y_tile @tiles[i][j].each_with_index do |tile, layer| tile_id = map.data[tile_x, tile_y, layer] diff --git a/Data/Scripts/006_Map renderer/004_TileDrawingHelper.rb b/Data/Scripts/006_Map renderer/004_TileDrawingHelper.rb index a2bb7e16a..ac6c0674b 100644 --- a/Data/Scripts/006_Map renderer/004_TileDrawingHelper.rb +++ b/Data/Scripts/006_Map renderer/004_TileDrawingHelper.rb @@ -60,7 +60,7 @@ class TileDrawingHelper def self.fromTileset(tileset) bmtileset = pbGetTileset(tileset.tileset_name) bmautotiles = [] - for i in 0...7 + 7.times do |i| bmautotiles.push(pbGetAutotile(tileset.autotile_names[i])) end return self.new(bmtileset, bmautotiles) @@ -81,8 +81,8 @@ class TileDrawingHelper def dispose @tileset.dispose if @tileset @tileset = nil - for i in 0...@autotiles.length - @autotiles[i].dispose + @autotiles.each_with_index do |autotile, i| + autotile.dispose @autotiles[i] = nil end end @@ -102,7 +102,7 @@ class TileDrawingHelper id %= 48 tiles = AUTOTILE_PATTERNS[id >> 3][id & 7] src = Rect.new(0, 0, 0, 0) - for i in 0...4 + 4.times do |i| tile_position = tiles[i] - 1 src.set((tile_position % 6 * 16) + anim, tile_position / 6 * 16, 16, 16) bitmap.stretch_blt(Rect.new((i % 2 * cxTile) + x, (i / 2 * cyTile) + y, cxTile, cyTile), @@ -155,9 +155,9 @@ def createMinimap(mapid) tileset = tilesets[map.tileset_id] return bitmap if !tileset helper = TileDrawingHelper.fromTileset(tileset) - for y in 0...map.height - for x in 0...map.width - for z in 0..2 + map.height.times do |y| + map.width.times do |x| + 3.times do |z| id = map.data[x, y, z] id = 0 if !id helper.bltSmallTile(bitmap, x * 4, y * 4, 4, 4, id) @@ -178,7 +178,7 @@ def bltMinimapAutotile(dstBitmap, x, y, srcBitmap, id) cyTile = 3 tiles = TileDrawingHelper::AUTOTILE_PATTERNS[id >> 3][id & 7] src = Rect.new(0, 0, 0, 0) - for i in 0...4 + 4.times do |i| tile_position = tiles[i] - 1 src.set((tile_position % 6 * cxTile) + anim, tile_position / 6 * cyTile, cxTile, cyTile) @@ -200,10 +200,10 @@ def getPassabilityMinimap(mapid) ret = Bitmap.new(map.width * 6, map.height * 6) passtable = Table.new(map.width, map.height) passages = tileset.passages - for i in 0...map.width - for j in 0...map.height + map.width.times do |i| + map.height.times do |j| pass = true - for z in [2, 1, 0] + [2, 1, 0].each do |z| if !passable?(passages, map.data[i, j, z]) pass = false break @@ -213,8 +213,8 @@ def getPassabilityMinimap(mapid) end end neighbors = TileDrawingHelper::NEIGHBORS_TO_AUTOTILE_INDEX - for i in 0...map.width - for j in 0...map.height + map.width.times do |i| + map.height.times do |j| if passtable[i, j] == 0 nb = TileDrawingHelper.tableNeighbors(passtable, i, j) tile = neighbors[nb] diff --git a/Data/Scripts/007_Objects and windows/002_MessageConfig.rb b/Data/Scripts/007_Objects and windows/002_MessageConfig.rb index 08171b21c..b76c787a7 100644 --- a/Data/Scripts/007_Objects and windows/002_MessageConfig.rb +++ b/Data/Scripts/007_Objects and windows/002_MessageConfig.rb @@ -144,13 +144,13 @@ module MessageConfig end def self.pbTryFonts(*args) - for a in args + args.each do |a| next if !a case a when String return a if Font.exist?(a) when Array - for aa in a + a.each do |aa| ret = MessageConfig.pbTryFonts(aa) return ret if ret != "" end @@ -455,14 +455,14 @@ end def pbSetSpritesToColor(sprites, color) return if !sprites || !color colors = {} - for i in sprites + sprites.each do |i| next if !i[1] || pbDisposed?(i[1]) colors[i[0]] = i[1].color.clone i[1].color = pbSrcOver(i[1].color, color) end Graphics.update Input.update - for i in colors + colors.each do |i| next if !sprites[i[0]] sprites[i[0]].color = i[1] end @@ -480,7 +480,7 @@ def using(window) end def pbUpdateSpriteHash(windows) - for i in windows + windows.each do |i| window = i[1] if window if window.is_a?(Sprite) || window.is_a?(Window) @@ -503,7 +503,7 @@ end # Disposes all objects in the specified hash. def pbDisposeSpriteHash(sprites) return if !sprites - for i in sprites.keys + sprites.keys.each do |i| pbDisposeSprite(sprites, i) end sprites.clear @@ -552,7 +552,7 @@ def pbFadeOutIn(z = 99999, nofadeout = false) viewport.z = z numFrames = (Graphics.frame_rate * 0.4).floor alphaDiff = (255.0 / numFrames).ceil - for j in 0..numFrames + (0..numFrames).each do |j| col.set(0, 0, 0, j * alphaDiff) viewport.color = col Graphics.update @@ -566,7 +566,7 @@ def pbFadeOutIn(z = 99999, nofadeout = false) ensure pbPopFade if !nofadeout - for j in 0..numFrames + (0..numFrames).each do |j| col.set(0, 0, 0, (numFrames - j) * alphaDiff) viewport.color = col Graphics.update @@ -583,7 +583,7 @@ def pbFadeOutInWithUpdate(z, sprites, nofadeout = false) viewport.z = z numFrames = (Graphics.frame_rate * 0.4).floor alphaDiff = (255.0 / numFrames).ceil - for j in 0..numFrames + (0..numFrames).each do |j| col.set(0, 0, 0, j * alphaDiff) viewport.color = col pbUpdateSpriteHash(sprites) @@ -596,7 +596,7 @@ def pbFadeOutInWithUpdate(z, sprites, nofadeout = false) ensure pbPopFade if !nofadeout - for j in 0..numFrames + (0..numFrames).each do |j| col.set(0, 0, 0, (numFrames - j) * alphaDiff) viewport.color = col pbUpdateSpriteHash(sprites) @@ -629,12 +629,12 @@ def pbFadeOutAndHide(sprites) numFrames = (Graphics.frame_rate * 0.4).floor alphaDiff = (255.0 / numFrames).ceil pbDeactivateWindows(sprites) { - for j in 0..numFrames + (0..numFrames).each do |j| pbSetSpritesToColor(sprites, Color.new(0, 0, 0, j * alphaDiff)) (block_given?) ? yield : pbUpdateSpriteHash(sprites) end } - for i in sprites + sprites.each do |i| next if !i[1] next if pbDisposed?(i[1]) visiblesprites[i[0]] = true if i[1].visible @@ -645,7 +645,7 @@ end def pbFadeInAndShow(sprites, visiblesprites = nil) if visiblesprites - for i in visiblesprites + visiblesprites.each do |i| if i[1] && sprites[i[0]] && !pbDisposed?(sprites[i[0]]) sprites[i[0]].visible = true end @@ -654,7 +654,7 @@ def pbFadeInAndShow(sprites, visiblesprites = nil) numFrames = (Graphics.frame_rate * 0.4).floor alphaDiff = (255.0 / numFrames).ceil pbDeactivateWindows(sprites) { - for j in 0..numFrames + (0..numFrames).each do |j| pbSetSpritesToColor(sprites, Color.new(0, 0, 0, ((numFrames - j) * alphaDiff))) (block_given?) ? yield : pbUpdateSpriteHash(sprites) end @@ -665,7 +665,7 @@ end # _activeStatuses_ is the result of a previous call to pbActivateWindows def pbRestoreActivations(sprites, activeStatuses) return if !sprites || !activeStatuses - for k in activeStatuses.keys + activeStatuses.keys.each do |k| if sprites[k] && sprites[k].is_a?(Window) && !pbDisposed?(sprites[k]) sprites[k].active = activeStatuses[k] ? true : false end @@ -688,7 +688,7 @@ end def pbActivateWindow(sprites, key) return if !sprites activeStatuses = {} - for i in sprites + sprites.each do |i| if i[1] && i[1].is_a?(Window) && !pbDisposed?(i[1]) activeStatuses[i[0]] = i[1].active i[1].active = (i[0] == key) @@ -723,7 +723,7 @@ def addBackgroundPlane(sprites, planename, background, viewport = nil) sprites[planename].visible = false else sprites[planename].setBitmap(bitmapName) - for spr in sprites.values + sprites.values.each do |spr| if spr.is_a?(Window) spr.windowskin = nil end @@ -745,7 +745,7 @@ def addBackgroundOrColoredPlane(sprites, planename, background, color, viewport else sprites[planename] = AnimatedPlane.new(viewport) sprites[planename].setBitmap(bitmapName) - for spr in sprites.values + sprites.values.each do |spr| if spr.is_a?(Window) spr.windowskin = nil end @@ -772,7 +772,7 @@ end if !defined?(_INTL) def _INTL(*args) string = args[0].clone - for i in 1...args.length + (1...args.length).each do |i| string.gsub!(/\{#{i}\}/, "#{args[i]}") end return string @@ -782,7 +782,7 @@ end if !defined?(_ISPRINTF) def _ISPRINTF(*args) string = args[0].clone - for i in 1...args.length + (1...args.length).each do |i| string.gsub!(/\{#{i}\:([^\}]+?)\}/) { |m| next sprintf("%" + $1, args[i]) } @@ -794,7 +794,7 @@ end if !defined?(_MAPINTL) def _MAPINTL(*args) string = args[1].clone - for i in 2...args.length + (2...args.length).each do |i| string.gsub!(/\{#{i}\}/, "#{args[i + 1]}") end return string diff --git a/Data/Scripts/007_Objects and windows/003_Window.rb b/Data/Scripts/007_Objects and windows/003_Window.rb index 4e1e24313..16e67bb9c 100644 --- a/Data/Scripts/007_Objects and windows/003_Window.rb +++ b/Data/Scripts/007_Objects and windows/003_Window.rb @@ -89,7 +89,7 @@ class Window @cursorbitmap = nil @bgbitmap = nil @viewport = viewport - for i in @spritekeys + @spritekeys.each do |i| @sprites[i] = Sprite.new(@viewport) end @disposed = false @@ -126,12 +126,12 @@ class Window def dispose if !self.disposed? - for i in @sprites + @sprites.each do |i| i[1].dispose if i[1] @sprites[i[0]] = nil end - for i in 0...@sidebitmaps.length - @sidebitmaps[i].dispose if @sidebitmaps[i] + @sidebitmaps.each_with_index do |bitmap, i| + bitmap.dispose if bitmap @sidebitmaps[i] = nil end @blankcontents.dispose @@ -164,7 +164,7 @@ class Window def viewport=(value) @viewport = value - for i in @spritekeys + @spritekeys.each do |i| @sprites[i].dispose if @sprites[i].is_a?(Sprite) @sprites[i] = Sprite.new(@viewport) @@ -286,7 +286,7 @@ class Window def flash(color, duration) return if disposed? - for i in @sprites + @sprites.each do |i| i[1].flash(color, duration) end end @@ -313,7 +313,7 @@ class Window mustchange = true end privRefresh if mustchange - for i in @sprites + @sprites.each do |i| i[1].update end end @@ -350,14 +350,14 @@ class Window backopac = self.back_opacity * self.opacity / 255 contopac = self.contents_opacity cursoropac = @cursoropacity * contopac / 255 - for i in 0...4 + 4.times do |i| @sprites["corner#{i}"].bitmap = @_windowskin @sprites["scroll#{i}"].bitmap = @_windowskin end @sprites["pause"].bitmap = @_windowskin @sprites["contents"].bitmap = @contents if @_windowskin && !@_windowskin.disposed? - for i in 0...4 + 4.times do |i| @sprites["corner#{i}"].opacity = @opacity @sprites["corner#{i}"].tone = @tone @sprites["corner#{i}"].color = @color @@ -374,7 +374,7 @@ class Window @sprites["scroll#{i}"].color = @color @sprites["scroll#{i}"].visible = @visible end - for i in ["back", "cursor", "pause", "contents"] + ["back", "cursor", "pause", "contents"].each do |i| @sprites[i].color = @color @sprites[i].tone = @tone @sprites[i].blend_type = @blend_type @@ -396,7 +396,7 @@ class Window @sprites["scroll3"].visible = @visible && hascontents && (@contents.height - @oy) > @height - 32 else - for i in 0...4 + 4.times do |i| @sprites["corner#{i}"].visible = false @sprites["side#{i}"].visible = false @sprites["scroll#{i}"].visible = false @@ -410,7 +410,7 @@ class Window @sprites["pause"].visible = false @sprites["cursor"].visible = false end - for i in @sprites + @sprites.each do |i| i[1].z = @z end if @rpgvx @@ -540,7 +540,7 @@ class Window @sprites["cursor"].visible = false @sprites["cursor"].src_rect.set(0, 0, 0, 0) end - for i in 0...4 + 4.times do |i| dwidth = [0, 3].include?(i) ? @width - 32 : 16 dheight = [0, 3].include?(i) ? 16 : @height - 32 @sidebitmaps[i] = ensureBitmap(@sidebitmaps[i], dwidth, dheight) @@ -573,7 +573,7 @@ class Window end if @openness != 255 opn = @openness / 255.0 - for k in @spritekeys + @spritekeys.each do |k| sprite = @sprites[k] ratio = (@height <= 0) ? 0 : (sprite.y - @y) / @height.to_f sprite.zoom_y = opn @@ -581,14 +581,14 @@ class Window sprite.y = (@y + (@height / 2.0) + (@height * ratio * opn) - (@height / 2 * opn)).floor end else - for k in @spritekeys + @spritekeys.each do |k| sprite = @sprites[k] sprite.zoom_y = 1.0 end end i = 0 # Ensure Z order - for k in @spritekeys + @spritekeys.each do |k| sprite = @sprites[k] y = sprite.y sprite.y = i diff --git a/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb b/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb index 715870d4d..77e9b9d34 100644 --- a/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb +++ b/Data/Scripts/007_Objects and windows/004_SpriteWindow.rb @@ -66,7 +66,7 @@ class SpriteWindow < Window @sidebitmaps = [nil, nil, nil, nil] @cursorbitmap = nil @bgbitmap = nil - for i in @spritekeys + @spritekeys.each do |i| @sprites[i] = Sprite.new(@viewport) end @disposed = false @@ -112,12 +112,12 @@ class SpriteWindow < Window def dispose if !self.disposed? - for i in @sprites + @sprites.each do |i| i[1].dispose if i[1] @sprites[i[0]] = nil end - for i in 0...@sidebitmaps.length - @sidebitmaps[i].dispose if @sidebitmaps[i] + @sidebitmaps.each_with_index do |bitmap, i| + bitmap.dispose if bitmap @sidebitmaps[i] = nil end @blankcontents.dispose @@ -142,7 +142,7 @@ class SpriteWindow < Window def viewport=(value) @viewport = value - for i in @spritekeys + @spritekeys.each do |i| @sprites[i].dispose if @sprites[i] if @sprites[i].is_a?(Sprite) @sprites[i] = Sprite.new(@viewport) @@ -288,7 +288,7 @@ class SpriteWindow < Window def flash(color, duration) return if disposed? @flash = duration + 1 - for i in @sprites + @sprites.each do |i| i[1].flash(color, duration) end end @@ -317,7 +317,7 @@ class SpriteWindow < Window end privRefresh if mustchange if @flash > 0 - for i in @sprites.values + @sprites.values.each do |i| i.update end @flash -= 1 @@ -477,14 +477,14 @@ class SpriteWindow < Window contopac = self.contents_opacity cursoropac = @cursoropacity * contopac / 255 haveskin = @_windowskin && !@_windowskin.disposed? - for i in 0...4 + 4.times do |i| @sprites["corner#{i}"].bitmap = @_windowskin @sprites["scroll#{i}"].bitmap = @_windowskin end @sprites["pause"].bitmap = @_windowskin @sprites["contents"].bitmap = @contents if haveskin - for i in 0...4 + 4.times do |i| @sprites["corner#{i}"].opacity = @opacity @sprites["corner#{i}"].tone = @tone @sprites["corner#{i}"].color = @color @@ -501,7 +501,7 @@ class SpriteWindow < Window @sprites["scroll#{i}"].visible = @visible @sprites["scroll#{i}"].blend_type = @blend_type end - for i in ["back", "cursor", "pause", "contents"] + ["back", "cursor", "pause", "contents"].each do |i| @sprites[i].color = @color @sprites[i].tone = @tone @sprites[i].blend_type = @blend_type @@ -524,7 +524,7 @@ class SpriteWindow < Window @sprites["scroll2"].visible = false @sprites["scroll3"].visible = false else - for i in 0...4 + 4.times do |i| @sprites["corner#{i}"].visible = false @sprites["side#{i}"].visible = false @sprites["scroll#{i}"].visible = false @@ -538,7 +538,7 @@ class SpriteWindow < Window @sprites["pause"].visible = false @sprites["cursor"].visible = false end - for i in @spritekeys + @spritekeys.each do |i| @sprites[i].z = @z end if (@compat & CompatBits::CorrectZ) > 0 && @skinformat == 0 && !@rpgvx @@ -725,7 +725,7 @@ class SpriteWindow < Window @sprites["cursor"].src_rect.set(0, 0, 0, 0) end end - for i in 0..3 + 4.times do |i| case i when 0 dwidth = @width - startX - endX @@ -783,7 +783,7 @@ class SpriteWindow < Window end if @openness != 255 opn = @openness / 255.0 - for k in @spritekeys + @spritekeys.each do |k| sprite = @sprites[k] ratio = (@height <= 0) ? 0 : (sprite.y - @y) / @height.to_f sprite.zoom_y = opn @@ -792,7 +792,7 @@ class SpriteWindow < Window sprite.y = (@y + (@height / 2.0) + (@height * ratio * opn) - (@height / 2 * opn)).floor end else - for k in @spritekeys + @spritekeys.each do |k| sprite = @sprites[k] sprite.zoom_x = 1.0 sprite.zoom_y = 1.0 @@ -800,7 +800,7 @@ class SpriteWindow < Window end i = 0 # Ensure Z order - for k in @spritekeys + @spritekeys.each do |k| sprite = @sprites[k] y = sprite.y sprite.y = i diff --git a/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb b/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb index 4ecd683b1..7e59891e4 100644 --- a/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb +++ b/Data/Scripts/007_Objects and windows/005_SpriteWindow_text.rb @@ -235,7 +235,7 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base cwidth = (maxwidth < 0) ? Graphics.width : maxwidth chars = getFormattedTextForDims(self.contents, 0, 0, cwidth - self.borderX - 2 - 6, -1, text, @lineHeight, true) - for ch in chars + chars.each do |ch| dims[0] = [dims[0], ch[1] + ch[3]].max dims[1] = [dims[1], ch[2] + ch[4]].max end @@ -312,7 +312,7 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base self.width - self.borderX - SpriteWindow_Base::TEXTPADDING, -1, shadowctag(@baseColor, @shadowColor) + value, 32, true) @oldfont = self.contents.font.clone - for ch in fmt + fmt.each do |ch| chx = ch[1] + ch[3] chy = ch[2] + ch[4] width = chx if width < chx @@ -340,7 +340,7 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base self.width - self.borderX - SpriteWindow_Base::TEXTPADDING, -1, shadowctag(@baseColor, @shadowColor) + value, 32, true) @oldfont = self.contents.font.clone - for ch in @fmtchars + @fmtchars.each do |ch| chx = ch[1] + ch[3] chy = ch[2] + ch[4] width = chx if width < chx @@ -390,7 +390,7 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base def maxPosition pos = 0 - for ch in @fmtchars + @fmtchars.each do |ch| # index after the last character's index pos = ch[14] + 1 if pos < ch[14] + 1 end @@ -481,7 +481,7 @@ class Window_AdvancedTextPokemon < SpriteWindow_Base end maxX = self.width - self.borderX maxY = self.height - self.borderY - for i in @drawncurchar + 1..numchars + (@drawncurchar + 1..numchars).each do |i| next if i >= @fmtchars.length if !self.letterbyletter next if @fmtchars[i][1] >= maxX @@ -667,7 +667,7 @@ class Window_InputNumberPokemon < SpriteWindow_Base if @sign textHelper(0, 0, @negative ? "-" : "+", 0) end - for i in 0...@digits_max + @digits_max.times do |i| index = i + (@sign ? 1 : 0) textHelper(index * 24, 0, s[i, 1], index) end @@ -1084,7 +1084,7 @@ class Window_DrawableCommand < SpriteWindow_SelectableEx width = 0 tmpbitmap = BitmapWrapper.new(1, 1) pbSetSystemFont(tmpbitmap) - for i in commands + commands.each do |i| width = [width, tmpbitmap.text_size(i).width].max end # one 16 to allow cursor @@ -1125,7 +1125,7 @@ class Window_DrawableCommand < SpriteWindow_SelectableEx dheight = self.height - self.borderY self.contents = pbDoEnsureBitmap(self.contents, dwidth, dheight) self.contents.clear - for i in 0...@item_max + @item_max.times do |i| next if i < self.top_item || i > self.top_item + self.page_item_max drawItem(i, @item_max, itemRect(i)) end @@ -1250,7 +1250,7 @@ class Window_AdvancedCommandPokemon < Window_DrawableCommand chars = getFormattedText(bitmap, 0, 0, Graphics.width - self.borderX - SpriteWindow_Base::TEXTPADDING - 16, -1, text, self.rowHeight, true, true) - for ch in chars + chars.each do |ch| dims[0] = dims[0] ? [dims[0], ch[1]].min : ch[1] dims[1] = [dims[1], ch[1] + ch[3]].max end diff --git a/Data/Scripts/007_Objects and windows/008_AnimatedBitmap.rb b/Data/Scripts/007_Objects and windows/008_AnimatedBitmap.rb index 688cc3314..ab78018d0 100644 --- a/Data/Scripts/007_Objects and windows/008_AnimatedBitmap.rb +++ b/Data/Scripts/007_Objects and windows/008_AnimatedBitmap.rb @@ -57,7 +57,7 @@ class PngAnimatedBitmap end @frameDelay = delay subWidth = panorama.width / numFrames - for i in 0...numFrames + numFrames.times do |i| subBitmap = BitmapWrapper.new(subWidth, panorama.height) subBitmap.blt(0, 0, panorama, Rect.new(subWidth * i, 0, subWidth, panorama.height)) @frames.push(subBitmap) @@ -76,7 +76,7 @@ class PngAnimatedBitmap def height; self.bitmap.height; end def deanimate - for i in 1...@frames.length + (1...@frames.length).each do |i| @frames[i].dispose end @frames = [@frames[0]] @@ -134,9 +134,7 @@ class PngAnimatedBitmap def copy x = self.clone x.frames = x.frames.clone - for i in 0...x.frames.length - x.frames[i] = x.frames[i].copy - end + x.frames.each_with_index { |frame, i| x.frames[i] = frame.copy } return x end end diff --git a/Data/Scripts/007_Objects and windows/010_DrawText.rb b/Data/Scripts/007_Objects and windows/010_DrawText.rb index 345d77dbd..02518a726 100644 --- a/Data/Scripts/007_Objects and windows/010_DrawText.rb +++ b/Data/Scripts/007_Objects and windows/010_DrawText.rb @@ -238,7 +238,7 @@ def getFormattedTextFast(bitmap, xDst, yDst, widthDst, heightDst, text, lineheig lastword[0] += 1 y += 1 x = 0 - for i in lastword[0]...characters.length + (lastword[0]...characters.length).each do |i| characters[i][2] += lineheight charwidth = characters[i][3] - 2 characters[i][1] = x @@ -251,12 +251,12 @@ def getFormattedTextFast(bitmap, xDst, yDst, widthDst, heightDst, text, lineheig # Eliminate spaces before newlines and pause character if havenl firstspace = -1 - for i in 0...characters.length + characters.length.times do |i| if characters[i][5] != false # If not a character firstspace = -1 elsif (characters[i][0] == "\n" || isWaitChar(characters[i][0])) && firstspace >= 0 - for j in firstspace...i + (firstspace...i).each do |j| characters[j] = nil end firstspace = -1 @@ -267,21 +267,17 @@ def getFormattedTextFast(bitmap, xDst, yDst, widthDst, heightDst, text, lineheig end end if firstspace > 0 - for j in firstspace...characters.length + (firstspace...characters.length).each do |j| characters[j] = nil end end characters.compact! end - for i in 0...characters.length - characters[i][1] = xDst + characters[i][1] - end + characters.each { |char| char[1] = xDst + char[1] } # Remove all characters with Y greater or equal to _yDst_+_heightDst_ if heightDst >= 0 - for i in 0...characters.length - if characters[i][2] >= yDst + heightDst - characters[i] = nil - end + characters.each_with_index do |char, i| + characters[i] = nil if char[2] >= yDst + heightDst end characters.compact! end @@ -397,7 +393,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = end textchunks = [] controls = [] - oldtext = text +# oldtext = text while text[FORMATREGEXP] textchunks.push($~.pre_match) if $~[3] @@ -424,7 +420,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = # realtextStart = oldtext[0, oldtext.length - realtext.length] # end textchunks.push(text) - for chunk in textchunks + textchunks.each do |chunk| chunk.gsub!(/</, "<") chunk.gsub!(/>/, ">") chunk.gsub!(/'/, "'") @@ -432,9 +428,9 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = chunk.gsub!(/&/, "&") end textlen = 0 - for i in 0...controls.length + controls.each_with_index do |control, i| textlen += textchunks[i].scan(/./m).length - controls[i][2] = textlen + control[2] = textlen end text = textchunks.join("") textchars = text.scan(/./m) @@ -475,7 +471,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = graphicWidth = nil graphicHeight = nil graphicRect = nil - for i in 0...controls.length + controls.length.times do |i| if controls[i] && controls[i][2] == position control = controls[i][0] param = controls[i][1] @@ -694,7 +690,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = lastword[0] += 1 y += 1 x = 0 - for i in lastword[0]...characters.length + (lastword[0]...characters.length).each do |i| characters[i][2] += lineheight charactersInternal[i][1] += 1 extraspace = (charactersInternal[i][4]) ? charactersInternal[i][4] : 0 @@ -754,12 +750,12 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = if havenl # Eliminate spaces before newlines and pause character firstspace = -1 - for i in 0...characters.length + characters.length.times do |i| if characters[i][5] != false # If not a character firstspace = -1 elsif (characters[i][0] == "\n" || isWaitChar(characters[i][0])) && firstspace >= 0 - for j in firstspace...i + (firstspace...i).each do |j| characters[j] = nil charactersInternal[j] = nil end @@ -773,7 +769,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = end end if firstspace > 0 - for j in firstspace...characters.length + (firstspace...characters.length).each do |j| characters[j] = nil charactersInternal[j] = nil end @@ -788,7 +784,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = lastalign = 0 lasty = 0 runstart = 0 - for i in 0...characters.length + characters.length.times do |i| c = characters[i] if i > 0 && (charactersInternal[i][0] != lastalign || charactersInternal[i][1] != lasty) @@ -806,7 +802,7 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = if collapseAlignments # Calculate the total width of each line totalLineWidths = [] - for block in widthblocks + widthblocks.each do |block| y = block[4] if !totalLineWidths[y] totalLineWidths[y] = 0 @@ -821,9 +817,9 @@ def getFormattedText(bitmap, xDst, yDst, widthDst, heightDst, text, lineheight = widthDst = [widthDst, (totalLineWidths.compact.max || 0)].min end # Now, based on the text runs found, recalculate Xs - for block in widthblocks + widthblocks.each do |block| next if block[0] >= block[1] - for i in block[0]...block[1] + (block[0]...block[1]).each do |i| case block[2] when 1 then characters[i][1] = xDst + (widthDst - block[3] - 4) + characters[i][1] when 2 then characters[i][1] = xDst + ((widthDst / 2) - (block[3] / 2)) + characters[i][1] @@ -874,7 +870,7 @@ def getLineBrokenText(bitmap, value, width, dims) next end words = [ccheck] - for i in 0...words.length + words.length.times do |i| word = words[i] if word && word != "" textSize = bitmap.text_size(word) @@ -929,7 +925,7 @@ def getLineBrokenChunks(bitmap, value, width, dims, plain = false) else words = [ccheck] end - for i in 0...words.length + words.length.times do |i| word = words[i] if word && word != "" textSize = bitmap.text_size(word) @@ -955,25 +951,25 @@ def getLineBrokenChunks(bitmap, value, width, dims, plain = false) end def renderLineBrokenChunks(bitmap, xDst, yDst, normtext, maxheight = 0) - for i in 0...normtext.length - width = normtext[i][3] - textx = normtext[i][1] + xDst - texty = normtext[i][2] + yDst - if maxheight == 0 || normtext[i][2] < maxheight - bitmap.font.color = normtext[i][5] - bitmap.draw_text(textx, texty, width + 2, normtext[i][4], normtext[i][0]) + normtext.each do |text| + width = text[3] + textx = text[1] + xDst + texty = text[2] + yDst + if maxheight == 0 || text[2] < maxheight + bitmap.font.color = text[5] + bitmap.draw_text(textx, texty, width + 2, text[4], text[0]) end end end def renderLineBrokenChunksWithShadow(bitmap, xDst, yDst, normtext, maxheight, baseColor, shadowColor) - for i in 0...normtext.length - width = normtext[i][3] - textx = normtext[i][1] + xDst - texty = normtext[i][2] + yDst - if maxheight == 0 || normtext[i][2] < maxheight - height = normtext[i][4] - text = normtext[i][0] + normtext.each do |text| + width = text[3] + textx = text[1] + xDst + texty = text[2] + yDst + if maxheight == 0 || text[2] < maxheight + height = text[4] + text = text[0] bitmap.font.color = shadowColor bitmap.draw_text(textx + 2, texty, width + 2, height, text) bitmap.draw_text(textx, texty + 2, width + 2, height, text) @@ -987,7 +983,7 @@ end def drawBitmapBuffer(chars) width = 1 height = 1 - for ch in chars + chars.each do |ch| chx = ch[1] + ch[3] chy = ch[2] + ch[4] width = chx if width < chx @@ -1057,7 +1053,7 @@ end def drawFormattedChars(bitmap, chars) return if chars.length == 0 || !bitmap || bitmap.disposed? oldfont = bitmap.font.clone - for ch in chars + chars.each do |ch| drawSingleFormattedChar(bitmap, ch) end bitmap.font = oldfont @@ -1066,10 +1062,10 @@ end # Unused def drawTextTable(bitmap, x, y, totalWidth, rowHeight, columnWidthPercents, table) yPos = y - for i in 0...table.length + table.length.times do |i| row = table[i] xPos = x - for j in 0...row.length + row.length.times do |j| cell = row[j] cellwidth = columnWidthPercents[j] * totalWidth / 100 chars = getFormattedText(bitmap, xPos, yPos, cellwidth, -1, cell, rowHeight) @@ -1149,7 +1145,7 @@ end # 5 - Shadow color # 6 - If true or 1, the text has an outline. Otherwise, the text has a shadow. def pbDrawTextPositions(bitmap, textpos) - for i in textpos + textpos.each do |i| textsize = bitmap.text_size(i[0]) x = i[1] y = i[2] + 6 @@ -1178,7 +1174,7 @@ def pbCopyBitmap(dstbm, srcbm, x, y, opacity = 255) end def pbDrawImagePositions(bitmap, textpos) - for i in textpos + textpos.each do |i| srcbitmap = AnimatedBitmap.new(pbBitmapName(i[0])) x = i[1] y = i[2] diff --git a/Data/Scripts/007_Objects and windows/011_Messages.rb b/Data/Scripts/007_Objects and windows/011_Messages.rb index 9fbf3b0e1..f59c2e1f7 100644 --- a/Data/Scripts/007_Objects and windows/011_Messages.rb +++ b/Data/Scripts/007_Objects and windows/011_Messages.rb @@ -28,12 +28,12 @@ def pbEventCommentInput(*args) trigger = args[2] # Trigger return nil if list == nil return nil unless list.is_a?(Array) - for item in list + list.each do |item| next unless item.code == 108 || item.code == 408 if item.parameters[0] == trigger start = list.index(item) + 1 finish = start + elements - for id in start...finish + (start...finish).each do |id| next if !list[id] parameters.push(list[id].parameters[0]) end @@ -225,8 +225,7 @@ class FaceWindowVX < SpriteWindow_Base @facebitmaptmp = AnimatedBitmap.new(facefile) @facebitmap = BitmapWrapper.new(96, 96) @facebitmap.blt(0, 0, @facebitmaptmp.bitmap, - Rect.new((@faceIndex % 4) * 96, (@faceIndex / 4) * 96, 96, 96) - ) + Rect.new((@faceIndex % 4) * 96, (@faceIndex / 4) * 96, 96, 96)) self.contents = @facebitmap end @@ -235,8 +234,7 @@ class FaceWindowVX < SpriteWindow_Base if @facebitmaptmp.totalFrames > 1 @facebitmaptmp.update @facebitmap.blt(0, 0, @facebitmaptmp.bitmap, - Rect.new((@faceIndex % 4) * 96, (@faceIndex / 4) * 96, 96, 96) - ) + Rect.new((@faceIndex % 4) * 96, (@faceIndex / 4) * 96, 96, 96)) end end @@ -504,11 +502,11 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni text = $~.post_match end textchunks.push(text) - for chunk in textchunks + textchunks.each do |chunk| chunk.gsub!(/\005/, "\\") end textlen = 0 - for i in 0...controls.length + controls.length.times do |i| control = controls[i][0] case control when "wt", "wtnp", ".", "|" @@ -524,7 +522,7 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni signWaitTime = Graphics.frame_rate / 2 haveSpecialClose = false specialCloseSE = "" - for i in 0...controls.length + controls.length.times do |i| control = controls[i][0] param = controls[i][1] case control @@ -582,7 +580,7 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni msgwindow.y = Graphics.height - (msgwindow.height * (signWaitTime - signWaitCount) / signWaitTime) end end - for i in 0...controls.length + controls.length.times do |i| next if !controls[i] next if controls[i][2] > msgwindow.position || msgwindow.waitcount != 0 control = controls[i][0] @@ -686,7 +684,7 @@ def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = ni if haveSpecialClose pbSEPlay(pbStringToAudioFile(specialCloseSE)) atTop = (msgwindow.y == 0) - for i in 0..signWaitTime + (0..signWaitTime).each do |i| if atTop msgwindow.y = -msgwindow.height * i / signWaitTime else diff --git a/Data/Scripts/007_Objects and windows/012_TextEntry.rb b/Data/Scripts/007_Objects and windows/012_TextEntry.rb index 132f78cb3..24e29a1c2 100644 --- a/Data/Scripts/007_Objects and windows/012_TextEntry.rb +++ b/Data/Scripts/007_Objects and windows/012_TextEntry.rb @@ -41,7 +41,7 @@ class CharacterEntryHelper return false if @maxlength >= 0 && chars.length >= @maxlength chars.insert(@cursor, ch) @text = "" - for ch in chars + chars.each do |ch| @text += ch if ch end @cursor += 1 @@ -59,7 +59,7 @@ class CharacterEntryHelper return false if chars.length <= 0 || @cursor <= 0 chars.delete_at(@cursor - 1) @text = "" - for ch in chars + chars.each do |ch| @text += ch if ch end @cursor -= 1 @@ -75,7 +75,7 @@ class CharacterEntryHelper chars = chars[0, @maxlength] end @text = "" - for ch in chars + chars.each do |ch| @text += ch if ch end end @@ -198,7 +198,7 @@ class Window_TextEntry < SpriteWindow_Base break if fromcursor > width - 4 startpos -= 1 end - for i in startpos...scanlength + (startpos...scanlength).each do |i| c = (@helper.passwordChar != "") ? @helper.passwordChar : textscan[i] textwidth = bitmap.text_size(c).width next if c == "\n" @@ -352,9 +352,9 @@ class Window_MultilineTextEntry < SpriteWindow_Base line = 0 if line < 0 line = totallines - 1 if line >= totallines maximumY = 0 - for i in 0...textchars.length - thisline = textchars[i][5] - y = textchars[i][2] + textchars.each do |text| + thisline = text[5] + y = text[2] return y if thisline == line maximumY = y if maximumY < y end @@ -368,9 +368,9 @@ class Window_MultilineTextEntry < SpriteWindow_Base line = 0 if line < 0 line = totallines - 1 if line >= totallines endpos = 0 - for i in 0...textchars.length - thisline = textchars[i][5] - thislength = textchars[i][8] + textchars.each do |text| + thisline = text[5] + thislength = text[8] endpos += thislength if thisline == line end return endpos @@ -383,11 +383,11 @@ class Window_MultilineTextEntry < SpriteWindow_Base line = 0 if line < 0 line = totallines - 1 if line >= totallines endpos = 0 - for i in 0...textchars.length - thisline = textchars[i][5] - thispos = textchars[i][6] - thiscolumn = textchars[i][7] - thislength = textchars[i][8] + textchars.each do |text| + thisline = text[5] + thispos = text[6] + thiscolumn = text[7] + thislength = text[8] if thisline == line endpos = thispos + thislength # echoln [endpos,thispos+(column-thiscolumn),textchars[i]] @@ -510,40 +510,40 @@ class Window_MultilineTextEntry < SpriteWindow_Base cursorcolor = Color.new(0, 0, 0) textchars = getTextChars startY = getLineY(@firstline) - for i in 0...textchars.length - thisline = textchars[i][5] - thiscolumn = textchars[i][7] - thislength = textchars[i][8] - textY = textchars[i][2] - startY + textchars.each do |text| + thisline = text[5] + thiscolumn = text[7] + thislength = text[8] + textY = text[2] - startY # Don't draw lines before the first or zero-length segments next if thisline < @firstline || thislength == 0 # Don't draw lines beyond the window's height break if textY >= height - c = textchars[i][0] + c = text[0] # Don't draw spaces next if c == " " - textwidth = textchars[i][3] + 4 # add 4 to prevent draw_text from stretching text - textheight = textchars[i][4] + textwidth = text[3] + 4 # add 4 to prevent draw_text from stretching text + textheight = text[4] # Draw text - pbDrawShadowText(bitmap, textchars[i][1], textY, textwidth, textheight, c, @baseColor, @shadowColor) + pbDrawShadowText(bitmap, text[1], textY, textwidth, textheight, c, @baseColor, @shadowColor) end # Draw cursor if ((@frame / 10) & 1) == 0 textheight = bitmap.text_size("X").height cursorY = (textheight * @cursorLine) - startY cursorX = 0 - for i in 0...textchars.length - thisline = textchars[i][5] - thiscolumn = textchars[i][7] - thislength = textchars[i][8] + textchars.each do |text| + thisline = text[5] + thiscolumn = text[7] + thislength = text[8] if thisline == @cursorLine && @cursorColumn >= thiscolumn && @cursorColumn <= thiscolumn + thislength - cursorY = textchars[i][2] - startY - cursorX = textchars[i][1] - textheight = textchars[i][4] + cursorY = text[2] - startY + cursorX = text[1] + textheight = text[4] posToCursor = @cursorColumn - thiscolumn if posToCursor >= 0 - partialString = textchars[i][0].scan(/./m)[0, posToCursor].join("") + partialString = text[0].scan(/./m)[0, posToCursor].join("") cursorX += bitmap.text_size(partialString).width end break diff --git a/Data/Scripts/008_Audio/001_Audio.rb b/Data/Scripts/008_Audio/001_Audio.rb index 7de205ef7..a7d480341 100644 --- a/Data/Scripts/008_Audio/001_Audio.rb +++ b/Data/Scripts/008_Audio/001_Audio.rb @@ -4,7 +4,7 @@ $AtExitProcs = [] if !$AtExitProcs def exit(code = 0) - for p in $AtExitProcs + $AtExitProcs.each do |p| p.call end raise SystemExit.new(code) @@ -51,7 +51,7 @@ def oggfiletime(file) i = -1 pcmlengths = [] rates = [] - for page in pages + pages.each do |page| header = page[0] serial = header[10, 4].unpack("V") frame = header[2, 8].unpack("C*") @@ -78,9 +78,7 @@ def oggfiletime(file) pcmlengths[i] = frameno end ret = 0.0 - for i in 0...pcmlengths.length - ret += pcmlengths[i].to_f / rates[i] - end + pcmlengths.each_with_index { |length, i| ret += length.to_f / rates[i] } return ret * 256.0 end diff --git a/Data/Scripts/009_Scenes/001_Transitions.rb b/Data/Scripts/009_Scenes/001_Transitions.rb index aba221c76..0b91fd6ec 100644 --- a/Data/Scripts/009_Scenes/001_Transitions.rb +++ b/Data/Scripts/009_Scenes/001_Transitions.rb @@ -176,8 +176,8 @@ module Transitions # Overworld sprites sprite_width = @overworld_bitmap.width / NUM_SPRITES_X sprite_height = @overworld_bitmap.height / NUM_SPRITES_Y - for j in 0...NUM_SPRITES_Y - for i in 0...NUM_SPRITES_X + NUM_SPRITES_Y.times do |j| + NUM_SPRITES_X.times do |i| idx_sprite = (j * NUM_SPRITES_X) + i @sprites[idx_sprite] = new_sprite(i * sprite_width, j * sprite_height, @overworld_bitmap) @sprites[idx_sprite].src_rect.set(i * sprite_width, j * sprite_height, sprite_width, sprite_height) @@ -187,8 +187,8 @@ module Transitions def set_up_timings @start_y = [] - for j in 0...NUM_SPRITES_Y - for i in 0...NUM_SPRITES_X + NUM_SPRITES_Y.times do |j| + NUM_SPRITES_X.times do |i| idx_sprite = (j * NUM_SPRITES_X) + i @start_y[idx_sprite] = @sprites[idx_sprite].y @timings[idx_sprite] = 0.5 + rand @@ -217,8 +217,8 @@ module Transitions # Overworld sprites sprite_width = @overworld_bitmap.width / NUM_SPRITES_X sprite_height = @overworld_bitmap.height / NUM_SPRITES_Y - for j in 0...NUM_SPRITES_Y - for i in 0...NUM_SPRITES_X + NUM_SPRITES_Y.times do |j| + NUM_SPRITES_X.times do |i| idx_sprite = (j * NUM_SPRITES_X) + i @sprites[idx_sprite] = new_sprite((i + 0.5) * sprite_width, (j + 0.5) * sprite_height, @overworld_bitmap, sprite_width / 2, sprite_height / 2) @@ -256,8 +256,8 @@ module Transitions # Overworld sprites sprite_width = @overworld_bitmap.width / NUM_SPRITES_X sprite_height = @overworld_bitmap.height / NUM_SPRITES_Y - for j in 0...NUM_SPRITES_Y - for i in 0...NUM_SPRITES_X + NUM_SPRITES_Y.times do |j| + NUM_SPRITES_X.times do |i| idx_sprite = (j * NUM_SPRITES_X) + i @sprites[idx_sprite] = new_sprite((i + 0.5) * sprite_width, (j + 0.5) * sprite_height, @overworld_bitmap, sprite_width / 2, sprite_height / 2) @@ -270,8 +270,8 @@ module Transitions @start_positions = [] @move_vectors = [] vague = (@parameters[0] || 9.6) * SPEED - for j in 0...NUM_SPRITES_Y - for i in 0...NUM_SPRITES_X + NUM_SPRITES_Y.times do |j| + NUM_SPRITES_X.times do |i| idx_sprite = (j * NUM_SPRITES_X) + i spr = @sprites[idx_sprite] @start_positions[idx_sprite] = [spr.x, spr.y] @@ -329,8 +329,8 @@ module Transitions num_stripes_x = 1 num_stripes_y = @overworld_bitmap.height / STRIPE_WIDTH end - for j in 0...num_stripes_y - for i in 0...num_stripes_x + num_stripes_y.times do |j| + num_stripes_x.times do |i| idx_sprite = (j * num_stripes_x) + i @sprites[idx_sprite] = new_sprite(i * sprite_width, j * sprite_height, @overworld_bitmap) @sprites[idx_sprite].src_rect.set(i * sprite_width, j * sprite_height, sprite_width, sprite_height) @@ -339,7 +339,7 @@ module Transitions end def set_up_timings - for i in 0...@sprites.length + @sprites.length.times do |i| @timings[i] = @duration * i / @sprites.length end @timings.shuffle! @@ -464,8 +464,8 @@ module Transitions end def initialize_sprites - for j in 0...NUM_SPRITES_Y - for i in 0...NUM_SPRITES_X + NUM_SPRITES_Y.times do |j| + NUM_SPRITES_X.times do |i| idx_sprite = (j * NUM_SPRITES_X) + i if idx_sprite >= TOTAL_SPRITES / 2 sprite_x = ((j.odd?) ? i : (NUM_SPRITES_X - i - 1)) * @black_bitmap.width @@ -483,8 +483,8 @@ module Transitions def set_up_timings time_between_zooms = (@duration - TIME_TO_ZOOM) * 2 / (TOTAL_SPRITES - 1) - for j in 0...NUM_SPRITES_Y - for i in 0...NUM_SPRITES_X + NUM_SPRITES_Y.times do |j| + NUM_SPRITES_X.times do |i| idx_sprite = (j * NUM_SPRITES_X) + i idx_from_start = (idx_sprite >= TOTAL_SPRITES / 2) ? TOTAL_SPRITES - 1 - idx_sprite : idx_sprite @timings[idx_sprite] = time_between_zooms * idx_from_start @@ -532,8 +532,8 @@ module Transitions end def initialize_sprites - for j in 0...NUM_SPRITES_Y - for i in 0...NUM_SPRITES_X + NUM_SPRITES_Y.times do |j| + NUM_SPRITES_X.times do |i| idx_sprite = (j * NUM_SPRITES_X) + i @sprites[idx_sprite] = new_sprite(((i * @bitmap.width) + (@bitmap.width / 2)) * @zoom_x_target, ((j * @bitmap.height) + (@bitmap.height / 2)) * @zoom_y_target, @@ -544,8 +544,8 @@ module Transitions end def set_up_timings - for j in 0...NUM_SPRITES_Y - for i in 0...NUM_SPRITES_X + NUM_SPRITES_Y.times do |j| + NUM_SPRITES_X.times do |i| idx_from_start = (j * NUM_SPRITES_X) + i # Top left -> bottom right case @parameters[0] # Origin when 1 # Top right -> bottom left @@ -603,7 +603,7 @@ module Transitions @overworld_sprite.visible = false # Overworld strips (they go all wavy) rect = Rect.new(0, 0, Graphics.width, 2) - for i in 0...Graphics.height / 2 + (Graphics.height / 2).times do |i| @sprites[i] = new_sprite(0, i * 2, @overworld_bitmap) @sprites[i].z = 2 rect.y = i * 2 @@ -679,7 +679,7 @@ module Transitions @overworld_sprite.oy = @overworld_bitmap.height / 2 # Balls that roll across the screen @ball_sprites = [] - for i in 0...2 + 2.times do |i| x = ((1 - i) * Graphics.width) + ((1 - (i * 2)) * @ball_bitmap.width / 2) y = (Graphics.height + (((i * 2) - 1) * @ball_bitmap.width)) / 2 @ball_sprites[i] = new_sprite(x, y, @ball_bitmap, @@ -687,7 +687,7 @@ module Transitions @ball_sprites[i].z = 2 end # Black foreground sprites - for i in 0...2 + 2.times do |i| @sprites[i] = new_sprite((1 - (i * 2)) * Graphics.width, i * Graphics.height / 2, @black_bitmap) @sprites[i].z = 1 end @@ -756,7 +756,7 @@ module Transitions @overworld_sprites = [] @black_sprites = [] @ball_sprites = [] - for i in 0...2 + 2.times do |i| # Overworld sprites (they split apart) @overworld_sprites[i] = new_sprite(Graphics.width / 2, Graphics.height / 2, @overworld_bitmap, Graphics.width / 2, (1 - i) * Graphics.height / 2) @@ -857,8 +857,8 @@ module Transitions @overworld_sprite.ox = @overworld_bitmap.width / 2 @overworld_sprite.oy = @overworld_bitmap.height / 2 # Black squares - for j in 0...NUM_SPRITES_Y - for i in 0...NUM_SPRITES_X + NUM_SPRITES_Y.times do |j| + NUM_SPRITES_X.times do |i| idx_sprite = (j * NUM_SPRITES_X) + i @sprites[idx_sprite] = new_sprite(i * @black_bitmap.width * @zoom_x_target, j * @black_bitmap.height * @zoom_y_target, @black_bitmap) @@ -867,7 +867,7 @@ module Transitions end # Falling balls @ball_sprites = [] - for i in 0...3 + 3.times do |i| @ball_sprites[i] = new_sprite((Graphics.width / 2) + ((i - 1) * 160), -@ball_bitmap.height - BALL_START_Y_OFFSETS[i], @ball_bitmap, @ball_bitmap.width / 2, @ball_bitmap.height / 2) @@ -879,9 +879,9 @@ module Transitions @black_appear_start = @duration * 0.2 appear_order = [0, 4, 1, 6, 7, 2, 5, 3] period = @duration - @black_appear_start - for j in 0...NUM_SPRITES_Y + NUM_SPRITES_Y.times do |j| row_offset = NUM_SPRITES_Y - j - 1 - for i in 0...NUM_SPRITES_X + NUM_SPRITES_X.times do |i| idx_sprite = (j * NUM_SPRITES_X) + i @timings[idx_sprite] = period * ((row_offset * NUM_SPRITES_X) + appear_order[i]) / TOTAL_SPRITES @timings[idx_sprite] += @black_appear_start @@ -1015,7 +1015,7 @@ module Transitions @overworld_sprite.visible = false # Overworld strips (they go all wavy) rect = Rect.new(0, 0, Graphics.width, 4) - for i in 0...Graphics.height / 4 + (Graphics.height / 4).times do |i| @sprites[i] = new_sprite(0, i * 4, @overworld_bitmap) @sprites[i].z = 2 rect.y = i * 4 @@ -1023,7 +1023,7 @@ module Transitions end # Ball sprites @ball_sprites = [] - for i in 0...3 + 3.times do |i| @ball_sprites[i] = new_sprite(((2 * i) + 1) * Graphics.width / 6, BALL_OFFSETS[i] * Graphics.height, @ball_bitmap, @ball_bitmap.width / 2, @ball_bitmap.height / 2) @@ -1031,7 +1031,7 @@ module Transitions end # Black columns that follow the ball sprites @black_trail_sprites = [] - for i in 0...3 + 3.times do |i| @black_trail_sprites[i] = new_sprite((i - 1) * Graphics.width * 2 / 3, BALL_OFFSETS[i] * Graphics.height, @black_bitmap) @black_trail_sprites[i].z = 3 @@ -1096,7 +1096,7 @@ module Transitions @overworld_sprite.visible = false # Overworld strips (they go all wavy) rect = Rect.new(0, 0, Graphics.width, 4) - for i in 0...Graphics.height / 4 + (Graphics.height / 4).times do |i| @sprites[i] = new_sprite(0, i * 4, @overworld_bitmap) @sprites[i].z = 2 rect.y = i * 4 @@ -1172,13 +1172,13 @@ module Transitions def initialize_sprites # Ball sprites @ball_sprites = [] - for i in 0...4 + 4.times do |i| @ball_sprites[i] = new_sprite(Graphics.width / 2, Graphics.height / 2, @ball_bitmap, @ball_bitmap.width / 2, @ball_bitmap.height / 2) @ball_sprites[i].z = [2, 1, 3, 0][i] end # Black wedges - for i in 0...4 + 4.times do |i| b = [@black_1_bitmap, @black_2_bitmap, @black_3_bitmap, @black_4_bitmap][i] @sprites[i] = new_sprite((i == 1) ? 0 : Graphics.width / 2, (i == 2) ? 0 : Graphics.height / 2, b, (i.even?) ? b.width / 2 : 0, (i.even?) ? 0 : b.height / 2) diff --git a/Data/Scripts/009_Scenes/002_EventScene.rb b/Data/Scripts/009_Scenes/002_EventScene.rb index f29c41c1e..459ff2d7a 100644 --- a/Data/Scripts/009_Scenes/002_EventScene.rb +++ b/Data/Scripts/009_Scenes/002_EventScene.rb @@ -80,10 +80,10 @@ class EventScene def dispose return if disposed? - for sprite in @picturesprites + @picturesprites.each do |sprite| sprite.dispose end - for sprite in @usersprites + @usersprites.each do |sprite| sprite.dispose end @onCTrigger.clear @@ -143,7 +143,7 @@ class EventScene def pictureWait(extraframes = 0) loop do hasRunning = false - for pic in @pictures + @pictures.each do |pic| hasRunning = true if pic.running? end break if !hasRunning @@ -156,13 +156,13 @@ class EventScene return if disposed? Graphics.update Input.update - for picture in @pictures + @pictures.each do |picture| picture.update end - for sprite in @picturesprites + @picturesprites.each do |sprite| sprite.update end - for sprite in @usersprites + @usersprites.each do |sprite| next if !sprite || sprite.disposed? || !sprite.is_a?(Sprite) sprite.update end diff --git a/Data/Scripts/010_Data/001_Hardcoded data/001_GrowthRate.rb b/Data/Scripts/010_Data/001_Hardcoded data/001_GrowthRate.rb index 988bae6eb..6fa9c71a0 100644 --- a/Data/Scripts/010_Data/001_Hardcoded data/001_GrowthRate.rb +++ b/Data/Scripts/010_Data/001_Hardcoded data/001_GrowthRate.rb @@ -64,7 +64,7 @@ module GameData return ArgumentError.new("Exp amount #{level} is invalid.") if !exp || exp < 0 max = GrowthRate.max_level return max if exp >= maximum_exp - for level in 1..max + (1..max).each do |level| return level - 1 if exp < minimum_exp_for_level(level) end return max diff --git a/Data/Scripts/010_Data/002_PBS data/009_Species_Files.rb b/Data/Scripts/010_Data/002_PBS data/009_Species_Files.rb index 8b12a805b..652913482 100644 --- a/Data/Scripts/010_Data/002_PBS data/009_Species_Files.rb +++ b/Data/Scripts/010_Data/002_PBS data/009_Species_Files.rb @@ -13,7 +13,7 @@ module GameData factors.push([1, try_form, ""]) if form > 0 factors.push([0, try_species, "000"]) # Go through each combination of parameters in turn to find an existing sprite - for i in 0...2**factors.length + (2**factors.length).times do |i| # Set try_ parameters for this combination factors.each_with_index do |factor, index| value = ((i / (2**index)).even?) ? factor[1] : factor[2] diff --git a/Data/Scripts/010_Data/002_PBS data/018_MapMetadata.rb b/Data/Scripts/010_Data/002_PBS data/018_MapMetadata.rb index 7938855ac..29e196a4f 100644 --- a/Data/Scripts/010_Data/002_PBS data/018_MapMetadata.rb +++ b/Data/Scripts/010_Data/002_PBS data/018_MapMetadata.rb @@ -28,28 +28,28 @@ module GameData DATA_FILENAME = "map_metadata.dat" SCHEMA = { - "Name" => [1, "s"], - "Outdoor" => [2, "b"], - "ShowArea" => [3, "b"], - "Bicycle" => [4, "b"], - "BicycleAlways" => [5, "b"], - "HealingSpot" => [6, "vuu"], - "Weather" => [7, "eu", :Weather], - "MapPosition" => [8, "uuu"], - "DiveMap" => [9, "v"], - "DarkMap" => [10, "b"], - "SafariMap" => [11, "b"], - "SnapEdges" => [12, "b"], - "Dungeon" => [13, "b"], - "BattleBack" => [14, "s"], - "WildBattleBGM" => [15, "s"], - "TrainerBattleBGM" => [16, "s"], - "WildVictoryME" => [17, "s"], - "TrainerVictoryME" => [18, "s"], - "WildCaptureME" => [19, "s"], - "MapSize" => [20, "us"], - "Environment" => [21, "e", :Environment], - "Flags" => [22, "*s"] + "Name" => [1, "s"], + "Outdoor" => [2, "b"], + "ShowArea" => [3, "b"], + "Bicycle" => [4, "b"], + "BicycleAlways" => [5, "b"], + "HealingSpot" => [6, "vuu"], + "Weather" => [7, "eu", :Weather], + "MapPosition" => [8, "uuu"], + "DiveMap" => [9, "v"], + "DarkMap" => [10, "b"], + "SafariMap" => [11, "b"], + "SnapEdges" => [12, "b"], + "Dungeon" => [13, "b"], + "BattleBack" => [14, "s"], + "WildBattleBGM" => [15, "s"], + "TrainerBattleBGM" => [16, "s"], + "WildVictoryME" => [17, "s"], + "TrainerVictoryME" => [18, "s"], + "WildCaptureME" => [19, "s"], + "MapSize" => [20, "us"], + "Environment" => [21, "e", :Environment], + "Flags" => [22, "*s"] } extend ClassMethodsIDNumbers @@ -57,28 +57,28 @@ module GameData def self.editor_properties return [ - ["Name", StringProperty, _INTL("The name of the map, as seen by the player. Can be different to the map's name as seen in RMXP.")], - ["Outdoor", BooleanProperty, _INTL("If true, this map is an outdoor map and will be tinted according to time of day.")], - ["ShowArea", BooleanProperty, _INTL("If true, the game will display the map's name upon entry.")], - ["Bicycle", BooleanProperty, _INTL("If true, the bicycle can be used on this map.")], - ["BicycleAlways", BooleanProperty, _INTL("If true, the bicycle will be mounted automatically on this map and cannot be dismounted.")], - ["HealingSpot", MapCoordsProperty, _INTL("Map ID of this Pokémon Center's town, and X and Y coordinates of its entrance within that town.")], - ["Weather", WeatherEffectProperty, _INTL("Weather conditions in effect for this map.")], - ["MapPosition", RegionMapCoordsProperty, _INTL("Identifies the point on the regional map for this map.")], - ["DiveMap", MapProperty, _INTL("Specifies the underwater layer of this map. Use only if this map has deep water.")], - ["DarkMap", BooleanProperty, _INTL("If true, this map is dark and a circle of light appears around the player. Flash can be used to expand the circle.")], - ["SafariMap", BooleanProperty, _INTL("If true, this map is part of the Safari Zone (both indoor and outdoor). Not to be used in the reception desk.")], - ["SnapEdges", BooleanProperty, _INTL("If true, when the player goes near this map's edge, the game doesn't center the player as usual.")], - ["Dungeon", BooleanProperty, _INTL("If true, this map has a randomly generated layout. See the wiki for more information.")], - ["BattleBack", StringProperty, _INTL("PNG files named 'XXX_bg', 'XXX_base0', 'XXX_base1', 'XXX_message' in Battlebacks folder, where XXX is this property's value.")], - ["WildBattleBGM", BGMProperty, _INTL("Default BGM for wild Pokémon battles on this map.")], - ["TrainerBattleBGM", BGMProperty, _INTL("Default BGM for trainer battles on this map.")], - ["WildVictoryME", MEProperty, _INTL("Default ME played after winning a wild Pokémon battle on this map.")], - ["TrainerVictoryME", MEProperty, _INTL("Default ME played after winning a Trainer battle on this map.")], - ["WildCaptureME", MEProperty, _INTL("Default ME played after catching a wild Pokémon on this map.")], - ["MapSize", MapSizeProperty, _INTL("The width of the map in Town Map squares, and a string indicating which squares are part of this map.")], - ["Environment", GameDataProperty.new(:Environment), _INTL("The default battle environment for battles on this map.")], - ["Flags", StringListProperty, _INTL("Words/phrases that distinguish this map from others.")] + ["Name", StringProperty, _INTL("The name of the map, as seen by the player. Can be different to the map's name as seen in RMXP.")], + ["Outdoor", BooleanProperty, _INTL("If true, this map is an outdoor map and will be tinted according to time of day.")], + ["ShowArea", BooleanProperty, _INTL("If true, the game will display the map's name upon entry.")], + ["Bicycle", BooleanProperty, _INTL("If true, the bicycle can be used on this map.")], + ["BicycleAlways", BooleanProperty, _INTL("If true, the bicycle will be mounted automatically on this map and cannot be dismounted.")], + ["HealingSpot", MapCoordsProperty, _INTL("Map ID of this Pokémon Center's town, and X and Y coordinates of its entrance within that town.")], + ["Weather", WeatherEffectProperty, _INTL("Weather conditions in effect for this map.")], + ["MapPosition", RegionMapCoordsProperty, _INTL("Identifies the point on the regional map for this map.")], + ["DiveMap", MapProperty, _INTL("Specifies the underwater layer of this map. Use only if this map has deep water.")], + ["DarkMap", BooleanProperty, _INTL("If true, this map is dark and a circle of light appears around the player. Flash can be used to expand the circle.")], + ["SafariMap", BooleanProperty, _INTL("If true, this map is part of the Safari Zone (both indoor and outdoor). Not to be used in the reception desk.")], + ["SnapEdges", BooleanProperty, _INTL("If true, when the player goes near this map's edge, the game doesn't center the player as usual.")], + ["Dungeon", BooleanProperty, _INTL("If true, this map has a randomly generated layout. See the wiki for more information.")], + ["BattleBack", StringProperty, _INTL("PNG files named 'XXX_bg', 'XXX_base0', 'XXX_base1', 'XXX_message' in Battlebacks folder, where XXX is this property's value.")], + ["WildBattleBGM", BGMProperty, _INTL("Default BGM for wild Pokémon battles on this map.")], + ["TrainerBattleBGM", BGMProperty, _INTL("Default BGM for trainer battles on this map.")], + ["WildVictoryME", MEProperty, _INTL("Default ME played after winning a wild Pokémon battle on this map.")], + ["TrainerVictoryME", MEProperty, _INTL("Default ME played after winning a Trainer battle on this map.")], + ["WildCaptureME", MEProperty, _INTL("Default ME played after catching a wild Pokémon on this map.")], + ["MapSize", MapSizeProperty, _INTL("The width of the map in Town Map squares, and a string indicating which squares are part of this map.")], + ["Environment", GameDataProperty.new(:Environment), _INTL("The default battle environment for battles on this map.")], + ["Flags", StringListProperty, _INTL("Words/phrases that distinguish this map from others.")] ] end diff --git a/Data/Scripts/011_Battle/001_Battle/001_Battle.rb b/Data/Scripts/011_Battle/001_Battle/001_Battle.rb index 4d4e6bf57..7f026fe71 100644 --- a/Data/Scripts/011_Battle/001_Battle/001_Battle.rb +++ b/Data/Scripts/011_Battle/001_Battle/001_Battle.rb @@ -281,7 +281,7 @@ class Battle # on the given side of battle. def pbNumPositions(side, idxTrainer) ret = 0 - for i in 0...pbSideSize(side) + pbSideSize(side).times do |i| t = pbGetOwnerIndexFromBattlerIndex((i * 2) + side) next if t != idxTrainer ret += 1 @@ -618,7 +618,7 @@ class Battle PBEffects::SkyDrop, PBEffects::TrappingUser] allBattlers.each do |b| - for i in effectsToSwap + effectsToSwap.each do |i| next if b.effects[i] != idxA && b.effects[i] != idxB b.effects[i] = (b.effects[i] == idxA) ? idxB : idxA end diff --git a/Data/Scripts/011_Battle/001_Battle/002_Battle_StartAndEnd.rb b/Data/Scripts/011_Battle/001_Battle/002_Battle_StartAndEnd.rb index c5c73c51c..6edd32014 100644 --- a/Data/Scripts/011_Battle/001_Battle/002_Battle_StartAndEnd.rb +++ b/Data/Scripts/011_Battle/001_Battle/002_Battle_StartAndEnd.rb @@ -43,12 +43,12 @@ class Battle # side if necessary loop do needsChanging = false - for side in 0...2 # Each side in turn + 2.times do |side| # Each side in turn next if side == 1 && wildBattle? # Wild side's size already checked above sideCounts = (side == 0) ? side1counts : side2counts requireds = [] # Find out how many Pokémon each trainer on side needs to have - for i in 0...@sideSizes[side] + @sideSizes[side].times do |i| idxTrainer = pbGetOwnerIndexFromBattlerIndex((i * 2) + side) requireds[idxTrainer] = 0 if requireds[idxTrainer].nil? requireds[idxTrainer] += 1 @@ -90,7 +90,7 @@ class Battle if newSize == 0 raise _INTL("Couldn't lower either side's size any further, battle isn't possible") end - for side in 0...2 + 2.times do |side| next if side == 1 && wildBattle? # Wild Pokémon's side size is fixed next if @sideSizes[side] == 1 || newSize > @sideSizes[side] @sideSizes[side] = newSize @@ -115,7 +115,7 @@ class Battle def pbSetUpSides ret = [[], []] - for side in 0...2 + 2.times do |side| # Set up wild Pokémon if side == 1 && wildBattle? pbParty(1).each_with_index do |pkmn, idxPkmn| @@ -131,7 +131,7 @@ class Battle trainer = (side == 0) ? @player : @opponent requireds = [] # Find out how many Pokémon each trainer on side needs to have - for i in 0...@sideSizes[side] + @sideSizes[side].times do |i| idxTrainer = pbGetOwnerIndexFromBattlerIndex((i * 2) + side) requireds[idxTrainer] = 0 if requireds[idxTrainer].nil? requireds[idxTrainer] += 1 @@ -184,7 +184,7 @@ class Battle end end # Send out Pokémon (opposing trainers first) - for side in [1, 0] + [1, 0].each do |side| next if side == 1 && wildBattle? msg = "" toSendOut = [] @@ -496,7 +496,7 @@ class Battle def pbDecisionOnTime counts = [0, 0] hpTotals = [0, 0] - for side in 0...2 + 2.times do |side| pbParty(side).each do |pkmn| next if !pkmn || !pkmn.able? counts[side] += 1 @@ -514,7 +514,7 @@ class Battle def pbDecisionOnTime2 counts = [0, 0] hpTotals = [0, 0] - for side in 0...2 + 2.times do |side| pbParty(side).each do |pkmn| next if !pkmn || !pkmn.able? counts[side] += 1 diff --git a/Data/Scripts/011_Battle/001_Battle/004_Battle_ActionAttacksPriority.rb b/Data/Scripts/011_Battle/001_Battle/004_Battle_ActionAttacksPriority.rb index 132555638..7967b5abe 100644 --- a/Data/Scripts/011_Battle/001_Battle/004_Battle_ActionAttacksPriority.rb +++ b/Data/Scripts/011_Battle/001_Battle/004_Battle_ActionAttacksPriority.rb @@ -144,7 +144,7 @@ class Battle randomOrder[i], randomOrder[r] = randomOrder[r], randomOrder[i] end @priority.clear - for i in 0..maxBattlerIndex + (0..maxBattlerIndex).each do |i| b = @battlers[i] next if !b # [battler, speed, sub-priority, priority, tie-breaker order] diff --git a/Data/Scripts/011_Battle/001_Battle/009_Battle_CommandPhase.rb b/Data/Scripts/011_Battle/001_Battle/009_Battle_CommandPhase.rb index 7ea985396..fbbd876bb 100644 --- a/Data/Scripts/011_Battle/001_Battle/009_Battle_CommandPhase.rb +++ b/Data/Scripts/011_Battle/001_Battle/009_Battle_CommandPhase.rb @@ -179,7 +179,7 @@ class Battle pbClearChoice(i) if pbCanShowCommands?(i) end # Reset choices to perform Mega Evolution if it wasn't done somehow - for side in 0...2 + 2.times do |side| @megaEvolution[side].each_with_index do |megaEvo, i| @megaEvolution[side][i] = -1 if megaEvo >= 0 end diff --git a/Data/Scripts/011_Battle/001_Battle/011_Battle_EndOfRoundPhase.rb b/Data/Scripts/011_Battle/001_Battle/011_Battle_EndOfRoundPhase.rb index af24e9abe..e36b8db0e 100644 --- a/Data/Scripts/011_Battle/001_Battle/011_Battle_EndOfRoundPhase.rb +++ b/Data/Scripts/011_Battle/001_Battle/011_Battle_EndOfRoundPhase.rb @@ -148,7 +148,7 @@ class Battle # is not generalised to larger side sizes. if !singleBattle? swaps = [] # Each element is an array of two battler indices to swap - for side in 0...2 + 2.times do |side| next if pbSideSize(side) == 1 # Only battlers on sides of size 2+ need to move # Check if any battler on this side is near any battler on the other side anyNear = false @@ -256,7 +256,7 @@ class Battle pbDisplay(_INTL("{1}'s wish came true!", wishMaker)) end # Sea of Fire damage (Fire Pledge + Grass Pledge combination) - for side in 0...2 + 2.times do |side| next if sides[side].effects[PBEffects::SeaOfFire] == 0 @battle.pbCommonAnimation("SeaOfFire") if side == 0 @battle.pbCommonAnimation("SeaOfFireOpp") if side == 1 @@ -516,7 +516,7 @@ class Battle pbGainExp return end - for side in 0...2 + 2.times do |side| # Reflect pbEORCountDownSideEffect(side, PBEffects::Reflect, _INTL("{1}'s Reflect wore off!", @battlers[side].pbTeam)) @@ -664,7 +664,7 @@ class Battle b.lastFoeAttacker.clear end # Reset/count down side-specific effects (no messages) - for side in 0...2 + 2.times do |side| @sides[side].effects[PBEffects::CraftyShield] = false if !@sides[side].effects[PBEffects::EchoedVoiceUsed] @sides[side].effects[PBEffects::EchoedVoiceCounter] = 0 diff --git a/Data/Scripts/011_Battle/002_Battler/007_Battler_UseMove.rb b/Data/Scripts/011_Battle/002_Battler/007_Battler_UseMove.rb index e7c3fe920..874b853dc 100644 --- a/Data/Scripts/011_Battle/002_Battler/007_Battler_UseMove.rb +++ b/Data/Scripts/011_Battle/002_Battler/007_Battler_UseMove.rb @@ -414,7 +414,7 @@ class Battle::Battler numHits = move.pbNumHits(user, targets) # Process each hit in turn realNumHits = 0 - for i in 0...numHits + numHits.times do |i| break if magicCoater >= 0 || magicBouncer >= 0 success = pbProcessMoveHit(move, user, targets, i, skipAccuracyCheck) if !success diff --git a/Data/Scripts/011_Battle/003_Move/002_Move_Usage.rb b/Data/Scripts/011_Battle/003_Move/002_Move_Usage.rb index 93b949086..082d96c7a 100644 --- a/Data/Scripts/011_Battle/003_Move/002_Move_Usage.rb +++ b/Data/Scripts/011_Battle/003_Move/002_Move_Usage.rb @@ -241,7 +241,7 @@ class Battle::Move def pbAnimateHitAndHPLost(user, targets) # Animate allies first, then foes animArray = [] - for side in 0...2 # side here means "allies first, then foes" + 2.times do |side| # side here means "allies first, then foes" targets.each do |b| next if b.damageState.unaffected || b.damageState.hpLost == 0 next if (side == 0 && b.opposes?(user)) || (side == 1 && !b.opposes?(user)) diff --git a/Data/Scripts/011_Battle/003_Move/004_Move_BaseEffects.rb b/Data/Scripts/011_Battle/003_Move/004_Move_BaseEffects.rb index 25bc4f912..9eb62b605 100644 --- a/Data/Scripts/011_Battle/003_Move/004_Move_BaseEffects.rb +++ b/Data/Scripts/011_Battle/003_Move/004_Move_BaseEffects.rb @@ -113,7 +113,7 @@ class Battle::Move::MultiStatUpMove < Battle::Move def pbMoveFailed?(user, targets) return false if damagingMove? failed = true - for i in 0...@statUp.length / 2 + (@statUp.length / 2).times do |i| next if !user.pbCanRaiseStatStage?(@statUp[i * 2], user, self) failed = false break @@ -128,7 +128,7 @@ class Battle::Move::MultiStatUpMove < Battle::Move def pbEffectGeneral(user) return if damagingMove? showAnim = true - for i in 0...@statUp.length / 2 + (@statUp.length / 2).times do |i| next if !user.pbCanRaiseStatStage?(@statUp[i * 2], user, self) if user.pbRaiseStatStage(@statUp[i * 2], @statUp[(i * 2) + 1], user, showAnim) showAnim = false @@ -138,7 +138,7 @@ class Battle::Move::MultiStatUpMove < Battle::Move def pbAdditionalEffect(user, target) showAnim = true - for i in 0...@statUp.length / 2 + (@statUp.length / 2).times do |i| next if !user.pbCanRaiseStatStage?(@statUp[i * 2], user, self) if user.pbRaiseStatStage(@statUp[i * 2], @statUp[(i * 2) + 1], user, showAnim) showAnim = false @@ -154,7 +154,7 @@ class Battle::Move::StatDownMove < Battle::Move def pbEffectWhenDealingDamage(user, target) return if @battle.pbAllFainted?(target.idxOwnSide) showAnim = true - for i in 0...@statDown.length / 2 + (@statDown.length / 2).times do |i| next if !user.pbCanLowerStatStage?(@statDown[i * 2], user, self) if user.pbLowerStatStage(@statDown[i * 2], @statDown[(i * 2) + 1], user, showAnim) showAnim = false @@ -195,7 +195,7 @@ class Battle::Move::TargetMultiStatDownMove < Battle::Move def pbFailsAgainstTarget?(user, target, show_message) return false if damagingMove? failed = true - for i in 0...@statDown.length / 2 + (@statDown.length / 2).times do |i| next if !target.pbCanLowerStatStage?(@statDown[i * 2], user, self) failed = false break @@ -205,14 +205,14 @@ class Battle::Move::TargetMultiStatDownMove < Battle::Move # is shown here, I know. canLower = false if target.hasActiveAbility?(:CONTRARY) && !@battle.moldBreaker - for i in 0...@statDown.length / 2 + (@statDown.length / 2).times do |i| next if target.statStageAtMax?(@statDown[i * 2]) canLower = true break end @battle.pbDisplay(_INTL("{1}'s stats won't go any higher!", user.pbThis)) if !canLower && show_message else - for i in 0...@statDown.length / 2 + (@statDown.length / 2).times do |i| next if target.statStageAtMin?(@statDown[i * 2]) canLower = true break @@ -230,7 +230,7 @@ class Battle::Move::TargetMultiStatDownMove < Battle::Move def pbCheckForMirrorArmor(user, target) if target.hasActiveAbility?(:MIRRORARMOR) && user.index != target.index failed = true - for i in 0...@statDown.length / 2 + (@statDown.length / 2).times do |i| next if target.statStageAtMin?(@statDown[i * 2]) next if !user.pbCanLowerStatStage?(@statDown[i * 2], target, self, false, false, true) failed = false @@ -253,7 +253,7 @@ class Battle::Move::TargetMultiStatDownMove < Battle::Move return if !pbCheckForMirrorArmor(user, target) showAnim = true showMirrorArmorSplash = true - for i in 0...@statDown.length / 2 + (@statDown.length / 2).times do |i| next if !target.pbCanLowerStatStage?(@statDown[i * 2], user, self) if target.pbLowerStatStage(@statDown[i * 2], @statDown[(i * 2) + 1], user, showAnim, false, (showMirrorArmorSplash) ? 1 : 3) diff --git a/Data/Scripts/011_Battle/003_Move/005_MoveEffects_Misc.rb b/Data/Scripts/011_Battle/003_Move/005_MoveEffects_Misc.rb index b6b8733e6..828b251ae 100644 --- a/Data/Scripts/011_Battle/003_Move/005_MoveEffects_Misc.rb +++ b/Data/Scripts/011_Battle/003_Move/005_MoveEffects_Misc.rb @@ -482,7 +482,7 @@ class Battle::Move::SwapSideEffects < Battle::Move def pbMoveFailed?(user, targets) has_effect = false - for side in 0...2 + 2.times do |side| effects = @battle.sides[side].effects @number_effects.each do |e| next if effects[e] == 0 diff --git a/Data/Scripts/011_Battle/003_Move/006_MoveEffects_BattlerStats.rb b/Data/Scripts/011_Battle/003_Move/006_MoveEffects_BattlerStats.rb index 03c5df771..e9701371d 100644 --- a/Data/Scripts/011_Battle/003_Move/006_MoveEffects_BattlerStats.rb +++ b/Data/Scripts/011_Battle/003_Move/006_MoveEffects_BattlerStats.rb @@ -417,13 +417,13 @@ class Battle::Move::LowerUserDefSpDef1RaiseUserAtkSpAtkSpd2 < Battle::Move def pbMoveFailed?(user, targets) failed = true - for i in 0...@statUp.length / 2 + (@statUp.length / 2).times do |i| if user.pbCanRaiseStatStage?(@statUp[i * 2], user, self) failed = false break end end - for i in 0...@statDown.length / 2 + (@statDown.length / 2).times do |i| if user.pbCanLowerStatStage?(@statDown[i * 2], user, self) failed = false break @@ -438,14 +438,14 @@ class Battle::Move::LowerUserDefSpDef1RaiseUserAtkSpAtkSpd2 < Battle::Move def pbEffectGeneral(user) showAnim = true - for i in 0...@statDown.length / 2 + (@statDown.length / 2).times do |i| next if !user.pbCanLowerStatStage?(@statDown[i * 2], user, self) if user.pbLowerStatStage(@statDown[i * 2], @statDown[(i * 2) + 1], user, showAnim) showAnim = false end end showAnim = true - for i in 0...@statUp.length / 2 + (@statUp.length / 2).times do |i| next if !user.pbCanRaiseStatStage?(@statUp[i * 2], user, self) if user.pbRaiseStatStage(@statUp[i * 2], @statUp[(i * 2) + 1], user, showAnim) showAnim = false @@ -1359,7 +1359,7 @@ class Battle::Move::LowerPoisonedTargetAtkSpAtkSpd1 < Battle::Move def pbCheckForMirrorArmor(user, target) if target.hasActiveAbility?(:MIRRORARMOR) && user.index != target.index failed = true - for i in 0...@statDown.length / 2 + (@statDown.length / 2).times do |i| next if target.statStageAtMin?(@statDown[i * 2]) next if !user.pbCanLowerStatStage?(@statDown[i * 2], target, self, false, false, true) failed = false @@ -1383,7 +1383,7 @@ class Battle::Move::LowerPoisonedTargetAtkSpAtkSpd1 < Battle::Move return if !pbCheckForMirrorArmor(user, target) showAnim = true showMirrorArmorSplash = true - for i in 0...@statDown.length / 2 + (@statDown.length / 2).times do |i| next if !target.pbCanLowerStatStage?(@statDown[i * 2], user, self) if target.pbLowerStatStage(@statDown[i * 2], @statDown[(i * 2) + 1], user, showAnim, false, (showMirrorArmorSplash) ? 1 : 3) diff --git a/Data/Scripts/011_Battle/004_Scene/001_Battle_Scene.rb b/Data/Scripts/011_Battle/004_Scene/001_Battle_Scene.rb index 34b726007..0bc791477 100644 --- a/Data/Scripts/011_Battle/004_Scene/001_Battle_Scene.rb +++ b/Data/Scripts/011_Battle/004_Scene/001_Battle_Scene.rb @@ -381,7 +381,7 @@ class Battle::Scene #============================================================================= def pbSelectBattler(idxBattler, selectMode = 1) numWindows = @battle.sideSizes.max * 2 - for i in 0...numWindows + numWindows.times do |i| sel = (idxBattler.is_a?(Array)) ? !idxBattler[i].nil? : i == idxBattler selVal = (sel) ? selectMode : 0 @sprites["dataBox_#{i}"].selected = selVal if @sprites["dataBox_#{i}"] diff --git a/Data/Scripts/011_Battle/004_Scene/002_Scene_Initialize.rb b/Data/Scripts/011_Battle/004_Scene/002_Scene_Initialize.rb index 4b629e207..58bde1144 100644 --- a/Data/Scripts/011_Battle/004_Scene/002_Scene_Initialize.rb +++ b/Data/Scripts/011_Battle/004_Scene/002_Scene_Initialize.rb @@ -48,13 +48,13 @@ class Battle::Scene @sprites["targetWindow"] = TargetMenu.new(@viewport, 200, @battle.sideSizes) pbShowWindow(MESSAGE_BOX) # The party lineup graphics (bar and balls) for both sides - for side in 0...2 + 2.times do |side| partyBar = pbAddSprite("partyBar_#{side}", 0, 0, "Graphics/Pictures/Battle/overlay_lineup", @viewport) partyBar.z = 120 partyBar.mirror = true if side == 0 # Player's lineup bar only partyBar.visible = false - for i in 0...NUM_BALLS + NUM_BALLS.times do |i| ball = pbAddSprite("partyBall_#{side}_#{i}", 0, 0, nil, @viewport) ball.z = 121 ball.visible = false @@ -137,7 +137,7 @@ class Battle::Scene bg = pbAddSprite("battle_bg2", -Graphics.width, 0, battleBG, @viewport) bg.z = 0 bg.mirror = true - for side in 0...2 + 2.times do |side| baseX, baseY = Battle::Scene.pbBattlerPosition(side) base = pbAddSprite("base_#{side}", baseX, baseY, (side == 0) ? playerBase : enemyBase, @viewport) diff --git a/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb b/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb index 171081d8d..6a6658ce5 100644 --- a/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb +++ b/Data/Scripts/011_Battle/004_Scene/004_Scene_PlayAnimations.rb @@ -27,7 +27,7 @@ class Battle::Scene # data box(es), return the wild Pokémon's sprite(s) to normal colour, show # shiny animation(s) # Set up data box animation - for i in 0...@battle.sideSizes[1] + @battle.sideSizes[1].times do |i| idxBattler = (2 * i) + 1 next if !@battle.battlers[idxBattler] dataBoxAnim = Animation::DataBoxAppear.new(@sprites, @viewport, idxBattler) @@ -42,7 +42,7 @@ class Battle::Scene end # Show shiny animation for wild Pokémon if @battle.showAnims - for i in 0...@battle.sideSizes[1] + @battle.sideSizes[1].times do |i| idxBattler = (2 * i) + 1 next if !@battle.battlers[idxBattler] || !@battle.battlers[idxBattler].shiny? if Settings::SUPER_SHINY && @battle.battlers[idxBattler].super_shiny? @@ -400,7 +400,7 @@ class Battle::Scene # Yield to other code, i.e. playing an animation yield # Restore shadow visibility - for i in 0...@battle.battlers.length + @battle.battlers.length.times do |i| shadow = @sprites["shadow_#{i}"] shadow.visible = shadows[i] if shadow end diff --git a/Data/Scripts/011_Battle/004_Scene/005_Battle_Scene_Menus.rb b/Data/Scripts/011_Battle/004_Scene/005_Battle_Scene_Menus.rb index 554405c59..ea506053e 100644 --- a/Data/Scripts/011_Battle/004_Scene/005_Battle_Scene_Menus.rb +++ b/Data/Scripts/011_Battle/004_Scene/005_Battle_Scene_Menus.rb @@ -38,21 +38,21 @@ class Battle::Scene::MenuBase def z=(value) @z = value - for i in @sprites + @sprites.each do |i| i[1].z = value if !i[1].disposed? end end def visible=(value) @visible = value - for i in @sprites + @sprites.each do |i| i[1].visible = (value && @visibility[i[0]]) if !i[1].disposed? end end def color=(value) @color = value - for i in @sprites + @sprites.each do |i| i[1].color = value if !i[1].disposed? end end @@ -174,7 +174,7 @@ class Battle::Scene::CommandMenu < Battle::Scene::MenuBase @msgBox.text = value[0] return if USE_GRAPHICS commands = [] - for i in 1..4 + (1..4).each do |i| commands.push(value[i]) if value[i] && value[i] != nil end @cmdWindow.commands = commands @@ -182,8 +182,7 @@ class Battle::Scene::CommandMenu < Battle::Scene::MenuBase def refreshButtons return if !USE_GRAPHICS - for i in 0...@buttons.length - button = @buttons[i] + @buttons.each_with_index do |button, i| button.src_rect.x = (i == @index) ? @buttonBitmap.width / 2 : 0 button.src_rect.y = MODES[@mode][i] * BUTTON_HEIGHT button.z = self.z + ((i == @index) ? 3 : 2) @@ -343,7 +342,7 @@ class Battle::Scene::FightMenu < Battle::Scene::MenuBase if !USE_GRAPHICS # Fill in command window commands = [] - for i in 0...[4, moves.length].max + [4, moves.length].max.times do |i| commands.push((moves[i]) ? moves[i].name : "-") end @cmdWindow.commands = commands diff --git a/Data/Scripts/011_Battle/004_Scene/006_Battle_Scene_Objects.rb b/Data/Scripts/011_Battle/004_Scene/006_Battle_Scene_Objects.rb index ace6ba022..8ea0fc87e 100644 --- a/Data/Scripts/011_Battle/004_Scene/006_Battle_Scene_Objects.rb +++ b/Data/Scripts/011_Battle/004_Scene/006_Battle_Scene_Objects.rb @@ -133,14 +133,14 @@ class Battle::Scene::PokemonDataBox < SpriteWrapper def opacity=(value) super - for i in @sprites + @sprites.each do |i| i[1].opacity = value if !i[1].disposed? end end def visible=(value) super - for i in @sprites + @sprites.each do |i| i[1].visible = value if !i[1].disposed? end @expBar.visible = (value && @showExp) @@ -148,7 +148,7 @@ class Battle::Scene::PokemonDataBox < SpriteWrapper def color=(value) super - for i in @sprites + @sprites.each do |i| i[1].color = value if !i[1].disposed? end end @@ -335,7 +335,7 @@ class Battle::Scene::PokemonDataBox < SpriteWrapper @expFlash = Graphics.frame_rate / 5 pbSEPlay("Pkmn exp full") self.flash(Color.new(64, 200, 248, 192), @expFlash) - for i in @sprites + @sprites.each do |i| i[1].flash(Color.new(64, 200, 248, 192), @expFlash) if !i[1].disposed? end else diff --git a/Data/Scripts/011_Battle/004_Scene/007_Battle_Scene_BaseAnimation.rb b/Data/Scripts/011_Battle/004_Scene/007_Battle_Scene_BaseAnimation.rb index fef655c7a..587b2742f 100644 --- a/Data/Scripts/011_Battle/004_Scene/007_Battle_Scene_BaseAnimation.rb +++ b/Data/Scripts/011_Battle/004_Scene/007_Battle_Scene_BaseAnimation.rb @@ -169,7 +169,7 @@ module Battle::Scene::Animation::BallAnimationMixin a = (2 * startY) - (4 * midY) + (2 * endY) b = (4 * midY) - (3 * startY) - endY c = startY - for i in 1..duration + (1..duration).each do |i| t = i.to_f / duration # t ranges from 0 to 1 x = startX + ((endX - startX) * t) # Linear in t y = (a * (t**2)) + (b * t) + c # Quadratic in t @@ -188,7 +188,7 @@ module Battle::Scene::Animation::BallAnimationMixin end if numFrames > 1 curFrame = 0 - for i in 1..duration + (1..duration).each do |i| thisFrame = numFrames * numTumbles * i / duration if thisFrame > curFrame curFrame = thisFrame diff --git a/Data/Scripts/011_Battle/004_Scene/008_Battle_Scene_Animations.rb b/Data/Scripts/011_Battle/004_Scene/008_Battle_Scene_Animations.rb index b079d7586..98fc2e2d2 100644 --- a/Data/Scripts/011_Battle/004_Scene/008_Battle_Scene_Animations.rb +++ b/Data/Scripts/011_Battle/004_Scene/008_Battle_Scene_Animations.rb @@ -33,7 +33,7 @@ class Battle::Scene::Animation::Intro < Battle::Scene::Animation end end # Shadows - for i in 0...@battle.battlers.length + @battle.battlers.length.times do |i| makeSlideSprite("shadow_#{i}", (i.even?) ? 1 : -1, appearTime, PictureOrigin::Center) end # Fading blackness over whole screen @@ -70,7 +70,7 @@ class Battle::Scene::Animation::Intro2 < Battle::Scene::Animation end def createProcesses - for i in 0...@sideSize + @sideSize.times do |i| idxBattler = (2 * i) + 1 next if !@sprites["pokemon_#{idxBattler}"] battler = addSprite(@sprites["pokemon_#{idxBattler}"], PictureOrigin::Bottom) @@ -117,7 +117,7 @@ class Battle::Scene::Animation::LineupAppear < Battle::Scene::Animation bar.y = barY bar.opacity = 255 bar.visible = false - for i in 0...Battle::Scene::NUM_BALLS + Battle::Scene::NUM_BALLS.times do |i| ball = sprites["partyBall_#{@side}_#{i}"] ball.x = ballX ball.y = ballY @@ -154,7 +154,7 @@ class Battle::Scene::Animation::LineupAppear < Battle::Scene::Animation bar.setDelta(0, dir * Graphics.width / 2, 0) bar.moveDelta(0, 8, -dir * Graphics.width / 2, 0) delay = bar.totalDuration - for i in 0...Battle::Scene::NUM_BALLS + Battle::Scene::NUM_BALLS.times do |i| createBall(i, (@fullAnim) ? delay + (i * 2) : 0, dir) end end @@ -339,7 +339,7 @@ class Battle::Scene::Animation::PlayerFade < Battle::Scene::Animation partyBar.setVisible(delay + 12, false) partyBar.setOpacity(delay + 12, 255) end - for i in 0...Battle::Scene::NUM_BALLS + Battle::Scene::NUM_BALLS.times do |i| next if !@sprites["partyBall_0_#{i}"] || !@sprites["partyBall_0_#{i}"].visible partyBall = addSprite(@sprites["partyBall_0_#{i}"]) partyBall.moveDelta(delay + (2 * i), 16, -Graphics.width, 0) if @fullAnim @@ -384,7 +384,7 @@ class Battle::Scene::Animation::TrainerFade < Battle::Scene::Animation partyBar.setVisible(delay + 12, false) partyBar.setOpacity(delay + 12, 255) end - for i in 0...Battle::Scene::NUM_BALLS + Battle::Scene::NUM_BALLS.times do |i| next if !@sprites["partyBall_1_#{i}"] || !@sprites["partyBall_1_#{i}"].visible partyBall = addSprite(@sprites["partyBall_1_#{i}"]) partyBall.moveDelta(delay + (2 * i), 16, Graphics.width, 0) if @fullAnim @@ -777,7 +777,7 @@ class Battle::Scene::Animation::PokeballThrowCapture < Battle::Scene::Animation delay = ball.totalDuration + 3 end # Poké Ball drops to the ground - for i in 0...4 + 4.times do |i| t = [4, 4, 3, 2][i] # Time taken to rise or fall for each bounce d = [1, 2, 4, 8][i] # Fraction of the starting height each bounce rises to delay -= t if i == 0 @@ -793,7 +793,7 @@ class Battle::Scene::Animation::PokeballThrowCapture < Battle::Scene::Animation battler.setXY(ball.totalDuration, ballEndX, ballGroundY) # Poké Ball shakes delay = ball.totalDuration + 12 - for i in 0...[@numShakes, 3].min + [@numShakes, 3].min.times do |i| ball.setSE(delay, "Battle ball shake") ball.moveXY(delay, 2, ballEndX - (2 * (4 - i)), ballGroundY) ball.moveAngle(delay, 2, 5 * (4 - i)) # positive means counterclockwise diff --git a/Data/Scripts/011_Battle/006_Other battle code/005_Battle_CatchAndStoreMixin.rb b/Data/Scripts/011_Battle/006_Other battle code/005_Battle_CatchAndStoreMixin.rb index be79a610e..171d181e0 100644 --- a/Data/Scripts/011_Battle/006_Other battle code/005_Battle_CatchAndStoreMixin.rb +++ b/Data/Scripts/011_Battle/006_Other battle code/005_Battle_CatchAndStoreMixin.rb @@ -193,7 +193,7 @@ module Battle::CatchAndStoreMixin end # Calculate the number of shakes numShakes = 0 - for i in 0...4 + 4.times do |i| break if numShakes < i numShakes += 1 if pbRandom(65536) < y end diff --git a/Data/Scripts/011_Battle/006_Other battle code/007_BattleAnimationPlayer.rb b/Data/Scripts/011_Battle/006_Other battle code/007_BattleAnimationPlayer.rb index 333321c3a..e7485d0a2 100644 --- a/Data/Scripts/011_Battle/006_Other battle code/007_BattleAnimationPlayer.rb +++ b/Data/Scripts/011_Battle/006_Other battle code/007_BattleAnimationPlayer.rb @@ -123,10 +123,10 @@ def pbConvertRPGAnimation(animation) pbAnim.position = animation.position yOffset = -64 if animation.position == 0 yOffset = 64 if animation.position == 2 - for i in 0...animation.frames.length + animation.frames.length.times do |i| frame = pbAnim.addFrame animFrame = animation.frames[i] - for j in 0...animFrame.cell_max + animFrame.cell_max.times do |j| data = animFrame.cell_data if data[j, 0] == -1 frame.push(nil) @@ -152,8 +152,7 @@ def pbConvertRPGAnimation(animation) frame.push(cel) end end - for i in 0...animation.timings.length - timing = animation.timings[i] + animation.timings.each do |timing| newTiming = PBAnimTiming.new newTiming.frame = timing.frame newTiming.name = timing.se.name @@ -193,18 +192,18 @@ class RPG::Animation def addAnimation(otherAnim, frame, x, y) # frame is zero-based if frame + otherAnim.frames.length >= self.frames.length totalframes = frame + otherAnim.frames.length + 1 - for i in self.frames.length...totalframes + (totalframes - self.frames.length).times do self.frames.push(RPG::Animation::Frame.new) end end self.frame_max = self.frames.length - for i in 0...otherAnim.frame_max + otherAnim.frame_max.times do |i| thisframe = self.frames[frame + i] otherframe = otherAnim.frames[i] cellStart = thisframe.cell_max thisframe.cell_max += otherframe.cell_max thisframe.cell_data.resize(thisframe.cell_max, 8) - for j in 0...otherframe.cell_max + otherframe.cell_max.times do |j| thisframe.cell_data[cellStart + j, 0] = otherframe.cell_data[j, 0] thisframe.cell_data[cellStart + j, 1] = otherframe.cell_data[j, 1] + x thisframe.cell_data[cellStart + j, 2] = otherframe.cell_data[j, 2] + y @@ -215,9 +214,8 @@ class RPG::Animation thisframe.cell_data[cellStart + j, 7] = otherframe.cell_data[j, 7] end end - for i in 0...otherAnim.timings.length + otherAnim.timings.each do |othertiming| timing = RPG::Animation::Timing.new - othertiming = otherAnim.timings[i] timing.frame = frame + othertiming.frame timing.se = RPG::AudioFile.new(othertiming.se.name.clone, othertiming.se.volume, @@ -398,13 +396,9 @@ class PBAnimations < Array idxStart = @array.length idxEnd = len if idxStart > idxEnd - for i in idxEnd...idxStart - @array.pop - end + (idxStart - idxEnd).times { @array.pop } else - for i in idxStart...idxEnd - @array.push(PBAnimation.new) - end + (idxEnd - idxStart).times { @array.push(PBAnimation.new) } end self.selected = len if self.selected >= len end @@ -494,7 +488,7 @@ class PBAnimation < Array end def playTiming(frame, bgGraphic, bgColor, foGraphic, foColor, oldbg = [], oldfo = [], user = nil) - for i in @timing + @timing.each do |i| next if i.frame != frame case i.timingType when 0 # Play SE @@ -562,7 +556,7 @@ class PBAnimation < Array end end end - for i in @timing + @timing.each do |i| case i.timingType when 2 next if !i.duration || i.duration <= 0 @@ -729,7 +723,7 @@ class PBAnimationPlayerX @animsprites = [] @animsprites[0] = @usersprite @animsprites[1] = @targetsprite - for i in 2...MAX_SPRITES + (2...MAX_SPRITES).each do |i| @animsprites[i] = Sprite.new(@viewport) @animsprites[i].bitmap = nil @animsprites[i].visible = false @@ -768,7 +762,7 @@ class PBAnimationPlayerX def dispose @animbitmap.dispose if @animbitmap - for i in 2...MAX_SPRITES + (2...MAX_SPRITES).each do |i| @animsprites[i].dispose if @animsprites[i] end @bgGraphic.dispose @@ -807,7 +801,7 @@ class PBAnimationPlayerX if !@animbitmap || @animbitmap.disposed? @animbitmap = AnimatedBitmap.new("Graphics/Animations/" + @animation.graphic, @animation.hue).deanimate - for i in 0...MAX_SPRITES + MAX_SPRITES.times do |i| @animsprites[i].bitmap = @animbitmap if @animsprites[i] end end @@ -821,11 +815,11 @@ class PBAnimationPlayerX if @framesPerTick == 1 || (@frame % @framesPerTick) == 0 thisframe = @animation[animFrame] # Make all cel sprites invisible - for i in 0...MAX_SPRITES + MAX_SPRITES.times do |i| @animsprites[i].visible = false if @animsprites[i] end # Set each cel sprite acoordingly - for i in 0...thisframe.length + thisframe.length.times do |i| cel = thisframe[i] next if !cel sprite = @animsprites[i] diff --git a/Data/Scripts/011_Battle/007_Other battle types/003_BattlePalaceBattle.rb b/Data/Scripts/011_Battle/007_Other battle types/003_BattlePalaceBattle.rb index 3920c3c03..20ca27378 100644 --- a/Data/Scripts/011_Battle/007_Other battle types/003_BattlePalaceBattle.rb +++ b/Data/Scripts/011_Battle/007_Other battle types/003_BattlePalaceBattle.rb @@ -123,7 +123,7 @@ class BattlePalaceBattle < Battle category = 2 end moves = [] - for i in 0...this_battler.moves.length + this_battler.moves.length.times do |i| next if !pbCanChooseMovePartial?(idxBattler, i) next if pbMoveCategory(this_battler.moves[i]) != category moves[moves.length] = i diff --git a/Data/Scripts/011_Battle/007_Other battle types/004_BattleArenaBattle.rb b/Data/Scripts/011_Battle/007_Other battle types/004_BattleArenaBattle.rb index f37ce8c53..586834b65 100644 --- a/Data/Scripts/011_Battle/007_Other battle types/004_BattleArenaBattle.rb +++ b/Data/Scripts/011_Battle/007_Other battle types/004_BattleArenaBattle.rb @@ -64,7 +64,7 @@ class BattleArenaBattle < Battle return if !favorDraws && @decision > 0 pbJudge return if @decision > 0 - for side in 0...2 + 2.times do |side| next if !@battlers[side].fainted? next if @partyindexes[side] + 1 >= self.pbParty(side).length @partyindexes[side] += 1 @@ -77,7 +77,7 @@ class BattleArenaBattle < Battle def pbOnAllBattlersEnteringBattle @battlersChanged = true - for side in 0...2 + 2.times do |side| @mind[side] = 0 @skill[side] = 0 @starthp[side] = battlers[side].hp @@ -88,7 +88,7 @@ class BattleArenaBattle < Battle def pbRecordBattlerAsActive(battler) @battlersChanged = true - for side in 0...2 + 2.times do |side| @mind[side] = 0 @skill[side] = 0 @starthp[side] = @battlers[side].hp @@ -122,7 +122,7 @@ class BattleArenaBattle < Battle return if @decision != 0 # Update mind rating (asserting that a move was chosen) # TODO: Actually done at Pokémon's turn - for side in 0...2 + 2.times do |side| if @choices[side][2] && @choices[side][0] == :UseMove @mind[side] += pbMindScore(@choices[side][2]) end @@ -133,7 +133,7 @@ class BattleArenaBattle < Battle super return if @decision != 0 # Update skill rating - for side in 0...2 + 2.times do |side| @skill[side] += self.successStates[side].skill end # PBDebug.log("[Mind: #{@mind.inspect}, Skill: #{@skill.inspect}]") @@ -234,7 +234,7 @@ class Battle::Scene def updateJudgment(window, phase, battler1, battler2, ratings1, ratings2) total1 = 0 total2 = 0 - for i in 0...phase + phase.times do |i| total1 += ratings1[i] total2 += ratings2[i] end @@ -253,7 +253,7 @@ class Battle::Scene ] pbDrawTextPositions(window.contents, textpos) images = [] - for i in 0...phase + phase.times do |i| y = [48, 80, 112][i] x = (ratings1[i] == ratings2[i]) ? 64 : ((ratings1[i] > ratings2[i]) ? 0 : 32) images.push(["Graphics/Pictures/judgment", 64 - 16, y, x, 0, 32, 32]) @@ -287,7 +287,7 @@ class Battle::Scene infowindow.height - infowindow.borderY) infowindow.z = 99999 infowindow.visible = false - for i in 0..10 + 11.times do |i| pbGraphicsUpdate pbInputUpdate msgwindow.update @@ -296,7 +296,7 @@ class Battle::Scene end updateJudgment(infowindow, 0, battler1, battler2, ratings1, ratings2) infowindow.visible = true - for i in 0..10 + 11.times do |i| pbGraphicsUpdate pbInputUpdate msgwindow.update @@ -326,7 +326,7 @@ class Battle::Scene } total1 = 0 total2 = 0 - for i in 0...3 + 3.times do |i| total1 += ratings1[i] total2 += ratings2[i] end @@ -356,7 +356,7 @@ class Battle::Scene end infowindow.visible = false msgwindow.visible = false - for i in 0..10 + 11.times do |i| pbGraphicsUpdate pbInputUpdate msgwindow.update diff --git a/Data/Scripts/011_Battle/007_Other battle types/005_RecordedBattle.rb b/Data/Scripts/011_Battle/007_Other battle types/005_RecordedBattle.rb index a68a2a1df..3fdffb6d8 100644 --- a/Data/Scripts/011_Battle/007_Other battle types/005_RecordedBattle.rb +++ b/Data/Scripts/011_Battle/007_Other battle types/005_RecordedBattle.rb @@ -29,11 +29,11 @@ module RecordedBattleModule return nil if !trainer if trainer.is_a?(Array) ret = [] - for i in 0...trainer.length - if trainer[i].is_a?(Player) - ret.push([trainer[i].trainer_type, trainer[i].name.clone, trainer[i].id, trainer[i].badges.clone]) + trainer.each do |tr| + if tr.is_a?(Player) + ret.push([tr.trainer_type, tr.name.clone, tr.id, tr.badges.clone]) else # NPCTrainer - ret.push([trainer[i].trainer_type, trainer[i].name.clone, trainer[i].id]) + ret.push([tr.trainer_type, tr.name.clone, tr.id]) end end return ret @@ -202,7 +202,7 @@ module RecordedBattlePlaybackModule def pbCommandPhaseLoop(isPlayer) return if !isPlayer @roundindex += 1 - for i in 0...4 + 4.times do |i| next if @rounds[@roundindex][i].length == 0 pbClearChoice(i) case @rounds[@roundindex][i][0] diff --git a/Data/Scripts/012_Overworld/001_Overworld visuals/001_Overworld_Weather.rb b/Data/Scripts/012_Overworld/001_Overworld visuals/001_Overworld_Weather.rb index 82354e8f7..13c85bb50 100644 --- a/Data/Scripts/012_Overworld/001_Overworld visuals/001_Overworld_Weather.rb +++ b/Data/Scripts/012_Overworld/001_Overworld visuals/001_Overworld_Weather.rb @@ -120,7 +120,7 @@ module RPG return if @max == value @max = value.clamp(0, MAX_SPRITES) ensureSprites - for i in 0...MAX_SPRITES + MAX_SPRITES.times do |i| @sprites[i].visible = (i < @max) if @sprites[i] end end @@ -149,7 +149,7 @@ module RPG weather_data = GameData::Weather.get(new_type) bitmap_names = weather_data.graphics @weatherTypes[new_type] = [weather_data, [], []] - for i in 0...2 # 0=particles, 1=tiles + 2.times do |i| # 0=particles, 1=tiles next if !bitmap_names[i] bitmap_names[i].each do |name| bitmap = RPG::Cache.load_bitmap("Graphics/Weather/", name) @@ -160,7 +160,7 @@ module RPG def ensureSprites if @sprites.length < MAX_SPRITES && @weatherTypes[@type] && @weatherTypes[@type][1].length > 0 - for i in 0...MAX_SPRITES + MAX_SPRITES.times do |i| if !@sprites[i] sprite = Sprite.new(@origViewport) sprite.z = 1000 @@ -175,7 +175,7 @@ module RPG end if @fading && @new_sprites.length < MAX_SPRITES && @weatherTypes[@target_type] && @weatherTypes[@target_type][1].length > 0 - for i in 0...MAX_SPRITES + MAX_SPRITES.times do |i| if !@new_sprites[i] sprite = Sprite.new(@origViewport) sprite.z = 1000 @@ -192,7 +192,7 @@ module RPG def ensureTiles return if @tiles.length >= @tiles_wide * @tiles_tall - for i in 0...(@tiles_wide * @tiles_tall) + (@tiles_wide * @tiles_tall).times do |i| if !@tiles[i] sprite = Sprite.new(@origViewport) sprite.z = 1000 @@ -497,7 +497,7 @@ module RPG # Update weather particles (raindrops, snowflakes, etc.) if @weatherTypes[@type] && @weatherTypes[@type][1].length > 0 ensureSprites - for i in 0...MAX_SPRITES + MAX_SPRITES.times do |i| update_sprite_position(@sprites[i], i, false) end elsif @sprites.length > 0 @@ -507,7 +507,7 @@ module RPG # Update new weather particles (while fading in only) if @fading && @weatherTypes[@target_type] && @weatherTypes[@target_type][1].length > 0 ensureSprites - for i in 0...MAX_SPRITES + MAX_SPRITES.times do |i| update_sprite_position(@new_sprites[i], i, true) end elsif @new_sprites.length > 0 diff --git a/Data/Scripts/012_Overworld/001_Overworld visuals/002_Overworld_Overlays.rb b/Data/Scripts/012_Overworld/001_Overworld visuals/002_Overworld_Overlays.rb index 5f3002cea..68ba42f30 100644 --- a/Data/Scripts/012_Overworld/001_Overworld visuals/002_Overworld_Overlays.rb +++ b/Data/Scripts/012_Overworld/001_Overworld visuals/002_Overworld_Overlays.rb @@ -74,8 +74,8 @@ class DarknessSprite < SpriteWrapper cy = Graphics.height / 2 cradius = @radius numfades = 5 - for i in 1..numfades - for j in cx - cradius..cx + cradius + (1..numfades).each do |i| + (cx - cradius..cx + cradius).each do |j| diff2 = (cradius * cradius) - ((j - cx) * (j - cx)) diff = Math.sqrt(diff2) @darkness.fill_rect(j, cy - diff, 1, diff * 2, Color.new(0, 0, 0, 255.0 * (numfades - i) / numfades)) @@ -209,7 +209,7 @@ Events.onSpritesetCreate += proc { |_sender, e| spriteset = e[0] # Spriteset being created viewport = e[1] # Viewport used for tilemap and characters map = spriteset.map # Map associated with the spriteset (not necessarily the current map) - for i in map.events.keys + map.events.keys.each do |i| if map.events[i].name[/^outdoorlight\((\w+)\)$/i] filename = $~[1].to_s spriteset.addUserSprite(LightEffect_DayNight.new(map.events[i], viewport, map, filename)) diff --git a/Data/Scripts/012_Overworld/001_Overworld visuals/003_Overworld_MapTransitionAnims.rb b/Data/Scripts/012_Overworld/001_Overworld visuals/003_Overworld_MapTransitionAnims.rb index f1343023e..967ecf8cd 100644 --- a/Data/Scripts/012_Overworld/001_Overworld visuals/003_Overworld_MapTransitionAnims.rb +++ b/Data/Scripts/012_Overworld/001_Overworld visuals/003_Overworld_MapTransitionAnims.rb @@ -18,7 +18,7 @@ def pbCaveEntranceEx(exiting) x = 0 y = 0 # Calculate color of each band - for k in 0...totalBands + totalBands.times do |k| next if k >= totalBands * j / totalFrames inc = increment inc *= -1 if exiting @@ -28,7 +28,7 @@ def pbCaveEntranceEx(exiting) # Draw gray rectangles rectwidth = Graphics.width rectheight = Graphics.height - for i in 0...totalBands + totalBands.times do |i| currentGray = grays[i] sprite.bitmap.fill_rect(Rect.new(x, y, rectwidth, rectheight), Color.new(currentGray, currentGray, currentGray)) @@ -47,7 +47,7 @@ def pbCaveEntranceEx(exiting) pbToneChangeAll(Tone.new(-255, -255, -255), 0) end # Animate fade to white (if exiting) or black (if entering) - for j in 0...totalFrames + totalFrames.times do |j| if exiting sprite.color = Color.new(255, 255, 255, j * increment) else diff --git a/Data/Scripts/012_Overworld/001_Overworld.rb b/Data/Scripts/012_Overworld/001_Overworld.rb index 538375305..c6052e9f5 100644 --- a/Data/Scripts/012_Overworld/001_Overworld.rb +++ b/Data/Scripts/012_Overworld/001_Overworld.rb @@ -7,7 +7,7 @@ Events.onMapUpdate += proc { |_sender, _e| last = $PokemonGlobal.pokerusTime now = pbGetTimeNow if !last || last.year != now.year || last.month != now.month || last.day != now.day - for i in $player.pokemon_party + $player.pokemon_party.each do |i| i.lowerPokerusCount end $PokemonGlobal.pokerusTime = now @@ -18,7 +18,7 @@ Events.onMapUpdate += proc { |_sender, _e| # healed Pokémon has it. def pbPokerus? return false if $game_switches[Settings::SEEN_POKERUS_SWITCH] - for i in $player.party + $player.party.each do |i| return true if i.pokerusStage == 1 end return false @@ -78,7 +78,7 @@ Events.onStepTaken += proc { $PokemonGlobal.happinessSteps = 0 if !$PokemonGlobal.happinessSteps $PokemonGlobal.happinessSteps += 1 if $PokemonGlobal.happinessSteps >= 128 - for pkmn in $player.able_party + $player.able_party.each do |pkmn| pkmn.changeHappiness("walking") if rand(2) == 0 end $PokemonGlobal.happinessSteps = 0 @@ -91,7 +91,7 @@ Events.onStepTakenTransferPossible += proc { |_sender, e| next if handled[0] if $PokemonGlobal.stepcount % 4 == 0 && Settings::POISON_IN_FIELD flashed = false - for i in $player.able_party + $player.able_party.each do |i| if i.status == :POISON && !i.hasAbility?(:IMMUNITY) if !flashed pbFlash(Color.new(255, 0, 0, 128), 8) @@ -131,7 +131,7 @@ Events.onStepTakenFieldMovement += proc { |_sender, e| event = e[0] # Get the event affected by field movement thistile = $map_factory.getRealTilePos(event.map.map_id, event.x, event.y) map = $map_factory.getMap(thistile[0]) - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = map.data[thistile[1], thistile[2], i] next if tile_id == nil next if GameData::TerrainTag.try_get(map.terrain_tags[tile_id]).id != :SootGrass @@ -284,7 +284,7 @@ Events.onMapSceneChange += proc { |_sender, e| if mapChanged && map_metadata && map_metadata.announce_location nosignpost = false if $PokemonGlobal.mapTrail[1] - for i in 0...Settings::NO_SIGNPOSTS.length / 2 + (Settings::NO_SIGNPOSTS.length / 2).times do |i| nosignpost = true if Settings::NO_SIGNPOSTS[2 * i] == $PokemonGlobal.mapTrail[1] && Settings::NO_SIGNPOSTS[(2 * i) + 1] == $game_map.map_id nosignpost = true if Settings::NO_SIGNPOSTS[(2 * i) + 1] == $PokemonGlobal.mapTrail[1] && @@ -691,7 +691,7 @@ def pbRegisterPartner(tr_type, tr_name, tr_id = 0) pbCancelVehicles trainer = pbLoadTrainer(tr_type, tr_name, tr_id) Events.onTrainerPartyLoad.trigger(nil, trainer) - for i in trainer.party + trainer.party.each do |i| i.owner = Pokemon::Owner.new_from_trainer(trainer) i.calc_stats end diff --git a/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb b/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb index ca955008b..0a2edfe29 100644 --- a/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb +++ b/Data/Scripts/012_Overworld/002_Battle triggering/001_Overworld_BattleStarting.rb @@ -66,7 +66,7 @@ end def setBattleRule(*args) r = nil - for arg in args + args.each do |arg| if r $game_temp.add_battle_rule(r, arg) r = nil @@ -234,7 +234,7 @@ def pbWildBattleCore(*args) # Generate wild Pokémon based on the species and level foeParty = [] sp = nil - for arg in args + args.each do |arg| if arg.is_a?(Pokemon) foeParty.push(arg) elsif arg.is_a?(Array) @@ -382,7 +382,7 @@ def pbTrainerBattleCore(*args) foeEndSpeeches = [] foeParty = [] foePartyStarts = [] - for arg in args + args.each do |arg| case arg when NPCTrainer foeTrainers.push(arg) @@ -483,7 +483,7 @@ def pbTrainerBattle(trainerID, trainerName, endSpeech = nil, # Find all other triggered trainer events triggeredEvents = $game_player.pbTriggeredTrainerEvents([2], false) otherEvent = [] - for i in triggeredEvents + triggeredEvents.each do |i| next if i.id == thisEvent.id next if $game_self_switches[[$game_map.map_id, i.id, "A"]] otherEvent.push(i) @@ -632,9 +632,7 @@ end def pbDynamicItemList(*args) ret = [] - for i in 0...args.length - ret.push(args[i]) if GameData::Item.exists?(args[i]) - end + args.each { |arg| ret.push(arg) if GameData::Item.exists?(arg) } return ret end @@ -685,10 +683,10 @@ def pbPickup(pkmn) pkmnLevel = [100, pkmn.level].min itemStartIndex = (pkmnLevel - 1) / 10 itemStartIndex = 0 if itemStartIndex < 0 - for i in 0...9 + 9.times do |i| items.push(pickupList[itemStartIndex + i]) end - for i in 0...2 + 2.times do |i| items.push(pickupListRare[itemStartIndex + i]) end # Probabilities of choosing each item in turn from the pool diff --git a/Data/Scripts/012_Overworld/002_Battle triggering/002_Overworld_BattleIntroAnim.rb b/Data/Scripts/012_Overworld/002_Battle triggering/002_Overworld_BattleIntroAnim.rb index 9a09dc265..5f443f843 100644 --- a/Data/Scripts/012_Overworld/002_Battle triggering/002_Overworld_BattleIntroAnim.rb +++ b/Data/Scripts/012_Overworld/002_Battle triggering/002_Overworld_BattleIntroAnim.rb @@ -109,7 +109,7 @@ def pbBattleAnimation(bgm = nil, battletype = 0, foe = nil) alphaDiff = (255.0 / halfFlashTime).ceil 2.times do viewport.color.alpha = 0 - for i in 0...halfFlashTime * 2 + (halfFlashTime * 2).times do |i| if i < halfFlashTime viewport.color.alpha += alphaDiff else @@ -238,7 +238,7 @@ SpecialBattleIntroAnimations.register("vs_animation", 50, # Priority 50 flash.opacity = 0 # Animate bars sliding in from either side slideInTime = (Graphics.frame_rate * 0.25).floor - for i in 0...slideInTime + slideInTime.times do |i| bar1.x = xoffset * (i + 1 - slideInTime) / slideInTime bar2.x = xoffset * (slideInTime - i - 1) / slideInTime pbWait(1) @@ -263,7 +263,7 @@ SpecialBattleIntroAnimations.register("vs_animation", 50, # Priority 50 trainer.tone = Tone.new(-255, -255, -255) # Dim the flash and make the trainer sprites appear, while animating bars animTime = (Graphics.frame_rate * 1.2).floor - for i in 0...animTime + animTime.times do |i| flash.opacity -= 52 * 20 / Graphics.frame_rate if flash.opacity > 0 bar1.ox -= 32 * 20 / Graphics.frame_rate bar2.ox += 32 * 20 / Graphics.frame_rate @@ -294,7 +294,7 @@ SpecialBattleIntroAnimations.register("vs_animation", 50, # Priority 50 shudderTime = (Graphics.frame_rate * 1.75).floor zoomTime = (Graphics.frame_rate * 2.5).floor shudderDelta = [4 * 20 / Graphics.frame_rate, 1].max - for i in 0...animTime + animTime.times do |i| if i < shudderTime # Fade out the white flash flash.opacity -= 52 * 20 / Graphics.frame_rate if flash.opacity > 0 elsif i == shudderTime # Make the flash black diff --git a/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb b/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb index 47b3be965..ed4ef4943 100644 --- a/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb +++ b/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb @@ -18,7 +18,7 @@ end # Resets all roaming Pokemon that were defeated without having been caught. def pbResetAllRoamers return if !$PokemonGlobal.roamPokemon - for i in 0...$PokemonGlobal.roamPokemon.length + $PokemonGlobal.roamPokemon.length.times do |i| next if $PokemonGlobal.roamPokemon[i] != true || !$PokemonGlobal.roamPokemonCaught[i] $PokemonGlobal.roamPokemon[i] = nil end @@ -45,14 +45,14 @@ def pbRoamPokemon # Start all roamers off in random maps if !$PokemonGlobal.roamPosition $PokemonGlobal.roamPosition = {} - for i in 0...Settings::ROAMING_SPECIES.length + Settings::ROAMING_SPECIES.length.times do |i| next if !GameData::Species.exists?(Settings::ROAMING_SPECIES[i][0]) keys = pbRoamingAreas(i).keys $PokemonGlobal.roamPosition[i] = keys[rand(keys.length)] end end # Roam each Pokémon in turn - for i in 0...Settings::ROAMING_SPECIES.length + Settings::ROAMING_SPECIES.length.times do |i| pbRoamPokemonOne(i) end end @@ -77,7 +77,7 @@ def pbRoamPokemonOne(idxRoamer) newMapChoices = [] nextMaps = pbRoamingAreas(idxRoamer)[currentMap] return if !nextMaps - for map in nextMaps + nextMaps.each do |map| # Only add map as a choice if the player hasn't been there recently newMapChoices.push(map) end diff --git a/Data/Scripts/012_Overworld/002_Overworld_Metadata.rb b/Data/Scripts/012_Overworld/002_Overworld_Metadata.rb index 6f44708f1..dc5600cfd 100644 --- a/Data/Scripts/012_Overworld/002_Overworld_Metadata.rb +++ b/Data/Scripts/012_Overworld/002_Overworld_Metadata.rb @@ -73,7 +73,7 @@ class PokemonGlobalMetadata @pokedexDex = (numRegions == 0) ? -1 : 0 @pokedexIndex = [] @pokedexMode = 0 - for i in 0...numRegions + 1 # National Dex isn't a region, but is included + (numRegions + 1).times do |i| # National Dex isn't a region, but is included @pokedexIndex[i] = 0 end # Day Care @@ -153,13 +153,13 @@ class PokemonMapMetadata end def updateMap - for i in @erasedEvents + @erasedEvents.each do |i| if i[0][0] == $game_map.map_id && i[1] event = $game_map.events[i[0][1]] event.erase if event end end - for i in @movedEvents + @movedEvents.each do |i| if i[0][0] == $game_map.map_id && i[1] next if !$game_map.events[i[0][1]] $game_map.events[i[0][1]].moveto(i[1][0], i[1][1]) diff --git a/Data/Scripts/012_Overworld/003_Overworld_Time.rb b/Data/Scripts/012_Overworld/003_Overworld_Time.rb index a85d82460..ab8e1926b 100644 --- a/Data/Scripts/012_Overworld/003_Overworld_Time.rb +++ b/Data/Scripts/012_Overworld/003_Overworld_Time.rb @@ -154,7 +154,7 @@ def moonphase(time = nil) # in UTC v = (j - 2451550.1) / 29.530588853 v = ((v - v.floor) + (v < 0 ? 1 : 0)) ag = v * 29.53 - for i in 0...transitions.length + transitions.length.times do |i| return i if ag <= transitions[i] end return 0 @@ -177,7 +177,7 @@ def zodiac(month, day) 1, 20, 2, 18, # Aquarius 2, 19, 3, 20 # Pisces ] - for i in 0...12 + (time.length / 4).times do |i| return i if month == time[i * 4] && day >= time[(i * 4) + 1] return i if month == time[(i * 4) + 2] && day <= time[(i * 4) + 3] end @@ -207,7 +207,7 @@ def pbIsWeekday(wdayVariable, *arg) timenow = pbGetTimeNow wday = timenow.wday ret = false - for wd in arg + arg.each do |wd| ret = true if wd == wday end if wdayVariable > 0 @@ -232,7 +232,7 @@ def pbIsMonth(monVariable, *arg) timenow = pbGetTimeNow thismon = timenow.mon ret = false - for wd in arg + arg.each do |wd| ret = true if wd == thismon end if monVariable > 0 @@ -282,7 +282,7 @@ end def pbIsSeason(seasonVariable, *arg) thisseason = pbGetSeason ret = false - for wd in arg + arg.each do |wd| ret = true if wd == thisseason end if seasonVariable > 0 diff --git a/Data/Scripts/012_Overworld/004_Overworld_FieldMoves.rb b/Data/Scripts/012_Overworld/004_Overworld_FieldMoves.rb index 2273bffaf..f7339b0de 100644 --- a/Data/Scripts/012_Overworld/004_Overworld_FieldMoves.rb +++ b/Data/Scripts/012_Overworld/004_Overworld_FieldMoves.rb @@ -155,7 +155,7 @@ def pbHiddenMoveAnimation(pokemon) phase = 6 if interp.done? end # Constantly stream the strobes across the screen - for strobe in strobes + strobes.each do |strobe| strobe.ox = strobe.viewport.rect.x strobe.oy = strobe.viewport.rect.y if !strobe.visible # Initial placement of strobes @@ -175,7 +175,7 @@ def pbHiddenMoveAnimation(pokemon) break if phase == 6 end sprite.dispose - for strobe in strobes + strobes.each do |strobe| strobe.dispose end strobes.clear diff --git a/Data/Scripts/012_Overworld/008_Overworld_RandomDungeons.rb b/Data/Scripts/012_Overworld/008_Overworld_RandomDungeons.rb index dc7e0716b..75030772b 100644 --- a/Data/Scripts/012_Overworld/008_Overworld_RandomDungeons.rb +++ b/Data/Scripts/012_Overworld/008_Overworld_RandomDungeons.rb @@ -91,9 +91,9 @@ module RandomDungeonGenerator tiles = [] x_offset = (CELL_WIDTH - CORRIDOR_WIDTH) / 2 y_offset = (CELL_HEIGHT - CORRIDOR_WIDTH) / 2 - for combo in 0...16 + 16.times do |combo| tiles[combo] = [] - for i in 0...CELL_WIDTH * CELL_HEIGHT + (CELL_WIDTH * CELL_HEIGHT).times do |i| tiles[combo][i] = DungeonTile::VOID end if (combo & EdgeMasks::NORTH) == 0 @@ -116,8 +116,8 @@ module RandomDungeonGenerator # Makes all tiles in a particular area corridor tiles. def paint_corridor(tile, x, y, width, height) - for j in 0...height - for i in 0...width + timesheight.times do |j| + timeswidth.times do |i| tile[((y + j) * CELL_WIDTH) + (x + i)] = DungeonTile::CORRIDOR end end @@ -127,26 +127,26 @@ module RandomDungeonGenerator def paint_tile_layout(dungeon, dstX, dstY, tile_layout, rotation) case rotation when TURN_NONE - for y in 0...CELL_HEIGHT - for x in 0...CELL_WIDTH + CELL_HEIGHT.times do |y| + CELL_WIDTH.times do |x| dungeon[x + dstX, y + dstY] = tile_layout[(y * CELL_WIDTH) + x] end end when TURN_LEFT - for y in 0...CELL_HEIGHT - for x in 0...CELL_WIDTH + CELL_HEIGHT.times do |y| + CELL_WIDTH.times do |x| dungeon[y + dstX, CELL_WIDTH - 1 - x + dstY] = tile_layout[(y * CELL_WIDTH) + x] end end when TURN_RIGHT - for y in 0...CELL_HEIGHT - for x in 0...CELL_WIDTH + CELL_HEIGHT.times do |y| + CELL_WIDTH.times do |x| dungeon[CELL_HEIGHT - 1 - y + dstX, x + dstY] = tile_layout[(y * CELL_WIDTH) + x] end end when TURN_BACK - for y in 0...CELL_HEIGHT - for x in 0...CELL_WIDTH + CELL_HEIGHT.times do |y| + CELL_WIDTH.times do |x| dungeon[CELL_WIDTH - 1 - x + dstX, CELL_HEIGHT - 1 - y + dstY] = tile_layout[(y * CELL_WIDTH) + x] end end @@ -258,7 +258,7 @@ module RandomDungeonGenerator end def clearAllCells - for c in 0...cellWidth * cellHeight + (cellWidth * cellHeight).times do |c| @cells[c] = 0 end end @@ -295,7 +295,7 @@ module RandomDungeonGenerator end def setAllEdges - for c in 0...nodeWidth * nodeHeight + (nodeWidth * nodeHeight).times do |c| @nodes[c].set end end @@ -327,7 +327,7 @@ module RandomDungeonGenerator end def clearAllEdges - for c in 0...nodeWidth * nodeHeight + (nodeWidth * nodeHeight).times do |c| @nodes[c].clear end end @@ -373,8 +373,8 @@ module RandomDungeonGenerator def buildNodeList list = [] - for x in 0...nodeWidth - for y in 0...nodeHeight + nodeWidth.times do |x| + nodeHeight.times do |y| list.push(NodeListElement.new(x, y)) end end @@ -386,7 +386,7 @@ module RandomDungeonGenerator maxWall = cellWidth if !maxWall nlist = buildNodeList return if nlist.length == 0 - for c in 0...nlist.length + nlist.length.times do |c| d = randomDir len = rand(maxWall + 1) x = nlist[c].x @@ -398,7 +398,7 @@ module RandomDungeonGenerator def recurseDepthFirst(x, y, depth) setVisited(x, y) dirs = DIRECTIONS.shuffle - for c in 0...4 + 4.times do |c| d = dirs[c] cx = x cy = y @@ -464,7 +464,7 @@ module RandomDungeonGenerator end def clear - for i in 0...width * height + (width * height).times do |i| @array[i] = DungeonTile::VOID end end @@ -472,8 +472,8 @@ module RandomDungeonGenerator def write ret = "" i = 0 - for y in 0...@height - for x in 0...@width + @height.times do |y| + @width.times do |x| ret += DungeonTile.to_text(value(x, y)) i += 1 end @@ -544,8 +544,8 @@ module RandomDungeonGenerator end def paint_room(rect, offsetX, offsetY) - for y in (rect[1] + offsetY)...(rect[1] + offsetY + rect[3]) - for x in (rect[0] + offsetX)...(rect[0] + offsetX + rect[2]) + ((rect[1] + offsetY)...(rect[1] + offsetY + rect[3])).each do |y| + ((rect[0] + offsetX)...(rect[0] + offsetX + rect[2])).each do |x| self[x, y] = DungeonTile::ROOM end end @@ -559,8 +559,8 @@ module RandomDungeonGenerator cellHeight = DungeonMaze::CELL_HEIGHT return if maxWidth < 0 || maxHeight < 0 if maxWidth < cellWidth || maxHeight < cellHeight # Map is too small - for x in 0...maxWidth - for y in 0...maxHeight + maxWidth.times do |x| + maxHeight.times do |y| self[x + BUFFER_X, y + BUFFER_Y] = DungeonTile::ROOM end end @@ -572,8 +572,8 @@ module RandomDungeonGenerator # Draw each cell's contents in turn (room and corridors) corridor_patterns = DungeonMaze.generate_corridor_patterns roomcount = 0 - for y in 0...maxHeight / cellHeight - for x in 0...maxWidth / cellWidth + (maxHeight / cellHeight).times do |y| + (maxWidth / cellWidth).times do |x| pattern = maze.getEdgePattern(x, y) next if !DungeonMaze.paint_cell_contents( self, BUFFER_X + (x * cellWidth), BUFFER_Y + (y * cellHeight), @@ -584,15 +584,15 @@ module RandomDungeonGenerator end # If no rooms were generated, make the whole map a room if roomcount == 0 - for x in 0...maxWidth - for y in 0...maxHeight + maxWidth.times do |x| + maxHeight.times do |y| self[x + BUFFER_X, y + BUFFER_Y] = DungeonTile::ROOM end end end # Generate walls - for y in 0...@height - for x in 0...@width + @height.times do |y| + @width.times do |x| self[x, y] = DungeonTile::WALL if isWall?(x, y) # Make appropriate tiles wall tiles end end @@ -601,8 +601,8 @@ module RandomDungeonGenerator # Convert dungeon layout into proper map tiles def generateMapInPlace(map) tbl = DungeonTable.new(self) - for i in 0...map.width - for j in 0...map.height + map.width.times do |i| + map.height.times do |j| nb = TileDrawingHelper.tableNeighbors(tbl, i, j) tile = TileDrawingHelper::NEIGHBORS_TO_AUTOTILE_INDEX[nb] map.data[i, j, 0] = tile + (48 * (tbl[i, j])) @@ -655,7 +655,7 @@ Events.onMapCreate += proc { |_sender, e| dungeon.generateMapInPlace(map) roomtiles = [] # Reposition events - for event in map.events.values + map.events.values.each do |event| tile = RandomDungeonGenerator.pbRandomRoomTile(dungeon, roomtiles) if tile event.x = tile[0] diff --git a/Data/Scripts/013_Items/001_Item_Utilities.rb b/Data/Scripts/013_Items/001_Item_Utilities.rb index abbe02464..6eec6c23d 100644 --- a/Data/Scripts/013_Items/001_Item_Utilities.rb +++ b/Data/Scripts/013_Items/001_Item_Utilities.rb @@ -183,7 +183,7 @@ def pbChangeLevel(pkmn, new_level, scene) pkmn.totalhp, pkmn.attack, pkmn.defense, pkmn.spatk, pkmn.spdef, pkmn.speed), scene) # Learn new moves upon level up movelist = pkmn.getMoveList - for i in movelist + movelist.each do |i| next if i[0] <= old_level || i[0] > pkmn.level pbLearnMove(pkmn, i[1], true) { scene.pbUpdate } end @@ -292,7 +292,7 @@ def pbChangeExp(pkmn, new_exp, scene) pkmn.totalhp, pkmn.attack, pkmn.defense, pkmn.spatk, pkmn.spdef, pkmn.speed), scene) # Learn new moves upon level up movelist = pkmn.getMoveList - for i in movelist + movelist.each do |i| next if i[0] <= old_level || i[0] > pkmn.level pbLearnMove(pkmn, i[1], true) { scene.pbUpdate } end @@ -551,7 +551,7 @@ def pbClosestHiddenItem result = [] playerX = $game_player.x playerY = $game_player.y - for event in $game_map.events.values + $game_map.events.values.each do |event| next if !event.name[/hiddenitem/i] next if (playerX - event.x).abs >= 8 next if (playerY - event.y).abs >= 6 @@ -561,7 +561,7 @@ def pbClosestHiddenItem return nil if result.length == 0 ret = nil retmin = 0 - for event in result + result.each do |event| dist = (playerX - event.x).abs + (playerY - event.y).abs next if ret && retmin <= dist ret = event @@ -663,7 +663,7 @@ def pbUseItem(bag, item, bagscene = nil) annot = nil if itm.is_evolution_stone? annot = [] - for pkmn in $player.party + $player.party.each do |pkmn| elig = pkmn.check_evolution_on_use_item(item) annot.push((elig) ? _INTL("ABLE") : _INTL("NOT ABLE")) end @@ -909,7 +909,7 @@ end def pbChooseItemFromList(message, variable, *args) commands = [] itemid = [] - for item in args + args.each do |item| next if !GameData::Item.exists?(item) itm = GameData::Item.get(item) next if !$bag.has?(itm) diff --git a/Data/Scripts/013_Items/002_Item_Effects.rb b/Data/Scripts/013_Items/002_Item_Effects.rb index 5f2945ae6..55d0ed95d 100644 --- a/Data/Scripts/013_Items/002_Item_Effects.rb +++ b/Data/Scripts/013_Items/002_Item_Effects.rb @@ -193,7 +193,7 @@ ItemHandlers::UseInField.add(:SACREDASH, proc { |item| next false end canrevive = false - for i in $player.pokemon_party + $player.pokemon_party.each do |i| next if !i.fainted? canrevive = true break @@ -604,7 +604,7 @@ ItemHandlers::UseOnPokemon.add(:MAXETHER, proc { |item, qty, pkmn, scene| ItemHandlers::UseOnPokemon.add(:ELIXIR, proc { |item, qty, pkmn, scene| pprestored = 0 - for i in 0...pkmn.moves.length + pkmn.moves.length.times do |i| pprestored += pbRestorePP(pkmn, i, 10) end if pprestored == 0 @@ -617,7 +617,7 @@ ItemHandlers::UseOnPokemon.add(:ELIXIR, proc { |item, qty, pkmn, scene| ItemHandlers::UseOnPokemon.add(:MAXELIXIR, proc { |item, qty, pkmn, scene| pprestored = 0 - for i in 0...pkmn.moves.length + pkmn.moves.length.times do |i| pprestored += pbRestorePP(pkmn, i, pkmn.moves[i].total_pp - pkmn.moves[i].pp) end if pprestored == 0 @@ -1027,7 +1027,7 @@ ItemHandlers::UseOnPokemon.add(:ABILITYCAPSULE, proc { |item, qty, pkmn, scene| abils = pkmn.getAbilityList abil1 = nil abil2 = nil - for i in abils + abils.each do |i| abil1 = i[0] if i[1] == 0 abil2 = i[0] if i[1] == 1 end diff --git a/Data/Scripts/013_Items/003_Item_BattleEffects.rb b/Data/Scripts/013_Items/003_Item_BattleEffects.rb index 47c94a46b..b885a0d00 100644 --- a/Data/Scripts/013_Items/003_Item_BattleEffects.rb +++ b/Data/Scripts/013_Items/003_Item_BattleEffects.rb @@ -163,7 +163,7 @@ ItemHandlers::CanUseInBattle.add(:ELIXIR, proc { |item, pokemon, battler, move, next false end canRestore = false - for m in pokemon.moves + pokemon.moves.each do |m| next if m.id == 0 next if m.total_pp <= 0 || m.pp == m.total_pp canRestore = true @@ -502,14 +502,14 @@ ItemHandlers::BattleUseOnPokemon.add(:MAXETHER, proc { |item, pokemon, battler, }) ItemHandlers::BattleUseOnPokemon.add(:ELIXIR, proc { |item, pokemon, battler, choices, scene| - for i in 0...pokemon.moves.length + pokemon.moves.length.times do |i| pbBattleRestorePP(pokemon, battler, i, 10) end scene.pbDisplay(_INTL("PP was restored.")) }) ItemHandlers::BattleUseOnPokemon.add(:MAXELIXIR, proc { |item, pokemon, battler, choices, scene| - for i in 0...pokemon.moves.length + pokemon.moves.length.times do |i| pbBattleRestorePP(pokemon, battler, i, pokemon.moves[i].total_pp) end scene.pbDisplay(_INTL("PP was restored.")) diff --git a/Data/Scripts/013_Items/004_Item_Phone.rb b/Data/Scripts/013_Items/004_Item_Phone.rb index f3f478bb0..b949c9450 100644 --- a/Data/Scripts/013_Items/004_Item_Phone.rb +++ b/Data/Scripts/013_Items/004_Item_Phone.rb @@ -67,7 +67,7 @@ def pbRandomPhoneTrainer this_map_metadata = $game_map.metadata return nil if !this_map_metadata || !this_map_metadata.town_map_position currentRegion = this_map_metadata.town_map_position[0] - for num in $PokemonGlobal.phoneNumbers + $PokemonGlobal.phoneNumbers.each do |num| next if !num[0] || num.length != 8 # if not visible or not a trainer next if $game_map.map_id == num[6] # Can't call if on same map caller_map_metadata = GameData::MapMetadata.try_get(num[6]) @@ -82,7 +82,7 @@ end def pbFindPhoneTrainer(tr_type, tr_name) # Ignores whether visible or not return nil if !$PokemonGlobal.phoneNumbers - for num in $PokemonGlobal.phoneNumbers + $PokemonGlobal.phoneNumbers.each do |num| return num if num[1] == tr_type && num[2] == tr_name # If a match end return nil @@ -146,7 +146,7 @@ Events.onMapUpdate += proc { |_sender, _e| $PokemonGlobal.phoneTime -= 1 # Count down time to next can-battle for each trainer contact if $PokemonGlobal.phoneTime % Graphics.frame_rate == 0 # Every second - for num in $PokemonGlobal.phoneNumbers + $PokemonGlobal.phoneNumbers.each do |num| next if !num[0] || num.length != 8 # if not visible or not a trainer # Reset time to next can-battle if necessary if num[4] == 0 @@ -291,7 +291,7 @@ def pbPhoneCall(call, phonenum) trainerspecies = pbTrainerSpecies(phonenum) trainermap = pbTrainerMapName(phonenum) messages = call.split("\\m") - for i in 0...messages.length + messages.length.times do |i| messages[i].gsub!(/\\TN/, phonenum[2]) messages[i].gsub!(/\\TP/, trainerspecies) messages[i].gsub!(/\\TE/, encspecies) diff --git a/Data/Scripts/013_Items/005_Item_PokeRadar.rb b/Data/Scripts/013_Items/005_Item_PokeRadar.rb index 5ac14eb37..5e6f84e18 100644 --- a/Data/Scripts/013_Items/005_Item_PokeRadar.rb +++ b/Data/Scripts/013_Items/005_Item_PokeRadar.rb @@ -58,7 +58,7 @@ end def pbPokeRadarHighlightGrass(showmessage = true) grasses = [] # x, y, ring (0-3 inner to outer), rarity # Choose 1 random tile from each ring around the player - for i in 0...4 + 4.times do |i| r = rand((i + 1) * 8) # Get coordinates of randomly chosen tile x = $game_player.x @@ -95,7 +95,7 @@ def pbPokeRadarHighlightGrass(showmessage = true) pbPokeRadarCancel else # Show grass rustling animations - for grass in grasses + grasses.each do |grass| case grass[3] when 0 # Normal rustle $scene.spriteset.addUserAnimation(Settings::RUSTLE_NORMAL_ANIMATION_ID, grass[0], grass[1], true, 1) @@ -114,7 +114,7 @@ def pbPokeRadarGetShakingGrass return -1 if !$game_temp.poke_radar_data grasses = $game_temp.poke_radar_data[3] return -1 if grasses.length == 0 - for i in grasses + grasses.each do |i| return i[2] if $game_player.x == i[0] && $game_player.y == i[1] end return -1 @@ -197,7 +197,7 @@ Events.onWildPokemonCreate += proc { |_sender, e| next if !$game_temp.poke_radar_data grasses = $game_temp.poke_radar_data[3] next if !grasses - for grass in grasses + grasses.each do |grass| next if $game_player.x != grass[0] || $game_player.y != grass[1] pokemon.shiny = true if grass[3] == 2 break diff --git a/Data/Scripts/013_Items/008_PokemonBag.rb b/Data/Scripts/013_Items/008_PokemonBag.rb index 119216878..e7bb9d3e5 100644 --- a/Data/Scripts/013_Items/008_PokemonBag.rb +++ b/Data/Scripts/013_Items/008_PokemonBag.rb @@ -19,7 +19,7 @@ class PokemonBag @last_viewed_pocket = 1 @pockets = [] @last_pocket_selections = [] - for i in 0..PokemonBag.pocket_count + (0..PokemonBag.pocket_count).each do |i| @pockets[i] = [] @last_pocket_selections[i] = 0 end diff --git a/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb b/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb index dc386abca..73d906168 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon-related/001_FormHandlers.rb @@ -37,9 +37,9 @@ end def drawSpot(bitmap, spotpattern, x, y, red, green, blue) height = spotpattern.length width = spotpattern[0].length - for yy in 0...height + height.times do |yy| spot = spotpattern[yy] - for xx in 0...width + width.times do |xx| if spot[xx] == 1 xOrg = (x + xx) << 1 yOrg = (y + yy) << 1 @@ -297,7 +297,7 @@ MultipleForms.register(:ARCEUS, { } ret = 0 typeArray.each do |f, items| - for item in items + items.each do |item| next if !pkmn.hasItem?(item) ret = f break @@ -502,7 +502,7 @@ MultipleForms.register(:SILVALLY, { } ret = 0 typeArray.each do |f, items| - for item in items + items.each do |item| next if !pkmn.hasItem?(item) ret = f break @@ -539,8 +539,8 @@ MultipleForms.register(:NECROZMA, { "onSetForm" => proc { |pkmn, form, oldForm| next if form > 2 || oldForm > 2 # Ultra form changes don't affect moveset form_moves = [ - :SUNSTEELSTRIKE, # Dusk Mane (with Solgaleo) (form 1) - :MOONGEISTBEAM # Dawn Wings (with Lunala) (form 2) + :SUNSTEELSTRIKE, # Dusk Mane (with Solgaleo) (form 1) + :MOONGEISTBEAM # Dawn Wings (with Lunala) (form 2) ] if form == 0 # Turned back into the base form; forget form-specific moves diff --git a/Data/Scripts/014_Pokemon/001_Pokemon-related/002_ShadowPokemon_Other.rb b/Data/Scripts/014_Pokemon/001_Pokemon-related/002_ShadowPokemon_Other.rb index e060b855c..2d4486fb2 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon-related/002_ShadowPokemon_Other.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon-related/002_ShadowPokemon_Other.rb @@ -372,7 +372,7 @@ end #=============================================================================== class Battle::Move::RemoveAllScreens < Battle::Move def pbEffectGeneral(user) - for i in @battle.sides + @battle.sides.each do |i| i.effects[PBEffects::AuroraVeil] = 0 i.effects[PBEffects::Reflect] = 0 i.effects[PBEffects::LightScreen] = 0 diff --git a/Data/Scripts/014_Pokemon/001_Pokemon-related/004_PokemonStorage.rb b/Data/Scripts/014_Pokemon/001_Pokemon-related/004_PokemonStorage.rb index e07a11716..3005390d0 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon-related/004_PokemonStorage.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon-related/004_PokemonStorage.rb @@ -8,12 +8,10 @@ class PokemonBox BOX_SIZE = BOX_WIDTH * BOX_HEIGHT def initialize(name, maxPokemon = BOX_SIZE) - @pokemon = [] @name = name @background = 0 - for i in 0...maxPokemon - @pokemon[i] = nil - end + @pokemon = [] + maxPokemon.times { |i| @pokemon[i] = nil } end def length @@ -62,14 +60,14 @@ class PokemonStorage def initialize(maxBoxes = Settings::NUM_STORAGE_BOXES, maxPokemon = PokemonBox::BOX_SIZE) @boxes = [] - for i in 0...maxBoxes + maxBoxes.times do |i| @boxes[i] = PokemonBox.new(_INTL("Box {1}", i + 1), maxPokemon) @boxes[i].background = i % BASICWALLPAPERQTY end @currentBox = 0 @boxmode = -1 @unlockedWallpapers = [] - for i in 0...allWallpapers.length + allWallpapers.length.times do |i| @unlockedWallpapers[i] = false end end @@ -107,7 +105,7 @@ class PokemonStorage ret = [[], []] # Names, IDs papers = allWallpapers @unlockedWallpapers = [] if !@unlockedWallpapers - for i in 0...papers.length + papers.length.times do |i| next if !isAvailableWallpaper?(i) ret[0].push(papers[i]) ret[1].push(i) @@ -137,7 +135,7 @@ class PokemonStorage end def full? - for i in 0...self.maxBoxes + self.maxBoxes.times do |i| return false if !@boxes[i].full? end return true @@ -148,7 +146,7 @@ class PokemonStorage ret = self.party.length return (ret >= Settings::MAX_PARTY_SIZE) ? -1 : ret end - for i in 0...maxPokemon(box) + maxPokemon(box).times do |i| return i if !self[box, i] end return -1 @@ -158,7 +156,7 @@ class PokemonStorage if y == nil return (x == -1) ? self.party : @boxes[x] else - for i in @boxes + @boxes.each do |i| raise "Box is a Pokémon, not a box" if i.is_a?(Pokemon) end return (x == -1) ? self.party[y] : @boxes[x][y] @@ -176,7 +174,7 @@ class PokemonStorage def pbCopy(boxDst, indexDst, boxSrc, indexSrc) if indexDst < 0 && boxDst < self.maxBoxes found = false - for i in 0...maxPokemon(boxDst) + maxPokemon(boxDst).times do |i| next if self[boxDst, i] found = true indexDst = i @@ -213,7 +211,7 @@ class PokemonStorage end def pbMoveCaughtToBox(pkmn, box) - for i in 0...maxPokemon(box) + maxPokemon(box).times do |i| if self[box, i] == nil if Settings::HEAL_STORED_POKEMON && box >= 0 old_ready_evo = pkmn.ready_to_evolve @@ -233,14 +231,14 @@ class PokemonStorage pkmn.heal pkmn.ready_to_evolve = old_ready_evo end - for i in 0...maxPokemon(@currentBox) + maxPokemon(@currentBox).times do |i| if self[@currentBox, i] == nil self[@currentBox, i] = pkmn return @currentBox end end - for j in 0...self.maxBoxes - for i in 0...maxPokemon(j) + self.maxBoxes.times do |j| + maxPokemon(j).times do |i| if self[j, i] == nil self[j, i] = pkmn @currentBox = j @@ -259,9 +257,7 @@ class PokemonStorage end def clear - for i in 0...self.maxBoxes - @boxes[i].clear - end + self.maxBoxes.times { |i| @boxes[i].clear } end end @@ -393,8 +389,8 @@ end #=============================================================================== # Yields every Pokémon/egg in storage in turn. def pbEachPokemon - for i in -1...$PokemonStorage.maxBoxes - for j in 0...$PokemonStorage.maxPokemon(i) + (-1...$PokemonStorage.maxBoxes).each do |i| + $PokemonStorage.maxPokemon(i).times do |j| pkmn = $PokemonStorage[i][j] yield(pkmn, i) if pkmn end diff --git a/Data/Scripts/014_Pokemon/001_Pokemon.rb b/Data/Scripts/014_Pokemon/001_Pokemon.rb index c416a5b0c..d5c183692 100644 --- a/Data/Scripts/014_Pokemon/001_Pokemon.rb +++ b/Data/Scripts/014_Pokemon/001_Pokemon.rb @@ -631,7 +631,7 @@ class Pokemon @moves.clear first_move_index = knowable_moves.length - MAX_MOVES first_move_index = 0 if first_move_index < 0 - for i in first_move_index...knowable_moves.length + (first_move_index...knowable_moves.length).each do |i| @moves.push(Pokemon::Move.new(knowable_moves[i])) end end @@ -744,7 +744,7 @@ class Pokemon args.each_with_index do |ribbon, i| this_ribbon_data = GameData::Ribbon.try_get(ribbon) next if !this_ribbon_data - for j in 0...@ribbons.length + @ribbons.length.times do |j| next if @ribbons[j] != this_ribbon_data.id next_ribbon_data = GameData::Ribbon.try_get(args[i + 1]) next if !next_ribbon_data diff --git a/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb b/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb index 0ca08164f..f305b23e0 100644 --- a/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb +++ b/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb @@ -11,7 +11,7 @@ end def pbNewTrainer(tr_type, tr_name, tr_version, save_changes = true) party = [] - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| if i == 0 pbMessage(_INTL("Please enter the first Pokémon.", i)) elsif !pbConfirmMessage(_INTL("Add another Pokémon?")) @@ -99,7 +99,7 @@ def pbGetFreeTrainerParty(tr_type, tr_name) tr_type_data = GameData::TrainerType.try_get(tr_type) raise _INTL("Trainer type {1} does not exist.", tr_type) if !tr_type_data tr_type = tr_type_data.id - for i in 0...256 + 256.times do |i| return i if !GameData::Trainer.try_get(tr_type, tr_name, i) end return -1 diff --git a/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb b/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb index 4ffb6d6c9..57d1e8a1b 100644 --- a/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb +++ b/Data/Scripts/015_Trainers and player/005_Player_Pokedex.rb @@ -119,7 +119,7 @@ class Player < Trainer ret = 0 @seen_forms[species_id] ||= [[[], []], [[], []]] array = @seen_forms[species_id] - for i in 0...[array[0].length, array[1].length].max + [array[0].length, array[1].length].max.times do |i| ret += 1 if array[0][0][i] || array[0][1][i] || # male or genderless shiny/non-shiny array[1][0][i] || array[1][1][i] # female shiny/non-shiny end @@ -325,7 +325,7 @@ class Player < Trainer @accessible_dexes.push(-1) end else # Regional Dexes + National Dex - for i in 0...dexes_count + dexes_count.times do |i| dex_list_to_check = (i == dexes_count - 1) ? -1 : i if self.unlocked?(i) && self.seen_any?(dex_list_to_check) @accessible_dexes.push(dex_list_to_check) diff --git a/Data/Scripts/016_UI/001_Non-interactive UI/003_UI_EggHatching.rb b/Data/Scripts/016_UI/001_Non-interactive UI/003_UI_EggHatching.rb index 6a96398d8..ccb928e3c 100644 --- a/Data/Scripts/016_UI/001_Non-interactive UI/003_UI_EggHatching.rb +++ b/Data/Scripts/016_UI/001_Non-interactive UI/003_UI_EggHatching.rb @@ -77,7 +77,7 @@ class PokemonEggHatch_Scene # Fade and change the sprite fadeTime = Graphics.frame_rate * 4 / 10 toneDiff = (255.0 / fadeTime).ceil - for i in 1..fadeTime + (1..fadeTime).each do |i| @sprites["pokemon"].tone = Tone.new(i * toneDiff, i * toneDiff, i * toneDiff) @sprites["overlay"].opacity = i * toneDiff updateScene @@ -88,7 +88,7 @@ class PokemonEggHatch_Scene @sprites["pokemon"].y = 264 @pokemon.species_data.apply_metrics_to_sprite(@sprites["pokemon"], 1) @sprites["hatch"].visible = false - for i in 1..fadeTime + (1..fadeTime).each do |i| @sprites["pokemon"].tone = Tone.new(255 - (i * toneDiff), 255 - (i * toneDiff), 255 - (i * toneDiff)) @sprites["overlay"].opacity = 255 - (i * toneDiff) updateScene @@ -220,10 +220,10 @@ def pbHatch(pokemon) end Events.onStepTaken += proc { |_sender, _e| - for egg in $player.party + $player.party.each do |egg| next if egg.steps_to_hatch <= 0 egg.steps_to_hatch -= 1 - for i in $player.pokemon_party + $player.pokemon_party.each do |i| next if ![:FLAMEBODY, :MAGMAARMOR, :STEAMENGINE].include?(i.ability_id) egg.steps_to_hatch -= 1 break diff --git a/Data/Scripts/016_UI/001_Non-interactive UI/004_UI_Evolution.rb b/Data/Scripts/016_UI/001_Non-interactive UI/004_UI_Evolution.rb index 123c2b886..9a153e292 100644 --- a/Data/Scripts/016_UI/001_Non-interactive UI/004_UI_Evolution.rb +++ b/Data/Scripts/016_UI/001_Non-interactive UI/004_UI_Evolution.rb @@ -253,12 +253,12 @@ class SpriteMetafilePlayer def update if @playing - for j in @index...@metafile.length + (@index...@metafile.length).each do |j| @index = j + 1 break if @metafile[j][0] < 0 code = @metafile[j][0] value = @metafile[j][1] - for sprite in @sprites + @sprites.each do |sprite| case code when SpriteMetafile::X then sprite.x = value when SpriteMetafile::Y then sprite.y = value @@ -379,7 +379,7 @@ class PokemonEvolutionScene currenttempo = 25 maxtempo = 7 * Graphics.frame_rate while totaltempo < maxtempo - for j in 0...currenttempo + currenttempo.times do |j| if alpha < 255 sprite.color.red = 255 sprite.color.green = 255 @@ -395,7 +395,7 @@ class PokemonEvolutionScene end totaltempo += currenttempo if totaltempo + currenttempo < maxtempo - for j in 0...currenttempo + currenttempo.times do |j| sprite.zoom = [1.1 * (j + 1) / currenttempo, 1.0].min sprite2.zoom = [1.1 * (currenttempo - j - 1) / currenttempo, 1.0].min sprite.update @@ -542,7 +542,7 @@ class PokemonEvolutionScene pbMEPlay("Evolution start") pbBGMPlay("Evolution") canceled = false - begin + loop do pbUpdateNarrowScreen metaplayer1.update metaplayer2.update @@ -555,7 +555,8 @@ class PokemonEvolutionScene canceled = true break end - end while metaplayer1.playing? && metaplayer2.playing? + break unless metaplayer1.playing? && metaplayer2.playing? + end pbFlashInOut(canceled, oldstate, oldstate2) if canceled $stats.evolutions_cancelled += 1 @@ -595,7 +596,7 @@ class PokemonEvolutionScene $player.pokedex.set_owned(@newspecies) # Learn moves upon evolution for evolved species movelist = @pokemon.getMoveList - for i in movelist + movelist.each do |i| next if i[0] != 0 && i[0] != @pokemon.level # 0 is "learn upon evolution" pbLearnMove(@pokemon, i[1], true) { pbUpdate } end diff --git a/Data/Scripts/016_UI/001_Non-interactive UI/005_UI_Trading.rb b/Data/Scripts/016_UI/001_Non-interactive UI/005_UI_Trading.rb index 635637edf..d86fb86cb 100644 --- a/Data/Scripts/016_UI/001_Non-interactive UI/005_UI_Trading.rb +++ b/Data/Scripts/016_UI/001_Non-interactive UI/005_UI_Trading.rb @@ -8,22 +8,18 @@ class PokemonTrade_Scene def pbRunPictures(pictures, sprites) loop do - for i in 0...pictures.length - pictures[i].update - end - for i in 0...sprites.length - if sprites[i].is_a?(IconSprite) - setPictureIconSprite(sprites[i], pictures[i]) + pictures.each { |pic| pic.update } + sprites.each_with_index do |sprite, i| + if sprite.is_a?(IconSprite) + setPictureIconSprite(sprite, pictures[i]) else - setPictureSprite(sprites[i], pictures[i]) + setPictureSprite(sprite, pictures[i]) end end Graphics.update Input.update running = false - for i in 0...pictures.length - running = true if pictures[i].running? - end + pictures.each { |pic| running = true if pic.running? } break if !running end end @@ -119,7 +115,7 @@ class PokemonTrade_Scene # Dropping ball y = Graphics.height - 96 - 16 - 16 # end point of Poké Ball delay = picturePoke.totalDuration + 2 - for i in 0...4 + 4.times do |i| t = [4, 4, 3, 2][i] # Time taken to rise or fall for each bounce d = [1, 2, 4, 8][i] # Fraction of the starting height each bounce rises to delay -= t if i == 0 diff --git a/Data/Scripts/016_UI/001_Non-interactive UI/006_UI_HallOfFame.rb b/Data/Scripts/016_UI/001_Non-interactive UI/006_UI_HallOfFame.rb index dddb157e6..d2e9d0dce 100644 --- a/Data/Scripts/016_UI/001_Non-interactive UI/006_UI_HallOfFame.rb +++ b/Data/Scripts/016_UI/001_Non-interactive UI/006_UI_HallOfFame.rb @@ -96,7 +96,7 @@ class HallOfFame_Scene exponent = 8 if exponent > 8 max = 2**exponent speed = (2**8) / max - for j in 0..max + (0..max).each do |j| if extraWaitExponent > -1 (2**extraWaitExponent).times do Graphics.update @@ -117,7 +117,7 @@ class HallOfFame_Scene # Change the pokémon sprites opacity except the index one def setPokemonSpritesOpacity(index, opacity = 255) - for n in 0...@hallEntry.size + @hallEntry.size.times do |n| @sprites["pokemon#{n}"].opacity = (n == index) ? 255 : opacity if @sprites["pokemon#{n}"] end end @@ -201,7 +201,7 @@ class HallOfFame_Scene def createBattlers(hide = true) # Movement in animation - for i in 0...6 + 6.times do |i| # Clear all 6 pokémon sprites and dispose the ones that exists every time # that this method is call restartSpritePosition(@sprites, "pokemon#{i}") diff --git a/Data/Scripts/016_UI/001_Non-interactive UI/007_UI_Credits.rb b/Data/Scripts/016_UI/001_Non-interactive UI/007_UI_Credits.rb index 5e857f86f..bb732ad1a 100644 --- a/Data/Scripts/016_UI/001_Non-interactive UI/007_UI_Credits.rb +++ b/Data/Scripts/016_UI/001_Non-interactive UI/007_UI_Credits.rb @@ -144,17 +144,17 @@ _END_ @total_height = credit_lines.size * 32 lines_per_bitmap = @bitmap_height / 32 num_bitmaps = (credit_lines.size.to_f / lines_per_bitmap).ceil - for i in 0...num_bitmaps + num_bitmaps.times do |i| credit_bitmap = Bitmap.new(Graphics.width, @bitmap_height + 16) pbSetSystemFont(credit_bitmap) - for j in 0...lines_per_bitmap + lines_per_bitmap.times do |j| line = credit_lines[(i * lines_per_bitmap) + j] next if !line line = line.split("") xpos = 0 align = 1 # Centre align linewidth = Graphics.width - for k in 0...line.length + line.length.times do |k| if line.length > 1 xpos = (k == 0) ? 0 : 20 + (Graphics.width / 2) align = (k == 0) ? 2 : 0 # Right align : left align diff --git a/Data/Scripts/016_UI/003_UI_Pokedex_Main.rb b/Data/Scripts/016_UI/003_UI_Pokedex_Main.rb index 53827cf2f..405b98a2f 100644 --- a/Data/Scripts/016_UI/003_UI_Pokedex_Main.rb +++ b/Data/Scripts/016_UI/003_UI_Pokedex_Main.rb @@ -58,7 +58,7 @@ class Window_Pokedex < Window_DrawableCommand dheight = self.height - self.borderY self.contents = pbDoEnsureBitmap(self.contents, dwidth, dheight) self.contents.clear - for i in 0...@item_max + @item_max.times do |i| next if i < self.top_item || i > self.top_item + self.page_item_max drawItem(i, @item_max, itemRect(i)) end @@ -613,7 +613,7 @@ class PokemonPokedex_Scene # Draw selected option(s) text in top bar case mode when 2 # Type icons - for i in 0...2 + 2.times do |i| if !sel[i] || sel[i] < 0 textpos.push(["----", 298 + (128 * i), 58, 2, base, shadow, 1]) else @@ -695,7 +695,7 @@ class PokemonPokedex_Scene textpos.push([txt1, xpos1 + halfwidth, ypos1, 2, base, nil, 1]) textpos.push([txt2, xpos2 + halfwidth, ypos2, 2, base, nil, 1]) else - for i in 0...sel.length + sel.length.times do |i| selrect = Rect.new(0, selbuttony, @selbitmap.bitmap.width, selbuttonheight) if sel[i] >= 0 overlay.blt(xstart + ((sel[i] % cols) * xgap), ystart + ((sel[i] / cols).floor * ygap), @selbitmap.bitmap, selrect) @@ -707,7 +707,7 @@ class PokemonPokedex_Scene # Draw options case mode when 0, 1 # Order, name - for i in 0...cmds.length + cmds.length.times do |i| x = xstart + halfwidth + ((i % cols) * xgap) y = ystart + 6 + ((i / cols).floor * ygap) textpos.push([cmds[i], x, y, 2, base, shadow, 1]) @@ -718,14 +718,14 @@ class PokemonPokedex_Scene end when 2 # Type typerect = Rect.new(0, 0, 96, 32) - for i in 0...cmds.length + cmds.length.times do |i| typerect.y = @typeCommands[i].icon_position * 32 overlay.blt(xstart + 14 + ((i % cols) * xgap), ystart + 6 + ((i / cols).floor * ygap), @typebitmap.bitmap, typerect) end textpos.push(["----", xstart + halfwidth + ((cols - 1) * xgap), ystart + 6 + ((cmds.length / cols).floor * ygap), 2, base, shadow, 1]) when 5 # Color - for i in 0...cmds.length + cmds.length.times do |i| x = xstart + halfwidth + ((i % cols) * xgap) y = ystart + 6 + ((i / cols).floor * ygap) textpos.push([cmds[i].name, x, y, 2, base, shadow, 1]) @@ -734,7 +734,7 @@ class PokemonPokedex_Scene xstart + halfwidth + ((cols - 1) * xgap), ystart + 6 + ((cmds.length / cols).floor * ygap), 2, base, shadow, 1]) when 6 # Shape shaperect = Rect.new(0, 0, 60, 60) - for i in 0...cmds.length + cmds.length.times do |i| shaperect.y = @shapeCommands[i].icon_position * 60 overlay.blt(xstart + 4 + ((i % cols) * xgap), ystart + 4 + ((i / cols).floor * ygap), @shapebitmap.bitmap, shaperect) end @@ -838,7 +838,7 @@ class PokemonPokedex_Scene $PokemonGlobal.pokedexMode = MODENUMERICAL @searchParams = [$PokemonGlobal.pokedexMode, -1, -1, -1, -1, -1, -1, -1, -1, -1] pbRefreshDexList($PokemonGlobal.pokedexIndex[pbGetSavePositionIndex]) - for i in 0...@dexlist.length + @dexlist.length.times do |i| next if @dexlist[i][0] != oldspecies @sprites["pokedex"].index = i pbRefresh @@ -1202,7 +1202,7 @@ class PokemonPokedex_Scene params[9] = newparam[0] if newparam != nil pbRefreshDexSearch(params, index) when 7 # Clear filters - for i in 0...10 + 10.times do |i| params[i] = (i == 0) ? MODENUMERICAL : -1 end pbRefreshDexSearch(params, index) diff --git a/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb b/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb index 33f9ca06b..6a9af665e 100644 --- a/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb +++ b/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb @@ -26,7 +26,7 @@ class PokemonPokedexInfo_Scene @sprites["areamap"].setBitmap("Graphics/Pictures/#{@mapdata[@region][1]}") @sprites["areamap"].x += (Graphics.width - @sprites["areamap"].bitmap.width) / 2 @sprites["areamap"].y += (Graphics.height + 32 - @sprites["areamap"].bitmap.height) / 2 - for hidden in Settings::REGION_MAP_EXTRAS + Settings::REGION_MAP_EXTRAS.each do |hidden| if hidden[0] == @region && hidden[1] > 0 && $game_switches[hidden[1]] pbDrawImagePositions( @sprites["areamap"].bitmap, @@ -82,7 +82,7 @@ class PokemonPokedexInfo_Scene dexnumshift = true if dexnum > 0 && Settings::DEXES_WITH_OFFSETS.include?(-1) end else - for i in 0...$player.pokedex.dexes_count - 1 # Regional Dexes + ($player.pokedex.dexes_count - 1).times do |i| # Regional Dexes next if !$player.pokedex.unlocked?(i) num = pbGetRegionalNumber(i, species) next if num <= 0 @@ -158,7 +158,7 @@ class PokemonPokedexInfo_Scene real_gender = 2 if sp.gender_ratio == :Genderless ret.push([sp.form_name, real_gender, sp.form]) else # Both male and female - for real_gender in 0...2 + 2.times do |real_gender| next if !$player.pokedex.seen_form?(@species, real_gender, sp.form) && !Settings::DEX_SHOWS_ALL_FORMS ret.push([sp.form_name, real_gender, sp.form]) break if sp.form_name && !sp.form_name.empty? # Only show 1 entry for each non-0 form @@ -309,7 +309,7 @@ class PokemonPokedexInfo_Scene mappos = (map_metadata) ? map_metadata.town_map_position : nil next if !mappos || mappos[0] != @region showpoint = true - for loc in @mapdata[@region][2] + @mapdata[@region][2].each do |loc| showpoint = false if loc[0] == mappos[1] && loc[1] == mappos[2] && loc[7] && !$game_switches[loc[7]] end @@ -318,8 +318,8 @@ class PokemonPokedexInfo_Scene if mapsize && mapsize[0] && mapsize[0] > 0 sqwidth = mapsize[0] sqheight = (mapsize[1].length.to_f / mapsize[0]).ceil - for i in 0...sqwidth - for j in 0...sqheight + sqwidth.times do |i| + sqheight.times do |j| if mapsize[1][i + (j * sqwidth), 1].to_i > 0 points[mappos[1] + i + ((mappos[2] + j) * mapwidth)] = true end @@ -334,7 +334,7 @@ class PokemonPokedexInfo_Scene pointcolorhl = Color.new(192, 248, 248) sqwidth = PokemonRegionMap_Scene::SQUARE_WIDTH sqheight = PokemonRegionMap_Scene::SQUARE_HEIGHT - for j in 0...points.length + points.length.times do |j| if points[j] x = (j % mapwidth) * sqwidth x += (Graphics.width - @sprites["areamap"].bitmap.width) / 2 @@ -377,7 +377,7 @@ class PokemonPokedexInfo_Scene shadow = Color.new(168, 184, 184) # Write species and form name formname = "" - for i in @available + @available.each do |i| if i[1] == @gender && i[2] == @form formname = i[0] break @@ -415,7 +415,7 @@ class PokemonPokedexInfo_Scene def pbChooseForm index = 0 - for i in 0...@available.length + @available.length.times do |i| if @available[i][1] == @gender && @available[i][2] == @form index = i break diff --git a/Data/Scripts/016_UI/005_UI_Party.rb b/Data/Scripts/016_UI/005_UI_Party.rb index e90a3db5a..466d36781 100644 --- a/Data/Scripts/016_UI/005_UI_Party.rb +++ b/Data/Scripts/016_UI/005_UI_Party.rb @@ -108,7 +108,7 @@ end class Window_CommandPokemonColor < Window_CommandPokemon def initialize(commands, width = nil) @colorKey = [] - for i in 0...commands.length + commands.length.times do |i| if commands[i].is_a?(Array) @colorKey[i] = commands[i][1] commands[i] = commands[i][0] @@ -472,7 +472,7 @@ class PokemonParty_Scene pbBottomLeftLines(@sprites["helpwindow"], 1) pbSetHelpText(starthelptext) # Add party Pokémon sprites - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| if @party[i] @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i], i, @viewport) else @@ -599,7 +599,7 @@ class PokemonParty_Scene end def pbAnnotate(annot) - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| @sprites["pokemon#{i}"].text = (annot) ? annot[i] : nil end end @@ -607,7 +607,7 @@ class PokemonParty_Scene def pbSelect(item) @activecmd = item numsprites = Settings::MAX_PARTY_SIZE + ((@multiselect) ? 2 : 1) - for i in 0...numsprites + numsprites.times do |i| @sprites["pokemon#{i}"].selected = (i == @activecmd) end end @@ -646,7 +646,7 @@ class PokemonParty_Scene Input.update self.update end - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| @sprites["pokemon#{i}"].preselected = false @sprites["pokemon#{i}"].switching = false end @@ -654,7 +654,7 @@ class PokemonParty_Scene end def pbClearSwitching - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| @sprites["pokemon#{i}"].preselected = false @sprites["pokemon#{i}"].switching = false end @@ -700,7 +700,7 @@ class PokemonParty_Scene end def pbChoosePokemon(switching = false, initialsel = -1, canswitch = 0) - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| @sprites["pokemon#{i}"].preselected = (switching && i == @activecmd) @sprites["pokemon#{i}"].switching = switching end @@ -722,7 +722,7 @@ class PokemonParty_Scene if @activecmd != oldsel # Changing selection pbPlayCursorSE numsprites = Settings::MAX_PARTY_SIZE + ((@multiselect) ? 2 : 1) - for i in 0...numsprites + numsprites.times do |i| @sprites["pokemon#{i}"].selected = (i == @activecmd) end end @@ -759,17 +759,19 @@ class PokemonParty_Scene numsprites = Settings::MAX_PARTY_SIZE + ((@multiselect) ? 2 : 1) case key when Input::LEFT - begin + loop do currentsel -= 1 - end while currentsel > 0 && currentsel < @party.length && !@party[currentsel] + break unless currentsel > 0 && currentsel < @party.length && !@party[currentsel] + end if currentsel >= @party.length && currentsel < Settings::MAX_PARTY_SIZE currentsel = @party.length - 1 end currentsel = numsprites - 1 if currentsel < 0 when Input::RIGHT - begin + loop do currentsel += 1 - end while currentsel < @party.length && !@party[currentsel] + break unless currentsel < @party.length && !@party[currentsel] + end if currentsel == @party.length currentsel = Settings::MAX_PARTY_SIZE elsif currentsel == numsprites @@ -782,9 +784,10 @@ class PokemonParty_Scene currentsel -= 1 end else - begin + loop do currentsel -= 2 - end while currentsel > 0 && !@party[currentsel] + break unless currentsel > 0 && !@party[currentsel] + end end if currentsel >= @party.length && currentsel < Settings::MAX_PARTY_SIZE currentsel = @party.length - 1 @@ -809,14 +812,14 @@ class PokemonParty_Scene def pbHardRefresh oldtext = [] lastselected = -1 - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| oldtext.push(@sprites["pokemon#{i}"].text) lastselected = i if @sprites["pokemon#{i}"].selected @sprites["pokemon#{i}"].dispose end lastselected = @party.length - 1 if lastselected >= @party.length lastselected = 0 if lastselected < 0 - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| if @party[i] @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i], i, @viewport) else @@ -828,7 +831,7 @@ class PokemonParty_Scene end def pbRefresh - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| sprite = @sprites["pokemon#{i}"] if sprite if sprite.is_a?(PokemonPartyPanel) @@ -943,8 +946,8 @@ class PokemonPartyScreen # Checks for identical species def pbCheckSpecies(array) # Unused - for i in 0...array.length - for j in i + 1...array.length + array.length.times do |i| + (i + 1...array.length).each do |j| return false if array[i].species == array[j].species end end @@ -953,9 +956,9 @@ class PokemonPartyScreen # Checks for identical held items def pbCheckItems(array) # Unused - for i in 0...array.length + array.length.times do |i| next if !array[i].hasItem? - for j in i + 1...array.length + (i + 1...array.length).each do |j| return false if array[i].item == array[j].item end end @@ -974,7 +977,7 @@ class PokemonPartyScreen def pbChooseMove(pokemon, helptext, index = 0) movenames = [] - for i in pokemon.moves + pokemon.moves.each do |i| next if !i || !i.id if i.total_pp <= 0 movenames.push(_INTL("{1} (PP: ---)", i.name)) @@ -988,7 +991,7 @@ class PokemonPartyScreen def pbRefreshAnnotations(ableProc) # For after using an evolution stone return if !@scene.pbHasAnnotations? annot = [] - for pkmn in @party + @party.each do |pkmn| elig = ableProc.call(pkmn) annot.push((elig) ? _INTL("ABLE") : _INTL("NOT ABLE")) end @@ -1006,7 +1009,7 @@ class PokemonPartyScreen positions = [_INTL("FIRST"), _INTL("SECOND"), _INTL("THIRD"), _INTL("FOURTH"), _INTL("FIFTH"), _INTL("SIXTH"), _INTL("SEVENTH"), _INTL("EIGHTH"), _INTL("NINTH"), _INTL("TENTH"), _INTL("ELEVENTH"), _INTL("TWELFTH")] - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| if i < positions.length ordinals.push(positions[i]) else @@ -1016,25 +1019,25 @@ class PokemonPartyScreen return nil if !ruleset.hasValidTeam?(@party) ret = nil addedEntry = false - for i in 0...@party.length + @party.length.times do |i| statuses[i] = (ruleset.isPokemonValid?(@party[i])) ? 1 : 2 annot[i] = ordinals[statuses[i]] end @scene.pbStartScene(@party, _INTL("Choose Pokémon and confirm."), annot, true) loop do realorder = [] - for i in 0...@party.length - for j in 0...@party.length + @party.length.times do |i| + @party.length.times do |j| if statuses[j] == i + 3 realorder.push(j) break end end end - for i in 0...realorder.length + realorder.length.times do |i| statuses[realorder[i]] = i + 3 end - for i in 0...@party.length + @party.length.times do |i| annot[i] = ordinals[statuses[i]] end @scene.pbAnnotate(annot) @@ -1046,7 +1049,7 @@ class PokemonPartyScreen addedEntry = false if pkmnid == Settings::MAX_PARTY_SIZE # Confirm was chosen ret = [] - for i in realorder + realorder.each do |i| ret.push(@party[i]) end error = [] @@ -1092,7 +1095,7 @@ class PokemonPartyScreen def pbChooseAblePokemon(ableProc, allowIneligible = false) annot = [] eligibility = [] - for pkmn in @party + @party.each do |pkmn| elig = ableProc.call(pkmn) eligibility.push(elig) annot.push((elig) ? _INTL("ABLE") : _INTL("NOT ABLE")) @@ -1123,7 +1126,7 @@ class PokemonPartyScreen def pbChooseTradablePokemon(ableProc, allowIneligible = false) annot = [] eligibility = [] - for pkmn in @party + @party.each do |pkmn| elig = ableProc.call(pkmn) elig = false if pkmn.egg? || pkmn.shadowPokemon? || pkmn.cannot_trade eligibility.push(elig) diff --git a/Data/Scripts/016_UI/006_UI_Summary.rb b/Data/Scripts/016_UI/006_UI_Summary.rb index 63513702d..43938b747 100644 --- a/Data/Scripts/016_UI/006_UI_Summary.rb +++ b/Data/Scripts/016_UI/006_UI_Summary.rb @@ -402,7 +402,7 @@ class PokemonSummary_Scene dexnum = @nationalDexList.index(@pokemon.species_data.species) || 0 dexnumshift = true if Settings::DEXES_WITH_OFFSETS.include?(-1) else - for i in 0...$player.pokedex.dexes_count - 1 + ($player.pokedex.dexes_count - 1).times do |i| next if !$player.pokedex.unlocked?(i) num = pbGetRegionalNumber(i, @pokemon.species) next if num <= 0 @@ -578,7 +578,7 @@ class PokemonSummary_Scene best_iv = 0 stats_order = [:HP, :ATTACK, :DEFENSE, :SPEED, :SPECIAL_ATTACK, :SPECIAL_DEFENSE] start_point = @pokemon.personalID % stats_order.length # Tiebreaker - for i in 0...stats_order.length + stats_order.length.times do |i| stat = stats_order[(i + start_point) % stats_order.length] if !best_stat || @pokemon.iv[stat] > @pokemon.iv[best_stat] best_stat = stat @@ -694,7 +694,7 @@ class PokemonSummary_Scene imagepos = [] # Write move names, types and PP amounts for each known move yPos = 92 - for i in 0...Pokemon::MAX_MOVES + Pokemon::MAX_MOVES.times do |i| move = @pokemon.moves[i] if move type_number = GameData::Type.get(move.display_type(@pokemon)).icon_position @@ -756,7 +756,7 @@ class PokemonSummary_Scene yPos = 92 yPos -= 76 if move_to_learn limit = (move_to_learn) ? Pokemon::MAX_MOVES + 1 : Pokemon::MAX_MOVES - for i in 0...limit + limit.times do |i| move = @pokemon.moves[i] if i == Pokemon::MAX_MOVES move = move_to_learn @@ -842,7 +842,7 @@ class PokemonSummary_Scene # Show all ribbons imagepos = [] coord = 0 - for i in @ribbonOffset * 4...(@ribbonOffset * 4) + 12 + (@ribbonOffset * 4...(@ribbonOffset * 4) + 12).each do |i| break if !@pokemon.ribbons[i] ribbon_data = GameData::Ribbon.get(@pokemon.ribbons[i]) ribn = ribbon_data.icon_position diff --git a/Data/Scripts/016_UI/007_UI_Bag.rb b/Data/Scripts/016_UI/007_UI_Bag.rb index 26acab70c..9ed2beabc 100644 --- a/Data/Scripts/016_UI/007_UI_Bag.rb +++ b/Data/Scripts/016_UI/007_UI_Bag.rb @@ -82,11 +82,13 @@ class Window_PokemonBag < Window_DrawableCommand if @bag.registered?(item) pbDrawImagePositions( self.contents, - [["Graphics/Pictures/Bag/icon_register", rect.x + rect.width - 72, rect.y + 8, 0, 0, -1, 24]]) + [["Graphics/Pictures/Bag/icon_register", rect.x + rect.width - 72, rect.y + 8, 0, 0, -1, 24]] + ) elsif pbCanRegisterItem?(item) pbDrawImagePositions( self.contents, - [["Graphics/Pictures/Bag/icon_register", rect.x + rect.width - 72, rect.y + 8, 0, 24, -1, 24]]) + [["Graphics/Pictures/Bag/icon_register", rect.x + rect.width - 72, rect.y + 8, 0, 24, -1, 24]] + ) end else qty = (@filterlist) ? thispocket[@filterlist[@pocket][index]][1] : thispocket[index][1] @@ -105,7 +107,7 @@ class Window_PokemonBag < Window_DrawableCommand dheight = self.height - self.borderY self.contents = pbDoEnsureBitmap(self.contents, dwidth, dheight) self.contents.clear - for i in 0...@item_max + @item_max.times do |i| next if i < self.top_item - 1 || i > self.top_item + self.page_item_max drawItem(i, @item_max, itemRect(i)) end @@ -147,18 +149,18 @@ class PokemonBag_Scene if @choosing numfilledpockets = 0 if @filterlist != nil - for i in 1...@bag.pockets.length + (1...@bag.pockets.length).each do |i| numfilledpockets += 1 if @filterlist[i].length > 0 end else - for i in 1...@bag.pockets.length + (1...@bag.pockets.length).each do |i| numfilledpockets += 1 if @bag.pockets[i].length > 0 end end lastpocket = (resetpocket) ? 1 : @bag.last_viewed_pocket if (@filterlist && @filterlist[lastpocket].length == 0) || (!@filterlist && @bag.pockets[lastpocket].length == 0) - for i in 1...@bag.pockets.length + (1...@bag.pockets.length).each do |i| if @filterlist && @filterlist[i].length > 0 lastpocket = i break @@ -267,7 +269,7 @@ class PokemonBag_Scene # Draw the pocket icons @sprites["pocketicon"].bitmap.clear if @choosing && @filterlist - for i in 1...@bag.pockets.length + (1...@bag.pockets.length).each do |i| if @filterlist[i].length == 0 @sprites["pocketicon"].bitmap.blt( 6 + ((i - 1) * 22), 6, @pocketbitmap.bitmap, Rect.new((i - 1) * 20, 28, 20, 20) @@ -292,7 +294,8 @@ class PokemonBag_Scene # Draw the pocket name pbDrawTextPositions( overlay, - [[PokemonBag.pocket_names[@bag.last_viewed_pocket - 1], 94, 176, 2, POCKETNAMEBASECOLOR, POCKETNAMESHADOWCOLOR]]) + [[PokemonBag.pocket_names[@bag.last_viewed_pocket - 1], 94, 176, 2, POCKETNAMEBASECOLOR, POCKETNAMESHADOWCOLOR]] + ) # Draw slider arrows showslider = false if itemlist.top_row > 0 @@ -332,9 +335,9 @@ class PokemonBag_Scene return if !@choosing return if @filterproc == nil @filterlist = [] - for i in 1...@bag.pockets.length + (1...@bag.pockets.length).each do |i| @filterlist[i] = [] - for j in 0...@bag.pockets[i].length + @bag.pockets[i].length.times do |j| @filterlist[i].push(j) if @filterproc.call(@bag.pockets[i][j][0]) end end diff --git a/Data/Scripts/016_UI/008_UI_Pokegear.rb b/Data/Scripts/016_UI/008_UI_Pokegear.rb index 49f9cd905..9bad70199 100644 --- a/Data/Scripts/016_UI/008_UI_Pokegear.rb +++ b/Data/Scripts/016_UI/008_UI_Pokegear.rb @@ -57,7 +57,7 @@ end #=============================================================================== class PokemonPokegear_Scene def pbUpdate - for i in 0...@commands.length + @commands.length.times do |i| @sprites["button#{i}"].selected = (i == @index) end pbUpdateSpriteHash(@sprites) @@ -75,7 +75,7 @@ class PokemonPokegear_Scene else @sprites["background"].setBitmap("Graphics/Pictures/Pokegear/bg") end - for i in 0...@commands.length + @commands.length.times do |i| y = 196 - (@commands.length * 24) + (i * 48) @sprites["button#{i}"] = PokegearButton.new(@commands[i], 118, y, @viewport) end diff --git a/Data/Scripts/016_UI/009_UI_RegionMap.rb b/Data/Scripts/016_UI/009_UI_RegionMap.rb index 6405ca659..ceb7ea0be 100644 --- a/Data/Scripts/016_UI/009_UI_RegionMap.rb +++ b/Data/Scripts/016_UI/009_UI_RegionMap.rb @@ -118,7 +118,8 @@ class PokemonRegionMap_Scene end pbDrawImagePositions( @sprites["map2"].bitmap, - [["Graphics/Pictures/#{graphic[4]}", graphic[2] * SQUARE_WIDTH, graphic[3] * SQUARE_HEIGHT]]) + [["Graphics/Pictures/#{graphic[4]}", graphic[2] * SQUARE_WIDTH, graphic[3] * SQUARE_HEIGHT]] + ) end @sprites["mapbottom"] = MapBottomSprite.new(@viewport) @sprites["mapbottom"].mapname = pbGetMessage(MessageTypes::RegionNames, mapindex) @@ -179,14 +180,14 @@ class PokemonRegionMap_Scene def pbSaveMapData File.open("PBS/town_map.txt", "wb") { |f| Compiler.add_PBS_header_to_file(f) - for i in 0...@map_data.length + @map_data.length.times do |i| map = @map_data[i] next if !map f.write("\#-------------------------------\r\n") f.write(sprintf("[%d]\r\n", i)) f.write(sprintf("Name = %s\r\nFilename = %s\r\n", Compiler.csvQuote(map[0]), Compiler.csvQuote(map[1]))) - for loc in map[2] + map[2].each do |loc| f.write("Point = ") Compiler.pbWriteCsvRecord(loc, f, [nil, "uussUUUU"]) f.write("\r\n") @@ -197,7 +198,7 @@ class PokemonRegionMap_Scene def pbGetMapLocation(x, y) return "" if !@map[2] - for point in @map[2] + @map[2].each do |point| next if point[0] != x || point[1] != y return "" if point[7] && (@wallmap || point[7] <= 0 || !$game_switches[point[7]]) name = pbGetMessageFromHash(MessageTypes::PlaceNames, point[2]) @@ -225,7 +226,7 @@ class PokemonRegionMap_Scene def pbGetMapDetails(x, y) # From Wichu, with my help return "" if !@map[2] - for point in @map[2] + @map[2].each do |point| next if point[0] != x || point[1] != y return "" if point[7] && (@wallmap || point[7] <= 0 || !$game_switches[point[7]]) mapdesc = pbGetMessageFromHash(MessageTypes::PlaceDescriptions, point[3]) @@ -236,7 +237,7 @@ class PokemonRegionMap_Scene def pbGetHealingSpot(x, y) return nil if !@map[2] - for point in @map[2] + @map[2].each do |point| next if point[0] != x || point[1] != y return nil if point[7] && (@wallmap || point[7] <= 0 || !$game_switches[point[7]]) return (point[4] && point[5] && point[6]) ? [point[4], point[5], point[6]] : nil @@ -250,7 +251,8 @@ class PokemonRegionMap_Scene text = (@mode == 0) ? _INTL("ACTION: Fly") : _INTL("ACTION: Cancel Fly") pbDrawTextPositions( @sprites["help"].bitmap, - [[text, Graphics.width - 16, -8, 1, Color.new(248, 248, 248), Color.new(0, 0, 0)]]) + [[text, Graphics.width - 16, -8, 1, Color.new(248, 248, 248), Color.new(0, 0, 0)]] + ) @sprites.each do |key, sprite| next if !key.include?("point") sprite.visible = (@mode == 1) diff --git a/Data/Scripts/016_UI/010_UI_Phone.rb b/Data/Scripts/016_UI/010_UI_Phone.rb index 553a0ccca..5dbae2e23 100644 --- a/Data/Scripts/016_UI/010_UI_Phone.rb +++ b/Data/Scripts/016_UI/010_UI_Phone.rb @@ -25,7 +25,7 @@ class PokemonPhoneScene commands = [] @trainers = [] if $PokemonGlobal.phoneNumbers - for num in $PokemonGlobal.phoneNumbers + $PokemonGlobal.phoneNumbers.each do |num| if num[0] # if visible if num.length == 8 # if trainer @trainers.push([num[1], num[2], num[6], (num[4] >= 2)]) @@ -67,7 +67,7 @@ class PokemonPhoneScene @sprites["icon"].x = 86 - (charwidth / 8) @sprites["icon"].y = 134 - (charheight / 8) @sprites["icon"].src_rect = Rect.new(0, 0, charwidth / 4, charheight / 4) - for trainer in @trainers + @trainers.each do |trainer| if trainer.length == 4 displayname = _INTL("{1} {2}", GameData::TrainerType.get(trainer[0]).name, pbGetMessageFromHash(MessageTypes::TrainerNames, trainer[1])) @@ -77,7 +77,7 @@ class PokemonPhoneScene end end @sprites["list"].commands = commands - for i in 0...@sprites["list"].page_item_max + @sprites["list"].page_item_max.times do |i| @sprites["rematch[#{i}]"] = IconSprite.new(468, 62 + (i * 32), @viewport) j = i + @sprites["list"].top_item next if j >= commands.length @@ -89,7 +89,7 @@ class PokemonPhoneScene end end rematchcount = 0 - for trainer in @trainers + @trainers.each do |trainer| if trainer.length == 4 rematchcount += 1 if trainer[3] end @@ -120,7 +120,7 @@ class PokemonPhoneScene @sprites["icon"].src_rect = Rect.new(0, 0, charwidth / 4, charheight / 4) mapname = (trainer[2]) ? pbGetMapNameFromId(trainer[2]) : "" @sprites["bottom"].text = "" + mapname - for i in 0...@sprites["list"].page_item_max + @sprites["list"].page_item_max.times do |i| @sprites["rematch[#{i}]"].clearBitmaps j = i + @sprites["list"].top_item next if j >= commands.length diff --git a/Data/Scripts/016_UI/012_UI_TrainerCard.rb b/Data/Scripts/016_UI/012_UI_TrainerCard.rb index 8f4d83a94..21f9f38a4 100644 --- a/Data/Scripts/016_UI/012_UI_TrainerCard.rb +++ b/Data/Scripts/016_UI/012_UI_TrainerCard.rb @@ -66,7 +66,7 @@ class PokemonTrainerCard_Scene x = 72 region = pbGetCurrentRegion(0) # Get the current region imagePositions = [] - for i in 0...8 + 8.times do |i| if $player.badges[i + (region * 8)] imagePositions.push(["Graphics/Pictures/Trainer Card/icon_badges", x, 310, i * 32, region * 32, 32, 32]) end diff --git a/Data/Scripts/016_UI/013_UI_Load.rb b/Data/Scripts/016_UI/013_UI_Load.rb index a20140ec7..5a87f988e 100644 --- a/Data/Scripts/016_UI/013_UI_Load.rb +++ b/Data/Scripts/016_UI/013_UI_Load.rb @@ -105,7 +105,7 @@ class PokemonLoad_Scene @viewport.z = 99998 addBackgroundOrColoredPlane(@sprites, "background", "loadbg", Color.new(248, 248, 248), @viewport) y = 16 * 2 - for i in 0...commands.length + commands.length.times do |i| @sprites["panel#{i}"] = PokemonLoadPanel.new( i, commands[i], (show_continue) ? (i == 0) : false, trainer, frame_count, stats, map_id, @viewport @@ -141,20 +141,20 @@ class PokemonLoad_Scene @sprites["panel#{newi}"].selected = true @sprites["panel#{newi}"].pbRefresh while @sprites["panel#{newi}"].y > Graphics.height - (40 * 2) - for i in 0...@commands.length + @commands.length.times do |i| @sprites["panel#{i}"].y -= 24 * 2 end - for i in 0...6 + 6.times do |i| break if !@sprites["party#{i}"] @sprites["party#{i}"].y -= 24 * 2 end @sprites["player"].y -= 24 * 2 if @sprites["player"] end while @sprites["panel#{newi}"].y < 16 * 2 - for i in 0...@commands.length + @commands.length.times do |i| @sprites["panel#{i}"].y += 24 * 2 end - for i in 0...6 + 6.times do |i| break if !@sprites["party#{i}"] @sprites["party#{i}"].y += 24 * 2 end @@ -175,8 +175,8 @@ class PokemonLoad_Scene @sprites["player"].y = (56 * 2) - (charheight / 8) @sprites["player"].src_rect = Rect.new(0, 0, charwidth / 4, charheight / 4) end - for i in 0...trainer.party.length - @sprites["party#{i}"] = PokemonIconSprite.new(trainer.party[i], @viewport) + trainer.party.each_with_index do |pkmn, i| + @sprites["party#{i}"] = PokemonIconSprite.new(pkmn, @viewport) @sprites["party#{i}"].setOffset(PictureOrigin::Center) @sprites["party#{i}"].x = (167 + (33 * (i % 2))) * 2 @sprites["party#{i}"].y = (56 + (25 * (i / 2))) * 2 diff --git a/Data/Scripts/016_UI/014_UI_Save.rb b/Data/Scripts/016_UI/014_UI_Save.rb index 274f7a1fe..d126894c2 100644 --- a/Data/Scripts/016_UI/014_UI_Save.rb +++ b/Data/Scripts/016_UI/014_UI_Save.rb @@ -6,8 +6,10 @@ def pbEmergencySave if SaveData.exists? File.open(SaveData::FILE_PATH, 'rb') do |r| File.open(SaveData::FILE_PATH + '.bak', 'wb') do |w| - while s = r.read(4096) - w.write s + loop do + s = r.read(4096) + break if !s + w.write(s) end end end diff --git a/Data/Scripts/016_UI/015_UI_Options.rb b/Data/Scripts/016_UI/015_UI_Options.rb index 2f9736a2d..75c1db9ac 100644 --- a/Data/Scripts/016_UI/015_UI_Options.rb +++ b/Data/Scripts/016_UI/015_UI_Options.rb @@ -179,7 +179,7 @@ class Window_PokemonOption < Window_DrawableCommand @selShadowColor = Color.new(31 * 8, 17 * 8, 16 * 8) @optvalues = [] @mustUpdateOptions = false - for i in 0...@options.length + @options.length.times do |i| @optvalues[i] = 0 end super(x, y, width, height) @@ -213,14 +213,14 @@ class Window_PokemonOption < Window_DrawableCommand when EnumOption if @options[index].values.length > 1 totalwidth = 0 - for value in @options[index].values + @options[index].values.each do |value| totalwidth += self.contents.text_size(value).width end spacing = (optionwidth - totalwidth) / (@options[index].values.length - 1) spacing = 0 if spacing < 0 xpos = optionwidth + rect.x ivalue = 0 - for value in @options[index].values + @options[index].values.each do |value| pbDrawShadowText(self.contents, xpos, rect.y, optionwidth, rect.height, value, (ivalue == self[index]) ? @selBaseColor : self.baseColor, (ivalue == self[index]) ? @selShadowColor : self.shadowColor) @@ -391,7 +391,7 @@ class PokemonOption_Scene @sprites["option"].viewport = @viewport @sprites["option"].visible = true # Get the values of each option - for i in 0...@PokemonOptions.length + @PokemonOptions.length.times do |i| @sprites["option"].setValueNoRefresh(i, (@PokemonOptions[i].get || 0)) end @sprites["option"].refresh @@ -413,7 +413,7 @@ class PokemonOption_Scene pbUpdate if @sprites["option"].mustUpdateOptions # Set the values of each option - for i in 0...@PokemonOptions.length + @PokemonOptions.length.times do |i| @PokemonOptions[i].set(@sprites["option"][i]) end if $PokemonSystem.textskin != oldTextSkin @@ -440,7 +440,7 @@ class PokemonOption_Scene pbPlayCloseMenuSE pbFadeOutAndHide(@sprites) { pbUpdate } # Set the values of each option - for i in 0...@PokemonOptions.length + @PokemonOptions.length.times do |i| @PokemonOptions[i].set(@sprites["option"][i]) end pbDisposeMessageWindow(@sprites["textbox"]) diff --git a/Data/Scripts/016_UI/016_UI_ReadyMenu.rb b/Data/Scripts/016_UI/016_UI_ReadyMenu.rb index 800a73f47..afc272be6 100644 --- a/Data/Scripts/016_UI/016_UI_ReadyMenu.rb +++ b/Data/Scripts/016_UI/016_UI_ReadyMenu.rb @@ -104,10 +104,10 @@ class PokemonReadyMenu_Scene @commands = commands @movecommands = [] @itemcommands = [] - for i in 0...@commands[0].length + @commands[0].length.times do |i| @movecommands.push(@commands[0][i][1]) end - for i in 0...@commands[1].length + @commands[1].length.times do |i| @itemcommands.push(@commands[1][i][1]) end @index = $bag.ready_menu_selection @@ -129,10 +129,10 @@ class PokemonReadyMenu_Scene @sprites["cmdwindow"].height = 6 * 32 @sprites["cmdwindow"].visible = false @sprites["cmdwindow"].viewport = @viewport - for i in 0...@commands[0].length + @commands[0].length.times do |i| @sprites["movebutton#{i}"] = ReadyMenuButton.new(i, @commands[0][i], @index[0], @index[2], @viewport) end - for i in 0...@commands[1].length + @commands[1].length.times do |i| @sprites["itembutton#{i}"] = ReadyMenuButton.new(i, @commands[1][i], @index[1], @index[2], @viewport) end pbSEPlay("GUI menu open") @@ -140,20 +140,20 @@ class PokemonReadyMenu_Scene def pbShowMenu @sprites["cmdwindow"].visible = false - for i in 0...@commands[0].length + @commands[0].length.times do |i| @sprites["movebutton#{i}"].visible = true end - for i in 0...@commands[1].length + @commands[1].length.times do |i| @sprites["itembutton#{i}"].visible = true end end def pbHideMenu @sprites["cmdwindow"].visible = false - for i in 0...@commands[0].length + @commands[0].length.times do |i| @sprites["movebutton#{i}"].visible = false end - for i in 0...@commands[1].length + @commands[1].length.times do |i| @sprites["itembutton#{i}"].visible = false end end @@ -190,10 +190,10 @@ class PokemonReadyMenu_Scene end def pbChangeSide - for i in 0...@commands[0].length + @commands[0].length.times do |i| @sprites["movebutton#{i}"].side = @index[2] end - for i in 0...@commands[1].length + @commands[1].length.times do |i| @sprites["itembutton#{i}"].side = @index[2] end @sprites["cmdwindow"].commands = (@index[2] == 0) ? @movecommands : @itemcommands @@ -208,11 +208,11 @@ class PokemonReadyMenu_Scene if @index[@index[2]] != oldindex case @index[2] when 0 - for i in 0...@commands[0].length + @commands[0].length.times do |i| @sprites["movebutton#{i}"].selected = @index[@index[2]] end when 1 - for i in 0...@commands[1].length + @commands[1].length.times do |i| @sprites["itembutton#{i}"].selected = @index[@index[2]] end end @@ -243,11 +243,11 @@ class PokemonReadyMenu def pbStartReadyMenu(moves, items) commands = [[], []] # Moves, items - for i in moves + moves.each do |i| commands[0].push([i[0], GameData::Move.get(i[0]).name, true, i[1]]) end commands[0].sort! { |a, b| a[1] <=> b[1] } - for i in items + items.each do |i| commands[1].push([i, GameData::Item.get(i).name, false]) end commands[1].sort! { |a, b| a[1] <=> b[1] } @@ -313,7 +313,7 @@ def pbUseKeyItem end end real_items = [] - for i in $bag.registered_items + $bag.registered_items.each do |i| itm = GameData::Item.get(i).id real_items.push(itm) if $bag.has?(itm) end diff --git a/Data/Scripts/016_UI/017_UI_PokemonStorage.rb b/Data/Scripts/016_UI/017_UI_PokemonStorage.rb index dae4f82fe..b702ad12a 100644 --- a/Data/Scripts/016_UI/017_UI_PokemonStorage.rb +++ b/Data/Scripts/016_UI/017_UI_PokemonStorage.rb @@ -299,7 +299,7 @@ class PokemonBoxSprite < SpriteWrapper @refreshBox = true @refreshSprites = true @pokemonsprites = [] - for i in 0...PokemonBox::BOX_SIZE + PokemonBox::BOX_SIZE.times do |i| @pokemonsprites[i] = nil pokemon = @storage[boxnumber, i] @pokemonsprites[i] = PokemonBoxIcon.new(pokemon, viewport) @@ -313,7 +313,7 @@ class PokemonBoxSprite < SpriteWrapper def dispose if !disposed? - for i in 0...PokemonBox::BOX_SIZE + PokemonBox::BOX_SIZE.times do |i| @pokemonsprites[i].dispose if @pokemonsprites[i] @pokemonsprites[i] = nil end @@ -336,7 +336,7 @@ class PokemonBoxSprite < SpriteWrapper def color=(value) super if @refreshSprites - for i in 0...PokemonBox::BOX_SIZE + PokemonBox::BOX_SIZE.times do |i| if @pokemonsprites[i] && !@pokemonsprites[i].disposed? @pokemonsprites[i].color = value end @@ -347,7 +347,7 @@ class PokemonBoxSprite < SpriteWrapper def visible=(value) super - for i in 0...PokemonBox::BOX_SIZE + PokemonBox::BOX_SIZE.times do |i| if @pokemonsprites[i] && !@pokemonsprites[i].disposed? @pokemonsprites[i].visible = value end @@ -414,9 +414,9 @@ class PokemonBoxSprite < SpriteWrapper @refreshBox = false end yval = self.y + 30 - for j in 0...PokemonBox::BOX_HEIGHT + PokemonBox::BOX_HEIGHT.times do |j| xval = self.x + 10 - for k in 0...PokemonBox::BOX_WIDTH + PokemonBox::BOX_WIDTH.times do |k| sprite = @pokemonsprites[(j * PokemonBox::BOX_WIDTH) + k] if sprite && !sprite.disposed? sprite.viewport = self.viewport @@ -432,7 +432,7 @@ class PokemonBoxSprite < SpriteWrapper def update super - for i in 0...PokemonBox::BOX_SIZE + PokemonBox::BOX_SIZE.times do |i| if @pokemonsprites[i] && !@pokemonsprites[i].disposed? @pokemonsprites[i].update end @@ -449,7 +449,7 @@ class PokemonBoxPartySprite < SpriteWrapper @party = party @boxbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/overlay_party") @pokemonsprites = [] - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| @pokemonsprites[i] = nil pokemon = @party[i] if pokemon @@ -465,7 +465,7 @@ class PokemonBoxPartySprite < SpriteWrapper end def dispose - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| @pokemonsprites[i].dispose if @pokemonsprites[i] end @boxbitmap.dispose @@ -485,7 +485,7 @@ class PokemonBoxPartySprite < SpriteWrapper def color=(value) super - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| if @pokemonsprites[i] && !@pokemonsprites[i].disposed? @pokemonsprites[i].color = pbSrcOver(@pokemonsprites[i].color, value) end @@ -494,7 +494,7 @@ class PokemonBoxPartySprite < SpriteWrapper def visible=(value) super - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| if @pokemonsprites[i] && !@pokemonsprites[i].disposed? @pokemonsprites[i].visible = value end @@ -535,13 +535,13 @@ class PokemonBoxPartySprite < SpriteWrapper ) xvalues = [] # [18, 90, 18, 90, 18, 90] yvalues = [] # [2, 18, 66, 82, 130, 146] - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| xvalues.push(18 + (72 * (i % 2))) yvalues.push(2 + (16 * (i % 2)) + (64 * (i / 2))) end @pokemonsprites.delete_if { |sprite| sprite && sprite.disposed? } @pokemonsprites.each { |sprite| sprite.refresh if sprite } - for j in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |j| sprite = @pokemonsprites[j] if sprite && !sprite.disposed? sprite.viewport = self.viewport @@ -554,7 +554,7 @@ class PokemonBoxPartySprite < SpriteWrapper def update super - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| @pokemonsprites[i].update if @pokemonsprites[i] && !@pokemonsprites[i].disposed? end end @@ -775,7 +775,7 @@ class PokemonStorageScene return if selection < 0 xvalues = [] # [200, 272, 200, 272, 200, 272, 236] yvalues = [] # [2, 18, 66, 82, 130, 146, 220] - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| xvalues.push(200 + (72 * (i % 2))) yvalues.push(2 + (16 * (i % 2)) + (64 * (i / 2))) end @@ -1196,7 +1196,7 @@ class PokemonStorageScene def pbChooseBox(msg) commands = [] - for i in 0...@storage.maxBoxes + @storage.maxBoxes.times do |i| box = @storage[i] if box commands.push(_INTL("{1} ({2}/{3})", box.name, box.nitems, box.length)) @@ -1527,7 +1527,6 @@ class PokemonStorageScreen cmdMark = -1 cmdRelease = -1 cmdDebug = -1 - cmdCancel = -1 if heldpoke helptext = _INTL("{1} is selected.", heldpoke.name) commands[cmdMove = commands.length] = (pokemon) ? _INTL("Shift") : _INTL("Place") @@ -1541,7 +1540,7 @@ class PokemonStorageScreen commands[cmdMark = commands.length] = _INTL("Mark") commands[cmdRelease = commands.length] = _INTL("Release") commands[cmdDebug = commands.length] = _INTL("Debug") if $DEBUG - commands[cmdCancel = commands.length] = _INTL("Cancel") + commands[commands.length] = _INTL("Cancel") command = pbShowCommands(helptext, commands) if cmdMove >= 0 && command == cmdMove # Move/Shift/Place if @heldpkmn @@ -1674,7 +1673,7 @@ class PokemonStorageScreen def pbAbleCount count = 0 - for p in @storage.party + @storage.party.each do |p| count += 1 if pbAble?(p) end return count @@ -1869,7 +1868,7 @@ class PokemonStorageScreen def pbChooseMove(pkmn, helptext, index = 0) movenames = [] - for i in pkmn.moves + pkmn.moves.each do |i| if i.total_pp <= 0 movenames.push(_INTL("{1} (PP: ---)", i.name)) else @@ -1938,7 +1937,7 @@ class PokemonStorageScreen when 1 papers = @storage.availableWallpapers index = 0 - for i in 0...papers[1].length + papers[1].length.times do |i| if papers[1][i] == @storage[@storage.currentBox].background index = i break diff --git a/Data/Scripts/016_UI/019_UI_PC.rb b/Data/Scripts/016_UI/019_UI_PC.rb index 10ebe7610..1410078f1 100644 --- a/Data/Scripts/016_UI/019_UI_PC.rb +++ b/Data/Scripts/016_UI/019_UI_PC.rb @@ -54,7 +54,7 @@ class StorageSystemPC end when 2 # Deposit count = 0 - for p in $PokemonStorage.party + $PokemonStorage.party.each do |p| count += 1 if p && !p.egg? && p.hp > 0 end if count <= 1 @@ -86,7 +86,7 @@ module PokemonPCList def self.getCommandList commands = [] - for pc in @@pclist + @@pclist.each do |pc| commands.push(pc.name) if pc.shouldShow? end commands.push(_INTL("Log Off")) @@ -96,7 +96,7 @@ module PokemonPCList def self.callCommand(cmd) return false if cmd < 0 || cmd >= @@pclist.length i = 0 - for pc in @@pclist + @@pclist.each do |pc| next if !pc.shouldShow? if i == cmd pc.access @@ -169,7 +169,7 @@ def pbPCMailbox loop do command = 0 commands = [] - for mail in $PokemonGlobal.mailbox + $PokemonGlobal.mailbox.each do |mail| commands.push(mail.sender) end commands.push(_INTL("Cancel")) diff --git a/Data/Scripts/016_UI/020_UI_PokeMart.rb b/Data/Scripts/016_UI/020_UI_PokeMart.rb index 7b9a92d24..48f4c87d4 100644 --- a/Data/Scripts/016_UI/020_UI_PokeMart.rb +++ b/Data/Scripts/016_UI/020_UI_PokeMart.rb @@ -257,7 +257,7 @@ class PokemonMart_Scene @viewport2.z = 99999 numFrames = Graphics.frame_rate * 4 / 10 alphaDiff = (255.0 / numFrames).ceil - for j in 0..numFrames + (0..numFrames).each do |j| col = Color.new(0, 0, 0, j * alphaDiff) @viewport2.color = col Graphics.update @@ -301,7 +301,7 @@ class PokemonMart_Scene if @viewport2 numFrames = Graphics.frame_rate * 4 / 10 alphaDiff = (255.0 / numFrames).ceil - for j in 0..numFrames + (0..numFrames).each do |j| col = Color.new(0, 0, 0, (numFrames - j) * alphaDiff) @viewport2.color = col Graphics.update diff --git a/Data/Scripts/016_UI/021_UI_MoveRelearner.rb b/Data/Scripts/016_UI/021_UI_MoveRelearner.rb index df5613e8f..a9bd238d7 100644 --- a/Data/Scripts/016_UI/021_UI_MoveRelearner.rb +++ b/Data/Scripts/016_UI/021_UI_MoveRelearner.rb @@ -63,7 +63,7 @@ class MoveRelearner_Scene ] imagepos = [] yPos = 76 - for i in 0...VISIBLEMOVES + VISIBLEMOVES.times do |i| moveobject = @moves[@sprites["commands"].top_item + i] if moveobject moveData = GameData::Move.get(moveobject) @@ -157,7 +157,7 @@ class MoveRelearnerScreen end tmoves = [] if pkmn.first_moves - for i in pkmn.first_moves + pkmn.first_moves.each do |i| tmoves.push(i) if !pkmn.hasMove?(i) && !moves.include?(i) end end diff --git a/Data/Scripts/016_UI/022_UI_PurifyChamber.rb b/Data/Scripts/016_UI/022_UI_PurifyChamber.rb index 341020281..f0e0fc95a 100644 --- a/Data/Scripts/016_UI/022_UI_PurifyChamber.rb +++ b/Data/Scripts/016_UI/022_UI_PurifyChamber.rb @@ -83,7 +83,7 @@ class PurifyChamberSet def flow ret = 0 return 0 if !@shadow - for i in 0...@list.length + @list.length.times do |i| ret += (PurifyChamberSet.isSuperEffective(@list[i], @list[(i + 1) % @list.length])) ? 1 : 0 end if @list[@facing] @@ -106,7 +106,7 @@ class PurifyChamberSet # clockwise direction. Tempo also depends on the number of Pokemon in the set def tempo ret = 0 - for i in 0...@list.length + @list.length.times do |i| ret += (PurifyChamberSet.isSuperEffective(@list[i], @list[(i + 1) % @list.length])) ? 1 : 0 end return partialSum(@list.length) + ret @@ -235,7 +235,7 @@ class PurifyChamber # Define an exception for Lugia if shadow.isSpecies?(:LUGIA) maxtempo = PurifyChamber.maximumTempo - for i in 0...NUMSETS + NUMSETS.times do |i| return false if @sets[i].tempo != maxtempo end end @@ -247,7 +247,7 @@ class PurifyChamber end def update # called each step - for set in 0...NUMSETS + NUMSETS.times do |set| # If a shadow Pokemon and a regular Pokemon are on the same set if @sets[set].shadow if @sets[set].shadow.heart_gauge > 0 @@ -560,7 +560,7 @@ class PurifyChamberScreen def pbCheckPurify purifiables = [] - for set in 0...PurifyChamber::NUMSETS + PurifyChamber::NUMSETS.times do |set| if @chamber.isPurifiable?(set) # if ready for purification purifiables.push(set) end @@ -570,12 +570,12 @@ class PurifyChamberScreen def pbDoPurify purifiables = [] - for set in 0...PurifyChamber::NUMSETS + PurifyChamber::NUMSETS.times do |set| if @chamber.isPurifiable?(set) # if ready for purification purifiables.push(set) end end - for i in 0...purifiables.length + purifiables.length.times do |i| set = purifiables[i] @chamber.currentSet = set @scene.pbOpenSet(set) @@ -698,13 +698,13 @@ class DirectFlowDiagram end def visible=(value) - for point in @points + @points.each do |point| point.visible = value end end def dispose - for point in @points + @points.each do |point| point.dispose end end @@ -719,7 +719,7 @@ class DirectFlowDiagram end def update - for point in @points + @points.each do |point| point.update point.visible = false end @@ -741,7 +741,7 @@ class DirectFlowDiagram end def color=(value) - for point in @points + @points.each do |point| point.color = value end end @@ -772,13 +772,13 @@ class FlowDiagram end def visible=(value) - for point in @points + @points.each do |point| point.visible = value end end def dispose - for point in @points + @points.each do |point| point.dispose end end @@ -802,7 +802,7 @@ class FlowDiagram end def update - for point in @points + @points.each do |point| point.update point.visible = false end @@ -824,7 +824,7 @@ class FlowDiagram end def color=(value) - for point in @points + @points.each do |point| point.color = value end end @@ -862,7 +862,7 @@ class PurifyChamberSetView < SpriteWrapper @directflow.setFlowStrength(1) @__sprites = [] @__sprites[0] = PokemonIconSprite.new(nil, viewport) - for i in 0...PurifyChamber::SETSIZE * 2 + PurifyChamber::SETSIZE * 2.times do |i| @__sprites[i + 1] = PokemonIconSprite.new(nil, viewport) end @__sprites[1 + (PurifyChamber::SETSIZE * 2)] = PokemonIconSprite.new(nil, viewport) @@ -871,11 +871,11 @@ class PurifyChamberSetView < SpriteWrapper end def refreshFlows - for flow in @flows + @flows.each do |flow| flow.setFlowStrength(0) end setcount = @chamber.setCount(@set) - for i in 0...setcount + setcount.times do |i| if !@flows[i] @flows[i] = FlowDiagram.new(self.viewport) end @@ -988,7 +988,7 @@ class PurifyChamberSetView < SpriteWrapper points = [@chamber.setCount(@set) * 2, 1].max setList = @chamber.setList(@set) refreshFlows - for i in 0...PurifyChamber::SETSIZE * 2 + (PurifyChamber::SETSIZE * 2).times do |i| pkmn = (i.odd? || i >= points) ? nil : setList[i / 2] angle = 360 - (i * 360 / points) angle += 90 # start at 12 not 3 o'clock @@ -1031,10 +1031,10 @@ class PurifyChamberSetView < SpriteWrapper def visible=(value) super - for sprite in @__sprites + @__sprites.each do |sprite| sprite.visible = value end - for flow in @flows + @flows.each do |flow| flow.visible = value end @directflow.visible = value @@ -1044,10 +1044,10 @@ class PurifyChamberSetView < SpriteWrapper def color=(value) super - for sprite in @__sprites + @__sprites.each do |sprite| sprite.color = pbSrcOver(sprite.color, value.clone) end - for flow in @flows + @flows.each do |flow| flow.color = value.clone end @directflow.color = value.clone @@ -1057,10 +1057,10 @@ class PurifyChamberSetView < SpriteWrapper def update super - for sprite in @__sprites + @__sprites.each do |sprite| sprite.update if sprite end - for flow in @flows + @flows.each do |flow| flow.update end @directflow.update @@ -1069,10 +1069,10 @@ class PurifyChamberSetView < SpriteWrapper end def dispose - for sprite in @__sprites + @__sprites.each do |sprite| sprite.dispose if sprite end - for flow in @flows + @flows.each do |flow| flow.dispose end @directflow.dispose @@ -1261,7 +1261,7 @@ class PurifyChamberScene indexes = [] startindex = 0 set = @sprites["setview"].set - for i in 0...@chamber.setCount(set) * 2 + (@chamber.setCount(set) * 2).times do |i| p = PurifyChamberHelper.pbGetPokemon2(@chamber, set, i) if p startindex = party.length if i == pos diff --git a/Data/Scripts/016_UI/023_UI_MysteryGift.rb b/Data/Scripts/016_UI/023_UI_MysteryGift.rb index c3c98e084..b5c0554f7 100644 --- a/Data/Scripts/016_UI/023_UI_MysteryGift.rb +++ b/Data/Scripts/016_UI/023_UI_MysteryGift.rb @@ -63,7 +63,7 @@ def pbEditMysteryGift(type, item, id = 0, giftname = "") master = IO.read("MysteryGiftMaster.txt") master = pbMysteryGiftDecrypt(master) end - for i in master + master.each do |i| idlist.push(i[0]) end params = ChooseNumberParams.new @@ -161,7 +161,7 @@ def pbManageMysteryGifts elsif command == commands.length - 2 # Export selected to file begin newfile = [] - for gift in master + master.each do |gift| newfile.push(gift) if online.include?(gift[0]) end string = pbMysteryGiftEncrypt(newfile) @@ -200,7 +200,7 @@ def pbManageMysteryGifts next end replaced = false - for i in 0...$player.mystery_gifts.length + $player.mystery_gifts.length.times do |i| if $player.mystery_gifts[i][0] == gift[0] $player.mystery_gifts[i] = gift replaced = true @@ -219,7 +219,7 @@ end def pbRefreshMGCommands(master, online) commands = [] - for gift in master + master.each do |gift| itemname = "BLANK" if gift[1] == 0 itemname = gift[2].speciesName @@ -252,9 +252,9 @@ def pbDownloadMysteryGift(trainer) else online = pbMysteryGiftDecrypt(string) pending = [] - for gift in online + online.each do |gift| notgot = true - for j in trainer.mystery_gifts + trainer.mystery_gifts.each do |j| notgot = false if j[0] == gift[0] end pending.push(gift) if notgot @@ -264,7 +264,7 @@ def pbDownloadMysteryGift(trainer) else loop do commands = [] - for gift in pending + pending.each do |gift| commands.push(gift[3]) end commands.push(_INTL("Cancel")) @@ -356,7 +356,7 @@ end # Collecting a Mystery Gift from the deliveryman. #=============================================================================== def pbNextMysteryGiftID - for i in $player.mystery_gifts + $player.mystery_gifts.each do |i| return i[0] if i.length > 1 end return 0 @@ -364,7 +364,7 @@ end def pbReceiveMysteryGift(id) index = -1 - for i in 0...$player.mystery_gifts.length + $player.mystery_gifts.length.times do |i| if $player.mystery_gifts[i][0] == id && $player.mystery_gifts[i].length > 1 index = i break diff --git a/Data/Scripts/016_UI/024_UI_TextEntry.rb b/Data/Scripts/016_UI/024_UI_TextEntry.rb index 38d302eae..9da314417 100644 --- a/Data/Scripts/016_UI/024_UI_TextEntry.rb +++ b/Data/Scripts/016_UI/024_UI_TextEntry.rb @@ -381,13 +381,13 @@ class PokemonEntryScene2 @helper = CharacterEntryHelper.new(initialText) # Create bitmaps @bitmaps = [] - for i in 0...@@Characters.length + @@Characters.length.times do |i| @bitmaps[i] = AnimatedBitmap.new(sprintf("Graphics/Pictures/Naming/overlay_tab_#{i + 1}")) b = @bitmaps[i].bitmap.clone pbSetSystemFont(b) textPos = [] - for y in 0...COLUMNS - for x in 0...ROWS + COLUMNS.times do |y| + ROWS.times do |x| pos = (y * ROWS) + x textPos.push([@@Characters[i][0][pos], 44 + (x * 32), 12 + (y * 38), 2, Color.new(16, 24, 32), Color.new(160, 160, 160)]) @@ -517,7 +517,7 @@ class PokemonEntryScene2 ] chars = @helper.textChars x = 166 - for ch in chars + chars.each do |ch| textPositions.push([ch, x, 42, false, Color.new(16, 24, 32), Color.new(168, 184, 184)]) x += 24 end @@ -566,7 +566,7 @@ class PokemonEntryScene2 end def pbUpdate - for i in 0...@@Characters.length + @@Characters.length.times do |i| @bitmaps[i].update end if @init || Graphics.frame_count % 5 == 0 @@ -608,20 +608,22 @@ class PokemonEntryScene2 @cursorpos -= 1 @cursorpos = OK if @cursorpos < MODE1 else - begin + loop do cursormod = wrapmod(cursormod - 1, ROWS) @cursorpos = cursororigin + cursormod - end while pbColumnEmpty?(cursormod) + break unless pbColumnEmpty?(cursormod) + end end elsif Input.repeat?(Input::RIGHT) if @cursorpos < 0 # Controls @cursorpos += 1 @cursorpos = MODE1 if @cursorpos > OK else - begin + loop do cursormod = wrapmod(cursormod + 1, ROWS) @cursorpos = cursororigin + cursormod - end while pbColumnEmpty?(cursormod) + break unless pbColumnEmpty?(cursormod) + end end elsif Input.repeat?(Input::UP) if @cursorpos < 0 # Controls @@ -738,7 +740,7 @@ class PokemonEntryScene2 def pbEndScene pbFadeOutAndHide(@sprites) { pbUpdate } - for bitmap in @bitmaps + @bitmaps.each do |bitmap| bitmap.dispose if bitmap end @bitmaps.clear diff --git a/Data/Scripts/017_Minigames/001_Minigame_Duel.rb b/Data/Scripts/017_Minigames/001_Minigame_Duel.rb index 56cfc7cea..8951878ff 100644 --- a/Data/Scripts/017_Minigames/001_Minigame_Duel.rb +++ b/Data/Scripts/017_Minigames/001_Minigame_Duel.rb @@ -106,7 +106,7 @@ class PokemonDuel else num = rand(total) cumtotal = 0 - for i in 0...4 + 4.times do |i| cumtotal += scores[i] if num < cumtotal action = i @@ -385,7 +385,7 @@ def pbDuel(trainer_id, trainer_name, event, speeches) pbGetMessageFromHash(MessageTypes::TrainerNames, trainer_name), trainer_id ) speech_texts = [] - for i in 0...12 + 12.times do |i| speech_texts.push(_I(speeches[i])) end duel.pbDuel(opponent, event, speech_texts) diff --git a/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb b/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb index 8f2622da5..90a96667d 100644 --- a/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb +++ b/Data/Scripts/017_Minigames/002_Minigame_TripleTriad.rb @@ -172,7 +172,7 @@ class TriadScene @sprites["helpwindow"] = Window_AdvancedTextPokemon.newWithSize( "", 0, Graphics.height - 64, Graphics.width, 64, @viewport ) - for i in 0...@battle.width * @battle.height + (@battle.width * @battle.height).times do |i| @sprites["sprite#{i}"] = SpriteWrapper.new(@viewport) @sprites["sprite#{i}"].x = (Graphics.width / 2) - 118 + ((i % 3) * 78) @sprites["sprite#{i}"].y = 36 + ((i / 3) * 94) @@ -187,7 +187,7 @@ class TriadScene @opponentCardIndexes = [] @boardSprites = [] @boardCards = [] - for i in 0...@battle.maxCards + @battle.maxCards.times do |i| @sprites["player#{i}"] = Sprite.new(@viewport) @sprites["player#{i}"].x = Graphics.width - 92 @sprites["player#{i}"].y = 44 + (44 * i) @@ -258,7 +258,7 @@ class TriadScene def pbChooseTriadCard(cardStorage) commands = [] chosenCards = [] - for item in cardStorage + cardStorage.each do |item| commands.push(_INTL("{1} x{2}", GameData::Species.get(item[0]).name, item[1])) end command = Window_CommandPokemonEx.newWithSize(commands, 0, 0, Graphics.width / 2, Graphics.height - 64, @viewport) @@ -268,7 +268,7 @@ class TriadScene preview.y = 60 preview.z = 4 index = -1 - for i in 0...@battle.maxCards + @battle.maxCards.times do |i| @sprites["player#{i}"] = Sprite.new(@viewport) @sprites["player#{i}"].x = Graphics.width - 92 @sprites["player#{i}"].y = 44 + (44 * i) @@ -292,7 +292,7 @@ class TriadScene item = chosenCards.pop @battle.pbAdd(cardStorage, item) commands = [] - for item in cardStorage + cardStorage.each do |item| commands.push(_INTL("{1} x{2}", GameData::Species.get(item[0]).name, item[1])) end command.commands = commands @@ -314,7 +314,7 @@ class TriadScene chosenCards.push(item[0]) @battle.pbSubtract(cardStorage, item[0]) commands = [] - for item in cardStorage + cardStorage.each do |item| commands.push(_INTL("{1} x{2}", GameData::Species.get(item[0]).name, item[1])) end command.commands = commands @@ -323,7 +323,7 @@ class TriadScene end end if Input.trigger?(Input::USE) || Input.trigger?(Input::BACK) - for i in 0...@battle.maxCards + @battle.maxCards.times do |i| @sprites["player#{i}"].visible = (i < chosenCards.length) end if chosenCards.length == @battle.maxCards @@ -346,7 +346,7 @@ class TriadScene end def pbShowPlayerCards(cards) - for i in 0...@battle.maxCards + @battle.maxCards.times do |i| @sprites["player#{i}"] = Sprite.new(@viewport) @sprites["player#{i}"].x = Graphics.width - 92 @sprites["player#{i}"].y = 44 + (44 * i) @@ -357,7 +357,7 @@ class TriadScene end def pbShowOpponentCards(cards) - for i in 0...@battle.maxCards + @battle.maxCards.times do |i| @sprites["opponent#{i}"] = Sprite.new(@viewport) @sprites["opponent#{i}"].x = 12 @sprites["opponent#{i}"].y = 44 + (44 * i) @@ -375,7 +375,7 @@ class TriadScene loop do if lastChoice != choice y = 44 - for i in 0...@opponentCardIndexes.length + @opponentCardIndexes.length.times do |i| @sprites["opponent#{@opponentCardIndexes[i]}"].bitmap = @opponentCardBitmaps[@opponentCardIndexes[i]] @sprites["opponent#{@opponentCardIndexes[i]}"].x = (i == choice) ? 28 : 12 @sprites["opponent#{@opponentCardIndexes[i]}"].y = y @@ -415,7 +415,7 @@ class TriadScene loop do if lastChoice != choice y = 44 - for i in 0...@cardIndexes.length + @cardIndexes.length.times do |i| @sprites["player#{@cardIndexes[i]}"].bitmap = @cardBitmaps[@cardIndexes[i]] @sprites["player#{@cardIndexes[i]}"].x = (i == choice) ? Graphics.width - 108 : Graphics.width - 92 @sprites["player#{@cardIndexes[i]}"].y = y @@ -457,7 +457,7 @@ class TriadScene loop do if doRefresh y = 44 - for i in 0...@cardIndexes.length + @cardIndexes.length.times do |i| if i == cardIndex # Card being placed @sprites["player#{@cardIndexes[i]}"].x = (Graphics.width / 2) - 118 + (boardX * 78) @sprites["player#{@cardIndexes[i]}"].y = 36 + (boardY * 94) @@ -521,7 +521,7 @@ class TriadScene def pbOpponentPlaceCard(triadCard, position, cardIndex) y = 44 - for i in 0...@opponentCardIndexes.length + @opponentCardIndexes.length.times do |i| sprite = @sprites["opponent#{@opponentCardIndexes[i]}"] if i == cardIndex @opponentCardBitmaps[@opponentCardIndexes[i]] = triadCard.createBitmap(2) @@ -550,7 +550,7 @@ class TriadScene end def pbRefresh - for i in 0...@battle.width * @battle.height + (@battle.width * @battle.height).times do |i| x = i % @battle.width y = i / @battle.width if @boardSprites[i] @@ -566,7 +566,7 @@ class TriadScene bitmap.clear playerscore = 0 oppscore = 0 - for i in 0...@battle.width * @battle.height + (@battle.width * @battle.height).times do |i| if @boardSprites[i] playerscore += 1 if @battle.board[i].owner == 1 oppscore += 1 if @battle.board[i].owner == 2 @@ -657,7 +657,7 @@ class TriadScreen flips = [] return nil if attackerParam != nil && @board[(y * @width) + x].owner != 0 return nil if !attacker.card || attacker.owner == 0 - for i in 0...4 + 4.times do |i| defenderX = panels[i * 2] defenderY = panels[(i * 2) + 1] defender = @board[(defenderY * @width) + defenderX] @@ -705,7 +705,7 @@ class TriadScreen raise _INTL("Maximum level must be 0 through 9.") if maxLevel < 0 || maxLevel > 9 raise _INTL("Maximum level shouldn't be less than the minimum level.") if maxLevel < minLevel if rules && rules.is_a?(Array) && rules.length > 0 - for rule in rules + rules.each do |rule| @sameWins = true if rule == "samewins" @openHand = true if rule == "openhand" @wrapAround = true if rule == "wrap" @@ -719,7 +719,7 @@ class TriadScreen end @triadCards = [] count = 0 - for i in 0...$PokemonGlobal.triads.length + $PokemonGlobal.triads.length.times do |i| item = $PokemonGlobal.triads[i] ItemStorageHelper.add(@triadCards, $PokemonGlobal.triads.maxSize, TriadStorage::MAX_PER_SLOT, item[0], item[1]) @@ -729,7 +729,7 @@ class TriadScreen @playerName = $player ? $player.name : "Trainer" @opponentName = opponentName type_keys = GameData::Type.keys - for i in 0...@width * @height + (@width * @height).times do |i| square = TriadSquare.new if @elements loop do @@ -764,7 +764,7 @@ class TriadScreen # Set the opponent's cards. if oppdeck && oppdeck.is_a?(Array) && oppdeck.length == self.maxCards # Preset opponentCards = [] - for i in oppdeck + oppdeck.each do |i| species_data = GameData::Species.try_get(i) if !species_data @scene.pbDisplayPaused(_INTL("Opponent has an illegal card, \"{1}\".", i)) @@ -806,7 +806,7 @@ class TriadScreen @scene.pbUpdateScore playerTurn = (rand(2) == 0) @scene.pbDisplay(_INTL("{1} will go first.", (playerTurn) ? @playerName : @opponentName)) - for i in 0...@width * @height + (@width * @height).times do |i| position = nil triadCard = nil cardIndex = 0 @@ -821,11 +821,11 @@ class TriadScreen # Opponent's turn @scene.pbDisplay(_INTL("{1} is making a move...", @opponentName)) scores = [] - for cardIndex in 0...opponentCards.length + opponentCards.length.times do |cardIndex| square = TriadSquare.new square.card = TriadCard.new(opponentCards[cardIndex]) square.owner = 2 - for i in 0...@width * @height + (@width * @height).times do |i| x = i % @width y = i / @width square.type = @board[i].type @@ -865,7 +865,7 @@ class TriadScreen # Determine the winner playerCount = 0 opponentCount = 0 - for i in 0...@width * @height + (@width * @height).times do |i| playerCount += 1 if board[i].owner == 1 opponentCount += 1 if board[i].owner == 2 end @@ -879,13 +879,13 @@ class TriadScreen result = 3 if @trade == 1 # Keep only cards of your color - for card in originalCards + originalCards.each do |card| $PokemonGlobal.triads.remove(card) end - for i in cards + cards.each do |i| $PokemonGlobal.triads.add(i) end - for i in 0...@width * @height + (@width * @height).times do |i| if board[i].owner == 1 card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id $PokemonGlobal.triads.add(card) @@ -910,13 +910,13 @@ class TriadScreen @scene.pbDisplayPaused(_INTL("Got opponent's {1} card.", cardname)) end when 1 # Keep only cards of your color - for card in originalCards + originalCards.each do |card| $PokemonGlobal.triads.remove(card) end - for i in cards + cards.each do |i| $PokemonGlobal.triads.add(i) end - for i in 0...@width * @height + (@width * @height).times do |i| if board[i].owner == 1 card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id $PokemonGlobal.triads.add(card) @@ -924,7 +924,7 @@ class TriadScreen end @scene.pbDisplayPaused(_INTL("Kept all cards of your color.")) when 2 # Gain all opponent's cards - for card in originalOpponentCards + originalOpponentCards.each do |card| $PokemonGlobal.triads.add(card) end @scene.pbDisplayPaused(_INTL("Got all opponent's cards.")) @@ -940,13 +940,13 @@ class TriadScreen cardname = GameData::Species.get(card).name @scene.pbDisplayPaused(_INTL("Opponent won your {1} card.", cardname)) when 1 # Keep only cards of your color - for card in originalCards + originalCards.each do |card| $PokemonGlobal.triads.remove(card) end - for i in cards + cards.each do |i| $PokemonGlobal.triads.add(i) end - for i in 0...@width * @height + (@width * @height).times do |i| if board[i].owner == 1 card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id $PokemonGlobal.triads.add(card) @@ -954,7 +954,7 @@ class TriadScreen end @scene.pbDisplayPaused(_INTL("Kept all cards of your color.", cardname)) when 2 # Lose all your cards - for card in originalCards + originalCards.each do |card| $PokemonGlobal.triads.remove(card) end @scene.pbDisplayPaused(_INTL("Opponent won all your cards.")) @@ -1071,7 +1071,7 @@ def pbBuyTriads return end commands.sort! { |a, b| a[1] <=> b[1] } # Sort alphabetically - for command in commands + commands.each do |command| realcommands.push(command[2]) end # Scroll right before showing screen @@ -1152,7 +1152,7 @@ end def pbSellTriads commands = [] - for i in 0...$PokemonGlobal.triads.length + $PokemonGlobal.triads.length.times do |i| item = $PokemonGlobal.triads[i] speciesname = GameData::Species.get(item[0]).name commands.push(_INTL("{1} x{2}", speciesname, item[1])) @@ -1234,7 +1234,7 @@ def pbSellTriads $PokemonGlobal.triads.remove(item, quantity) pbMessage(_INTL("Turned over the {1} card and received ${2}.\\se[Mart buy item]", itemname, price.to_s_formatted)) commands = [] - for i in 0...$PokemonGlobal.triads.length + $PokemonGlobal.triads.length.times do |i| item = $PokemonGlobal.triads[i] speciesname = GameData::Species.get(item[0]).name commands.push(_INTL("{1} x{2}", speciesname, item[1])) @@ -1258,7 +1258,7 @@ end def pbTriadList commands = [] - for i in 0...$PokemonGlobal.triads.length + $PokemonGlobal.triads.length.times do |i| item = $PokemonGlobal.triads[i] speciesname = GameData::Species.get(item[0]).name commands.push(_INTL("{1} x{2}", speciesname, item[1])) diff --git a/Data/Scripts/017_Minigames/003_Minigame_SlotMachine.rb b/Data/Scripts/017_Minigames/003_Minigame_SlotMachine.rb index 4f318f131..a8e3c7bf2 100644 --- a/Data/Scripts/017_Minigames/003_Minigame_SlotMachine.rb +++ b/Data/Scripts/017_Minigames/003_Minigame_SlotMachine.rb @@ -23,7 +23,7 @@ class SlotMachineReel < BitmapSprite @viewport.z = 99999 super(64, 144, @viewport) @reel = [] - for i in 0...ICONSPOOL[difficulty].length + ICONSPOOL[difficulty].length.times do |i| @reel.push(ICONSPOOL[difficulty][i]) end @reel.shuffle! @@ -49,7 +49,7 @@ class SlotMachineReel < BitmapSprite def showing array = [] - for i in 0...3 + 3.times do |i| num = @index - i num += @reel.length if num < 0 array.push(@reel[num]) @@ -70,7 +70,7 @@ class SlotMachineReel < BitmapSprite @slipping -= 1 if @slipping > 0 end end - for i in 0...4 + 4.times do |i| num = @index - i num += @reel.length if num < 0 self.bitmap.blt(0, @toppos + (i * 48), @images.bitmap, Rect.new(@reel[num] * 64, 0, 64, 48)) @@ -100,7 +100,7 @@ class SlotMachineScore < BitmapSprite def refresh self.bitmap.clear - for i in 0...5 + 5.times do |i| digit = (@score / (10**i)) % 10 # Least significant digit first self.bitmap.blt(14 * (4 - i), 0, @numbers.bitmap, Rect.new(digit * 14, 0, 14, 22)) end @@ -133,7 +133,7 @@ class SlotMachineScene [reel1[2], reel2[2], reel3[2]], # Bottom row [reel1[0], reel2[1], reel3[2]], # Diagonal top left -> bottom right [reel1[2], reel2[1], reel3[0]]] # Diagonal bottom left -> top right - for i in 0...combinations.length + combinations.length.times do |i| break if i >= 1 && @wager <= 1 # One coin = centre row only break if i >= 3 && @wager <= 2 # Two coins = three rows only wonRow[i] = true @@ -191,7 +191,7 @@ class SlotMachineScene @sprites["light1"].src_rect.set(0, 26 * ((frame / timePerFrame) % 4), 96, 26) @sprites["light2"].visible = true @sprites["light2"].src_rect.set(0, 26 * ((frame / timePerFrame) % 4), 96, 26) - for i in 1..5 + (1..5).each do |i| if wonRow[i - 1] @sprites["row#{i}"].visible = (frame / timePerFrame).even? else @@ -245,12 +245,12 @@ class SlotMachineScene @sprites["reel1"] = SlotMachineReel.new(64, 112, difficulty) @sprites["reel2"] = SlotMachineReel.new(144, 112, difficulty) @sprites["reel3"] = SlotMachineReel.new(224, 112, difficulty) - for i in 1..3 + (1..3).each do |i| @sprites["button#{i}"] = IconSprite.new(68 + (80 * (i - 1)), 260, @viewport) @sprites["button#{i}"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/button")) @sprites["button#{i}"].visible = false end - for i in 1..5 + (1..5).each do |i| y = [170, 122, 218, 82, 82][i - 1] @sprites["row#{i}"] = IconSprite.new(2, y, @viewport) @sprites["row#{i}"].setBitmap(sprintf("Graphics/Pictures/Slot Machine/line%1d%s", @@ -317,7 +317,7 @@ class SlotMachineScene @sprites["button1"].visible = false @sprites["button2"].visible = false @sprites["button3"].visible = false - for i in 1..5 + (1..5).each do |i| @sprites["row#{i}"].visible = false end @gameEnd = false @@ -345,7 +345,7 @@ class SlotMachineScene (Input.trigger?(Input::USE) && @wager > 0) || @replay if @replay @wager = 3 - for i in 1..5 + (1..5).each do |i| @sprites["row#{i}"].visible = true end end diff --git a/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb b/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb index 81fc1e127..b041609a6 100644 --- a/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb +++ b/Data/Scripts/017_Minigames/004_Minigame_VoltorbFlip.rb @@ -35,7 +35,7 @@ class VoltorbFlip squareValues = [] total = 1 voltorbs = 0 - for i in 0...25 + 25.times do |i| # Sets the value to 1 by default squareValues[i] = 1 # Sets the value to 0 (a voltorb) if # for that level hasn't been reached @@ -54,7 +54,7 @@ class VoltorbFlip end end # Randomize the values a little - for i in 0...25 + 25.times do |i| temp = squareValues[i] if squareValues[i] > 1 if rand(10) > 8 @@ -72,7 +72,7 @@ class VoltorbFlip end end # Populate @squares array - for i in 0...25 + 25.times do |i| x = i if i % 5 == 0 r = rand(squareValues.length) @squares[i] = [((i - x).abs * 64) + 128, (i / 5).abs * 64, squareValues[r], false] @@ -80,7 +80,7 @@ class VoltorbFlip end pbCreateSprites # Display numbers (all zeroes, as no values have been calculated yet) - for i in 0...5 + 5.times do |i| pbUpdateRowNumbers(0, 0, i) pbUpdateColumnNumbers(0, 0, i) end @@ -122,12 +122,12 @@ class VoltorbFlip @voltorbNumbers = [] @numbers = [] # Draw numbers for each row (precautionary) - for i in 0...@squares.length + @squares.length.times do |i| if i % 5 == 0 num = 0 voltorbs = 0 j = i + 5 - for k in i...j + (i...j).each do |k| num += @squares[k][2] if @squares[k][2] == 0 voltorbs += 1 @@ -140,10 +140,10 @@ class VoltorbFlip @voltorbNumbers = [] @numbers = [] # Draw numbers for each column - for i in 0...5 + 5.times do |i| num = 0 voltorbs = 0 - for j in 0...5 + 5.times do |j| num += @squares[i + (j * 5)][2] if @squares[i + (j * 5)][2] == 0 voltorbs += 1 @@ -193,7 +193,7 @@ class VoltorbFlip @sprites["currentCoins"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport) @sprites["animation"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport) @sprites["animation"].z = 99999 - for i in 0...6 + 6.times do |i| @sprites[i] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport) @sprites[i].z = 99996 @sprites[i].visible = false @@ -201,8 +201,8 @@ class VoltorbFlip # Creates images ahead of time for the display-all animation (reduces lag) icons = [] points = 0 - for i in 0...3 - for j in 0...25 + 3.times do |i| + 25.times do |j| points = @squares[j][2] if i == 2 icons[j] = [@directory + "tiles", @squares[j][0], @squares[j][1], 320 + (i * 64) + (points * 64), 0, 64, 64] end @@ -210,7 +210,7 @@ class VoltorbFlip pbDrawImagePositions(@sprites[i].bitmap, icons) end icons = [] - for i in 0...25 + 25.times do |i| icons[i] = [@directory + "tiles", @squares[i][0], @squares[i][1], @squares[i][2] * 64, 0, 64, 64] end pbDrawImagePositions(@sprites[5].bitmap, icons) @@ -257,12 +257,12 @@ class VoltorbFlip end elsif Input.trigger?(Input::USE) if @cursor[0][3] == 64 # If in mark mode - for i in 0...@squares.length + @squares.length.times do |i| if (@index[0] * 64) + 128 == @squares[i][0] && @index[1] * 64 == @squares[i][1] && @squares[i][3] == false pbSEPlay("Voltorb Flip mark") end end - for i in 0...@marks.length + 1 + (@marks.length + 1).times do |i| if @marks[i] == nil @marks[i] = [@directory + "tiles", (@index[0] * 64) + 128, @index[1] * 64, 256, 0, 64, 64] elsif @marks[i][1] == (@index[0] * 64) + 128 && @marks[i][2] == @index[1] * 64 @@ -277,7 +277,7 @@ class VoltorbFlip else # Display the tile for the selected spot icons = [] - for i in 0...@squares.length + @squares.length.times do |i| if (@index[0] * 64) + 128 == @squares[i][0] && @index[1] * 64 == @squares[i][1] && @squares[i][3] == false pbAnimateTile((@index[0] * 64) + 128, @index[1] * 64, @squares[i][2]) @squares[i][3] = true @@ -287,7 +287,7 @@ class VoltorbFlip # Play explosion animation # Part1 animation = [] - for j in 0...3 + 3.times do |j| animation[0] = icons[0] = [@directory + "tiles", (@index[0] * 64) + 128, @index[1] * 64, 704 + (64 * j), 0, 64, 64] pbDrawImagePositions(@sprites["animation"].bitmap, animation) pbWait(Graphics.frame_rate / 20) @@ -295,7 +295,7 @@ class VoltorbFlip end # Part2 animation = [] - for j in 0...6 + 6.times do |j| animation[0] = [@directory + "explosion", (@index[0] * 64) - 32 + 128, (@index[1] * 64) - 32, j * 128, 0, 128, 128] pbDrawImagePositions(@sprites["animation"].bitmap, animation) pbWait(Graphics.frame_rate / 10) @@ -308,7 +308,7 @@ class VoltorbFlip if @level > 1 # Determine how many levels to reduce by newLevel = 0 - for j in 0...@squares.length + @squares.length.times do |j| newLevel += 1 if @squares[j][3] == true && @squares[j][2] > 1 end newLevel = @level if newLevel > @level @@ -325,7 +325,7 @@ class VoltorbFlip pbUpdateCoins # Revert numbers to 0s @sprites["numbers"].bitmap.clear - for i in 0...5 + 5.times do |i| pbUpdateRowNumbers(0, 0, i) pbUpdateColumnNumbers(0, 0, i) end @@ -335,7 +335,7 @@ class VoltorbFlip else # Play tile animation animation = [] - for j in 0...4 + 4.times do |j| animation[0] = [@directory + "flipAnimation", (@index[0] * 64) - 14 + 128, (@index[1] * 64) - 16, j * 92, 0, 92, 96] pbDrawImagePositions(@sprites["animation"].bitmap, animation) pbWait(Graphics.frame_rate / 20) @@ -354,7 +354,7 @@ class VoltorbFlip end end count = 0 - for i in 0...@squares.length + @squares.length.times do |i| if @squares[i][3] == false && @squares[i][2] > 1 count += 1 end @@ -379,7 +379,7 @@ class VoltorbFlip pbShowAndDispose # Revert numbers to 0s @sprites["numbers"].bitmap.clear - for i in 0...5 + 5.times do |i| pbUpdateRowNumbers(0, 0, i) pbUpdateColumnNumbers(0, 0, i) end @@ -440,7 +440,7 @@ class VoltorbFlip end numText += num.to_s numImages = numText.split(//)[0...2] - for j in 0...2 + 2.times do |j| @numbers[j] = [@directory + "numbersSmall", 472 + (j * 16), (i * 64) + 8, numImages[j].to_i * 16, 0, 16, 16] end @voltorbNumbers[i] = [@directory + "numbersSmall", 488, (i * 64) + 34, voltorbs * 16, 0, 16, 16] @@ -458,7 +458,7 @@ class VoltorbFlip end numText += num.to_s numImages = numText.split(//)[0...2] - for j in 0...2 + 2.times do |j| @numbers[j] = [@directory + "numbersSmall", (i * 64) + 152 + (j * 16), 328, numImages[j].to_i * 16, 0, 16, 16] end @voltorbNumbers[i] = [@directory + "numbersSmall", (i * 64) + 168, 354, voltorbs * 16, 0, 16, 16] @@ -475,7 +475,7 @@ class VoltorbFlip end coinText += source.to_s coinImages = coinText.split(//)[0...5] - for i in 0...5 + 5.times do |i| @coins[i] = [@directory + "numbersScore", 6 + (i * 24), y, coinImages[i].to_i * 24, 0, 24, 38] end end @@ -494,7 +494,7 @@ class VoltorbFlip def pbAnimateTile(x, y, tile) icons = [] points = 0 - for i in 0...3 + 3.times do |i| points = tile if i == 2 icons[i] = [@directory + "tiles", x, y, 320 + (i * 64) + (points * 64), 0, 64, 64] pbDrawImagePositions(@sprites["icon"].bitmap, icons) @@ -507,7 +507,7 @@ class VoltorbFlip def pbShowAndDispose # Make pre-rendered sprites visible (this approach reduces lag) - for i in 0...5 + 5.times do |i| @sprites[i].visible = true pbWait(Graphics.frame_rate / 20) if i < 3 @sprites[i].bitmap.clear @@ -527,32 +527,32 @@ class VoltorbFlip end end # "Dispose" of tiles by column - for i in 0...5 + 5.times do |i| icons = [] pbSEPlay("Voltorb Flip tile") - for j in 0...5 + 5.times do |j| icons[j] = [@directory + "tiles", @squares[i + (j * 5)][0], @squares[i + (j * 5)][1], 448 + (@squares[i + (j * 5)][2] * 64), 0, 64, 64] end pbDrawImagePositions(@sprites[i].bitmap, icons) pbWait(Graphics.frame_rate / 20) - for j in 0...5 + 5.times do |j| icons[j] = [@directory + "tiles", @squares[i + (j * 5)][0], @squares[i + (j * 5)][1], 384, 0, 64, 64] end pbDrawImagePositions(@sprites[i].bitmap, icons) pbWait(Graphics.frame_rate / 20) - for j in 0...5 + 5.times do |j| icons[j] = [@directory + "tiles", @squares[i + (j * 5)][0], @squares[i + (j * 5)][1], 320, 0, 64, 64] end pbDrawImagePositions(@sprites[i].bitmap, icons) pbWait(Graphics.frame_rate / 20) - for j in 0...5 + 5.times do |j| icons[j] = [@directory + "tiles", @squares[i + (j * 5)][0], @squares[i + (j * 5)][1], 896, 0, 64, 64] end pbDrawImagePositions(@sprites[i].bitmap, icons) pbWait(Graphics.frame_rate / 20) end @sprites["icon"].bitmap.clear - for i in 0...6 + 6.times do |i| @sprites[i].bitmap.clear end @sprites["cursor"].bitmap.clear diff --git a/Data/Scripts/017_Minigames/005_Minigame_Lottery.rb b/Data/Scripts/017_Minigames/005_Minigame_Lottery.rb index 2da873d91..647fb9338 100644 --- a/Data/Scripts/017_Minigames/005_Minigame_Lottery.rb +++ b/Data/Scripts/017_Minigames/005_Minigame_Lottery.rb @@ -16,10 +16,10 @@ def pbLottery(winnum, nameVar = 2, positionVar = 3, matchedVar = 4) winpoke = nil winpos = 0 winmatched = 0 - for i in $player.party + $player.party.each do |i| thismatched = 0 id = i.owner.public_id - for j in 0...5 + 5.times do |j| if (id / (10**j)) % 10 == (winnum / (10**j)) % 10 thismatched += 1 else @@ -35,7 +35,7 @@ def pbLottery(winnum, nameVar = 2, positionVar = 3, matchedVar = 4) pbEachPokemon { |poke, _box| thismatched = 0 id = poke.owner.public_id - for j in 0...5 + 5.times do |j| if (id / (10**j)) % 10 == (winnum / (10**j)) % 10 thismatched += 1 else diff --git a/Data/Scripts/017_Minigames/006_Minigame_Mining.rb b/Data/Scripts/017_Minigames/006_Minigame_Mining.rb index e36b69db3..e78f91283 100644 --- a/Data/Scripts/017_Minigames/006_Minigame_Mining.rb +++ b/Data/Scripts/017_Minigames/006_Minigame_Mining.rb @@ -239,8 +239,8 @@ class MiningGameScene @iron = [] pbDistributeItems pbDistributeIron - for i in 0...BOARD_HEIGHT - for j in 0...BOARD_WIDTH + BOARD_HEIGHT.times do |i| + BOARD_WIDTH.times do |j| @sprites["tile#{j + (i * BOARD_WIDTH)}"] = MiningGameTile.new(32 * j, 64 + (32 * i)) end end @@ -256,7 +256,7 @@ class MiningGameScene def pbDistributeItems # Set items to be buried (index in ITEMS, x coord, y coord) ptotal = 0 - for i in ITEMS + ITEMS.each do |i| ptotal += i[1] end numitems = rand(2..4) @@ -264,7 +264,7 @@ class MiningGameScene while numitems > 0 rnd = rand(ptotal) added = false - for i in 0...ITEMS.length + ITEMS.length.times do |i| rnd -= ITEMS[i][1] if rnd < 0 if pbNoDuplicateItems(ITEMS[i][0]) @@ -288,7 +288,7 @@ class MiningGameScene end # Draw items on item layer layer = @sprites["itemlayer"].bitmap - for i in @items + @items.each do |i| ox = ITEMS[i[0]][2] oy = ITEMS[i[0]][3] rectx = ITEMS[i[0]][4] @@ -314,7 +314,7 @@ class MiningGameScene end # Draw items on item layer layer = @sprites["itemlayer"].bitmap - for i in @iron + @iron.each do |i| ox = IRON[i[0]][0] oy = IRON[i[0]][1] rectx = IRON[i[0]][2] @@ -330,7 +330,7 @@ class MiningGameScene plates = [:INSECTPLATE, :DREADPLATE, :DRACOPLATE, :ZAPPLATE, :FISTPLATE, :FLAMEPLATE, :MEADOWPLATE, :EARTHPLATE, :ICICLEPLATE, :TOXICPLATE, :MINDPLATE, :STONEPLATE, :SKYPLATE, :SPOOKYPLATE, :IRONPLATE, :SPLASHPLATE] - for i in @items + @items.each do |i| preitem = ITEMS[i[0]][0] return false if preitem == newitem # No duplicate items return false if fossils.include?(preitem) && fossils.include?(newitem) @@ -340,7 +340,7 @@ class MiningGameScene end def pbCheckOverlaps(checkiron, provx, provy, provwidth, provheight, provpattern) - for i in @items + @items.each do |i| prex = i[1] prey = i[2] prewidth = ITEMS[i[0]][4] @@ -348,7 +348,7 @@ class MiningGameScene prepattern = ITEMS[i[0]][6] next if provx + provwidth <= prex || provx >= prex + prewidth || provy + provheight <= prey || provy >= prey + preheight - for j in 0...prepattern.length + prepattern.length.times do |j| next if prepattern[j] == 0 xco = prex + (j % prewidth) yco = prey + (j / prewidth).floor @@ -358,7 +358,7 @@ class MiningGameScene end end if checkiron # Check other irons as well - for i in @iron + @iron.each do |i| prex = i[1] prey = i[2] prewidth = IRON[i[0]][2] @@ -366,7 +366,7 @@ class MiningGameScene prepattern = IRON[i[0]][4] next if provx + provwidth <= prex || provx >= prex + prewidth || provy + provheight <= prey || provy >= prey + preheight - for j in 0...prepattern.length + prepattern.length.times do |j| next if prepattern[j] == 0 xco = prex + (j % prewidth) yco = prey + (j / prewidth).floor @@ -398,10 +398,10 @@ class MiningGameScene pbSEPlay("Mining iron") hittype = 2 else - for i in 0..2 + 3.times do |i| ytile = i - 1 + (position / BOARD_WIDTH) next if ytile < 0 || ytile >= BOARD_HEIGHT - for j in 0..2 + 3.times do |j| xtile = j - 1 + (position % BOARD_WIDTH) next if xtile < 0 || xtile >= BOARD_WIDTH @sprites["tile#{xtile + (ytile * BOARD_WIDTH)}"].layer -= pattern[j + (i * 3)] @@ -430,7 +430,7 @@ class MiningGameScene def pbIsItemThere?(position) posx = position % BOARD_WIDTH posy = position / BOARD_WIDTH - for i in @items + @items.each do |i| index = i[0] width = ITEMS[index][4] height = ITEMS[index][5] @@ -447,7 +447,7 @@ class MiningGameScene def pbIsIronThere?(position) posx = position % BOARD_WIDTH posy = position / BOARD_WIDTH - for i in @iron + @iron.each do |i| index = i[0] width = IRON[index][2] height = IRON[index][3] @@ -463,15 +463,15 @@ class MiningGameScene def pbCheckRevealed ret = [] - for i in 0...@items.length + @items.length.times do |i| next if @items[i][3] revealed = true index = @items[i][0] width = ITEMS[index][4] height = ITEMS[index][5] pattern = ITEMS[index][6] - for j in 0...height - for k in 0...width + height.times do |j| + width.times do |k| layer = @sprites["tile#{@items[i][1] + k + ((@items[i][2] + j) * BOARD_WIDTH)}"].layer revealed = false if layer > 0 && pattern[k + (j * width)] > 0 break if !revealed @@ -488,8 +488,8 @@ class MiningGameScene revealeditems = BitmapSprite.new(Graphics.width, Graphics.height, @viewport) halfFlashTime = Graphics.frame_rate / 8 alphaDiff = (255.0 / halfFlashTime).ceil - for i in 1..halfFlashTime * 2 - for index in revealed + (1..halfFlashTime * 2).each do |i| + revealed.each do |index| burieditem = @items[index] revealeditems.bitmap.blt(32 * burieditem[1], 64 + (32 * burieditem[2]), @itembitmap.bitmap, @@ -505,7 +505,7 @@ class MiningGameScene Graphics.update end revealeditems.dispose - for index in revealed + revealed.each do |index| @items[index][3] = true item = ITEMS[@items[index][0]][0] @itemswon.push(item) @@ -529,7 +529,7 @@ class MiningGameScene @sprites["collapse"] = BitmapSprite.new(Graphics.width, Graphics.height, collapseviewport) collapseTime = Graphics.frame_rate * 8 / 10 collapseFraction = (Graphics.height.to_f / collapseTime).ceil - for i in 1..collapseTime + (1..collapseTime).each do |i| @sprites["collapse"].bitmap.fill_rect(0, collapseFraction * (i - 1), Graphics.width, collapseFraction * i, Color.new(0, 0, 0)) Graphics.update @@ -538,7 +538,7 @@ class MiningGameScene break end foundall = true - for i in @items + @items.each do |i| foundall = false if !i[3] break if !foundall end @@ -587,7 +587,7 @@ class MiningGameScene def pbGiveItems if @itemswon.length > 0 - for i in @itemswon + @itemswon.each do |i| if $bag.add(i) pbMessage(_INTL("One {1} was obtained.\\se[Mining item get]\\wtnp[30]", GameData::Item.get(i).name)) diff --git a/Data/Scripts/017_Minigames/007_Minigame_TilePuzzles.rb b/Data/Scripts/017_Minigames/007_Minigame_TilePuzzles.rb index 604f5e4c4..3aad737e1 100644 --- a/Data/Scripts/017_Minigames/007_Minigame_TilePuzzles.rb +++ b/Data/Scripts/017_Minigames/007_Minigame_TilePuzzles.rb @@ -55,7 +55,7 @@ class TilePuzzleCursor < BitmapSprite # Cursor if @game != 3 expand = (@holding) ? 0 : 4 - for i in 0...4 + 4.times do |i| self.bitmap.blt( x + ((i % 2) * (@tilewidth - (@cursorbitmap.width / 4))) + (expand * (((i % 2) * 2) - 1)), y + ((i / 2) * (@tileheight - (@cursorbitmap.height / 2))) + (expand * (((i / 2) * 2) - 1)), @@ -72,7 +72,7 @@ class TilePuzzleCursor < BitmapSprite @tilewidth - (@cursorbitmap.width / 4) + expand, (@tilewidth - (@cursorbitmap.width / 4)) / 2] yin = [@tileheight - (@cursorbitmap.height / 2) + expand, (@tileheight - (@cursorbitmap.height / 2)) / 2, (@tileheight - (@cursorbitmap.height / 2)) / 2, -expand] - for i in 0...4 + 4.times do |i| if @arrows[i] self.bitmap.blt(x + xin[i], y + yin[i], @cursorbitmap.bitmap, Rect.new((@cursorbitmap.width / 2) + ((i % 2) * (@cursorbitmap.width / 4)), @@ -97,9 +97,9 @@ class TilePuzzleScene def update xtop = (Graphics.width - (@tilewidth * @boardwidth)) / 2 ytop = ((Graphics.height - (@tileheight * @boardheight)) / 2) + (@tileheight / 2) - 32 - for i in 0...@boardwidth * @boardheight + (@boardwidth * @boardheight).times do |i| pos = -1 - for j in 0...@tiles.length + @tiles.length.times do |j| pos = j if @tiles[j] == i end @sprites["tile#{i}"].z = 0 @@ -139,7 +139,7 @@ class TilePuzzleScene def updateCursor arrows = [] - for i in 0...4 + 4.times do |i| arrows.push(pbCanMoveInDir?(@sprites["cursor"].position, (i + 1) * 2, @game == 6)) end @sprites["cursor"].arrows = arrows @@ -169,7 +169,7 @@ class TilePuzzleScene end @tilewidth = @tilebitmap.width / @boardwidth @tileheight = @tilebitmap.height / @boardheight - for i in 0...@boardwidth * @boardheight + (@boardwidth * @boardheight).times do |i| @sprites["tile#{i}"] = BitmapSprite.new(@tilewidth, @tileheight, @viewport) @sprites["tile#{i}"].ox = @tilewidth / 2 @sprites["tile#{i}"].oy = @tileheight / 2 @@ -188,7 +188,7 @@ class TilePuzzleScene def pbShuffleTiles ret = [] - for i in 0...@boardwidth * @boardheight + (@boardwidth * @boardheight).times do |i| ret.push(i) @angles.push(0) end @@ -209,9 +209,9 @@ class TilePuzzleScene if @game == 3 # Make sure only solvable Mystic Squares are allowed. num = 0 blank = -1 - for i in 0...ret.length - 1 + (ret.length - 1).times do |i| blank = i if ret[i] == (@boardwidth * @boardheight) - 1 - for j in i...ret.length + (i...ret.length).each do |j| num += 1 if ret[j] < ret[i] && ret[i] != (@boardwidth * @boardheight) - 1 && ret[j] != (@boardwidth * @boardheight) - 1 end @@ -224,13 +224,13 @@ class TilePuzzleScene end if @game == 1 || @game == 2 ret2 = [] - for i in 0...@boardwidth * @boardheight + (@boardwidth * @boardheight).times do |i| ret2.push(-1) end ret = ret2 + ret end if @game == 2 || @game == 5 - for i in 0...@angles.length + @angles.length.times do |i| @angles[i] = rand(4) end end @@ -240,7 +240,7 @@ class TilePuzzleScene def pbDefaultCursorPosition if @game == 3 - for i in 0...@boardwidth * @boardheight + (@boardwidth * @boardheight).times do |i| return i if @tiles[i] == (@boardwidth * @boardheight) - 1 end end @@ -330,27 +330,27 @@ class TilePuzzleScene if anim @sprites["cursor"].visible = false oldAngles = [] - for i in group + group.each do |i| @sprites["tile#{@tiles[i]}"].z = 1 oldAngles[i] = @sprites["tile#{@tiles[i]}"].angle end rotateTime = Graphics.frame_rate / 4 angleDiff = 90.0 / rotateTime rotateTime.times do - for i in group + group.each do |i| @sprites["tile#{@tiles[i]}"].angle -= angleDiff end pbUpdateSpriteHash(@sprites) Graphics.update Input.update end - for i in group + group.each do |i| @sprites["tile#{@tiles[i]}"].z = 0 @sprites["tile#{@tiles[i]}"].angle = oldAngles[i] - 90 end @sprites["cursor"].visible = true if !pbCheckWin end - for i in group + group.each do |i| tile = @tiles[i] @angles[tile] -= 1 @angles[tile] += 4 if @angles[tile] < 0 @@ -361,7 +361,7 @@ class TilePuzzleScene def pbGetNearTiles(pos) ret = [pos] if @game == 7 - for i in [2, 4, 6, 8] + [2, 4, 6, 8].each do |i| ret.push(pbMoveCursor(pos, i)) if pbCanMoveInDir?(pos, i, true) end end @@ -414,7 +414,7 @@ class TilePuzzleScene (dist < 0 && cursor >= @boardwidth) cursor += (@boardwidth * dist) end - for i in 0...@boardheight + @boardheight.times do |i| tiles.push(cursor - (i * dist * @boardwidth)) end else @@ -423,7 +423,7 @@ class TilePuzzleScene (dist < 0 && cursor % @boardwidth < @boardwidth - 1) cursor -= dist end - for i in 0...@boardwidth + @boardwidth.times do |i| tiles.push(cursor + (i * dist)) end end @@ -441,7 +441,7 @@ class TilePuzzleScene if [2, 8].include?(dir) distancePerFrame = (@tileheight.to_f / shiftTime).ceil shiftTime.times do - for i in tiles + tiles.each do |i| @sprites["tile#{@tiles[i]}"].y -= dist * distancePerFrame end pbUpdateSpriteHash(@sprites) @@ -451,7 +451,7 @@ class TilePuzzleScene else distancePerFrame = (@tilewidth.to_f / shiftTime).ceil shiftTime.times do - for i in tiles + tiles.each do |i| @sprites["tile#{@tiles[i]}"].x += dist * distancePerFrame end pbUpdateSpriteHash(@sprites) @@ -461,10 +461,10 @@ class TilePuzzleScene end end temp = [] - for i in tiles + tiles.each do |i| temp.push(@tiles[i]) end - for i in 0...temp.length + temp.length.times do |i| @tiles[tiles[(i + 1) % (temp.length)]] = temp[i] end if anim @@ -487,7 +487,7 @@ class TilePuzzleScene end def pbCheckWin - for i in 0...@boardwidth * @boardheight + (@boardwidth * @boardheight).times do |i| return false if @tiles[i] != i return false if @angles[i] != 0 end diff --git a/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/001_Challenge_BattleChallenge.rb b/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/001_Challenge_BattleChallenge.rb index bb74700ed..b41143cb0 100644 --- a/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/001_Challenge_BattleChallenge.rb +++ b/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/001_Challenge_BattleChallenge.rb @@ -216,7 +216,7 @@ class BattleChallengeData while @trainers.length < @numRounds newtrainer = pbBattleChallengeTrainer(@wins + @trainers.length, btTrainers) found = false - for tr in @trainers + @trainers.each do |tr| found = true if tr == newtrainer end @trainers.push(newtrainer) if !found diff --git a/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/002_Challenge_Data.rb b/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/002_Challenge_Data.rb index bb7340943..68129aa95 100644 --- a/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/002_Challenge_Data.rb +++ b/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/002_Challenge_Data.rb @@ -130,7 +130,7 @@ class PBPokemon end moves = pieces[4].split(/\s*,\s*/) moveid = [] - for i in 0...Pokemon::MAX_MOVES + Pokemon::MAX_MOVES.times do |i| move_data = GameData::Move.try_get(moves[i]) moveid.push(move_data.id) if move_data end diff --git a/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/003_Challenge_ChooseFoes.rb b/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/003_Challenge_ChooseFoes.rb index dd13968a1..caf10494d 100644 --- a/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/003_Challenge_ChooseFoes.rb +++ b/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/003_Challenge_ChooseFoes.rb @@ -60,7 +60,7 @@ def pbGenerateBattleTrainer(idxTrainer, rules) # The number of possible Pokémon is <= the required number; make them # all Pokémon and use them if pokemonnumbers.length <= rules.ruleset.suggestedNumber - for n in pokemonnumbers + pokemonnumbers.each do |n| rndpoke = btpokemon[n] pkmn = rndpoke.createPokemon(level, indvalues, opponent) opponent.party.push(pkmn) diff --git a/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/005_UI_BattleSwap.rb b/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/005_UI_BattleSwap.rb index a5235d4f4..abbe25d0e 100644 --- a/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/005_UI_BattleSwap.rb +++ b/Data/Scripts/018_Alternate battle modes/001_Battle Frontier/005_UI_BattleSwap.rb @@ -76,7 +76,7 @@ class BattleSwapScene def pbGetCommands(list, choices) commands = [] - for i in 0...list.length + list.length.times do |i| pkmn = list[i] category = pkmn.species_data.category cmd = _INTL("{1} - {2} Pokémon", pkmn.speciesName, category) diff --git a/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/001_Challenge_ChallengeRules.rb b/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/001_Challenge_ChallengeRules.rb index 5fc9b4d4f..8c99ec4db 100644 --- a/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/001_Challenge_ChallengeRules.rb +++ b/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/001_Challenge_ChallengeRules.rb @@ -17,7 +17,7 @@ class PokemonChallengeRules ret = PokemonChallengeRules.new(@ruleset.copy) ret.setBattleType(@battletype) ret.setLevelAdjustment(@levelAdjustment) - for rule in @battlerules + @battlerules.each do |rule| ret.addBattleRule(rule) end return ret @@ -110,7 +110,7 @@ class PokemonChallengeRules def createBattle(scene, trainer1, trainer2) battle = @battletype.pbCreateBattle(scene, trainer1, trainer2) - for p in @battlerules + @battlerules.each do |p| p.setRule(battle) end return battle diff --git a/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/002_Challenge_Rulesets.rb b/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/002_Challenge_Rulesets.rb index cc8062d19..0622a17bb 100644 --- a/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/002_Challenge_Rulesets.rb +++ b/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/002_Challenge_Rulesets.rb @@ -12,13 +12,13 @@ class PokemonRuleSet def copy ret = PokemonRuleSet.new(@number) - for rule in @pokemonRules + @pokemonRules.each do |rule| ret.addPokemonRule(rule) end - for rule in @teamRules + @teamRules.each do |rule| ret.addTeamRule(rule) end - for rule in @subsetRules + @subsetRules.each do |rule| ret.addSubsetRule(rule) end return ret @@ -51,7 +51,7 @@ class PokemonRuleSet minLevel = 1 maxLevel = GameData::GrowthRate.max_level num = self.suggestedNumber - for rule in @pokemonRules + @pokemonRules.each do |rule| case rule when MinimumLevelRestriction minLevel = rule.level @@ -60,7 +60,7 @@ class PokemonRuleSet end end totalLevel = maxLevel * num - for rule in @subsetRules + @subsetRules.each do |rule| totalLevel = rule.level if rule.is_a?(TotalLevelRestriction) end return [maxLevel, minLevel].max if totalLevel >= maxLevel * num @@ -126,7 +126,7 @@ class PokemonRuleSet def isPokemonValid?(pkmn) return false if !pkmn - for rule in @pokemonRules + @pokemonRules.each do |rule| return false if !rule.isValid?(pkmn) end return true @@ -149,16 +149,16 @@ class PokemonRuleSet return false if !team || team.length < self.minTeamLength return false if team.length > self.maxTeamLength teamNumber = [self.maxLength, team.length].min - for pkmn in team + team.each do |pkmn| return false if !isPokemonValid?(pkmn) end - for rule in @teamRules + @teamRules.each do |rule| return false if !rule.isValid?(team) end if @subsetRules.length > 0 pbEachCombination(team, teamNumber) { |comb| isValid = true - for rule in @subsetRules + @subsetRules.each do |rule| next if rule.isValid?(comb) isValid = false break @@ -177,7 +177,7 @@ class PokemonRuleSet return false if !team || team.length < self.minTeamLength teamNumber = [self.maxLength, team.length].min validPokemon = [] - for pkmn in team + team.each do |pkmn| validPokemon.push(pkmn) if isPokemonValid?(pkmn) end return false if validPokemon.length < teamNumber @@ -200,7 +200,7 @@ class PokemonRuleSet error.push(_INTL("No more than {1} Pokémon may enter.", self.maxLength)) if error return false end - for pkmn in team + team.each do |pkmn| next if isPokemonValid?(pkmn) if pkmn error.push(_INTL("{1} is not allowed.", pkmn.name)) if error @@ -209,12 +209,12 @@ class PokemonRuleSet end return false end - for rule in @teamRules + @teamRules.each do |rule| next if rule.isValid?(team) error.push(rule.errorMessage) if error return false end - for rule in @subsetRules + @subsetRules.each do |rule| next if rule.isValid?(team) error.push(rule.errorMessage) if error return false diff --git a/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/003_Challenge_EntryRestrictions.rb b/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/003_Challenge_EntryRestrictions.rb index 611afe63b..8c5e69214 100644 --- a/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/003_Challenge_EntryRestrictions.rb +++ b/Data/Scripts/018_Alternate battle modes/002_Battle Frontier rules/003_Challenge_EntryRestrictions.rb @@ -125,8 +125,8 @@ end #=============================================================================== class NicknameClause def isValid?(team) - for i in 0...team.length - 1 - for j in i + 1...team.length + (team.length - 1).times do |i| + (i + 1...team.length).each do |j| return false if team[i].name == team[j].name return false if !NicknameChecker.check(team[i].name, team[i].species) end diff --git a/Data/Scripts/018_Alternate battle modes/002_BugContest.rb b/Data/Scripts/018_Alternate battle modes/002_BugContest.rb index dfe419c6f..f19296d7f 100644 --- a/Data/Scripts/018_Alternate battle modes/002_BugContest.rb +++ b/Data/Scripts/018_Alternate battle modes/002_BugContest.rb @@ -69,7 +69,7 @@ class BugContestState # can be outdoors, with its own grassy patches. def pbSetReception(*arg) @reception = [] - for i in arg + arg.each do |i| @reception.push(i) end end @@ -77,7 +77,7 @@ class BugContestState def pbOffLimits?(map) # p [map,@contestMap,@reception] return false if map == @contestMap - for i in @reception + @reception.each do |i| return false if map == i end return true @@ -100,7 +100,7 @@ class BugContestState if !$PokemonEncounters.map_has_encounter_type?(@contestMap, enctype) enctype = :Land end - for cont in @contestants + @contestants.each do |cont| enc = $PokemonEncounters.choose_wild_pokemon_for_map(@contestMap, enctype) if !enc raise _INTL("No encounters for map {1}, so can't judge contest", @contestMap) @@ -163,7 +163,7 @@ class BugContestState @timer = Graphics.frame_count @places = [] chosenpkmn = $player.party[@chosenPokemon] - for i in 0...$player.party.length + $player.party.length.times do |i| @otherparty.push($player.party[i]) if i != @chosenPokemon end @contestants = [] @@ -182,7 +182,7 @@ class BugContestState end def place - for i in 0...3 + 3.times do |i| return i if @places[i][0] < 0 end return 3 @@ -190,7 +190,7 @@ class BugContestState def pbEnd(interrupted = false) return if !@inProgress - for poke in @otherparty + @otherparty.each do |poke| $player.party.push(poke) end if !interrupted diff --git a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/001_ChallengeGenerator_Data.rb b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/001_ChallengeGenerator_Data.rb index 26154d8c7..1770a0bdb 100644 --- a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/001_ChallengeGenerator_Data.rb +++ b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/001_ChallengeGenerator_Data.rb @@ -85,10 +85,10 @@ def pbArrangeByTier(pokemonlist, rule) # Sort each Pokémon into tiers. Which tier a Pokémon is put in deoends on the # Pokémon's position within pokemonlist (later = higher tier). pokemonlist is # already roughly arranged by rank from weakest to strongest. - for i in 0...pokemonlist.length + pokemonlist.length.times do |i| next if !rule.ruleset.isPokemonValid?(pokemonlist[i]) validtiers = [] - for j in 0...tiers.length + tiers.length.times do |j| validtiers.push(j) if tiers[j].ruleset.isPokemonValid?(pokemonlist[i]) end if validtiers.length > 0 @@ -98,7 +98,7 @@ def pbArrangeByTier(pokemonlist, rule) end # Now for each tier, sort the Pokemon in that tier by their BST (lowest first). ret = [] - for i in 0...tiers.length + tiers.length.times do |i| tierPokemon[i].sort! { |a, b| bstA = baseStatTotal(a.species) bstB = baseStatTotal(b.species) @@ -116,7 +116,7 @@ def pbReplenishBattlePokemon(party, rule) while party.length < 20 pkmn = pbRandomPokemonFromRule(rule, nil) found = false - for pk in party + party.each do |pk| next if !isBattlePokemonDuplicate(pkmn, pk) found = true break @@ -129,7 +129,7 @@ def isBattlePokemonDuplicate(pk, pk2) return false if pk.species != pk2.species moves1 = [] moves2 = [] - for i in 0...Pokemon::MAX_MOVES + Pokemon::MAX_MOVES.times do |i| moves1.push((pk.moves[i]) ? pk.moves[i].id : nil) moves2.push((pk2.moves[i]) ? pk2.moves[i].id : nil) end @@ -144,11 +144,11 @@ end def pbRemoveDuplicates(party) ret = [] - for pk in party + party.each do |pk| found = false count = 0 firstIndex = -1 - for i in 0...ret.length + ret.length.times do |i| pk2 = ret[i] if isBattlePokemonDuplicate(pk, pk2) found = true @@ -181,7 +181,7 @@ def pbGenerateChallenge(rule, tag) btpokemon = pbGetBTPokemon(tag) if btpokemon && btpokemon.length != 0 suggestedLevel = rule.ruleset.suggestedLevel - for pk in btpokemon + btpokemon.each do |pk| pkmn = pk.createPokemon(suggestedLevel, 31, nil) party.push(pkmn) if rule.ruleset.isPokemonValid?(pkmn) end @@ -209,7 +209,7 @@ def pbGenerateChallenge(rule, tag) teams.delete_at(i) elsif teams[i].totalGames >= 250 # retire - for j in 0...teams[i].length + teams[i].length.times do |j| party.push(teams[i][j]) end teams[i] = RuledTeam.new(party, rule) @@ -244,12 +244,12 @@ def pbGenerateChallenge(rule, tag) } i += 1 gameCount = 0 - for team in teams + teams.each do |team| gameCount += team.games end yield(nil) if gameCount / teams.length >= 12 - for team in teams + teams.each do |team| team.updateRating end break @@ -261,9 +261,9 @@ def pbGenerateChallenge(rule, tag) party = [] yield(nil) teams.sort! { |a, b| a.rating <=> b.rating } - for team in teams + teams.each do |team| next if team.rating <= cutoffrating - for i in 0...team.length + team.length.times do |i| party.push(team[i]) end end @@ -284,7 +284,7 @@ def pbWriteCup(id, rules) return if !$DEBUG trlists = (load_data("Data/trainer_lists.dat") rescue []) list = [] - for i in 0...trlists.length + trlists.length.times do |i| tr = trlists[i] if tr[5] list.push("*" + (tr[3].sub(/\.txt$/, ""))) @@ -312,7 +312,7 @@ def pbWriteCup(id, rules) cmd = pbMessage(_INTL("Choose a challenge."), list, -1) if cmd >= 0 pbMessage(_INTL("This challenge will use the Pokémon list from {1}.", list[cmd])) - for i in 0...trlists.length + trlists.length.times do |i| tr = trlists[i] while !tr[5] && tr[2].include?(id) tr[2].delete(id) diff --git a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb index 87689d895..2575cb55d 100644 --- a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb +++ b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/002_ChallengeGenerator_Pokemon.rb @@ -61,7 +61,7 @@ def pbGetLegalMoves2(species, maxlevel) babyspecies = babySpecies(species) GameData::Species.get(babyspecies).egg_moves.each { |m| addMove(moves, m, 2) } movedatas = [] - for move in moves + moves.each do |move| movedatas.push([move, GameData::Move.get(move)]) end # Delete less powerful moves @@ -70,9 +70,9 @@ def pbGetLegalMoves2(species, maxlevel) a.delete(item) end } - for move in moves + moves.each do |move| md = GameData::Move.get(move) - for move2 in movedatas + movedatas.each do |move2| # If we have a move that always hits, remove all other moves with no # effect of the same type and <= base power if md.accuracy == 0 && move2[1].function_code == "None" && @@ -130,7 +130,7 @@ end def hasMorePowerfulMove(moves, thismove) thisdata = GameData::Move.get(thismove) return false if thisdata.base_damage == 0 - for move in moves + moves.each do |move| next if !move moveData = GameData::Move.get(move) if moveData.type == thisdata.type && moveData.base_damage > thisdata.base_damage @@ -262,9 +262,7 @@ def pbRandomPokemonFromRule(rules, trainer) sketch = false if moves[0] == :SKETCH sketch = true - for m in 0...Pokemon::MAX_MOVES - moves[m] = pbRandomMove - end + Pokemon::MAX_MOVES.times { |m| moves[m] = pbRandomMove } end next if moves.length == 0 if (moves | []).length < Pokemon::MAX_MOVES @@ -303,7 +301,7 @@ def pbRandomPokemonFromRule(rules, trainer) hasPhysical = false hasSpecial = false hasNormal = false - for move in newmoves + newmoves.each do |move| d = GameData::Move.get(move) if d.base_damage >= 1 totalbasedamage += d.base_damage diff --git a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb index 546264527..5020afd60 100644 --- a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb +++ b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/003_ChallengeGenerator_Trainers.rb @@ -17,7 +17,7 @@ def pbTrainerInfo(pokemonlist, trfile, rules) # No battle trainers found; fill bttrainers with 200 randomly chosen ones from # all that exist (with a base money < 100) if bttrainers.length == 0 - for i in 0...200 + 200.times do |i| yield(nil) if block_given? && i % 50 == 0 trainerid = nil if GameData::TrainerType.exists?(:YOUNGSTER) && rand(30) == 0 @@ -53,7 +53,7 @@ def pbTrainerInfo(pokemonlist, trfile, rules) rulesetTeam = rules.ruleset.copy.clearPokemonRules pkmntypes = [] validities = [] - for pkmn in pokemonlist + pokemonlist.each do |pkmn| pkmn.level = suggestedLevel if pkmn.level != suggestedLevel pkmntypes.push(getTypes(pkmn.species)) validities.push(rules.ruleset.isPokemonValid?(pkmn)) @@ -62,7 +62,7 @@ def pbTrainerInfo(pokemonlist, trfile, rules) # pokemonlist for that trainer, and copy the trainer and their set of Pokémon # to newbttrainers newbttrainers = [] - for btt in 0...bttrainers.length + bttrainers.length.times do |btt| yield(nil) if block_given? && btt % 50 == 0 trainerdata = bttrainers[btt] pokemonnumbers = trainerdata[5] || [] @@ -71,7 +71,7 @@ def pbTrainerInfo(pokemonlist, trfile, rules) species = [] types = {} GameData::Type.each { |t| types[t.id] = 0 } - for pn in pokemonnumbers + pokemonnumbers.each do |pn| pkmn = btpokemon[pn] species.push(pkmn.species) t = getTypes(pkmn.species) @@ -104,7 +104,7 @@ def pbTrainerInfo(pokemonlist, trfile, rules) # pokemonlist, or if the trainer is positioned earlier in bttrainers (i.e. # later trainers get better Pokémon). numbersPokemon = [] - for index in 0...pokemonlist.length + pokemonlist.length.times do |index| next if !validities[index] pkmn = pokemonlist[index] absDiff = ((index * 8 / pokemonlist.length) - (btt * 8 / bttrainers.length)).abs @@ -137,7 +137,7 @@ def pbTrainerInfo(pokemonlist, trfile, rules) # formed from what's in numbers if numbers.length < Settings::MAX_PARTY_SIZE || !rulesetTeam.hasValidTeam?(numbersPokemon) - for index in 0...pokemonlist.length + pokemonlist.length.times do |index| pkmn = pokemonlist[index] next if !validities[index] if species.include?(pkmn.species) @@ -180,18 +180,18 @@ def pbTrainerInfo(pokemonlist, trfile, rules) # Add the trainer and Pokémon data from above to trainer_lists.dat, and then # create all PBS files from it pbpokemonlist = [] - for pkmn in pokemonlist + pokemonlist.each do |pkmn| pbpokemonlist.push(PBPokemon.fromPokemon(pkmn)) end trlists = (load_data("Data/trainer_lists.dat") rescue []) hasDefault = false trIndex = -1 - for i in 0...trlists.length + trlists.length.times do |i| next if !trlists[i][5] hasDefault = true break end - for i in 0...trlists.length + trlists.length.times do |i| if trlists[i][2].include?(trfile) trIndex = i trlists[i][0] = newbttrainers diff --git a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/004_ChallengeGenerator_BattleSim.rb b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/004_ChallengeGenerator_BattleSim.rb index 4f0917e85..092ec62f8 100644 --- a/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/004_ChallengeGenerator_BattleSim.rb +++ b/Data/Scripts/018_Alternate battle modes/003_Battle Frontier generator/004_ChallengeGenerator_BattleSim.rb @@ -9,7 +9,7 @@ class RuledTeam @team = [] retnum = [] loop do - for i in 0...count + count.times do |i| retnum[i] = rand(party.length) @team[i] = party[retnum[i]] party.delete_at(retnum[i]) @@ -71,7 +71,7 @@ class RuledTeam def load(party) ret = [] - for i in 0...team.length + team.length.times do |i| ret.push(party[team[i]]) end return ret @@ -208,7 +208,7 @@ class PlayerRating g = [] e = [] score = [] - for i in 0...matches.length + matches.length.times do |i| match = matches[i] g[i] = getGFactor(match.opponentDeviation) e[i] = getEFactor(rating, match.opponentRating, g[i]) @@ -216,13 +216,13 @@ class PlayerRating end # Estimated variance variance = 0.0 - for i in 0...matches.length + matches.length.times do |i| variance += g[i] * g[i] * e[i] * (1 - e[i]) end variance = 1.0 / variance # Improvement sum sum = 0.0 - for i in 0...matches.length + matches.length.times do |i| v = score[i] sum += g[i] * (v.to_f - e[i]) if v != -1 end @@ -333,15 +333,15 @@ def pbDecideWinnerScore(party0, party1, rating) types1 = [] types2 = [] abilities = [] - for j in 0...party1.length + party1.length.times do |j| types1.push(party1[j].types[0]) types2.push(party1[j].types[1] || party1[j].types[0]) abilities.push(party1[j].ability_id) end - for i in 0...party0.length - for move in party0[i].moves + party0.length.times do |i| + party0[i].moves.each do |move| next if !move - for j in 0...party1.length + party1.length.times do |j| score += pbDecideWinnerEffectiveness( move.id, types1[j], types2[j], abilities[j], [-16, -8, 0, 4, 12, 20] ) diff --git a/Data/Scripts/019_Utilities/001_Utilities.rb b/Data/Scripts/019_Utilities/001_Utilities.rb index a5d526576..19bfb82f0 100644 --- a/Data/Scripts/019_Utilities/001_Utilities.rb +++ b/Data/Scripts/019_Utilities/001_Utilities.rb @@ -3,9 +3,9 @@ #=============================================================================== def _pbNextComb(comb, length) i = comb.length - 1 - begin + loop do valid = true - for j in i...comb.length + (i...comb.length).each do |j| if j == i comb[j] += 1 else @@ -18,7 +18,8 @@ def _pbNextComb(comb, length) end return true if valid i -= 1 - end while i >= 0 + break unless i >= 0 + end return false end @@ -30,22 +31,19 @@ def pbEachCombination(array, num) yield array return elsif num == 1 - for x in array + array.each do |x| yield [x] end return end currentComb = [] arr = [] - for i in 0...num - currentComb[i] = i - end - begin - for i in 0...num - arr[i] = array[currentComb[i]] - end + num.times { |i| currentComb[i] = i } + loop do + num.times { |i| arr[i] = array[currentComb[i]] } yield arr - end while _pbNextComb(currentComb, array.length) + break unless _pbNextComb(currentComb, array.length) + end end # Returns a language ID @@ -113,7 +111,7 @@ end def getConstantName(mod, value) mod = Object.const_get(mod) if mod.is_a?(Symbol) - for c in mod.constants + mod.constants.each do |c| return c.to_s if mod.const_get(c.to_sym) == value end raise _INTL("Value {1} not defined by a constant in {2}", value, mod.name) @@ -121,7 +119,7 @@ end def getConstantNameOrValue(mod, value) mod = Object.const_get(mod) if mod.is_a?(Symbol) - for c in mod.constants + mod.constants.each do |c| return c.to_s if mod.const_get(c.to_sym) == value end return value.inspect @@ -177,7 +175,7 @@ def pbExclaim(event, id = Settings::EXCLAMATION_ANIMATION_ID, tinting = false) if event.is_a?(Array) sprite = nil done = [] - for i in event + event.each do |i| if !done.include?(i.id) sprite = $scene.spriteset.addUserAnimation(id, i.x, i.y, tinting, 2) done.push(i.id) @@ -428,7 +426,7 @@ def pbMoveTutorChoose(move, movelist = nil, bymachine = false, oneusemachine = f ret = false move = GameData::Move.get(move).id if movelist != nil && movelist.is_a?(Array) - for i in 0...movelist.length + movelist.length.times do |i| movelist[i] = GameData::Move.get(movelist[i]).id end end @@ -466,7 +464,7 @@ end def pbConvertItemToItem(variable, array) item = GameData::Item.get(pbGet(variable)) pbSet(variable, nil) - for i in 0...(array.length / 2) + (array.length / 2).times do |i| next if item != array[2 * i] pbSet(variable, array[(2 * i) + 1]) return @@ -476,7 +474,7 @@ end def pbConvertItemToPokemon(variable, array) item = GameData::Item.get(pbGet(variable)) pbSet(variable, nil) - for i in 0...(array.length / 2) + (array.length / 2).times do |i| next if item != array[2 * i] pbSet(variable, GameData::Species.get(array[(2 * i) + 1]).id) return @@ -505,12 +503,13 @@ def pbCommonEvent(id) celist = ce.list interp = Interpreter.new interp.setup(celist, 0) - begin + loop do Graphics.update Input.update interp.update pbUpdateSceneMap - end while interp.running? + break unless interp.running? + end return true end @@ -550,7 +549,7 @@ def pbHideVisibleObjects end def pbShowObjects(visibleObjects) - for o in visibleObjects + visibleObjects.each do |o| next if pbDisposed?(o) o.visible = true end @@ -578,7 +577,7 @@ end def pbChooseLanguage commands = [] - for lang in Settings::LANGUAGES + Settings::LANGUAGES.each do |lang| commands.push(lang[0]) end return pbShowCommands(nil, commands) diff --git a/Data/Scripts/019_Utilities/002_Utilities_Pokemon.rb b/Data/Scripts/019_Utilities/002_Utilities_Pokemon.rb index 3e89be12f..79f50e9bb 100644 --- a/Data/Scripts/019_Utilities/002_Utilities_Pokemon.rb +++ b/Data/Scripts/019_Utilities/002_Utilities_Pokemon.rb @@ -210,22 +210,22 @@ def pbSize(pkmn) m = pkmn.personalID & 0xFF n = (pkmn.personalID >> 8) & 0xFF s = ((((ativ ^ dfiv) * hpiv) ^ m) * 256) + (((saiv ^ sdiv) * spiv) ^ n) - xyz = [] - if s < 10 then xyz = [ 290, 1, 0] - elsif s < 110 then xyz = [ 300, 1, 10] - elsif s < 310 then xyz = [ 400, 2, 110] - elsif s < 710 then xyz = [ 500, 4, 310] - elsif s < 2710 then xyz = [ 600, 20, 710] - elsif s < 7710 then xyz = [ 700, 50, 2710] - elsif s < 17710 then xyz = [ 800, 100, 7710] - elsif s < 32710 then xyz = [ 900, 150, 17710] - elsif s < 47710 then xyz = [1000, 150, 32710] - elsif s < 57710 then xyz = [1100, 100, 47710] - elsif s < 62710 then xyz = [1200, 50, 57710] - elsif s < 64710 then xyz = [1300, 20, 62710] - elsif s < 65210 then xyz = [1400, 5, 64710] - elsif s < 65410 then xyz = [1500, 2, 65210] - else xyz = [1700, 1, 65510] + xyz = [1700, 1, 65510] + case s + when 0...10 then xyz = [ 290, 1, 0] + when 10...110 then xyz = [ 300, 1, 10] + when 110...310 then xyz = [ 400, 2, 110] + when 310...710 then xyz = [ 500, 4, 310] + when 710...2710 then xyz = [ 600, 20, 710] + when 2710...7710 then xyz = [ 700, 50, 2710] + when 7710...17710 then xyz = [ 800, 100, 7710] + when 17710...32710 then xyz = [ 900, 150, 17710] + when 32710...47710 then xyz = [1000, 150, 32710] + when 47710...57710 then xyz = [1100, 100, 47710] + when 57710...62710 then xyz = [1200, 50, 57710] + when 62710...64710 then xyz = [1300, 20, 62710] + when 64710...65210 then xyz = [1400, 5, 64710] + when 65210...65410 then xyz = [1500, 2, 65210] end return ((((s - xyz[2]) / xyz[1]) + xyz[0]).floor * baseheight / 10).floor end diff --git a/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb b/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb index b31cb9caf..c7589e28e 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb @@ -427,7 +427,7 @@ def pbTrainerTypeEditorNew(default_name) id = "T_" + id end if GameData::TrainerType.exists?(id) - for i in 1..100 + (1..100).each do |i| trial_id = sprintf("%s_%d", id, i) next if GameData::TrainerType.exists?(trial_id) id = trial_id @@ -522,10 +522,10 @@ def pbTrainerBattleEditor tr_data.version, tr_data.real_lose_text ] - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| data.push(tr_data.pokemon[i]) end - for i in 0...TrainerBattleProperty::NUM_ITEMS + TrainerBattleProperty::NUM_ITEMS.times do |i| data.push(tr_data.items[i]) end loop do @@ -533,10 +533,10 @@ def pbTrainerBattleEditor break if !data party = [] items = [] - for i in 0...Settings::MAX_PARTY_SIZE + Settings::MAX_PARTY_SIZE.times do |i| party.push(data[4 + i]) if data[4 + i] && data[4 + i][:species] end - for i in 0...TrainerBattleProperty::NUM_ITEMS + TrainerBattleProperty::NUM_ITEMS.times do |i| items.push(data[4 + Settings::MAX_PARTY_SIZE + i]) if data[4 + Settings::MAX_PARTY_SIZE + i] end if !data[0] @@ -959,7 +959,7 @@ def pbItemEditorNew(default_name) id = "ITEM_" + id end if GameData::Item.exists?(id) - for i in 1..100 + (1..100).each do |i| trial_id = sprintf("%s_%d", id, i) next if GameData::Item.exists?(trial_id) id = trial_id @@ -1387,7 +1387,7 @@ def pbAppendEvoToFamilyArray(species, array, seenarray) evos = GameData::Species.get(species).get_evolutions if evos.length > 0 subarray = [] - for i in evos + evos.each do |i| pbAppendEvoToFamilyArray(i[0], subarray, seenarray) end array.push(subarray) if subarray.length > 0 @@ -1410,9 +1410,9 @@ end def pbEvoFamiliesToStrings ret = [] families = pbGetEvoFamilies - for fam in 0...families.length + families.length.times do |fam| string = "" - for p in 0...families[fam].length + families[fam].length.times do |p| if p >= 3 string += " + #{families[fam].length - 3} more" break @@ -1457,7 +1457,7 @@ def pbAnimationsOrganiser loop do if refreshlist commands = [] - for i in 0...list.length + list.length.times do |i| commands.push(sprintf("%d: %s", i, (list[i]) ? list[i].name : "???")) end end diff --git a/Data/Scripts/020_Debug/001_Editor screens/002_EditorScreens_TerrainTags.rb b/Data/Scripts/020_Debug/001_Editor screens/002_EditorScreens_TerrainTags.rb index c05e18b19..3b184b755 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/002_EditorScreens_TerrainTags.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/002_EditorScreens_TerrainTags.rb @@ -60,7 +60,7 @@ class PokemonTilesetScene def choose_tileset commands = [] - for i in 1...@tilesets_data.length + (1...@tilesets_data.length).each do |i| commands.push(sprintf("%03d %s", i, @tilesets_data[i].name)) end ret = pbShowCommands(nil, commands, -1) @@ -69,10 +69,10 @@ class PokemonTilesetScene def draw_tiles @sprites["tileset"].bitmap.clear - for yy in 0...@visible_height + @visible_height.times do |yy| autotile_row = (@top_y == 0 && yy == 0) # Autotiles id_y_offset = (autotile_row) ? 0 : TILESET_START_ID + ((@top_y + yy - 1) * TILES_PER_ROW) - for xx in 0...TILES_PER_ROW + TILES_PER_ROW.times do |xx| id_x_offset = (autotile_row) ? xx * TILES_PER_AUTOTILE : xx @tilehelper.bltTile(@sprites["tileset"].bitmap, xx * TILE_SIZE, yy * TILE_SIZE, id_y_offset + id_x_offset) @@ -84,8 +84,8 @@ class PokemonTilesetScene @sprites["overlay"].bitmap.clear # Draw all text over tiles (terrain tag numbers) textpos = [] - for yy in 0...@visible_height - for xx in 0...TILES_PER_ROW + @visible_height.times do |yy| + TILES_PER_ROW.times do |xx| tile_id = tile_ID_from_coordinates(xx, @top_y + yy) terr = @tileset.terrain_tags[tile_id] textpos.push(["#{terr}", (xx * TILE_SIZE) + (TILE_SIZE / 2), (yy * TILE_SIZE) - 6, 2, TEXT_COLOR, TEXT_SHADOW_COLOR]) @@ -137,9 +137,7 @@ class PokemonTilesetScene def set_terrain_tag_for_tile_ID(i, value) if i < TILESET_START_ID - for j in 0...TILES_PER_AUTOTILE - @tileset.terrain_tags[i + j] = value - end + TILES_PER_AUTOTILE.times { |j| @tileset.terrain_tags[i + j] = value } else @tileset.terrain_tags[i] = value end diff --git a/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb b/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb index f477c214e..69347db71 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb @@ -168,7 +168,7 @@ class MapScreenScene mapsprite = getMapSprite(id) dispx = mapsprite.x dispy = mapsprite.y - for conn in conns + conns.each do |conn| if conn[0] == id b = sprites.any? { |i| i == conn[3] } if !b @@ -192,7 +192,7 @@ class MapScreenScene end def hasConnections?(conns, id) - for conn in conns + conns.each do |conn| return true if conn[0] == id || conn[3] == id end return false @@ -228,7 +228,7 @@ class MapScreenScene thissprite = getMapSprite(map) thisdims = MapFactoryHelper.getMapDims(map) ret = [] - for i in keys + keys.each do |i| next if i == map othersprite = getMapSprite(i) otherdims = MapFactoryHelper.getMapDims(i) @@ -250,19 +250,19 @@ class MapScreenScene def generateConnectionData ret = [] # Create a clone of current map connection - for conn in @mapconns + @mapconns.each do |conn| ret.push(conn.clone) end keys = @mapsprites.keys return ret if keys.length < 2 # Remove all connections containing any sprites on the canvas from the array - for i in keys + keys.each do |i| removeOldConnections(ret, i) end # Rebuild connections - for i in keys + keys.each do |i| refs = getDirectConnections(keys, i) - for refmap in refs + refs.each do |refmap| othersprite = getMapSprite(i) refsprite = getMapSprite(refmap) c1 = (refsprite.x - othersprite.x) / 4 @@ -302,7 +302,7 @@ class MapScreenScene def saveMapSpritePos @mapspritepos.clear - for i in @mapsprites.keys + @mapsprites.keys.each do |i| s = @mapsprites[i] @mapspritepos[i] = [s.x, s.y] if s && !s.disposed? end @@ -332,7 +332,7 @@ class MapScreenScene @mapinfos = pbLoadMapInfos conns = MapFactoryHelper.getMapConnections @mapconns = [] - for map_conns in conns + conns.each do |map_conns| next if !map_conns map_conns.each do |c| @mapconns.push(c.clone) if !@mapconns.any? { |x| x[0] == c[0] && x[3] == c[3] } @@ -347,7 +347,7 @@ class MapScreenScene end def setTopSprite(id) - for i in @mapsprites.keys + @mapsprites.keys.each do |i| @mapsprites[i].z = (i == id) ? 1 : 0 end end @@ -441,7 +441,7 @@ class MapScreenScene else xpos = x - @dragOffsetX ypos = y - @dragOffsetY - for i in @mapspritepos.keys + @mapspritepos.keys.each do |i| sprite = getMapSprite(i) sprite.x = (@mapspritepos[i][0] + xpos) & ~3 sprite.y = (@mapspritepos[i][1] + ypos) & ~3 @@ -456,7 +456,7 @@ class MapScreenScene end def hittest(x, y) - for i in @mapsprites.keys + @mapsprites.keys.each do |i| sx = @mapsprites[i].x sy = @mapsprites[i].y sr = sx + @mapsprites[i].bitmap.width @@ -495,22 +495,22 @@ class MapScreenScene end end if Input.press?(Input::UP) - for i in @mapsprites + @mapsprites.each do |i| i[1].y += 4 if i end end if Input.press?(Input::DOWN) - for i in @mapsprites + @mapsprites.each do |i| i[1].y -= 4 if i end end if Input.press?(Input::LEFT) - for i in @mapsprites + @mapsprites.each do |i| i[1].x += 4 if i end end if Input.press?(Input::RIGHT) - for i in @mapsprites + @mapsprites.each do |i| i[1].x -= 4 if i end end diff --git a/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb b/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb index 951abe659..b355c1cd9 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb @@ -3,8 +3,8 @@ #=============================================================================== def findBottom(bitmap) return 0 if !bitmap - for i in 1..bitmap.height - for j in 0..bitmap.width - 1 + (1..bitmap.height).each do |i| + bitmap.width.times do |j| return bitmap.height - i if bitmap.get_pixel(j, bitmap.height - i).alpha > 0 end end @@ -117,7 +117,7 @@ class SpritePositioner return end metrics_data = GameData::SpeciesMetrics.get_species_form(@species, @form) - for i in 0...2 + 2.times do |i| pos = Battle::Scene.pbBattlerPosition(i, 1) @sprites["pokemon_#{i}"].x = pos[0] @sprites["pokemon_#{i}"].y = pos[1] diff --git a/Data/Scripts/020_Debug/001_Editor_Utilities.rb b/Data/Scripts/020_Debug/001_Editor_Utilities.rb index a7a8e7f62..1d633cfad 100644 --- a/Data/Scripts/020_Debug/001_Editor_Utilities.rb +++ b/Data/Scripts/020_Debug/001_Editor_Utilities.rb @@ -41,7 +41,7 @@ def pbSafeCopyFile(x, y, z = nil) end def pbAllocateAnimation(animations, name) - for i in 1...animations.length + (1...animations.length).each do |i| anim = animations[i] return i if !anim # if name && name!="" && anim.name==name @@ -62,7 +62,7 @@ def pbMapTree mapinfos = pbLoadMapInfos maplevels = [] retarray = [] - for i in mapinfos.keys + mapinfos.keys.each do |i| info = mapinfos[i] level = -1 while info @@ -97,7 +97,7 @@ def pbMapTree next end retarray.push([maplevel[0], mapinfos[maplevel[0]].name, maplevel[1]]) - for i in index + 1...maplevels.length + (index + 1...maplevels.length).each do |i| if maplevels[i][2] == maplevel[0] stack.push(i) stack.push(maplevel[0]) @@ -191,8 +191,8 @@ def pbChooseMoveListForSpecies(species, defaultMoveID = nil) commands.sort! { |a, b| a[1] <=> b[1] } moveDefault = 0 if defaultMoveID - commands.each_with_index do |_item, i| - moveDefault = i if moveDefault == 0 && i[2] == defaultMoveID + commands.each_with_index do |item, i| + moveDefault = i if moveDefault == 0 && item[2] == defaultMoveID end end # Get all moves @@ -203,8 +203,8 @@ def pbChooseMoveListForSpecies(species, defaultMoveID = nil) end commands2.sort! { |a, b| a[1] <=> b[1] } if defaultMoveID - commands2.each_with_index do |_item, i| - moveDefault = i if moveDefault == 0 && i[2] == defaultMoveID + commands2.each_with_index do |item, i| + moveDefault = i if moveDefault == 0 && item[2] == defaultMoveID end end # Choose from all moves @@ -225,12 +225,14 @@ def pbChooseBallList(defaultMoveID = nil) end commands.sort! { |a, b| a[1] <=> b[1] } if defaultMoveID - for i in 0...commands.length - moveDefault = i if commands[i][0] == defaultMoveID + commands.each_with_index do |cmd, i| + next if cmd[0] != defaultMoveID + moveDefault = i + break end end realcommands = [] - for i in commands + commands.each do |i| realcommands.push(i[1]) end ret = pbCommands2(cmdwin, realcommands, -1, moveDefault, true) @@ -354,7 +356,7 @@ def pbChooseList(commands, default = 0, cancelValue = -1, sortType = 1) commands.each_with_index { |command, i| itemIndex = i if command[0] == itemID } end realcommands = [] - for command in commands + commands.each do |command| if sortType <= 0 realcommands.push(sprintf("%03d: %s", command[0], command[1])) else diff --git a/Data/Scripts/020_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb b/Data/Scripts/020_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb index 5df2d072f..15cd762fd 100644 --- a/Data/Scripts/020_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb +++ b/Data/Scripts/020_Debug/002_Animation editor/001_AnimEditor_SceneElements.rb @@ -5,7 +5,7 @@ class Window_Menu < Window_CommandPokemon def initialize(commands, x, y) tempbitmap = Bitmap.new(32, 32) w = 0 - for i in commands + commands.each do |i| width = tempbitmap.text_size(i).width w = width if w < width end @@ -28,7 +28,7 @@ class Window_Menu < Window_CommandPokemon mousepos = Mouse.getMousePos return -1 if !mousepos toprow = self.top_row - for i in toprow...toprow + @item_max + (toprow...toprow + @item_max).each do |i| rc = Rect.new(0, 32 * (i - toprow), self.contents.width, 32) rc.x += self.x + self.leftEdge rc.y += self.y + self.topEdge @@ -229,7 +229,7 @@ class AnimationWindow < SpriteWrapper rect = Rect.new(0, 0, 0, 0) rectdst = Rect.new(0, 0, 0, 0) x = arrowwidth - for i in 0...NUMFRAMES + NUMFRAMES.times do |i| j = i + @start rect.set((j % 5) * 192, (j / 5) * 192, 192, 192) rectdst.set(x, 0, 96, 96) @@ -237,7 +237,7 @@ class AnimationWindow < SpriteWrapper x += 96 end end - for i in 0...NUMFRAMES + NUMFRAMES.times do |i| drawrect(@contents, arrowwidth + (i * 96), 0, 96, 96, Color.new(100, 100, 100)) if @start + i == @selected && havebitmap drawborder(@contents, arrowwidth + (i * 96), 0, 96, 96, Color.new(255, 0, 0)) @@ -265,10 +265,10 @@ class AnimationWindow < SpriteWrapper right.y += self.y swatchrects = [] repeattime = Input.time?(Input::MOUSELEFT) / 1000 - for i in 0...NUMFRAMES + NUMFRAMES.times do |i| swatchrects.push(Rect.new(arrowwidth + (i * 96) + self.x, self.y, 96, 96)) end - for i in 0...NUMFRAMES + NUMFRAMES.times do |i| if swatchrects[i].contains(mousepos[0], mousepos[1]) @selected = @start + i @changed = true @@ -458,12 +458,12 @@ class AnimationCanvas < Sprite @target = AnimatedBitmap.new("Graphics/Pictures/testfront").deanimate @testscreen = AnimatedBitmap.new("Graphics/Pictures/testscreen") self.bitmap = @testscreen.bitmap - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| @lastframesprites[i] = SpriteFrame.new(i, @celsprites[i], viewport, true) @lastframesprites[i].selected = false @lastframesprites[i].visible = false end - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| @celsprites[i] = Sprite.new(viewport) @celsprites[i].visible = false @celsprites[i].src_rect = Rect.new(0, 0, 0, 0) @@ -499,7 +499,7 @@ class AnimationCanvas < Sprite def animbitmap=(value) @animbitmap.dispose if @animbitmap @animbitmap = value - for i in 2...PBAnimation::MAX_SPRITES + (2...PBAnimation::MAX_SPRITES).each do |i| @celsprites[i].bitmap = @animbitmap if @celsprites[i] end self.invalidate @@ -512,7 +512,7 @@ class AnimationCanvas < Sprite @selectedbitmap.dispose if @selectedbitmap @celbitmap.dispose if @celbitmap self.bitmap.dispose if self.bitmap - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| @celsprites[i].dispose if @celsprites[i] end super @@ -557,7 +557,7 @@ class AnimationCanvas < Sprite @sprites["pokemon_1"].x += BORDERSIZE @sprites["pokemon_1"].y += BORDERSIZE oldstate = [] - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| oldstate.push([@celsprites[i].visible, @framesprites[i].visible, @lastframesprites[i].visible]) @celsprites[i].visible = false @framesprites[i].visible = false @@ -568,7 +568,7 @@ class AnimationCanvas < Sprite self.update break if !@playing end - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| @celsprites[i].visible = oldstate[i][0] @framesprites[i].visible = oldstate[i][1] @lastframesprites[i].visible = oldstate[i][2] @@ -581,7 +581,7 @@ class AnimationCanvas < Sprite end def invalidate - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| invalidateCel(i) end end @@ -635,7 +635,7 @@ class AnimationCanvas < Sprite def offsetFrame(frame, ox, oy) if frame >= 0 && frame < @animation.length - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| if !self.locked?(i) && @animation[frame][i] @animation[frame][i][AnimFrame::X] += ox @animation[frame][i][AnimFrame::Y] += oy @@ -648,7 +648,7 @@ class AnimationCanvas < Sprite # Clears all items in the frame except locked items def clearFrame(frame) if frame >= 0 && frame < @animation.length - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| if self.deletable?(i) @animation[frame][i] = nil else @@ -667,7 +667,7 @@ class AnimationCanvas < Sprite def copyFrame(src, dst) return if dst >= @animation.length - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| clonedframe = @animation[src][i] clonedframe = clonedframe.clone if clonedframe && clonedframe != true @animation[dst][i] = clonedframe @@ -704,7 +704,7 @@ class AnimationCanvas < Sprite def pasteCel(x, y) return if @currentframe >= @animation.length return if Clipboard.typekey != "PBAnimCel" - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| next if @animation[@currentframe][i] @animation[@currentframe][i] = Clipboard.data cel = @animation[@currentframe][i] @@ -754,7 +754,7 @@ class AnimationCanvas < Sprite if cel[AnimFrame::PATTERN] < 0 count = 0 pattern = cel[AnimFrame::PATTERN] - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| othercel = @animation[self.currentframe][i] count += 1 if othercel && othercel[AnimFrame::PATTERN] == pattern end @@ -786,7 +786,7 @@ class AnimationCanvas < Sprite def addSprite(x, y) return false if @currentframe >= @animation.length - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| next if @animation[@currentframe][i] @animation[@currentframe][i] = pbCreateCel(x, y, @pattern, @animation.position) @dirty[i] = true @@ -803,7 +803,7 @@ class AnimationCanvas < Sprite if Input.trigger?(Input::MOUSELEFT) # Left mouse button selectedcel = -1 usealpha = (Input.press?(Input::ALT)) ? true : false - for j in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |j| if pbSpriteHitTest(@celsprites[j], mousepos[0], mousepos[1], usealpha, false) selectedcel = j end @@ -924,7 +924,7 @@ class AnimationCanvas < Sprite # @testscreen.update # self.bitmap=@testscreen.bitmap if @currentframe < @animation.length - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| if @dirty[i] if @celsprites[i] setBitmap(i, @currentframe) @@ -938,7 +938,7 @@ class AnimationCanvas < Sprite end end else - for i in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |i| pbSpriteSetAnimFrame(@celsprites[i], nil, @celsprites[0], @celsprites[1], true) @celsprites[i].x += BORDERSIZE @celsprites[i].y += BORDERSIZE diff --git a/Data/Scripts/020_Debug/002_Animation editor/002_AnimEditor_ControlsButtons.rb b/Data/Scripts/020_Debug/002_Animation editor/002_AnimEditor_ControlsButtons.rb index 804c8a950..ff5a61364 100644 --- a/Data/Scripts/020_Debug/002_Animation editor/002_AnimEditor_ControlsButtons.rb +++ b/Data/Scripts/020_Debug/002_Animation editor/002_AnimEditor_ControlsButtons.rb @@ -233,7 +233,7 @@ class TextField < UIControl chars = self.text.scan(/./m) chars.insert(@cursor, ch) @text = "" - for ch in chars + chars.each do |ch| @text += ch end @cursor += 1 @@ -246,7 +246,7 @@ class TextField < UIControl chars = self.text.scan(/./m) chars.delete_at(@cursor - 1) @text = "" - for ch in chars + chars.each do |ch| @text += ch end @cursor -= 1 @@ -320,7 +320,7 @@ class TextField < UIControl break if fromcursor > width - 4 startpos -= 1 end - for i in startpos...scanlength + (startpos...scanlength).each do |i| c = textscan[i] textwidth = bitmap.text_size(c).width next if c == "\n" @@ -669,7 +669,7 @@ class TextSlider < UIControl def refresh bitmap = self.bitmap if @maxoptionwidth == nil - for i in 0...@options.length + @options.length.times do |i| w = self.bitmap.text_size(" " + @options[i] + " ").width @maxoptionwidth = w if !@maxoptionwidth || @maxoptionwidth < w end @@ -808,21 +808,15 @@ class ControlWindow < SpriteWindow_Base end def refresh - for i in 0...@controls.length - @controls[i].refresh - end + @controls.each { |ctrl| ctrl.refresh } end def repaint - for i in 0...@controls.length - @controls[i].repaint - end + @controls.each { |ctrl| ctrl.repaint } end def invalidate - for i in 0...@controls.length - @controls[i].invalidate - end + @controls.each { |ctrl| ctrl.invalidate } end def hittest?(i) @@ -882,9 +876,7 @@ class ControlWindow < SpriteWindow_Base def update super - for i in 0...@controls.length - @controls[i].update - end + @controls.each { |ctrl| ctrl.update } repaint end diff --git a/Data/Scripts/020_Debug/002_Animation editor/003_AnimEditor_Interpolation.rb b/Data/Scripts/020_Debug/002_Animation editor/003_AnimEditor_Interpolation.rb index fe9754d5d..2bc5b0061 100644 --- a/Data/Scripts/020_Debug/002_Animation editor/003_AnimEditor_Interpolation.rb +++ b/Data/Scripts/020_Debug/002_Animation editor/003_AnimEditor_Interpolation.rb @@ -98,7 +98,7 @@ class PointPath def inspect p = [] - for point in @points + @points.each do |point| p.push([point[0].to_i, point[1].to_i]) end return p.inspect @@ -164,7 +164,7 @@ class PointPath curdist = 0 distForT = @totaldist * t i = 0 - for dist in @distances + @distances.each do |dist| curdist += dist if dist > 0.0 if curdist >= distForT @@ -249,7 +249,7 @@ def pbDefinePath(canvas) if path path = path.smoothPointPath(sliderwin2.value(0), false) i = 0 - for point in path + path.each do |point| if i < points.length points[i].x = point[0] points[i].y = point[1] @@ -258,14 +258,14 @@ def pbDefinePath(canvas) end i += 1 end - for j in i...points.length + (i...points.length).each do |j| points[j].dispose points[j] = nil end points.compact! end elsif sliderwin2.changed?(defcurvebutton) - for point in points + points.each do |point| point.dispose end points.clear @@ -293,19 +293,19 @@ def pbDefinePath(canvas) break end if Input.trigger?(Input::MOUSELEFT) - for j in 0...4 + 4.times do |j| next if !curve[j].hittest? if [1, 2].include?(j) next if !curve[0].visible || !curve[3].visible end curve[j].visible = true - for k in 0...4 + 4.times do |k| curve[k].dragging = (k == j) end break end end - for j in 0...4 + 4.times do |j| curve[j].mouseover end mousepos = Mouse.getMousePos(true) @@ -315,7 +315,7 @@ def pbDefinePath(canvas) end if curve[0].visible && curve[3].visible && !curve[0].dragging && !curve[3].dragging - for point in points + points.each do |point| point.visible = true end if !showline @@ -331,7 +331,7 @@ def pbDefinePath(canvas) if showline step = 1.0 / (points.length - 1) t = 0.0 - for i in 0...points.length + points.length.times do |i| point = getCurvePoint(curve, t) points[i].x = point[0] points[i].y = point[1] @@ -341,18 +341,18 @@ def pbDefinePath(canvas) end window.dispose # dispose temporary path - for point in points + points.each do |point| point.dispose end points.clear if showline path = curveToPointPath(curve, sliderwin2.value(0)) # File.open("pointpath.txt","wb") { |f| f.write(path.inspect) } - for point in path + path.each do |point| points.push(PointSprite.new(point[0], point[1], canvas.viewport)) end end - for point in curve + curve.each do |point| point.dispose end sliderwin2.visible = true @@ -360,7 +360,7 @@ def pbDefinePath(canvas) elsif sliderwin2.changed?(defpathbutton) canceled = false pointpath = PointPath.new - for point in points + points.each do |point| point.dispose end points.clear @@ -396,14 +396,14 @@ def pbDefinePath(canvas) end window.dispose # dispose temporary path - for point in points + points.each do |point| point.dispose end points.clear # generate smooth path from temporary path path = pointpath.smoothPointPath(sliderwin2.value(0), true) # redraw path from smooth path - for point in path + path.each do |point| points.push(PointSprite.new(point[0], point[1], canvas.viewport)) end # File.open("pointpath.txt","wb") { |f| f.write(path.inspect) } @@ -417,7 +417,7 @@ def pbDefinePath(canvas) end thiscel = canvas.currentCel celnumber = canvas.currentcel - for i in canvas.currentframe...neededsize + (canvas.currentframe...neededsize).each do |i| cel = canvas.animation[i][celnumber] if !canvas.animation[i][celnumber] cel = pbCreateCel(0, 0, thiscel[AnimFrame::PATTERN], canvas.animation.position) @@ -432,7 +432,7 @@ def pbDefinePath(canvas) end end # dispose all points - for point in points + points.each do |point| point.dispose end points.clear diff --git a/Data/Scripts/020_Debug/002_Animation editor/004_AnimEditor_ExportImport.rb b/Data/Scripts/020_Debug/002_Animation editor/004_AnimEditor_ExportImport.rb index a88691753..531506f0a 100644 --- a/Data/Scripts/020_Debug/002_Animation editor/004_AnimEditor_ExportImport.rb +++ b/Data/Scripts/020_Debug/002_Animation editor/004_AnimEditor_ExportImport.rb @@ -87,9 +87,9 @@ end ################################################################################ def pbConvertAnimToNewFormat(textdata) needconverting = false - for i in 0...textdata.length + textdata.length.times do |i| next if !textdata[i] - for j in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |j| next if !textdata[i][j] needconverting = true if textdata[i][j][AnimFrame::FOCUS] == nil break if needconverting @@ -97,9 +97,9 @@ def pbConvertAnimToNewFormat(textdata) break if needconverting end if needconverting - for i in 0...textdata.length + textdata.length.times do |i| next if !textdata[i] - for j in 0...PBAnimation::MAX_SPRITES + PBAnimation::MAX_SPRITES.times do |j| next if !textdata[i][j] textdata[i][j][AnimFrame::PRIORITY] = 1 if textdata[i][j][AnimFrame::PRIORITY] == nil case j @@ -132,7 +132,7 @@ def pbConvertAnimsToNewFormat pbMessage(_INTL("No animations exist.")) return end - for k in 0...animations.length + animations.length.times do |k| next if !animations[k] ret = pbConvertAnimToNewFormat(animations[k]) count += 1 if ret diff --git a/Data/Scripts/020_Debug/002_Animation editor/005_AnimEditor_Functions.rb b/Data/Scripts/020_Debug/002_Animation editor/005_AnimEditor_Functions.rb index 16a6d47d9..458b67353 100644 --- a/Data/Scripts/020_Debug/002_Animation editor/005_AnimEditor_Functions.rb +++ b/Data/Scripts/020_Debug/002_Animation editor/005_AnimEditor_Functions.rb @@ -15,9 +15,7 @@ class MiniBattle def initialize @battlers = [] - for i in 0...4 - @battlers[i] = MiniBattler.new(i) - end + 4.times { |i| @battlers[i] = MiniBattler.new(i) } end end @@ -118,7 +116,7 @@ end def pbAnimList(animations, canvas, animwin) commands = [] - for i in 0...animations.length + animations.length.times do |i| animations[i] = PBAnimation.new if !animations[i] commands[commands.length] = _INTL("{1} {2}", i, animations[i].name) end @@ -146,7 +144,7 @@ def pbAnimList(animations, canvas, animwin) newsize = maxsizewindow.value(0) animations.resize(newsize) commands.clear - for i in 0...animations.length + animations.length.times do |i| commands[commands.length] = _INTL("{1} {2}", i, animations[i].name) end cmdwin.commands = commands @@ -382,7 +380,7 @@ def pbTimingList(canvas) cmdEditBG = -1 cmdNewFO = -1 cmdEditFO = -1 - for i in canvas.animation.timing + canvas.animation.timing.each do |i| commands.push(sprintf("%s", i)) end commands[cmdNewSound = commands.length] = _INTL("Add: Play Sound...") @@ -752,7 +750,7 @@ def pbClearFrames(canvas) if sliderwin2.changed?(okbutton) startframe = sliderwin2.value(0) - 1 endframe = sliderwin2.value(1) - 1 - for i in startframe..endframe + (startframe..endframe).each do |i| canvas.clearFrame(i) end break @@ -789,7 +787,7 @@ def pbTweening(canvas) frames = endframe - startframe startcel = sliderwin2.value(s1set2) endcel = sliderwin2.value(s1set3) - for j in startcel..endcel + (startcel..endcel).each do |j| cel1 = canvas.animation[startframe][j] cel2 = canvas.animation[endframe][j] next if !cel1 || !cel2 @@ -809,7 +807,7 @@ def pbTweening(canvas) startAngle = cel1[AnimFrame::ANGLE] startOpacity = cel1[AnimFrame::OPACITY] startBlend = cel1[AnimFrame::BLENDTYPE] - for k in 0..frames + (0..frames).each do |k| cel = canvas.animation[startframe + k][j] curcel = cel if !cel @@ -879,8 +877,8 @@ def pbCellBatch(canvas) endframe = sliderwin1.value(s1set1) - 1 startcel = sliderwin1.value(s1set2) endcel = sliderwin1.value(s1set3) - for i in startframe..endframe - for j in startcel..endcel + (startframe..endframe).each do |i| + (startcel..endcel).each do |j| next if !canvas.animation[i][j] cel = canvas.animation[i][j] cel[AnimFrame::PATTERN] = sliderwin2.value(set0) if sliderwin2.value(set0) @@ -926,7 +924,7 @@ def pbEntireSlide(canvas) endvalue = sliderwin2.value(1) - 1 xoffset = sliderwin2.value(2) yoffset = sliderwin2.value(3) - for i in startvalue..endvalue + (startvalue..endvalue).each do |i| canvas.offsetFrame(i, xoffset, yoffset) end break @@ -1129,7 +1127,7 @@ def animationEditorMain(animation) if sidewin.changed?(1) positions = [_INTL("User"), _INTL("Target"), _INTL("User and target"), _INTL("Screen")] indexes = [2, 1, 3, 4] # Keeping backwards compatibility - for i in 0...positions.length + positions.length.times do |i| selected = "[ ]" if animation[animation.selected].position == indexes[i] selected = "[x]" diff --git a/Data/Scripts/020_Debug/002_Editor_DataTypes.rb b/Data/Scripts/020_Debug/002_Editor_DataTypes.rb index c06686d7c..05b828001 100644 --- a/Data/Scripts/020_Debug/002_Editor_DataTypes.rb +++ b/Data/Scripts/020_Debug/002_Editor_DataTypes.rb @@ -190,7 +190,7 @@ class EnumProperty def set(settingname, oldsetting) commands = [] - for value in @values + @values.each do |value| commands.push(value) end cmd = pbMessage(_INTL("Choose a value for {1}.", settingname), commands, -1) @@ -217,7 +217,7 @@ class EnumProperty2 def set(settingname, oldsetting) commands = [] - for i in 0..@module.maxValue + (0..@module.maxValue).each do |i| commands.push(getConstantName(@module, i)) end cmd = pbMessage(_INTL("Choose a value for {1}.", settingname), commands, -1, nil, oldsetting) @@ -299,7 +299,7 @@ class StringListProperty else # Cancel/quit case pbMessage(_INTL("Keep changes?"), [_INTL("Yes"), _INTL("No"), _INTL("Cancel")], 3) when 0 - for i in 0...real_cmds.length + real_cmds.length.times do |i| real_cmds[i] = (real_cmds[i][1] == -1) ? nil : real_cmds[i][0] end real_cmds.compact! @@ -769,7 +769,7 @@ module RegionMapCoordsProperty selregion = regions[0][0] else cmds = [] - for region in regions + regions.each do |region| cmds.push(region[1]) end selcmd = pbMessage(_INTL("Choose a region map."), cmds, -1) @@ -790,7 +790,7 @@ module RegionMapCoordsProperty def self.getMapNameList mapdata = pbLoadTownMapData ret = [] - for i in 0...mapdata.length + mapdata.length.times do |i| next if !mapdata[i] ret.push([i, pbGetMessage(MessageTypes::RegionNames, i)]) end @@ -1067,7 +1067,7 @@ class GameDataPoolProperty [_INTL("Yes"), _INTL("No"), _INTL("Cancel")], 3) when 0 values.shift # Remove the "add value" option - for i in 0...values.length + values.length.times do |i| values[i] = values[i][0] end values.compact! @@ -1107,7 +1107,7 @@ module LevelUpMovesProperty # Get all moves in move pool realcmds = [] realcmds.push([-1, nil, -1, "-"]) # Level, move ID, index in this list, name - for i in 0...oldsetting.length + oldsetting.length.times do |i| realcmds.push([oldsetting[i][0], oldsetting[i][1], i, GameData::Move.get(oldsetting[i][1]).real_name]) end # Edit move pool @@ -1221,7 +1221,7 @@ module LevelUpMovesProperty [_INTL("Yes"), _INTL("No"), _INTL("Cancel")], 3) when 0 realcmds.shift - for i in 0...realcmds.length + realcmds.length.times do |i| realcmds[i].pop # Remove name realcmds[i].pop # Remove index in this list end @@ -1244,7 +1244,7 @@ module LevelUpMovesProperty def self.format(value) ret = "" - for i in 0...value.length + value.length.times do |i| ret << "," if i > 0 ret << sprintf("%s,%s", value[i][0], GameData::Move.get(value[i][1]).real_name) end @@ -1300,7 +1300,7 @@ class EvolutionsProperty commands = [] realcmds = [] realcmds.push([-1, 0, 0, -1]) - for i in 0...oldsetting.length + oldsetting.length.times do |i| realcmds.push([oldsetting[i][0], oldsetting[i][1], oldsetting[i][2], i]) end refreshlist = true @@ -1310,7 +1310,7 @@ class EvolutionsProperty if refreshlist realcmds.sort! { |a, b| a[3] <=> b[3] } commands = [] - for i in 0...realcmds.length + realcmds.length.times do |i| if realcmds[i][3] < 0 commands.push(_INTL("[ADD EVOLUTION]")) else @@ -1359,7 +1359,7 @@ class EvolutionsProperty newparam = edit_parameter(newmethod) if newparam || GameData::Evolution.get(newmethod).parameter.nil? existing_evo = -1 - for i in 0...realcmds.length + realcmds.length.times do |i| existing_evo = realcmds[i][3] if realcmds[i][0] == newspecies && realcmds[i][1] == newmethod && realcmds[i][2] == newparam @@ -1384,7 +1384,7 @@ class EvolutionsProperty newspecies = pbChooseSpeciesList(entry[0]) if newspecies existing_evo = -1 - for i in 0...realcmds.length + realcmds.length.times do |i| existing_evo = realcmds[i][3] if realcmds[i][0] == newspecies && realcmds[i][1] == entry[1] && realcmds[i][2] == entry[2] @@ -1405,7 +1405,7 @@ class EvolutionsProperty if newmethodindex >= 0 newmethod = @evo_ids[newmethodindex] existing_evo = -1 - for i in 0...realcmds.length + realcmds.length.times do |i| existing_evo = realcmds[i][3] if realcmds[i][0] == entry[0] && realcmds[i][1] == newmethod && realcmds[i][2] == entry[2] @@ -1427,7 +1427,7 @@ class EvolutionsProperty newparam = edit_parameter(entry[1], entry[2]) if newparam existing_evo = -1 - for i in 0...realcmds.length + realcmds.length.times do |i| existing_evo = realcmds[i][3] if realcmds[i][0] == entry[0] && realcmds[i][1] == entry[1] && realcmds[i][2] == newparam @@ -1453,7 +1453,7 @@ class EvolutionsProperty [_INTL("Yes"), _INTL("No"), _INTL("Cancel")], 3) if [0, 1].include?(cmd2) if cmd2 == 0 - for i in 0...realcmds.length + realcmds.length.times do |i| realcmds[i].pop realcmds[i] = nil if realcmds[i][0] == -1 end @@ -1475,7 +1475,7 @@ class EvolutionsProperty def format(value) ret = "" - for i in 0...value.length + value.length.times do |i| ret << "," if i > 0 param = value[i][2] evo_method_data = GameData::Evolution.get(value[i][1]) @@ -1564,13 +1564,13 @@ def pbPropertyList(title, data, properties, saveprompt = false) selectedmap = -1 retval = nil commands = [] - for i in 0...properties.length + properties.length.times do |i| propobj = properties[i][1] commands.push(sprintf("%s=%s", properties[i][0], propobj.format(data[i]))) end list.commands = commands list.index = 0 - begin + loop do loop do Graphics.update Input.update @@ -1591,7 +1591,7 @@ def pbPropertyList(title, data, properties, saveprompt = false) end end commands.clear - for i in 0...properties.length + properties.length.times do |i| propobj = properties[i][1] commands.push(sprintf("%s=%s", properties[i][0], propobj.format(data[i]))) end @@ -1605,7 +1605,7 @@ def pbPropertyList(title, data, properties, saveprompt = false) newsetting = propobj.set(properties[selectedmap][0], oldsetting) data[selectedmap] = newsetting commands.clear - for i in 0...properties.length + properties.length.times do |i| propobj = properties[i][1] commands.push(sprintf("%s=%s", properties[i][0], propobj.format(data[i]))) end @@ -1622,7 +1622,8 @@ def pbPropertyList(title, data, properties, saveprompt = false) retval = (cmd == 0) end end - end while selectedmap != -1 + break unless selectedmap != -1 + end title.dispose list.dispose desc.dispose diff --git a/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb b/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb index 1acbff691..9ec3cfce6 100644 --- a/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb +++ b/Data/Scripts/020_Debug/003_Debug menus/002_Debug_MenuCommands.rb @@ -129,18 +129,18 @@ DebugMenuCommands.register("togglewallpapers", { paperscmds = [] paperscmds.push(_INTL("Unlock all")) paperscmds.push(_INTL("Lock all")) - for i in PokemonStorage::BASICWALLPAPERQTY...w.length + (PokemonStorage::BASICWALLPAPERQTY...w.length).each do |i| paperscmds.push(_INTL("{1} {2}", unlockarray[i] ? "[Y]" : "[ ]", w[i])) end paperscmd = pbShowCommands(nil, paperscmds, -1, paperscmd) break if paperscmd < 0 case paperscmd when 0 # Unlock all - for i in PokemonStorage::BASICWALLPAPERQTY...w.length + (PokemonStorage::BASICWALLPAPERQTY...w.length).each do |i| unlockarray[i] = true end when 1 # Lock all - for i in PokemonStorage::BASICWALLPAPERQTY...w.length + (PokemonStorage::BASICWALLPAPERQTY...w.length).each do |i| unlockarray[i] = false end else @@ -406,7 +406,7 @@ DebugMenuCommands.register("resettrainers", { "description" => _INTL("Turn off Self Switches A and B for all events with \"Trainer\" in their name."), "effect" => proc { if $game_map - for event in $game_map.events.values + $game_map.events.values.each do |event| if event.name[/trainer/i] $game_self_switches[[$game_map.map_id, event.id, "A"]] = false $game_self_switches[[$game_map.map_id, event.id, "B"]] = false @@ -428,7 +428,7 @@ DebugMenuCommands.register("readyrematches", { if !$PokemonGlobal.phoneNumbers || $PokemonGlobal.phoneNumbers.length == 0 pbMessage(_INTL("There are no trainers in the Phone.")) else - for i in $PokemonGlobal.phoneNumbers + $PokemonGlobal.phoneNumbers.each do |i| next if i.length != 8 # Isn't a trainer with an event i[4] = 2 pbSetReadyToBattle(i) @@ -566,7 +566,7 @@ DebugMenuCommands.register("demoparty", { "effect" => proc { party = [] species = [:PIKACHU, :PIDGEOTTO, :KADABRA, :GYARADOS, :DIGLETT, :CHANSEY] - for id in species + species.each do |id| party.push(id) if GameData::Species.exists?(id) end $player.party.clear @@ -674,8 +674,8 @@ DebugMenuCommands.register("clearboxes", { "name" => _INTL("Clear Storage Boxes"), "description" => _INTL("Remove all Pokémon in storage."), "effect" => proc { - for i in 0...$PokemonStorage.maxBoxes - for j in 0...$PokemonStorage.maxPokemon(i) + $PokemonStorage.maxBoxes.times do |i| + $PokemonStorage.maxPokemon(i).times do |j| $PokemonStorage[i, j] = nil end end @@ -715,7 +715,7 @@ DebugMenuCommands.register("setbadges", { badgecmds = [] badgecmds.push(_INTL("Give all")) badgecmds.push(_INTL("Remove all")) - for i in 0...24 + 24.times do |i| badgecmds.push(_INTL("{1} Badge {2}", $player.badges[i] ? "[Y]" : "[ ]", i + 1)) end badgecmd = pbShowCommands(nil, badgecmds, -1, badgecmd) @@ -803,7 +803,7 @@ DebugMenuCommands.register("dexlists", { dexescmds = [] dexescmds.push(_INTL("Have Pokédex: {1}", $player.has_pokedex ? "[YES]" : "[NO]")) dex_names = Settings.pokedex_names - for i in 0...dex_names.length + dex_names.length.times do |i| name = (dex_names[i].is_a?(Array)) ? dex_names[i][0] : dex_names[i] unlocked = $player.pokedex.unlocked?(i) dexescmds.push(_INTL("{1} {2}", unlocked ? "[Y]" : "[ ]", name)) diff --git a/Data/Scripts/020_Debug/003_Debug menus/003_Debug_MenuExtraCode.rb b/Data/Scripts/020_Debug/003_Debug menus/003_Debug_MenuExtraCode.rb index ff0d48d97..eff5e0420 100644 --- a/Data/Scripts/020_Debug/003_Debug menus/003_Debug_MenuExtraCode.rb +++ b/Data/Scripts/020_Debug/003_Debug menus/003_Debug_MenuExtraCode.rb @@ -20,7 +20,7 @@ def pbWarpToMap y = rand(map.height) next if !map.passableStrict?(x, y, 0, $game_player) blocked = false - for event in map.events.values + map.events.values.each do |event| if event.at_coordinate?(x, y) && !event.through blocked = true if event.character_name != "" end @@ -509,7 +509,7 @@ def pbDebugRoamers pbPlayBuzzerSE else pbPlayDecisionSE - for i in 0...Settings::ROAMING_SPECIES.length + Settings::ROAMING_SPECIES.length.times do |i| $PokemonGlobal.roamPosition[i] = nil end $PokemonGlobal.roamedAlready = false @@ -564,7 +564,7 @@ def pbExportAllAnimations animations = pbLoadBattleAnimations if animations msgwindow = pbCreateMessageWindow - for anim in animations + animations.each do |anim| next if !anim || anim.length == 0 || anim.name == "" pbMessageDisplay(msgwindow, anim.name, false) Graphics.update @@ -577,7 +577,7 @@ def pbExportAllAnimations graphicname = RTP.getImagePath("Graphics/Animations/" + anim.graphic) pbSafeCopyFile(graphicname, "Animations/#{safename}/" + File.basename(graphicname)) end - for timing in anim.timing + anim.timing.each do |timing| if !timing.timingType || timing.timingType == 0 if timing.name && timing.name != "" audioName = RTP.getAudioPath("Audio/SE/Anim/" + timing.name) @@ -618,7 +618,7 @@ def pbImportAllAnimations msgwindow = pbCreateMessageWindow animations = pbLoadBattleAnimations animations = PBAnimations.new if !animations - for folder in animationFolders + animationFolders.each do |folder| pbMessageDisplay(msgwindow, folder, false) Graphics.update audios = [] @@ -628,7 +628,7 @@ def pbImportAllAnimations audios.concat(files.find_all { |f| f[f.length - 3, 3] == ext }) audios.concat(files.find_all { |f| f[f.length - 3, 3] == upext }) } - for audio in audios + audios.each do |audio| pbSafeCopyFile(audio, RTP.getAudioPath("Audio/SE/Anim/" + File.basename(audio)), "Audio/SE/Anim/" + File.basename(audio)) end images = [] @@ -637,7 +637,7 @@ def pbImportAllAnimations images.concat(files.find_all { |f| f[f.length - 3, 3] == ext }) images.concat(files.find_all { |f| f[f.length - 3, 3] == upext }) } - for image in images + images.each do |image| pbSafeCopyFile(image, RTP.getImagePath("Graphics/Animations/" + File.basename(image)), "Graphics/Animations/" + File.basename(image)) end Dir.glob(folder + "/*.anm") { |f| @@ -655,7 +655,7 @@ def pbImportAllAnimations missingFiles.push(textdata.graphic) end end - for timing in textdata.timing + textdata.timing.each do |timing| if timing.name && timing.name != "" if !safeExists?(folder + "/" + timing.name) && !FileTest.audio_exist?("Audio/SE/Anim/" + timing.name) @@ -687,7 +687,7 @@ def pbDebugFixInvalidTiles Graphics.update total_maps = mapData.mapinfos.keys.length Console.echo_h1 _INTL("Checking {1} maps for invalid tiles", total_maps) - for id in mapData.mapinfos.keys.sort + mapData.mapinfos.keys.sort.each do |id| if Time.now.to_i - t >= 5 Graphics.update t = Time.now.to_i @@ -697,9 +697,9 @@ def pbDebugFixInvalidTiles next if !map || !mapData.mapinfos[id] passages = mapData.getTilesetPassages(map, id) # Check all tiles in map for non-existent tiles - for x in 0...map.data.xsize - for y in 0...map.data.ysize - for i in 0...map.data.zsize + map.data.xsize.times do |x| + map.data.ysize.times do |y| + map.data.zsize.times do |i| tile_id = map.data[x, y, i] next if pbCheckTileValidity(tile_id, map, tilesets, passages) map.data[x, y, i] = 0 @@ -708,9 +708,9 @@ def pbDebugFixInvalidTiles end end # Check all events in map for page graphics using a non-existent tile - for key in map.events.keys + map.events.keys.each do |key| event = map.events[key] - for page in event.pages + event.pages.each do |page| next if page.graphic.tile_id <= 0 next if pbCheckTileValidity(page.graphic.tile_id, map, tilesets, passages) page.graphic.tile_id = 0 @@ -864,7 +864,7 @@ class PokemonDebugPartyScreen def pbChooseMove(pkmn, text, index = 0) moveNames = [] - for i in pkmn.moves + pkmn.moves.each do |i| if i.total_pp <= 0 moveNames.push(_INTL("{1} (PP: ---)", i.name)) else diff --git a/Data/Scripts/020_Debug/003_Debug menus/005_Debug_PokemonCommands.rb b/Data/Scripts/020_Debug/003_Debug menus/005_Debug_PokemonCommands.rb index c050f49ab..1c060f089 100644 --- a/Data/Scripts/020_Debug/003_Debug menus/005_Debug_PokemonCommands.rb +++ b/Data/Scripts/020_Debug/003_Debug menus/005_Debug_PokemonCommands.rb @@ -565,7 +565,7 @@ PokemonDebugMenuCommands.register("setmovepp", { cmd = 0 loop do commands = [] - for i in pkmn.moves + pkmn.moves.each do |i| break if !i.id if i.total_pp <= 0 commands.push(_INTL("{1} (PP: ---)", i.name)) @@ -698,7 +698,7 @@ PokemonDebugMenuCommands.register("setability", { abils = pkmn.getAbilityList ability_commands = [] abil_cmd = 0 - for i in abils + abils.each do |i| ability_commands.push(((i[1] < 2) ? "" : "(H) ") + GameData::Ability.get(i[0]).name) abil_cmd = ability_commands.length - 1 if pkmn.ability_id == i[0] end @@ -917,8 +917,8 @@ PokemonDebugMenuCommands.register("setpokeball", { end balls.sort! { |a, b| a[1] <=> b[1] } cmd = 0 - for i in 0...balls.length - next if balls[i][0] != pkmn.poke_ball + balls.each_with_index do |ball, i| + next if ball[0] != pkmn.poke_ball cmd = i break end diff --git a/Data/Scripts/020_Debug/003_Debug menus/006_Debug_FilenameUpdater.rb b/Data/Scripts/020_Debug/003_Debug menus/006_Debug_FilenameUpdater.rb index cbe78a54b..e155c0d5b 100644 --- a/Data/Scripts/020_Debug/003_Debug menus/006_Debug_FilenameUpdater.rb +++ b/Data/Scripts/020_Debug/003_Debug menus/006_Debug_FilenameUpdater.rb @@ -7,8 +7,8 @@ module FilenameUpdater def readDirectoryFiles(directory, formats) files = [] Dir.chdir(directory) { - for i in 0...formats.length - Dir.glob(formats[i]) { |f| files.push(f) } + formats.each do |format| + Dir.glob(format) { |f| files.push(f) } end } return files @@ -40,14 +40,14 @@ module FilenameUpdater Graphics.update Console.echo_li _INTL("Checking {1} maps for used berry tree charsets...", mapData.mapinfos.keys.length) idx = 0 - for id in mapData.mapinfos.keys.sort + mapData.mapinfos.keys.sort.each do |id| echo "." if idx % 20 == 0 idx += 1 Graphics.update if idx % 250 == 0 map = mapData.getMap(id) next if !map || !mapData.mapinfos[id] changed = false - for key in map.events.keys + map.events.keys.each do |key| if Time.now.to_i - t >= 5 Graphics.update t = Time.now.to_i diff --git a/Data/Scripts/020_Debug/003_Debug menus/008_Debug_BattlerCommands.rb b/Data/Scripts/020_Debug/003_Debug menus/008_Debug_BattlerCommands.rb index af3a9f55c..ddc5ff7b0 100644 --- a/Data/Scripts/020_Debug/003_Debug menus/008_Debug_BattlerCommands.rb +++ b/Data/Scripts/020_Debug/003_Debug menus/008_Debug_BattlerCommands.rb @@ -385,7 +385,7 @@ BattlerDebugMenuCommands.register("settypes", { loop do commands = [] types = [] - (0...max_main_types).each do |i| + max_main_types.times do |i| type = battler.types[i] type_name = (type) ? GameData::Type.get(type).name : "-" commands.push(_INTL("Type {1}: {2}", i + 1, type_name)) diff --git a/Data/Scripts/020_Debug/003_Editor_Listers.rb b/Data/Scripts/020_Debug/003_Editor_Listers.rb index c0073116f..0d1a9a67a 100644 --- a/Data/Scripts/020_Debug/003_Editor_Listers.rb +++ b/Data/Scripts/020_Debug/003_Editor_Listers.rb @@ -314,7 +314,7 @@ class MapLister @maps = pbMapTree @addGlobalOffset = (addGlobal) ? 1 : 0 @index = 0 - for i in 0...@maps.length + @maps.length.times do |i| @index = i + @addGlobalOffset if @maps[i][0] == selmap end end @@ -337,7 +337,7 @@ class MapLister if @addGlobalOffset == 1 @commands.push(_INTL("[GLOBAL]")) end - for i in 0...@maps.length + @maps.length.times do |i| @commands.push(sprintf("%s%03d %s", (" " * @maps[i][2]), @maps[i][0], @maps[i][1])) end return @commands @@ -393,7 +393,7 @@ class SpeciesLister @commands.push(_INTL("[NEW SPECIES]")) @ids.push(true) end - for i in cmds + cmds.each do |i| @commands.push(sprintf("%03d: %s", i[0], i[2])) @ids.push(i[1]) end @@ -452,7 +452,7 @@ class ItemLister @commands.push(_INTL("[NEW ITEM]")) @ids.push(true) end - for i in cmds + cmds.each do |i| @commands.push(sprintf("%03d: %s", i[0], i[2])) @ids.push(i[1]) end @@ -513,7 +513,7 @@ class TrainerTypeLister @commands.push(_INTL("[NEW TRAINER TYPE]")) @ids.push(true) end - for t in cmds + cmds.each do |t| @commands.push(sprintf("%03d: %s", t[0], t[2])) @ids.push(t[1]) end @@ -604,7 +604,7 @@ class TrainerBattleLister @commands.push(_INTL("[NEW TRAINER BATTLE]")) @ids.push(true) end - for t in cmds + cmds.each do |t| if t[3] > 0 @commands.push(_INTL("{1} {2} ({3}) x{4}", GameData::TrainerType.get(t[1]).name, t[2], t[3], diff --git a/Data/Scripts/021_Compiler/001_Compiler.rb b/Data/Scripts/021_Compiler/001_Compiler.rb index 78d16d0f9..366db7ba8 100644 --- a/Data/Scripts/021_Compiler/001_Compiler.rb +++ b/Data/Scripts/021_Compiler/001_Compiler.rb @@ -404,9 +404,9 @@ module Compiler start = 1 end subarrays = repeat && schema[1].length > 2 - begin + loop do subrecord = [] - for i in start...schema[1].length + (start...schema[1].length).each do |i| chr = schema[1][i, 1] case chr when "i" # Integer @@ -540,7 +540,8 @@ module Compiler end end break if repeat && nil_or_empty?(rec) - end while repeat + break unless repeat + end return (schema[1].length == 1) ? record[0] : record end @@ -551,8 +552,8 @@ module Compiler rec = (record.is_a?(Array)) ? record.flatten : [record] start = (schema[1][0, 1] == "*") ? 1 : 0 index = -1 - begin - for i in start...schema[1].length + loop do + (start...schema[1].length).each do |i| index += 1 file.write(",") if index > 0 value = rec[index] @@ -579,7 +580,7 @@ module Compiler when Module file.write(getConstantName(enumer, value)) when Hash - for key in enumer.keys + enumer.keys.each do |key| if enumer[key] == value file.write(key) break @@ -602,7 +603,7 @@ module Compiler file.write(getConstantNameOrValue(enumer, value)) when Hash hasenum = false - for key in enumer.keys + enumer.keys.each do |key| if enumer[key] == value file.write(key) hasenum = true @@ -619,7 +620,8 @@ module Compiler end end break if start > 0 && index >= rec.length - 1 - end while start > 0 + break if start <= 0 + end return record end @@ -845,7 +847,7 @@ module Compiler mustCompile = true if Input.press?(Input::CTRL) # Delete old data files in preparation for recompiling if mustCompile - for i in 0...dataFiles.length + dataFiles.length.times do |i| begin File.delete("Data/#{dataFiles[i]}") if safeExists?("Data/#{dataFiles[i]}") rescue SystemCallError @@ -858,7 +860,7 @@ module Compiler e = $! raise e if "#{e.class}" == "Reset" || e.is_a?(Reset) || e.is_a?(SystemExit) pbPrintException(e) - for i in 0...dataFiles.length + dataFiles.length.times do |i| begin File.delete("Data/#{dataFiles[i]}") rescue SystemCallError diff --git a/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb b/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb index 6a7dcc658..7865ef465 100644 --- a/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb +++ b/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb @@ -154,7 +154,7 @@ module Compiler contents["InternalName"] = type_id if !type_id[/^\d+/] icon_pos = (type_id[/^\d+/]) ? type_id.to_i : nil # Go through schema hash of compilable data and compile this section - for key in schema.keys + schema.keys.each do |key| FileLineData.setSection(type_id, key, contents[key]) # For error reporting # Skip empty properties, or raise an error if a required property is # empty @@ -606,7 +606,7 @@ module Compiler contents["InternalName"] = species_id if !species_id[/^\d+/] # Ensure all required properties have been defined, and raise an error # if not - for key in schema.keys + schema.keys.each do |key| next if !nil_or_empty?(contents[key]) if ["Name", "InternalName"].include?(key) raise _INTL("The entry {1} is required in {2} section {3}.", key, path, species_id) @@ -618,7 +618,7 @@ module Compiler raise _INTL("Species ID '{1}' is used twice.\r\n{2}", contents["InternalName"], FileLineData.linereport) end # Go through schema hash of compilable data and compile this section - for key in schema.keys + schema.keys.each do |key| next if nil_or_empty?(contents[key]) FileLineData.setSection(species_id, key, contents[key]) # For error reporting # Compile value for key @@ -792,7 +792,7 @@ module Compiler used_forms[species_symbol].push(form) base_data = GameData::Species.get(species_symbol) # Go through schema hash of compilable data and compile this section - for key in schema.keys + schema.keys.each do |key| # Skip empty properties (none are required) if nil_or_empty?(contents[key]) contents[key] = nil @@ -982,7 +982,7 @@ module Compiler species_symbol = csvEnumField!(split_section_name[0], :Species, nil, nil) form = (split_section_name[1]) ? csvPosInt!(split_section_name[1]) : 0 # Go through schema hash of compilable data and compile this section - for key in schema.keys + schema.keys.each do |key| # Skip empty properties (none are required) if nil_or_empty?(contents[key]) contents[key] = nil @@ -1099,7 +1099,7 @@ module Compiler else raise _INTL("Expected a section at the beginning of the file.\r\n{1}", FileLineData.linereport) if !section species_list = line.split(",") - for species in species_list + species_list.each do |species| next if !species || species.empty? s = parseSpecies(species) dex_lists[section].push(s) @@ -1540,7 +1540,7 @@ module Compiler Graphics.update next if name != "DefaultTrainerList" && name != "TrainerList" rsection = [] - for key in section.keys + section.keys.each do |key| FileLineData.setSection(name, key, section[key]) schema = btTrainersRequiredTypes[key] next if key == "Challenges" && name == "DefaultTrainerList" @@ -1602,7 +1602,7 @@ module Compiler FileLineData.file = filename pbEachFileSection(f) { |section, name| rsection = [] - for key in section.keys + section.keys.each do |key| FileLineData.setSection(name, key, section[key]) schema = requiredtypes[key] next if !schema @@ -1641,7 +1641,7 @@ module Compiler pbEachFileSectionNumbered(f) { |contents, section_id| schema = (section_id == 0) ? GameData::Metadata::SCHEMA : GameData::PlayerMetadata::SCHEMA # Go through schema hash of compilable data and compile this section - for key in schema.keys + schema.keys.each do |key| FileLineData.setSection(section_id, key, contents[key]) # For error reporting # Skip empty properties, or raise an error if a required property is # empty @@ -1725,7 +1725,7 @@ module Compiler idx += 1 Graphics.update if idx % 250 == 0 # Go through schema hash of compilable data and compile this section - for key in schema.keys + schema.keys.each do |key| FileLineData.setSection(map_id, key, contents[key]) # For error reporting # Skip empty properties next if contents[key].nil? @@ -1797,7 +1797,7 @@ module Compiler pbanims[anim.id] = pbConvertRPGAnimation(anim) if !found end =end - for i in 0...pbanims.length + pbanims.length.times do |i| next if !pbanims[i] if pbanims[i].name[/^OppMove\:\s*(.*)$/] if GameData::Move.exists?($~[1]) diff --git a/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb b/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb index d8e7ac92f..408f1e8cb 100644 --- a/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb +++ b/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb @@ -18,7 +18,7 @@ module Compiler File.open(path, "wb") { |f| idx = 0 add_PBS_header_to_file(f) - for i in 0...mapdata.length + mapdata.length.times do |i| echo "." if idx % 50 == 0 idx += 1 Graphics.update if idx % 250 == 0 @@ -30,7 +30,7 @@ module Compiler f.write(sprintf("Name = %s\r\nFilename = %s\r\n", (rname && rname != "") ? rname : _INTL("Unnamed"), csvQuote((map[1].is_a?(Array)) ? map[1][0] : map[1]))) - for loc in map[2] + map[2].each do |loc| f.write("Point = ") pbWriteCsvRecord(loc, f, [nil, "uussUUUU"]) f.write("\r\n") @@ -79,7 +79,7 @@ module Compiler File.open(path, "wb") { |f| add_PBS_header_to_file(f) f.write("\#-------------------------------\r\n") - for conn in conndata + conndata.each do |conn| if mapinfos # Skip if map no longer exists next if !mapinfos[conn[0]] || !mapinfos[conn[3]] @@ -703,7 +703,7 @@ module Compiler write_pbs_file_message_start(path) File.open(path, "wb") { |f| add_PBS_header_to_file(f) - for tr in trainerlists + trainerlists.each do |tr| echo "." f.write("\#-------------------------------\r\n") f.write(((tr[5]) ? "[DefaultTrainerList]" : "[TrainerList]") + "\r\n") @@ -732,11 +732,11 @@ module Compiler } File.open(filename, "wb") { |f| add_PBS_header_to_file(f) - for i in 0...bttrainers.length + bttrainers.length.times do |i| next if !bttrainers[i] f.write("\#-------------------------------\r\n") f.write(sprintf("[%03d]\r\n", i)) - for key in btTrainersRequiredTypes.keys + btTrainersRequiredTypes.keys.each do |key| schema = btTrainersRequiredTypes[key] record = bttrainers[i][schema[0]] next if record == nil @@ -776,7 +776,7 @@ module Compiler File.open(filename, "wb") { |f| add_PBS_header_to_file(f) f.write("\#-------------------------------\r\n") - for i in 0...btpokemon.length + btpokemon.length.times do |i| Graphics.update if i % 500 == 0 pkmn = btpokemon[i] c1 = (species[pkmn.species]) ? species[pkmn.species] : (species[pkmn.species] = GameData::Species.get(pkmn.species).species.to_s) @@ -820,7 +820,7 @@ module Compiler metadata = GameData::Metadata.get schema = GameData::Metadata::SCHEMA keys = schema.keys.sort { |a, b| schema[a][0] <=> schema[b][0] } - for key in keys + keys.each do |key| record = metadata.property_from_string(key) next if record.nil? || (record.is_a?(Array) && record.empty?) f.write(sprintf("%s = ", key)) @@ -833,7 +833,7 @@ module Compiler GameData::PlayerMetadata.each do |player_data| f.write("\#-------------------------------\r\n") f.write(sprintf("[%d]\r\n", player_data.id)) - for key in keys + keys.each do |key| record = player_data.property_from_string(key) next if record.nil? || (record.is_a?(Array) && record.empty?) f.write(sprintf("%s = ", key)) @@ -868,7 +868,7 @@ module Compiler else f.write(sprintf("[%03d]\r\n", map_data.id)) end - for key in keys + keys.each do |key| record = map_data.property_from_string(key) next if record.nil? || (record.is_a?(Array) && record.empty?) f.write(sprintf("%s = ", key)) diff --git a/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb b/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb index 6a4669134..f65f4f5ea 100644 --- a/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb +++ b/Data/Scripts/021_Compiler/004_Compiler_MapsAndEvents.rb @@ -45,14 +45,14 @@ module Compiler # Get IDs of all maps in the Data folder Dir.chdir("Data") { mapData = sprintf("Map*.rxdata") - for map in Dir.glob(mapData) + Dir.glob(mapData).each do |map| mapfiles[$1.to_i(10)] = true if map[/map(\d+)\.rxdata/i] end } mapinfos = pbLoadMapInfos maxOrder = 0 # Exclude maps found in mapinfos - for id in mapinfos.keys + mapinfos.keys.each do |id| next if !mapinfos[id] mapfiles.delete(id) if mapfiles[id] maxOrder = [maxOrder, mapinfos[id].order].max @@ -61,7 +61,7 @@ module Compiler maxOrder += 1 imported = false count = 0 - for id in mapfiles.keys + mapfiles.keys.each do |id| next if id == 999 # Ignore 999 (random dungeon map) mapinfo = RPG::MapInfo.new mapinfo.order = maxOrder @@ -116,7 +116,7 @@ module Compiler def push_move_route(list, character, route, indent = 0) route = generate_move_route(route) if route.is_a?(Array) - for i in 0...route.list.length + route.list.length.times do |i| list.push( RPG::EventCommand.new((i == 0) ? 209 : 509, indent, (i == 0) ? [character, route] : [route.list[i - 1]]) @@ -143,7 +143,7 @@ module Compiler def push_comment(list, cmt, indent = 0) textsplit2 = cmt.split(/\n/) - for i in 0...textsplit2.length + textsplit2.length.times do |i| list.push(RPG::EventCommand.new((i == 0) ? 108 : 408, indent, [textsplit2[i].gsub(/\s+$/, "")])) end end @@ -151,10 +151,10 @@ module Compiler def push_text(list, text, indent = 0) return if !text textsplit = text.split(/\\m/) - for t in textsplit + textsplit.each do |t| first = true textsplit2 = t.split(/\n/) - for i in 0...textsplit2.length + textsplit2.length.times do |i| textchunk = textsplit2[i].gsub(/\s+$/, "") if textchunk && textchunk != "" list.push(RPG::EventCommand.new((first) ? 101 : 401, indent, [textchunk])) @@ -168,7 +168,7 @@ module Compiler return if !script first = true textsplit2 = script.split(/\n/) - for i in 0...textsplit2.length + textsplit2.length.times do |i| textchunk = textsplit2[i].gsub(/\s+$/, "") if textchunk && textchunk != "" list.push(RPG::EventCommand.new((first) ? 355 : 655, indent, [textchunk])) @@ -200,7 +200,7 @@ module Compiler end def apply_pages(page, pages) - for p in pages + pages.each do |p| p.graphic = page.graphic p.walk_anime = page.walk_anime p.step_anime = page.step_anime @@ -314,7 +314,7 @@ module Compiler @mapHeights[mapID] = map.height mapPositions = [] width = map.width - for e in map.events.values + map.events.values.each do |e| mapPositions[(e.y * width) + e.x] = e if e end @mapxy[mapID] = mapPositions @@ -351,7 +351,7 @@ module Compiler return false if x < 0 || x >= map.width || y < 0 || y >= map.height passages = getTilesetPassages(map, mapID) priorities = getTilesetPriorities(map, mapID) - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = map.data[x, y, i] return false if tile_id == nil passage = passages[tile_id] @@ -369,7 +369,7 @@ module Compiler map = getMap(mapID) return false if !map passages = getTilesetPassages(map, mapID) - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = map.data[x, y, i] return false if tile_id == nil passage = passages[tile_id] @@ -386,7 +386,7 @@ module Compiler map = getMap(mapID) return if !map passages = getTilesetPassages(map, mapID) - for i in [2, 1, 0] + [2, 1, 0].each do |i| tile_id = map.data[x, y, i] next if tile_id == 0 passages[tile_id] |= 0x80 @@ -396,7 +396,7 @@ module Compiler def registerSwitch(switch) return @registeredSwitches[switch] if @registeredSwitches[switch] - for id in 1..5000 + (1..5000).each do |id| name = @system.switches[id] next if name && name != "" && name != switch @system.switches[id] = switch @@ -459,10 +459,10 @@ module Compiler commands = [] isFirstCommand = false # Find all the trainer comments in the event - for i in 0...list.length + list.length.times do |i| next if list[i].code != 108 # Comment (first line) command = list[i].parameters[0] - for j in (i + 1)...list.length + ((i + 1)...list.length).each do |j| break if list[j].code != 408 # Comment (continuation line) command += "\r\n" + list[j].parameters[0] end @@ -502,7 +502,7 @@ module Compiler endifswitch = [] vanishifswitch = [] regspeech = nil - for command in commands + commands.each do |command| if command[/^Battle\:\s*([\s\S]+)$/i] battles.push($~[1]) push_comment(firstpage.list, command) if rewriteComments @@ -604,7 +604,7 @@ module Compiler rematchpage.condition.self_switch_valid = true rematchpage.condition.self_switch_ch = "B" # Write rematch and last pages - for i in 1...battles.length + (1...battles.length).each do |i| # Run trainer check now, except in editor trainerChecker.pbTrainerBattleCheck(trtype, trname, battleid + i) if i == battles.length - 1 @@ -664,7 +664,7 @@ module Compiler ret.pages = [firstpage, rematchpage, lastpage] end # Copy last page to endIfSwitch page - for endswitch in endifswitch + endifswitch.each do |endswitch| endIfSwitchPage = Marshal.load(Marshal.dump(lastpage)) endIfSwitchPage.condition = lastpage.condition.clone if endIfSwitchPage.condition.switch1_valid # Add another page condition @@ -682,7 +682,7 @@ module Compiler ret.pages.push(endIfSwitchPage) end # Copy last page to vanishIfSwitch page - for vanishswitch in vanishifswitch + vanishifswitch.each do |vanishswitch| vanishIfSwitchPage = Marshal.load(Marshal.dump(lastpage)) vanishIfSwitchPage.graphic.character_name = "" # No charset vanishIfSwitchPage.condition = lastpage.condition.clone @@ -952,7 +952,7 @@ module Compiler # Using old method of recovering case script when "foriin$player.partyi.healend" - for j in i..lastScript + (i..lastScript).each do |j| list.delete_at(i) end list.insert(i, @@ -960,7 +960,7 @@ module Compiler changed = true when "pbFadeOutIn(99999){foriin$player.partyi.healend}" oldIndent = list[i].indent - for j in i..lastScript + (i..lastScript).each do |j| list.delete_at(i) end list.insert( @@ -1431,7 +1431,7 @@ module Compiler def check_counters(map, mapID, mapData) toDelete = [] changed = false - for key in map.events.keys + map.events.keys.each do |key| event = map.events[key] next if !plain_event_or_mart?(event) # Found an event that is empty or looks like a simple Mart or a Poké @@ -1442,7 +1442,7 @@ module Compiler neighbors.push(mapData.getEventFromXY(mapID, event.x - 1, event.y)) neighbors.push(mapData.getEventFromXY(mapID, event.x + 1, event.y)) neighbors.compact! - for otherEvent in neighbors + neighbors.each do |otherEvent| next if plain_event?(otherEvent) # Blank/cosmetic-only event next if !likely_counter?(event, otherEvent, mapID, mapData) # Found an adjacent event that looks like it's supposed to be a counter. @@ -1471,14 +1471,14 @@ module Compiler change_record = [] Console.echo_li _INTL("Processing {1} maps...", mapData.mapinfos.keys.length) idx = 0 - for id in mapData.mapinfos.keys.sort + mapData.mapinfos.keys.sort.each do |id| echo "." if idx % 20 == 0 idx += 1 Graphics.update if idx % 250 == 0 changed = false map = mapData.getMap(id) next if !map || !mapData.mapinfos[id] - for key in map.events.keys + map.events.keys.each do |key| if Time.now.to_i - t >= 5 Graphics.update t = Time.now.to_i @@ -1518,7 +1518,7 @@ module Compiler Graphics.update commonEvents = load_data("Data/CommonEvents.rxdata") Console.echo_li _INTL("Processing common events...") - for key in 0...commonEvents.length + commonEvents.length.times do |key| newevent = fix_event_use(commonEvents[key], 0, mapData) if newevent commonEvents[key] = newevent