LiTTleDRAgo

[RGSS] Method & Class Library (MACL) Part 1

May 20th, 2013
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 297.14 KB | None | 0 0
  1. #==============================================================================
  2. # ** Method & Class Library
  3. #------------------------------------------------------------------------------
  4. # Build Date  - 09-17-2006
  5. # Version 1.0 - 09-17-2006 - Trickster
  6. # Version 1.1 - 10-03-2006 - Trickster
  7. # Version 1.2 - 11-01-2006 - Trickster & Selwyn
  8. # Version 1.3 - 11-10-2006 - Trickster
  9. # Version 1.4 - 12-01-2006 - Trickster
  10. # Version 1.5 - 01-01-2007 - Trickster, Yeyinde & Lobosque
  11. # Version 2.0 - 04-26-2007 - MACL Authors  
  12. # Version 2.1 - 07-22-2007 - MACL Authors  
  13. # Version 2.2 - 11-20-2007 - MACL Authors & SephirothSpawn
  14. # Version 2.3 - 06-19-2008 - SephirothSpawn & Zeriab
  15. #==============================================================================
  16.  
  17. #==============================================================================
  18. # ** Method & Class Library Settings
  19. #------------------------------------------------------------------------------
  20. # ** General MACL Settings
  21. #
  22. #   * Pose Names for Charactersets
  23. #    - Poses = ['down', 'left', 'right', 'up']
  24. #   * Number of Frames Per Pose for charactersets
  25. #    - Frames = 4
  26. #   * Real Elements
  27. #    - Real_Elements = 1, 2, 3, 4, 5, 6, 7, 8
  28. #
  29. # ** Action Test Setup
  30. #
  31. #   * Attack Using
  32. #     - Set this to the basic ids that perform an attack effect
  33. #   * Skill Using
  34. #     - Set this to the kinds that perform an skill effect
  35. #   * Defend Using
  36. #     - Set this to the basic ids that perform an defend effect
  37. #   * Item Using
  38. #     - Set this to the kinds that perform a item using effect
  39. #   * Escape Using
  40. #     - Set this to the basic ids that perform an escape effect
  41. #   * Wait Using
  42. #     - Set this to the basic ids that perform a wait effect
  43. #
  44. # ** Font
  45. #
  46. #   * Default Text Underline Setting
  47. #    - Default_Underline = true or false
  48. #   * Default Text Underline Full Setting
  49. #    - Default_Underline_Full = true or false
  50. #   * Default Text Strikethrough Setting
  51. #    - Default_Strikethrough = true or false
  52. #   * Default Text Stikethrough Full Setting
  53. #    - Default_Strikethrough_Full = true or false
  54. #   * Default Text Shadow Setting
  55. #    - Default_Shadow = true or false
  56. #   * Default Text Shadow Color Setting
  57. #    - Default_Shadow_Color = Color.new(0, 0, 0, 100)
  58. #   * Default Text Outline Setting
  59. #    - Default_Outline = true or false
  60. #   * Default Text Outline Color Setting
  61. #    - Default_Outline_Color = Color.new(0, 0, 0, 100)
  62. #   * Default Text Vertical Gradient Setting
  63. #    - Default_Vert_Grad = true or false
  64. #   * Default Text Horizontal Gradient Setting
  65. #    - Default_Horiz_Grad = true or false
  66. #   * Default Text Gradient Start Color Setting
  67. #    - Default_Grad_S_Color = Color.new(0, 0, 0, 100)
  68. #   * Default Text Gradient End Color Setting
  69. #    - Default_Grad_E_Color = Color.new(0, 0, 0, 100)
  70. #   * Default Font Addon Order (For multi-add settings)
  71. #    - Font_Addon_Order = [:method_name, :method_name, ...]
  72. #
  73. # ** State Icon Settings
  74. #
  75. #   * Normal Icon Filename
  76. #    - Normal_Icon = 'filename'
  77. #   * State Specific Icons
  78. #    - Icon_Name = {state_id => 'filename', ...}
  79. #
  80. # ** Bitmap Draw Settings
  81. #
  82. #   * Bitmap.draw_equip settings (Icon Type Settings When Item Not Equipped)
  83. #    - Draw_Equipment_Icon_Settings = {type_id => icon_name, ...}
  84. #   * Bitmap.draw_blur settings
  85. #    - Blur_Settings = {setting_key => setting, ...}
  86. #    Setting Keys
  87. #     'offset'  - Pixels to be offseted when bluring
  88. #     'spacing' - Number of times to offset blur
  89. #     'opacity' - Max Opacity of blur
  90. #   * Bitmap.draw_anim_sprite settings
  91. #    - Anim_Sprite_Settings = {setting_key => setting, ...}
  92. #    Settings
  93. #     'f' - Frame count reset
  94. #     'w' - Number of frames wide in sprite set
  95. #     'h' - Height of frames wide in sprite set
  96. #==============================================================================
  97.  
  98. module MACL
  99.   #-------------------------------------------------------------------------
  100.   # * Author Settings (DO NOT TOUCH)
  101.   #-------------------------------------------------------------------------
  102.   Version   = 2.3
  103.   Loaded = []
  104.   #-------------------------------------------------------------------------
  105.   # * General Settings
  106.   #-------------------------------------------------------------------------
  107.   Poses = ['down', 'left', 'right', 'up']
  108.   Frames = 4
  109.   Real_Elements = 1, 2, 3, 4, 5, 6, 7, 8
  110.   #-------------------------------------------------------------------------
  111.   # * Action Test Setup
  112.   #-------------------------------------------------------------------------
  113.   Game_BattleAction::ATTACK_USING = [0]
  114.   Game_BattleAction::SKILL_USING  = [1]
  115.   Game_BattleAction::DEFEND_USING = [1]
  116.   Game_BattleAction::ITEM_USING   = [2]
  117.   Game_BattleAction::ESCAPE_USING = [2]
  118.   Game_BattleAction::WAIT_USING  = [3]
  119.   #-------------------------------------------------------------------------
  120.   # * Font Settings
  121.   #-------------------------------------------------------------------------
  122.   Font::Default_Underline           = false
  123.   Font::Default_Underline_Full      = false
  124.   Font::Default_Strikethrough       = false
  125.   Font::Default_Strikethrough_Full  = false
  126.   Font::Default_Shadow              = true
  127.   Font::Default_Shadow_Color        = Color.new(0, 0, 0, 100)
  128.   Font::Default_Outline             = false
  129.   Font::Default_Outline_Color       = Color.new(0, 0, 0)
  130.   Font::Default_Vert_Grad           = false
  131.   Font::Default_Horiz_Grad          = false
  132.   Font::Default_Grad_S_Color        = Color.new(255, 255, 255)
  133.   Font::Default_Grad_E_Color        = Color.new(128, 128, 128)
  134.   Font::Addon_Order = [
  135.     :draw_text_shadow,
  136.     :draw_text_outline,
  137.     :draw_text,
  138.     :draw_text_underline,
  139.     :draw_text_strikethrough,
  140.     :draw_text_gradient
  141.   ]
  142.   #-------------------------------------------------------------------------
  143.   # * State Icon Settings
  144.   #-------------------------------------------------------------------------
  145.   RPG::State::Normal_Icon = '050-Skill07'
  146.   RPG::State::Icon_Name = {
  147.     1  => '046-Skill03',
  148.     2  => 'Stop',
  149.     3  => 'Venom',
  150.     4  => 'Darkness',
  151.     5  => 'Mute',
  152.     6  => 'Confused',
  153.     7  => 'Sleep',
  154.     8  => 'Paralysis',
  155.     9  => '047-Skill04',
  156.     10 => '047-Skill04',
  157.     11 => 'Slow',
  158.     12 => '047-Skill04',
  159.     13 => '045-Skill06',
  160.     14 => '045-Skill06',
  161.     15 => '045-Skill06',
  162.     16 => '045-Skill06'
  163.   }
  164.   RPG::State::Icon_Name.default = nil
  165.   #-------------------------------------------------------------------------
  166.   # * Bitmap Draw Settings
  167.   #-------------------------------------------------------------------------
  168.   Bitmap::Draw_Equipment_Icon_Settings = {
  169.     0 => '001-Weapon01',
  170.     1 => '009-Shield01',
  171.     2 => '010-Head01',
  172.     3 => '014-Body02',
  173.     4 => '016-Accessory01'
  174.   }
  175.   Bitmap::Draw_Equipment_Icon_Settings.default = '001-Weapon01'
  176.   Bitmap::Blur_Settings = {
  177.     'offset' => 2,
  178.     'spacing' => 1,
  179.     'opacity' => 255
  180.   }
  181.   Bitmap::Anim_Sprite_Settings = {
  182.     'f' => 8,
  183.     'w' => 4,
  184.     'h' => 4
  185.   }
  186.   #-------------------------------------------------------------------------
  187.   # * Animated Autotile Settings
  188.   #-------------------------------------------------------------------------
  189.   RPG::Cache::Animated_Autotiles_Frames = 16
  190. end
  191.  
  192. #==============================================================================
  193. # ** SDK Log
  194. #==============================================================================
  195.  
  196. if Object.const_defined?(:SDK)
  197.   SDK.log('Method & Class Library', 'MACL Authors', 2.11, '2007-08-29')
  198. end
  199.  
  200. #==============================================================================
  201. # ** Method and Class Library - Documentation
  202. #------------------------------------------------------------------------------
  203. # * Outline
  204. #
  205. #  This script set provides a utility for other scripters by: adding extra
  206. #  methods, classes & modules to prevent other scripters from
  207. #  "reinventing the wheel" and adding methods, classes & modules for other
  208. #  scripters to use
  209. #------------------------------------------------------------------------------
  210. # * How to Install
  211. #
  212. #  - The main setup should be placed below all default scripts, but above
  213. #    custom ones, that is, below Scene_Debug, but above main. If SDK is present
  214. #    then below SDK.
  215. #  - Non scripters can just add the set so that scripts that utilize these
  216. #    methods/classes will work without any errors.
  217. #  - Notice the System Setup this controls constants which may affect some
  218. #    scripts using them.
  219. #------------------------------------------------------------------------------
  220. # * How to Use
  221. #
  222. #  - Please refer to the individual files for method/class information
  223. #  - If you see a method/class you want to use copy the whole set into your
  224. #    script preferably in a new script telling what set it is so for people who
  225. #    have the whole set can just remove that script since it is already included
  226. #  - Do not just copy the method/class you want to use copy the whole set since
  227. #    some methods in a set depend on other methods.
  228. #  - DO NOT EDIT ANY OF THE METHODS IN MACL!!!
  229. #     If you want to edit a method make a copy of it change the name and edit it
  230. #     If you want to edit a class make a new class w/a copy the methods from
  231. #     there
  232. #  - Be sure to follow the method call instructions given
  233. #  - If you have any questions then post in the following topic:
  234. #    http://www.rmxp.org/forums/showthread.php?t=9417
  235. #------------------------------------------------------------------------------
  236. # * Submitting an Item to the library  
  237. #
  238. # Naming
  239. # ------
  240. #  - Method names should be in all lowercase letters, this is to prevent the
  241. #    Ruby Interpreter from confusing methods with constants.
  242. #  - Dangerous (Modifies Itself) Methods should be followed by an !
  243. #  - Query (Testing, Checking) Methods should be followed by an ?
  244. #  - Commonly created methods (gradient bars, etc.) should have the author's
  245. #    name in it as well to prevent incompatibilty
  246. #  - Class names should begin with a Capital letter
  247. #  
  248. # Headers
  249. # -------
  250. #  - Methods should use this header
  251.   #-------------------------------------------------------------------------
  252.   # * Name      :
  253.   #   Info      :
  254.   #   Author    :
  255.   #   Call Info :
  256.   #   Comments  :
  257.   #-------------------------------------------------------------------------
  258. #  - Classes should use this header
  259. #==============================================================================
  260. # ** Class Name                                                       By Author
  261. #------------------------------------------------------------------------------
  262. #  A Description of your class here
  263. #==============================================================================
  264. #
  265. # Approval
  266. # --------
  267. #  - All Items must be approved before being put in the library, this is to
  268. #    maintain quality and to ensure that methods/classes work, are functional
  269. #    and stable.
  270. #      
  271. # Improvements
  272. # ------------
  273. #  - If you want to improve a method, such as adding new functionality or
  274. #    improving a method, you can directly edit it, but the old and new calls
  275. #    to a method must be compatible, that is it should do the same thing it
  276. #    did with the original call. You must update the method header and then
  277. #    submit it for approval.
  278. #==============================================================================
  279.  
  280. #==============================================================================
  281. # ** Ruby.Higher Classes
  282. #------------------------------------------------------------------------------
  283. # Description:
  284. # ------------
  285. # Methods created to enhance the higher classes in Ruby.
  286. #  
  287. # Method List:
  288. # ------------
  289. #
  290. #   Module
  291. #   ------
  292. #   attr_sec_accessor
  293. #   attr_sec_reader
  294. #   class_accessor
  295. #   class_writer
  296. #   class_reader
  297. #   class_sec_accessor
  298. #   class_sec_reader
  299. #   super_skip
  300. #    
  301. #   Kernel
  302. #   ------
  303. #   class_type
  304. #   rand_between
  305. #   rand_name
  306. #==============================================================================
  307.  
  308. MACL::Loaded << 'Ruby.Higher Classes'
  309.  
  310. #==============================================================================
  311. # ** Module    
  312. #==============================================================================
  313.  
  314. class Module
  315.   #-------------------------------------------------------------------------
  316.   # * Name      : Secondary Accessor (Reader with a default)
  317.   #   Info      : Creates reader and writer method for one or more
  318.   #               instance variables, with the reader methods having
  319.   #               default values
  320.   #   Author    : Zeriab
  321.   #   Call Info : Symbol & Default Pairs, and optional Block
  322.   #-------------------------------------------------------------------------
  323.   def attr_sec_accessor(sym, *args, &block)
  324.     if block.nil? # default actions
  325.       args = [0] if args.size == 0 #default = 0
  326.       if args.size < 2 # One pair
  327.         attr_writer sym
  328.         attr_sec_reader sym, *args
  329.       else # loads of methods followed by a default value.
  330.         default = args[-1]
  331.         syms = [sym].concat(args)
  332.         syms.pop
  333.         for sym in syms
  334.           attr_writer sym
  335.           attr_sec_reader sym, default
  336.         end
  337.       end
  338.     else # when a block is given
  339.       # currently just pair sematics
  340.       args.unshift(sym)
  341.       i = 0
  342.       while i < args.size
  343.         attr_writer args[i]
  344.         attr_sec_reader args[i], args[i+1]
  345.         i += 2
  346.       end
  347.     end
  348.   end
  349.   #-------------------------------------------------------------------------
  350.   # * Name      : Secondary Reader (Reader with a default)
  351.   #   Info      : Creates reader method for one instance variable,
  352.   #               with the reader methods having default a value
  353.   #   Author    : Zeriab
  354.   #   Call Info : Symbol & Default Pair
  355.   #-------------------------------------------------------------------------
  356.   def attr_sec_reader(sym, default = 0)
  357.     sym = sym.id2name
  358.     string = "def #{sym};" +
  359.              "  @#{sym} = #{default}  if @#{sym}.nil?;" +
  360.              "  @#{sym};" +
  361.              "end;"
  362.     module_eval(string)
  363.   end
  364.   #-------------------------------------------------------------------------
  365.   # * Name      : Class Attribute
  366.   #   Info      : Calls class_reader/writer for a symbol
  367.   #   Author    : Yeyinde
  368.   #   Call Info : symbol, writable
  369.   #               symbol:   A Symbol
  370.   #               writable: Boolean telling is symbol is writable
  371.   #-------------------------------------------------------------------------
  372.   private
  373.   def class_attr(symbol, writable = false)
  374.     class_reader(symbol)
  375.     class_writer(symbol) if writable
  376.     return nil
  377.   end
  378.   #-------------------------------------------------------------------------
  379.   # * Name       : Class Accessor
  380.   #   Info       : Creates reader and writer methods for one or more class
  381.   #                variables
  382.   #   Author     : Yeyinde
  383.   #   Call Info  : One or more Symbols
  384.   #-------------------------------------------------------------------------
  385.   def class_accessor(*symbols)
  386.     class_writer(*symbols)
  387.     class_reader(*symbols)
  388.   end
  389.   #-------------------------------------------------------------------------
  390.   # * Name      : Class Writer
  391.   #   Info      : Creates writer method for one or more class variables
  392.   #   Author    : Yeyinde
  393.   #   Call Info : One or more Symbols
  394.   #-------------------------------------------------------------------------
  395.   def class_writer(*symbols)
  396.     symbols.each do |symbol|
  397.       method = symbol.id2name
  398.       module_eval("def self.#{method}=(var); @@#{method} = var; end")
  399.     end
  400.     return nil
  401.   end
  402.   #-------------------------------------------------------------------------
  403.   # * Name      : Class Reader
  404.   #   Info      : Creates reader method for one or more class variables
  405.   #   Author    : Yeyinde
  406.   #   Call Info : One or more Symbols
  407.   #-------------------------------------------------------------------------
  408.   def class_reader(*symbols)
  409.     symbols.each do |symbol|
  410.       method = symbol.id2name
  411.       module_eval("def self.#{method}; return @@#{method}; end")
  412.     end
  413.     return nil
  414.   end
  415.   #-------------------------------------------------------------------------
  416.   # * Name      : Class Secondary Accessor (Reader with a default)
  417.   #   Info      : Creates reader and writer method for one or more
  418.   #               class variables, with the reader methods having
  419.   #               default values
  420.   #   Author    : Zeriab, Yeyinde & SephirothSpawn
  421.   #   Call Info : Symbol & Default Pairs, and optional Block
  422.   #-------------------------------------------------------------------------
  423.   def class_sec_accessor(sym, *args, &block)
  424.     if block.nil? # default actions
  425.       args = [0] if args.size == 0 #default = 0
  426.       if args.size < 2 # One pair
  427.         class_writer sym
  428.         class_sec_reader sym, *args
  429.       else # loads of methods followed by a default value.
  430.         default = args[-1]
  431.         syms = [sym].concat(args)
  432.         syms.pop
  433.         for sym in syms
  434.           class_writer sym
  435.           class_sec_reader sym, default
  436.         end
  437.       end
  438.     else # when a block is given
  439.       # currently just pair sematics
  440.       args.unshift(sym)
  441.       i = 0
  442.       while i < args.size
  443.         class_writer args[i]
  444.         class_sec_reader args[i], args[i+1]
  445.         i += 2
  446.       end
  447.     end
  448.   end
  449.   #-------------------------------------------------------------------------
  450.   # * Name      : Class Secondary Reader (Reader with a default)
  451.   #   Info      : Creates reader method for one class variable,
  452.   #               with the reader methods having default a value
  453.   #   Author    : Zeriab, Yeyinde & SephirothSpawn
  454.   #   Call Info : Symbol & Default Pair
  455.   #-------------------------------------------------------------------------
  456.   def class_sec_reader(sym, default = 0)
  457.     sym = sym.id2name
  458.     string = "def self.#{sym};" +
  459.              "  @@#{sym} = #{default}  if @@#{sym}.nil?;" +
  460.              "  @@#{sym};" +
  461.              "end;"
  462.     module_eval(string)
  463.   end
  464.   #-------------------------------------------------------------------------
  465.   # * Name      : Super Skip
  466.   #   Info      : Allows you to call ancestor super method, without calling
  467.   #               ancestors between target ancestor.
  468.   #   Author    : SephirothSpawn
  469.   #   Call Info : Method Name (Symbol)
  470.   #               Target Parent Class (Class Name)
  471.   #               Script Name (String)
  472.   #-------------------------------------------------------------------------
  473.   def super_skip(method_name, tpc, script_name = 'modulemethodskip')
  474.     # Gets String Version of Method Name
  475.     method_name = method_name.id2name
  476.     # Gets Array of Ancstors
  477.     ancestors = self.ancestors
  478.     # If Target Parent Class not part of Ancestors
  479.     unless ancestors.include?(tpc)
  480.       p 'Un-defined Parents Class - ' + tpc.to_s
  481.       return
  482.     end
  483.     # Starts Index
  484.     index = 0
  485.     # Gets Target Parent Index
  486.     target_index = ancestors.index(tpc)
  487.     # Loop
  488.     loop do
  489.       # Adds Index
  490.       index += 1
  491.       # Break if Passed Target Index
  492.       break if index >= target_index
  493.       # Gets Class Names
  494.       cname1 = ancestors[index].to_s
  495.       cname2 = ancestors[index - 1].to_s
  496.       # Gets Alias Name
  497.       aliasn = "seph_#{script_name}_#{cname1.downcase}_#{method_name}"
  498.       # Gets String
  499.       string  = "class ::#{cname1};"
  500.       string += "  alias_method :#{aliasn}, :#{method_name};"
  501.       string += "  def #{method_name}(*args);"
  502.       string += "    super(*args);"
  503.       string += "    return if self.is_a?(#{ancestors[index - 1]});"
  504.       string += "    self.#{aliasn}(*args);"
  505.       string += "  end;"
  506.       string += "end;"
  507.       # Evaulates String
  508.       eval string
  509.     end
  510.   end
  511. end
  512.  
  513. #==============================================================================
  514. # ** Kernel    
  515. #==============================================================================
  516.  
  517. module Kernel
  518.   #-------------------------------------------------------------------------
  519.   #   Name      : Class Type
  520.   #   Info      : Returns a string representing the class type
  521.   #   Author    : Trickster
  522.   #   Call Info : No Arguments
  523.   #-------------------------------------------------------------------------
  524.   def class_type
  525.     # Branch By Object's class
  526.     case self
  527.     when FalseClass, TrueClass, NilClass, Numeric, Range, Regexp, String, Symbol
  528.       # Inspection
  529.       string = inspect
  530.     when Array
  531.       # If Object Is Empty
  532.       if empty?
  533.         # Set String
  534.         string = 'Empty Array'
  535.       else
  536.         # Get Class
  537.         data_type = compact[0].class
  538.         # Setup flag
  539.         flag = true
  540.         # Run Through Compacted data checking class
  541.         compact.each {|data| flag &&= data.class == data_type}
  542.         # Setup Extra String to class if flag is true
  543.         string = 'Array - ' + (flag ? data_type.to_s : 'Object')
  544.       end
  545.     when Hash
  546.       # If Object Is Empty
  547.       if empty?
  548.         # Set String
  549.         string = 'Empty Hash'
  550.       else
  551.         # Get Class
  552.         key_type = keys.compact[0].class
  553.         # Setup flag
  554.         key = true
  555.         # Run Through Compacted data checking class
  556.         keys.compact.each {|data| key &&= data.class == key_type}
  557.         # Get Class
  558.         value_type = values.compact[0].class
  559.         # Setup flag
  560.         value = true
  561.         # Run Through Compacted data checking class
  562.         values.compact.each {|data| value &&= data.class == value_type}
  563.         # Setup Extra String to class if flag is true
  564.         string = 'Hash - ' + (key ? key_type.to_s : 'Object') + ' => ' +
  565.           (value ? value_type.to_s : 'Object')
  566.       end
  567.     when Class
  568.       string = self.to_s + ':Class'
  569.     when Module
  570.       string = self.to_s + ':Module'
  571.     else
  572.       # Get Class Name
  573.       string = self.class.to_s
  574.     end
  575.     # Return String
  576.     return string  
  577.   end
  578.   #-------------------------------------------------------------------------
  579.   # * Name      : Random Number Between
  580.   #   Info      : Creates a random number between two numbers
  581.   #   Author    : SephirothSpawn
  582.   #   Call Info : Min and Max Number
  583.   #-------------------------------------------------------------------------
  584.   def rand_between(min, max)
  585.     return min + rand(max - min + 1)
  586.   end
  587.   #-------------------------------------------------------------------------
  588.   # * Name      : Random Name
  589.   #   Info      : Creates a random name
  590.   #   Author    : Trickster
  591.   #   Call Info : Variable - Format Strings If none then strings from Setup
  592.   #               Are Used
  593.   #   Comments  : Format C - consonant V - vowel
  594.   #-------------------------------------------------------------------------
  595.   def rand_name(*formats)
  596.     format = formats.random
  597.     name = ''
  598.     format.split(//).each do |char|
  599.       case char
  600.       when 'C'
  601.         name += %w( B C D F G H J K L M N P R S T V W X Y Z ).random
  602.       when 'V'
  603.         name += %w( A E I O U Y ).random
  604.       when 'c'
  605.         name += %w( b c d f g h j k l m n p r s t v w x y z ).random
  606.       when 'v'
  607.         name += %w( a e i o u y ).random
  608.       else
  609.         name += char
  610.       end
  611.     end
  612.     return name
  613.   end
  614. end
  615.  
  616. #==============================================================================
  617. # ** Ruby.Array.find
  618. #------------------------------------------------------------------------------
  619. # Description:
  620. # ------------
  621. # Methods created for finding and returning objects inside of an array.
  622. #  
  623. # Method List:
  624. # ------------
  625. # all_indexes
  626. # find_index
  627. # includes?
  628. # includes_any?
  629. # include_times
  630. # of_index
  631. #==============================================================================
  632.  
  633. MACL::Loaded << 'Ruby.Array.find'
  634.  
  635. #==============================================================================
  636. # ** Array    
  637. #==============================================================================
  638.  
  639. class Array
  640.   #-------------------------------------------------------------------------
  641.   # * Name      : All Indexes
  642.   #   Info      : Returns All indexes where obj is (see find_index)
  643.   #   Author    : Trickster
  644.   #   Call Info : One Argument. Value (Object)
  645.   #   Comment   : Synonym for find_index
  646.   #-------------------------------------------------------------------------
  647.   def all_indexes(obj)
  648.     # Setup Array
  649.     array = []
  650.     # Run Through Push index if objects are equal
  651.     each_index {|index| array << index if obj == self[index]}
  652.     # Return Array
  653.     return array
  654.   end
  655.   #-------------------------------------------------------------------------
  656.   # * Name      : Finds Index
  657.   #   Info      : Finds all indexes with the value sent to it
  658.   #   Author    : Trickster
  659.   #   Call Info : One Argument. a Object
  660.   #-------------------------------------------------------------------------
  661.   def find_index(value)
  662.     # Setup Array of Indexes
  663.     indexes = []
  664.     # Run Through each with index and add index if the same
  665.     each_with_index {|element, index| indexes << index if element == value}
  666.     # Return Indexes
  667.     return indexes
  668.   end  
  669.   #-------------------------------------------------------------------------
  670.   #   Name      : Includes?
  671.   #   Info      : Returns true if all of the values sent is included
  672.   #   Author    : Trickster
  673.   #   Call Info : Variable Amount, Objects
  674.   #   Comment   : If using an array and want to check each element,
  675.   #               use argument expansion to expand the array.
  676.   #-------------------------------------------------------------------------
  677.   def includes?(*args)
  678.     # Return false if object is not included
  679.     args.each {|object| return false unless include?(object)}
  680.     # Everything is included
  681.     return true
  682.   end
  683.   #-------------------------------------------------------------------------
  684.   #   Name      : Includes Any?
  685.   #   Info      : Returns true if any of the values sent is included
  686.   #   Author    : Trickster
  687.   #   Call Info : Variable Amount, Objects
  688.   #   Comment   : If using an array and want to check each element,
  689.   #               use argument expansion to expand the array.
  690.   #-------------------------------------------------------------------------
  691.   def includes_any?(*args)
  692.     # Return true if args is empty
  693.     return true if args.empty?
  694.     # Return true if any of the objects is included
  695.     args.each {|object| return true if include?(object)}
  696.     # Not Included
  697.     return false
  698.   end
  699.   #-------------------------------------------------------------------------
  700.   # * Name      : Include Times
  701.   #   Info      : Returns how many times the value sent is included
  702.   #   Author    : Trickster
  703.   #   Call Info : One Argument. anObject
  704.   #-------------------------------------------------------------------------
  705.   def include_times(obj)
  706.     # Setup Local Variable
  707.     times = 0
  708.     # Run Through Each Increaing Times if object is equal
  709.     each {|element| times += 1 if element == obj}
  710.     # Return number of times included
  711.     return times
  712.   end
  713.   #-------------------------------------------------------------------------
  714.   # * Name      : Of index
  715.   #   Info      : Assuming Self is an Array of Arrays returns the values at index
  716.   #   Author    : Trickster
  717.   #   Call Info : One - Integer index index of the values you want to return
  718.   #-------------------------------------------------------------------------
  719.   def of_index(index)
  720.     # Create Array
  721.     array = []
  722.     # Run Through and get array at index
  723.     each {|sub_array| array << sub_array[index] if sub_array.is_a?(Array)}
  724.     # Return Array
  725.     return array
  726.   end
  727. end
  728.  
  729. #==============================================================================
  730. # ** Ruby.Array.math
  731. #------------------------------------------------------------------------------
  732. # Description:
  733. # ------------
  734. # More Mathematical methods for the Array class, these methods however assume
  735. # all objects in the array are of class Numeric.
  736. #  
  737. # Method List:
  738. # ------------
  739. # average
  740. # geometric_average
  741. # product
  742. # sum
  743. #==============================================================================
  744.  
  745. MACL::Loaded << 'Ruby.Array.math'
  746.  
  747. #==============================================================================
  748. # ** Array    
  749. #==============================================================================
  750.  
  751. class Array
  752.   #---------------------------------------------------------------------------
  753.   # * Name      : Average
  754.   #   Info      : Averages all values in the array
  755.   #   Author    : Trickster
  756.   #   Call Info : Zero To One Arguments Defaults to False
  757.   #               Boolean float if true always returns a Float else returns a
  758.   #               Float or a Integer depending on the Types in the array
  759.   #---------------------------------------------------------------------------
  760.   def average(float = false)
  761.     # Divide By Number
  762.     return sum / (float ? size.to_f : size)
  763.   end
  764.   #---------------------------------------------------------------------------
  765.   # * Name      : Geometric Average
  766.   #   Info      : Returns the Geometric Mean of all values in the array
  767.   #   Author    : Trickster
  768.   #   Call Info : Zero To One Arguments Defaults to False
  769.   #               Boolean to_float if true always returns a Float else
  770.   #               always returns an Integer regardless of the Types in the
  771.   #               array
  772.   #---------------------------------------------------------------------------
  773.   def geometric_average(float = false)
  774.     # Return 0 if empty
  775.     return 0 if empty?
  776.     # Get Geometric Average
  777.     average = product ** (1.0 / size)
  778.     # If Float return average else convert to integer
  779.     return (float ? average : average.to_i)
  780.   end
  781.   #---------------------------------------------------------------------------
  782.   # * Name      : Product
  783.   #   Info      : Returns the product of all values in the array
  784.   #   Author    : Trickster
  785.   #   Call Info : No Arguments
  786.   #---------------------------------------------------------------------------
  787.   def product
  788.     # Setup N initialize to 1
  789.     n = 1
  790.     # Run Through and Find Product
  791.     each {|num| n *= num}
  792.     # Return Product
  793.     return n
  794.   end
  795.   #---------------------------------------------------------------------------
  796.   # * Name      : Sum
  797.   #   Info      : Sums all values in the array
  798.   #   Author    : Trickster
  799.   #   Call Info : No Arguments
  800.   #---------------------------------------------------------------------------
  801.   def sum
  802.     # Initialize local variable n
  803.     n = 0
  804.     # Sum Up Values in Array
  805.     each {|num| n += num}
  806.     # Return number
  807.     return n
  808.   end
  809. end
  810.  
  811. #==============================================================================
  812. # ** Ruby.Array.iterator
  813. #------------------------------------------------------------------------------
  814. # Description:
  815. # ------------
  816. # More Iterator Methods for the array class Iterator methods are methods that
  817. # iterate over an object Each of these methods require a block as an example
  818. #
  819. #  anArray.each {|iterators| <code>}
  820. #
  821. #  anArray.each do |iterators|
  822. #    code_to_execute
  823. #  end
  824. #
  825. #  anArray.each { |iterators|
  826. #    code_to_execute
  827. #  }
  828. #  
  829. #  
  830. # Method List:
  831. # ------------
  832. # each_nth_index
  833. # each_nth_index_with_index
  834. # each_ntuple
  835. # each_pair
  836. # each_triple
  837. # each_with_array
  838. # each_with_array_and_index
  839. # each_with_next
  840. # each_with_next_and_index
  841. #==============================================================================
  842.  
  843. MACL::Loaded << 'Ruby.Array.iterator'
  844.  
  845. #==============================================================================
  846. # ** Array    
  847. #==============================================================================
  848.  
  849. class Array
  850.   #-------------------------------------------------------------------------
  851.   #   Name      : Each Nth Index
  852.   #   Info      : An Iterator Method calls block for every nth in the
  853.   #               array of arrays
  854.   #   Author    : Trickster
  855.   #   Call Info : Integer index the index to iterate over, A Block
  856.   #-------------------------------------------------------------------------
  857.   def each_nth_index(index)
  858.     # Run Through Each Sub Array and return the value at index
  859.     each {|array| yield(array[index])}
  860.   end
  861.   #-------------------------------------------------------------------------
  862.   #   Name      : Each Nth Index with index
  863.   #   Info      : An Iterator Method calls block for every nth in the
  864.   #               array of arrays with index
  865.   #   Author    : Trickster
  866.   #   Call Info : Integer index the index to iterate over, A Block
  867.   #-------------------------------------------------------------------------
  868.   def each_nth_index_with_index(index)
  869.     # Run Through Each Sub Array and return the value at index
  870.     each_with_index {|array, i| yield(array[index], i)}
  871.   end
  872.   #-------------------------------------------------------------------------
  873.   #   Name      : Each N-tuple
  874.   #   Info      : An Iterator Method calls block for every tuple in the array
  875.   #   Author    : Trickster
  876.   #   Call Info : Number an Integer value for how many to iterate over, A Block
  877.   #-------------------------------------------------------------------------
  878.   def each_ntuple(number)
  879.     # Get Last Index (last index divisible by number)
  880.     end_num = size - size % number - 1
  881.     # Run Through each index 0, number, 2*number, ..., end_num
  882.     # and yield i, i+1, i+2, ... i + (number - 1)
  883.     0.step(end_num, number) {|i| yield(*self[i, number])}
  884.   end
  885.   #-------------------------------------------------------------------------
  886.   #   Name      : Each Pair
  887.   #   Info      : An Iterator Method calls block for every pair in the array
  888.   #   Author    : Trickster
  889.   #   Call Info : A Block
  890.   #-------------------------------------------------------------------------
  891.   def each_pair
  892.     # Get Last Index (last even numbered index)
  893.     end_num = size - size % 2 - 1
  894.     # Run Through each index 0, 2, 4, ..., end_num and yield i and i+1
  895.     0.step(end_num, 2) {|i| yield(*self[i,2])}
  896.   end
  897.   #-------------------------------------------------------------------------
  898.   #   Name      : Each Triple
  899.   #   Info      : An Iterator Method calls block for every triple in the array
  900.   #   Author    : Trickster
  901.   #   Call Info : A Block
  902.   #-------------------------------------------------------------------------
  903.   def each_triple
  904.     # Get Last Index (last index divisible by 3)
  905.     end_num = size - size % 3 - 1
  906.     # Run Through each index 0, 3, 6, ..., end_num and yield i, i+1, and i+2
  907.     0.step(end_num, 3) {|i| yield(*self[i,3])}
  908.   end
  909.   #-------------------------------------------------------------------------
  910.   #   Name      : Each With Array
  911.   #   Info      : An Iterator Method calls block for each object in both arrays
  912.   #   Author    : Trickster
  913.   #   Call Info : Variable Amount, Object obj objects to be iterated over. A Block
  914.   #-------------------------------------------------------------------------
  915.   def each_with_array(*array)
  916.     # Run Through Each Index and yield self at i and array at i
  917.     each_index {|i| yield(self[i], array[i])}
  918.   end
  919.   #-------------------------------------------------------------------------
  920.   #   Name      : Each With Array and Index
  921.   #   Info      : An Iterator Method calls block for each object in both arrays
  922.   #               with the index
  923.   #   Author    : Trickster
  924.   #   Call Info : Variable Amount, Object obj objects to be iterated over. A Block
  925.   #-------------------------------------------------------------------------
  926.   def each_with_array_and_index(*array)
  927.     # Run Through Each Index and yield self at i and array at i and index
  928.     each_index {|i| yield(self[i],array[i], i)}
  929.   end
  930.   #-------------------------------------------------------------------------
  931.   #   Name      : Each With Next
  932.   #   Info      : Runs Through with Next num elements
  933.   #   Author    : Trickster
  934.   #   Call Info : Integer num - next few elements to send as well
  935.   #               A Block
  936.   #-------------------------------------------------------------------------
  937.   def each_with_next(num = 1)
  938.     (size - num).times {|i| yield(*self[i..(i+num)])}
  939.   end
  940.   #-------------------------------------------------------------------------
  941.   #   Name      : Each With Next And Index
  942.   #   Info      : Runs Through with Next num elements with index
  943.   #   Author    : Trickster
  944.   #   Call Info : Integer num - next few elements to send as well
  945.   #               A Block
  946.   #-------------------------------------------------------------------------
  947.   def each_with_next_and_index(num = 1)
  948.     (size - num).times {|i| yield(*(self[i..(i+num)] << i))}
  949.   end
  950. end
  951.  
  952. #==============================================================================
  953. # ** Ruby.Array.list
  954. #------------------------------------------------------------------------------
  955. # Description:
  956. # ------------
  957. # Methods created that treats an array as a list.
  958. #  
  959. # Method List:
  960. # ------------
  961. # random
  962. # random!
  963. # rate
  964. # series_string
  965. # sort_by!
  966. # unsort
  967. #==============================================================================
  968.  
  969. MACL::Loaded << 'Ruby.Array.list'
  970.  
  971. #==============================================================================
  972. # ** Array    
  973. #==============================================================================
  974.  
  975. class Array
  976.   #-------------------------------------------------------------------------
  977.   #   Name      : Random
  978.   #   Info      : Returns a Random element in the array
  979.   #   Author    : SephirothSpawn
  980.   #   Call Info : No Arguments
  981.   #-------------------------------------------------------------------------
  982.   def random
  983.     return self[rand(size)]
  984.   end
  985.   #-------------------------------------------------------------------------
  986.   #   Name      : Random!
  987.   #   Info      : Returns and Deletes a Random element in the array
  988.   #   Author    : Trickster
  989.   #   Call Info : No Arguments
  990.   #-------------------------------------------------------------------------
  991.   def random!
  992.     return delete_at(rand(size))
  993.   end
  994.   #-------------------------------------------------------------------------
  995.   #   Name      : Rate
  996.   #   Info      : Rates all indexes from least(0) to greatest(size-1)
  997.   #   Author    : Trickster
  998.   #   Call Info : Zero or One Arguemtns Boolean Same (Defaults to true)
  999.   #              If same is true then rating increases for same values in the
  1000.   #              array
  1001.   #-------------------------------------------------------------------------
  1002.   def rate(same = true)
  1003.     # Create Rated Array
  1004.     rated = []
  1005.     # Create A Copy of the Array
  1006.     copy = self.dup
  1007.     # Initialize rate
  1008.     rate = 1
  1009.     # Run Through Size number of times
  1010.     size.times do
  1011.       # For each index where minimum is found
  1012.       copy.find_index(copy.compact.min).each do |index|
  1013.         # Set Rated at index to rating
  1014.         rated[index] = rate
  1015.         # Set Copy at index to nil
  1016.         copy[index] = nil
  1017.         # Increase Rating if false sent (increase for same)
  1018.         rate += 1 if !same
  1019.       end
  1020.       # Increase Rating if same is true (don't increase for same valued)
  1021.       rate += 1 if same
  1022.       # Break if no more non nil items
  1023.       break if copy.nitems == 0
  1024.     end
  1025.     # Return Rated Array
  1026.     return rated
  1027.   end
  1028.   #-------------------------------------------------------------------------
  1029.   # * Name      : Series String
  1030.   #   Info      : Returns a String with a list of the objects in the array
  1031.   #   Author    : Trickster
  1032.   #   Call Info : No Arguments
  1033.   #-------------------------------------------------------------------------
  1034.   def series_string
  1035.     # Setup String
  1036.     series = ''
  1037.     # If Size is 1
  1038.     if size == 1
  1039.       # Set Series to First
  1040.       series = self[0].to_s
  1041.     elsif size == 2
  1042.       # Set Battlers to battler and battler
  1043.       series = self[0].to_s + ' and ' + self[1].to_s
  1044.     else
  1045.       # Run Through Each Item with index
  1046.       each_with_index do |string, index|
  1047.         # Add String to Series
  1048.         series += string.to_s
  1049.         # Add , if not at last entry
  1050.         series += ', ' if index <= size - 2
  1051.         # Add and if at last entry
  1052.         series += 'and ' if index == size - 2
  1053.       end
  1054.     end
  1055.     return series
  1056.   end
  1057.   #-------------------------------------------------------------------------
  1058.   #   Name      : Sort By!
  1059.   #   Info      : Modifies Itself, Performs sort_by on the array
  1060.   #   Author    : Trickster
  1061.   #   Call Info : A Block
  1062.   #   Comment   : See Enumerable#sort_by
  1063.   #-------------------------------------------------------------------------
  1064.   def sort_by!(&block)
  1065.     # Duplicate Array
  1066.     saved = self.dup
  1067.     # Sort Array Call Block Sent
  1068.     sorted = sort_by {|object| block.call(object)}
  1069.     # Modify Original Array
  1070.     sorted.each_with_index {|item, index| self[index] = item}
  1071.     # If Changes Made Return self else nil
  1072.     return (saved == self ? nil : self)
  1073.   end
  1074.   #-------------------------------------------------------------------------
  1075.   # * Name      : self.unsort
  1076.   #   Info      : return a array of mixed elements
  1077.   #   Author    : Hanmac
  1078.   #   Call Info :  with min one Argument from type can this be everything
  1079.   #-------------------------------------------------------------------------
  1080.   def self.unsort(*arrays)
  1081.     array = arrays.flatten
  1082.     Array.new(array.size) {
  1083.       zufall = rand(array.size)
  1084.       array.delete_at(zufall)
  1085.     }
  1086.   end
  1087. end
  1088.  
  1089. #==============================================================================
  1090. # ** Ruby.Comparable/Enumerable
  1091. #------------------------------------------------------------------------------
  1092. # Description:
  1093. # ------------
  1094. # Miscellaneous New stuff for the Comparable/Enumerable module
  1095. #  
  1096. # Method List:
  1097. # ------------
  1098. #
  1099. #   Enumerable
  1100. #   ----------
  1101. #   unsort
  1102. #==============================================================================
  1103.  
  1104. MACL::Loaded << 'Ruby.Comparable/Enumerable'
  1105.  
  1106. #==============================================================================
  1107. # ** Enumerable
  1108. #==============================================================================
  1109.  
  1110. module Enumerable
  1111.   #-------------------------------------------------------------------------
  1112.   #   Name      : unsort
  1113.   #   Info      : return a array of mixed elements
  1114.   #   Author    : Hanmac
  1115.   #   Call Info : with no Arguments
  1116.   #   Comments  : can make nosense with strings
  1117.   #-------------------------------------------------------------------------
  1118.   def unsort
  1119.     Array.unsort(self.entries)
  1120.   end
  1121. end
  1122.  
  1123. #==============================================================================
  1124. # ** Ruby.Dir
  1125. #------------------------------------------------------------------------------
  1126. # Description:
  1127. # ------------
  1128. # Miscellaneous New stuff for the Dir class.
  1129. #  
  1130. # Method List:
  1131. # ------------
  1132. # make_dir
  1133. #==============================================================================
  1134.  
  1135. MACL::Loaded << 'Ruby.Dir'
  1136.  
  1137. #==============================================================================
  1138. # ** Dir    
  1139. #==============================================================================
  1140.  
  1141. class Dir
  1142.   #-------------------------------------------------------------------------
  1143.   # * Name      : Make Dir
  1144.   #   Info      : Creates Folder Dir
  1145.   #   Author    : ??? - http://www.66rpg.com/htm/news624.htm
  1146.   #   Call Info : One Arguments
  1147.   #               Path : Path to create directory
  1148.   #-------------------------------------------------------------------------
  1149.   def self.make_dir(path)
  1150.     dir = path.split("/")
  1151.     for i in 0...dir.size
  1152.       unless dir == "."
  1153.         add_dir = dir[0..i].join("/")
  1154.         begin
  1155.           Dir.mkdir(add_dir)
  1156.         rescue
  1157.         end
  1158.       end
  1159.     end
  1160.   end
  1161. end
  1162.  
  1163. #==============================================================================
  1164. # ** Ruby.Float
  1165. #------------------------------------------------------------------------------
  1166. # Description:
  1167. # ------------
  1168. # Miscellaneous New stuff for the Float class.
  1169. #  
  1170. # Method List:
  1171. # ------------
  1172. # float_points
  1173. #==============================================================================
  1174.  
  1175. MACL::Loaded << 'Ruby.Float'
  1176.  
  1177. #==============================================================================
  1178. # ** Float  
  1179. #==============================================================================
  1180.  
  1181. class Float
  1182.   #-------------------------------------------------------------------------
  1183.   #   Name      : Float Points
  1184.   #   Info      : Sets number of float points
  1185.   #   Author    : SephirothSpawn
  1186.   #   Call Info : One Argument, an Integer, number of float points
  1187.   #-------------------------------------------------------------------------
  1188.   def float_points(points = 2)
  1189.     # Gets Self
  1190.     n = self
  1191.     # Multiple N
  1192.     n *= 10 ** points
  1193.     # Converts N to Integer
  1194.     n = n.round.to_f
  1195.     # Divide back to float
  1196.     n /= 10.0 ** points
  1197.     # Return N
  1198.     return n
  1199.   end
  1200. end
  1201.  
  1202. #==============================================================================
  1203. # ** Ruby.Hash
  1204. #------------------------------------------------------------------------------
  1205. # Description:
  1206. # ------------
  1207. # Miscellaneous New stuff for the Hash class.
  1208. #  
  1209. # Method List:
  1210. # ------------
  1211. # contains_key?
  1212. # get_value
  1213. #==============================================================================
  1214.  
  1215. MACL::Loaded << 'Ruby.Hash'
  1216.  
  1217. #==============================================================================
  1218. # ** Hash    
  1219. #==============================================================================
  1220.  
  1221. class Hash
  1222.   #-------------------------------------------------------------------------
  1223.   #   Name      : Contains Key?
  1224.   #   Info      : Compares all Keys using == similiar to has_key?
  1225.   #   Author    : Trickster
  1226.   #   Call Info : One, Key an Object
  1227.   #-------------------------------------------------------------------------
  1228.   def contains_key?(key)
  1229.     # Run Through and Return true if keys are equal
  1230.     each_key {|other_key| return true if key == other_key}
  1231.     # Return false
  1232.     return false
  1233.   end
  1234.   #-------------------------------------------------------------------------
  1235.   #   Name      : Get Value
  1236.   #   Info      : Gets Value using == similiar to []
  1237.   #   Author    : Trickster
  1238.   #   Call Info : One, Key an Object
  1239.   #-------------------------------------------------------------------------
  1240.   def get_value(key)
  1241.     # Run Through and Return Key if equal
  1242.     each_key {|other_key| return self[other_key] if key == other_key}
  1243.     # If Default Proc is undefined return default else call proc
  1244.     return default_proc.nil? ? default : default_proc.call(self, key)
  1245.   end
  1246. end
  1247.  
  1248. #==============================================================================
  1249. # ** Ruby.Integer
  1250. #------------------------------------------------------------------------------
  1251. # Description:
  1252. # ------------
  1253. # Miscellaneous New stuff for the Integer class.
  1254. #  
  1255. # Method List:
  1256. # ------------
  1257. # factorial
  1258. # primorial
  1259. # multifactorial
  1260. #==============================================================================
  1261.  
  1262. MACL::Loaded << 'Ruby.Integer'
  1263.  
  1264. #==============================================================================
  1265. # ** Integer    
  1266. #==============================================================================
  1267.  
  1268. class Integer    
  1269.   #-------------------------------------------------------------------------
  1270.   #   Name      : Factorial
  1271.   #   Info      : Return the factorial of number
  1272.   #   Author    : Tibuda
  1273.   #   Call Info : No Arguments
  1274.   #-------------------------------------------------------------------------
  1275.   def factorial
  1276.     result = 1
  1277.     self.downto(2) {|i| result *= i }
  1278.     return result
  1279.   end            
  1280.   #-------------------------------------------------------------------------
  1281.   #   Name      : Primorial
  1282.   #   Info      : Return the primorial of number
  1283.   #   Author    : Tibuda
  1284.   #   Call Info : No Arguments
  1285.   #-------------------------------------------------------------------------
  1286.   def primorial
  1287.     result = 1
  1288.     self.downto(2) {|i| result *= i if i.is_prime? }
  1289.     return result
  1290.   end      
  1291.   #-------------------------------------------------------------------------
  1292.   #   Name      : Multifactorial
  1293.   #   Info      : Return the multifactorial of number
  1294.   #   Author    : Tibuda
  1295.   #   Call Info : No Arguments
  1296.   #-------------------------------------------------------------------------  
  1297.   def multifactorial(n = 2)
  1298.     result = self
  1299.     n.downto(1) {|i| result = result.factorial }
  1300.     return result
  1301.   end
  1302. end
  1303.  
  1304. #==============================================================================
  1305. # ** Ruby.Math
  1306. #------------------------------------------------------------------------------
  1307. # Description:
  1308. # ------------
  1309. # Miscellaneous new methods for the Math module
  1310. #  
  1311. # Method List:
  1312. # ------------
  1313. # A (Ackermann function)
  1314. # cw_between_angles?
  1315. # ccw_between_angles?
  1316. # cw_percent_between_angles
  1317. # ccw_percent_between_angles
  1318. #==============================================================================
  1319.  
  1320. MACL::Loaded << 'Ruby.Math'
  1321.  
  1322. module Math
  1323.   #-------------------------------------------------------------------------
  1324.   # * Name      : Ackermann function
  1325.   #   Info      : returns the Natural Number of an A(m,n) Integer
  1326.   #   Author    : Me(tm)
  1327.   #   Call Info : m as Integer, n as Integer, both 0 or positive.
  1328.   #-------------------------------------------------------------------------  
  1329.   def Math.A(m,n)
  1330.     raise ArgumentError.new('Ackermann: No negative values allowed.') if m < 0 or n < 0
  1331.     return n + 1 if m == 0
  1332.     return Math.A(m - 1, 1) if n == 0
  1333.     return Math.A(m - 1, Math.A(m, n - 1))
  1334.   end
  1335.   #-------------------------------------------------------------------------
  1336.   # * Name      : Angle Between Angles (Clockwise)
  1337.   #   Info      : Returns boolean of angle between 2 angles
  1338.   #   Author    : SephirothSpawn
  1339.   #   Call Info : Test Angle, Start Angle, End Angle
  1340.   #               Radians boolean (if true, converts to degrees)
  1341.   #-------------------------------------------------------------------------  
  1342.   def self.cw_between_angles?(ang, a1, a2, radians = false)
  1343.     # Convert from degrees to radians, if radians
  1344.     a1 *= 180 / PI if radians
  1345.     a2 *= 180 / PI if radians
  1346.     # Make Degrees between 0 - 360
  1347.     a1 %= 360 ; a2 %= 360
  1348.     # Make a1 Greater than a2
  1349.     a1 += 360 if a1 < a2
  1350.     # Returns Angle Between Angles
  1351.     return ang.between?(a2, 360) || ang.between?(0, a1 - 360) if a1 > 360
  1352.     return ang.between?(a2, a1)
  1353.   end
  1354.   #-------------------------------------------------------------------------
  1355.   # * Name      : Angle Between Angles (Counter-Clockwise)
  1356.   #   Info      : Returns boolean of angle between 2 angles
  1357.   #   Author    : SephirothSpawn
  1358.   #   Call Info : Test Angle, Start Angle, End Angle
  1359.   #               Radians boolean (if true, converts to degrees)
  1360.   #-------------------------------------------------------------------------  
  1361.   def self.ccw_between_angles?(ang, a1, a2, radians = false)
  1362.     # Convert from degrees to radians, if radians
  1363.     a1 *= 180 / PI if radians
  1364.     a2 *= 180 / PI if radians
  1365.     # Make Degrees between 0 - 360
  1366.     a1 %= 360 ; a2 %= 360
  1367.     # Make a2 Greater than a1
  1368.     a2 += 360 if a2 < a1
  1369.     # Returns Angle Between Angles
  1370.     return ang.between?(a1, 360) || ang.between?(0, a2 - 360) if a2 > 360
  1371.     return ang.between?(a1, a2)
  1372.   end
  1373.   #-------------------------------------------------------------------------
  1374.   # * Name      : Angle Percnt Between Angles (Clockwise)
  1375.   #   Info      : Returns boolean of angle between 2 angles
  1376.   #   Author    : SephirothSpawn
  1377.   #   Call Info : Test Angle, Start Angle, End Angle
  1378.   #               Radians boolean (if true, converts to degrees)
  1379.   #-------------------------------------------------------------------------  
  1380.   def self.cw_percent_between_angles(ang, a1, a2, radians = false)
  1381.     # Convert from degrees to radians, if radians
  1382.     a1 *= 180 / PI if radians
  1383.     a2 *= 180 / PI if radians
  1384.     # Make Degrees between 0 - 360
  1385.     a1 %= 360 ; a2 %= 360
  1386.     # Make aa Greater than a2
  1387.     a1 += 360 if a1 < a2
  1388.     # Gets Percent
  1389.     per = (ang - a2) / (a1 - a2).to_f
  1390.     # If Negative, and 360 to Angle
  1391.     per = (ang + 360 - a2) / (a1 - a2).to_f if per < 0
  1392.     # Return Percent
  1393.     return per
  1394.   end
  1395.   #-------------------------------------------------------------------------
  1396.   # * Name      : Angle Percent Between Angles (Counter-Clockwise)
  1397.   #   Info      : Returns boolean of angle between 2 angles
  1398.   #   Author    : SephirothSpawn
  1399.   #   Call Info : Test Angle, Start Angle, End Angle
  1400.   #               Radians boolean (if true, converts to degrees)
  1401.   #-------------------------------------------------------------------------  
  1402.   def self.ccw_percent_between_angles(ang, a1, a2, radians = false)
  1403.     # Convert from degrees to radians, if radians
  1404.     a1 *= 180 / PI if radians
  1405.     a2 *= 180 / PI if radians
  1406.     # Make Degrees between 0 - 360
  1407.     a1 %= 360 ; a2 %= 360
  1408.     # Make a2 Greater than a1
  1409.     a2 += 360 if a2 < a1
  1410.     # Gets Percent
  1411.     per = (ang - a1) / (a2 - a1).to_f
  1412.     # If Negative, and 360 to Angle
  1413.     per = (ang + 360 - a1) / (a2 - a1).to_f if per < 0
  1414.     # Return Percent
  1415.     return per
  1416.   end
  1417. end
  1418.  
  1419. #==============================================================================
  1420. # ** Ruby.Math.dist
  1421. #------------------------------------------------------------------------------
  1422. # Description:
  1423. # ------------
  1424. # This set allows the generation of discrete distributed random values.
  1425. #
  1426. # Class List:
  1427. # -----------
  1428. # Math::Uniform
  1429. # Math::Bernoulli
  1430. # Math::Binomial
  1431. # Math::Geometric
  1432. # Math::Poisson
  1433. #
  1434. # Method List: (avaiable for all classes)
  1435. # ------------
  1436. # initialize
  1437. # generate
  1438. # generate_array
  1439. # prob
  1440. #==============================================================================
  1441.  
  1442. MACL::Loaded << 'Ruby.Math.dist'
  1443.  
  1444. #==============================================================================
  1445. # ** Math    
  1446. #==============================================================================
  1447.  
  1448. module Math        
  1449.   #-------------------------------------------------------------------------
  1450.   # * Distribution precision (keep it high and float)
  1451.   #-------------------------------------------------------------------------
  1452.   Dist_precision = 1000.0
  1453.   #==============================================================================
  1454.   # ** Math::Uniform                                                 By: Tibuda
  1455.   #-----------------------------------------------------------------------------
  1456.   #  A class for generating unform distributed random values. It's used as a
  1457.   #  base for other distributions.                                          
  1458.   #-----------------------------------------------------------------------------  
  1459.   #  The discrete uniform distribution can be characterized by saying that all
  1460.   #  values of a finite set of possible values are equally probable.
  1461.   #==============================================================================
  1462.   class Uniform        
  1463.     #--------------------------------------------------------------------------
  1464.     # * Public Instance Variables
  1465.     #--------------------------------------------------------------------------
  1466.     attr_reader :min
  1467.     attr_reader :max
  1468.     #-------------------------------------------------------------------------
  1469.     # * Name      : Initialize
  1470.     #   Info      : Object Initialization
  1471.     #   Author    : Tibuda
  1472.     #   Call Info : Zero to Two
  1473.     #               Integer minumum value (default 0)
  1474.     #               Integer maximum value (default 1)
  1475.     #-------------------------------------------------------------------------
  1476.     def initialize(min = 0, max = 1)
  1477.       @min = min
  1478.       @max = max
  1479.       @max += @min if max < min
  1480.     end
  1481.     #-------------------------------------------------------------------------
  1482.     # * Name      : Generate
  1483.     #   Info      : Generates uniform distributed value
  1484.     #   Author    : Tibuda
  1485.     #   Call Info : No Arguments
  1486.     #-------------------------------------------------------------------------
  1487.     def generate
  1488.       return @min + rand(@max - @min)
  1489.     end
  1490.     def gen
  1491.       return generate
  1492.     end          
  1493.     #-------------------------------------------------------------------------
  1494.     # * Name      : Generate array
  1495.     #   Info      : Generates an array with uniform distributed values
  1496.     #   Author    : Tibuda
  1497.     #   Call Info : One
  1498.     #               Integer array size
  1499.     #-------------------------------------------------------------------------
  1500.     def generate_array(size)
  1501.       result = []
  1502.       for i in 0...size
  1503.         result << generate
  1504.       end
  1505.       return result
  1506.     end  
  1507.     def gen_array(size)
  1508.       return generate_array(size)
  1509.     end
  1510.     #-------------------------------------------------------------------------
  1511.     # * Name      : Probability mass function
  1512.     #   Info      : Returns the probability of observing a value
  1513.     #   Author    : Tibuda
  1514.     #   Call Info : One
  1515.     #               Integer tested value
  1516.     #-------------------------------------------------------------------------
  1517.     def prob(x)
  1518.       return (x < @min || x > @max) ? 0 : 1 / (@max - @min)
  1519.     end    
  1520.   end    
  1521.  
  1522.   #==============================================================================
  1523.   # ** Math::Bernoulli                                               By: Tibuda
  1524.   #-----------------------------------------------------------------------------  
  1525.   #  A class for generating Bernoulli distributed random values. It's used as a
  1526.   #  base class for binomial and geometric distributions.        
  1527.   #-----------------------------------------------------------------------------  
  1528.   #  Bernoulli trial is an experiment whose outcome is random and can be either
  1529.   #  of two possible outcomes, "success" and "failure". In practice it refers to
  1530.   #  a single experiment which can have one of two possible outcomes, like "yes
  1531.   #  or no" questions.
  1532.   #==============================================================================
  1533.   class Bernoulli < Uniform      
  1534.     #--------------------------------------------------------------------------
  1535.     # * Public Instance Variables
  1536.     #--------------------------------------------------------------------------
  1537.     attr_reader :p          
  1538.     attr_reader :success        
  1539.     attr_reader :failure          
  1540.     #-------------------------------------------------------------------------
  1541.     # * Name      : Initialize
  1542.     #   Info      : Object Initialization
  1543.     #   Author    : Tibuda
  1544.     #   Call Info : Zero to Three
  1545.     #               Float probability of success (default 0.5)
  1546.     #               Variant success return value (default 1)
  1547.     #               Variant failure return value (default 0)
  1548.     #-------------------------------------------------------------------------  
  1549.     def initialize(p = 0.5, success = 1, failure = 0)
  1550.       super(0, Dist_precision)
  1551.       @p = p
  1552.       @success = success
  1553.       @failure = failure
  1554.     end            
  1555.     #-------------------------------------------------------------------------
  1556.     # * Name      : Generate
  1557.     #   Info      : Generates Bernoulli distributed value
  1558.     #   Author    : Tibuda
  1559.     #   Call Info : No Arguments
  1560.     #-------------------------------------------------------------------------
  1561.     def generate
  1562.       return super.to_f / Dist_precision <= @p ? @success : @failure
  1563.     end  
  1564.     #-------------------------------------------------------------------------
  1565.     # * Name      : Probability mass function
  1566.     #   Info      : Returns the probability of observing a value
  1567.     #   Author    : Tibuda
  1568.     #   Call Info : One
  1569.     #               Integer tested value
  1570.     #-------------------------------------------------------------------------
  1571.     def prob(x)
  1572.       return @p if x == @success
  1573.       return 1 - @p if x == @failure
  1574.       return 0
  1575.     end    
  1576.   end
  1577.  
  1578.   #==============================================================================
  1579.   # ** Math::Binomial                                                By: Tibuda
  1580.   #-----------------------------------------------------------------------------    
  1581.   #  A class for generating binomial distributed random values.  
  1582.   #-----------------------------------------------------------------------------  
  1583.   #  The binomial distribution is the probability distribution of the number of
  1584.   #  "successes" in n independent Bernoulli trials, with the same probability of
  1585.   #  "success" on each trial.
  1586.   #==============================================================================
  1587.   class Binomial < Bernoulli              
  1588.     #--------------------------------------------------------------------------
  1589.     # * Public Instance Variables
  1590.     #--------------------------------------------------------------------------
  1591.     attr_reader :n                        
  1592.     #-------------------------------------------------------------------------
  1593.     # * Name      : Initialize
  1594.     #   Info      : Object Initialization
  1595.     #   Author    : Tibuda
  1596.     #   Call Info : Zero to Two
  1597.     #               Integer number of trials (default 1)
  1598.     #               Float probability of success (default 0.5)
  1599.     #-------------------------------------------------------------------------
  1600.     def initialize(n = 1, p = 0.5)
  1601.       super(p, 1, 0)
  1602.       @n = n
  1603.     end  
  1604.     #-------------------------------------------------------------------------
  1605.     # * Name      : Generate
  1606.     #   Info      : Generates binomial distributed value
  1607.     #   Author    : Tibuda
  1608.     #   Call Info : No Arguments
  1609.     #-------------------------------------------------------------------------
  1610.     def generate  
  1611.       result = 0
  1612.       for i in 0...@n
  1613.         result += super
  1614.       end
  1615.       return result
  1616.     end
  1617.     #-------------------------------------------------------------------------
  1618.     # * Name      : Probability mass function
  1619.     #   Info      : Returns the probability of observing a value
  1620.     #   Author    : Tibuda
  1621.     #   Call Info : One
  1622.     #               Integer tested value
  1623.     #-------------------------------------------------------------------------
  1624.     def prob(x)
  1625.       binomial_coef = @n.factorial / (x.factorial * (@n - x).factorial)
  1626.       return  binomial_coef * @p ** x * (1 - @p) ** (@n - x)
  1627.     end
  1628.   end
  1629.  
  1630.   #==============================================================================
  1631.   # ** Math::Geometric                                               By: Tibuda
  1632.   #-----------------------------------------------------------------------------    
  1633.   #  A class for generating geometric distributed random values.  
  1634.   #-----------------------------------------------------------------------------  
  1635.   #  The geometric distribution is the probability distribution of the number
  1636.   #  of Bernoulli trials needed to get one success.
  1637.   #==============================================================================
  1638.   class Geometric < Bernoulli  
  1639.     #-------------------------------------------------------------------------
  1640.     # * Name      : Initialize
  1641.     #   Info      : Object Initialization
  1642.     #   Author    : Tibuda
  1643.     #   Call Info : Zero to One
  1644.     #               Float probability of success (default 0.5)
  1645.     #-------------------------------------------------------------------------
  1646.     def initialize(p = 0.5)
  1647.       super(p, true, false)
  1648.     end        
  1649.     #-------------------------------------------------------------------------
  1650.     # * Name      : Generate
  1651.     #   Info      : Generates geometric distributed value
  1652.     #   Author    : Tibuda
  1653.     #   Call Info : No Arguments
  1654.     #-------------------------------------------------------------------------
  1655.     def generate
  1656.       k = 0
  1657.       while super == false
  1658.         k += 1
  1659.       end
  1660.       return k
  1661.     end        
  1662.     #-------------------------------------------------------------------------
  1663.     # * Name      : Probability mass function
  1664.     #   Info      : Returns the probability of observing a value
  1665.     #   Author    : Tibuda
  1666.     #   Call Info : One
  1667.     #               Integer tested value
  1668.     #-------------------------------------------------------------------------
  1669.     def prob(x)
  1670.       return @p * (1 - @p) ** x
  1671.     end
  1672.   end
  1673.  
  1674.   #==============================================================================
  1675.   # ** Math::Poisson                            By: Tibuda using Knuth algorithm
  1676.   #-----------------------------------------------------------------------------    
  1677.   #  A class for generating Poisson distributed random values.  
  1678.   #-----------------------------------------------------------------------------  
  1679.   #  The Poisson distribution expresses the probability of a number of events
  1680.   #  occurring in a fixed period of time if these events occur with a known
  1681.   #  average rate, and are independent of the time since the last event.
  1682.   #==============================================================================
  1683.   class Poisson < Uniform            
  1684.     #--------------------------------------------------------------------------
  1685.     # * Public Instance Variables
  1686.     #--------------------------------------------------------------------------
  1687.     attr_reader :lambda    
  1688.     #-------------------------------------------------------------------------
  1689.     # * Name      : Initialize
  1690.     #   Info      : Object Initialization
  1691.     #   Author    : Tibuda
  1692.     #   Call Info : One
  1693.     #               Float expected number of occurrences
  1694.     #-------------------------------------------------------------------------
  1695.     def initialize(lambda)    
  1696.       super(0, Dist_precision)
  1697.       @lambda = lambda
  1698.     end                
  1699.     #-------------------------------------------------------------------------
  1700.     # * Name      : Generate
  1701.     #   Info      : Generates Poisson distributed value
  1702.     #   Author    : Tibuda using Knuth algorithm
  1703.     #   Call Info : No Arguments
  1704.     #-------------------------------------------------------------------------
  1705.     def generate
  1706.       k = 0
  1707.       p = 1.0
  1708.       while p >= Math.exp(-@lambda)
  1709.         k += 1
  1710.         p *= super.to_f / Dist_precision
  1711.       end
  1712.       return k - 1
  1713.     end      
  1714.     #-------------------------------------------------------------------------
  1715.     # * Name      : Probability mass function
  1716.     #   Info      : Returns the probability of observing a value
  1717.     #   Author    : Tibuda
  1718.     #   Call Info : One
  1719.     #               Integer tested value
  1720.     #-------------------------------------------------------------------------
  1721.     def prob(x)
  1722.       return Math.exp(-@lambda) * @lambda ** x / x.factorial
  1723.     end
  1724.   end
  1725. end
  1726.  
  1727. #==============================================================================
  1728. # ** Ruby.Numeric
  1729. #------------------------------------------------------------------------------
  1730. # Description:
  1731. # ------------
  1732. # Miscellaneous New stuff for the Numeric class.
  1733. #  
  1734. # Method List:
  1735. # ------------
  1736. # is_prime?
  1737. # linear?
  1738. # sign
  1739. #==============================================================================
  1740.  
  1741. MACL::Loaded << 'Ruby.Numeric'
  1742.  
  1743. #==============================================================================
  1744. # ** Numeric    
  1745. #==============================================================================
  1746.  
  1747. class Numeric
  1748.   #-------------------------------------------------------------------------
  1749.   #   Name      : Is Prime?
  1750.   #   Info      : Checks if a number is prime or not
  1751.   #   Author    : Lobosque/Trickster
  1752.   #   Call Info : No Arguments
  1753.   #-------------------------------------------------------------------------
  1754.   def is_prime?
  1755.     # Not Prime if 0 or one or even
  1756.     return false if [0,1].include?(self) or self % 2 == 0
  1757.     # Initialize Check Variable
  1758.     check = 3
  1759.     # While Check is less than self
  1760.     while check < Math.sqrt(self)
  1761.       # Return false if divisible
  1762.       return false if self % check == 0
  1763.       # Increase By 2 (Odd numbers only)
  1764.       check += 2
  1765.     end
  1766.     # Is Prime
  1767.     return true
  1768.   end
  1769.   #-------------------------------------------------------------------------
  1770.   # * Name      : Linear?
  1771.   #   Info      : Tests if Num falls in a + bx
  1772.   #   Author    : Trickster
  1773.   #   Call Info : Two or Three Arguments Integer A and B
  1774.   #               Boolean Neg X allow for negative x
  1775.   #-------------------------------------------------------------------------
  1776.   def linear?(a, b, negx = true)
  1777.     n = self
  1778.     return (b == 0 && n == a) || ((n >= a || negx) && (n - a) % b == 0)
  1779.   end
  1780.   #-------------------------------------------------------------------------
  1781.   #   Name      : Sign
  1782.   #   Info      : Returns the Sign of the number (0 if 0 1 if + -1 if -)
  1783.   #   Author    : Trickster
  1784.   #   Call Info : No Arguments
  1785.   #-------------------------------------------------------------------------
  1786.   def sign
  1787.     return zero? ? 0 : (self / self.abs).to_i
  1788.   end
  1789. end
  1790.  
  1791. #==============================================================================
  1792. # ** Ruby.Range
  1793. #------------------------------------------------------------------------------
  1794. # Description:
  1795. # ------------
  1796. # Methods created for finding and returning objects inside of an array.
  1797. #  
  1798. # Method List:
  1799. # ------------
  1800. # random
  1801. # <=>
  1802. #==============================================================================
  1803.  
  1804. MACL::Loaded << 'Ruby.Range'
  1805.  
  1806. #==============================================================================
  1807. # ** Range    
  1808. #==============================================================================
  1809.  
  1810. class Range
  1811.   #--------------------------------------------------------------------------
  1812.   # * Include Comparable
  1813.   #--------------------------------------------------------------------------
  1814.   include(Comparable)
  1815.   #--------------------------------------------------------------------------
  1816.   # * Name      : Random
  1817.   #   Info      : Returns random object in array
  1818.   #   Author    : SephirothSpawn
  1819.   #   Call Info : Nil
  1820.   #--------------------------------------------------------------------------
  1821.   def random
  1822.     return self.to_a.random
  1823.   end
  1824.   #--------------------------------------------------------------------------
  1825.   # * Name      : <=>
  1826.   #   Info      : Compares ranges
  1827.   #   Author    : hanmac
  1828.   #   Call Info : One Argument, Other range
  1829.   #--------------------------------------------------------------------------
  1830.   def <=>(other)
  1831.     temp = first <=> other.first
  1832.     temp = last <=> other.last if temp = 0
  1833.     return temp
  1834.   end
  1835. end
  1836.  
  1837. #==============================================================================
  1838. # ** Ruby.String
  1839. #------------------------------------------------------------------------------
  1840. # Description:
  1841. # ------------
  1842. # Miscellaneous New stuff for the String class.
  1843. #  
  1844. # Method List:
  1845. # ------------
  1846. # clear
  1847. # get_int
  1848. # get_ints
  1849. # seph_encrypt
  1850. # seph_encrypt!
  1851. # seph_decrypt
  1852. # seph_decrypt!
  1853. # to_filename
  1854. # to_filename!
  1855. #==============================================================================
  1856.  
  1857. MACL::Loaded << 'Ruby.String'
  1858.  
  1859. #==============================================================================
  1860. # ** String    
  1861. #==============================================================================
  1862.  
  1863. class String
  1864.   #-------------------------------------------------------------------------
  1865.   # * Name      : Clear
  1866.   #   Info      : Removes string characters and returns self
  1867.   #   Author    : SephirothSpawn
  1868.   #   Call Info : No Arguments
  1869.   #-------------------------------------------------------------------------
  1870.   def clear
  1871.     slice!(0, self.size)
  1872.   end
  1873.   #-------------------------------------------------------------------------
  1874.   # * Name      : Get Integer
  1875.   #   Info      : Gets the Integer from String
  1876.   #   Author    : Trickster
  1877.   #   Call Info : No Arguments
  1878.   #-------------------------------------------------------------------------
  1879.   def get_int
  1880.     m = self.gsub(/\D/,'')
  1881.     return m.to_i
  1882.   end
  1883.   #-------------------------------------------------------------------------
  1884.   # * Name      : Get Integers
  1885.   #   Info      : Gets all Integers from String
  1886.   #   Author    : Trickster
  1887.   #   Call Info : No Arguments
  1888.   #-------------------------------------------------------------------------
  1889.   def get_ints
  1890.     array = self.split(/\D/)
  1891.     array.collect! {|item| item.to_i}
  1892.     return array
  1893.   end
  1894.   #-------------------------------------------------------------------------
  1895.   # * Name      : Seph Encrypt
  1896.   #   Info      : Returns an encrypted version of a string with a keyword
  1897.   #   Author    : SephirothSpawn
  1898.   #   Call Info : Encryption Word String
  1899.   #-------------------------------------------------------------------------
  1900.   def seph_encrypt(encryption_string = 'encrypt')
  1901.     # Collects Encryption String Bytes
  1902.     encryption_bytes = []
  1903.     encryption_string.each_byte {|c| encryption_bytes << c}
  1904.     # Creates New String
  1905.     string = ''
  1906.     # Pass Through Self
  1907.     for i in 0...self.size
  1908.       # Gets Encrypted Byte
  1909.       byte = self[i] * encryption_bytes[i % encryption_bytes.size]
  1910.       # Gets Base & Mod Value
  1911.       base, mod = byte / 255, byte % 255
  1912.       # Adds Encrypted Character
  1913.       string += base.chr + mod.chr
  1914.     end
  1915.     # Returns Encryption String
  1916.     return string
  1917.   end
  1918.   #-------------------------------------------------------------------------
  1919.   # * Name      : Seph Encrypt!
  1920.   #   Info      : Encrypts self with a keyword. Returns modified self.
  1921.   #   Author    : SephirothSpawn
  1922.   #   Call Info : Encryption Word String
  1923.   #-------------------------------------------------------------------------
  1924.   def seph_encrypt!(encryption_string = 'encrypt')
  1925.     # Gets Encryption String
  1926.     encrypted_string = seph_encrypt(encryption_string)
  1927.     # Clears self
  1928.     clear
  1929.     # Makes self encrypted string
  1930.     self.concat(encrypted_string)
  1931.     # Returns Decrypted String
  1932.     return self
  1933.   end
  1934.   #-------------------------------------------------------------------------
  1935.   # * Name      : Seph Decrypt
  1936.   #   Info      : Returns an decrypted version of a string with a keyword
  1937.   #   Author    : SephirothSpawn
  1938.   #   Call Info : Encryption Word String
  1939.   #-------------------------------------------------------------------------
  1940.   def seph_decrypt(encryption_string = 'encrypt')
  1941.     # Collects Encryption String Bytes
  1942.     encryption_bytes = []
  1943.     encryption_string.each_byte {|c| encryption_bytes << c}
  1944.     # Creates New String
  1945.     string = ''
  1946.     # Pass Through Self
  1947.     for i in 0...(self.size / 2)
  1948.       # Gets Base & Mod Value
  1949.       b, m = self[i * 2] * 255, self[i * 2 + 1]
  1950.       # Gets New Character
  1951.       string += ((b + m) / encryption_bytes[i % encryption_bytes.size]).chr
  1952.     end
  1953.     # Returns Decrypted String
  1954.     return string
  1955.   end
  1956.   #-------------------------------------------------------------------------
  1957.   # * Name      : Seph Decrypt
  1958.   #   Info      : Decrypts a string with keyword. Returns modified self.
  1959.   #   Author    : SephirothSpawn
  1960.   #   Call Info : Encryption Word String
  1961.   #-------------------------------------------------------------------------
  1962.   def seph_decrypt!(encryption_string = 'encrypt')
  1963.     # Gets Decrypted String
  1964.     decrypted_string = seph_decrypt(encryption_string)
  1965.     # Clears self
  1966.     clear
  1967.     # Makes self encrypted string
  1968.     self.concat(decrypted_string)
  1969.     # Returns Decrypted String
  1970.     return self
  1971.   end
  1972.   #-------------------------------------------------------------------------
  1973.   # * Name      : To Filename
  1974.   #   Info      : Converts the string to a filename
  1975.   #   Author    : Trickster
  1976.   #   Call Info : No Arguments
  1977.   #-------------------------------------------------------------------------
  1978.   def to_filename
  1979.     string = self.clone
  1980.     string.downcase!
  1981.     string.gsub!(/\s/,'_')
  1982.     return string
  1983.   end
  1984.   #-------------------------------------------------------------------------
  1985.   # * Name      : To Filename!
  1986.   #   Info      : Modifies Itself Converts the string to a filename
  1987.   #   Author    : Trickster
  1988.   #   Call Info : No Arguments
  1989.   #-------------------------------------------------------------------------
  1990.   def to_filename!
  1991.     string = self.clone
  1992.     self.downcase!
  1993.     self.gsub!(/\s/,'_')
  1994.     return string == self ? nil : self
  1995.   end
  1996. end
  1997.  
  1998. #==============================================================================
  1999. # ** RGSS.Action Test
  2000. #------------------------------------------------------------------------------
  2001. # Description:
  2002. # ------------
  2003. # These Set of Methods test the type of action created by a player/enemy in
  2004. # battle. If you are adding new commands based on Attack, Skill, Item, Defend,
  2005. # or Escape then see the constants related to this set in the MACL Setup section.
  2006. #  
  2007. # Method List:
  2008. # ------------
  2009. #
  2010. #   Game_Battler
  2011. #   -----------------
  2012. #   action?
  2013. #  
  2014. #   Game_BattleAction
  2015. #   -----------------
  2016. #   is_a_skill?
  2017. #   is_a_attack?
  2018. #   is_a_item?
  2019. #   is_a_defend?
  2020. #   is_a_escape?
  2021. #   is_a_wait?
  2022. #==============================================================================
  2023.  
  2024. MACL::Loaded << 'RGSS.Action Test'
  2025.  
  2026. #==============================================================================
  2027. # ** Game_Battler
  2028. #==============================================================================
  2029.  
  2030. class Game_Battler
  2031.   #-------------------------------------------------------------------------
  2032.   #   Name      : Action?
  2033.   #   Info      : Is Action of kind, basic, skill id, and item id
  2034.   #   Author    : Trickster
  2035.   #   Call Info : Integer kind, basic, skill id, and item id
  2036.   #-------------------------------------------------------------------------
  2037.   def action?(kind, basic, skill_id = 0, item_id = 0)
  2038.     return (@current_action.kind == kind && @current_action.basic == basic &&
  2039.     (@current_action.skill_id == skill_id || skill_id == 0) &&
  2040.     (@current_action.item_id == item_id || item_id == 0))
  2041.   end
  2042. end
  2043.  
  2044. #==============================================================================
  2045. # ** Game_BattleAction
  2046. #==============================================================================
  2047.  
  2048. class Game_BattleAction
  2049.   #-------------------------------------------------------------------------
  2050.   #   Name      : Is a Skill?
  2051.   #   Info      : Is Action a Skill (That is, if skill id is not zero
  2052.   #               Or if the action's kind is included in skill using)
  2053.   #   Author    : Trickster
  2054.   #   Call Info : No Arguments
  2055.   #-------------------------------------------------------------------------
  2056.   def is_a_skill?
  2057.     return (@skill_id != 0) && SKILL_USING.include?(@kind)
  2058.   end
  2059.   #-------------------------------------------------------------------------
  2060.   #   Name      : Is a Attack?
  2061.   #   Info      : Is Action an Attack (That is, if kind is zero and
  2062.   #               if the action's basic is zero or included in attack using)
  2063.   #   Author    : Trickster
  2064.   #   Call Info : No Arguments
  2065.   #-------------------------------------------------------------------------
  2066.   def is_a_attack?
  2067.     return (@kind == 0) && ((@basic == 0) || ATTACK_USING.include?(@basic))
  2068.   end
  2069.   #-------------------------------------------------------------------------
  2070.   #   Name      : Is a Item?
  2071.   #   Info      : Is Action a Item (That is, if item id is not zero
  2072.   #               Or if the action's kind is included in item using)
  2073.   #   Author    : Trickster
  2074.   #   Call Info : No Arguments
  2075.   #-------------------------------------------------------------------------
  2076.   def is_a_item?
  2077.     return ITEM_USING.include?(@kind) && (@item_id != 0)
  2078.   end
  2079.   #-------------------------------------------------------------------------
  2080.   #   Name      : Is a Defend?
  2081.   #   Info      : Is Action a Defend (That is, if basic is one
  2082.   #               Or if the action's basic is included in defend using and
  2083.   #               the kind is 0)
  2084.   #   Author    : Trickster
  2085.   #   Call Info : No Arguments
  2086.   #-------------------------------------------------------------------------
  2087.   def is_a_defend?
  2088.     return (@kind == 0) && (DEFEND_USING.include?(@basic) || (@basic == 1))
  2089.   end
  2090.   #-------------------------------------------------------------------------
  2091.   #   Name      : Is a Wait?
  2092.   #   Info      : Is Action a wait like command (That is, if basic is three
  2093.   #               Or if the action's basic is included in wait using and the
  2094.   #               kind is 0)
  2095.   #   Author    : Trickster
  2096.   #   Call Info : No Arguments
  2097.   #-------------------------------------------------------------------------
  2098.   def is_a_wait?
  2099.     return (@kind == 0) && (WAIT_USING.include?(@basic) || @basic == 3)
  2100.   end
  2101.   #-------------------------------------------------------------------------
  2102.   #   Name      : Is a Escape?
  2103.   #   Info      : Is Action a Escape like command (That is, if basic is two
  2104.   #               Or if the action's basic is included in the escape using and
  2105.   #               the kind is 0)
  2106.   #   Author    : Trickster
  2107.   #   Call Info : No Arguments
  2108.   #-------------------------------------------------------------------------
  2109.   def is_a_escape?
  2110.     return (@kind == 0) && (ESCAPE_USING.include?(@basic) || @basic == 2)
  2111.   end
  2112. end
  2113.  
  2114. #==============================================================================
  2115. # ** RGSS.Actor and Party Info
  2116. #------------------------------------------------------------------------------
  2117. # Description:
  2118. # ------------
  2119. # These set of methods add observer methods to the Game_Actor and Game_Party
  2120. # classes, you can get information on how weak an enemy is to a state, all
  2121. # of the enemies resistances and weaknesses, etc.
  2122. #  
  2123. # Method List:
  2124. # ------------
  2125. #
  2126. #   Game_Battler
  2127. #   ------------
  2128. #   hp_percent
  2129. #   sp_percent
  2130. #
  2131. #   Game_Actor
  2132. #   ----------
  2133. #   element_effectiveness
  2134. #   state_effectiveness
  2135. #   now_exp
  2136. #   next_exp
  2137. #   weapon_ids
  2138. #   armor_ids
  2139. #   equipment
  2140. #   element_test
  2141. #   weaknesses
  2142. #   resistance
  2143. #   next_exp_percent
  2144. #  
  2145. #   Game_Party
  2146. #   ----------
  2147. #   equipped_weapon?
  2148. #   equipped_armor?
  2149. #   has_actors?
  2150. #   strongest
  2151. #   weakest
  2152. #   existing_actors
  2153. #   average_level
  2154. #==============================================================================
  2155.  
  2156. MACL::Loaded << 'RGSS.Actor and Party Info'
  2157.  
  2158. #==============================================================================
  2159. # ** Game_Battler
  2160. #==============================================================================
  2161.  
  2162. class Game_Battler
  2163.   #-------------------------------------------------------------------------
  2164.   # * Name      : Hp Percent
  2165.   #   Info      : Returns HP Percent
  2166.   #   Author    : SephirothSpawn
  2167.   #   Call Info : Two Arguments
  2168.   #               Integer truth, true for integer, false for float
  2169.   #               Float points, integer value for number of float points
  2170.   #-------------------------------------------------------------------------
  2171.   def hp_percent(integer = false, float_points = 2)
  2172.     # Gets Float Percent
  2173.     n = (self.hp / self.maxhp.to_f * 100.0)
  2174.     # Return Percent
  2175.     return integer ? Integer(n) : n.float_points(float_points)
  2176.   end
  2177.   #-------------------------------------------------------------------------
  2178.   # * Name      : Sp Percent
  2179.   #   Info      : Returns SP Percent
  2180.   #   Author    : SephirothSpawn
  2181.   #   Call Info : Two Arguments
  2182.   #               Integer truth, true for integer, false for float
  2183.   #               Float points, integer value for number of float points
  2184.   #-------------------------------------------------------------------------
  2185.   def sp_percent(integer = false, float_points = 2)
  2186.     # Gets Float Percent
  2187.     n = (self.sp / self.maxsp.to_f * 100.0)
  2188.     # Return Percent
  2189.     return integer ? Integer(n) : n.float_points(float_points)
  2190.   end
  2191. end
  2192.  
  2193. #==============================================================================
  2194. # ** Game_Actor
  2195. #==============================================================================
  2196.  
  2197. class Game_Actor
  2198.   #-------------------------------------------------------------------------
  2199.   #   Name      : Element Effectiveness
  2200.   #   Info      : How Effective Enemy is against an Element
  2201.   #               An Integer from 0-5 (5: most effective 0: not effective at all)
  2202.   #   Author    : Trickster
  2203.   #   Call Info : Integer Element_ID id of the element to check
  2204.   #-------------------------------------------------------------------------
  2205.   def element_effectiveness(element_id)
  2206.     # Get a numerical value corresponding to element effectiveness
  2207.     table = [0,5,4,3,2,1,0]
  2208.     effective = table[$data_classes[@class_id].element_ranks[element_id]]
  2209.     # If protected by state, this element is reduced by half
  2210.     for i in @states
  2211.       if $data_states[i].guard_element_set.include?(element_id)
  2212.         effective = (effective / 2.0).ceil
  2213.       end
  2214.     end
  2215.     # End Method
  2216.     return effective
  2217.   end
  2218.   #-------------------------------------------------------------------------
  2219.   #   Name      : State Effectiveness
  2220.   #   Info      : How Effective Enemy is against a State
  2221.   #               An Integer from 0-5 (5: most effective 0: ineffective)
  2222.   #   Author    : Trickster
  2223.   #   Call Info : Integer State_ID id of the state to check
  2224.   #-------------------------------------------------------------------------
  2225.   def state_effectiveness(state_id)
  2226.     table = [0,5,4,3,2,1,0]
  2227.     effective = table[$data_enemies[@enemy_id].state_ranks[state_id]]
  2228.     return effective
  2229.   end
  2230.   #-------------------------------------------------------------------------
  2231.   # * Name      : Now Exp
  2232.   #   Info      : Gets Actors Next in Current Level
  2233.   #   Author    : Near Fantastica
  2234.   #   Call Info : No Arguments
  2235.   #-------------------------------------------------------------------------
  2236.   def now_exp
  2237.     return @exp - @exp_list[@level]
  2238.   end
  2239.   #-------------------------------------------------------------------------
  2240.   # * Name      : Next Exp
  2241.   #   Info      : Gets Actors Exp for Next Level
  2242.   #   Author    : Near Fantastica
  2243.   #   Call Info : No Arguments
  2244.   #-------------------------------------------------------------------------
  2245.   def next_exp
  2246.     exp = @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
  2247.     return exp
  2248.   end
  2249.   #-------------------------------------------------------------------------
  2250.   # * Name      : Weapon Ids
  2251.   #   Info      : Gets ALL Weapon IDs - An Array of Weapon Ids
  2252.   #   Author    : Trickster
  2253.   #   Call Info : No Arguments
  2254.   #   Comment   : Detects @weapon_id and @weapon(n)_id n >= 2
  2255.   #-------------------------------------------------------------------------
  2256.   def weapon_ids
  2257.     equipment = []
  2258.     equipment << @weapon_id
  2259.     i = 2
  2260.     while instance_eval("@weapon#{i}_id") != nil
  2261.       equipment << instance_eval("@weapon#{i}_id")
  2262.       i += 1
  2263.     end
  2264.     return equipment
  2265.   end
  2266.   #-------------------------------------------------------------------------
  2267.   # * Name      : Armor Ids
  2268.   #   Info      : Gets All Armor IDs - An Array of Armor Ids
  2269.   #   Author    : Trickster
  2270.   #   Call Info : No Arguments
  2271.   #   Comment   : Detects @armor(n)_id
  2272.   #-------------------------------------------------------------------------
  2273.   def armor_ids
  2274.     equipment = []
  2275.     i = 1
  2276.     while instance_eval("@armor#{i}_id") != nil
  2277.       equipment << instance_eval("@armor#{i}_id")
  2278.       i += 1
  2279.     end
  2280.     return equipment
  2281.   end
  2282.   #-------------------------------------------------------------------------
  2283.   #   Name      : Get Equipment
  2284.   #   Info      : Gets All Actor's Equipment
  2285.   #               A Hash in this form {'weapons' => ids, 'armors' => ids}
  2286.   #   Author    : Trickster
  2287.   #   Call Info : No Arguments
  2288.   #   Comment   : Must Follow Naming Conventions weapon#{n}_id armor#{n}_id
  2289.   #-------------------------------------------------------------------------
  2290.   def equipment
  2291.     @equipment = {'weapons' => [], 'armors' => []}
  2292.     @equipment['weapons'].push(@weapon_id)
  2293.     i = 1
  2294.     while instance_eval("@weapon#{i}_id") != nil
  2295.       @equipment['weapons'].push(instance_eval("@weapon#{i}_id"))
  2296.       i += 1
  2297.     end
  2298.     i = 1
  2299.     while instance_eval("@armor#{i}_id") != nil
  2300.       @equipment['armors'].push(instance_eval("@armor#{i}_id"))
  2301.       i += 1
  2302.     end
  2303.     return @equipment
  2304.   end
  2305.   #-------------------------------------------------------------------------
  2306.   # * Name      : Element Test
  2307.   #   Info      : Returns Element Effiency Value
  2308.   #               An Integer 1-6 representing the effiency
  2309.   #   Author    : Trickster
  2310.   #   Call Info : One Argument Element_Id the element Id to test
  2311.   #-------------------------------------------------------------------------
  2312.   def element_test(element_id)
  2313.     # Get a numerical value corresponding to element effectiveness
  2314.     table = [0,6,5,4,3,2,1]
  2315.     result = table[$data_classes[@class_id].element_ranks[element_id]]
  2316.     return result
  2317.   end
  2318.   #-------------------------------------------------------------------------
  2319.   # * Name      : Weaknesses
  2320.   #   Info      : Returns Enemy Weaknesses
  2321.   #               An Array of Element Ids for which an A or B effiency
  2322.   #   Author    : Trickster
  2323.   #   Call Info : None
  2324.   #-------------------------------------------------------------------------
  2325.   def weaknesses
  2326.     weak = []
  2327.     MACL::Real_Elements.each {|i| weak << i if [6,5].include?(element_test(i))}
  2328.     return weak
  2329.   end
  2330.   #-------------------------------------------------------------------------
  2331.   # * Name      : Resistance
  2332.   #   Info      : Returns Enemy Resistance
  2333.   #               An Array of Element Ids for which an D, E, or F effiency
  2334.   #   Author    : Trickster
  2335.   #   Call Info : None
  2336.   #-------------------------------------------------------------------------
  2337.   def resistance
  2338.     resists = []
  2339.     MACL::Real_Elements.each {|i| resists << i if [1,2,3].include?(element_test(i))}
  2340.     return resists
  2341.   end
  2342.   #-------------------------------------------------------------------------
  2343.   # * Name      : Next Exp Percent
  2344.   #   Info      : Returns Exp Percent
  2345.   #   Author    : SephirothSpawn
  2346.   #   Call Info : Two Arguments
  2347.   #               Integer truth, true for integer, false for float
  2348.   #               Float points, integer value for number of float points
  2349.   #-------------------------------------------------------------------------
  2350.   def next_exp_percent(integer = false, float_points = 2)
  2351.     lst = @exp_list[@level] > 0     ? @exp_list[@level]     : 0
  2352.     nxt = @exp_list[@level + 1] > 0 ? @exp_list[@level + 1] : 0
  2353.     rst = nxt - @exp
  2354.     begin
  2355.       n = 100 - (rst.to_f / (nxt - lst) * 100)
  2356.       return integer ? Integer(n) : n.float_points(float_points)
  2357.     rescue
  2358.       return 100
  2359.     end
  2360.   end
  2361. end
  2362.  
  2363. #==============================================================================
  2364. # ** Game_Party
  2365. #==============================================================================
  2366.  
  2367. class Game_Party
  2368.   #-------------------------------------------------------------------------
  2369.   # * Name      : Equipped Weapon?
  2370.   #   Info      : Does Someone in the party have Weapon Equipped
  2371.   #               returns true if condition fulfilled false otherwise
  2372.   #   Author    : Trickster
  2373.   #   Call Info : One Argument - Integer Weapon Id
  2374.   #-------------------------------------------------------------------------
  2375.   def equipped_weapon?(weapon_id)
  2376.     # Run through each actor and return if if weapon equipped
  2377.     @actors.each {|actor| return true if actor.weapon_ids.include?(weapon_id)}
  2378.     # Don't have it equipped
  2379.     return false
  2380.   end
  2381.   #-------------------------------------------------------------------------
  2382.   # * Name      : Equipped Armor?
  2383.   #   Info      : Does Soeme in the party have Armor Eqipped
  2384.   #               returns true if condition fulfilled false otherwise
  2385.   #   Author    : Trickster
  2386.   #   Call Info : One Argument - Integer Armor Id
  2387.   #-------------------------------------------------------------------------
  2388.   def equipped_armor?(armor_id)
  2389.     # Run through each actor and return if if weapon equipped
  2390.     @actors.each {|actor| return true if actor.armor_ids.include?(armor_id)}
  2391.     # Don't have it equipped
  2392.     return false
  2393.   end
  2394.   #-------------------------------------------------------------------------
  2395.   # * Name      : Has Actors?
  2396.   #   Info      : Are These Actor Ids in party?
  2397.   #               returns true if those actors are in the party
  2398.   #   Author    : Trickster
  2399.   #   Call Info : Variable Amount Integer Actor actor id to check
  2400.   #-------------------------------------------------------------------------
  2401.   def has_actors?(*actors)
  2402.     # Setup Array
  2403.     actor_ids = []
  2404.     # Get All Actor IDs
  2405.     @actors.each {|actor| actor_ids << actor.id}
  2406.     # If All Actors included
  2407.     return actor_ids.includes?(*actors)
  2408.   end
  2409.   #-------------------------------------------------------------------------
  2410.   #   Name      : Strongest Actor in Party
  2411.   #   Info      : Gets Strongest Actor
  2412.   #   Author    : Trickster
  2413.   #   Call Info : No Arguments
  2414.   #-------------------------------------------------------------------------
  2415.   def strongest
  2416.     array = actors.dup
  2417.     array.sort! {|a,b| b.hp - a.hp}
  2418.     return array[0]
  2419.   end
  2420.   #-------------------------------------------------------------------------
  2421.   #   Name      : Weakest Actor in Party
  2422.   #   Info      : Gets Weakest Actor
  2423.   #   Author    : Trickster
  2424.   #   Call Info : No Arguments
  2425.   #-------------------------------------------------------------------------
  2426.   def weakest
  2427.     array = existing_actors
  2428.     array.sort! {|a,b| b.hp - a.hp}
  2429.     return array[-1]
  2430.   end
  2431.   #-------------------------------------------------------------------------
  2432.   #   Name      : Get Existing Actors
  2433.   #   Info      : Gets All Non-Dead Actors
  2434.   #   Author    : Trickster
  2435.   #   Call Info : No Arguments
  2436.   #-------------------------------------------------------------------------
  2437.   def existing_actors
  2438.     array = []
  2439.     @actors.each {|actor| array << actor if actor.exist?}
  2440.     return array
  2441.   end
  2442.   #-------------------------------------------------------------------------
  2443.   # * Name      : Average Level
  2444.   #   Info      : Returns the Average Level of Party
  2445.   #   Author    : Trickster
  2446.   #   Call Info : None
  2447.   #-------------------------------------------------------------------------
  2448.   def average_level
  2449.     # Return 0 If 0 members are in the party
  2450.     return 0 if @actors.size == 0
  2451.     # Initialize local variable sum
  2452.     sum = 0
  2453.     # Sum Up Values in Array
  2454.     @actors.each {|actor| sum += actor.level}
  2455.     # Return Average
  2456.     return sum / @actors.size
  2457.   end
  2458. end
  2459.  
  2460. #==============================================================================
  2461. # ** RGSS.Battle
  2462. #------------------------------------------------------------------------------
  2463. # Description:
  2464. # ------------
  2465. # These set of methods specialized in the Spriteset & Scene for battle.
  2466. #  
  2467. # Method List:
  2468. # ------------
  2469. #
  2470. #   Spriteset_Battle
  2471. #   ----------------
  2472. #   enemy_sprites
  2473. #   actor_sprites
  2474. #   find_battler
  2475. #
  2476. #   Scene_Battle
  2477. #   ------------
  2478. #   active_battler
  2479. #   priority
  2480. #==============================================================================
  2481.  
  2482. MACL::Loaded << 'RGSS.Battle'
  2483.  
  2484. #==============================================================================
  2485. # ** Spriteset_Battle
  2486. #==============================================================================
  2487.  
  2488. class Spriteset_Battle
  2489.   #--------------------------------------------------------------------------
  2490.   # * Public Instance Variables
  2491.   #--------------------------------------------------------------------------
  2492.   attr_reader :enemy_sprites
  2493.   attr_reader :actor_sprites
  2494.   #-------------------------------------------------------------------------
  2495.   #   Name      : Find Sprite Battler
  2496.   #   Info      : Returns Sprite_Battler object if found else nil
  2497.   #   Author    : Trickster
  2498.   #   Call Info : One Argument, Game_Battler batter battler to search
  2499.   #-------------------------------------------------------------------------
  2500.   def find_battler(battler)
  2501.     # Run Through Each Sprite
  2502.     (@actor_sprites + @enemy_sprites).each do |sprite|
  2503.       # Return sprite if same battler
  2504.       return sprite if sprite.battler == battler
  2505.     end
  2506.     # Return nil
  2507.     return nil
  2508.   end
  2509. end
  2510.  
  2511. #==============================================================================
  2512. # ** Scene_Battle
  2513. #==============================================================================
  2514.  
  2515. class Scene_Battle
  2516.   #--------------------------------------------------------------------------
  2517.   # * Public Instance Variables
  2518.   #--------------------------------------------------------------------------
  2519.   attr_reader :active_battler
  2520.   #-------------------------------------------------------------------------
  2521.   #   Name      : Update Priority
  2522.   #   Info      : Priority Update Rate
  2523.   #   Author    : Trickster
  2524.   #   Call Info : One Argument Integer rating the rating of updating
  2525.   #   Comment   : Allows for easier aliasing of update_phase3
  2526.   #-------------------------------------------------------------------------
  2527.   def priority(rating = 0)
  2528.     flag = true
  2529.     flag &&= @enemy_arrow == nil if rating < 5
  2530.     flag &&= @actor_arrow == nil if rating < 4
  2531.     flag &&= @skill_window == nil if rating < 3
  2532.     flag &&= @item_window == nil if rating < 2
  2533.     flag &&= !@actor_command_window.active if rating < 1
  2534.     return flag
  2535.   end
  2536. end
  2537.  
  2538. #==============================================================================
  2539. # ** RGSS.Bitmap.draw
  2540. #------------------------------------------------------------------------------
  2541. # Description:
  2542. # ------------
  2543. # Methods created for the Bitmap class that handle general drawing functions.
  2544. # Functions include drawing parts of bitmaps and drawing stretched bitmaps.
  2545. #  
  2546. # Method List:
  2547. # ------------
  2548. # Bitmap.default_blur_settings=
  2549. # Bitmap.default_blur_settings
  2550. # Bitmap.default_anim_sprite_settings=
  2551. # Bitmap.default_anim_sprite_settings
  2552. # blur_settings=
  2553. # blur_settings
  2554. # anim_sprite_settings=
  2555. # anim_sprite_settings
  2556. # draw_char_bar
  2557. # draw_line
  2558. # draw_box
  2559. # draw_circle
  2560. # draw_ellipse
  2561. # draw_polygon
  2562. # draw_gradient_polygon
  2563. # draw_anim_sprite
  2564. # draw_sprite
  2565. # draw_equipment
  2566. # crop_blt
  2567. # fit_blt
  2568. # full_blt
  2569. # full_fill
  2570. # scale_blt
  2571. # shade_section
  2572. # shade_gradient_section
  2573. #
  2574. # Modified Methods:
  2575. # -----------------
  2576. # initialize
  2577. #==============================================================================
  2578.  
  2579. MACL::Loaded << 'RGSS.Bitmap.draw'
  2580.  
  2581. #==============================================================================
  2582. # ** Bitmap
  2583. #==============================================================================
  2584.  
  2585. class Bitmap
  2586.   #--------------------------------------------------------------------------
  2587.   # * Class Variable Declaration
  2588.   #--------------------------------------------------------------------------
  2589.   class_accessor :default_blur_settings
  2590.   class_accessor :default_anim_sprite_settings
  2591.   #--------------------------------------------------------------------------
  2592.   # * Class Variable Declaration
  2593.   #--------------------------------------------------------------------------
  2594.   Bitmap.default_blur_settings        = Blur_Settings
  2595.   Bitmap.default_anim_sprite_settings = Anim_Sprite_Settings
  2596.   #--------------------------------------------------------------------------
  2597.   # * Public Instance Variables
  2598.   #--------------------------------------------------------------------------
  2599.   attr_accessor :blur_settings
  2600.   attr_accessor :anim_sprite_settings
  2601.   #--------------------------------------------------------------------------
  2602.   # * Alias Method
  2603.   #--------------------------------------------------------------------------
  2604.   alias_method :macl_bitmapdraw_init, :initialize
  2605.   #--------------------------------------------------------------------------
  2606.   # * Object Initialization
  2607.   #--------------------------------------------------------------------------
  2608.   def initialize(*args)
  2609.     # Set draw settings
  2610.     @blur_settings        = Bitmap.default_blur_settings
  2611.     @anim_sprite_settings = Bitmap.default_anim_sprite_settings
  2612.     # Original Initialization
  2613.     macl_bitmapdraw_init(*args)
  2614.   end
  2615.   #-------------------------------------------------------------------------
  2616.   # * Name      : Draw Char Bar
  2617.   #   Info      : Draws a Character Bar
  2618.   #   Author    : Trickster
  2619.   #   Call Info : Integer X, Y - Defines Position
  2620.   #               Integer Min, Max - Defines How filled the bar is
  2621.   #               Integer Width and height - Defines Dimensions
  2622.   #               String Start Content and Finish
  2623.   #-------------------------------------------------------------------------
  2624.   def draw_char_bar(x, y, min = 1, max = 1, width = nil, height = 32, start = '[',
  2625.     content = 'ヲ', finish = ']', color = Color.new(255, 255, 255))
  2626.     # Get Width if width is nil
  2627.     width = text_size(start + (content * max) + finish).width if width == nil
  2628.     # save color
  2629.     saved = font.color
  2630.     # Set color
  2631.     self.font.color = color
  2632.     # Get Bar Text
  2633.     bar_text = start + content * min.to_i
  2634.     # Draw Bar Text
  2635.     draw_text(x, y, width, height, bar_text)
  2636.     # Draw Finish
  2637.     draw_text(x, y, width, height, finish, 2)
  2638.     # Restore Color
  2639.     self.font.color = saved
  2640.   end
  2641.   #-------------------------------------------------------------------------
  2642.   # * Name      : Draw Line
  2643.   #   Info      : Draws a line from x1,y1 to x2,y2
  2644.   #   Author    : Caesar (Rewrote By Trickster)
  2645.   #   Call Info : Integer x1, y1, x2, y2 - Points of the line
  2646.   #               Integer width - Thickness of the line
  2647.   #               Color color - Color of the line
  2648.   #   Comments  : uses the Digital Differential Analyzer Algorithm
  2649.   #-------------------------------------------------------------------------
  2650.   def draw_line(x1, y1, x2, y2, width = 1, color = Color.new(255, 255, 255))
  2651.     # Return if width is less than or 0
  2652.     return if width <= 0
  2653.     # Reverse all parameters sent if 2 x is less than the first x
  2654.     x1, x2, y1, y2 = x2, x1, y2, y1 if x2 < x1    
  2655.     # Get S (1/2 width)
  2656.     s = width / 2.0
  2657.     # If X Coordinates are equal
  2658.     if x1 == x2
  2659.       # Draw Vertical line
  2660.       fill_rect(x1 - s, [y1, y2].min, width, (y2 - y1).abs, color)
  2661.     # If Y Coordinates are equal
  2662.     elsif y1 == y2
  2663.       # Draw Horizontal line
  2664.       fill_rect(x1, y1 - s, x2 - x1, width, color)
  2665.     end
  2666.     # Get Length
  2667.     length = x2 - x1 < (y2 - y1).abs ? (y2 - y1).abs : x2 - x1
  2668.     # Get Increments
  2669.     x_increment, y_increment = (x2 - x1) / length.to_f, (y2 - y1) / length.to_f
  2670.     # Get Current X and Y
  2671.     x, y = x1, y1
  2672.     # While Current X is less than end X
  2673.     while x < x2
  2674.       # Draw Box of width width and width height
  2675.       fill_rect(x-s, y-s, width, width, color)
  2676.       # Increment X and Y
  2677.       x += x_increment
  2678.       y += y_increment
  2679.     end
  2680.   end
  2681.   #-------------------------------------------------------------------------
  2682.   # * Name      : Draw Box
  2683.   #   Info      : Draws a Box
  2684.   #   Author    : Trickster
  2685.   #   Call Info : Two to Four Arguments Rect Outer Rectangle to Draw Box
  2686.   #               Color color color to draw the box in
  2687.   #-------------------------------------------------------------------------
  2688.   def draw_box(outer, color, width = 1, height = 1)
  2689.     fill_rect(outer, color)
  2690.     inner = Rect.new(outer.x + width, outer.y + height, outer.width - width * 2,
  2691.     outer.height - height * 2)
  2692.     fill_rect(inner, Color.new(0, 0, 0, 0))
  2693.   end
  2694.   #-------------------------------------------------------------------------
  2695.   # * Name      : Draw Circle
  2696.   #   Info      : Draws A Circle
  2697.   #   Author    : SephirothSpawn
  2698.   #   Call Info : Integer X and Y Define Position Center Pt of Circle
  2699.   #               Integer Radius Radius of the Circle to Draw
  2700.   #               Color color Color of the circle to draw
  2701.   #-------------------------------------------------------------------------
  2702.   def draw_circle(x, y, radius, color = Color.new(255, 255, 255, 255))
  2703.     # Starts From Left
  2704.     for i in (x - radius)..(x + radius)
  2705.       # Finds Distance From Center
  2706.       sa = (x - i).abs
  2707.       # Finds X Position
  2708.       x_ = i < x ? x - sa : i == x ? x : x + sa
  2709.       # Finds Top Vertical Portion
  2710.       y_ = Integer((radius ** 2 - sa ** 2) ** 0.5)
  2711.       # Draws Vertical Bar
  2712.       self.fill_rect(x_, y - y_, 1, y_ * 2, color)
  2713.     end
  2714.   end
  2715.   #-------------------------------------------------------------------------
  2716.   # * Name      : Draw Ellipse
  2717.   #   Info      : Draws a Ellispse
  2718.   #   Author    : SephirothSpawn
  2719.   #   Call Info : Four or Five Arguments
  2720.   #               Four Arguments: x, y, a, b
  2721.   #                 x the center position of circle
  2722.   #                 y the center position of circle
  2723.   #                 a the distance from center to right side
  2724.   #                 b the distance from center to top side
  2725.   #               Five Arguments: (as above) + color
  2726.   #                 color the color of the circle drawn (defaults to white)
  2727.   #-------------------------------------------------------------------------
  2728.   def draw_ellipse(x, y, a, b, color = Color.new(255, 255, 255))
  2729.     # Converts Each Argument to Float
  2730.     x, y, a, b = x.to_f, y.to_f, a.to_f, b.to_f
  2731.     # Gets Square of a and b values
  2732.     a2, b2 = a * a, b * b
  2733.     # If a is smaller or equal to b
  2734.     if a <= b
  2735.       # Draws Center Line
  2736.       self.fill_rect(x, y - b, 1, b * 2, color)
  2737.       # Pass from center to right side
  2738.       for i in 1..a
  2739.         # Gets Y Distance
  2740.         y_ = Integer(Math.sqrt(b2 * (1 - (i ** 2) / a2)))
  2741.         # Draws Lines on Each Side
  2742.         self.fill_rect(x - i, y - y_, 1, y_ * 2, color)
  2743.         self.fill_rect(x + i, y - y_, 1, y_ * 2, color)
  2744.       end
  2745.     # If b is smaller than b
  2746.     else
  2747.       # Draws Center Line
  2748.       self.fill_rect(x - a, y, a * 2, 1, color)
  2749.       # Pass from center to right side
  2750.       for i in 1..b
  2751.         # Gets X Distance
  2752.         x_ = Integer(Math.sqrt(a2 * (1 - i ** 2 / b2)))
  2753.         # Draws Lines on Top & Bottom
  2754.         self.fill_rect(x - x_, y - i, x_ * 2, 1, color)
  2755.         self.fill_rect(x - x_, y + i, x_ * 2, 1, color)
  2756.       end
  2757.     end
  2758.   end
  2759.   #-------------------------------------------------------------------------
  2760.   # * Name      : Draw Polygon
  2761.   #   Info      : Draws a Polygon
  2762.   #   Author    : Caesar (Rewrote By Trickster)
  2763.   #   Call Info : Array vertices - Points of the polygon
  2764.   #               Integer width - Thickness of the lines
  2765.   #               Color color - color to draw it in
  2766.   #               Boolean filled - false outline true filled
  2767.   #               Integer step - fill steps
  2768.   #   Comments  : Example of vertices setup [[30, 80], [80, 80], [30, 60]]
  2769.   #-------------------------------------------------------------------------
  2770.   def draw_polygon(vertices, stroke = 1, color = Color.new(255, 255, 255),
  2771.     filled = false, step = 1)
  2772.     # Return if no width or not enough points
  2773.     return if stroke <= 0 or vertices.size <= 2
  2774.     # Get Count
  2775.     count = vertices.size
  2776.     # Get Points
  2777.     x1, y1, x2, y2 = vertices[-1] + vertices[0]
  2778.     # Draw Line
  2779.     draw_line(x1, y1, x2, y2, stroke, color)
  2780.     # Shade if filled
  2781.     shade_section(cx, cy, x1, y1, x2, y2, stroke, step, color) if filled
  2782.     # Run Through with next
  2783.     vertices.each_with_next do |start, point|
  2784.       # Get Points
  2785.       x1, y1, x2, y2 = start + point
  2786.       # Draw Line
  2787.       draw_line(x1, y1, x2, y2, stroke, color)
  2788.       # Shade if filled
  2789.       shade_section(cx, cy, x1, y1, x2, y2, stroke, step, color) if filled
  2790.     end
  2791.   end
  2792.   #-------------------------------------------------------------------------
  2793.   # * Name      : Draw Gradient Polygon
  2794.   #   Info      : Draws a Gradient Polygon  (Filled)
  2795.   #   Author    : Caesar (Rewrote By Trickster)
  2796.   #   Call Info : Array vertices - Points of the polygon
  2797.   #               Integer width - Thickness of the lines
  2798.   #               Color color - color to draw it in
  2799.   #               Boolean filled - false outline true filled
  2800.   #               Integer step - fill steps
  2801.   #   Comments  : Example of vertices setup [[30, 80], [80, 80], [30, 60]]
  2802.   #-------------------------------------------------------------------------
  2803.   def draw_gradient_polygon(cx, cy, vertices, stroke = 1,
  2804.     start_color = Color.new(255, 255, 255), end_color = Color.new(0, 0, 0),
  2805.     step = 1)
  2806.     # Return if no width or not enough points
  2807.     return if stroke <= 0 or vertices.size <= 2
  2808.     # Get Count
  2809.     count = vertices.size
  2810.     # Get Points
  2811.     x1, y1, x2, y2 = vertices[-1] + vertices[0]
  2812.     # Draw Line
  2813.     draw_line(x1, y1, x2, y2, stroke, end_color)
  2814.     shade_gradient_section(cx, cy, x1, y1, x2, y2, 2, 1, start_color, end_color)
  2815.     # Run Through with next
  2816.     vertices.each_with_next do |start, point|
  2817.       # Get Points
  2818.       x1, y1, x2, y2 = start + point
  2819.       # Draw Line
  2820.       draw_line(x1, y1, x2, y2, stroke, end_color)
  2821.       shade_gradient_section(cx, cy, x1, y1, x2, y2, 1, 0.4, start_color, end_color)
  2822.     end
  2823.   end
  2824.   #-------------------------------------------------------------------------
  2825.   # * Name      : Draw Animated Sprite
  2826.   #   Info      : Draws an Animated Sprite
  2827.   #   Author    : SephirothSpawn
  2828.   #   Call Info : Six to Seven Arguments Integer x and y Defines Position
  2829.   #               Integer W and H Defines Dimensions
  2830.   #               String name Character Set Graphic
  2831.   #               Integer hue sets hue displacement
  2832.   #               Integer stance pose for character
  2833.   #-------------------------------------------------------------------------
  2834.   def draw_anim_sprite(x, y, w, h, name, hue, stance = 0)
  2835.     # Gets Frame
  2836.     frame = (Graphics.frame_count / @anim_sprite_settings['f']) %
  2837.             @anim_sprite_settings['w']
  2838.     # Draw Sprite
  2839.     draw_sprite(x, y, w, h, name, hue, stance, frame)
  2840.   end
  2841.   #-------------------------------------------------------------------------
  2842.   # * Name      : Draw Sprite
  2843.   #   Info      : Draws an Animated Sprite
  2844.   #   Author    : SephirothSpawn
  2845.   #   Call Info : Six to Seven Arguments Integer x and y Defines Position
  2846.   #               Integer W and H Defines Dimensions
  2847.   #               String name Character Set Graphic
  2848.   #               Integer hue sets hue displacement
  2849.   #               Integer stance pose for character
  2850.   #               Integer frame frame of pose to show
  2851.   #-------------------------------------------------------------------------
  2852.   def draw_sprite(x, y, w, h, name, hue, stance = 0, frame = 0)
  2853.     # Gets Bitmap
  2854.     bitmap = RPG::Cache.character(name, hue)
  2855.     # Bitmap Division
  2856.     cw = bitmap.width / @anim_sprite_settings['w']
  2857.     ch = bitmap.height / @anim_sprite_settings['h']
  2858.     # Gets Animation Offsets
  2859.     x_off, y_off = cw * frame, ch * stance
  2860.     # Clears Area
  2861.     self.fill_rect(Rect.new(x, y, w, h), Color.new(0, 0, 0, 0))
  2862.     # Draws Bitmap
  2863.     self.scale_blt(Rect.new(x, y, w, h), bitmap,
  2864.       Rect.new(x_off, y_off, cw, ch))
  2865.   end
  2866.   #-------------------------------------------------------------------------
  2867.   # * Name      : Draw Equip
  2868.   #   Info      : Draws Item or Equipment icon and name
  2869.   #   Author    : SephirothSpawn
  2870.   #   Call Info : Three to Eight Arguments
  2871.   #               Item - RPG::Item, RPG::Weapon or RPG::Armor
  2872.   #               X - Position Icon & Text Being drawn
  2873.   #               Y - Position Icon & Test Being drawn
  2874.   #               W - Width for Icon & Text to be drawn in
  2875.   #               H - Height for Icon & Text to be drawn in (24 min)
  2876.   #               A - Alignment of text
  2877.   #               T - Type of icon to be used when nil item (See MACL Setup)
  2878.   #               Txt - Text when Item is nil
  2879.   #-------------------------------------------------------------------------
  2880.   def draw_equipment(i, x, y, w = 212, h = 32, a = 0, t = 0, txt = 'Nothing')
  2881.     # If Nil Item
  2882.     if i.nil?
  2883.       # Gets Unequipped Bitmap & Font Color
  2884.       bitmap = RPG::Cache.icon(Draw_Equipment_Icon_Settings[t])
  2885.       c = Color.disabled
  2886.     # If Item Exist
  2887.     else
  2888.       # Gets Bitmap, Font Color & Item Name
  2889.       bitmap = RPG::Cache.icon(i.icon_name)
  2890.       c, txt = Color.normal, i.name
  2891.     end
  2892.     # Sets Font Color, Draws Icon & Text
  2893.     old_color = self.font.color.dup
  2894.     self.blt(x + 4, y + (h - 24) / 2, bitmap, bitmap.rect, c.alpha)
  2895.     self.font.color = c
  2896.     self.draw_text(x + 32, y, w - 28, h, txt, a)
  2897.     self.font.color = old_color
  2898.   end
  2899.   #-------------------------------------------------------------------------
  2900.   # * Name      : Crop BLT
  2901.   #   Info      : Crops to Width and Height, if needed
  2902.   #   Author    : Trickster
  2903.   #   Call Info : Five - Eight Arguments, Integer X and Y Define Position
  2904.   #               Integer Width and Height Defines Dimensions
  2905.   #               Bitmap bitmap bitmap to transfer
  2906.   #               Integer dir, part to crop
  2907.   #               Integer align, alignment (0:left, 1:center, 2:right)
  2908.   #               Integer opacity, opacity
  2909.   #-------------------------------------------------------------------------
  2910.   def crop_blt(x, y, width, height, bitmap, dir = 1, align = 1, opacity = 255)
  2911.     # Get Width and Height
  2912.     w, h = bitmap.width, bitmap.height
  2913.     # If Can Fit
  2914.     if w < width and h < height
  2915.       # Branch By alignment
  2916.       case align
  2917.       when 1
  2918.         # Add To Make it in the center
  2919.         x += (width - w) / 2
  2920.       when 2
  2921.         # Add to Make it in the right
  2922.         x += width - w
  2923.       end
  2924.       # Draw Bitmap
  2925.       full_blt(x, y, bitmap, opacity)
  2926.       # Return
  2927.       return
  2928.     end
  2929.     # Get I and J (Position)
  2930.     i, j = dir % 3, dir / 3
  2931.     # Initialize Crop X and Crop Y (Left Top Align)
  2932.     crop_x, crop_y = 0, 0
  2933.     # Branch by Horizontal Position
  2934.     case i
  2935.     when 1
  2936.       # Center Align
  2937.       crop_x = (w - width) / 2
  2938.     when 2
  2939.       # Right Align
  2940.       crop_x = w - width
  2941.     end
  2942.     # Branch by Vertical Position
  2943.     case j
  2944.     when 1
  2945.       # Center Align
  2946.       crop_y = (h - height) / 2
  2947.     when 2
  2948.       # Bottom Align
  2949.       crop_y = h - height
  2950.     end
  2951.     # Draw Bitmap Cropped
  2952.     blt(x, y, bitmap, Rect.new(crop_x, crop_y, width, height), opacity)
  2953.   end
  2954.   #-------------------------------------------------------------------------
  2955.   # * Name      : Fit BLT
  2956.   #   Info      : Zooms to Width and Height, if needed
  2957.   #   Author    : Trickster
  2958.   #   Call Info : Five-Seven Arguments, Integer X and Y Define Position
  2959.   #               Integer Width and Height Defines Dimensions
  2960.   #               Bitmap bitmap bitmap to transfer
  2961.   #               Integer opacity, opacity
  2962.   #               Integer Align, Alignment
  2963.   #-------------------------------------------------------------------------
  2964.   def fit_blt(x, y, width, height, bitmap, opacity = 255, align = 1)
  2965.     # Get Width and Height
  2966.     w, h = bitmap.width, bitmap.height
  2967.     # If Width or Height is Greater
  2968.     if w > width or h > height
  2969.       # Get Conversion
  2970.       conversion = w / h.to_f
  2971.       # if Conversion is smaller than or 1
  2972.       if conversion <= 1
  2973.         # Get Zoom X and Y
  2974.         zoom_x, zoom_y = width * conversion, height
  2975.       else
  2976.         # Get Zoom X and Y
  2977.         zoom_x, zoom_y = width, height / conversion
  2978.       end
  2979.       # Branch By Align
  2980.       case align
  2981.       when 1
  2982.         # Add To Make it in the center
  2983.         x += (width - zoom_x) / 2
  2984.       when 2
  2985.         # Add to Make it in the right
  2986.         x += width - zoom_x
  2987.       end
  2988.       # Get Destination Rect
  2989.       dest_rect = Rect.new(x, y, zoom_x, zoom_y)
  2990.       # Stretch to Fit
  2991.       stretch_blt(dest_rect, bitmap, bitmap.rect, opacity)
  2992.     else
  2993.       # Branch By alignment
  2994.       case align
  2995.       when 1
  2996.         # Add To Make it in the center
  2997.         x += (width - w) / 2
  2998.       when 2
  2999.         # Add to Make it in the right
  3000.         x += width - w
  3001.       end
  3002.       # Draw Bitmap
  3003.       full_blt(x, y, bitmap, opacity)
  3004.     end
  3005.   end
  3006.   #-------------------------------------------------------------------------
  3007.   #   Name      : Full Block Transfer
  3008.   #   Info      : Draws a Bitmap
  3009.   #   Author    : Trickster
  3010.   #   Call Info : Three or Four Arguments
  3011.   #               Integer X and Y define position
  3012.   #               Bitmap bitmap is the bitmap to draw
  3013.   #               Integer Opacity is the transparency (defaults to 255)
  3014.   #   Comment   : Lazy method for people who don't want to type bitmap.rect
  3015.   #-------------------------------------------------------------------------
  3016.   def full_blt(x, y, bitmap, opacity = 255)
  3017.     blt(x, y, bitmap, bitmap.rect, opacity)
  3018.   end
  3019.   #-------------------------------------------------------------------------
  3020.   #   Name      : Full Fill
  3021.   #   Info      : Fills Whole Bitmap
  3022.   #   Author    : Trickster
  3023.   #   Call Info : One Argument, Color color the color to be filled
  3024.   #   Comment   : Lazy method for people who don't want to type bitmap.rect
  3025.   #-------------------------------------------------------------------------
  3026.   def full_fill(color)
  3027.     fill_rect(rect, color)
  3028.   end
  3029.   #-------------------------------------------------------------------------
  3030.   # * Name      : Scale BLT
  3031.   #   Info      : Scales Bitmap to fit Rectangle
  3032.   #   Author    : SephirothSpawn
  3033.   #   Call Info : Two to Four Arguments
  3034.   #               Rect Dest_Rect - Destination Rectangle
  3035.   #               Bitmap Src_Bitmap - Source Bitmap
  3036.   #               Rect Src_Rect - Source Rectangle for Bitmap
  3037.   #               Integer Opacity - Opacity
  3038.   #-------------------------------------------------------------------------
  3039.   def scale_blt(dest_rect, src_bitmap, src_rect = src_bitmap.rect, o = 255)
  3040.     w, h = src_rect.width, src_rect.height
  3041.     scale = [w / dest_rect.width.to_f, h / dest_rect.height.to_f].max
  3042.     ow, oh = (w / scale).to_i, (h / scale).to_i
  3043.     ox, oy = (dest_rect.width - ow) / 2, (dest_rect.height - oh) / 2
  3044.     stretch_blt(Rect.new(ox + dest_rect.x, oy + dest_rect.y, ow, oh),
  3045.       src_bitmap, src_rect, o)
  3046.   end
  3047.   #-------------------------------------------------------------------------
  3048.   # * Name      : Shade Section
  3049.   #   Info      : Shades a section from (cx,cy), (x1,y1), (x2,y2)
  3050.   #   Author    : Trickster
  3051.   #   Call Info : Six to Nine Arguments
  3052.   #               Integer cx, cy, x1, y1, x2, y2 - Points
  3053.   #               Integer Thick - Line Thickness
  3054.   #               Integer Step - how many lines to draw (lower = higher accuracy)
  3055.   #               Color color - color to shade in
  3056.   #-------------------------------------------------------------------------
  3057.   def shade_section(cx, cy, x1, y1, x2, y2, thick = 1, step = 1,
  3058.       color = Color.new(255, 255, 255))
  3059.     # Reverse all parameters sent if 2 x is less than the first x
  3060.     x1, x2, y1, y2 = x2, x1, y2, y1 if x2 < x1    
  3061.     # Get Slope
  3062.     slope = (y2 - y1).to_f / (x2 - x1)
  3063.     # If Slope is infinite
  3064.     if slope.infinite?
  3065.       y1.step(y2, step) {|y| draw_line(cx, cy, x1, y, thick, color)}
  3066.     # If Slope is zero
  3067.     elsif slope.zero?
  3068.       x1.step(x2, step) {|x| draw_line(cx, cy, x, y1, thick, color)}
  3069.     elsif not slope.nan?
  3070.       # Get Y intercept
  3071.       yint = y1 - slope * x1
  3072.       x1.step(x2, step) {|x| draw_line(cx, cy, x, slope * x + yint, thick, color)}
  3073.     end
  3074.   end
  3075.   #-------------------------------------------------------------------------
  3076.   # * Name      : Shade Gradient Section
  3077.   #   Info      : Shades a section from (cx,cy), (x1,y1), (x2,y2) w/ gradient
  3078.   #   Author    : Trickster
  3079.   #   Call Info : Six to Ten Arguments
  3080.   #               Integer cx, cy, x1, y1, x2, y2 - Points
  3081.   #               Integer Thick - Line Thickness
  3082.   #               Integer Step - how many lines to draw (lower = higher accuracy)
  3083.   #               Color start_color, end_color - Start and end colors
  3084.   #-------------------------------------------------------------------------
  3085.   def shade_gradient_section(cx, cy, x1, y1, x2, y2, thick = 1, step = 1,
  3086.     start_color = Color.new(0, 0, 0), end_color = start_color)
  3087.     # Reverse all parameters sent if 2 x is less than the first x
  3088.     x1, x2, y1, y2 = x2, x1, y2, y1 if x2 < x1    
  3089.     # Get Slope
  3090.     slope = (y2 - y1).to_f / (x2 - x1)
  3091.     # If Slope is infinite
  3092.     if slope.infinite?
  3093.       y1.step(y2, step) {|y| draw_gradient_line(cx, cy, x1, y, thick, start_color, end_color)}
  3094.     # If Slope is zero
  3095.     elsif slope.zero?
  3096.       x1.step(x2, step) {|x| draw_gradient_line(cx, cy, x, y1, thick, start_color, end_color)}
  3097.     elsif not slope.nan?
  3098.       # Get Y intercept
  3099.       yint = y1 - slope * x1
  3100.       x1.step(x2, step) {|x| draw_gradient_line(cx, cy, x, slope * x + yint, thick, start_color, end_color)}
  3101.     end
  3102.   end
  3103. end
  3104.  
  3105. #==============================================================================
  3106. # ** RGSS.Bitmap.gradient
  3107. #------------------------------------------------------------------------------
  3108. # Description:
  3109. # ------------
  3110. # Methods created for the Bitmap class that draws different types of gradient
  3111. # bars and other things some gradients from colors and others from images.
  3112. #  
  3113. # Method List:
  3114. # ------------
  3115. # draw_gradient_line
  3116. # draw_meter_line
  3117. # draw_seph_gradient_bar
  3118. # draw_seph_rev_gradient_bar
  3119. # draw_slant_bar
  3120. # draw_rev_slant_bar
  3121. # draw_trick_circular_bar
  3122. # draw_trick_rev_cirular_bar
  3123. # draw_seph_v_gradient_bar
  3124. # draw_seph_v_rev_gradient_bar
  3125. # draw_v_slant_bar
  3126. # draw_v_rev_slant_bar
  3127. # draw_trick_v_circular_bar
  3128. # draw_trick_v_rev_circular_bar
  3129. # draw_cw_arc_region
  3130. # draw_ccw_arc_region
  3131. # draw_cw_grad_arc_region
  3132. # draw_ccw_grad_arc_region
  3133. # draw_trick_function_bar
  3134. # draw_trick_gradient_bar
  3135. # draw_trick_gradient_bar_back
  3136. # draw_trick_gradient_bar_sub
  3137. # shade_gradient_section
  3138. # v_gradient_pixel_change
  3139. # h_gradient_pixel_change
  3140. #  
  3141. # Deprecated Stuff (V 2.0):
  3142. # -------------------------
  3143. # trick_draw_gradient_bar_circ
  3144. # trick_draw_gradient_bar_func
  3145. #  
  3146. # Renamed Stuff (V 2.0):
  3147. # ----------------------
  3148. # trick_draw_circular_bar -> draw_trick_circular_bar
  3149. # trick_draw_function_bar -> draw_trick_function_bar
  3150. #==============================================================================
  3151.  
  3152. MACL::Loaded << 'RGSS.Bitmap.gradient'
  3153.  
  3154. #==============================================================================
  3155. # ** Bitmap
  3156. #==============================================================================
  3157.  
  3158. class Bitmap
  3159.   #-------------------------------------------------------------------------
  3160.   # * Name      : Draw Gradient Line
  3161.   #   Info      : Draws a Gradient Line From (x, y) to (x1, y1) of a thickness
  3162.   #   Author    : RXS (Edited by Trickster)
  3163.   #   Call Info : Four to Seven Arguments
  3164.   #               Integer start_x, start_y, end_x, end_y - Defines Position
  3165.   #               Integer thick - thickness of the line
  3166.   #               Color start_color and end_color Colors for the line
  3167.   #-------------------------------------------------------------------------
  3168.   def draw_gradient_line(start_x, start_y, end_x, end_y, width = 1,
  3169.     start_color = Color.new(0, 0, 0), end_color = start_color)
  3170.     # Get Distance
  3171.     distance = (start_x - end_x).abs + (start_y - end_y).abs
  3172.     # If Same Color
  3173.     if end_color == start_color
  3174.       # Run Through from 1 to distance
  3175.       (1..distance).each do |i|
  3176.         # Get X and Y
  3177.         x = (start_x + (end_x.to_f - start_x) * i / distance).to_i
  3178.         y = (start_y + (end_y.to_f - start_y) * i / distance).to_i
  3179.         # Fill Rectangle
  3180.         fill_rect(x, y, width, width, start_color)
  3181.       end
  3182.     # Different Colors
  3183.     else
  3184.       # Run Through from 1 to distance
  3185.       (1..distance).each do |i|
  3186.         # Get Percent Disance and I Distance
  3187.         per_dist, i_dist = (distance - i.to_f) / distance, i.to_f / distance
  3188.         # Get Position
  3189.         x = (start_x + (end_x.to_f - start_x) * i_dist).to_i
  3190.         y = (start_y + (end_y.to_f - start_y) * i_dist).to_i
  3191.         # Get Color Information
  3192.         r = start_color.red * per_dist + end_color.red * i_dist
  3193.         g = start_color.green * per_dist + end_color.green * i_dist
  3194.         b = start_color.blue * per_dist + end_color.blue * i_dist
  3195.         a = start_color.alpha * per_dist + end_color.alpha * i_dist
  3196.         # Fill Rectangle
  3197.         fill_rect(x, y, width, width, Color.new(r, g, b, a))
  3198.       end
  3199.     end
  3200.   end
  3201.   #-------------------------------------------------------------------------
  3202.   # * Name      : Draw Meter Line
  3203.   #   Info      : Draws a Slanted Gradient Bar
  3204.   #   Author    : XRXS Edited By Trickster
  3205.   #   Call Info : Four to Nine Arguments Integer x and y Define Position
  3206.   #               Integer min and max define percentage of bar's fill
  3207.   #               Integer width and height defines dimensions
  3208.   #               Color bar_start bar_end and background Defines Colors for bar
  3209.   #-------------------------------------------------------------------------
  3210.   def draw_meter_line(x, y, min, max, width = 156, height = 4,
  3211.     bar_start = Color.new(255, 0, 0, 192), bar_end = Color.new(255, 255, 0, 192),
  3212.     background = Color.new(0, 0, 0, 128))
  3213.     # Get Fill Width
  3214.     w = width * min / max
  3215.     # Do Four Times
  3216.     4.times do
  3217.       # Draws Background
  3218.       fill_rect(x + 8, y + 4, width, height / 4, background)
  3219.       # Draw Gradient Line
  3220.       draw_gradient_line(x, y, x + w, y, height / 4, bar_start, bar_end)
  3221.       # Decrement X
  3222.       x -= 1
  3223.       # Increment Y by height / 4
  3224.       y += height / 4
  3225.     end
  3226.   end
  3227.   #-------------------------------------------------------------------------
  3228.   # * Name      : Draw Gradient Bar
  3229.   #   Info      : Draws a Gradient Bar
  3230.   #   Author    : SephirothSpawn
  3231.   #   Call Info : Four to Nince Arguments
  3232.   #               Integer x and y Defines Position
  3233.   #               Integer min and max Defines Dimensions of Bar
  3234.   #               Start Bar Color and End Color - Colors for Gradient Bar
  3235.   #               Background Bar Color
  3236.   #-------------------------------------------------------------------------
  3237.   def draw_seph_gradient_bar(x, y, cur, max, width = 152, height = 8,
  3238.       s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
  3239.     # Draw Border
  3240.     self.fill_rect(x, y, width, height, b_color)
  3241.     # Draws Bar
  3242.     for i in 1...((cur / max.to_f) * (width - 1))
  3243.       c = Color.color_between(s_color, e_color, (i / width.to_f))
  3244.       self.fill_rect(x + i, y + 1, 1, height - 2, c)
  3245.     end
  3246.   end
  3247.   #-------------------------------------------------------------------------
  3248.   # * Name      : Draw Reverse Gradient Bar
  3249.   #   Info      : Draws a Gradient Bar
  3250.   #   Author    : SephirothSpawn
  3251.   #   Call Info : Four to Nine Arguments
  3252.   #               Integer x and y Defines Position
  3253.   #               Integer min and max Defines Dimensions of Bar
  3254.   #               Start Bar Color and End Color - Colors for Gradient Bar
  3255.   #               Background Bar Color
  3256.   #-------------------------------------------------------------------------
  3257.   def draw_seph_rev_gradient_bar(x, y, cur, max, width = 152, height = 8,
  3258.       s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
  3259.     # Draw Border
  3260.     self.fill_rect(x, y, width, height, b_color)
  3261.     # Draws Bar
  3262.     for i in 1...((cur / max.to_f) * (width - 1))
  3263.       c = Color.color_between(s_color, e_color, (i / width.to_f))
  3264.       self.fill_rect(x + width - 1 - i, y + 1, 1, height - 2, c)
  3265.     end
  3266.   end  
  3267.   #-------------------------------------------------------------------------
  3268.   # * Name      : Draw Slant Bar
  3269.   #   Info      : Draws a slanted Gradient Bar
  3270.   #   Author    : SephirothSpawn
  3271.   #   Call Info : Four to Nine Arguments
  3272.   #               Integer x and y Defines Position
  3273.   #               Integer min and max Defines Dimensions of Bar
  3274.   #               Start Bar Color and End Color - Colors for Gradient Bar
  3275.   #               Background Bar Color
  3276.   #-------------------------------------------------------------------------
  3277.   def draw_slant_bar(x, y, cur, max, width = 152, height = 8,
  3278.       s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
  3279.     # Draw Border
  3280.     for i in 0..height
  3281.       self.fill_rect(x + i, y + height - i, width - height, 1, b_color)
  3282.     end
  3283.     # Draws Bar
  3284.     for i in 1...((cur / max.to_f) * (width - height - 1))
  3285.       for j in 1...(height)
  3286.         c = Color.color_between(s_color, e_color, (i / width.to_f))
  3287.         self.fill_rect(x + i + j, y + height - j, 1, 1, c)
  3288.       end
  3289.     end
  3290.   end
  3291.   #-------------------------------------------------------------------------
  3292.   # * Name      : Draw Reverse Slant Bar
  3293.   #   Info      : Draws a slanted Gradient Bar
  3294.   #   Author    : SephirothSpawn
  3295.   #   Call Info : Four to Nine Arguments
  3296.   #               Integer x and y Defines Position
  3297.   #               Integer min and max Defines Dimensions of Bar
  3298.   #               Start Bar Color and End Color - Colors for Gradient Bar
  3299.   #               Background Bar Color
  3300.   #-------------------------------------------------------------------------
  3301.   def draw_rev_slant_bar(x, y, cur, max, width = 152, height = 8,
  3302.       s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
  3303.     # Draw Border
  3304.     for i in 0..height
  3305.       self.fill_rect(x + i, y + height - i, width - height, 1, b_color)
  3306.     end
  3307.     # Draws Bar
  3308.     for i in 1...((cur / max.to_f) * (width - height - 1))
  3309.       for j in 1...(height)
  3310.         c = Color.color_between(s_color, e_color, (i / width.to_f))
  3311.         self.fill_rect(x + width - 1 - i - j, y + j, 1, 1, c)
  3312.       end
  3313.     end
  3314.   end
  3315.   #-------------------------------------------------------------------------
  3316.   #   Name      : Draw Circular Gradient Bar
  3317.   #   Info      : Draws a Circular Gradient Bar
  3318.   #   Author    : Trickster
  3319.   #   Call Info : Six to Nine Arguments
  3320.   #               Integer X, Y, Width, Height, Current, and Max
  3321.   #               Color start, finish, back all default to Black
  3322.   #               X and Y Define Position
  3323.   #               Width and Height defines dimensions
  3324.   #               Current Defines How Much of the Bar to Draw
  3325.   #               Max Defines the Maximum Value
  3326.   #               start, finish, back is the starting, ending, and back color
  3327.   #-------------------------------------------------------------------------
  3328.   def draw_trick_circular_bar(x, y, width, height, current, max,
  3329.       start = Color.red, finish = Color.yellow, back = Color.black)
  3330.     # Draw Background
  3331.     radius = height / 2
  3332.     # Draw Rectangle Center
  3333.     fill_rect(x + radius, y, width - height, height, back)
  3334.     # Draws Ends
  3335.     (radius + 1).times do |x1|
  3336.       # Get Y
  3337.       y1 = Math.sqrt(radius ** 2 - (radius - x1) ** 2).round
  3338.       # Draw Line of Back Color at Left Edge
  3339.       fill_rect(x + x1, y - y1 + radius, 1, 2 * y1, back)
  3340.       # Draw Line of Back Color at Right Edge
  3341.       fill_rect(x + width - x1, y - y1 + radius, 1, 2 * y1, back)
  3342.     end
  3343.     # Get Percentage
  3344.     percentage = current / max.to_f
  3345.     # Return if not a finite number
  3346.     return if not percentage.finite?
  3347.     # Decrease Width and Height increase x and y
  3348.     x, y, width, height = x + 2, y + 2, width - 4, height - 4
  3349.     # Get new Radius
  3350.     radius = height / 2
  3351.     # Get Bar Width
  3352.     barwidth = width * percentage
  3353.     # Draws Left End
  3354.     (radius + 1).times do |x1|
  3355.       # Stop if Past Width
  3356.       break if x1 > barwidth
  3357.       # Get Y
  3358.       y1 = Math.sqrt(radius ** 2 - (radius - x1) ** 2).round
  3359.       # Get Color
  3360.       color = Color.color_between(start, finish, (x1 / width.to_f))
  3361.       # Draw Line
  3362.       fill_rect(x + x1, y - y1 + radius, 1, 2 * y1, color)
  3363.     end
  3364.     # Run From Radius upto Rectangles End
  3365.     (width - height + 1).times do |t|
  3366.       # Get X1
  3367.       x1 = t + radius
  3368.       # Break if Past Width
  3369.       break if x1 > barwidth
  3370.       # Get Color
  3371.       color = Color.color_between(start, finish, (x1 / width.to_f))
  3372.       # Draw Line
  3373.       fill_rect(x + x1, y, 1, height, color)
  3374.     end
  3375.     # Draws Right End
  3376.     radius.times do |t|
  3377.       # Get X
  3378.       x1 = width - radius + t
  3379.       # Stop if Past Width
  3380.       break if x1 > barwidth
  3381.       # Get Y
  3382.       y1 = Math.sqrt(radius ** 2 - t ** 2).round
  3383.       # Get Color
  3384.       color = Color.color_between(start, finish, (x1 / width.to_f))
  3385.       # Draw Line
  3386.       fill_rect(x + x1, y - y1 + radius, 1, 2 * y1, color)
  3387.     end
  3388.   end
  3389.   #-------------------------------------------------------------------------
  3390.   #   Name      : Draw Reverse Circular Gradient Bar
  3391.   #   Info      : Draws a Circular Gradient Bar
  3392.   #   Author    : Trickster / SephirothSpawn
  3393.   #   Call Info : Six to Nine Arguments
  3394.   #               Integer X, Y, Width, Height, Current, and Max
  3395.   #               Color start, finish, back all default to Black
  3396.   #               X and Y Define Position
  3397.   #               Width and Height defines dimensions
  3398.   #               Current Defines How Much of the Bar to Draw
  3399.   #               Max Defines the Maximum Value
  3400.   #               start, finish, back is the starting, ending, and back color
  3401.   #-------------------------------------------------------------------------
  3402.   def draw_trick_rev_circular_bar(x, y, width, height, current, max,
  3403.       start = Color.red, finish = Color.yellow, back = Color.black)
  3404.     # Draw Background
  3405.     radius = height / 2
  3406.     # Draw Rectangle Center
  3407.     fill_rect(x + radius, y, width - height, height, back)
  3408.     # Draws Ends
  3409.     (radius + 1).times do |x1|
  3410.       # Get Y
  3411.       y1 = Math.sqrt(radius ** 2 - (radius - x1) ** 2).round
  3412.       # Draw Line of Back Color at Left Edge
  3413.       fill_rect(x + x1, y - y1 + radius, 1, 2 * y1, back)
  3414.       # Draw Line of Back Color at Right Edge
  3415.       fill_rect(x + width - x1, y - y1 + radius, 1, 2 * y1, back)
  3416.     end
  3417.     # Get Percentage
  3418.     percentage = current / max.to_f
  3419.     # Return if not a finite number
  3420.     return if not percentage.finite?
  3421.     # Decrease Width and Height increase x and y
  3422.     x, y, width, height = x + 2, y + 2, width - 4, height - 4
  3423.     # Get new Radius
  3424.     radius = height / 2
  3425.     # Get Bar Width
  3426.     barwidth = width * percentage
  3427.     # Draws Left End
  3428.     (radius + 1).times do |x1|
  3429.       # Stop if Past Width
  3430.       break if x1 > barwidth
  3431.       # Get Y
  3432.       y1 = Math.sqrt(radius ** 2 - (radius - x1) ** 2).round
  3433.       # Get Color
  3434.       color = Color.color_between(start, finish, (x1 / width.to_f))
  3435.       # Draw Line
  3436.       fill_rect(x + width - x1, y - y1 + radius, 1, 2 * y1, color)
  3437.     end
  3438.     # Run From Radius upto Rectangles End
  3439.     (width - height + 1).times do |t|
  3440.       # Get X1
  3441.       x1 = t + radius
  3442.       # Break if Past Width
  3443.       break if x1 > barwidth
  3444.       # Get Color
  3445.       color = Color.color_between(start, finish, (x1 / width.to_f))
  3446.       # Draw Line
  3447.       fill_rect(x + width - x1, y, 1, height, color)
  3448.     end
  3449.     # Draws Right End
  3450.     radius.times do |t|
  3451.       # Get X
  3452.       x1 = width - radius + t
  3453.       # Stop if Past Width
  3454.       break if x1 > barwidth
  3455.       # Get Y
  3456.       y1 = Math.sqrt(radius ** 2 - t ** 2).round
  3457.       # Get Color
  3458.       color = Color.color_between(start, finish, (x1 / width.to_f))
  3459.       # Draw Line
  3460.       fill_rect(x + width - x1, y - y1 + radius, 1, 2 * y1, color)
  3461.     end
  3462.   end
  3463.   #-------------------------------------------------------------------------
  3464.   # * Name      : Draw Vertical Gradient Bar
  3465.   #   Info      : Draws a Gradient Bar
  3466.   #   Author    : SephirothSpawn
  3467.   #   Call Info : Four to Nine Arguments
  3468.   #               Integer x and y Defines Position
  3469.   #               Integer min and max Defines Dimensions of Bar
  3470.   #               Start Bar Color and End Color - Colors for Gradient Bar
  3471.   #               Background Bar Color
  3472.   #-------------------------------------------------------------------------
  3473.   def draw_seph_v_gradient_bar(x, y, cur, max, width = 8, height = 152,
  3474.       s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
  3475.     # Draw Border
  3476.     self.fill_rect(x, y, width, height, b_color)
  3477.     # Draws Bar
  3478.     for i in 1...((cur / max.to_f) * (height - 1))
  3479.       c = Color.color_between(s_color, e_color, (i / height.to_f))
  3480.       self.fill_rect(x + 1, y + i, width - 2, 1, c)
  3481.     end
  3482.   end
  3483.   #-------------------------------------------------------------------------
  3484.   # * Name      : Draw Vertical Reverse Gradient Bar
  3485.   #   Info      : Draws a Gradient Bar
  3486.   #   Author    : SephirothSpawn
  3487.   #   Call Info : Four to Nine Arguments
  3488.   #               Integer x and y Defines Position
  3489.   #               Integer min and max Defines Dimensions of Bar
  3490.   #               Start Bar Color and End Color - Colors for Gradient Bar
  3491.   #               Background Bar Color
  3492.   #-------------------------------------------------------------------------
  3493.   def draw_seph_v_rev_gradient_bar(x, y, cur, max, width = 8, height = 152,
  3494.       s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
  3495.     # Draw Border
  3496.     self.fill_rect(x, y, width, height, b_color)
  3497.     # Draws Bar
  3498.     for i in 1...((cur / max.to_f) * (height - 1))
  3499.       c = Color.color_between(s_color, e_color, (i / height.to_f))
  3500.       self.fill_rect(x + 1, y + height - 1 - i, width - 2, 1, c)
  3501.     end
  3502.   end
  3503.   #-------------------------------------------------------------------------
  3504.   # * Name      : Draw Vertical Slant Bar
  3505.   #   Info      : Draws a slanted Gradient Bar
  3506.   #   Author    : SephirothSpawn
  3507.   #   Call Info : Four to Nice Arguments
  3508.   #               Integer x and y Defines Position
  3509.   #               Integer min and max Defines Dimensions of Bar
  3510.   #               Start Bar Color and End Color - Colors for Gradient Bar
  3511.   #               Background Bar Color
  3512.   #-------------------------------------------------------------------------
  3513.   def draw_v_slant_bar(x, y, cur, max, width = 8, height = 152,
  3514.       s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
  3515.     # Draw Border
  3516.     for i in 0..width
  3517.       self.fill_rect(x + i, y + i, 1, height - width, b_color)
  3518.     end
  3519.     # Draws Bar
  3520.     for i in 1...((cur / max.to_f) * (height - width - 1))
  3521.       for j in 1...(width)
  3522.         c = Color.color_between(s_color, e_color, (i / height.to_f))
  3523.         self.fill_rect(x + j, y + i + j, 1, 1, c)
  3524.       end
  3525.     end
  3526.   end
  3527.   #-------------------------------------------------------------------------
  3528.   # * Name      : Draw Vertical Reverse Slant Bar
  3529.   #   Info      : Draws a slanted Gradient Bar
  3530.   #   Author    : SephirothSpawn
  3531.   #   Call Info : Four to Nine Arguments
  3532.   #               Integer x and y Defines Position
  3533.   #               Integer min and max Defines Dimensions of Bar
  3534.   #               Start Bar Color and End Color - Colors for Gradient Bar
  3535.   #               Background Bar Color
  3536.   #-------------------------------------------------------------------------
  3537.   def draw_v_rev_slant_bar(x, y, cur, max, width = 8, height = 152,
  3538.       s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
  3539.     # Draw Border
  3540.     for i in 0..width
  3541.       self.fill_rect(x + i, y + i, 1, height - width, b_color)
  3542.     end
  3543.     # Draws Bar
  3544.     for i in 1...( (cur / max.to_f) * (height - width - 1))
  3545.       for j in 1...(width)
  3546.         c = Color.color_between(s_color, e_color, (i / height.to_f))
  3547.         self.fill_rect(x + width - j, y + height - i - j - 1, 1, 1, c)
  3548.       end
  3549.     end
  3550.   end
  3551.   #-------------------------------------------------------------------------
  3552.   #   Name      : Draw Vertical Circular Gradient Bar
  3553.   #   Info      : Draws a Circular Gradient Bar
  3554.   #   Author    : Trickster / SephirothSpawn
  3555.   #   Call Info : Six to Nine Arguments
  3556.   #               Integer X, Y, Width, Height, Current, and Max
  3557.   #               Color start, finish, back all default to Black
  3558.   #               X and Y Define Position
  3559.   #               Width and Height defines dimensions
  3560.   #               Current Defines How Much of the Bar to Draw
  3561.   #               Max Defines the Maximum Value
  3562.   #               start, finish, back is the starting, ending, and back color
  3563.   #-------------------------------------------------------------------------
  3564.   def draw_trick_v_circular_bar(x, y, width, height, current, max,
  3565.       start = Color.red, finish = Color.yellow, back = Color.black)
  3566.     # Draw Background
  3567.     radius = width / 2
  3568.     # Draw Rectangle Center
  3569.     fill_rect(x, y + radius, width, height - width, back)
  3570.     # Draws Ends
  3571.     (radius + 1).times do |y1|
  3572.       # Get X
  3573.       x1 = Math.sqrt(radius ** 2 - (radius - y1) ** 2).round
  3574.       # Draw Line of Back Color at Left Edge
  3575.       fill_rect(x - x1 + radius, y + y1, 2 * x1, 1, back)
  3576.       # Draw Line of Back Color at Right Edge
  3577.       fill_rect(x - x1 + radius, y + height - y1, 2 * x1, 1, back)
  3578.     end
  3579.     # Get Percentage
  3580.     percentage = current / max.to_f
  3581.     # Return if not a finite number
  3582.     return if not percentage.finite?
  3583.     # Decrease Width and Height increase x and y
  3584.     x, y, width, height = x + 2, y + 2, width - 4, height - 4
  3585.     # Get new Radius
  3586.     radius = width / 2
  3587.     # Get Bar Height
  3588.     barheight = height * percentage
  3589.     # Draws Top End
  3590.     (radius + 1).times do |y1|
  3591.       # Stop if Past Height
  3592.       break if y1 > barheight
  3593.       # Get T (Parameter)
  3594.       t = radius - y1
  3595.       # Get X
  3596.       x1 = Math.sqrt(radius ** 2 - t ** 2).round
  3597.       # Get Color
  3598.       color = Color.color_between(start, finish, (y1 / height.to_f))
  3599.       # Draw Line
  3600.       fill_rect(x - x1 + radius, y + y1, 2 * x1, 1, color)
  3601.     end
  3602.     # Run From Radius upto Rectangles End
  3603.     (height - width + 1).times do |t|
  3604.       # Get Y1
  3605.       y1 = t + radius
  3606.       # Break if Past Width
  3607.       break if y1 > barheight
  3608.       # Get Color
  3609.       color = Color.color_between(start, finish, (y1 / height.to_f))
  3610.       # Draw Line
  3611.       fill_rect(x, y + y1, width, 1, color)
  3612.     end
  3613.     # Draws Bottom End
  3614.     radius.times do |t|
  3615.       # Get Y
  3616.       y1 = height - radius + t
  3617.       # Get X
  3618.       x1 = Math.sqrt(radius ** 2 - t ** 2).round
  3619.       # Stop if Past Height
  3620.       break if y1 > barheight
  3621.       # Get Color
  3622.       color = Color.color_between(start, finish, (y1 / height.to_f))
  3623.       # Draw Line
  3624.       fill_rect(x - x1 + radius, y + y1, 2 * x1, 1, color)
  3625.     end
  3626.   end
  3627.   #-------------------------------------------------------------------------
  3628.   #   Name      : Draw Vertical Reverse Circular Gradient Bar
  3629.   #   Info      : Draws a Circular Gradient Bar
  3630.   #   Author    : Trickster / SephirothSpawn
  3631.   #   Call Info : Six to Nine Arguments
  3632.   #               Integer X, Y, Width, Height, Current, and Max
  3633.   #               Color start, finish, back all default to Black
  3634.   #               X and Y Define Position
  3635.   #               Width and Height defines dimensions
  3636.   #               Current Defines How Much of the Bar to Draw
  3637.   #               Max Defines the Maximum Value
  3638.   #               start, finish, back is the starting, ending, and back color
  3639.   #-------------------------------------------------------------------------
  3640.   def draw_trick_v_rev_circular_bar(x, y, width, height, current, max,
  3641.       start = Color.red, finish = Color.yellow, back = Color.black)
  3642.     # Draw Background
  3643.     radius = width / 2
  3644.     # Draw Rectangle Center
  3645.     fill_rect(x, y + radius, width, height - width, back)
  3646.     # Draws Ends
  3647.     (radius + 1).times do |y1|
  3648.       # Get X
  3649.       x1 = Math.sqrt(radius ** 2 - (radius - y1) ** 2).round
  3650.       # Draw Line of Back Color at Left Edge
  3651.       fill_rect(x - x1 + radius, y + y1, 2 * x1, 1, back)
  3652.       # Draw Line of Back Color at Right Edge
  3653.       fill_rect(x - x1 + radius, y + height - y1, 2 * x1, 1, back)
  3654.     end
  3655.     # Get Percentage
  3656.     percentage = current / max.to_f
  3657.     # Return if not a finite number
  3658.     return if not percentage.finite?
  3659.     # Decrease Width and Height increase x and y
  3660.     x, y, width, height = x + 2, y + 2, width - 4, height - 4
  3661.     # Get new Radius
  3662.     radius = width / 2
  3663.     # Get Bar Height
  3664.     barheight = height * percentage
  3665.     # Draws Bottom End
  3666.     (radius + 1).times do |y1|
  3667.       # Stop if Past Height
  3668.       break if y1 > barheight
  3669.       # Get X
  3670.       x1 = Math.sqrt(radius ** 2 - (radius - y1) ** 2).round
  3671.       # Get Color
  3672.       color = Color.color_between(start, finish, (y1 / height.to_f))
  3673.       # Draw Line
  3674.       fill_rect(x - x1 + radius, y + height - y1, 2 * x1, 1, color)
  3675.     end
  3676.     # Run From Radius upto Rectangles End
  3677.     (height - width + 1).times do |t|
  3678.       # Get Y1
  3679.       y1 = t + radius
  3680.       # Break if Past Width
  3681.       break if y1 > barheight
  3682.       # Get Color
  3683.       color = Color.color_between(start, finish, (y1 / height.to_f))
  3684.       # Draw Line
  3685.       fill_rect(x, y + height - y1, width, 1, color)
  3686.     end
  3687.     # Draws Bottom End
  3688.     radius.times do |t|
  3689.       # Get Y
  3690.       y1 = radius - t
  3691.       # Stop if Past Height
  3692.       break if height - y1 > barheight
  3693.       # Get X
  3694.       x1 = Math.sqrt(radius ** 2 - t ** 2).round
  3695.       # Get Color
  3696.       color = Color.color_between(start, finish, ((height - y1) / height.to_f))
  3697.       # Draw Line
  3698.       fill_rect(x - x1 + radius, y + y1, 2 * x1, 1, color)
  3699.     end
  3700.   end
  3701.   #-------------------------------------------------------------------------
  3702.   # * Name      : Draw Clockwise Circular Arc Region
  3703.   #   Info      : Draws Circular Gradient clockwise, from s_angle to e_angle
  3704.   #   Author    : SephirothSpawn
  3705.   #   Call Info : Eight to Nine Arguments
  3706.   #               center_x and center_y
  3707.   #               min_radius, max_radius
  3708.   #               s_angle & e_angle (in Degrees)
  3709.   #               currect_value & max_value
  3710.   #               bar_color
  3711.   #-------------------------------------------------------------------------
  3712.   def draw_cw_arc_region(x, y, min_rad, max_rad, s_angle, e_angle,
  3713.                          cur_v, max_v, color = Color.red)
  3714.     # Calculate Inner Regions
  3715.     inner_region = {}
  3716.     for i in 0..min_rad
  3717.       y_ = Integer((min_rad ** 2 - i ** 2) ** 0.5)
  3718.       inner_region[x + i] = y_
  3719.       inner_region[x - i] = y_
  3720.     end
  3721.     # Make Degrees between 0 - 360
  3722.     s_angle %= 360 ; e_angle %= 360
  3723.     # Make s_angle Greater than e_angle
  3724.     s_angle += 360 if  s_angle < e_angle
  3725.     # Calculate Difference
  3726.     diff = s_angle - e_angle
  3727.     # Get Percent Difference
  3728.     p_diff = Integer(diff * cur_v / max_v.to_f)
  3729.     # Modify e_angle with percent Diffence
  3730.     e_angle = s_angle - p_diff
  3731.     # Pass from left to right
  3732.     for i in (x - max_rad)..(x + max_rad)
  3733.       # Get Y max at that pixel
  3734.       y_max = Integer((max_rad ** 2 - (x - i).abs ** 2) ** 0.5)
  3735.       # Pass from top to bottom
  3736.       for j in (y - y_max)..(y + y_max)
  3737.         # If within inner-region limits
  3738.         if i.between?(x - min_rad, x + min_rad)
  3739.           # If Inner region has key
  3740.           if inner_region.has_key?(i)
  3741.             # Get Inner Value
  3742.             inner = inner_region[i]
  3743.             # Skip if Between inner region limits
  3744.             next if j.between?(x - inner, x + inner)
  3745.           end
  3746.         end
  3747.         # Gets Angle of pixel from center
  3748.         a = Math.atan2((j - y).abs, (i - x).abs.to_f) * 180 / Math::PI
  3749.         # Get 360 Degree Angle
  3750.         if (i - x) > 0
  3751.           a = 360 - a if (j - y) > 0
  3752.         else
  3753.           a = 180 + ((j - y) > 0 ? a : -a)
  3754.         end
  3755.         # Set Pixel if Between Angles
  3756.         if Math.cw_between_angles?(a, s_angle, e_angle)
  3757.           set_pixel(i, j, color)
  3758.         end
  3759.       end
  3760.     end
  3761.   end
  3762.   #-------------------------------------------------------------------------
  3763.   # * Name      : Draw Counter-Clockwise Circular Arc Region
  3764.   #   Info      : Draws Circular Gradient ccw, from s_angle to e_angle
  3765.   #   Author    : SephirothSpawn
  3766.   #   Call Info : Eight to Nine Arguments
  3767.   #               center_x and center_y
  3768.   #               min_radius, max_radius
  3769.   #               s_angle & e_angle (in Degrees)
  3770.   #               currect_value & max_value
  3771.   #               bar_color
  3772.   #-------------------------------------------------------------------------
  3773.   def draw_ccw_arc_region(x, y, min_rad, max_rad, s_angle, e_angle,
  3774.                           cur_v, max_v, color = Color.red)
  3775.     # Calculate Inner Regions
  3776.     inner_region = {}
  3777.     for i in 0..min_rad
  3778.       sa = i
  3779.       y_ = Integer((min_rad ** 2 - sa ** 2) ** 0.5)
  3780.       inner_region[x + i] = y_
  3781.       inner_region[x - i] = y_
  3782.     end
  3783.     # Make Degrees between 0 - 360
  3784.     s_angle %= 360 ; e_angle %= 360
  3785.     # Make s_angle Greater than e_angle
  3786.     e_angle += 360 if  e_angle < s_angle
  3787.     # Calculate Difference
  3788.     diff = e_angle - s_angle
  3789.     # Get Percent Difference
  3790.     p_diff = Integer(diff * cur_v / max_v.to_f)
  3791.     # Modify e_angle with percent Diffence
  3792.     e_angle = s_angle + p_diff
  3793.     # Pass from left to right
  3794.     for i in (x - max_rad)..(x + max_rad)
  3795.       # Get Y max at that pixel
  3796.       y_max = Integer((max_rad ** 2 - (x - i).abs ** 2) ** 0.5)
  3797.       # Pass from top to bottom
  3798.       for j in (y - y_max)..(y + y_max)
  3799.         # If within inner-region limits
  3800.         if i.between?(x - min_rad, x + min_rad)
  3801.           # If Inner region has key
  3802.           if inner_region.has_key?(i)
  3803.             # Get Inner Value
  3804.             inner = inner_region[i]
  3805.             # Skip if Between inner region limits
  3806.             next if j.between?(x - inner, x + inner)
  3807.           end
  3808.         end
  3809.         # Gets Angle of pixel from center
  3810.         a = Math.atan2((j - y).abs, (i - x).abs.to_f) * 180 / Math::PI
  3811.         # Get 360 Degree Angle
  3812.         if (i - x) > 0
  3813.           a = 360 - a if (j - y) > 0
  3814.         else
  3815.           a = 180 + ((j - y) > 0 ? a : -a)
  3816.         end
  3817.         # Set Pixel if Between Angles
  3818.         if Math.cw_between_angles?(a, s_angle, e_angle)
  3819.           set_pixel(i, j, color)
  3820.         end
  3821.       end
  3822.     end
  3823.   end
  3824.   #-------------------------------------------------------------------------
  3825.   # * Name      : Draw Clockwise Gradient Circular Arc Region
  3826.   #   Info      : Draws Circular Gradient clockwise, from s_angle to e_angle
  3827.   #   Author    : SephirothSpawn
  3828.   #   Call Info : Eight to Ten Arguments
  3829.   #               center_x and center_y
  3830.   #               min_radius, max_radius
  3831.   #               s_angle & e_angle (in Degrees)
  3832.   #               currect_value & max_value
  3833.   #               start_bar_color & end_bar _color
  3834.   #-------------------------------------------------------------------------
  3835.   def draw_cw_grad_arc_region(x, y, min_rad, max_rad, s_angle, e_angle,
  3836.                               cur_v, max_v, s_color = Color.red,
  3837.                               e_color = Color.blue)
  3838.     # Calculate Inner Regions
  3839.     inner_region = {}
  3840.     for i in 0..min_rad
  3841.       y_ = Integer((min_rad ** 2 - i ** 2) ** 0.5)
  3842.       inner_region[x + i] = y_
  3843.       inner_region[x - i] = y_
  3844.     end
  3845.     # Make Degrees between 0 - 360
  3846.     s_angle %= 360 ; e_angle %= 360
  3847.     # Make s_angle Greater than e_angle
  3848.     s_angle += 360 if  s_angle < e_angle
  3849.     # Calculate Difference
  3850.     diff = s_angle - e_angle
  3851.     # Get Percent Difference
  3852.     p_diff = Integer(diff * cur_v / max_v.to_f)
  3853.     # Modify e_angle with percent Diffence
  3854.     e_angle = s_angle - p_diff
  3855.     # Pass from left to right
  3856.     for i in (x - max_rad)..(x + max_rad)
  3857.       # Get Y max at that pixel
  3858.       y_max = Integer((max_rad ** 2 - (x - i).abs ** 2) ** 0.5)
  3859.       # Pass from top to bottom
  3860.       for j in (y - y_max)..(y + y_max)
  3861.         # If within inner-region limits
  3862.         if i.between?(x - min_rad, x + min_rad)
  3863.           # If Inner region has key
  3864.           if inner_region.has_key?(i)
  3865.             # Get Inner Value
  3866.             inner = inner_region[i]
  3867.             # Skip if Between inner region limits
  3868.             next if j.between?(x - inner, x + inner)
  3869.           end
  3870.         end
  3871.         # Gets Angle of pixel from center
  3872.         a = Math.atan2((j - y).abs, (i - x).abs.to_f) * 180 / Math::PI
  3873.         # Get 360 Degree Angle
  3874.         if (i - x) > 0
  3875.           a = 360 - a if (j - y) > 0
  3876.         else
  3877.           a = 180 + ((j - y) > 0 ? a : -a)
  3878.         end
  3879.         # If Between Angles
  3880.         if Math.cw_between_angles?(a, s_angle, e_angle)
  3881.           # Get Color Value
  3882.           per = Math.cw_percent_between_angles(a, s_angle, s_angle - diff)
  3883.           color = Color.color_between(e_color, s_color, per)
  3884.           # Set Pixel
  3885.           set_pixel(i, j, color)
  3886.         end
  3887.       end
  3888.     end
  3889.   end
  3890.   #-------------------------------------------------------------------------
  3891.   # * Name      : Draw Counter-Clockwise Gradient Circular Arc Region
  3892.   #   Info      : Draws Circular Gradient ccw, from s_angle to e_angle
  3893.   #   Author    : SephirothSpawn
  3894.   #   Call Info : Eight to Ten Arguments
  3895.   #               center_x and center_y
  3896.   #               min_radius, max_radius
  3897.   #               s_angle & e_angle (in Degrees)
  3898.   #               currect_value & max_value
  3899.   #               start_bar_color & end_bar _color
  3900.   #-------------------------------------------------------------------------
  3901.   def draw_ccw_grad_arc_region(x, y, min_rad, max_rad, s_angle, e_angle,
  3902.                                cur_v, max_v, s_color = Color.red,
  3903.                                e_color = Color.blue)
  3904.     # Calculate Inner Regions
  3905.     inner_region = {}
  3906.     for i in 0..min_rad
  3907.       sa = i
  3908.       y_ = Integer((min_rad ** 2 - sa ** 2) ** 0.5)
  3909.       inner_region[x + i] = y_
  3910.       inner_region[x - i] = y_
  3911.     end
  3912.     # Make Degrees between 0 - 360
  3913.     s_angle %= 360 ; e_angle %= 360
  3914.     # Make s_angle Greater than e_angle
  3915.     e_angle += 360 if  e_angle < s_angle
  3916.     # Calculate Difference
  3917.     diff = e_angle - s_angle
  3918.     # Get Percent Difference
  3919.     p_diff = Integer(diff * cur_v / max_v.to_f)
  3920.     # Modify e_angle with percent Diffence
  3921.     e_angle = s_angle + p_diff
  3922.     # Pass from left to right
  3923.     for i in (x - max_rad)..(x + max_rad)
  3924.       # Get Y max at that pixel
  3925.       y_max = Integer((max_rad ** 2 - (x - i).abs ** 2) ** 0.5)
  3926.       # Pass from top to bottom
  3927.       for j in (y - y_max)..(y + y_max)
  3928.         # If within inner-region limits
  3929.         if i.between?(x - min_rad, x + min_rad)
  3930.           # If Inner region has key
  3931.           if inner_region.has_key?(i)
  3932.             # Get Inner Value
  3933.             inner = inner_region[i]
  3934.             # Skip if Between inner region limits
  3935.             next if j.between?(x - inner, x + inner)
  3936.           end
  3937.         end
  3938.         # Gets Angle of pixel from center
  3939.         a = Math.atan2((j - y).abs, (i - x).abs.to_f) * 180 / Math::PI
  3940.         # Get 360 Degree Angle
  3941.         if (i - x) > 0
  3942.           a = 360 - a if (j - y) > 0
  3943.         else
  3944.           a = 180 + ((j - y) > 0 ? a : -a)
  3945.         end
  3946.         # If Between Angles
  3947.         if Math.cw_between_angles?(a, s_angle, e_angle)
  3948.           # Get Color Value
  3949.           per = Math.ccw_percent_between_angles(a, s_angle, s_angle + diff)
  3950.           color = Color.color_between(s_color, e_color, per)
  3951.           # Set Pixel
  3952.           set_pixel(i, j, color)
  3953.         end
  3954.       end
  3955.     end
  3956.   end
  3957.   #-------------------------------------------------------------------------
  3958.   #   Name      : Draw Functional Gradient Bar
  3959.   #   Info      : Draws a Functional Gradient Bar
  3960.   #   Author    : Trickster
  3961.   #   Call Info : Seven to Nine Arguments
  3962.   #               Integer X, Y, Width, Height, Current, and Max
  3963.   #               Proc Function
  3964.   #               Color start and finish both Default to Black
  3965.   #               X and Y Define Position, Width and Height defines dimensions
  3966.   #               Function is a function of r and x1
  3967.   #                 Example proc {Math.sqrt(r**2 - x1**2)} (Circular)
  3968.   #               Current Defines How Much of the Bar to Draw
  3969.   #               Max Defines the Maximum Value
  3970.   #               start, finish is the starting and Ending Colors Respectively
  3971.   #-------------------------------------------------------------------------
  3972.   def draw_trick_function_bar(x, y, width, height, function, current, max,
  3973.       start = Color.new(0,0,0), finish = Color.new(0,0,0),
  3974.       back = Color.new(0,0,0))
  3975.     # Get Change in Colors
  3976.     chred, chblue = finish.red - start.red, finish.blue - start.blue
  3977.     chgreen, chalpha = finish.green - start.green, finish.alpha - start.alpha
  3978.     # Draw Background
  3979.     radius = height / 2
  3980.     # Setup Values Array
  3981.     values = []
  3982.     # Draw Rectangle Center
  3983.     fill_rect(x + radius, y, width - height, height, back)
  3984.     # Draws Ends
  3985.     (radius + 1).times do |x1|
  3986.       # Get Parameter
  3987.       t = radius - x1
  3988.       # Get Y
  3989.       y1 = function.call(radius, t).round
  3990.       # Get Height
  3991.       h = 2 * y1
  3992.       # Draw Line of Back Color at Left Edge
  3993.       fill_rect(x + x1, y - y1 + radius, 1, h, back)
  3994.       # Draw Line of Back Color at Right Edge
  3995.       fill_rect(x + width - x1, y - y1 + radius, 1, h, back)
  3996.     end
  3997.     # Get Percentage
  3998.     percentage = current / max.to_f
  3999.     # Return if not a finite number
  4000.     return if not percentage.finite?
  4001.     # Decrease Width and Height increase x and y
  4002.     width -= 4
  4003.     height -= 4
  4004.     x += 2
  4005.     y += 2
  4006.     # Get new Radius
  4007.     radius = height / 2
  4008.     # Get Bar Width
  4009.     barwidth = width * percentage
  4010.     # Draws Left End
  4011.     (radius + 1).times do |x1|
  4012.       # Stop if Past Width
  4013.       break if x1 > barwidth
  4014.       # Get T (Parameter)
  4015.       t = radius - x1
  4016.       # Get Width Change
  4017.       chwidth = x1
  4018.       # Get Colors
  4019.       red = start.red + chred * chwidth / width
  4020.       green = start.green + chgreen * chwidth / width
  4021.       blue = start.blue + chblue * chwidth / width
  4022.       alpha = start.alpha + chalpha * chwidth / width
  4023.       # Get Y
  4024.       y1 = function.call(radius, t).round
  4025.       # Push onto Values
  4026.       values << y1
  4027.       # Get Height
  4028.       h = 2 * y1
  4029.       # Get Color
  4030.       color = Color.new(red, green, blue, alpha) if alpha != 255
  4031.       color = Color.new(red, green, blue) if alpha == 255
  4032.       # Draw Line
  4033.       fill_rect(x + x1, y - y1 + radius, 1, h, color)
  4034.     end
  4035.     # Run From Radius upto Rectangles End
  4036.     (width - height + 1).times do |t|
  4037.       # Get X1
  4038.       x1 = t + radius
  4039.       # Break if Past Width
  4040.       break if x1 > barwidth
  4041.       # Get Width Change
  4042.       chwidth = x1
  4043.       # Get Colors
  4044.       red = start.red + chred * chwidth / width
  4045.       green = start.green + chgreen * chwidth / width
  4046.       blue = start.blue + chblue * chwidth / width
  4047.       alpha = start.alpha + chalpha * chwidth / width
  4048.       # Get Color
  4049.       color = Color.new(red, green, blue, alpha) if alpha != 255
  4050.       color = Color.new(red, green, blue) if alpha == 255
  4051.       # Draw Line
  4052.       fill_rect(x + x1, y, 1, height, color)
  4053.     end
  4054.     # Draws Right End
  4055.     radius.times do |t|
  4056.       # Get X
  4057.       x1 = width - radius + t
  4058.       # Stop if Past Width
  4059.       break if x1 > barwidth
  4060.       # Get Width Change
  4061.       chwidth = x1
  4062.       # Get Colors
  4063.       red = start.red + chred * chwidth / width
  4064.       green = start.green + chgreen * chwidth / width
  4065.       blue = start.blue + chblue * chwidth / width
  4066.       alpha = start.alpha + chalpha * chwidth / width
  4067.       # Get Y
  4068.       y1 = values[radius-t]
  4069.       # Get Height
  4070.       h = 2 * y1
  4071.       # Get Color
  4072.       color = Color.new(red, green, blue, alpha) if alpha != 255
  4073.       color = Color.new(red, green, blue) if alpha == 255
  4074.       # Draw Line
  4075.       fill_rect(x + x1, y - y1 + radius, 1, h, color)
  4076.     end
  4077.   end
  4078.   #-------------------------------------------------------------------------
  4079.   #   Name      : Draw Trick Gradient Bar
  4080.   #   Info      : Draws a Gradient Bar (Uses Pictures)
  4081.   #   Author    : Trickster
  4082.   #   Call Info : Thirteen Arguments
  4083.   #               Integer X and Y Define Position
  4084.   #               Integer Min and Max Define How Much is Drawn
  4085.   #               String File Is the File to load
  4086.   #               Integer Width and Height defines dimensions (def bar size)
  4087.   #               String Back and Back2 Are the Backgrounds for the bar
  4088.   #               Integer cx,cy,dx,dy Define the Borders of the Backgrounds
  4089.   #-------------------------------------------------------------------------
  4090.   def draw_trick_gradient_bar(x, y, min, max, file, width = nil, height = nil,
  4091.     back = 'Back', back2 = 'Back2', cx = 1, cy = 1, dx = 1, dy = 1)
  4092.     # Get Bar and Background Bitmaps
  4093.     bar = RPG::Cache.gradient(file)
  4094.     back = RPG::Cache.gradient(back)
  4095.     back2 = RPG::Cache.gradient(back2)
  4096.     # Get Zoom X and Zoom Y
  4097.     zoom_x = width != nil ? width : back.width
  4098.     zoom_y = height != nil ? height : back.height
  4099.     # Get Percentage
  4100.     percent = max == 0 ? 0 : min / max.to_f
  4101.     # Create Destination Rect Objects
  4102.     back_dest = Rect.new(x, y, zoom_x, zoom_y)
  4103.     back2_dest = Rect.new(x + dx, y + dy, zoom_x - dx * 2, zoom_y - dy * 2)
  4104.     bar_dest = Rect.new(x + cx, y + cy, zoom_x * percent - cx*2, zoom_y - cy*2)
  4105.     # Get Source Rect
  4106.     source = Rect.new(0, 0, bar.width * percent, bar.height)
  4107.     # Draw Onto Window
  4108.     stretch_blt(back_dest, back, back.rect)
  4109.     stretch_blt(back2_dest, back2, back2.rect)
  4110.     stretch_blt(bar_dest, bar, source)
  4111.   end  
  4112.   #-------------------------------------------------------------------------
  4113.   #   Name      : Draw Trick Vertical Gradient Bar
  4114.   #   Info      : Draws a Gradient Bar (Uses Pictures)
  4115.   #   Author    : Trickster
  4116.   #   Call Info : Thirteen Arguments
  4117.   #               Integer X and Y Define Position
  4118.   #               Integer Min and Max Define How Much is Drawn
  4119.   #               String File Is the File to load
  4120.   #               Integer Width and Height defines dimensions (def bar size)
  4121.   #               String Back and Back2 Are the Backgrounds for the bar
  4122.   #               Integer cx,cy,dx,dy Define the Borders of the Backgrounds
  4123.   #-------------------------------------------------------------------------
  4124.   def draw_trick_vertical_gradient_bar(x, y, min, max, file, width = nil,
  4125.     height = nil, back = 'Back', back2 = 'Back2', cx = 1, cy = 1, dx = 1, dy = 1)
  4126.     # Ger Bar Bitmaps
  4127.     bar = RPG::Cache.gradient(file)
  4128.     back = RPG::Cache.gradient(back)
  4129.     back2 = RPG::Cache.gradient(back2)
  4130.     # Get Zoom X and Zoom Y
  4131.     zoom_x = width != nil ? width : back.width
  4132.     zoom_y = height != nil ? height : back.height
  4133.     # Get Percentage
  4134.     percent = max == 0 ? 0 : min / max.to_f
  4135.     # Get Bar Y
  4136.     bar_y = (zoom_y - zoom_y * percent).ceil
  4137.     # Get Bar Source Y
  4138.     source_y = bar.height - bar.height * percent
  4139.     # Get Bar Dest Y
  4140.     dest_y = (zoom_y * percent).to_i
  4141.     # Create Destination Rect Objects
  4142.     back_dest = Rect.new(x, y, zoom_x, zoom_y)
  4143.     back2_dest = Rect.new(x + dx, y + dy, zoom_x - dx * 2, zoom_y - dy * 2)
  4144.     bar_dest = Rect.new(x + cx, y + bar_y + cy, zoom_x - cx * 2, dest_y - cy * 2)
  4145.     # Get Source Rect
  4146.     source = Rect.new(0, source_y, bar.width, bar.height * percent)
  4147.     # Draw Onto Window
  4148.     stretch_blt(back_dest_rect, back, back_source_rect)
  4149.     stretch_blt(back2_dest_rect, back2, back2_source_rect)
  4150.     stretch_blt(bar_dest_rect, bar, source)
  4151.   end
  4152.   #-------------------------------------------------------------------------
  4153.   #   Name      : Draw Trick Gradient Bar Background
  4154.   #   Info      : Draws a Gradient Bar Background (Uses Pictures)
  4155.   #   Author:    Trickster
  4156.   #   Call Info : Thirteen Arguments
  4157.   #              Integer X and Y Define Position
  4158.   #              Integer Min and Max Define How Much is Drawn
  4159.   #              String File Is the File to load
  4160.   #              Integer Width and Height is the width and height (Defaults to nil)
  4161.   #              String Back and Back2 Are the Backgrounds for the bar
  4162.   #              Integer cx,cy,dx,dy Define the Borders of the Backgrounds
  4163.   #-------------------------------------------------------------------------
  4164.   def draw_trick_gradient_bar_back(x, y, width = nil, height = nil, back = 'Back',
  4165.     back2 = 'Back2', dx = 1, dy = 1)
  4166.     # Get Bitmaps
  4167.     back = RPG::Cache.gradient(back)
  4168.     back2 = RPG::Cache.gradient(back2)
  4169.     # Get Zoom X and Zoom Y
  4170.     zoom_x = width != nil ? width : back.width
  4171.     zoom_y = height != nil ? height : back.height
  4172.     # Get Destination Rects
  4173.     back_dest_rect = Rect.new(x, y, zoom_x, zoom_y)
  4174.     back2_dest_rect = Rect.new(x + dx, y + dy, zoom_x - dx * 2, zoom_y - dy * 2)
  4175.     # Draw Border
  4176.     stretch_blt(back_dest_rect, back, back.rect)
  4177.     # Draw Background
  4178.     stretch_blt(back2_dest_rect, back2, back2.rect)
  4179.   end
  4180.   #-------------------------------------------------------------------------
  4181.   #   Name      : Draw Trick Gradient Bar Substance
  4182.   #   Info      : Draws a Gradient Bar w/o the Background(Uses Pictures)
  4183.   #   Author:    Trickster
  4184.   #   Call Info : Ten Arguments
  4185.   #              Integer X and Y Define Position
  4186.   #              Integer Min and Max Define How Much is Drawn
  4187.   #              String File Is the File to load
  4188.   #              Integer Width and Height is the width and height (Defaults to nil)
  4189.   #              String Back is the background used for the bar
  4190.   #              Integer cx,cy Define the Borders of the Backgrounds
  4191.   #-------------------------------------------------------------------------
  4192.   def draw_trick_gradient_bar_sub(x, y, min, max, file, width = nil, height = nil,
  4193.     back = 'Back', cx = 1, cy = 1, slanted = false)
  4194.     # Get Bitmaps
  4195.     bar = RPG::Cache.gradient(file)
  4196.     back = RPG::Cache.gradient(back)
  4197.     # Get Zoom X and Zoom Y
  4198.     zoom_x = width != nil ? width : back.width
  4199.     zoom_y = height != nil ? height : back.height
  4200.     # Get Percentage
  4201.     percent = max == 0 ? 0 : min / max.to_f
  4202.     # Get Destination Rect
  4203.     bar_dest_rect = Rect.new(x+cx, y+cy, zoom_x * percent - cx*2, zoom_y - cy*2)
  4204.     # Get Source Rect
  4205.     bar_source_rect = Rect.new(0, 0, bar.width * percent, bar.height)
  4206.     # Draw Bitmap
  4207.     stretch_blt(bar_dest_rect, bar, bar_source_rect)
  4208.     # If Slanted
  4209.     if slanted
  4210.       # Setup Transparent Color
  4211.       color = Color.new(0,0,0,0)
  4212.       # Run Through and remove edges
  4213.       (0...zoom_y).each do |i|
  4214.         # Get Height
  4215.         x_i = zoom_y - 1 - i
  4216.         # Fill Lines at Start and End
  4217.         fill_rect(x + i, y, 1, x_i, color)
  4218.         fill_rect(x + zoom_x * percent - cx*2 - i, y + zoom_y - x_i, 1, x_i, color)
  4219.       end
  4220.     end
  4221.   end
  4222.   #-------------------------------------------------------------------------
  4223.   # * Name      : Shade Gradient Section
  4224.   #   Info      : Shades a section from (cx,cy), (x1,y1), (x2,y2) w/ gradient
  4225.   #   Author    : Trickster
  4226.   #   Call Info : Six to Ten Arguments
  4227.   #               Integer cx, cy, x1, y1, x2, y2 - Points
  4228.   #               Integer Thick - Line Thickness
  4229.   #               Integer Step - how many lines to draw (lower = higher accuracy)
  4230.   #               Color start_color, end_color - Start and end colors
  4231.   #-------------------------------------------------------------------------
  4232.   def shade_gradient_section(cx, cy, x1, y1, x2, y2, thick = 1, step = 1,
  4233.     start_color = Color.new(0, 0, 0), end_color = start_color)
  4234.     # Reverse all parameters sent if 2 x is less than the first x
  4235.     x1, x2, y1, y2 = x2, x1, y2, y1 if x2 < x1    
  4236.     # Get Slope
  4237.     slope = (y2 - y1).to_f / (x2 - x1)
  4238.     # If Slope is infinite
  4239.     if slope.infinite?
  4240.       y1.step(y2, step) {|y| draw_gradient_line(cx, cy, x1, y, thick, start_color, end_color)}
  4241.     # If Slope is zero
  4242.     elsif slope.zero?
  4243.       x1.step(x2, step) {|x| draw_gradient_line(cx, cy, x, y1, thick, start_color, end_color)}
  4244.     elsif not slope.nan?
  4245.       # Get Y intercept
  4246.       yint = y1 - slope * x1
  4247.       x1.step(x2, step) {|x| draw_gradient_line(cx, cy, x, slope * x + yint, thick, start_color, end_color)}
  4248.     end
  4249.   end
  4250.   #-------------------------------------------------------------------------
  4251.   # * Name      : Vertical Gradient Pixel Change
  4252.   #   Info      : Changes Pixels to Linear Gradient
  4253.   #   Author    : SephirothSpawn
  4254.   #   Call Info : Two to Three Arguments
  4255.   #               Start Color and End Color
  4256.   #               Optional Rect, rect of bitmap being changed
  4257.   #-------------------------------------------------------------------------
  4258.   def v_gradient_pixel_change(sc = Color.red, ec = Color.blue, r = rect)
  4259.     # Pass From Top to Bottom
  4260.     for y_ in (r.y)...(r.y + r.height)
  4261.       # Get Color
  4262.       color = Color.color_between(sc, ec, (y_ / (r.height).to_f))
  4263.       # Pass From Left to Right
  4264.       for x_ in (r.x)...(r.x + r.width)
  4265.         # Gets Alpha Pixel
  4266.         a = get_pixel(x_, y_).alpha
  4267.         # Skip if 0 Alpha
  4268.         next if a == 0
  4269.         # Set Color Alpha
  4270.         color.alpha = a
  4271.         # Set Pixel
  4272.         set_pixel(x_, y_, color)
  4273.       end
  4274.     end
  4275.   end
  4276.   #-------------------------------------------------------------------------
  4277.   # * Name      : Horizontal Gradient Pixel Change
  4278.   #   Info      : Changes Pixels to Linear Gradient
  4279.   #   Author    : SephirothSpawn
  4280.   #   Call Info : Two to Three Arguments
  4281.   #               Start Color and End Color
  4282.   #               Optional Rect, rect of bitmap being changed
  4283.   #-------------------------------------------------------------------------
  4284.   def h_gradient_pixel_change(sc = Color.red, ec = Color.blue, r = rect)
  4285.     # Passes From Left to Right
  4286.     for x_ in (r.x)...(r.x + r.width)
  4287.       # Get Color
  4288.       color = Color.color_between(sc, ec, (x_ / r.width.to_f))
  4289.       # Pass From Top to Bottom
  4290.       for y_ in (r.y)...(r.y + r.height)
  4291.         # Gets Alpha Pixel
  4292.         a = get_pixel(x_, y_).alpha
  4293.         # Skip if 0 Alpha
  4294.         next if a == 0
  4295.         # Set Color Alpha
  4296.         color.alpha = a
  4297.         # Set Pixel
  4298.         set_pixel(x_, y_, color)
  4299.       end
  4300.     end
  4301.   end
  4302. end
  4303.  
  4304. #==============================================================================
  4305. # ** RGSS.Bitmap.image
  4306. #------------------------------------------------------------------------------
  4307. # Description:
  4308. # ------------
  4309. # Methods created for the Bitmap class that manipulates the bitmap. Methods
  4310. # include flipping, stretching, and erasing.
  4311. #  
  4312. # Method List:
  4313. # ------------
  4314. # erase
  4315. # flip_horizontal
  4316. # flip_horizontal!
  4317. # flip_vertical
  4318. # flip_vertical!
  4319. # frames_flip_horizontal!
  4320. # frames_flip_vertical!
  4321. # stretch
  4322. # blur_area
  4323. # add_bitmap_blend
  4324. # sub_bitmap_blend
  4325. #==============================================================================
  4326.  
  4327. MACL::Loaded << 'RGSS.Bitmap.image'
  4328.  
  4329. #==============================================================================
  4330. # ** Bitmap
  4331. #==============================================================================
  4332.  
  4333. class Bitmap
  4334.   #-------------------------------------------------------------------------
  4335.   # * Name      : Erase
  4336.   #   Info      : This method clears a part of the bitmap
  4337.   #   Author    : Selwyn
  4338.   #   Call Info : One or Four arguments,
  4339.   #               One Argument : Rect ; Four arguments : Integers
  4340.   #               One Argument  : Rect.new(x, y, width, height)
  4341.   #               Four Arguments : x, y, width, height
  4342.   #   Comment   : works the same as the build-in method 'clear'
  4343.   #               but only for a portion of the bitmap
  4344.   #-------------------------------------------------------------------------
  4345.   def erase(*args)
  4346.     # If One Argument Sent
  4347.     if args.size == 1
  4348.       # Set Rect
  4349.       rect = args
  4350.     # If Four Arguments Sent
  4351.     elsif args.size == 4
  4352.       # Create Rect
  4353.       rect = Rect.new(*args)
  4354.     end
  4355.     # Erase (Set To Transparent Color)
  4356.     fill_rect(rect, Color.new(0, 0, 0, 0))
  4357.   end
  4358.   #-------------------------------------------------------------------------
  4359.   #   Name      : Flip Horizontally
  4360.   #   Info      : Flips Bitmap Horizontally
  4361.   #   Author    : Trickster
  4362.   #   Call Info : No Arguments
  4363.   #-------------------------------------------------------------------------
  4364.   def flip_horizontal
  4365.     # Create Flipped Bitmap
  4366.     flipped = Bitmap.new(width, height)
  4367.     # Create Rect
  4368.     rect = Rect.new(0, 0, 1, height)
  4369.     # Do Width Times
  4370.     width.times do |i|
  4371.       # Set X
  4372.       rect.x = width - 1 - i
  4373.       # Draw on other side
  4374.       flipped.blt(i, 0, self, rect)
  4375.     end
  4376.     # Return Flipped Bitmap
  4377.     return flipped
  4378.   end
  4379.   #-------------------------------------------------------------------------
  4380.   #   Name      : Flip Horizontally!
  4381.   #   Info      : Flips Bitmap Horizontally Modifies the Bitmap
  4382.   #   Author    : Trickster
  4383.   #   Call Info : No Arguments
  4384.   #-------------------------------------------------------------------------
  4385.   def flip_horizontal!
  4386.     # Create Flipped Bitmap
  4387.     flipped = Bitmap.new(width, height)
  4388.     # Create Rect
  4389.     flip_rect = Rect.new(0, 0, 1, height)
  4390.     # Do Width Times
  4391.     width.times do |i|
  4392.       # Set X
  4393.       flip_rect.x = width - 1 - i
  4394.       # Draw on other side
  4395.       flipped.blt(i, 0, self, flip_rect)
  4396.     end
  4397.     # Clear Bitmap
  4398.     clear
  4399.     # Draw Flipped
  4400.     blt(0, 0, flipped, rect)
  4401.     # Dispose Flipped
  4402.     flipped.dispose
  4403.   end
  4404.   #-------------------------------------------------------------------------
  4405.   #   Name      : Flip Vertically
  4406.   #   Info      : Flips Bitmap Vertically
  4407.   #   Author    : Trickster
  4408.   #   Call Info : No Arguments
  4409.   #-------------------------------------------------------------------------
  4410.   def flip_vertical
  4411.     # Create Flipped Bitmap
  4412.     flipped = Bitmap.new(width, height)
  4413.     # Create Rect
  4414.     flip_rect = Rect.new(0, 0, width, 1)
  4415.     # Do Width Times
  4416.     height.times do |i|
  4417.       # Set Y
  4418.       flip_rect.y = height - 1 - i
  4419.       # Draw on Other Side
  4420.       flipped.blt(0, i, self, flip_rect)
  4421.     end
  4422.     # Return Flipped
  4423.     return flipped
  4424.   end
  4425.   #-------------------------------------------------------------------------
  4426.   #   Name      : Flip Vertically!
  4427.   #   Info      : Flips Bitmap Vertically Modifies the Bitmap
  4428.   #   Author    : Trickster
  4429.   #   Call Info : No Arguments
  4430.   #-------------------------------------------------------------------------
  4431.   def flip_vertical!
  4432.     # Create Flipped Bitmap
  4433.     flipped = Bitmap.new(width, height)
  4434.     # Create Rect
  4435.     flip_rect = Rect.new(0, 0, width, 1)
  4436.     # Do Width Times
  4437.     height.times do |i|
  4438.       # Set Y
  4439.       flip_rect.y = height - 1 - i
  4440.       # Draw on Other Side
  4441.       flipped.blt(0, i, self, flip_rect)
  4442.     end
  4443.     # Clear Bitmap
  4444.     clear
  4445.     # Draw Flipped
  4446.     blt(0, 0, flipped, rect)
  4447.     # Dispose Flipped
  4448.     flipped.dispose
  4449.   end
  4450.   #-------------------------------------------------------------------------
  4451.   #   Name      : Flip Each Frame Horizontally
  4452.   #   Info      : Flips Each Frame Horizontally Modifies Itself
  4453.   #   Author    : Trickster
  4454.   #   Call Info : One Argument, Integer Frames the number of frames to split and
  4455.   #               flip
  4456.   #-------------------------------------------------------------------------
  4457.   def frames_flip_horizontal!(frames)
  4458.     # Get Frame Width
  4459.     frame_width = width / frames
  4460.     # Create A Frame Dummy Bitmap
  4461.     frame_bitmap = Bitmap.new(frame_width, height)
  4462.     # Create Rect
  4463.     rect = Rect.new(0, 0, frame_width, height)
  4464.     # Do Frames times
  4465.     frames.times do |i|
  4466.       # Clear Bitmap
  4467.       frame_bitmap.clear
  4468.       # Get X
  4469.       x = i * frame_width
  4470.       # Set Rect.x
  4471.       rect.x = x
  4472.       # Draw Piece of Bitmap onto dummy
  4473.       frame_bitmap.blt(0, 0, self, rect)
  4474.       # Flip Horizontally
  4475.       frame_bitmap.flip_horizontal!
  4476.       # Draw Onto Self
  4477.       blt(x, 0, frame_bitmap, frame_bitmap.rect)
  4478.     end
  4479.     # Dispose Dummy Bitmap
  4480.     frame_bitmap.dispose
  4481.   end
  4482.   #-------------------------------------------------------------------------
  4483.   #   Name      : Flip Each Frame Vertically
  4484.   #   Info      : Flips Each Frame Vertically Modifies Itself
  4485.   #   Author    : Trickster
  4486.   #   Call Info : One Argument, Integer Frames the number of frames to split and
  4487.   #               flip
  4488.   #-------------------------------------------------------------------------
  4489.   def frames_flip_vertical!(frames)
  4490.     # Get Frame Height
  4491.     frame_height = height / frames
  4492.     # Create A Frame Dummy Bitmap
  4493.     frame_bitmap = Bitmap.new(width, frame_height)
  4494.     # Create Rect
  4495.     rect = Rect.new(0, 0, width, frame_height)
  4496.     # Do Frames times
  4497.     frames.times do |i|
  4498.       # Clear Bitmap
  4499.       frame_bitmap.clear
  4500.       # Get Y
  4501.       y = i * frame_height
  4502.       # Set Rect.y
  4503.       rect.y = y
  4504.       # Draw Piece Of Bitmap onto Dummy
  4505.       frame_bitmap.blt(0, 0, self, rect)
  4506.       # Flip Vertically
  4507.       frame_bitmap.flip_vertical!
  4508.       # Draw onto Self
  4509.       blt(0, y, frame_bitmap, frame_bitmap.rect)
  4510.     end
  4511.     # Dispose Dummy Bitmap
  4512.     frame_bitmap.dispose
  4513.   end
  4514.   #-------------------------------------------------------------------------
  4515.   #   Name      : Stretch
  4516.   #   Info      : Stretches and Returns Bitmap
  4517.   #   Author    : Trickster
  4518.   #   Call Info : Two Arguments, Width and Height of Bitmap
  4519.   #-------------------------------------------------------------------------
  4520.   def stretch(width, height)
  4521.     # Create Dummy Bitmap
  4522.     dummy = Bitmap.new(width, height)
  4523.     # Stretch Blt onto dummy
  4524.     dummy.stretch_blt(Rect.new(0, 0, width, height), self, dummy.rect)
  4525.     # Return dummy
  4526.     return dummy
  4527.   end
  4528.   #-------------------------------------------------------------------------
  4529.   # * Name      : Blur Area
  4530.   #   Info      : Blurs area of bitmap
  4531.   #   Author    : SephirothSpawn
  4532.   #   Call Info : One Argument as hash
  4533.   #
  4534.   #               Defining Area of Blur
  4535.   #                hash['rect']             = Rect object
  4536.   #                hash['x'], 'y', 'w', 'h' = Rect properties
  4537.   #                nothing = Entire bitmap
  4538.   #
  4539.   #               Optional Settings (Defaults to @blur_settings)
  4540.   #                hash['spacing'] = Space between redraws
  4541.   #                hash['opacity'] = Max opacity of blut
  4542.   #                hash['offset']  = Number of times to space out blur
  4543.   #-------------------------------------------------------------------------
  4544.   def blur_area(settings = {})
  4545.     # Set Defaults
  4546.     @blur_settings.each do |default, setting|
  4547.       settings[default] = setting unless settings.has_key?(default)
  4548.     end
  4549.     # Collects Keys
  4550.     keys = settings.keys
  4551.     # Rect Defined Flag
  4552.     rect_defined = keys.include?('rect')
  4553.     # Rect Positions Defined
  4554.     rect_p_defined = keys.include?('x') && keys.include?('y') &&
  4555.                      keys.include?('w') && keys.include?('h')
  4556.     # If Rect Defined
  4557.     if rect_defined
  4558.       # Gets Rect
  4559.       rect = settings['rect']
  4560.       # Set Position Arguments
  4561.       x, y, w, h = rect.x, rect.y, rect.width, rect.height
  4562.     # If Rect Positions Defined
  4563.     elsif rect_p_defined
  4564.       # Set Position Arguments
  4565.       x, y, w, h = settings['x'], settings['y'], settings['w'], settings['h']
  4566.     else
  4567.       # Set Entire Bitmap
  4568.       x, y, w, h = 0, 0, self.width, self.height
  4569.     end
  4570.     # Duplicated Bitmap
  4571.     dummy = self.dup
  4572.     # Gets Spacing & Max Opacity
  4573.     spacing = settings['spacing']
  4574.     opacity = settings['opacity']
  4575.     # Number of Offsets
  4576.     settings['offset'].times do |i|
  4577.       # Collects Src Rect
  4578.       src_rects = []
  4579.       src_rects << Rect.new(x + i * spacing, y + i * spacing, w, h)
  4580.       src_rects << Rect.new(x - i * spacing, y + i * spacing, w, h)
  4581.       src_rects << Rect.new(x + i * spacing, y - i * spacing, w, h)
  4582.       src_rects << Rect.new(x - i * spacing, y - i * spacing, w, h)
  4583.       # Gets Opacity
  4584.       o = Integer(opacity * (settings['offset'] - i) / (settings['offset']))
  4585.       # Draws Rects
  4586.       src_rects.each do |src_rect|
  4587.         blt(x, y, dummy, src_rect, o)
  4588.       end
  4589.     end
  4590.   end
  4591.   #-------------------------------------------------------------------------
  4592.   # * Name      : Add Bitmap Blend
  4593.   #   Info      : Adds Bitmap Pixel Values to another
  4594.   #   Author    : Gibmaker / SephirothSpawn
  4595.   #   Call Info : Three to Four Arguments
  4596.   #               X and Y position
  4597.   #               src bitmap
  4598.   #               src bitmap rect
  4599.   #-------------------------------------------------------------------------
  4600.   def add_bitmap_blend(x, y, bitmap, src_rect = bitmap.rect)
  4601.     for i in 0...src_rect.width
  4602.       for j in 0...src_rect.height
  4603.         c1 = get_pixel(x + i, y + j)
  4604.         c2 = bitmap.get_pixel(src_rect.x + i, src_rect.y + j)
  4605.         nc = Color.new(c1.red + c2.red, c1.green + c2.green, c1.blue + c2.blue)
  4606.         set_pixel(x + i, y + j, nc)
  4607.       end
  4608.     end
  4609.   end
  4610.   #-------------------------------------------------------------------------
  4611.   # * Name      : Subtract Bitmap Blend
  4612.   #   Info      : Subtracts Bitmap Pixel Values to another
  4613.   #   Author    : Gibmaker / SephirothSpawn
  4614.   #   Call Info : Three to Four Arguments
  4615.   #               X and Y position
  4616.   #               src bitmap
  4617.   #               src bitmap rect
  4618.   #-------------------------------------------------------------------------
  4619.   def sub_bitmap_blend(x, y, bitmap, src_rect = bitmap.rect)
  4620.     for i in 0...src_rect.width
  4621.       for j in 0...src_rect.height
  4622.         c1 = get_pixel(x + i, y + j)
  4623.         c2 = bitmap.get_pixel(src_rect.x + i, src_rect.y + j)
  4624.         nc = Color.new(c1.red - c2.red, c1.green - c2.green, c1.blue - c2.blue)
  4625.         set_pixel(x + i, y + j, nc)
  4626.       end
  4627.     end
  4628.   end
  4629. end
  4630.  
  4631. #==============================================================================
  4632. # ** RGSS.Bitmap.memory
  4633. #------------------------------------------------------------------------------
  4634. # Description:
  4635. # ------------
  4636. # Specialized Methods for tbe bitmap class for remembering text. Also includes
  4637. # a non-laggy draw_text method based on the original draw text which stores the
  4638. # text in memory and calls blt instead of draw_text if it is needed again. One
  4639. # thing to remember is to call Bitmap.clear_text_memory
  4640. # Bitmap.clear_formatted_text_memory to dispose of all memorized sprites
  4641. # when you are finished (preferably at the end of a scene).
  4642. #    
  4643. # When Benchmarked drawing the string 'Hello World '*5 100 times the results
  4644. #   draw_text_memory around 0.266 seconds
  4645. #   draw_wrap_text_memory around 1.969 seconds
  4646. #   draw_formatted_text_memory around 0.266 seconds
  4647. #   draw_text around 6.235 seconds
  4648. #  
  4649. # Method List:
  4650. # ------------
  4651. # Bitmap.clear_text_memory
  4652. # Bitmap.clear_formatted_text_memory
  4653. # clear_memory
  4654. # cleat_to_memory
  4655. # draw_formatted_text_memory
  4656. # draw_text_memory
  4657. # draw_wrap_text_memory
  4658. # get_formatted_size (from Bitmap.text)
  4659. # set_memory
  4660. #==============================================================================
  4661.  
  4662. MACL::Loaded << 'RGSS.Bitmap.memory'
  4663.  
  4664. #==============================================================================
  4665. # ** Bitmap
  4666. #==============================================================================
  4667.  
  4668. class Bitmap
  4669.   #--------------------------------------------------------------------------
  4670.   # * Class Variables
  4671.   #--------------------------------------------------------------------------
  4672.   class_reader :text_memory, :formatted_text_memory
  4673.   #-------------------------------------------------------------------------
  4674.   # * Class Variables
  4675.   #-------------------------------------------------------------------------
  4676.   @@text_memory, @@formatted_text_memory = {}, {}
  4677.   #-------------------------------------------------------------------------
  4678.   #   Name      : Clear Text Memory
  4679.   #   Info      : Clears Text Memory
  4680.   #   Author    : Trickster
  4681.   #   Call Info : No Arguments
  4682.   #   Comment   : Should be called at the end of every scene where
  4683.   #               draw_text_memory or draw_wrap_text_memory is used
  4684.   #-------------------------------------------------------------------------
  4685.   def self.clear_text_memory
  4686.     # Run Through Each Bitmap In Text Memory and dispose
  4687.     @@text_memory.each_value {|bitmap| bitmap.dispose}
  4688.     # Clear
  4689.     @@text_memory.clear
  4690.   end
  4691.   #-------------------------------------------------------------------------
  4692.   #   Name      : Clear Formatted Text Memory
  4693.   #   Info      : Clears Formatted Text Memory
  4694.   #   Author    : Trickster
  4695.   #   Call Info : No Arguments
  4696.   #   Returns   : Nothing
  4697.   #   Comment   : Should be called at the end of every scene where
  4698.   #               draw_formatted_text_memory is used
  4699.   #-------------------------------------------------------------------------
  4700.   def self.clear_formatted_text_memory
  4701.     # Run Through Each Bitmap In Text Memory and dispose
  4702.     @@formatted_text_memory.each_value {|bitmap| bitmap.dispose}
  4703.     # Clear
  4704.     @@formatted_text_memory.clear
  4705.   end
  4706.   #-------------------------------------------------------------------------
  4707.   #   Name      : Clear Memory
  4708.   #   Info      : Clears Bitmap Memory
  4709.   #   Author    : Trickster
  4710.   #   Call Info : No Arguments
  4711.   #-------------------------------------------------------------------------
  4712.   def clear_memory
  4713.     # Dispose Memory
  4714.     @memory.dispose
  4715.     # Set To nil
  4716.     @memory = nil
  4717.   end
  4718.   #-------------------------------------------------------------------------
  4719.   #   Name      : Clear To Memory
  4720.   #   Info      : Clears to Bitmap Memory
  4721.   #   Author    : Trickster
  4722.   #   Call Info : No Arguments
  4723.   #-------------------------------------------------------------------------
  4724.   def clear_to_memory
  4725.     # Clear Bitmap
  4726.     clear
  4727.     # Draw Memory if it is a Bitmap
  4728.     blt(0, 0, @memory, rect) if @memory.is_a?(Bitmap)
  4729.   end
  4730.   #-------------------------------------------------------------------------
  4731.   #   Name      : Draw Formatted Text Memory
  4732.   #   Info      : Draws Formatted Wrapped Text from Memory
  4733.   #   Author    : Trickster
  4734.   #   Call Info : Five Arguments
  4735.   #               Integer Offset_x and Offset_Y, define starting position
  4736.   #               Integer Width, defines the width of the text rectangle
  4737.   #               Integer Height, defines the height of the text drawn
  4738.   #               String Text, The text to be drawn
  4739.   #   Comment   : C[rrggbb] -> Change Color values are in hex
  4740.   #               C[N] -> Change Color to Normal Color
  4741.   #               B[] -> Turns on/off Bold
  4742.   #               I[] -> Turns on/off Italics
  4743.   #               T[] -> Tab (4 Spaces)
  4744.   #               N[] -> Newline
  4745.   #-------------------------------------------------------------------------
  4746.   def draw_formatted_text_memory(x, y, width, height, text)
  4747.     # If Already drawn
  4748.     if @@formatted_text_memory.has_key?(text)
  4749.       # Get Bitmap
  4750.       bitmap = @@formatted_text_memory[text]
  4751.       # Draw Bitmap
  4752.       blt(x, y, bitmap, bitmap.rect)
  4753.     else
  4754.       # Get Height of Text Drawn
  4755.       height = get_formatted_size(x, y, width, height, text).height
  4756.       # Create Text Bitmap
  4757.       text_bitmap = Bitmap.new(width, height)
  4758.       # Initialize X and Y
  4759.       cx, cy = 0, 0
  4760.       # Setup Font Color
  4761.       text_bitmap.font.color = Color.new(255, 255, 255)
  4762.       # Setup Save String
  4763.       string = text.dup
  4764.       # Make a Copy of Text
  4765.       text = text.dup
  4766.       # Replace C[Hex+] or C[N] with \001[Matched]
  4767.       text.gsub!(/[Cc]\[([A-F a-f 0-9]+|N)\]/) {" \001[#{$1}] "}
  4768.       # Replace B[] with \002
  4769.       text.gsub!(/[Bb]\[\]/) {" \002 "}
  4770.       # Replace I[] with \003
  4771.       text.gsub!(/[Ii]\[\]/) {" \003 "}
  4772.       # Replace T[] with \004
  4773.       text.gsub!(/[Tt]\[\]/) {" \004 "}
  4774.       # Replace N[] with \005
  4775.       text.gsub!(/[Nn]\[\]/) {" \005 "}
  4776.       # Run Through each text
  4777.       text.split(/\s/).each do |word|
  4778.         # If String \001 is included
  4779.         if word.include?("\001")
  4780.           # Slice from String
  4781.           word.slice!("\001")
  4782.           # Change text color
  4783.           word.sub!(/[Cc]\[([A-F a-f 0-9]+|N)\]/, '')
  4784.           # If matched is not nil and size of match is > 1
  4785.           if $1 != nil and $1.size > 1
  4786.             # Create Color
  4787.             color = Color.new($1[0..1].hex, $1[2..3].hex, $1[4..5].hex)
  4788.           else
  4789.             # Normal Color
  4790.             color = Color.new(255, 255, 255)
  4791.           end
  4792.           # Set Color
  4793.           self.font.color = color
  4794.           # Go to next text
  4795.           next
  4796.         end
  4797.         # If String \002 is included
  4798.         if word.include?("\002")
  4799.           # Invert Bold Status
  4800.           self.font.bold = !self.font.bold
  4801.           # Go to next text
  4802.           next
  4803.         end
  4804.         # If String \003 is included
  4805.         if word.include?("\003")
  4806.           # Invert Italic Status
  4807.           self.font.italic = !self.font.italic
  4808.           # Go to next text
  4809.           next
  4810.         end
  4811.         # If String \004 is included
  4812.         if word.include?("\004")
  4813.           # Add Four Spaces
  4814.           x += text_size('    ').width
  4815.           # Go to next text
  4816.           next
  4817.         end
  4818.         # If String \005 is included
  4819.         if word.include?("\005")
  4820.           # Move to new line
  4821.           cy = cx / width + 1
  4822.           # Move to start
  4823.           cx = cy * width
  4824.           # Go to next text
  4825.           next
  4826.         end
  4827.         # Get Word Width
  4828.         word_width = text_size("#{word} ").width
  4829.         # If can't fit on line
  4830.         if (cx + word_width) % width < x % width
  4831.           # Move to new line
  4832.           cy = cx / width + 1
  4833.           # Move to start
  4834.           cx = cy * width
  4835.         end
  4836.         # Get Draw X
  4837.         dx = cx % width + x
  4838.         # Get Draw Y
  4839.         dy = cx / width * height + y
  4840.         # Draw Text
  4841.         text_bitmap.draw_text(dx, dy, word_width, 32, word)
  4842.         # Increase by Word Width
  4843.         cx += word_width
  4844.       end
  4845.       # Save Copy of Bitmap
  4846.       @@formatted_text_memory[string] = text_bitmap
  4847.       # Draw onto Bitmap
  4848.       blt(x, y, text_bitmap, text_bitmap.rect)
  4849.     end
  4850.   end
  4851.   #-------------------------------------------------------------------------
  4852.   #   Name      : Draw Text Memory
  4853.   #   Info      : Draws Text and Saves it to Text_Memory
  4854.   #   Author    : Trickster
  4855.   #   Call Info : Two,Three,Five or Six Arguments
  4856.   #               Two Arguments: rect, str
  4857.   #                 Rect rect for the text to be drawn
  4858.   #                 String str text to be drawn
  4859.   #               Three Arguments: rect, str, align
  4860.   #                 Rect rect for the text to be drawn
  4861.   #                 String str text to be drawn
  4862.   #                 Integer align 0: left 1: center 2:right
  4863.   #               Five Arguments: x,y,width,height,str
  4864.   #                 Integer X and Y, Defines Position
  4865.   #                 Width and Height, Defines Width and Hieght of the text drawn
  4866.   #                 String str text to be drawn
  4867.   #               Six Arguments: x,y,width,height,str,align
  4868.   #                 Integer X and Y, Defines Position
  4869.   #                 Width and Height, Defines Width and Hieght of the text drawn
  4870.   #                 String str text to be drawn
  4871.   #                 Integer align 0: left 1: center 2:right
  4872.   #-------------------------------------------------------------------------
  4873.   def draw_text_memory(*args)
  4874.     # If Two Arguments Sent
  4875.     if args.size == 2
  4876.       # Default align, Rect and String were sent
  4877.       align, rect, str = 0, *args
  4878.     # If Three Arguments Sent
  4879.     elsif args.size == 3
  4880.       # All Were Sent Rect String and Alignment
  4881.       rect, str, align = args
  4882.     # If Five Arguments Sent
  4883.     elsif args.size == 5
  4884.       # Create Rect from (X,Y,Width,Height), Set String, Default align
  4885.       rect, str, align = Rect.new(*args[0, 4]), args[4], 0
  4886.     # If Six Arguments Sent
  4887.     elsif args.size == 6
  4888.       # Create Rect from (X,Y,Width,Height), Set String and align      
  4889.       rect, str, align = Rect.new(*args[0, 4]), *args[4, 2]
  4890.     end
  4891.     # Create Text Rect from Rect
  4892.     txt_rect = Rect.new(0, 0, rect.width, rect.height)
  4893.     # If Key is contained
  4894.     if @@text_memory.contains_key?([font, txt_rect, str])
  4895.       # Get Bitmap
  4896.       bitmap = @@text_memory.get_value([font, txt_rect, str])
  4897.       # Draw Bitmap by getting value from hash
  4898.       blt(rect.x, rect.y, bitmap, txt_rect)
  4899.     else
  4900.       # Create Bitmap
  4901.       bitmap = Bitmap.new(rect.width, rect.height)
  4902.       # Make A Copy of the Font
  4903.       bitmap.font = font.dup
  4904.       # Draw Text on bitmap
  4905.       bitmap.draw_text(txt_rect, str, align)
  4906.       # Draw Bitmap
  4907.       blt(rect.x, rect.y, bitmap, txt_rect)
  4908.       # Set Text Memory
  4909.       @@text_memory[[font.dup, txt_rect, str]] = bitmap
  4910.     end
  4911.   end
  4912.   #-------------------------------------------------------------------------
  4913.   #   Name      : Draw Wrapped Text From Memory
  4914.   #   Info      : Draws Text with Text Wrap and Saves it
  4915.   #   Author    : Trickster
  4916.   #   Call Info : Five
  4917.   #               Integer X and Y, Define Position
  4918.   #               Integer Width, defines the width of the text rectangle
  4919.   #               Integer Height, defines the height of the text
  4920.   #               String Text, Text to be drawn
  4921.   #-------------------------------------------------------------------------
  4922.   def draw_wrap_text_memory(x, y, width, height, text)
  4923.     # Get Array of Text
  4924.     strings = text.split
  4925.     # Run Through Array of Strings
  4926.     strings.each do |string|
  4927.       # Get Word
  4928.       word = string + ' '
  4929.       # Get Word Width
  4930.       word_width = text_size(word).width
  4931.       # If Can't Fit on Line move to next one
  4932.       x, y = 0, y + height if x + word_width > width
  4933.       # Draw Text Memory
  4934.       draw_text_memory(x, y, word_width, height, word)
  4935.       # Add To X
  4936.       x += word_width
  4937.     end
  4938.   end
  4939.   #-------------------------------------------------------------------------
  4940.   #   Name      : Get Formatted Text Size
  4941.   #   Info      : Gets Rect information for drawing formatted text
  4942.   #               The Rect Object Returned will have this information
  4943.   #               x, x coordinate where drawing ends
  4944.   #               y, y coordinate where drawing ends
  4945.   #               width, the width sent to this method
  4946.   #               height, the height of all of the text drawn
  4947.   #   Author    : Trickster
  4948.   #   Call Info : Five
  4949.   #               Integer X and Y, Define Position
  4950.   #               Integer Width, defines the width of the text rectangle
  4951.   #               Integer Height, defines the height of the text
  4952.   #               String Text, Text to get information for
  4953.   #-------------------------------------------------------------------------
  4954.   def get_formatted_size(x, y, width, height, text)
  4955.     # Make a Copy and Save
  4956.     text = text.dup
  4957.     # Replace C[Hex+ or N] I[] B[] with nothing
  4958.     text.gsub!(/[BbIiCc]\[([A-F a-f 0-9]+|N)*\]/) {''}
  4959.     # Replace T[] with \004
  4960.     text.gsub!(/[Tt]\[\]/) {" \004 "}
  4961.     # Replace N[] with \005
  4962.     text.gsub!(/[Nn]\[\]/) {" \005 "}
  4963.     # Setup Cx and Cy
  4964.     cx, cy = 0, 0
  4965.     # Declare Dx and Dx as local variables
  4966.     dx, dy = 0, 0
  4967.     # Run Through each text
  4968.     text.split(/\s/).each do |word|
  4969.       # If \004 is included
  4970.       if word.include?("\004")
  4971.         # Add Four Spaces
  4972.         x += text_size(' '*4).width
  4973.         # Go to Next Text
  4974.         next
  4975.       end
  4976.       # If \005 is included
  4977.       if word.include?("\005")
  4978.         # Move to new line
  4979.         cy = cx / width + 1
  4980.         # Move to start
  4981.         cx = cy * width
  4982.         # Go to Next Text
  4983.         next
  4984.       end
  4985.       # Get Word Width
  4986.       word_width = text_size("#{word} ").width
  4987.       # If can't fit on line
  4988.       if (cx + word_width) % width < x % width
  4989.         # Move to new line
  4990.         cy = cx / width + 1
  4991.         # Move to start
  4992.         cx = cy * width
  4993.       end
  4994.       # Add Width to X
  4995.       cx += word_width
  4996.       # Get Draw X and Y
  4997.       dx = cx % width + x
  4998.       dy = cx / width * height + y
  4999.     end
  5000.     # Return Rect Object
  5001.     return Rect.new(dx, dy, width, (dy - y + height).to_i)
  5002.   end
  5003.   #-------------------------------------------------------------------------
  5004.   #   Name      : Set Memory
  5005.   #   Info      : Sets Bitmap Memory
  5006.   #   Author    : Trickster
  5007.   #   Call Info : No Arguments
  5008.   #   Comment   : Use with Clear To Memory
  5009.   #-------------------------------------------------------------------------
  5010.   def set_memory
  5011.     # Make A Clone of itself
  5012.     @memory = self.dup
  5013.   end
  5014. end
  5015.  
  5016. #==============================================================================
  5017. # ** RGSS.Bitmap.misc
  5018. #------------------------------------------------------------------------------
  5019. # Description:
  5020. # ------------
  5021. # Miscellaneous New stuff for the Bitmap class.
  5022. #  
  5023. # Method List:
  5024. # ------------
  5025. # make_png
  5026. #==============================================================================
  5027.  
  5028. MACL::Loaded << 'RGSS.Bitmap.misc'
  5029.  
  5030. #==============================================================================
  5031. # ** Bitmap    
  5032. #==============================================================================
  5033.  
  5034. class Bitmap
  5035.   #-------------------------------------------------------------------------
  5036.   # * Name      : Make PNG
  5037.   #   Info      : Saves Bitmap to File
  5038.   #   Author    : ??? - http://www.66rpg.com/htm/news624.htm
  5039.   #   Call Info : Zero to Three Arguments
  5040.   #               Name : Name of filenam
  5041.   #               Path : Directory in Game Folder
  5042.   #               Mode : Mode of Writing
  5043.   #-------------------------------------------------------------------------
  5044.   def make_png(name = 'like', path = '', mode = 0)
  5045.     Dir.make_dir(path) if path != ''
  5046.     Zlib::Png_File.open('temp.gz')   { |gz| gz.make_png(self, mode) }
  5047.     Zlib::GzipReader.open('temp.gz') { |gz| $read = gz.read }
  5048.     f = File.open(path + name + '.png', 'wb')
  5049.     f.write($read)
  5050.     f.close
  5051.     File.delete('temp.gz')
  5052.   end
  5053. end
  5054.  
  5055. #==============================================================================
  5056. # ** RGSS.Bitmap.text
  5057. #------------------------------------------------------------------------------
  5058. # Description:
  5059. # ------------
  5060. # Methods created for the Bitmap class that handle text drawing such as
  5061. # drawing wrapped text and formatted text see Bitmap.memory for more text
  5062. # drawing functions.
  5063. #  
  5064. # Method List:
  5065. # ------------
  5066. # Bitmap.dummy=
  5067. # Bitmap.dummy
  5068. # Bitmap.text_size
  5069. # Bitmap.string_to_text_icons
  5070. # Bitmap.icon_text_sizes
  5071. # get_formatted_size
  5072. # text_wrap_size
  5073. # draw_formatted_text
  5074. # draw_paragraph
  5075. # draw_wrap_text
  5076. # draw_icon_text
  5077. # draw_text_shadow
  5078. # draw_text_outline
  5079. # draw_text_underline
  5080. # draw_text_strikethrough
  5081. # draw_text_gradient
  5082. #
  5083. # Modified Methods:
  5084. # -----------------
  5085. # draw_text -> basic_draw_text
  5086. #==============================================================================
  5087.  
  5088. MACL::Loaded << 'RGSS.Bitmap.text'
  5089.  
  5090. #==============================================================================
  5091. # ** Bitmap
  5092. #==============================================================================
  5093.  
  5094. class Bitmap
  5095.   #--------------------------------------------------------------------------
  5096.   # * Class Variable Declaration
  5097.   #--------------------------------------------------------------------------
  5098.   class_accessor :dummy
  5099.   Bitmap.dummy = Bitmap.new(32, 32)
  5100.   #--------------------------------------------------------------------------
  5101.   #   Name      : Text Size
  5102.   #   Info      : Gets text size based off dummy bitmap
  5103.   #   Author    : SephirothSpawn
  5104.   #   Call Info : One Argument, a String
  5105.   #--------------------------------------------------------------------------
  5106.   def Bitmap.text_size(text)
  5107.     return Bitmap.dummy.text_size(text)
  5108.   end
  5109.   #--------------------------------------------------------------------------
  5110.   #   Name      : Format String to Text & Icons
  5111.   #   Info      : Changes Strint to Array of Strings and Bitmaps
  5112.   #               (Used for draw_icon_text)
  5113.   #   Author    : SephirothSpawn
  5114.   #   Call Info : One Argument, a String
  5115.   #   Comments  : Format for String : "text [icon_filename] text text..."
  5116.   #--------------------------------------------------------------------------
  5117.   def Bitmap.string_to_text_icons(text)
  5118.     # Splits Text
  5119.     text = text.split
  5120.     # Start Icon List
  5121.     icons = []
  5122.     # Pass Through Text List
  5123.     for i in 0...text.size
  5124.       # Get Word
  5125.       word = text[i]
  5126.       # Sub [icon_filename]
  5127.       word.gsub(/\[(.+?)\]/, '')
  5128.       # Skip if nothing substituted
  5129.       next if $1.nil?
  5130.       # Replace Text Word with nil
  5131.       text[i] = nil
  5132.       # Add Icon to Icon List
  5133.       icons << RPG::Cache.icon($1)
  5134.     end
  5135.     # Return Text & Icons
  5136.     return text, icons
  5137.   end
  5138.   #--------------------------------------------------------------------------
  5139.   #   Name      : Get Icon Text Widths
  5140.   #   Info      : Determines size required to draw_icon_text
  5141.   #               (Used for draw_icon_text)
  5142.   #   Author    : SephirothSpawn
  5143.   #   Call Info : Two Arguments, an Array of strings and an Array of bitmaps
  5144.   #--------------------------------------------------------------------------
  5145.   def Bitmap.icon_text_sizes(text, icons)
  5146.     # Gets Icon Width
  5147.     icn_w = 0
  5148.     icons.each {|b| icn_w += b.width}
  5149.     # Gets Text Width
  5150.     txt_w = 0
  5151.     text.each do |w|
  5152.       next if w.nil?
  5153.       txt_w += @@dummy.text_size(w).width
  5154.     end
  5155.     # Gets Space Width
  5156.     spc_w = Bitmap.text_size(' ').width
  5157.     # Gets Total Width
  5158.     tot_w = icn_w + txt_w + (text.size - 1) * spc_w
  5159.     # Return Icon, Text, Space & Total Width
  5160.     return icn_w, txt_w, spc_w, tot_w
  5161.   end
  5162.   #-------------------------------------------------------------------------
  5163.   #   Name      : Get Formatted Text Size
  5164.   #   Info      : Gets Rect information for drawing formatted text
  5165.   #               And Returns A Rect with this information
  5166.   #               x, x coordinate where drawing ends
  5167.   #               y, y coordinate where drawing ends
  5168.   #               width, the width sent to this method
  5169.   #               height, the height of all of the text drawn
  5170.   #   Author    : Trickster
  5171.   #   Call Info : Five Arguments
  5172.   #               Integer X and Y, Define Position
  5173.   #               Integer Width, defines the width of the text rectangle
  5174.   #               Integer Height, defines the height of the text
  5175.   #               String Text, Text to get information for
  5176.   #-------------------------------------------------------------------------
  5177.   def get_formatted_size(x, y, width, height, text)
  5178.     # Make a Copy and Save
  5179.     text = text.dup
  5180.     # Replace C[Hex+ or N] I[] B[] with nothing
  5181.     text.gsub!(/[BbIiCc]\[([A-F a-f 0-9]+|N)*\]/) {''}
  5182.     # Replace T[] with \004
  5183.     text.gsub!(/[Tt]\[\]/) {" \004 "}
  5184.     # Replace N[] with \005
  5185.     text.gsub!(/[Nn]\[\]/) {" \005 "}
  5186.     # Setup Cx and Cy
  5187.     cx, cy = 0, 0
  5188.     # Run Through each text
  5189.     text.split(/\s/).each do |word|
  5190.       # If \004 is included
  5191.       if word.include?("\004")
  5192.         # Add Four Spaces
  5193.         x += text_size('    ').width
  5194.         # Go to Next Text
  5195.         next
  5196.       end
  5197.       # If \005 is included
  5198.       if word.include?("\005")
  5199.         # Move to new line
  5200.         cy = cx / width + 1
  5201.         # Move to start
  5202.         cx = cy * width
  5203.         # Go to Next Text
  5204.         next
  5205.       end
  5206.       # Get Word Width
  5207.       word_width = text_size("#{word} ").width
  5208.       # If can't fit on line
  5209.       if (cx + word_width) % width < x % width
  5210.         # Move to new line
  5211.         cy = cx / width + 1
  5212.         # Move to start
  5213.         cx = cy * width
  5214.       end
  5215.       # Add Width to X
  5216.       cx += word_width
  5217.       # Get Draw X and Y
  5218.       dx = cx % width + x
  5219.       dy = cx / width * height + y
  5220.     end
  5221.     # Return Rect Object
  5222.     return Rect.new(dx, dy, width, (dy - y + height).to_i)
  5223.   end
  5224.   #-------------------------------------------------------------------------
  5225.   #   Name      : Get Wrapped Text Size
  5226.   #   Info      : Gets Rect information for drawing wrapped text
  5227.   #               And Returns A Rect with this information
  5228.   #               x, x coordinate where drawing ends
  5229.   #               y, y coordinate where drawing ends
  5230.   #               width, the width sent to this method
  5231.   #               height, the height of all of the text drawn
  5232.   #   Author    : Trickster
  5233.   #   Call Info : Five Arguments
  5234.   #               Integer X and Y, Define Position
  5235.   #               Integer Width, defines the width of the text rectangle
  5236.   #               Integer Height, defines the height of the text
  5237.   #               String Text, Text to get information for
  5238.   #-------------------------------------------------------------------------
  5239.   def text_wrap_size(x, y, width, height, text)
  5240.     # Get Array of Text
  5241.     strings = text.split
  5242.     # Form Rect Object
  5243.     rect = Rect.new(x, y, width, 1)
  5244.     # Run Through Array of Strings
  5245.     strings.each do |string|
  5246.       # Get Word
  5247.       word = string + ' '
  5248.       # Get Word Width
  5249.       word_width = text_size(word).width
  5250.       # If Can't Fit on Line move to next one
  5251.       x, y = 0, y + height if x + word_width > width
  5252.       # Add To X
  5253.       x += word_width
  5254.     end
  5255.     # Set Rect Information
  5256.     rect.x, rect.height = x, y - rect.y
  5257.     rect.y = y
  5258.     # Return Rect
  5259.     return rect
  5260.   end
  5261.   #--------------------------------------------------------------------------
  5262.   #   Name      : Draw Formatted Text
  5263.   #   Info      : Draws Formatted Wrapped Text
  5264.   #   Author    : Trickster
  5265.   #   Call Info : Five Arguments
  5266.   #               Integer Offset_x and Offset_Y, define starting position
  5267.   #               Integer Width, defines the width of the text rectangle
  5268.   #               Integer Height, defines the height of the text drawn
  5269.   #               String Text, The text to be drawn
  5270.   #   Comment   : C[rrggbb] -> Change Color values are in hex
  5271.   #               C[N] -> Change Color to Normal Color (255, 255, 255)
  5272.   #               B[] -> Turns on/off Bold
  5273.   #               I[] -> Turns on/off Italics
  5274.   #               T[] -> Tab (4 Spaces)
  5275.   #               N[] -> Newline
  5276.   #-------------------------------------------------------------------------
  5277.   def draw_formatted_text(x, y, width, height, text)
  5278.     # Set to Normal Color (White)
  5279.     self.font.color = Color.new(255, 255, 255)
  5280.     # Make Copy of Text Sent
  5281.     text = text.dup
  5282.     # Replace C[Hex+] or C[N] with \001[Matched]
  5283.     text.gsub!(/[Cc]\[([A-F a-f 0-9]+|N)\]/) {" \001[#{$1}] "}
  5284.     # Replace B[] with \002
  5285.     text.gsub!(/[Bb]\[\]/) {" \002 "}
  5286.     # Replace I[] with \003
  5287.     text.gsub!(/[Ii]\[\]/) {" \003 "}
  5288.     # Replace T[] with \004
  5289.     text.gsub!(/[Tt]\[\]/) {" \004 "}
  5290.     # Replace N[] with \005
  5291.     text.gsub!(/[Nn]\[\]/) {" \005 "}
  5292.     # Setup Cx and Cy
  5293.     cx, cy = 0, 0
  5294.     # Run Through each text
  5295.     text.split(/\s/).each do |word|
  5296.       # If String \001 is included
  5297.       if word.include?("\001")
  5298.         # Slice from String
  5299.         word.slice!("\001")
  5300.         # Change text color
  5301.         word.sub!(/[Cc]\[([A-F a-f 0-9]+|N)\]/, '')
  5302.         # If matched is not nil and size of match is > 1
  5303.         if $1 != nil and $1.size > 1
  5304.           # Create Color
  5305.           color = Color.new($1[0..1].hex, $1[2..3].hex, $1[4..5].hex)
  5306.         else
  5307.           # Normal Color
  5308.           color = Color.new(255, 255, 255)
  5309.         end
  5310.         # Set Color
  5311.         self.font.color = color
  5312.         # Go to next text
  5313.         next
  5314.       end
  5315.       # If String \002 is included
  5316.       if word.include?("\002")
  5317.         # Invert Bold Status
  5318.         self.font.bold = !self.font.bold
  5319.         # Go to next text
  5320.         next
  5321.       end
  5322.       # If String \003 is included
  5323.       if word.include?("\003")
  5324.         # Invert Italic Status
  5325.         self.font.italic = !self.font.italic
  5326.         # Go to next text
  5327.         next
  5328.       end
  5329.       # If String \004 is included
  5330.       if word.include?("\004")
  5331.         # Add Four Spaces
  5332.         x += text_size('    ').width
  5333.         # Go to next text
  5334.         next
  5335.       end
  5336.       # If String \005 is included
  5337.       if word.include?("\005")
  5338.         # Move to new line
  5339.         cy = cx / width + 1
  5340.         # Move to start
  5341.         cx = cy * width
  5342.         # Go to next text
  5343.         next
  5344.       end
  5345.       # Get Word Width
  5346.       word_width = text_size("#{word} ").width
  5347.       # If can't fit on line
  5348.       if (cx + word_width) % width < x % width
  5349.         # Move to new line
  5350.         cy = cx / width + 1
  5351.         # Move to start
  5352.         cx = cy * width
  5353.       end
  5354.       # Get Draw X
  5355.       dx = cx % width + x
  5356.       # Get Draw Y
  5357.       dy = cx / width * height + y
  5358.       # Draw Text
  5359.       draw_text(dx, dy, word_width, 32, word)
  5360.       # Increase by Word Width
  5361.       cx += word_width
  5362.     end
  5363.   end
  5364.   #-------------------------------------------------------------------------
  5365.   #   Name      : Draw Paragraph
  5366.   #   Info      : Draws a Paragraph
  5367.   #   Author    : SephirothSpawn
  5368.   #   Call Info : Five
  5369.   #               Integer X and Y, Define Position
  5370.   #               Integer Width, defines the width of the text rectangle
  5371.   #               String Text, Information to Draw
  5372.   #               Integer Indent Amount of Space to indent by
  5373.   #               Integer Line_Height line height
  5374.   #-------------------------------------------------------------------------
  5375.   def draw_paragraph(x, y, width, text, indent = 32, line_height = 24)
  5376.     ox, oy = indent, 0
  5377.     for word in text.split
  5378.       ow = text_size(word).width
  5379.       if ow + ox > width
  5380.         ox = 0
  5381.         oy += line_height
  5382.       end
  5383.       ow = [ow, width].min
  5384.       draw_text(x + ox, y + oy, ow, line_height, word)
  5385.       ox += ow + text_size(' ').width
  5386.     end
  5387.   end
  5388.   #-------------------------------------------------------------------------
  5389.   #   Name      : Draw Wrapped Text
  5390.   #   Info      : Draws Text with Text Wrap
  5391.   #   Author    : Trickster
  5392.   #   Call Info : Five Arguments
  5393.   #               Integer X and Y, Define Position
  5394.   #               Integer Width, defines the width of the text rectangle
  5395.   #               Integer Height, defines the height of the text
  5396.   #               String Text, Text to be drawn
  5397.   #-------------------------------------------------------------------------
  5398.   def draw_wrap_text(x, y, width, height, text)
  5399.     # Get Array of Text
  5400.     strings = text.split
  5401.     # Run Through Array of Strings
  5402.     strings.each do |string|
  5403.       # Get Word
  5404.       word = string + ' '
  5405.       # Get Word Width
  5406.       word_width = text_size(word).width
  5407.       # If Can't Fit on Line move to next one
  5408.       x, y = 0, y + height if x + word_width > width
  5409.       # Draw Text Memory
  5410.       self.draw_text(x, y, word_width, height, word)
  5411.       # Add To X
  5412.       x += word_width
  5413.     end
  5414.   end
  5415.   #--------------------------------------------------------------------------
  5416.   #   Name      : Draw Icon Text
  5417.   #   Info      : Draws Icons & Text together
  5418.   #   Author    : SephirothSpawn
  5419.   #   Call Info : Five or Six Arguments
  5420.   #               X & Y - Top-left coordinates of text rectangle
  5421.   #               Width & Height - Size of text rectangle
  5422.   #               Text - String or text and icons
  5423.   #               A - alignment, same as draw_text alignment
  5424.   #   Comments  : Format for String : "text [icon_filename] text text..."
  5425.   #--------------------------------------------------------------------------
  5426.   def draw_icon_text(x, y, width, height, text, a = 0)
  5427.     # Gets Text & Icons
  5428.     text, icons = *Bitmap.string_to_text_icons(text)
  5429.     # Gets Icon, Text, Space & Total Width
  5430.     icn_w, txt_w, spc_w, tot_w = *Bitmap.icon_text_sizes(text, icons)
  5431.     # If Icon Width Greater than Width
  5432.     if icn_w + (icons.size - 1) * spc_w > width
  5433.       # Print Error
  5434.       p 'Text Width Not Big Enough.'
  5435.       return
  5436.     end
  5437.     # If Total Width Less than Text W
  5438.     if tot_w <= width
  5439.       # Gets Start Point
  5440.       ox = a == 0 ? 0 : a == 1 ? width / 2 - tot_w / 2 : width - tot_w
  5441.       # Pass Through Text
  5442.       text.each do |word|
  5443.         # If Word is nil
  5444.         if word.nil?
  5445.           # Gets Icon
  5446.           icon = icons.shift
  5447.           # Next if Nil Icon
  5448.           next if icon.nil?
  5449.           # Draws Icon
  5450.           x_, y_ = x + ox, y + (height - icon.height) / 2
  5451.           self.blt(x_, y_, icon, icon.rect, self.font.color.alpha)
  5452.           # Adds to OX
  5453.           ox += icon.width + spc_w
  5454.           next
  5455.         end
  5456.         # Draws Text
  5457.         self.draw_text(x + ox, y, width, height, word)
  5458.         # Adds to OX
  5459.         ox += self.text_size(word).width + spc_w
  5460.       end
  5461.     # If Total Width Greater than Text W
  5462.     else
  5463.       # Gets Difference
  5464.       diff = width - icn_w
  5465.       # Percent Txt Width
  5466.       percent = (txt_w + (icons.size - 1) * spc_w) / width.to_f
  5467.       # Alter Space Width
  5468.       spc_w = Integer(spc_w * percent)
  5469.       # Gets Start Point
  5470.       ox = 0
  5471.       # Pass Through Text
  5472.       text.each do |word|
  5473.         # If Word is nil
  5474.         if word.nil?
  5475.           # Gets Icon
  5476.           icon = icons.shift
  5477.           # Next if Nil Icon
  5478.           next if icon.nil?
  5479.           # Draws Icon
  5480.           x_, y_ = x + ox, y + (height - icon.height) / 2
  5481.           self.blt(x_, y_, icon, icon.rect, self.font.color.alpha)
  5482.           # Adds to OX
  5483.           ox += icon.width + spc_w
  5484.           next
  5485.         end
  5486.         # Draws Text
  5487.         w_ = Integer(self.text_size(word).width * percent)
  5488.         self.draw_text(x + ox, y, w_, height, word)
  5489.         # Adds to OX
  5490.         ox += w_ + spc_w
  5491.       end
  5492.     end
  5493.   end
  5494.   #--------------------------------------------------------------------------
  5495.   # * Object Aliasing
  5496.   #--------------------------------------------------------------------------
  5497.   if @font_addons_alias.nil?
  5498.     alias_method :basic_draw_text, :draw_text
  5499.     @font_addons_alias = true
  5500.   end
  5501.   #--------------------------------------------------------------------------
  5502.   # * Draw Text
  5503.   #--------------------------------------------------------------------------
  5504.   def draw_text(*args)
  5505.     # Create Conditions Hash
  5506.     conditions = {
  5507.       :draw_text_shadow        => self.font.shadow,
  5508.       :draw_text_outline       => self.font.outline,
  5509.       :draw_text_underline     => self.font.underline,
  5510.       :draw_text_strikethrough => self.font.strikethrough,
  5511.       :draw_text_gradient      => self.font.vert_grad || self.font.horiz_grad
  5512.     }
  5513.     # Pass through font effects
  5514.     for effect in Font::Addon_Order
  5515.       # If Draw Text
  5516.       if effect == :draw_text
  5517.         basic_draw_text(*args)
  5518.         next
  5519.       end
  5520.       # If Condition
  5521.       if conditions[effect]
  5522.         # Call Method
  5523.         send(effect, *args)
  5524.       end
  5525.     end
  5526.   end
  5527.   #--------------------------------------------------------------------------
  5528.   # * Draw Text : Get Positions
  5529.   #--------------------------------------------------------------------------
  5530.   def draw_text_positions(*args)
  5531.     if (r = args[0]).is_a?(Rect)
  5532.       x, y, w, h, t = r.x, r.y, r.width, r.height, args[1]
  5533.       a = args.size == 3 ? args[2] : 0
  5534.     else
  5535.       x, y, w, h, t = args[0], args[1], args[2], args[3], args[4]
  5536.       a = args.size == 6 ? args[5] : 0
  5537.     end
  5538.     return x, y, w, h, t, a
  5539.   end
  5540.   #--------------------------------------------------------------------------
  5541.   # * Draw Text : Effect Shadow
  5542.   #--------------------------------------------------------------------------
  5543.   def draw_text_shadow(*args)
  5544.     orig_color = font.color.dup
  5545.     self.font.color = self.font.shadow_color
  5546.     x, y, w, h, t, a = *draw_text_positions(*args)
  5547.     basic_draw_text(x + 2, y + 2, w, h, t, a)
  5548.     self.font.color = orig_color
  5549.   end
  5550.   #--------------------------------------------------------------------------
  5551.   # * Draw Text : Outline Shadow
  5552.   #--------------------------------------------------------------------------
  5553.   def draw_text_outline(*args)
  5554.     orig_color = font.color.dup
  5555.     self.font.color = self.font.outline_color
  5556.     x, y, w, h, t, a = *draw_text_positions(*args)
  5557.     for i in -1..1
  5558.       for j in -1..1
  5559.         basic_draw_text(x + i, y + j, w, h, t, a)
  5560.       end
  5561.     end
  5562.     self.font.color = orig_color
  5563.   end
  5564.   #--------------------------------------------------------------------------
  5565.   # * Draw Text : Effect Underline
  5566.   #--------------------------------------------------------------------------
  5567.   def draw_text_underline(*args)
  5568.     u_color = font.color.dup
  5569.     x, y, w, h, t, a = *draw_text_positions(*args)
  5570.     ux = x
  5571.     uy = y + h / 2 + font.size / 3
  5572.     if font.underline_full
  5573.       uw = w
  5574.     else
  5575.       uw = text_size(args[1]).width
  5576.       ux += a == 1 ? w / 2 - uw / 2 : w - uw
  5577.     end
  5578.     fill_rect(u_x, u_y, u_width, 1, u_color)
  5579.   end
  5580.   #--------------------------------------------------------------------------
  5581.   # * Draw Text : Effect Strikethrough
  5582.   #--------------------------------------------------------------------------
  5583.   def draw_text_strikethrough(*args)
  5584.     x, y, w, h, t, a = *draw_text_positions(*args)
  5585.     sx = x
  5586.     sy = y + h / 2
  5587.     if font.strikethrough_full
  5588.       sw = w
  5589.     else
  5590.       sw = text_size(args[1]).width
  5591.       sx += a == 1 ? w / 2 - sw / 2 : w - sw
  5592.     end
  5593.     fill_rect(s_x, s_y, s_width, 1, s_color)
  5594.   end
  5595.   #--------------------------------------------------------------------------
  5596.   # * Draw Text : Effect Gradient
  5597.   #--------------------------------------------------------------------------
  5598.   def draw_text_gradient(*args)
  5599.     x, y, w, h, t, a = *draw_text_positions(*args)
  5600.     # If Draw Vertical Font Gradient
  5601.     if self.font.vert_grad || self.font.horiz_grad
  5602.       # Creates Dummy Bitmap
  5603.       dummy = Bitmap.new(w, h)
  5604.       dummy.font = font
  5605.       dummy.font.vert_grad = false
  5606.       dummy.font.horiz_grad = false
  5607.       dummy.basic_draw_text(0, 0, w, h, t, a)
  5608.       # Gets Cached Bitmap
  5609.       if font.vert_grad
  5610.         # Applys Gradient Pixel Change
  5611.         dummy.v_gradient_pixel_change(font.grad_s_color, font.grad_e_color)
  5612.       else
  5613.         # Applys Gradient Pixel Change
  5614.         dummy.h_gradient_pixel_change(font.grad_s_color, font.grad_e_color)
  5615.       end
  5616.       # Draw Dummy Bitmap over self
  5617.       self.blt(x, y, dummy, dummy.rect)
  5618.     end
  5619.   end
  5620. end
  5621.  
  5622. #==============================================================================
  5623. # ** RGSS.Character
  5624. #------------------------------------------------------------------------------
  5625. # Description:
  5626. # ------------
  5627. # Miscellaneous methods for RGSS classes.
  5628. #  
  5629. # Method List:
  5630. # ------------
  5631. #
  5632. #   Game_Character
  5633. #   --------------
  5634. #   opacity=
  5635. #   battler=
  5636. #   battler
  5637. #   critical=
  5638. #   critical
  5639. #   damage=
  5640. #   damage
  5641. #   damage_pop=
  5642. #   damage_pop
  5643. #   can_jump?
  5644. #   moving_down?
  5645. #   moving_left?
  5646. #   moving_right?
  5647. #   moving_up?
  5648. #   can_move_toward_event?
  5649. #   can_move_toward_target?
  5650. #   move_toward_event
  5651. #   move_toward_target
  5652. #   turn_toward_event
  5653. #   turn_toward_target
  5654. #
  5655. #   Game_Player
  5656. #   -----------
  5657. #   disable_player_movement
  5658. #   disable_player_trigger
  5659. #
  5660. #   Game_Event
  5661. #   ----------
  5662. #   event
  5663. #   erased
  5664. #   event_comment_list
  5665. #==============================================================================
  5666.  
  5667. MACL::Loaded << 'RGSS.Miscellaneous Methods'
  5668.  
  5669. #==============================================================================
  5670. # ** Game_Character
  5671. #==============================================================================
  5672.  
  5673. class Game_Character
  5674.   #--------------------------------------------------------------------------
  5675.   # * Public Instance Variables
  5676.   #--------------------------------------------------------------------------
  5677.   attr_writer :opacity
  5678.   attr_accessor :battler
  5679.   attr_accessor :critical
  5680.   attr_accessor :damage
  5681.   attr_accessor :damage_pop
  5682.   #--------------------------------------------------------------------------
  5683.   # * Alias Listings
  5684.   #--------------------------------------------------------------------------
  5685.   alias_method :macl_rgsschar_init, :initialize
  5686.   alias_method :macl_rgsschar_updt, :update
  5687.   #--------------------------------------------------------------------------
  5688.   # * Object Initialization
  5689.   #--------------------------------------------------------------------------
  5690.   def initialize(*args)
  5691.     # Set character settings
  5692.     @battler    = nil
  5693.     @critical   = false
  5694.     @damage     = nil
  5695.     @damage_pop = false
  5696.     # Original Initialization
  5697.     macl_rgsschar_init(*args)
  5698.   end
  5699.   #--------------------------------------------------------------------------
  5700.   # * Frame Update
  5701.   #--------------------------------------------------------------------------
  5702.   def update
  5703.     # Original Update
  5704.     macl_rgsschar_updt
  5705.     # Refresh
  5706.     refresh
  5707.   end
  5708.   #--------------------------------------------------------------------------
  5709.   # * Refresh
  5710.   #--------------------------------------------------------------------------
  5711.   def refresh
  5712.     # Set character file name and hue
  5713.     if @battler != nil
  5714.       # If Dead
  5715.       if @battler.dead?
  5716.         @character_name = ''
  5717.         @character_hue = 0
  5718.         return
  5719.       end
  5720.       @character_name = @battler.character_name
  5721.       @character_hue = @battler.character_hue
  5722.     end
  5723.   end
  5724.   #-------------------------------------------------------------------------
  5725.   # * Name      : Can Jump?
  5726.   #   Info      : Returns if Can Jump
  5727.   #   Author    : SephirothSpawn
  5728.   #   Call Info : Integer Amounts, X & Y Plus
  5729.   #-------------------------------------------------------------------------
  5730.   def can_jump?(x_plus, y_plus)
  5731.     new_x = @x + x_plus
  5732.     new_y = @y + y_plus
  5733.     return (x_plus == 0 and y_plus == 0) || passable?(new_x, new_y, 0)
  5734.   end
  5735.   #-------------------------------------------------------------------------
  5736.   # * Name      : Moving Down
  5737.   #   Info      : Returns if moving down
  5738.   #   Author    : SephirothSpawn
  5739.   #   Call Info : None
  5740.   #-------------------------------------------------------------------------
  5741.   def moving_down?
  5742.     return @y * 128 > @real_y
  5743.   end
  5744.   #-------------------------------------------------------------------------
  5745.   # * Name      : Moving Left
  5746.   #   Info      : Returns if moving left
  5747.   #   Author    : SephirothSpawn
  5748.   #   Call Info : None
  5749.   #-------------------------------------------------------------------------
  5750.   def moving_left?
  5751.     return @x * 128 < @real_x
  5752.   end
  5753.   #-------------------------------------------------------------------------
  5754.   # * Name      : Moving Right
  5755.   #   Info      : Returns if moving right
  5756.   #   Author    : SephirothSpawn
  5757.   #   Call Info : None
  5758.   #-------------------------------------------------------------------------
  5759.   def moving_right?
  5760.     return @x * 128 > @real_x
  5761.   end
  5762.   #-------------------------------------------------------------------------
  5763.   # * Name      : Moving Up
  5764.   #   Info      : Returns if moving up
  5765.   #   Author    : SephirothSpawn
  5766.   #   Call Info : None
  5767.   #-------------------------------------------------------------------------
  5768.   def moving_up?
  5769.     return @y * 128 < @real_y
  5770.   end
  5771.   #-------------------------------------------------------------------------
  5772.   # * Name      : Can Move Towards Event?
  5773.   #   Info      : Checks if character can move towards event
  5774.   #   Author    : SephirothSpawn
  5775.   #   Call Info : Integer Amount, Event ID (or 0 for player)
  5776.   #-------------------------------------------------------------------------
  5777.   def can_move_toward_event?(event_id = 1)
  5778.     c = event_id == 0 ? $game_player : $game_map.events[event_id]
  5779.     return false if c.nil?
  5780.     return can_move_toward_target?(c.x, c.y)
  5781.   end
  5782.   #-------------------------------------------------------------------------
  5783.   # * Name      : Can Move Towards Target?
  5784.   #   Info      : Checks if character can move towards target
  5785.   #   Author    : SephirothSpawn
  5786.   #   Call Info : Integer Amounts, Destination X & Y
  5787.   #-------------------------------------------------------------------------
  5788.   def can_move_toward_target?(x, y)
  5789.     # Get difference in player coordinates
  5790.     sx = @x - x
  5791.     sy = @y - y
  5792.     # If coordinates are equal, return false
  5793.     return false if sx == 0 and sy == 0
  5794.     # Get absolute value of difference
  5795.     abs_sx = sx.abs
  5796.     abs_sy = sy.abs
  5797.     # Passable Testings
  5798.     pass = {2 => passable?(@x, @y, 2), 4 => passable?(@x, @y, 4),
  5799.             6 => passable?(@x, @y, 6), 8 => passable?(@x, @y, 8),
  5800.             24 => passable?(@x, @y, 2) && passable?(@x, @y + 1, 4),
  5801.             26 => passable?(@x, @y, 2) && passable?(@x, @y + 1, 6),
  5802.             42 => passable?(@x, @y, 4) && passable?(@x - 1, @y, 2),
  5803.             48 => passable?(@x, @y, 4) && passable?(@x - 1, @y, 8),
  5804.             62 => passable?(@x, @y, 6) && passable?(@x + 1, @y, 2),
  5805.             68 => passable?(@x, @y, 6) && passable?(@x + 1, @y, 8),
  5806.             84 => passable?(@x, @y, 8) && passable?(@x, @y - 1, 4),
  5807.             86 => passable?(@x, @y, 8) && passable?(@x, @y - 1, 6)}
  5808.     # Movement Testings
  5809.     if abs_sx > abs_sy
  5810.       if sx != 0
  5811.         if sx > 0
  5812.           return true, 4 if pass[4]
  5813.           sy > 0 ? (return true, 8 if pass[84]) : (return true, 2 if pass[24])
  5814.         else
  5815.           return true, 6 if pass[6]
  5816.           sy > 0 ? (return true, 8 if pass[86]) : (return true, 2 if pass[26])
  5817.         end
  5818.       end
  5819.       if sy != 0
  5820.         if sy > 0
  5821.           return true, 8 if pass[8]
  5822.           sx > 0 ? (return true, 4 if pass[48]) : (return true, 6 if pass[68])
  5823.         else
  5824.           return true, 2 if pass[2]
  5825.           sx > 0 ? (return true, 4 if pass[42]) : (return true, 6 if pass[62])
  5826.         end
  5827.       end
  5828.     else
  5829.       if sy != 0
  5830.         if sy > 0
  5831.           return true, 8 if pass[8]
  5832.           sx > 0 ? (return true, 4 if pass[48]) : (return true, 6 if pass[68])
  5833.         else
  5834.           return true, 2 if pass[2]
  5835.           sx > 0 ? (return true, 4 if pass[42]) : (return true, 6 if pass[62])
  5836.         end
  5837.       end
  5838.       if sx != 0
  5839.         if sx > 0
  5840.           return true, 4 if pass[4]
  5841.           sy > 0 ? (return true, 8 if pass[84]) : (return true, 2 if pass[24])
  5842.         else
  5843.           return true, 6 if pass[6]
  5844.           sy > 0 ? (return true, 8 if pass[86]) : (return true, 2 if pass[26])
  5845.         end
  5846.       end
  5847.     end
  5848.     # Return False if No Possible Moves
  5849.     return false
  5850.   end
  5851.   #-------------------------------------------------------------------------
  5852.   # * Name      : Move Towards Event
  5853.   #   Info      : Moves character towards event
  5854.   #   Author    : SephirothSpawn
  5855.   #   Call Info : Integer Amount, Event ID (or 0 for player)
  5856.   #-------------------------------------------------------------------------
  5857.   def move_towards_event(event_id = 1)
  5858.     c = event_id == 0 ? $game_player : $game_map.events[event_id]
  5859.     return if c.nil?
  5860.     move_toward_target(c.x, c.y)
  5861.   end
  5862.   #-------------------------------------------------------------------------
  5863.   # * Name      : Move Towards Target
  5864.   #   Info      : Moves character towards target position
  5865.   #   Author    : SephirothSpawn
  5866.   #   Call Info : Integer Amounts, Destination X & Y
  5867.   #-------------------------------------------------------------------------
  5868.   def move_toward_target(x, y)
  5869.     # Gets Test Status
  5870.     can, dir = can_move_toward_target?(x, y)
  5871.     # Returns If Can't Move
  5872.     return unless can
  5873.     # Moves By Direction
  5874.     move_down  if dir == 2
  5875.     move_left  if dir == 4
  5876.     move_right if dir == 6
  5877.     move_up    if dir == 8
  5878.   end
  5879.   #-------------------------------------------------------------------------
  5880.   # * Name      : Turn Towards Event
  5881.   #   Info      : Turns character towards event
  5882.   #   Author    : SephirothSpawn
  5883.   #   Call Info : Integer Amount, Event ID (or 0 for player)
  5884.   #-------------------------------------------------------------------------
  5885.   def turn_toward_event(event_id = 1)
  5886.     c = event_id == 0 ? $game_player : $game_map.events[event_id]
  5887.     return if c.nil?
  5888.     turn_toward_target(c.x, c.y)
  5889.   end
  5890.   #-------------------------------------------------------------------------
  5891.   # * Name      : Turn Towards Target
  5892.   #   Info      : Turns character towards target position
  5893.   #   Author    : SephirothSpawn
  5894.   #   Call Info : Integer Amounts, Destination X & Y
  5895.   #-------------------------------------------------------------------------
  5896.   def turn_toward_target(x, y)
  5897.     # Get difference in target coordinates
  5898.     sx, sy = @x - x, @y - y
  5899.     # If coordinates are equal
  5900.     return if sx == 0 && sy == 0
  5901.     # If horizontal distance is longer
  5902.     if sx.abs > sy.abs
  5903.       # Turn to the right or left towards player
  5904.       sx > 0 ? turn_left : turn_right
  5905.     # If vertical distance is longer
  5906.     else
  5907.       # Turn up or down towards player
  5908.       sy > 0 ? turn_up : turn_down
  5909.     end
  5910.   end
  5911. end
  5912.  
  5913. #==============================================================================
  5914. # ** Game_Player
  5915. #==============================================================================
  5916.  
  5917. class Game_Player
  5918.   #--------------------------------------------------------------------------
  5919.   # * Public Instance Variables
  5920.   #--------------------------------------------------------------------------
  5921.   attr_accessor :disable_player_movement
  5922.   attr_accessor :disable_player_trigger
  5923.   #--------------------------------------------------------------------------
  5924.   # * Alias Listings
  5925.   #--------------------------------------------------------------------------
  5926.   alias_method :macl_gmplyr_init,  :initialize
  5927.   alias_method :macl_gmplyr_pass?, :passable?
  5928.   alias_method :macl_gmplyr_ceth,  :check_event_trigger_here
  5929.   alias_method :macl_gmplyr_cett,  :check_event_trigger_there
  5930.   #--------------------------------------------------------------------------
  5931.   # * Object Initialization
  5932.   #--------------------------------------------------------------------------
  5933.   def initialize
  5934.     # Original Initialization
  5935.     macl_gmplyr_init
  5936.     # Set game player settings
  5937.     @battler                 = $game_party.actors[0]
  5938.     @disable_player_movement = false
  5939.     @disable_player_trigger  = false
  5940.   end
  5941.   #--------------------------------------------------------------------------
  5942.   # * Refresh
  5943.   #--------------------------------------------------------------------------
  5944.   def refresh
  5945.     # If party members = 0
  5946.     if $game_party.actors.size == 0
  5947.       # Clear character file name and hue
  5948.       @character_name = ''
  5949.       @character_hue = 0
  5950.       # End method
  5951.       return
  5952.     end
  5953.     # Set lead actor
  5954.     @battler = $game_party.actors[0]
  5955.     # Parent Refresh
  5956.     super
  5957.     # Initialize opacity level and blending method
  5958.     @opacity = 255
  5959.     @blend_type = 0
  5960.   end
  5961.   #--------------------------------------------------------------------------
  5962.   # * Passable Determinants
  5963.   #--------------------------------------------------------------------------
  5964.   def passable?(x, y, d)
  5965.     # Return false if Disable Player Movement
  5966.     return false if disable_player_movement
  5967.     # Return Orginal Result
  5968.     return macl_gmplyr_pass?(x, y, d)
  5969.   end
  5970.   #--------------------------------------------------------------------------
  5971.   # * Same Position Starting Determinant
  5972.   #--------------------------------------------------------------------------
  5973.   def check_event_trigger_here(triggers)
  5974.     # Return false if disable player trigger
  5975.     return false if disable_player_trigger
  5976.     # Return Orginal Result
  5977.     return macl_gmplyr_ceth(triggers)
  5978.   end
  5979.   #--------------------------------------------------------------------------
  5980.   # * Front Envent Starting Determinant
  5981.   #--------------------------------------------------------------------------
  5982.   def check_event_trigger_there(triggers)
  5983.     # Return false if disable player trigger
  5984.     return false if disable_player_trigger
  5985.     # Return Orginal Result
  5986.     return macl_gmplyr_cett(triggers)
  5987.   end
  5988. end
  5989.  
  5990. #==============================================================================
  5991. # ** Game_Event
  5992. #==============================================================================
  5993.  
  5994. class Game_Event
  5995.   #--------------------------------------------------------------------------
  5996.   # * Public Instance Variables
  5997.   #--------------------------------------------------------------------------
  5998.   attr_reader   :erased
  5999.   attr_reader   :event
  6000.   #-------------------------------------------------------------------------
  6001.   # * Name      : Event Comment List
  6002.   #   Info      : Gets the Info from the comments in events
  6003.   #               returns A Hash setup like so {'trigger' => info}
  6004.   #   Author    : Trickster
  6005.   #   Call Info : Variable Amount, String used for triggers
  6006.   #   Comments  : Detects Integers, Floats, Arrays and Hashes, else its a string
  6007.   #-------------------------------------------------------------------------
  6008.   def event_comment_list(*triggers)
  6009.     # Setup Parameters
  6010.     parameters = {}
  6011.     # Run Through Each Page With Index
  6012.     @event.pages.each_with_index do |page, index|
  6013.       parameters[index] = {}
  6014.       list = page.list
  6015.       return if list == nil or not list.is_a?(Array)
  6016.       list.each do |command|
  6017.         next if command.code != 108
  6018.         comment = command.parameters[0]
  6019.         array = comment.split
  6020.         trigger = array[0]
  6021.         value = array[1...array.size].join
  6022.         value = value.to_i if value =~ /\d+/
  6023.         value = value.to_f if value =~ /\d+\.\d+/
  6024.         value = eval(value) if value =~ /\[\.+\]/ or value =~ /\{\.+\}/
  6025.         parameters[index][trigger] = value if triggers.include?(trigger)
  6026.       end
  6027.     end
  6028.     return parameters
  6029.   end
  6030. end
  6031.  
  6032. #==============================================================================
  6033. # ** Sprite_Character
  6034. #==============================================================================
  6035.  
  6036. class Sprite_Character
  6037.   #--------------------------------------------------------------------------
  6038.   # * Alias Listings
  6039.   #--------------------------------------------------------------------------
  6040.   alias_method :sephmaclchdp_schr_update, :update
  6041.   #--------------------------------------------------------------------------
  6042.   # * Frame Update
  6043.   #--------------------------------------------------------------------------
  6044.   def update
  6045.     sephmaclchdp_schr_update
  6046.     return if @character.nil? || self.visible == false || self.bitmap.nil?
  6047.     # Damage
  6048.     if @character.damage_pop
  6049.       damage(@character.damage, @character.critical)
  6050.       @character.damage = nil
  6051.       @character.critical = false
  6052.       @character.damage_pop = false
  6053.     end
  6054.   end
  6055. end
  6056.  
  6057. #==============================================================================
  6058. # ** RGSS.Color.colors
  6059. #------------------------------------------------------------------------------
  6060. # Description:
  6061. # ------------
  6062. # This Set Defines the Basic Colors so now you can do Color.(color) to define a
  6063. # Color Also Adds methods to create colors easily.
  6064. #  
  6065. # Method List:
  6066. # ------------
  6067. # Color.color_between
  6068. # Color.red
  6069. # Color.green
  6070. # Color.blue
  6071. # Color.yellow
  6072. # Color.orange
  6073. # Color.purple
  6074. # Color.white
  6075. # Color.black
  6076. # Color.gray
  6077. # Color.clear
  6078. # Color.normal
  6079. # Color.disabled
  6080. # Color.system
  6081. # Color.crisis
  6082. # Color.knockout
  6083. # Color.get_color
  6084. #==============================================================================
  6085.  
  6086. MACL::Loaded << 'RGSS.Color.colors'
  6087.  
  6088. #==============================================================================
  6089. # ** Color
  6090. #==============================================================================
  6091.  
  6092. class Color
  6093.   #-------------------------------------------------------------------------
  6094.   # * Color Between Memory
  6095.   #-------------------------------------------------------------------------
  6096.   @color_between = {}
  6097.   #-------------------------------------------------------------------------
  6098.   # * Name      : Color Between
  6099.   #   Info      : Gets Color Between Two colors given the percent
  6100.   #   Author    : SephirothSpawn
  6101.   #   Call Info : Start Color, Finish Color, Percent
  6102.   #-------------------------------------------------------------------------
  6103.   def self.color_between(color_a, color_b, percent = 0.5)
  6104.     # Gets Save Key
  6105.     key = [color_a, color_b, percent]
  6106.     if @color_between.has_key?(key)
  6107.       return @color_between[key]
  6108.     end
  6109.     # Calculates New Color
  6110.     r = Integer(color_a.red   + (color_b.red   - color_a.red)   * percent)
  6111.     g = Integer(color_a.green + (color_b.green - color_a.green) * percent)
  6112.     b = Integer(color_a.blue  + (color_b.blue  - color_a.blue)  * percent)
  6113.     a = Integer(color_a.alpha + (color_b.alpha - color_a.alpha) * percent)
  6114.     # Saves Color
  6115.     @color_between[key] = Color.new(r, g, b, a)
  6116.     # Returns Color
  6117.     return @color_between[key]
  6118.   end
  6119.   #-------------------------------------------------------------------------
  6120.   # * Name      : Red
  6121.   #   Info      : Red Color (255,0,0)
  6122.   #   Author    : Trickster
  6123.   #   Call Info : No Arguments
  6124.   #-------------------------------------------------------------------------
  6125.   def self.red
  6126.     return Color.new(255,0,0)
  6127.   end
  6128.   #-------------------------------------------------------------------------
  6129.   #   Name      : Green
  6130.   #   Info      : Green Color (0,128,0)
  6131.   #   Author    : Trickster
  6132.   #   Call Info : No Arguments
  6133.   #-------------------------------------------------------------------------
  6134.   def self.green
  6135.     return Color.new(0,128,0)
  6136.   end
  6137.   #-------------------------------------------------------------------------
  6138.   #   Name      : Blue
  6139.   #   Info      : Blue Color (0,0,255)
  6140.   #   Author    : Trickster
  6141.   #   Call Info : No Arguments
  6142.   #-------------------------------------------------------------------------
  6143.   def self.blue
  6144.     return Color.new(0,0,255)
  6145.   end
  6146.   #-------------------------------------------------------------------------
  6147.   #   Name      : Yellow
  6148.   #   Info      : Yellow Color (255, 255, 0)
  6149.   #   Author    : Trickster
  6150.   #   Call Info : No Arguments
  6151.   #-------------------------------------------------------------------------
  6152.   def self.yellow
  6153.     return Color.new(255,255,0)
  6154.   end
  6155.   #-------------------------------------------------------------------------
  6156.   #   Name      : Purple
  6157.   #   Info      : Purple Color (128,0,128)
  6158.   #   Author    : Trickster
  6159.   #   Call Info : No Arguments
  6160.   #-------------------------------------------------------------------------
  6161.   def self.purple
  6162.     return Color.new(128,0,128)
  6163.   end
  6164.   #-------------------------------------------------------------------------
  6165.   #   Name      : Orange
  6166.   #   Info      : Orange Color (255,128,0)
  6167.   #   Author    : Trickster
  6168.   #   Call Info : No Arguments
  6169.   #-------------------------------------------------------------------------
  6170.   def self.orange
  6171.     return Color.new(255, 128, 0)
  6172.   end
  6173.   #-------------------------------------------------------------------------
  6174.   #   Name      : White
  6175.   #   Info      : White Color (255,255,255)
  6176.   #   Author    : Trickster
  6177.   #   Call Info : No Arguments
  6178.   #-------------------------------------------------------------------------
  6179.   def self.white
  6180.     return Color.new(255, 255, 255)
  6181.   end
  6182.   #-------------------------------------------------------------------------
  6183.   #   Name      : Black
  6184.   #   Info      : Black Color (0,0,0)
  6185.   #   Author    : Trickster
  6186.   #   Call Info : No Arguments
  6187.   #-------------------------------------------------------------------------
  6188.   def self.black
  6189.     return Color.new(0,0,0)
  6190.   end
  6191.   #-------------------------------------------------------------------------
  6192.   #   Name      : Gray
  6193.   #   Info      : Gray Color (128,128,128)
  6194.   #   Author    : Trickster
  6195.   #   Call Info : No Arguments
  6196.   #-------------------------------------------------------------------------
  6197.   def self.gray
  6198.     return Color.new(128, 128, 128)
  6199.   end
  6200.   #-------------------------------------------------------------------------
  6201.   #   Name      : Clear
  6202.   #   Info      : Transparent Color
  6203.   #   Author    : Trickster
  6204.   #   Call Info : No Arguments
  6205.   #-------------------------------------------------------------------------
  6206.   def self.clear
  6207.     return Color.new(0, 0, 0, 0)
  6208.   end
  6209.   #-------------------------------------------------------------------------
  6210.   #   Name      : Normal
  6211.   #   Info      : Normal Color (255,255,255)
  6212.   #   Author    : SephirothSpawn
  6213.   #   Call Info : No Arguments
  6214.   #-------------------------------------------------------------------------
  6215.   def Color.normal
  6216.     return Color.new(255, 255, 255, 255)
  6217.   end
  6218.   #-------------------------------------------------------------------------
  6219.   #   Name      : Disabled
  6220.   #   Info      : Disabled Color (255,255,255,128)
  6221.   #   Author    : SephirothSpawn
  6222.   #   Call Info : No Arguments
  6223.   #-------------------------------------------------------------------------
  6224.   def Color.disabled
  6225.     return Color.new(255, 255, 255, 128)
  6226.   end
  6227.   #-------------------------------------------------------------------------
  6228.   #   Name      : System
  6229.   #   Info      : System Color (192,224,255)
  6230.   #   Author    : SephirothSpawn
  6231.   #   Call Info : No Arguments
  6232.   #-------------------------------------------------------------------------
  6233.   def Color.system
  6234.     return Color.new(192, 224, 255, 255)
  6235.   end
  6236.   #-------------------------------------------------------------------------
  6237.   #   Name      : Crisis
  6238.   #   Info      : Crisis Color (255,255,64)
  6239.   #   Author    : SephirothSpawn
  6240.   #   Call Info : No Arguments
  6241.   #-------------------------------------------------------------------------
  6242.   def Color.crisis
  6243.     return Color.new(255, 255, 64, 255)
  6244.   end
  6245.   #-------------------------------------------------------------------------
  6246.   #   Name      : Knockout
  6247.   #   Info      : Knockout Color (255,64,0)
  6248.   #   Author    : SephirothSpawn
  6249.   #   Call Info : No Arguments
  6250.   #-------------------------------------------------------------------------
  6251.   def Color.knockout
  6252.     return Color.new(255, 64, 0)
  6253.   end
  6254.   #-------------------------------------------------------------------------
  6255.   #   Name      : Get Color
  6256.   #   Info      : Gets a Color
  6257.   #   Author    : Trickster
  6258.   #   Call Info : Integer Value the color code to get
  6259.   #   Comment   : 0: Clear 1: Red 2: Blue 3:Yellow 4: Purple 5:Orange 6:Green
  6260.   #               7:White 8: Black - 10 for lighter + 10 for darker
  6261.   #-------------------------------------------------------------------------
  6262.   def self.get_color(value)
  6263.     # Convert to 0-8
  6264.     color_value = value < 0 ? value + 10 : value % 10
  6265.     # Branch According to number
  6266.     case color_value
  6267.     when 0 # Clear
  6268.       return
  6269.     when 1 # Red
  6270.       r = 255; g = 0; b = 0
  6271.     when 2 # Blue
  6272.       r = 0; g = 0; b = 255
  6273.     when 3 # Yellow
  6274.       r = 255; g = 255; b = 0
  6275.     when 4 # Purple
  6276.       r = 255; g = 0; b = 255
  6277.     when 5 # Orange
  6278.       r = 255; g = 128; b = 0
  6279.     when 6 # Green
  6280.       r = 0; g = 255; b = 0
  6281.     when 7 # White
  6282.       r = 255; g = 255; b = 255
  6283.     when 8 # Black
  6284.       r = 0; g = 0; b = 0
  6285.     end
  6286.     # Convert if Lighter/Darker
  6287.     if value < 0
  6288.       r += 64; g += 64; b += 64
  6289.     elsif value > 10
  6290.       r -= 64; g -= 64; b -= 64
  6291.     end
  6292.     # Correction
  6293.     r = [[0,r].max, 255].min
  6294.     g = [[0,g].max, 255].min
  6295.     b = [[0,b].max, 255].min
  6296.     return Color.new(r,g,b)
  6297.   end
  6298. end
  6299.  
  6300. #==============================================================================
  6301. # ** RGSS.Color.compare
  6302. #------------------------------------------------------------------------------
  6303. # Description:
  6304. # ------------
  6305. # Adds Color Comparision methods too the color class
  6306. #  
  6307. # Method List:
  6308. # ------------
  6309. # ==
  6310. # same?
  6311. #==============================================================================
  6312.  
  6313. MACL::Loaded << 'RGSS.Color.compare'
  6314.  
  6315. #==============================================================================
  6316. # ** Color
  6317. #==============================================================================
  6318.  
  6319. class Color
  6320.   #-------------------------------------------------------------------------
  6321.   #   Name      : == (Equals Comparison)
  6322.   #   Info      : Comparision Method (checks if r, g, b, and a are equal)
  6323.   #   Author    : Trickster
  6324.   #   Call Info : Color other color to test
  6325.   #-------------------------------------------------------------------------
  6326.   def ==(other)
  6327.     return (red == other.red && green == other.green && blue == other.blue &&
  6328.     alpha == other.alpha)
  6329.   end
  6330.   #-------------------------------------------------------------------------
  6331.   #   Name      : Same?
  6332.   #   Info      : Same Color (r, g, and b are equal)
  6333.   #   Author    : Trickster
  6334.   #   Call Info : Color other color to test
  6335.   #-------------------------------------------------------------------------
  6336.   def same?(other)
  6337.     return (red == other.red && green == other.green && blue == other.blue)
  6338.   end
  6339. end
  6340.  
  6341. #==============================================================================
  6342. # ** RGSS.Color.hsb
  6343. #------------------------------------------------------------------------------
  6344. # Description:
  6345. # ------------
  6346. # Adds a new color space to the Color class that allows to change the hue
  6347. # saturation and value (brightness). Also adds methods to create new colors
  6348. # based on an Hue, Saturation, and Brightness value. The Domain and Range
  6349. # of the three new values are Hue - [0-360), Saturation [0-100],
  6350. # Brightness [0-100].
  6351. # Formula is from the wikipedia.
  6352. #  
  6353. # Method List:
  6354. # ------------
  6355. # Color.to_hsb
  6356. # Color.hsb_new
  6357. # Color.hsb_to_rgb
  6358. # to_hsb
  6359. # to_rgb
  6360. # hue
  6361. # saturation
  6362. # brightness
  6363. # value
  6364. # hue=
  6365. # saturation=
  6366. # brightness=
  6367. # value=
  6368. #  
  6369. # Modified Methods:
  6370. # -----------------
  6371. # initialize
  6372. # set
  6373. # red=
  6374. # green=
  6375. # blue=
  6376. #  
  6377. # Deprecated Methods from V1.5:
  6378. # -----------------------------
  6379. # hsb_to_rgb
  6380. #==============================================================================
  6381.  
  6382. MACL::Loaded << 'RGSS.Color.hsb'
  6383.  
  6384. #==============================================================================
  6385. # ** Color
  6386. #==============================================================================
  6387.  
  6388. class Color
  6389.   #-------------------------------------------------------------------------
  6390.   # * Alias Listings
  6391.   #-------------------------------------------------------------------------
  6392.   unless self.method_defined?(:trick_color_hsb_initialize)
  6393.     alias_method :trick_color_hsb_initialize, :initialize
  6394.     alias_method :trick_color_hsb_set, :set
  6395.     alias_method :trick_color_hsb_red=, :red=
  6396.     alias_method :trick_color_hsb_green=, :green=
  6397.     alias_method :trick_color_hsb_blue=, :blue=
  6398.   end
  6399.   #-------------------------------------------------------------------------
  6400.   # * Object Initialization
  6401.   #-------------------------------------------------------------------------
  6402.   def initialize(*args)
  6403.     trick_color_hsb_initialize(*args)
  6404.     @hue, @saturation, @brightness = to_hsb
  6405.   end
  6406.   #-------------------------------------------------------------------------
  6407.   # * Set
  6408.   #-------------------------------------------------------------------------
  6409.   def set(*args)
  6410.     trick_color_hsb_set(*args)
  6411.     @hue, @saturation, @brightness = to_hsb
  6412.   end
  6413.   #-------------------------------------------------------------------------
  6414.   # * Red
  6415.   #-------------------------------------------------------------------------
  6416.   def red=(red)
  6417.     # The Usual
  6418.     self.trick_color_hsb_red=(red)
  6419.     # Update HSB
  6420.     @hue, @saturation, @brightness = to_hsb
  6421.   end
  6422.   #-------------------------------------------------------------------------
  6423.   # * Green
  6424.   #-------------------------------------------------------------------------  
  6425.   def green=(green)
  6426.     # The Usual
  6427.     self.trick_color_hsb_green=(green)
  6428.     # Update HSB
  6429.     @hue, @saturation, @brightness = to_hsb
  6430.   end
  6431.   #-------------------------------------------------------------------------
  6432.   # * Blue
  6433.   #-------------------------------------------------------------------------
  6434.   def blue=(blue)
  6435.     # The Usual
  6436.     self.trick_color_hsb_blue=(blue)
  6437.     # Update HSB
  6438.     @hue, @saturation, @brightness = to_hsb
  6439.   end
  6440.   #-------------------------------------------------------------------------
  6441.   # * Name      : To HSB (Class method)
  6442.   #   Info      : Converts to Hue, Saturation, and Brightness
  6443.   #               returns an array setup like so: [hue, sat, bright]
  6444.   #   Author    : Trickster
  6445.   #   Call Info : One or Three Arguments
  6446.   #               For One Argument - Color color Color to convert
  6447.   #               For Three Arguments - Integer red, blue, green color values to
  6448.   #                convert
  6449.   #-------------------------------------------------------------------------
  6450.   def self.to_hsb(r, g, b)
  6451.     # Correction if Greater than 255
  6452.     r,g,b = [r,g,b].collect! {|color| color = 255 if color > 255}
  6453.     # Get Maximum
  6454.     max = [r,g,b].max.to_f
  6455.     # Get Minimum
  6456.     min = [r,g,b].min.to_f
  6457.     # Calculate hue
  6458.     h = 60 * (g - b) / (max - min) if max == r and g >= b
  6459.     h = 60 * (g - b) / (max - min) + 360 if max == r and g < b
  6460.     h = 60 * (b - r) / (max - min) + 120 if max == g
  6461.     h = 60 * (r - g) / (max - min) + 240 if max == b
  6462.     h = 0 if max == min
  6463.     # Calculate Saturation
  6464.     s = max == 0 ? 0 : 100 * (1-min/max)
  6465.     # Calculate Brightness
  6466.     v = 100 * max / 255
  6467.     # Return Hue, Saturation, And Value
  6468.     return h,s,v
  6469.   end
  6470.   #-------------------------------------------------------------------------
  6471.   # * Name      : To HSB
  6472.   #   Info      : Converts to Hue, Saturation, and Brightness
  6473.   #               returns an array setup like so: [hue, sat, bright]
  6474.   #   Author    : Trickster
  6475.   #   Call Info : No Arguments
  6476.   #-------------------------------------------------------------------------
  6477.   def to_hsb
  6478.     return self.class.to_hsb(red, green, blue)
  6479.   end
  6480.   #-------------------------------------------------------------------------
  6481.   # * Name      : HSB New (Class Method)
  6482.   #   Info      : Creates a new color based on Hue Sat and Brightness + Alpha
  6483.   #   Author    : Trickster
  6484.   #   Call Info : Three or Four Arguements
  6485.   #               Integer hue,sat,bri - Hue, Saturation, and Brightness
  6486.   #               Integer Alpha - Transparency Defaults to 255
  6487.   #-------------------------------------------------------------------------
  6488.   def self.hsb_new(hue, sat, bri, alpha = 255)
  6489.     # Get Colors
  6490.     red, green, blue = Color.hsb_to_rgb(hue, sat, bri)
  6491.     # Create and Return Color
  6492.     return Color.new(red, green, blue, alpha)
  6493.   end
  6494.   #-------------------------------------------------------------------------
  6495.   # * Name      : HSB To RGB
  6496.   #   Info      : HSB to RGB Color Conversion
  6497.   #               An array setup like so [red, green, blue]
  6498.   #   Author    : Trickster
  6499.   #   Call Info : Three Arguments.
  6500.   #               Integer hue,sat,bri - Hue, Saturation, and Brightness
  6501.   #-------------------------------------------------------------------------
  6502.   def self.hsb_to_rgb(hue, sat, bri)
  6503.     # Convert All To Floats
  6504.     hue, sat, bri = hue.to_f, sat.to_f , bri.to_f
  6505.     # Ensure Hue is [0, 360)
  6506.     hue %= 360
  6507.     # Reduce to [0, 1]
  6508.     sat = sat > 100 ? 1.0 : sat / 100
  6509.     bri = bri > 100 ? 1.0 : bri / 100
  6510.     # Get Sector
  6511.     sector = (hue / 60).to_i
  6512.     f = hue / 60 - sector
  6513.     p = bri * (1 - sat)
  6514.     q = bri * (1 - f * sat)
  6515.     t = bri * (1 - (1 - f) * sat)
  6516.     # Branch By Sector and get r,g,b values
  6517.     case sector
  6518.     when 0...1
  6519.       r,g,b = bri,t,p
  6520.     when 1...2
  6521.       r,g,b = q,bri,p
  6522.     when 2...3
  6523.       r,g,b = p,bri,t
  6524.     when 3...4
  6525.       r,g,b = p,q,bri
  6526.     when 4...5
  6527.       r,g,b = t,p,bri
  6528.     when 5..6
  6529.       r,g,b = bri,p,q
  6530.     end
  6531.     # Set Color
  6532.     color = [r,g,b]
  6533.     # Convert to [0, 255] Range
  6534.     color.collect! {|value| value * 255}
  6535.     # Return Color
  6536.     return color
  6537.   end
  6538.   #-------------------------------------------------------------------------
  6539.   # * Name      : To RGB
  6540.   #   Info      : Converts to Red, Green, Blue
  6541.   #   Author    : Trickster
  6542.   #   Call Info : An Array setup like so [red, green, blue]
  6543.   #   Comment   : Not Very Useful, but included anyway.
  6544.   #-------------------------------------------------------------------------
  6545.   def to_rgb
  6546.     return red, green, blue
  6547.   end
  6548.   #-------------------------------------------------------------------------
  6549.   # * Name      : Get Hue
  6550.   #   Info      : Gets the hue
  6551.   #   Author    : Trickster
  6552.   #   Call Info : No Arguments
  6553.   #-------------------------------------------------------------------------
  6554.   def hue
  6555.     # If Hue is undefined set HSB
  6556.     @hue, @saturation, @brightness = to_hsb if @hue == nil
  6557.     # Return hue
  6558.     return @hue
  6559.   end
  6560.   #-------------------------------------------------------------------------
  6561.   # * Name      : Get Saturation
  6562.   #   Info      : Gets the Saturation
  6563.   #   Author    : Trickster
  6564.   #   Call Info : No Arguments
  6565.   #-------------------------------------------------------------------------
  6566.   def saturation
  6567.     # If Saturation is undefined set HSB
  6568.     @hue, @saturation, @brightness = to_hsb if @saturation == nil
  6569.     # Return Saturation
  6570.     return @saturation
  6571.   end
  6572.   #-------------------------------------------------------------------------
  6573.   # * Name      : Get Brightness
  6574.   #   Info      : Gets the Brightness
  6575.   #   Author    : Trickster
  6576.   #   Call Info : No Arguments
  6577.   #-------------------------------------------------------------------------
  6578.   def brightness
  6579.     # If Brightness is undefined set HSB
  6580.     @hue, @saturation, @brightness = to_hsb if @brightness == nil
  6581.     # Return Brightness
  6582.     return @brightness
  6583.   end
  6584.   #-------------------------------------------------------------------------
  6585.   # * Name      : Get Value
  6586.   #   Info      : Gets the Value
  6587.   #   Author    : Trickster
  6588.   #   Call Info : No Arguments
  6589.   #-------------------------------------------------------------------------
  6590.   def value
  6591.     return brightness
  6592.   end
  6593.   #-------------------------------------------------------------------------
  6594.   # * Name      : Set Hue
  6595.   #   Info      : Sets the Hue, Updates RGB
  6596.   #   Author    : Trickster
  6597.   #   Call Info : One Arguement Integer new_hue, The New Hue
  6598.   #   Comment   : May be used as a replacement to <bitmap>.hue_change, which
  6599.   #               lags and when used many times creates graphical errors
  6600.   #-------------------------------------------------------------------------  
  6601.   def hue=(new_hue)
  6602.     # Set HSB if Hue is nil
  6603.     @hue, @saturation, @brightness = to_hsb if @hue == nil
  6604.     # Ensure domain [0, 360) and set to new hue
  6605.     @hue = new_hue % 360
  6606.     # Get RGB Values
  6607.     rgb = Color.hsb_to_rgb(@hue, @saturation, @brightness)
  6608.     # Set Red Green And Blue Values by Converting to rgb
  6609.     self.red, self.green, self.blue = rgb
  6610.   end
  6611.   #-------------------------------------------------------------------------
  6612.   # * Name      : Set Saturation
  6613.   #   Info      : Sets the Saturation, Updates RGB
  6614.   #   Author    : Trickster
  6615.   #   Call Info : One Arguement Integer new_sat, The New Saturation
  6616.   #-------------------------------------------------------------------------
  6617.   def saturation=(new_sat)
  6618.     # Set HSB if Saturation is nil
  6619.     @hue, @saturation, @brightness = self.to_hsb if @saturation == nil
  6620.     # Set Saturation
  6621.     @saturation = new_sat
  6622.     # Get RGB Values
  6623.     rgb = Color.hsb_to_rgb(@hue, @saturation, @brightness)
  6624.     # Set Red Green And Blue Values by Converting to rgb
  6625.     self.red, self.green, self.blue = rgb
  6626.   end
  6627.   #-------------------------------------------------------------------------
  6628.   # * Name      : Set Brightness
  6629.   #   Info      : Sets the Brightness, Updates RGB
  6630.   #   Author    : Trickster
  6631.   #   Call Info : One Arguement Integer new_bri, The New Brightness
  6632.   #-------------------------------------------------------------------------
  6633.   def brightness=(new_bri)
  6634.     # Set HSB if Brightness is nil
  6635.     @hue, @saturation, @brightness = self.to_hsb if @brightness == nil
  6636.     # Set New Brightness
  6637.     @brightness = new_bri
  6638.     # Get RGB Values
  6639.     rgb = Color.hsb_to_rgb(@hue, @saturation, @brightness)
  6640.     # Set Red Green And Blue Values by Converting to rgb
  6641.     self.red, self.green, self.blue = rgb
  6642.   end
  6643.   #-------------------------------------------------------------------------
  6644.   # * Name      : Set Value
  6645.   #   Info      : Sets the Value, Updates RGB
  6646.   #   Author    : Trickster
  6647.   #   Call Info : One Arguement Integer new_val, The New Value
  6648.   #   Comment   : Synomym for brightness=
  6649.   #-------------------------------------------------------------------------
  6650.   def value=(val)
  6651.     # Set Brightness
  6652.     self.brightness = val
  6653.   end
  6654. end
  6655.  
  6656. #==============================================================================
  6657. # ** RGSS.Enemy and Troop Info
  6658. #------------------------------------------------------------------------------
  6659. # Description:
  6660. # ------------
  6661. # These set of methods add observer methods to the Game_Enemy and Game_Troop
  6662. # classes, you can get information on how weak an enemy is to a state, all
  6663. # of the enemies resistances and weaknesses, etc.
  6664. #  
  6665. # Method List:
  6666. # ------------
  6667. #
  6668. #   Game_Enemy
  6669. #   ----------
  6670. #   character_name
  6671. #   character_hue
  6672. #   element_effectiveness
  6673. #   state_effectiveness
  6674. #   skills
  6675. #   elements
  6676. #   element_test
  6677. #   weaknesses
  6678. #   resistance
  6679. #    
  6680. #   Game_Troop
  6681. #   ----------
  6682. #   strongest
  6683. #   weakest
  6684. #   existing_enemies
  6685. #   has_enemies?
  6686. #
  6687. #   RGP::Enemy
  6688. #   ----------
  6689. #   element_test
  6690. #   weakness
  6691. #   resistance
  6692. #
  6693. #   RPG::Troop
  6694. #   ----------
  6695. #   has_enemy?
  6696. #==============================================================================
  6697.  
  6698. MACL::Loaded << 'RGSS.Enemy and Troop Info'
  6699.  
  6700. #==============================================================================
  6701. # ** Game_Enemy
  6702. #==============================================================================
  6703.  
  6704. class Game_Enemy
  6705.   #-------------------------------------------------------------------------
  6706.   # * Name      : Character Name
  6707.   #   Info      : Returns Character Filename (Battler Name by Default)
  6708.   #   Author    : SephirothSpawn
  6709.   #   Call Info : None
  6710.   #-------------------------------------------------------------------------
  6711.   def character_name
  6712.     return self.battler_name
  6713.   end
  6714.   #-------------------------------------------------------------------------
  6715.   # * Name      : Character Hue
  6716.   #   Info      : Returns Character Filename Hue (Battler Hue by Default)
  6717.   #   Author    : SephirothSpawn
  6718.   #   Call Info : None
  6719.   #-------------------------------------------------------------------------
  6720.   def character_hue
  6721.     return self.battler_hue
  6722.   end
  6723.   #-------------------------------------------------------------------------
  6724.   #   Name      : Element Effectiveness
  6725.   #   Info      : How Effective Enemy is against an Element
  6726.   #               An Integer from 0-5 (5: most effective 0: not effective at all)
  6727.   #   Author    : Trickster
  6728.   #   Call Info : Integer Element_ID id of the element to check
  6729.   #-------------------------------------------------------------------------
  6730.   def element_effectiveness(element_id)
  6731.     # Get a numerical value corresponding to element effectiveness
  6732.     table = [0,5,4,3,2,1,0]
  6733.     effective = table[$data_enemies[@enemy_id].element_ranks[element_id]]
  6734.     # If protected by state, this element is reduced by half
  6735.     for i in @states
  6736.       if $data_states[i].guard_element_set.include?(element_id)
  6737.         effective = (effective / 2.0).ceil
  6738.       end
  6739.     end
  6740.     # End Method
  6741.     return effective
  6742.   end
  6743.   #-------------------------------------------------------------------------
  6744.   #   Name      : State Effectiveness
  6745.   #   Info      : How Effective Enemy is against a State
  6746.   #               An Integer from 0-5 (5: most effective 0: ineffective)
  6747.   #   Author    : Trickster
  6748.   #   Call Info : Integer State_ID id of the state to check
  6749.   #-------------------------------------------------------------------------
  6750.   def state_effectiveness(state_id)
  6751.     table = [0,5,4,3,2,1,0]
  6752.     effective = table[$data_enemies[@enemy_id].state_ranks[state_id]]
  6753.     return effective
  6754.   end
  6755.   #-------------------------------------------------------------------------
  6756.   #   Name      : Enemies Skills
  6757.   #   Info      : Returns all skills enemy can use
  6758.   #   Author    : Trickster
  6759.   #   Call Info : No Arguments
  6760.   #-------------------------------------------------------------------------
  6761.   def skills
  6762.     data = []
  6763.     actions.each {|action| data << action.skill_id if action.kind == 1}
  6764.     return data
  6765.   end
  6766.   #-------------------------------------------------------------------------
  6767.   #   Name      : Enemy's Elements
  6768.   #   Info      : Returns All Elements Enemy can use
  6769.   #   Author    : Trickster
  6770.   #   Call Info : No Arguments
  6771.   #-------------------------------------------------------------------------
  6772.   def elements
  6773.     elements = []
  6774.     skills.each {|skill_id| elements += $data_skills[skill_id].element_set}
  6775.     elements += element_set
  6776.     elements.uniq!
  6777.     return elements
  6778.   end
  6779.   #-------------------------------------------------------------------------
  6780.   # * Name      : Element Test
  6781.   #   Info      : Returns Element Effiency Value
  6782.   #               An Integer 1-6 representing the effiency
  6783.   #   Author    : Trickster
  6784.   #   Call Info : One Argument Element_Id the element Id to test
  6785.   #-------------------------------------------------------------------------
  6786.   def element_test(element_id)
  6787.     # Get a numerical value corresponding to element effectiveness
  6788.     table = [0,6,5,4,3,2,1]
  6789.     result = table[$data_enemies[@enemy_id].element_ranks[element_id]]
  6790.     return result
  6791.   end
  6792.   #-------------------------------------------------------------------------
  6793.   # * Name      : Weaknesses
  6794.   #   Info      : Returns Enemy Weaknesses
  6795.   #               An Array of Element Ids for which an A or B effiency
  6796.   #   Author    : Trickster
  6797.   #   Call Info : None
  6798.   #-------------------------------------------------------------------------
  6799.   def weaknesses
  6800.     weak = []
  6801.     MACL::Real_Elements.each {|i| weak << i if [6,5].include?(element_test(i))}
  6802.     return weak
  6803.   end
  6804.   #-------------------------------------------------------------------------
  6805.   # * Name      : Resistance
  6806.   #   Info      : Returns Enemy Resistance
  6807.   #               An Array of Element Ids for which an F or E or D effiency
  6808.   #   Author    : Trickster
  6809.   #   Call Info : None
  6810.   #-------------------------------------------------------------------------
  6811.   def resistance
  6812.     resists = []
  6813.     MACL::Real_Elements.each {|i| resists << i if [1,2,3].include?(element_test(i))}
  6814.     return resists
  6815.   end
  6816. end
  6817.  
  6818. #==============================================================================
  6819. # ** Game_Troop
  6820. #==============================================================================
  6821.  
  6822. class Game_Troop
  6823.   #-------------------------------------------------------------------------
  6824.   #   Name      : Strongest Enemy in Troop
  6825.   #   Info      : Gets Strongest Enemy, in terms of hp
  6826.   #   Author    : Trickster
  6827.   #   Call Info : No Arguments
  6828.   #-------------------------------------------------------------------------
  6829.   def strongest
  6830.     array = enemies.sort {|a,b| b.hp - a.hp}
  6831.     return array[0]
  6832.   end
  6833.   #-------------------------------------------------------------------------
  6834.   #   Name      : Weakest Enemy in Troop
  6835.   #   Info      : Gets Weakest Enemy, in terms of hp
  6836.   #   Author    : Trickster
  6837.   #   Call Info : No Arguments
  6838.   #-------------------------------------------------------------------------
  6839.   def weakest
  6840.     array = existing_enemies.sort! {|a,b| b.hp - a.hp}
  6841.     return array[-1]
  6842.   end
  6843.   #-------------------------------------------------------------------------
  6844.   #   Name      : Get Existing Enemies
  6845.   #   Info      : Gets All Non-Dead, Non-Hidden Enemies
  6846.   #   Author    : Trickster
  6847.   #   Call Info : No Arguments
  6848.   #-------------------------------------------------------------------------
  6849.   def existing_enemies
  6850.     array = []
  6851.     enemies.each {|enemy| array << enemy if enemy.exist?}
  6852.     return array
  6853.   end
  6854.   #-------------------------------------------------------------------------
  6855.   # * Name      : Has Enemies?
  6856.   #   Info      : Are These Enemy Ids in troop?
  6857.   #   Author    : Trickster
  6858.   #   Call Info : Variable Amount Integer Enemy enemy id to check
  6859.   #-------------------------------------------------------------------------
  6860.   def has_enemies?(*enemies)
  6861.     # Setup Array
  6862.     enemy_ids = []
  6863.     # Get All Enemy IDs
  6864.     @enemies.each {|enemy| enemy_ids << enemy.id}
  6865.     # Run Through All Enemies Sent
  6866.     enemies.each_with_index do |enemy_id, index|
  6867.       # Return false if not included
  6868.       return false if not enemy_ids.include?(enemy_id)
  6869.       # Delete from Enemies
  6870.       enemies.delete_at(index)
  6871.       # Delete ONE from Enemy Ids
  6872.       enemy_ids.delete_at(enemy_ids.index(enemy_id))
  6873.     end
  6874.     # All Are Included
  6875.     return true
  6876.   end
  6877. end
  6878.  
  6879. #==============================================================================
  6880. # ** RPG::Enemy
  6881. #==============================================================================
  6882.  
  6883. class RPG::Enemy
  6884.   #-------------------------------------------------------------------------
  6885.   # * Name      : Element Test
  6886.   #   Info      : Returns Element Effiency Value
  6887.   #               An Integer 1-6 representing the effiency
  6888.   #   Author    : Trickster
  6889.   #   Call Info : One Argument Element_Id the element Id to test
  6890.   #-------------------------------------------------------------------------
  6891.   def element_test(element_id)
  6892.     # Get a numerical value corresponding to element effectiveness
  6893.     return [0,6,5,4,3,2,1][element_ranks[element_id]]
  6894.   end
  6895.   #-------------------------------------------------------------------------
  6896.   # * Name      : Weaknesses
  6897.   #   Info      : Returns Enemy Weaknesses
  6898.   #               An Array of Element Ids for which an A or B effiency
  6899.   #   Author    : Trickster
  6900.   #   Call Info : None
  6901.   #-------------------------------------------------------------------------
  6902.   def weaknesses
  6903.     weak = []
  6904.     MACL::Real_Elements.each do |element_id|
  6905.       weak << element_id if [6,5].include?(element_test(element_id))
  6906.     end
  6907.     return weak
  6908.   end
  6909.   #-------------------------------------------------------------------------
  6910.   # * Name      : Resistance
  6911.   #   Info      : Returns Enemy Resistance
  6912.   #               An Array of Element Ids for which an F or E effiency
  6913.   #   Author    : Trickster
  6914.   #   Call Info : None
  6915.   #-------------------------------------------------------------------------
  6916.   def resistance
  6917.     resists = []
  6918.     MACL::Real_Elements.each do |element_id|
  6919.       resists << element_id if [1,2].include?(self.element_test(element_id))
  6920.     end
  6921.     return resists
  6922.   end
  6923. end
  6924.  
  6925. #==============================================================================
  6926. # ** RPG::Troop
  6927. #==============================================================================
  6928.  
  6929. class RPG::Troop
  6930.   #-------------------------------------------------------------------------
  6931.   # * Name      : Has Enemy?
  6932.   #   Info      : Does Troop have enemy id in members
  6933.   #   Author    : Trickster
  6934.   #   Call Info : One Argument Integer Enemy id - Enemy Id to check
  6935.   #-------------------------------------------------------------------------
  6936.   def has_enemy?(enemy_id)
  6937.     # Run through each member and return true if included
  6938.     self.members.each {|member| return true if member.enemy_id == enemy_id}
  6939.     # Not In Troop
  6940.     return false
  6941.   end
  6942. end
  6943.  
  6944. #==============================================================================
  6945. # ** RGSS.Font
  6946. #------------------------------------------------------------------------------
  6947. # Description:
  6948. # ------------
  6949. # This sections improves the font class to allow for more font styles, such as
  6950. # shadow and outline and strikethrough.
  6951. #  
  6952. # Method List:
  6953. # ------------
  6954. # Font.default_underline=
  6955. # Font.default_underline
  6956. # Font.default_underline_full=
  6957. # Font.default_underline_full
  6958. # Font.default_strikethrough=
  6959. # Font.default_strikethrough
  6960. # Font.default_strikethrough_full=
  6961. # Font.default_strikethrough_full
  6962. # Font.default_shadow=
  6963. # Font.default_shadow
  6964. # Font.default_shadow_color=
  6965. # Font.default_shadow_color
  6966. # Font.default_outline=
  6967. # Font.default_outline
  6968. # Font.default_outline_color=
  6969. # Font.default_outline_color
  6970. # Font.default_vert_grad=
  6971. # Font.default_vert_grad
  6972. # Font.default_horiz_grad=
  6973. # Font.default_horiz_grad
  6974. # Font.default_grad_s_color=
  6975. # Font.default_grad_s_color
  6976. # Font.default_grad_e_color=
  6977. # Font.default_grad_e_color
  6978. # underline=
  6979. # underline
  6980. # underline_full=
  6981. # underline_full
  6982. # strikethrough=
  6983. # strikethrough
  6984. # strikethrough_full=
  6985. # strikethrough_full
  6986. # shadow_color=
  6987. # shadow_color
  6988. # outline_color=
  6989. # outline_color
  6990. # shadow=
  6991. # shadow
  6992. # outline=
  6993. # outline
  6994. # vert_grad=
  6995. # vert_grad
  6996. # horiz_grad=
  6997. # horiz_grad
  6998. # grad_s_color=
  6999. # grad_s_color
  7000. # grad_e_color=
  7001. # grad_e_color
  7002. # ==(other)
  7003. #  
  7004. # Modified Methods:
  7005. # -----------------
  7006. # initailzie
  7007. #==============================================================================
  7008.  
  7009. MACL::Loaded << 'RGSS.Font'
  7010.  
  7011. #==============================================================================
  7012. # ** Font
  7013. #==============================================================================
  7014.  
  7015. class Font
  7016.   #--------------------------------------------------------------------------
  7017.   # * Class Variables
  7018.   #--------------------------------------------------------------------------
  7019.   class_accessor :default_underline
  7020.   class_accessor :default_underline_full
  7021.   class_accessor :default_strikethrough
  7022.   class_accessor :default_strikethrough_full
  7023.   class_accessor :default_shadow
  7024.   class_accessor :default_shadow_color
  7025.   class_accessor :default_outline
  7026.   class_accessor :default_outline_color
  7027.   class_accessor :default_vert_grad
  7028.   class_accessor :default_horiz_grad
  7029.   class_accessor :default_grad_s_color
  7030.   class_accessor :default_grad_e_color
  7031.   #--------------------------------------------------------------------------
  7032.   # * Class Variable Declaration
  7033.   #--------------------------------------------------------------------------
  7034.   Font.default_underline          = Default_Underline
  7035.   Font.default_underline_full     = Default_Underline_Full
  7036.   Font.default_strikethrough      = Default_Strikethrough
  7037.   Font.default_strikethrough_full = Default_Strikethrough_Full
  7038.   Font.default_shadow             = Default_Shadow
  7039.   Font.default_shadow_color       = Default_Shadow_Color
  7040.   Font.default_outline            = Default_Outline
  7041.   Font.default_outline_color      = Default_Outline_Color
  7042.   Font.default_vert_grad          = Default_Vert_Grad
  7043.   Font.default_horiz_grad         = Default_Horiz_Grad
  7044.   Font.default_grad_s_color       = Default_Grad_S_Color
  7045.   Font.default_grad_e_color       = Default_Grad_E_Color
  7046.   #--------------------------------------------------------------------------
  7047.   # * Public Instance Variables
  7048.   #--------------------------------------------------------------------------
  7049.   attr_accessor :underline
  7050.   attr_accessor :underline_full
  7051.   attr_accessor :strikethrough
  7052.   attr_accessor :strikethrough_full
  7053.   attr_accessor :shadow_color
  7054.   attr_accessor :outline_color
  7055.   attr_reader   :shadow
  7056.   attr_reader   :outline
  7057.   attr_reader   :vert_grad
  7058.   attr_reader   :horiz_grad
  7059.   attr_accessor :grad_s_color
  7060.   attr_accessor :grad_e_color
  7061.   #--------------------------------------------------------------------------
  7062.   # * Alias Listings
  7063.   #--------------------------------------------------------------------------
  7064.   alias_method :macl_rgssfont_init, :initialize
  7065.   #--------------------------------------------------------------------------
  7066.   # * Object Initialization
  7067.   #--------------------------------------------------------------------------
  7068.   def initialize(*args)
  7069.     # Set font settings
  7070.     @underline          = Font.default_underline
  7071.     @underline_full     = Font.default_underline_full
  7072.     @strikethrough      = Font.default_strikethrough
  7073.     @strikethrough_full = Font.default_strikethrough_full
  7074.     @shadow_color       = Font.default_shadow_color
  7075.     @outline_color      = Font.default_outline_color
  7076.     @shadow             = Font.default_shadow
  7077.     @outline            = Font.default_outline
  7078.     @vert_grad          = Font.default_vert_grad
  7079.     @horiz_grad         = Font.default_horiz_grad
  7080.     @grad_s_color       = Font.default_grad_s_color
  7081.     @grad_e_color       = Font.default_grad_e_color
  7082.     # Original Initialization
  7083.     macl_rgssfont_init(*args)
  7084.   end
  7085.   #-------------------------------------------------------------------------
  7086.   # * Name      : Set Shadow
  7087.   #   Info      : Sets Shadow Flag
  7088.   #   Author    : Yeyinde
  7089.   #   Call Info : One Argument Boolean bool flag
  7090.   #-------------------------------------------------------------------------
  7091.   def shadow=(bool)
  7092.     @shadow = bool
  7093.     @outline = false unless bool == false
  7094.   end
  7095.   #-------------------------------------------------------------------------
  7096.   # * Name      : Set Outline
  7097.   #   Info      : Sets Outline Flag
  7098.   #   Author    : Yeyinde
  7099.   #   Call Info : One Argument Boolean bool flag
  7100.   #-------------------------------------------------------------------------
  7101.   def outline=(bool)
  7102.     @shadow = false unless bool == false
  7103.     @outline = bool
  7104.   end
  7105.   #-------------------------------------------------------------------------
  7106.   # * Name      : Set Vert Gradient
  7107.   #   Info      : Sets Vert Gradient Flag
  7108.   #   Author    : SephirothSpawn
  7109.   #   Call Info : One Argument Boolean bool flag
  7110.   #-------------------------------------------------------------------------
  7111.   def vert_grad=(bool)
  7112.     @vert_grad = bool
  7113.     @horiz_grad = false unless bool == false
  7114.   end
  7115.   #-------------------------------------------------------------------------
  7116.   # * Name      : Set Horiz Gradient
  7117.   #   Info      : Sets Horiz Gradient Flag
  7118.   #   Author    : SephirothSpawn
  7119.   #   Call Info : One Argument Boolean bool flag
  7120.   #-------------------------------------------------------------------------
  7121.   def horiz_grad=(bool)
  7122.     @vert_grad = false unless bool == false
  7123.     @horiz_grad = bool
  7124.   end
  7125.   #-------------------------------------------------------------------------
  7126.   #   Name      : == (Comparision Equals)
  7127.   #   Info      : Compares two Fonts
  7128.   #   Author    : Trickster
  7129.   #   Call Info : One Argument Font other, Font to Check
  7130.   #-------------------------------------------------------------------------
  7131.   def ==(other)
  7132.     attr = %w( name size color bold italic underline underline_full strikethrough
  7133.     strikethrough_full shadow_color outline_color shadow outline vert_grad
  7134.     horiz_grad grad_s_color grad_e_color)
  7135.     attr.each do |var|
  7136.       return false if method(var).call != other.method(var).call
  7137.     end
  7138.     return true
  7139.   end
  7140. end
  7141.  
  7142. #==============================================================================
  7143. # ** RGSS.Input
  7144. #------------------------------------------------------------------------------
  7145. # Description:
  7146. # ------------
  7147. # New methods to add to the RGSS Modules
  7148. #  
  7149. # Method List:
  7150. # ------------
  7151. #
  7152. # disable_key
  7153. # enable_key
  7154. #==============================================================================
  7155.  
  7156. MACL::Loaded << 'RGSS.Input'
  7157.  
  7158. #==============================================================================
  7159. # ** Input
  7160. #==============================================================================
  7161.  
  7162. module Input
  7163.   #------------------------------------------------------------------------
  7164.   # * Disabled Keys
  7165.   #------------------------------------------------------------------------
  7166.   @disabled_keys  = []
  7167.   @disabled_timer = {}
  7168.   class << self
  7169.     #------------------------------------------------------------------------
  7170.     # * Alias Listings
  7171.     #------------------------------------------------------------------------
  7172.     unless self.method_defined?(:seph_disabledkeys_input_update)
  7173.       alias_method :seph_disabledkeys_input_update,   :update
  7174.       alias_method :seph_disabledkeys_input_press?,   :press?
  7175.       alias_method :seph_disabledkeys_input_trigger?, :trigger?
  7176.       alias_method :seph_disabledkeys_input_repeat?,  :repeat?
  7177.       alias_method :seph_disabledkeys_input_dir4,     :dir4
  7178.       alias_method :seph_disabledkeys_input_dir8,     :dir8
  7179.     end
  7180.     #------------------------------------------------------------------------
  7181.     # * Name      : Disable Key
  7182.     #   Info      : Disables Input Constant from being read
  7183.     #   Author    : SephirothSpawn
  7184.     #   Call Info : Constant defined in Input Module to be disabled
  7185.     #               Frames to be disabled (nil for infinite frames)
  7186.     #------------------------------------------------------------------------
  7187.     def disable_key(constant, frames = nil)
  7188.       # Add Key to Disabled List
  7189.       @disabled_keys << constant unless @disabled_keys.include?(constant)
  7190.       # Set Disabled Counter if non-nil
  7191.       @disabled_timer[constant] = frames unless frames.nil?
  7192.     end
  7193.     #------------------------------------------------------------------------
  7194.     # * Name      : Enable Key
  7195.     #   Info      : Enable Input Constant
  7196.     #   Author    : SephirothSpawn
  7197.     #   Call Info : Constant defined in Input Module to be enabled
  7198.     #------------------------------------------------------------------------
  7199.     def enable_key(constant)
  7200.       # Remove Constant From List
  7201.       @disabled_keys.delete(constant)
  7202.       # Set Nil Timer
  7203.       @disabled_timer[constant] = nil
  7204.     end
  7205.     #------------------------------------------------------------------------
  7206.     # * Frame Update
  7207.     #------------------------------------------------------------------------
  7208.     def update
  7209.       # Pass Through Timer List
  7210.       @disabled_timer.each do |key, timer|
  7211.         # Next if nil timer or key not-disabled
  7212.         next if timer.nil? || !@disabled_keys.include?(key)
  7213.         # If Greater than 0 Timer
  7214.         if timer > 0
  7215.           timer -= 1
  7216.           next
  7217.         end
  7218.         # Enable Key
  7219.         @disabled_keys.delete(key) if @disabled_keys.include?(key)
  7220.         # Set Timer to Nil
  7221.         @disabled_timer[key] = nil
  7222.       end
  7223.       # Original Update
  7224.       seph_disabledkeys_input_update
  7225.     end
  7226.     #------------------------------------------------------------------------
  7227.     # * Press? Test
  7228.     #------------------------------------------------------------------------
  7229.     def press?(constant)
  7230.       return @disabled_keys.include?(constant) ?
  7231.         false : seph_disabledkeys_input_press?(constant)
  7232.     end
  7233.     #------------------------------------------------------------------------
  7234.     # * Trigger? Test
  7235.     #------------------------------------------------------------------------
  7236.     def trigger?(constant)
  7237.       return @disabled_keys.include?(constant) ?
  7238.         false : seph_disabledkeys_input_trigger?(constant)
  7239.     end
  7240.     #------------------------------------------------------------------------
  7241.     # * Repeat? Test
  7242.     #------------------------------------------------------------------------
  7243.     def repeat?(constant)
  7244.       return @disabled_keys.include?(constant) ?
  7245.         false : seph_disabledkeys_input_repeat?(constant)
  7246.     end
  7247.     #------------------------------------------------------------------------
  7248.     # * Dir4 Test
  7249.     #------------------------------------------------------------------------
  7250.     def dir4
  7251.       # Gets Original Direction Test
  7252.       dir = seph_disabledkeys_input_dir4
  7253.       # Return 0 if Direction Disabled
  7254.       if (dir == 2 && @disabled_keys.include?(DOWN))  ||
  7255.          (dir == 4 && @disabled_keys.include?(LEFT))  ||
  7256.          (dir == 6 && @disabled_keys.include?(RIGHT)) ||
  7257.          (dir == 8 && @disabled_keys.include?(UP))
  7258.         return 0
  7259.       end
  7260.       # Return Original Dir Test
  7261.       return dir
  7262.     end
  7263.     #------------------------------------------------------------------------
  7264.     # * Dir8 Test
  7265.     #------------------------------------------------------------------------
  7266.     def dir8
  7267.       # Gets Original Direction Test
  7268.       dir = seph_disabledkeys_input_dir8
  7269.       # Return 0 if Direction Disabled
  7270.       if (dir == 2 && @disabled_keys.include?(DOWN))  ||
  7271.          (dir == 4 && @disabled_keys.include?(LEFT))  ||
  7272.          (dir == 6 && @disabled_keys.include?(RIGHT)) ||
  7273.          (dir == 8 && @disabled_keys.include?(UP))    ||
  7274.          (dir == 1 && @disabled_keys.include?(DOWN)   &&
  7275.                       @disabled_keys.include?(LEFT))  ||
  7276.          (dir == 3 && @disabled_keys.include?(DOWN)   &&
  7277.                       @disabled_keys.include?(RIGHT)) ||
  7278.          (dir == 7 && @disabled_keys.include?(UP)     &&
  7279.                       @disabled_keys.include?(LEFT))  ||
  7280.          (dir == 9 && @disabled_keys.include?(UP)     &&
  7281.                       @disabled_keys.include?(RIGHT))
  7282.         return 0
  7283.       end
  7284.       # Return Original Dir Test
  7285.       return dir
  7286.     end
  7287.   end
  7288. end
  7289.  
  7290. #==============================================================================
  7291. # ** RGSS.Interpreter
  7292. #------------------------------------------------------------------------------
  7293. # Description:
  7294. # ------------
  7295. # Miscellaneous methods for RGSS classes.
  7296. #  
  7297. # Method List:
  7298. # ------------
  7299. # event
  7300. #==============================================================================
  7301.  
  7302. MACL::Loaded << 'RGSS.Interpreter'
  7303.  
  7304. #==============================================================================
  7305. # ** Interpreter
  7306. #==============================================================================
  7307.  
  7308. class Interpreter
  7309.   #--------------------------------------------------------------------------
  7310.   # * Name      : Event
  7311.   #   Info      : Returns Interpreter Event
  7312.   #   Author    : Near Fantastica
  7313.   #   Call Info : Nothing
  7314.   #--------------------------------------------------------------------------
  7315.   def event
  7316.     return $game_map.events[@event_id]
  7317.   end
  7318. end
  7319.  
  7320. #==============================================================================
  7321. # ** RGSS.Map
  7322. #------------------------------------------------------------------------------
  7323. # Description:
  7324. # ------------
  7325. # These set of methods add to the map classes, game, spriteset & scene.
  7326. #  
  7327. # Method List:
  7328. # ------------
  7329. #
  7330. #   Game_Map
  7331. #   --------
  7332. #   characters
  7333. #   add_event
  7334. #   delete_event
  7335. #   add_character
  7336. #   delete_character
  7337. #   event?
  7338. #   event_at
  7339. #   character?
  7340. #   character_at
  7341. #   tile_terrain
  7342. #   terrain_ids
  7343. #    
  7344. #   Spriteset_Map
  7345. #   -------------
  7346. #   add_character
  7347. #   delete_character
  7348. #
  7349. #   Scene_Map
  7350. #   ---------
  7351. #   spriteset
  7352. #==============================================================================
  7353.  
  7354. MACL::Loaded << 'RGSS.Map'
  7355.  
  7356. #==============================================================================
  7357. # ** Game_Map
  7358. #==============================================================================
  7359.  
  7360. class Game_Map
  7361.   #--------------------------------------------------------------------------
  7362.   # * Public Instance Variables
  7363.   #--------------------------------------------------------------------------
  7364.   attr_reader   :characters
  7365.   #--------------------------------------------------------------------------
  7366.   # * Alias Listings
  7367.   #--------------------------------------------------------------------------
  7368.   alias_method :seph_macl_gmmap_setup,   :setup
  7369.   alias_method :seph_macl_gmmap_refresh, :refresh
  7370.   alias_method :seph_macl_gmmap_passbl?, :passable?
  7371.   alias_method :seph_macl_gmmap_update,  :update
  7372.   #--------------------------------------------------------------------------
  7373.   # * Setup
  7374.   #--------------------------------------------------------------------------
  7375.   def setup(map_id)
  7376.     # Set map characters data
  7377.     @characters = {}
  7378.     # Original Setup
  7379.     seph_macl_gmmap_setup(map_id)
  7380.   end
  7381.   #--------------------------------------------------------------------------
  7382.   # * Refresh
  7383.   #--------------------------------------------------------------------------
  7384.   def refresh
  7385.     # Original Refresh
  7386.     seph_macl_gmmap_refresh
  7387.     # If map ID is effective
  7388.     if @map_id > 0
  7389.       # Refresh all map characters
  7390.       for character in @characters.values
  7391.         character.refresh
  7392.       end
  7393.     end
  7394.   end
  7395.   #--------------------------------------------------------------------------
  7396.   # * Determine if Passable
  7397.   #--------------------------------------------------------------------------
  7398.   def passable?(x, y, d, self_event = nil)
  7399.     # Return false if Previous Test False
  7400.     return false unless seph_macl_gmmap_passbl?(x, y, d, self_event)
  7401.     # Change direction (0,2,4,6,8,10) to obstacle bit (0,1,2,4,8,0)
  7402.     bit = (1 << (d / 2 - 1)) & 0x0f
  7403.     # Loop in all characters
  7404.     for character in @characters.values
  7405.       # If tiles other than self are consistent with coordinates
  7406.       if character.tile_id >= 0 and character != self_event and
  7407.          character.x == x and character.y == y and not character.through
  7408.         # If obstacle bit is set
  7409.         if @passages[character.tile_id] & bit != 0
  7410.           # impassable
  7411.           return false
  7412.         # If obstacle bit is set in all directions
  7413.         elsif @passages[character.tile_id] & 0x0f == 0x0f
  7414.           # impassable
  7415.           return false
  7416.         # If priorities other than that are 0
  7417.         elsif @priorities[character.tile_id] == 0
  7418.           # passable
  7419.           return true
  7420.         end
  7421.       end
  7422.     end
  7423.     # passable
  7424.     return true
  7425.   end
  7426.   #--------------------------------------------------------------------------
  7427.   # * Frame Update
  7428.   #--------------------------------------------------------------------------
  7429.   def update
  7430.     # Original Update
  7431.     seph_macl_gmmap_update
  7432.     # Update map characters
  7433.     for character in @characters.values
  7434.       character.update
  7435.     end
  7436.   end
  7437.   #-------------------------------------------------------------------------
  7438.   # * Name      : Add Event
  7439.   #   Info      : Adds Game_Event to Game_Map#events list
  7440.   #   Author    : SephirothSpawn
  7441.   #   Call Info : RPG::Event object
  7442.   #-------------------------------------------------------------------------
  7443.   def add_event(event)
  7444.     # Change Id if Already Taken
  7445.     event.id = @events.keys.max + 1 if @events.has_key?(event.id)
  7446.     # Creates New Event
  7447.     @events[event.id] = Game_Event.new(@map_id, event)
  7448.     # Adds To Spriteset
  7449.     if $scene.is_a?(Scene_Map) && $scene.spriteset.is_a?(Spriteset_Map)
  7450.       $scene.spriteset.add_character(@events[event.id])
  7451.     end
  7452.   end
  7453.   #-------------------------------------------------------------------------
  7454.   # * Name      : Delete Event
  7455.   #   Info      : Deletes Game_Event to Game_Map#events list
  7456.   #   Author    : SephirothSpawn
  7457.   #   Call Info : Event ID
  7458.   #-------------------------------------------------------------------------
  7459.   def delete_event(event_id = 1)
  7460.     # Return if event not present
  7461.     return unless @events.has_key?(event_id)
  7462.     # Removes event from spriteset
  7463.     if $scene.is_a?(Scene_Map) && $scene.spriteset.is_a?(Spriteset_Map)
  7464.       $scene.spriteset.delete_character(@events[event_id])
  7465.     end
  7466.     # Deletes event from events list
  7467.     @events.delete(event_id)
  7468.   end
  7469.   #-------------------------------------------------------------------------
  7470.   # * Name      : Add Character
  7471.   #   Info      : Adds Game_Character to Game_Map#characters list
  7472.   #   Author    : SephirothSpawn
  7473.   #   Call Info : Game_Character, ID of Event (Auto-corrects if taken)
  7474.   #-------------------------------------------------------------------------
  7475.   def add_character(character, id = nil)
  7476.     # If ID Already taken or nil
  7477.     if id.nil? || @characters.has_key?(id)
  7478.       id = @characters.empty? ? 1 : @characters.keys.max + 1
  7479.     end
  7480.     # Creates New Event
  7481.     @characters[id] = character
  7482.     # Adds To Spriteset
  7483.     if $scene.is_a?(Scene_Map) && $scene.spriteset.is_a?(Spriteset_Map)
  7484.       $scene.spriteset.add_character(character)
  7485.     end
  7486.   end
  7487.   #-------------------------------------------------------------------------
  7488.   # * Name      : Delete Character
  7489.   #   Info      : Deletes Game_Character to Game_Map#characters list
  7490.   #   Author    : SephirothSpawn
  7491.   #   Call Info : Character ID
  7492.   #-------------------------------------------------------------------------
  7493.   def delete_character(character_id = 1)
  7494.     # Return if character not present
  7495.     return unless @characters.has_key?(character_id)
  7496.     # Removes character from spriteset
  7497.     if $scene.is_a?(Scene_Map) && $scene.spriteset.is_a?(Spriteset_Map)
  7498.       $scene.spriteset.delete_character(@characters[character_id])
  7499.     end
  7500.     # Deletes character from characters list
  7501.     @characters.delete(character_id)
  7502.   end
  7503.   #-------------------------------------------------------------------------
  7504.   # * Name      : Event?
  7505.   #   Info      : Is there an event on x and y
  7506.   #   Author    : Trickster
  7507.   #   Call Info : Two Arguments Integer X, Y - Position to Check
  7508.   #-------------------------------------------------------------------------
  7509.   def event?(x, y)
  7510.     @events.each_value do |event|
  7511.       return true if event.x == x and event.y == y
  7512.     end
  7513.     return false
  7514.   end
  7515.   #-------------------------------------------------------------------------
  7516.   # * Name      : Event at
  7517.   #   Info      : Returns event at location or nil
  7518.   #   Author    : SephirothSpawn
  7519.   #   Call Info : Two Arguments Integer X, Y - Position to Check
  7520.   #-------------------------------------------------------------------------
  7521.   def event_at(x, y)
  7522.     for event in @events.values
  7523.       return event if event.x == x && event.y == y
  7524.     end
  7525.     return nil
  7526.   end
  7527.   #-------------------------------------------------------------------------
  7528.   # * Name      : Character?
  7529.   #   Info      : Is there an character on x and y
  7530.   #   Author    : SephirothSpawn
  7531.   #   Call Info : Two Arguments Integer X, Y - Position to Check
  7532.   #-------------------------------------------------------------------------
  7533.   def character?(x, y)
  7534.     @characters.each_value do |character|
  7535.       return true if character.x == x and character.y == y
  7536.     end
  7537.     return false
  7538.   end
  7539.   #-------------------------------------------------------------------------
  7540.   # * Name      : Character at
  7541.   #   Info      : Returns character at location or nil
  7542.   #   Author    : SephirothSpawn
  7543.   #   Call Info : Two Arguments Integer X, Y - Position to Check
  7544.   #-------------------------------------------------------------------------
  7545.   def character_at(x, y)
  7546.     @characters.each_value do |character|
  7547.       return character if character.x == x and character.y == y
  7548.     end
  7549.     return nil
  7550.   end
  7551.   #-------------------------------------------------------------------------
  7552.   # * Name      : Tile Terrain
  7553.   #   Info      : Returns tile specific terrain from given x, y and layer
  7554.   #   Author    : Hanmac
  7555.   #   Call Info : x, y, z (Integer) Position
  7556.   #-------------------------------------------------------------------------
  7557.   def tile_terrain(x, y, z)
  7558.     tile_id = data[x, y, z]
  7559.     return tile_id.nil? ? 0 : @terrain_tags[tile_id]
  7560.   end
  7561.   #-------------------------------------------------------------------------
  7562.   # * Name      : Terrain IDs
  7563.   #   Info      : Returns a list of terrain ids at a x y locations
  7564.   #   Author    : Hanmac
  7565.   #   Call Info : x, y (Integer) Position
  7566.   #-------------------------------------------------------------------------
  7567.   def terrain_ids(x, y)
  7568.     return [0, 1, 2].collect {|i| tile_terrain(x, y, i)}
  7569.   end
  7570. end
  7571.  
  7572. #==============================================================================
  7573. # ** Spriteset_Map
  7574. #==============================================================================
  7575.  
  7576. class Spriteset_Map
  7577.   #--------------------------------------------------------------------------
  7578.   # * Add Character
  7579.   #--------------------------------------------------------------------------
  7580.   def add_character(game_character)
  7581.     # Returns if Character already has sprite
  7582.     for sprite in @character_sprites
  7583.       return if sprite.character == game_character
  7584.     end
  7585.     # Adds New Sprite
  7586.     @character_sprites << Sprite_Character.new(@viewport1, game_character)
  7587.   end
  7588.   #--------------------------------------------------------------------------
  7589.   # * Delete Character
  7590.   #--------------------------------------------------------------------------
  7591.   def delete_character(game_character)
  7592.     # Pass Through Sprites
  7593.     for sprite in @character_sprites
  7594.       # If Character Matches
  7595.       if sprite.character == game_character
  7596.         # Dispose Sprite
  7597.         sprite.dispose
  7598.         # Delete from List
  7599.         @character_sprites.delete(sprite)
  7600.         break
  7601.       end
  7602.     end
  7603.   end
  7604. end
  7605.  
  7606. #==============================================================================
  7607. # ** Scene_Map
  7608. #==============================================================================
  7609.  
  7610. class Scene_Map
  7611.   #--------------------------------------------------------------------------
  7612.   # * Public Instance Variables
  7613.   #--------------------------------------------------------------------------
  7614.   attr_reader :spriteset
  7615. end
  7616.  
  7617. #==============================================================================
  7618. # ** RGSS.RPG::AudioFile
  7619. #------------------------------------------------------------------------------
  7620. # Description:
  7621. # ------------
  7622. # New methods to add to the RPG::AudioFile class
  7623. #  
  7624. # Method List:
  7625. # ------------
  7626. # is_a_bgm?
  7627. # is_a_bgm=
  7628. # is_a_bgm
  7629. # is_a_bgs?
  7630. # is_a_bgs=
  7631. # is_a_bgs
  7632. # is_a_me?
  7633. # is_a_me=
  7634. # is_a_me
  7635. # is_a_se?
  7636. # is_a_se=
  7637. # is_a_se
  7638. # play
  7639. # stop
  7640. #==============================================================================
  7641.  
  7642. MACL::Loaded << 'RGSS.RPG::AudioFile'
  7643.  
  7644. #==============================================================================
  7645. # ** RPG::AudioFile
  7646. #==============================================================================
  7647.  
  7648. class RPG::AudioFile
  7649.   #--------------------------------------------------------------------------
  7650.   # * Public Instance Variables
  7651.   #--------------------------------------------------------------------------
  7652.   attr_accessor :is_a_bgm
  7653.   attr_accessor :is_a_bgs
  7654.   attr_accessor :is_a_me
  7655.   attr_accessor :is_a_se
  7656.   #-------------------------------------------------------------------------
  7657.   # * Name      : Is a BGM?
  7658.   #   Info      : Test if AudioFile is BGM (In theory)
  7659.   #   Author    : SephirothSpawn
  7660.   #-------------------------------------------------------------------------
  7661.   def is_a_bgm?
  7662.     return @is_a_bgm.nil? ? @name.include?('BGM/') : @is_a_bgm
  7663.   end
  7664.   #-------------------------------------------------------------------------
  7665.   # * Name      : Is a BGS?
  7666.   #   Info      : Test if AudioFile is BGS (In theory)
  7667.   #   Author    : SephirothSpawn
  7668.   #-------------------------------------------------------------------------
  7669.   def is_a_bgs?
  7670.     return @is_a_bgs.nil? ? @name.include?('BGS/') : @is_a_bgs
  7671.   end
  7672.   #-------------------------------------------------------------------------
  7673.   # * Name      : Is a ME?
  7674.   #   Info      : Test if AudioFile is ME (In theory)
  7675.   #   Author    : SephirothSpawn
  7676.   #-------------------------------------------------------------------------
  7677.   def is_a_me?
  7678.     return @is_a_me.nil? ? @name.include?('ME/') : @is_a_me
  7679.   end
  7680.   #-------------------------------------------------------------------------
  7681.   # * Name      : Is a SE?
  7682.   #   Info      : Test if AudioFile is SE (In theory)
  7683.   #   Author    : SephirothSpawn
  7684.   #-------------------------------------------------------------------------
  7685.   def is_a_se?
  7686.     return @is_a_se.nil? ? @name.include?('SE/') : @is_a_se
  7687.   end
  7688.   #-------------------------------------------------------------------------
  7689.   # * Name      : Play
  7690.   #   Info      : Autoplays AudioFile
  7691.   #   Author    : SephirothSpawn
  7692.   #-------------------------------------------------------------------------
  7693.   def play
  7694.     if is_a_bgm?
  7695.       Audio.bgm_play(@name, @volume, @pitch)
  7696.     elsif is_a_bgs?
  7697.       Audio.bgs_play(@name, @volume, @pitch)
  7698.     elsif is_a_me?
  7699.       Audio.me_play(@name, @volume, @pitch)
  7700.     elsif is_a_se?
  7701.       Audio.se_play(@name, @volume, @pitch)
  7702.     end
  7703.   end
  7704.   #-------------------------------------------------------------------------
  7705.   # * Name      : Stop
  7706.   #   Info      : Stops AudioFile
  7707.   #   Author    : SephirothSpawn
  7708.   #-------------------------------------------------------------------------
  7709.   def stop
  7710.     if is_a_bgm?
  7711.       Audio.bgm_stop
  7712.     elsif is_a_bgs?
  7713.       Audio.bgs_stop
  7714.     elsif is_a_me?
  7715.       Audio.me_stop
  7716.     elsif is_a_se?
  7717.       Audio.se_stop
  7718.     end
  7719.   end
  7720. end
  7721.  
  7722. #==============================================================================
  7723. # ** RGSS.RPG::Cache
  7724. #------------------------------------------------------------------------------
  7725. # Description:
  7726. # ------------
  7727. # These set of methods add to the RPG::Cache.
  7728. #  
  7729. # Method List:
  7730. # ------------
  7731. # autotile_tile
  7732. # gradient
  7733. #==============================================================================
  7734.  
  7735. MACL::Loaded << 'RGSS.RPG::Cache'
  7736.  
  7737. #==============================================================================
  7738. # ** RPG::Cache
  7739. #==============================================================================
  7740.  
  7741. module RPG::Cache
  7742.   #--------------------------------------------------------------------------
  7743.   # * Auto-Tiles
  7744.   #--------------------------------------------------------------------------
  7745.   Autotiles = [
  7746.     [[27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],
  7747.      [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12]],
  7748.     [[27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],
  7749.      [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12]],
  7750.     [[25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],
  7751.      [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12]],
  7752.     [[29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
  7753.      [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46]],
  7754.     [[25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
  7755.      [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48]],
  7756.     [[37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
  7757.      [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8]]
  7758.   ]
  7759.   #--------------------------------------------------------------------------
  7760.   # * Autotile Cache
  7761.   #
  7762.   #   @autotile_cache = {
  7763.   #     filename => { [autotile_id, frame_id, hue] => bitmap, ... },
  7764.   #     ...
  7765.   #    }
  7766.   #--------------------------------------------------------------------------
  7767.   @autotile_cache = {}
  7768.   #--------------------------------------------------------------------------
  7769.   # * Autotile Tile
  7770.   #--------------------------------------------------------------------------
  7771.   def self.autotile_tile(filename, tile_id, hue = 0, frame_id = nil)
  7772.     # Gets Autotile Bitmap
  7773.     autotile = self.autotile(filename)
  7774.     # Configures Frame ID if not specified
  7775.     if frame_id.nil?
  7776.       # Animated Tiles
  7777.       frames = autotile.width / 96
  7778.       # Configures Animation Offset
  7779.       fc = Graphics.frame_count / Animated_Autotiles_Frames
  7780.       frame_id = (fc) % frames * 96
  7781.     end
  7782.     # Creates list if already not created
  7783.     @autotile_cache[filename] = {} unless @autotile_cache.has_key?(filename)
  7784.     # Gets Key
  7785.     key = [tile_id, frame_id, hue]
  7786.     # If Key Not Found
  7787.     unless @autotile_cache[filename].has_key?(key)
  7788.       # Reconfigure Tile ID
  7789.       tile_id %= 48
  7790.       # Creates Bitmap
  7791.       bitmap = Bitmap.new(32, 32)
  7792.       # Collects Auto-Tile Tile Layout
  7793.       tiles = Autotiles[tile_id / 8][tile_id % 8]
  7794.       # Draws Auto-Tile Rects
  7795.       for i in 0...4
  7796.         tile_position = tiles[i] - 1
  7797.         src_rect = Rect.new(tile_position % 6 * 16 + frame_id,
  7798.           tile_position / 6 * 16, 16, 16)
  7799.         bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
  7800.       end
  7801.       # Saves Autotile to Cache
  7802.       @autotile_cache[filename][key] = bitmap
  7803.       # Change Hue
  7804.       @autotile_cache[filename][key].hue_change(hue)
  7805.     end
  7806.     # Return Autotile
  7807.     return @autotile_cache[filename][key]
  7808.   end
  7809.   #-------------------------------------------------------------------------
  7810.   # * Name      : Gradient
  7811.   #   Info      : Loads A Gradient Bar
  7812.   #   Author    : Trickster
  7813.   #   Call Info : One to Two Arguments
  7814.   #               String filename of Bar to load
  7815.   #               Integer hue - hue displacement
  7816.   #   Comment   : Files are to be located in Graphics/Gradients
  7817.   #-------------------------------------------------------------------------
  7818.   def self.gradient(filename, hue = 0)
  7819.     self.load_bitmap("Graphics/Gradients/", filename, hue)
  7820.   end
  7821. end
  7822.  
  7823. #==============================================================================
  7824. # ** RGSS.RPG::State
  7825. #------------------------------------------------------------------------------
  7826. # Description:
  7827. # ------------
  7828. # Miscellaneous New stuff for the RPG::State class.
  7829. #  
  7830. # Method List:
  7831. # ------------
  7832. # RPG::State.normal_icon_name
  7833. # RPG::State.normal_icon
  7834. # icon_name
  7835. # icon
  7836. #==============================================================================
  7837.  
  7838. MACL::Loaded << 'RGSS.RPG::State'
  7839.  
  7840. #==============================================================================
  7841. # ** RPG::State
  7842. #==============================================================================
  7843.  
  7844. class RPG::State
  7845.   #--------------------------------------------------------------------------
  7846.   # * Normal Icon Name
  7847.   #--------------------------------------------------------------------------
  7848.   def self.normal_icon_name
  7849.     return Normal_Icon
  7850.   end
  7851.   #--------------------------------------------------------------------------
  7852.   # * Normal Icon
  7853.   #--------------------------------------------------------------------------
  7854.   def self.normal_icon
  7855.     begin
  7856.       return RPG::Cache.icon(Normal_Icon)
  7857.     rescue
  7858.       return nil
  7859.     end
  7860.   end
  7861.   #--------------------------------------------------------------------------
  7862.   # * Icon Name
  7863.   #--------------------------------------------------------------------------
  7864.   def icon_name
  7865.     return Icon_Name[@id].nil? ? self.name : Icon_Name[@id]
  7866.   end
  7867.   #--------------------------------------------------------------------------
  7868.   # * Icon
  7869.   #--------------------------------------------------------------------------
  7870.   def icon
  7871.     begin
  7872.       return RPG::Cache.icon(icon_name)
  7873.     rescue
  7874.       return nil
  7875.     end
  7876.   end
  7877. end
Add Comment
Please, Sign In to add comment