MACL - Method and Class Library 2.3

Method and Class Library
Version 2.3

What is this?

This script set provides a utility for other scripters by: adding extra methods, classes & modules to prevent other scripters from "reinventing the wheel" and adding methods, classes & modules for other scripters to use. It also provides a set of commonly used constants so setup will not be as much as a hassle among scripts.


Installing the MACL 2.3

Simple copy and paste the MACL Complete text file from below into your game. Paste it below Scene_Debug. Make sure this is the first script after Scene_Debug unless you use the SDK, then put this directly after the SDK.

Files
MACL Complete Text File

What Can I do to Help?

If you have something you want to submit, then post here but read the section in the documentation on this topic. If you find a bug with any item in the library also post here. All of your help is appreciated.
Well, here it goes.

By the way that there is no fill version of these methods. I planned to do them later as they are slightly more complicated but in the end I chose to let it gather dust instead.

Note that the Bitmap#draw_ellipse method is actually a draw_polygon that, by default, draws a 30-sided polygon... but at 30 sides, it looks like a circle or an ellipse. Change the parameter to smaller values if you want something that looks like a polygon. Also, please leave the line_width parameter to its default value, which is 1. You will probably get sloppy results if you use another value. That parameter should be removed. (That, or the Bitmap#draw_line method, which is used "under-the-hood", should be recoded to round its extremities so it looks better.)

Ok, enough talk. Here is the script.
  1. #==============================================================================
  2. #******************************************************************************
  3. #
  4. # RGSS Extensions: Bitmap
  5. # ----------------------------------------------------------------------------
  6. # This script is an extension of the Bitmap class provided with RGSS. It
  7. # allows to execute more vectorial and geometric operations, such as drawing
  8. # lines, circles, rectangles, etc...
  9. #
  10. # Note that all those operations are coded in Ruby, so if you heavily depend on
  11. # those operations (if you redraw them on every frame, etc...), it might
  12. # slowdown your game. The best, as always, is to draw only when necessary.
  13. #
  14. #                                                              by exseiken
  15. #
  16. #******************************************************************************
  17. #==============================================================================
  18.  
  19. class Bitmap
  20.   #----------------------------------------------------------------------------
  21.   # draw_line: Draw a line between points (x1;y1) and (x2;y2) on the bitmap.
  22.   #   x1: X-coordinate of an extremity of the line.
  23.   #   y1: Y-coordinate of an extremity of the line.
  24.   #   x2: X-coordinate of another extremity of the line.
  25.   #   y2: Y-coordinate of another extremity of the line.
  26.   #   color: The color of the line. It can support transparency.
  27.   #   line_width: The width of the line in pixels. Set to 1 by default.
  28.   #----------------------------------------------------------------------------
  29.   def draw_line(x1, y1, x2, y2, color, line_width = 1)
  30.     # calculate the dimensions vertically and horizontally
  31.     cx = x2 - x1
  32.     cy = y2 - y1
  33.    
  34.     # if the line is larger horizontally, draw it on an horizontal basis
  35.     if cx.abs > cy.abs
  36.       # if cx is 0, don't draw
  37.       return if cx == 0
  38.      
  39.       # reorder the coordinates so that x1 is left of x2
  40.       if x2 < x1
  41.         temp = x2
  42.         x2 = x1
  43.         x1 = temp
  44.         temp = y2
  45.         y2 = y1
  46.         y1 = temp
  47.       end
  48.      
  49.       # draw the line
  50.       for i in 0..cx.abs
  51.         # calculate the position vertically
  52.         y = y1 + cy * i / cx
  53.        
  54.         # draw the pixel
  55.         set_pixel(x1 + i, y, color)
  56.        
  57.         # enlarge the line if the width is not 1
  58.         if line_width != 1
  59.           for j in 2..line_width
  60.             # on even counter, draw higher; on odd draw below
  61.             if (j & 1) == 0
  62.               set_pixel(x1 + i, y - j / 2, color)
  63.             else
  64.               set_pixel(x1 + i, y + j / 2, color)
  65.             end
  66.           end
  67.         end
  68.       end
  69.     else
  70.       # if cy is 0, don't draw
  71.       return if cy == 0
  72.      
  73.       # reorder the coordinates so that y1 is above y2
  74.       if y2 < y1
  75.         temp = x2
  76.         x2 = x1
  77.         x1 = temp
  78.         temp = y2
  79.         y2 = y1
  80.         y1 = temp
  81.       end
  82.      
  83.       # draw the line
  84.       for i in 0..cy.abs
  85.         # calculate the position horizontally
  86.         x = x1 + cx * i / cy
  87.        
  88.         # draw the pixel
  89.         set_pixel(x, y1 + i, color)
  90.        
  91.         # enlarge the line if the width is not 1
  92.         if line_width != 1
  93.           for j in 2..line_width
  94.             # on even counter, draw left; on odd draw right
  95.             if j & 1
  96.               set_pixel(x - j / 2, y1 + i, color)
  97.             else
  98.               set_pixel(x + j / 2, y1 + i, color)
  99.             end
  100.           end
  101.         end
  102.       end
  103.     end
  104.   end
  105.  
  106.   #----------------------------------------------------------------------------
  107.   # draw_square: Draw an unfilled square.
  108.   #   rect: Rectangle corresponding to the square to draw.
  109.   #   color: Color of the border.
  110.   #   line_width: Width of the border. Set to 1 by default.
  111.   #----------------------------------------------------------------------------
  112.   def draw_square(rect, color, line_width = 1)
  113.     draw_square(rect.x, rect.y, rect.cx, rect.cy, color, line_width)
  114.   end
  115.  
  116.   #----------------------------------------------------------------------------
  117.   # draw_square: Draw an unfilled square.
  118.   #   x: X-coordinate of the top-left corner of the square.
  119.   #   y: Y-coordinate of the top-left corner of the square.
  120.   #   width: Width of the square.
  121.   #   height: Height of the square.
  122.   #   color: Color of the border.
  123.   #   line_width: Width of the border. Set to 1 by default.
  124.   #----------------------------------------------------------------------------
  125.   def draw_square(x, y, width, height, color, line_width = 1)
  126.     # draw the left side
  127.     fill_rect(x, y, line_width, height, color)
  128.    
  129.     # draw the top side
  130.     fill_rect(x, y, width, line_width, color)
  131.    
  132.     # draw the right side
  133.     fill_rect(x + width - line_width + 1, y, line_width, height, color)
  134.    
  135.     # draw the bottom side
  136.     fill_rect(x, y + height - line_width + 1, width, line_width, color)
  137.   end
  138.  
  139.   #----------------------------------------------------------------------------
  140.   # draw_ellipse: Draw an unfilled ellipse. (oval)
  141.   #   ox: X-coordinate of the center of the ellipse.
  142.   #   oy: Y-coordinate of the center of the ellipse.
  143.   #   vradius: The vertical radius.
  144.   #   ratio: Ratio between the vertical radius and the horizontal radius.
  145.   #            (horizontal / vertical) Set it to 1.0 to draw a circle.
  146.   #   color: Color of the border.
  147.   #   line_width: Width of the border. Set to 1 by default.
  148.   #   sides: The ellipse is in fact an elliptic polygon with a given amount of
  149.   #            faces. For example, set it to 6 to have an hexagon. This is set
  150.   #            to 32 by default, which is plenty to make it look like a curved
  151.   #            form.
  152.   #----------------------------------------------------------------------------
  153.   def draw_ellipse(ox, oy, vradius, ratio, color, line_width = 1, sides = 32)
  154.     # calculate the horizontal radius
  155.     hradius = (vradius * ratio).to_i
  156.    
  157.     # set the initial coordinate
  158.     x1 = ox
  159.     y1 = oy - vradius
  160.    
  161.     # draw each side of the polygon except the last
  162.     for i in 1...sides
  163.       # calculate the position of the new point
  164.       x2 = ox - (hradius * Math.sin(i * Math::PI * 2 / sides)).round
  165.       y2 = oy - (vradius * Math.cos(i * Math::PI * 2 / sides)).round
  166.      
  167.       # draw a the line
  168.       draw_line(x1, y1, x2, y2, color, line_width)
  169.      
  170.       # store the old position
  171.       x1 = x2
  172.       y1 = y2
  173.     end
  174.    
  175.     # draw the last side
  176.     draw_line(x1, y1, ox, oy - vradius, color, line_width)
  177.   end
  178. end
  179.  
Expand to see the code.


PS: I wrote this long before the legal English version was released, so I apologize if the comments are non-standard.
I haven't had much time to go and search for everything I made but I can already post one bitmap method :

#==============================================================================
# ** RGSS Extensions: Bitmap
#-----------------------------------------------------------------------------
#    The Bitmap Class
#==============================================================================
class Bitmap
  #-------------------------------------------------------------------------
  # * Name:      Erase
  #   Info:      This method clears a part of the bitmap
  #   Author:    Selwyn
  #   Call Info: One or Four arguments, One Argument : Rect ; Four arguments : Integers
  #     One Arg  : Rect.new(x, y, width, height)
  #     Four Args : x, y, width, height
  #   Returns : nil
  #   Comments:  works the same as the build-in method 'clear' but only for a portion of the bitmap
  #-------------------------------------------------------------------------
  def erase(*args)
    if args.size == 1
      rect = args
    elsif args.size == 4
      rect = Rect.new(*args)
    end
    fill_rect(rect, Color.new(0, 0, 0, 0))
  end
end
Expand to see the code.
Here are some methods I've been working on recently. I created an Math.root method based on the Nth Root Algorithm and a plus-minus function. Since both these method return arrays, I added arithmetic operators to the array class. In addition, I modified the Array class' [] and []= methods. If called with a range as the key, they will now read all values and write to all indexes inside the range.

Nth Root Show
#==============================================================================
# ** Math Module
#==============================================================================
module Math
  #-------------------------------------------------------------------------
  #   Name:      Nth Root
  #   Info:      Finds the nth root
  #   Author:    Icarus Featherfight
  #   Call Info: Numeric nth and other
  #   Returns:   An interger of the nth root rounded to the nearest whole number
  #   Example:   Math.√ 3, 729 => 9
  #-------------------------------------------------------------------------
  def Math.root(n, other, both = false)
    return nil if other < 0 and n % 2 == 0
    case n
    when 0
      raise ZeroDivisionError, "You cannot find the zeroith root of a number"
    when 1
      return other
    when 2
      return both ? [sqrt(other), -(sqrt(other))] : sqrt(other)
    else
      # Make an initial guess
      g = 15
      if other < g**n and (g**n - other).abs > ((g-5)**n - other).abs
        g -= 5
      elsif other > g**n and (g**n - other).abs > ((g+5)**n - other).abs
        g += 5
      end
      # Return if the guess is now correct
      return (n % 2 == 0 && both ? [g, -g] : g) if other == g**n
      # If not, refine the guess...
      if other < (g.√ 2)**n
        g = g.√ 2
      elsif other > g**2**n
        g **= 2
      end
      # and use nth root algorithm to iteratively find the nth root x
      x = [g.to_f]
      until x[-2] != nil and (x[-2]*100_000).round == (x[-1]*100_000).round
        x.push 1.to_f/n * ((n-1).to_f * x[-1] + other.to_f / x[-1]**(n-1))
      end
      x = x.pop.round
      return n % 2 == 0 && both ? [x, -x] : x
    end
  end
end
Expand to see the code.

Numeric Show
#==============================================================================
# ** Numeric
#==============================================================================
class Numeric
  #-------------------------------------------------------------------------
  #   Name:      ? (plus-minus)
  #   Info:      Both adds and subtacts
  #   Author:    Icarus Featherfight
  #   Call Info: One Argument: other
  #   Returns:   An array of both the addition and the subtraction values
  #   Example:   4.? 7 => [11, -3]
  #-------------------------------------------------------------------------
  def ?(other)
    return [self + other, self - other]
  end
  #-------------------------------------------------------------------------
  #   Name:      Nth Root
  #   Info:      Finds the nth root
  #   Author:    Icarus Featherfight
  #   Call Info: A Numeric other
  #   Returns:   An interger of the nth root rounded to the nearest whole number
  #   Example:   3.√ 729 => 9
  #              3.root 729 => 9
  #-------------------------------------------------------------------------
  def √(other)
    return Math.root(self, other)
  end
  alias_method :root, :√
end
Expand to see the code.

Array.math Show
=begin
==============================================================================
** Array.math
------------------------------------------------------------------------------
Description:
------------
  More Mathematical methods for the Array class. These methods however assume
  all objects in the array are of class Numeric.
 
Method List:
------------
  Arithmetic operators (+, -, ?, *, /, **, √)
==============================================================================
=end
class Array
  #-------------------------------------------------------------------------
  #   Names:     Arithmetic operators (+, -, ?, *, /, %, **, √)
  #   Info:      Preforms basic mathamatical operations on the array
  #   Author:    Icarus Featherfight
  #   Call Info: A Numeric other
  #   Returns:   The Array self with each element modified
  #   Examples:  [6, 2, 4] + 1      =>  [7, 3, 5]
  #              [0, 3, 2] - 1      =>  [-1, 2, 1]
  #              [5, 6, 3].? 2      =>  [[7, 3], [8, 4], [5, 1]]
  #              [9, 1, 7] * 3      =>  [27, 3, 21]
  #              [6, 12, 9] / 3     =>  [2, 4, 3]
  #              [3, 5, 10] ** 3    =>  [27, 125, 1000)
  #              [25, 4, 9].√ 2     =>  [5, 2, 3]
  #              [25, 4, 9].root 2  =>  [5, 2, 3]
  #-------------------------------------------------------------------------
  alias_method :icarus_macl_add, :+
  def +(other)
    if other.is_a? Numeric
      result = []
      self.each_index {|index| result[index] = self[index] + other}
      return result
    else
      icarus_macl_add(other)
    end
  end
  #-------------------------------------------------------------------------
  alias_method :icarus_macl_subtract, :-
  def -(other)
    if other.is_a? Numeric
      result = []
      self.each_index {|index| result[index] = self[index] - other}
      return result
    else
      icarus_macl_subtract(other)
    end
  end
  #-------------------------------------------------------------------------
  def ?(other)
    result = []
    self.each_index {|index| result[index] = self[index].? other}
    return result
  end
  #-------------------------------------------------------------------------
  def *(other)
    result = []
    self.each_index {|index| result[index] = self[index] * other}
    return result
  end
  #-------------------------------------------------------------------------
  def /(other)
    result = []
    self.each_index {|index| result[index] = self[index] / other}
    return result
  end
  #-------------------------------------------------------------------------
  def %(other)
    result = []
    self.each_index {|index| result[index] = self[index] % other}
    return result
  end
  #-------------------------------------------------------------------------
  def **(other)
    result = []
    self.each_index {|index| result[index] = self[index] ** other}
    return result
  end
  #-------------------------------------------------------------------------
  def √(nth)
    result = []
    self.each_index {|index| result[index] = other.√ self[index]}
    return result
  end
  alias_method :root, :√
end
Expand to see the code.

Array Index Range Show
#==============================================================================
# ** Array
#==============================================================================
class Array
  #-------------------------------------------------------------------------
  #   Name:      []
  #   Info:      Modifies [key] when key is a range expression
  #              Return an array of indexed values within the range
  #   Author:    Icarus Featherfight
  #   Example:   @data = [6, nil, true, 'max', 4]
  #              p @data[-1..2] => [4, 6, true]
  #-------------------------------------------------------------------------
  alias_method :icarus_macl_index, :[]
  def [](key)
    if key.is_a? Range
      array = []
      for index in key do array << self[index] end
      return array
    else
      icarus_macl_index(key)
    end
  end
  #-------------------------------------------------------------------------
  #   Name:      []=
  #   Info:      Modifies [key]=(value) when key is a range expression
  #              Sets each index within the key (range) to value
  #   Author:    Icarus Featherfight
  #   Example:   @data = []
  #              @data[1..5] = 2
  #              p @data => [nil, 2, 2, 2, 2, 2]
  #-------------------------------------------------------------------------
  alias_method :icarus_macl_indexequals, :[]=
  def []=(key, value)
    if key.is_a? Range
      for index in key do self[index] = value end
    else
      icarus_macl_indexequals(key, value)
    end
  end
end
Expand to see the code.

Hopefully, they will make a valuable addition to the MaCL. :)
unsort Show
=begin
==============================================================================
** unsort
------------------------------------------------------------------------------
Description:
------------
  this method can unsort all types of Enumerable

Class List:
-----------
  Enumerable
  Array

Method List: (avaiable for all classes)
------------
  unsort

==============================================================================
=end

module Enumerable
  #-------------------------------------------------------------------------
  #   Name      : unsort
  #   Info      : return a array of mixed elements
  #   Author    : Hanmac
  #   Call Info : with no Arguments
  #   Comments  : can make nosense with strings
  #-------------------------------------------------------------------------
  def unsort
    Array.unsort(self.entries)
  end
end

class Array
  #-------------------------------------------------------------------------
  #   Name      : self.unsort
  #   Info      : return a array of mixed elements
  #   Author    : Hanmac
  #   Call Info :  with min one Argument from type can this be everything
  #-------------------------------------------------------------------------
   def self.unsort(*arrays)
      array = arrays.flatten
      Array.new(array.size) {
         zufall = rand(array.size)
         array.delete_at(zufall)
      }
   end
  #-------------------------------------------------------------------------
  #   Name      : unsort
  #   Info      : return a array of mixed elements
  #   Author    : Hanmac
  #   Call Info : with no Arguments
  #-------------------------------------------------------------------------
   def unsort
      self.class.unsort(self)
   end
end
Expand to see the code.
Range.sort Show
=begin
==============================================================================
** Range.sort
------------------------------------------------------------------------------
Description:
------------
  with this you can sort Ranges

Class List:
-----------
  Range

Method List:
------------
  <=>

==============================================================================
=end

class Range
  include(Comparable)
  def <=>(other)
    temp = first <=> other.first
    temp = last <=> other.last if temp = 0
    return temp
  end
end
Expand to see the code.

i hope this are in the right form


EDIT:
To HSB Show
  #-------------------------------------------------------------------------
  # * Name      : To HSB
  #   Info      : Converts to Hue, Saturation, and Brightness
  #               returns an array setup like so: [hue, sat, bright]
  #   Author    : Trickster
  #   Call Info : No Arguments
  #-------------------------------------------------------------------------
  def to_hsb
    return self.class.to_hsb(red, green, blue)
  end
Expand to see the code.

this is shorter then yours (why write the code double)
Calibre;255946 wrote:
In my demo, I have just had an error reported that won't allow the game to load. So many other people have loaded it fine though, can you spot the reason?

"Script 'Method & Class Library' line 47: LoadError occured.
No such file to load--Array_2D.rb"


uhh it seems to me that you are using an older version please update to version 2.1

Korin;256507 wrote:
I get an error at 4261 - Stack Level too deep.


It doesn't help anyone if you don't post the line that causes the error
Original Post Show
Ok Trickster, I see now that my original submissions are redundant. This time however I added to the Table class and scripted a descendant Object_Table class. It stores the objects numerical id then retrieves the original object using the included module ObjectSpace's _id2ref method. However, since object ids are often greater than 32,767 I had to create a secondary Table to properly store the values. So, what's the verdict on this one?

[spoiler=RGSS.Table]
#==============================================================================
# ** RGSS.Table
#------------------------------------------------------------------------------
# Description:
# ------------
# Adds new features to the Table class. [] and []= methods now accept
# coordinate key arrays and negative coordinate indexes. It also adds
# iteration methods, the Enumerable module and several miscellaneous methods
# all objects in the array are of class Numeric.
#
# Modified Methods:
# -----------------
# initialize
# []
# []=
# _dump
# self._load
#
# Methods Added:
# ------------
# Enumerable (see below)
# each
# each_coordinates
# each_with_coordinates
# coordinates
# each_index
# index
# clear
# nitems
# compact
# compact!
# plane
# column
# row
#==============================================================================
#==============================================================================
# ** Table
#==============================================================================
class Table
  #-------------------------------------------------------------------------
  # Include
  # * Names     : all?, any?, collect, map, each_with_index,  find, detect,
  #               find_all, select, grep, inject, member?, include?, max,
  #               min, partition, reject, sort, sort_by, to_a, entries, zip
  #------------------------------------------------------------------------- 
  include Enumerable
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :negitive_read            # allow negitive index reading?
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias_method :icarus_table_initialize, :initialize
  def initialize(*args)
    icarus_table_initialize(*args)
    # Default value for negitive index reading
    @negitive_read = true
    # Store number of axis for each coordinate method
    @axis = args.size
  end
  #-------------------------------------------------------------------------
  # * []
  #-------------------------------------------------------------------------
  alias_method :icarus_table_nth, :[]
  def [](*args)
    # Remove nil arguments from the end of the array
    args.delete_at(-1) while args[-1].nil?
    # If negitive reading is enabled
    if @negitive_read
      # Modify arguments if they are negative indexes
      args[0] += self.xsize unless                 args[0] >= 0
      args[1] += self.ysize unless args[1].nil? or args[1] >= 0
      args[2] += self.zsize unless args[2].nil? or args[2] >= 0
    end
    # Call original method with modified arguments
    return icarus_table_nth(*args)
  end
  #-------------------------------------------------------------------------
  # * []=
  #-------------------------------------------------------------------------
  alias_method :icarus_table_nthequals, :[]=
  def []=(*args)
    # Modify arguments if they are negative indexes
    args[0] += self.xsize unless                 args[0] >= 0
    args[1] += self.ysize unless args[2].nil? or args[1] >= 0
    args[2] += self.zsize unless args[3].nil? or args[2] >= 0
    # Call original method with modified arguments
    icarus_table_nthequals(*args)
  end
  #-------------------------------------------------------------------------
  # * _dump
  #-------------------------------------------------------------------------
  alias_method :icarus_table_dump, :_dump
  def _dump(i)
    return icarus_table_dump(i) + '~~' +
           Marshal.dump(@negitive_read) + '~~' + Marshal.dump(@axis)
  end
  #-------------------------------------------------------------------------
  # * self._load
  #-------------------------------------------------------------------------
  class << self
    alias_method :icarus_table_load, :_load
  end
  def self._load(string)
    array = string.split('~~')
    table = self.icarus_table_load(array[0])
    unless array[1].nil?
      table.instance_variable_set(:@negitive_read, Marshal.load(array[1]))
      table.instance_variable_set(:@axis, Marshal.load(array[2]))
    end
    return table
  end
  #-------------------------------------------------------------------------
  # * Name      : Each
  #   Info      : Iterates through all coordinates, yielding each value
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #   Comments  : Provides the basis for included Enumerable methods
  #-------------------------------------------------------------------------
  def each
    each_coordinates{|key| yield self[*key]}
  end
  #-------------------------------------------------------------------------
  # * Name      : Each Coordinates
  #   Info      : Iterates through all coordinates in the table
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #   Comments  : See Each or Coordinates methods for proper block setup
  #-------------------------------------------------------------------------
  def each_coordinates
    for x in 0...self.xsize
      if @axis == 1
        yield [x]
      else
        for y in 0...self.ysize
          if @axis == 2
            yield [x, y]
          else
            for z in 0...self.zsize
              yield [x, y, z]
            end
          end
        end
      end
    end
    return nil
  end
  #-------------------------------------------------------------------------
  # * Name      : Each With Coordinates
  #   Info      : Iterates through table, yielding each value and key
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def each_with_coordinates
    each_coordinates{|key| yield (self[*key], key)}
  end
  #-------------------------------------------------------------------------
  # * Name      : Coordinates
  #   Info      : Finds the first coordinates to contain a value
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def coordinates(value)
    each_coordinates{|key| return key if self[*key] == value}
  end
  #-------------------------------------------------------------------------
  # * Name      : Each Index
  #   Info      : Iterates through all indexes in a table array
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #-------------------------------------------------------------------------
  def each_index
    self.to_a.each_index{|index| yield(index)}
  end
  #-------------------------------------------------------------------------
  # * Name      : Index
  #   Info      : Finds the first index to contain a value
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def index(value)
    each_with_index{|val, index| return index if val == value}
  end
  #-------------------------------------------------------------------------
  # * Name      : Clear
  #   Info      : Reinitializes table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #   Comments  : See Array.clear
  #-------------------------------------------------------------------------
  def clear
    # Reset table
    if self.ysize == 1    then initialize(self.xsize)
    elsif self.zsize == 1 then initialize(self.xsize, self.ysize)
    else                       initialize(self.xsize, self.ysize, self.zsize)
    end
    return self
  end
  #-------------------------------------------------------------------------
  # * Name      : NItems
  #   Info      : Iterates through index, counting all non-zero elements
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def nitems
    n = 0
    each{|value| n += 1 unless value == false}
    return n
  end
  #-------------------------------------------------------------------------
  # * Name      : Compact
  #   Info      : Returns a new table with nil elements removed from positive
  #               extremities of table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def compact
    return self.dup.compact!
  end
  #-------------------------------------------------------------------------
  # * Name      : Compact!
  #   Info      : Removes nil elements from positive extremities of table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def compact!
    if self.zsize == 1
      x = self.xsize
      y = self.ysize
      x -= 1 while row(x - 1).all?{|item| item.nil?} && x > 1
      y -= 1 while column(y - 1).all?{|item| item.nil?} && y > 1
      resize(x, y)
    else
      planes = []
      for z in 0...self.zsize
        planes[z] = plane(z).compact!
      end
      planes.delete_at(-1) while planes[-1].all?{|item| item.nil?}
      xmax, ymax = 1, 1
      planes.each{|table|
                  xmax = table.xsize if xmax < table.xsize
                  ymax = table.ysize if ymax < table.ysize
                  }
      resize(xmax, ymax, planes.size)
    end
    return self
  end
  #-------------------------------------------------------------------------
  # * Name      : Plane
  #   Info      : On a 3D table returns the 2D plane at z value
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical z
  #-------------------------------------------------------------------------
  def plane(z)
    return if self.ysize == 1 || self.zsize == 1 || z.nil? || z >= self.zsize
    if self.class == Object_Table
      plane = Object_Table.new(self.xsize, self.ysize)
    else
      plane = Table.new(self.xsize, self.ysize)
    end
    for x in 0...self.xsize
      for y in 0...self.ysize
        plane[x, y] = self[x, y, z]
      end
    end
    return plane
  end
  #-------------------------------------------------------------------------
  # * Name      : Column
  #   Info      : On a 3D or 2D table returns the array at y and z values.
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical y and an optional z for 3D tables
  #-------------------------------------------------------------------------
  def column(x, z = nil)
    column = []
    for y in 0...self.ysize
      column[y] = self[x, y, z]
    end
  end
  #-------------------------------------------------------------------------
  # * Name      : Row
  #   Info      : On a 3D or 2D table returns the array at x and z values.
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical x and an optional z for 3D tables
  #-------------------------------------------------------------------------
  def row(y, z = nil)
    row = []
    for x in 0...self.xsize
      row[x] = self[x, y, z]
    end
  end
end
Expand to see the code.

Object_Table Show
#==============================================================================
# ** Object Table                                        By Icarus Featherfight
#------------------------------------------------------------------------------
#  The multidimensional array class; extended to hold objects.
#   - when resizing table, all data from before the size change is retained
#==============================================================================
class Object_Table < Table
  #-------------------------------------------------------------------------
  # Include ObjectSpace
  # * Names     : _id2ref, define_finalizer, each_object, garbage_collect,
  #               undefine_finalizer
  #------------------------------------------------------------------------- 
  include ObjectSpace
  #-------------------------------------------------------------------------
  # * Name      : Initialize
  #   Info      : Creates main table and additional depth table
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate maximums (xsize[, ysize[, zsize]])
  #-------------------------------------------------------------------------
  def initialize(*args)
    super
    # Creates depth table
    @depth = Table.new(*args)
    # Initialize table with nil values
    self.each_coordinates{|key| self[*key] = nil}
  end
  #-------------------------------------------------------------------------
  # * Name      : Element Reference
  #   Info      : Extends method to return objects; stored as ids
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate arguments or one coordinate key array
  #   Comments  : Prevents ArgumentErrors when using a coordinate key array
  #-------------------------------------------------------------------------
  def [](*args)
    # Abort if coordinates are outside of table
    return nil if super.nil?
    # Returns original object after recalculating its id
    return _id2ref(super + (32_768 * @depth[*args]))
  end
  #-------------------------------------------------------------------------
  # * Name      : Element Assignment
  #   Info      : Extends method to store an objects id
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate arguments or array and value
  #   Comments  : Prevents ArgumentErrors when using a coordinate key array
  #-------------------------------------------------------------------------
  def []=(*args)
    # Free current contents for GC
    a = args.dup
    a.pop
    undefine_finalizer(self[*a]) unless self[*a] == false
    # Define finalizer to prevent GC
    define_finalizer(args[-1], proc {|id| p "Object Table Entry: #{id}" })
    # Replace object with its id
    args[-1] = args[-1].id
    # Create key for secondary depth table
    key = args.dup
    key.pop
    # Store depth and reduce id integer to effective range of table
    @depth[*key] = args[-1] / 32_768
    args[-1] %= 32_768
    # Store modified object id value
    return super(*args)
  end
  #-------------------------------------------------------------------------
  # * Name      : _dump
  #   Info      : Marshals Object_Table data
  #   Author    : Icarus Featherfight
  #   Call Info : An Interger i
  #   Comments  : Adds @depth Table to dump
  #-------------------------------------------------------------------------
  def _dump(i)
    return super(i) + '~|~' + Marshal.dump(@depth)
  end
  #-------------------------------------------------------------------------
  # * Name      : self._load
  #   Info      : Retores Object_Table from a marshaled string
  #   Author    : Icarus Featherfight
  #   Call Info : A String string
  #   Comments  : Restores @depth Table
  #-------------------------------------------------------------------------
  def self._load(string)
    array = string.split('~|~')
    table = super(array[0])
    table.instance_variable_set(:@depth, Marshal.load(array[1]))
    return table
  end
  #-------------------------------------------------------------------------
  # * Name      : Resize
  #   Info      : Resizes main table and additional depth table
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate maximums (xsize[, ysize[, zsize]])
  #   Comments  : All data from before the size change is retained
  #-------------------------------------------------------------------------
  def resize(*args)
    # Resize main table
    super
    # Resize depth table
    @depth.resize(*args)
  end
  #-------------------------------------------------------------------------
  # * Name      : Clear
  #   Info      : Reinitializes table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #   Comments  : See Array.clear
  #-------------------------------------------------------------------------
  def clear
    self.each{|obj| undefine_finalizer(obj)}
    super
  end
  #-------------------------------------------------------------------------
  # * Name      : Expand
  #   Info      : Returns the tables array with nested arrays expanded
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def expand
    array = self.to_a
    array.each_index{|i| array[i, 1] = array[i] if array[i].class == Array}
    return array
  end
end
Expand to see the code.

P.S. I know Selwyn already created Array_2D and Table_Object classes for the MaCL but his were based on the Array class.
[/spoiler]
As it turns out, the above code suffers from a critical oversight. Since all objects are disposed on exit, saving only their ids is not enough. The version below fixes this and is based on the array class.

New Object_Table Show
#==============================================================================
# ** Object Table By Icarus Featherfight
#------------------------------------------------------------------------------
# The multidimensional array class; can hold all objects.
# - when resizing table, all data from before the size change is retained
# - negative coordinate indexes can be used
# - includes the Enumerable module
#==============================================================================
class Object_Table
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :negative_read # allow negative index reading?
attr_reader :data # data array
attr_reader :xsize, :ysize, :zsize # numerical coordinate maximums
#-------------------------------------------------------------------------
# * Name : Initialize
# Info : Initializes Object_Table
# Author : Icarus Featherfight
# Call Info : 1..3 Numeric coordinate maximums (xsize[, ysize[, zsize]])
#-------------------------------------------------------------------------
def initialize(*args)
# Store number of axis and axial maximums
@axis = args.size
@xsize, @ysize, @zsize = args[0], args[1], args[2]
# Create data table array
@data = []
if @axis >= 2
for x in 0...@xsize
@data[x] = []
end
if @axis == 3
for x in 0...@xsize
for y in 0...@ysize
@data[x][y] = []
end
end
end
end
# Default value for negative index reading
@negitive_read = true
end
#-------------------------------------------------------------------------
# * Name : Element Reference
# Info : Returns Object stored at coordinates
# Author : Icarus Featherfight
# Call Info : 1..3 Numeric coordinate arguments
#-------------------------------------------------------------------------
def [](*args)
# Raise ArgumentError if there is the wrong number of arguments
raise ArgumentError if args.size != @axis
# Return if negative reading is disabled and a coordinate is negative
return nil if !@negitive_read and args.any?{|num| num < 0}
# Return Object stored at coordinates
case @axis
when 1
return @data[args[0]]
when 2
return @data[args[0]][args[1]]
when 3
return @data[args[0]][args[1]][args[2]]
end
end
#-------------------------------------------------------------------------
# * Name : Element Assignment
# Info : Stores Object at designated coordinates
# Author : Icarus Featherfight
# Call Info : 1..3 coordinate arguments and a Object value
#-------------------------------------------------------------------------
def []=(*args)
# Raise ArgumentError if there is the wrong number of arguments
raise ArgumentError if args.size - 1 != @axis
# Raise IndexError if coordinates are out of range
raise IndexError if args[0] >= @xsize or
args[1] != nil && args[1] >= @ysize or
args[2] != nil && args[2] >= @zsize
# Store Object at coordinates
case @axis
when 1
return @data[args[0]] = args[-1]
when 2
return @data[args[0]][args[1]] = args[-1]
when 3
return @data[args[0]][args[1]][args[2]] = args[-1]
end
end
#-------------------------------------------------------------------------
# Include
# * Names : all?, any?, collect, map, each_with_index, find, detect,
# find_all, select, grep, inject, member?, include?, max,
# min, partition, reject, sort, sort_by, to_a, entries, zip
#-------------------------------------------------------------------------
include Enumerable
#-------------------------------------------------------------------------
# * Name : Each
# Info : Iterates through all coordinates, yielding each value
# Author : Icarus Featherfight
# Call Info : A block
# Comments : Provides the basis for included Enumerable methods
#-------------------------------------------------------------------------
def each
each_coordinates{|key| yield self[*key]}
end
#-------------------------------------------------------------------------
# * Name : Each Coordinates
# Info : Iterates through all coordinates in the table
# Author : Icarus Featherfight
# Call Info : A block
# Comments : See Each or Coordinates methods for proper block setup
#-------------------------------------------------------------------------
def each_coordinates
for x in 0...@xsize
if @axis == 1
yield [x]
else
for y in 0...@ysize
if @axis == 2
yield [x, y]
else
for z in 0...@zsize
yield [x, y, z]
end
end
end
end
end
return nil
end
#-------------------------------------------------------------------------
# * Name : Each With Coordinates
# Info : Iterates through table, yielding each value and key
# Author : Icarus Featherfight
# Call Info : One numeric value to be found
#-------------------------------------------------------------------------
def each_with_coordinates
each_coordinates{|key| yield (self[*key], key)}
end
#-------------------------------------------------------------------------
# * Name : Coordinates
# Info : Finds the first coordinates to contain a value
# Author : Icarus Featherfight
# Call Info : One numeric value to be found
#-------------------------------------------------------------------------
def coordinates(value)
each_coordinates{|key| return key if self[*key] == value}
end
#-------------------------------------------------------------------------
# * Name : Each Index
# Info : Iterates through all indexes in a table array
# Author : Icarus Featherfight
# Call Info : A block
#-------------------------------------------------------------------------
def each_index
self.to_a.each_index{|index| yield(index)}
end
#-------------------------------------------------------------------------
# * Name : Index
# Info : Finds the first index to contain a value
# Author : Icarus Featherfight
# Call Info : One numeric value to be found
#-------------------------------------------------------------------------
def index(value)
each_with_index{|val, index| return index if val == value}
end
#-------------------------------------------------------------------------
# * Name : Clear
# Info : Reinitializes table
# Author : Icarus Featherfight
# Call Info : No arguments
# Comments : See Array.clear
#-------------------------------------------------------------------------
def clear
initialize(@xsize, @ysize, @zsize)
end
#-------------------------------------------------------------------------
# * Name : Resize
# Info : Resizes main table and additional depth table
# Author : Icarus Featherfight
# Call Info : 1..3 coordinate maximums (xsize[, ysize[, zsize]])
# Comments : All data from before the size change is retained
#-------------------------------------------------------------------------
def resize(*args)
# Abort if new dimentions equal the old
return if args[0], args[1], agrs[2] == @xsize, @ysize, @zsize
# Destroy axis
if args[1].nil?
case @axis
when 2
# Destroy y axis
for x in 0...@xsize
@data[x] = @data[x][0]
end
when 3
# Destroy y and z axis
for x in 0...@xsize
@data[x] = @data[x][0][0]
end
end
@axis = 1
@ysize, @zsize = nil, nil
elsif args[2].nil?
if @axis = 3
# Destroy z axis
for x in 0...@xsize
for y in 0...@ysize
@data[x][y] = @data[x][y][0]
end
end
end
@axis = 2
@zsize = nil
end
# Resize x axis
if args[0] < @xsize
# Crop table
for x in args[0]...@xsize
@data.delete_at(x)
end
elsif args[0] > @xsize and @axis >= 2
# Extend table
for x in @xsize...args[0]
@data[x] = []
end
if @axis == 3
for x in @xsize...args[0]
for y in @ysize...args[1]
@data[x][y] = []
end
end
end
end
return if @axis == 1
# Resize y axis
if args[1] < @ysize
# Crop table
for x in 0...args[0]
for y in args[1]...@ysize
@data[x].delete_at(y)
end
end
elsif args[1] > @ysize and @axis == 3
# Extend table
for x in @xsize...args[0]
for y in @ysize...args[1]
@data[x][y] = []
end
end
end
return if @axis != 3
# Resize z axis
if args[2] < @zsize
# Crop table
for x in 0...args[0]
for y in args[1]...@ysize
for z in args[2]...@zsize
@data[x][y].delete_at(z)
end
end
end
elsif args[2] > @zsize
# Extend table
for x in @xsize...args[0]
for y in @ysize...args[1]
@data[x][y] = []
end
end
end
end
#-------------------------------------------------------------------------
# * Name : NItems
# Info : Iterates through index, counting all non-zero elements
# Author : Icarus Featherfight
# Call Info : No arguments
#-------------------------------------------------------------------------
def nitems
n = 0
each{|value| n += 1 unless value == false}
return n
end
#-------------------------------------------------------------------------
# * Name : Compact
# Info : Returns a new table with nil elements removed from positive
# extremities of table
# Author : Icarus Featherfight
# Call Info : No arguments
#-------------------------------------------------------------------------
def compact
return self.dup.compact!
end
#-------------------------------------------------------------------------
# * Name : Compact!
# Info : Removes nil elements from positive extremities of table
# Author : Icarus Featherfight
# Call Info : No arguments
#-------------------------------------------------------------------------
def compact!
if @zsize == nil
x = @xsize
y = @ysize
x -= 1 while row(x - 1).all?{|item| item.nil?} && x > 1
y -= 1 while column(y - 1).all?{|item| item.nil?} && y > 1
resize(x, y)
else
planes = []
for z in 0...@zsize
planes[z] = plane(z).compact!
end
planes.delete_at(-1) while planes[-1].all?{|item| item.nil?}
xmax, ymax = 1, 1
planes.each{|table|
xmax = table.xsize if xmax < table.xsize
ymax = table.ysize if ymax < table.ysize
}
resize(xmax, ymax, planes.size)
end
return self
end
#-------------------------------------------------------------------------
# * Name : Plane
# Info : On a 3D table returns the 2D plane at z value
# Author : Icarus Featherfight
# Call Info : A numerical z
#-------------------------------------------------------------------------
def plane(z)
return if @ysize == 1 || @zsize == 1 || z.nil? || z >= @zsize
plane = Object_Table.new(@xsize, @ysize)
for x in 0...@xsize
for y in 0...@ysize
plane[x, y] = @data[x][y][z]
end
end
return plane
end
#-------------------------------------------------------------------------
# * Name : Column
# Info : On a 3D or 2D table returns the array at y and z values.
# Author : Icarus Featherfight
# Call Info : A numerical y and an optional z for 3D tables
#-------------------------------------------------------------------------
def column(x, z = nil)
column = []
if z.nil?
for y in 0...@ysize
column[y] = @data[x][y]
end
else
for y in 0...@ysize
column[y] = @data[x][y][z]
end
end
end
#-------------------------------------------------------------------------
# * Name : Row
# Info : On a 3D or 2D table returns the array at x and z values.
# Author : Icarus Featherfight
# Call Info : A numerical x and an optional z for 3D tables
#-------------------------------------------------------------------------
def row(y, z = nil)
row = []
if z.nil?
for x in 0...@xsize
row[x] = @data[x][y]
end
else
for x in 0...@xsize
row[x] = @data[x][y][z]
end
end
end
end
Question:
are you think that defs for even and odd can be useful?

EDIT:

there is that:

Class Numeric
  #-------------------------------------------------------------------------
  #   Name      : Even?
  #   Info      : Return true if number is even
  #   Author    : Hanmac
  #   Call Info : zero(optimal) (says if zero is even)
  #-------------------------------------------------------------------------
  def even?(zero=true)
   return false if self.is_a?(Float)
   return zero if zero?
   return self % 2 == 0
  end
  #-------------------------------------------------------------------------
  #   Name      : Odd?
  #   Info      : Return true if number is odd
  #   Author    : Hanmac
  #   Call Info : No Arguments
  #-------------------------------------------------------------------------
  def odd?
   return false if self.is_a?(Float)
   return self % 2 == 1
  end
Expand to see the code.
Seph, how about adding the CRC class I when searching for a checksum algorithm?
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/149918
As it turns out, my first Object_Table suffered from a critical oversight. Since all objects are disposed on exit, saving only their ids is not enough. The version below fixes this and is based on a nested @data array. What do you think?

Object_Table Show
#==============================================================================
# ** Object Table                                        By Icarus Featherfight
#------------------------------------------------------------------------------
#  The multidimensional array class; can hold all objects.
#   - when resizing table, all data from before the size change is retained
#   - negative coordinate indexes can be used
#   - includes the Enumerable module
#==============================================================================
class Object_Table
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :negative_read            # allow negative index reading?
  attr_reader   :data                     # data array
  attr_reader   :xsize, :ysize, :zsize    # numerical coordinate maximums
  #-------------------------------------------------------------------------
  # * Name      : Initialize
  #   Info      : Initializes Object_Table
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 Numeric coordinate maximums (xsize[, ysize[, zsize]])
  #-------------------------------------------------------------------------
  def initialize(*args)
    # Store number of axis and axial maximums
    @axis = args.size
    @xsize, @ysize, @zsize = args[0], args[1], args[2]
    # Create data table array
    @data = []
    if @axis >= 2
      for x in 0...@xsize
        @data[x] = []
      end
      if @axis == 3
        for x in 0...@xsize
          for y in 0...@ysize
            @data[x][y] = []
          end
        end
      end
    end
    # Default value for negative index reading
    @negative_read = true
  end
  #-------------------------------------------------------------------------
  # * Name      : Element Reference
  #   Info      : Returns Object stored at coordinates
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 Numeric coordinate arguments
  #-------------------------------------------------------------------------
  def [](*args)
    # Raise ArgumentError if there is the wrong number of arguments
    raise ArgumentError if args.size != @axis
    # Return nil if negative reading is disabled and a coordinate is negative
    return nil if @negative_read == false and args.any?{|num| num < 0}
    # Return Object stored at coordinates
    case @axis
    when 1
      return @data[args[0]]
    when 2
      return nil if @data[args[0]].nil?
      return @data[args[0]][args[1]]
    when 3
      return nil if @data[args[0]].nil? or @data[args[0]][args[1]].nil?
      return @data[args[0]][args[1]][args[2]]
    end
  end
  #-------------------------------------------------------------------------
  # * Name      : Element Assignment
  #   Info      : Stores Object at designated coordinates
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate arguments and a Object value
  #-------------------------------------------------------------------------
  def []=(*args)
    # Raise ArgumentError if there is the wrong number of arguments
    raise ArgumentError if args.size - 1 != @axis
    # Raise IndexError if coordinates are out of range
    raise IndexError    if                   args[0] >= @xsize or
                           args[1] != nil && args[1] >= @ysize or
                           args[2] != nil && args[2] >= @zsize
    # Store Object at coordinates
    case @axis
    when 1
      return @data[args[0]]                   = args[-1]
    when 2
      return @data[args[0]][args[1]]          = args[-1]
    when 3
      return @data[args[0]][args[1]][args[2]] = args[-1]
    end
  end
  #-------------------------------------------------------------------------
  # Include
  # * Names     : all?, any?, collect, map, each_with_index,  find, detect,
  #               find_all, select, grep, inject, member?, include?, max,
  #               min, partition, reject, sort, sort_by, to_a, entries, zip
  #------------------------------------------------------------------------- 
  include Enumerable
  #-------------------------------------------------------------------------
  # * Name      : Each
  #   Info      : Iterates through all coordinates, yielding each value
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #   Comments  : Provides the basis for included Enumerable methods
  #-------------------------------------------------------------------------
  def each
    each_coordinates{|key| yield self[*key]}
  end
  #-------------------------------------------------------------------------
  # * Name      : Each Coordinates
  #   Info      : Iterates through all coordinates in the table
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #   Comments  : See Each or Coordinates methods for proper block setup
  #-------------------------------------------------------------------------
  def each_coordinates
    for x in 0...@xsize
      if @axis == 1
        yield [x]
      else
        for y in 0...@ysize
          if @axis == 2
            yield [x, y]
          else
            for z in 0...@zsize
              yield [x, y, z]
            end
          end
        end
      end
    end
    return nil
  end
  #-------------------------------------------------------------------------
  # * Name      : Each With Coordinates
  #   Info      : Iterates through table, yielding each value and key
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def each_with_coordinates
    each_coordinates{|key| yield (self[*key], key)}
  end
  #-------------------------------------------------------------------------
  # * Name      : Coordinates
  #   Info      : Finds the first coordinates to contain a value
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def coordinates(value)
    each_coordinates{|key| return key if self[*key] == value}
  end
  #-------------------------------------------------------------------------
  # * Name      : Each Index
  #   Info      : Iterates through all indexes in a table array
  #   Author    : Icarus Featherfight
  #   Call Info : A block
  #-------------------------------------------------------------------------
  def each_index
    self.to_a.each_index{|index| yield(index)}
  end
  #-------------------------------------------------------------------------
  # * Name      : Index
  #   Info      : Finds the first index to contain a value
  #   Author    : Icarus Featherfight
  #   Call Info : One numeric value to be found
  #-------------------------------------------------------------------------
  def index(value)
    each_with_index{|val, index| return index if val == value}
  end
  #-------------------------------------------------------------------------
  # * Name      : Clear
  #   Info      : Reinitializes table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #   Comments  : See Array.clear
  #-------------------------------------------------------------------------
  def clear
    initialize(@xsize, @ysize, @zsize)
  end
  #-------------------------------------------------------------------------
  # * Name      : Resize
  #   Info      : Resizes main table and additional depth table
  #   Author    : Icarus Featherfight
  #   Call Info : 1..3 coordinate maximums (xsize[, ysize[, zsize]])
  #   Comments  : All data from before the size change is retained
  #-------------------------------------------------------------------------
  def resize(*args)
    # Abort if new dimentions equal the old
    return if args[0] == @xsize and args[1] == @ysize and args[2] == @zsize
    # Destroy axis
    if args[1].nil?
      case @axis
      when 2
        # Destroy y axis
        for x in 0...@xsize
          @data[x] = @data[x][0]
        end
      when 3
        # Destroy y and z axis
        for x in 0...@xsize
          @data[x] = @data[x][0][0]
        end
      end
      @axis = 1
      @ysize, @zsize = nil, nil
    elsif args[2].nil?
      if @axis = 3
        # Destroy z axis
        for x in 0...@xsize
          for y in 0...@ysize
            @data[x][y] = @data[x][y][0]
          end
        end
      end
      @axis = 2
      @zsize = nil
    end
    # Resize x axis
    if args[0] < @xsize
      # Crop table
      for x in args[0]...@xsize
        @data.delete_at(x)
      end
    elsif args[0] > @xsize and @axis >= 2
      # Extend table
      for x in @xsize...args[0]
        @data[x] = []
      end
      if @axis == 3
        for x in @xsize...args[0]
          for y in @ysize...args[1]
            @data[x][y] = []
          end
        end
      end
    end
    return if @axis == 1
    # Resize y axis
    if args[1] < @ysize
      # Crop table
      for x in 0...args[0]
        for y in args[1]...@ysize
          @data[x].delete_at(y)
        end
      end
    elsif args[1] > @ysize and @axis == 3
      # Extend table
      for x in @xsize...args[0]
        for y in @ysize...args[1]
          @data[x][y] = []
        end
      end
    end
    return if @axis != 3
    # Resize z axis
    if args[2] < @zsize
      # Crop table
      for x in 0...args[0]
        for y in args[1]...@ysize
          for z in args[2]...@zsize
            @data[x][y].delete_at(z)
          end
        end
      end
    elsif args[2] > @zsize
      # Extend table
      for x in @xsize...args[0]
        for y in @ysize...args[1]
          @data[x][y] = []
        end
      end
    end
  end
  #-------------------------------------------------------------------------
  # * Name      : NItems
  #   Info      : Iterates through index, counting all non-zero elements
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def nitems
    n = 0
    each{|value| n += 1 unless value == false}
    return n
  end
  #-------------------------------------------------------------------------
  # * Name      : Compact
  #   Info      : Returns a new table with nil elements removed from positive
  #               extremities of table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def compact
    return self.dup.compact!
  end
  #-------------------------------------------------------------------------
  # * Name      : Compact!
  #   Info      : Removes nil elements from positive extremities of table
  #   Author    : Icarus Featherfight
  #   Call Info : No arguments
  #-------------------------------------------------------------------------
  def compact!
    if @zsize == nil
      x = @xsize
      y = @ysize
      x -= 1 while row(x - 1).all?{|item| item.nil?} && x > 1
      y -= 1 while column(y - 1).all?{|item| item.nil?} && y > 1
      resize(x, y)
    else
      planes = []
      for z in 0...@zsize
        planes[z] = plane(z).compact!
      end
      planes.delete_at(-1) while planes[-1].all?{|item| item.nil?}
      xmax, ymax = 1, 1
      planes.each{|table|
                  xmax = table.xsize if xmax < table.xsize
                  ymax = table.ysize if ymax < table.ysize
                  }
      resize(xmax, ymax, planes.size)
    end
    return self
  end
  #-------------------------------------------------------------------------
  # * Name      : Plane
  #   Info      : On a 3D table returns the 2D plane at z value
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical z
  #-------------------------------------------------------------------------
  def plane(z)
    return if @ysize == 1 || @zsize == 1 || z.nil? || z >= @zsize
    plane = Object_Table.new(@xsize, @ysize)
    for x in 0...@xsize
      for y in 0...@ysize
        plane[x, y] = @data[x][y][z]
      end
    end
    return plane
  end
  #-------------------------------------------------------------------------
  # * Name      : Column
  #   Info      : On a 3D or 2D table returns the array at y and z values.
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical y and an optional z for 3D tables
  #-------------------------------------------------------------------------
  def column(x, z = nil)
    column = []
    if z.nil?
      for y in 0...@ysize
        column[y] = @data[x][y]
      end
    else
      for y in 0...@ysize
        column[y] = @data[x][y][z]
      end
    end
  end
  #-------------------------------------------------------------------------
  # * Name      : Row
  #   Info      : On a 3D or 2D table returns the array at x and z values.
  #   Author    : Icarus Featherfight
  #   Call Info : A numerical x and an optional z for 3D tables
  #-------------------------------------------------------------------------
  def row(y, z = nil)
    row = []
    if z.nil?
      for x in 0...@xsize
        row[x] = @data[x][y]
      end
    else
      for x in 0...@xsize
        row[x] = @data[x][y][z]
      end
    end
  end
end
Expand to see the code.
some usefull methods for arrays:
I've send them to trickster yesterday night...
So just in case
class Array
  # rotate  n item(s) to the left ( first becomes last) as a new array
  def rotate_l(n=1)
    a = self.clone
    n.times{a.push(a.shift)}
    return a
  end
  # rotate  n item(s) to the right ( last becomes first) as a new array
  def rotate_r(n=1)
    a = self.clone
    n.times{a.unshift(a.pop)}
    return a
  end
  # rotate n item(s) to the left
  def rotate_l!(n=1)
    n.times{self.push(self.shift)}
    return self
  end
  # rotate n item(s) to the right
  def rotate_r!(n=1)
    n.times{self.unshift(self.pop)}
    return self
  end
end
Expand to see the code.
        Here is my first contribution to the Rmxp community, hopefully this gets added to the MCL!
(As if you couldn't tell this goes in the class String section)

  #-------------------------------------------------------------------------
  # * Name       : Check Prefix
  #   Info       : Checks a String for specified Prefix
  #   Author     : Malucifer
  #   Call Info  : String
  #-------------------------------------------------------------------------
  def starts_with?(string)
     self.index( string ) == 0
  end

  #-------------------------------------------------------------------------
  # * Name       : Check Suffix
  #   Info       : Checks a String for specified Suffix
  #   Author     : Malucifer
  #   Call Info  : String
  #-------------------------------------------------------------------------
  def ends_with?(string)
     self.rindex( string ) == self.length - str.length
  end
Expand to see the code.


I hope this helps somebody....
I don't know if work on this is discontinued or no longer supported but while helping someone out I discovered two tiny bugs that deal with variable misnaming.

*Original* module Point_Slope Show
  module Point_Slope
    #------------------------------------------------------------------------
    # * Generate Curve
    #
    #   Args : min_level, max_level, start value, inflation
    #------------------------------------------------------------------------
    def self.generate_curve(min_l, max_level, start_value, inflation)
      # Creates Table
      table = {}
      # Fills Table
      for level in min_l..max_l
        table[level] = start_value + inflation * level
      end
      # Return Table
      return table
    end
  end
Expand to see the code.


*Fixed* module Point_Slope Show
  module Point_Slope
    #------------------------------------------------------------------------
    # * Generate Curve
    #
    #   Args : min_l, max_l, start value, inflation
    #------------------------------------------------------------------------
    def self.generate_curve(min_l, max_l, start_value, inflation)
      # Creates Table
      table = {}
      # Fills Table
      for level in min_l..max_l
        table[level] = start_value + inflation * level
      end
      # Return Table
      return table
    end
  end
Expand to see the code.


*Original* module Curve_Generator Show
module Curve_Generator
  #-------------------------------------------------------------------------
  # * Save Table
  #-------------------------------------------------------------------------
  def self.save_table(type, args, table)
    # Collects Saved Tables
    tables = self.load_tables
    # Creates Hash of Type (If non present)
    tables[type] = {} unless tables.has_key?(type)
    # Saves Table Data
    tables[type][args] = curve
    # Resaves Tables to File
    save_data(tables, 'Data/Curve Generator.rxdata')   
  end
end
Expand to see the code.


*Fixed* module Curve_Generator Show
module Curve_Generator
  #-------------------------------------------------------------------------
  # * Save Table
  #-------------------------------------------------------------------------
  def self.save_table(type, args, table)
    # Collects Saved Tables
    tables = self.load_tables
    # Creates Hash of Type (If non present)
    tables[type] = {} unless tables.has_key?(type)
    # Saves Table Data
    tables[type][args] = table
    # Resaves Tables to File
    save_data(tables, 'Data/Curve Generator.rxdata')   
  end
end
Expand to see the code.
The MACL has been updated to version 2.3!


Some of you may be asking, what happened to 2.2? Well many parts of the 2.2 version have been leeked around and about. To avoid any confusion, this is version 2.3. Any old versions of the MACL may be removed completely. We will probably be not using the RSC require method, simply because its a headache for people to get to use. So from here on out, you get one big script (over 16000 lines, go us!).


Let me know if I made any mistakes, as I haven't had a lot of time to review this yet.
That's a nice update. I'm massively using the MACL in my FF6 SDK.
I have a suggestion, why don't you add your Bitmap sqr_rotate_90 method to it? It would be a nice addition along with the Bitmap flipping methods.

Also, I found a class_defined? method not long ago if you are interested.
Kernel.class_defined? by David Garamond Show
#==============================================================================
# ** Kernel    
#==============================================================================

module Kernel
  #-------------------------------------------------------------------------
  # * Name      : Class Defined?
  #   Info      : Check if a specific class has been defined
  #   Author    : David Garamond <[email hidden]>
  #   Call Info : One Argument
  #               Class name : String representing the class name
  #-------------------------------------------------------------------------
  def class_defined?(classname)
    m = Class
    classname.split("::").each { |c|
      m.constants.include?(c) or return false
      m = m.const_get c
    }
    return true
  end
end
Expand to see the code.
Thanks. From here on out it will be month updates. I left the post in this thread with anything I am unsure if its already in there. I am going to try to include everything in this thread in the next update, or any other useful methods that pop up.

#==============================================================================
# ** Object
#==============================================================================

class Object
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  @@subclasses = {}
  #-------------------------------------------------------------------------
  # * Name      : Subclasses
  #   Info      : Gets array of subclasses for class
  #   Author    : SephirothSpawn
  #   Call Info : NA
  #-------------------------------------------------------------------------
  def self.subclasses
    return @@subclasses.has_key?(self) ? @@subclasses[self] : []
  end
  #-------------------------------------------------------------------------
  # * Name      : Add Subclass
  #   Info      : Adds subclass to parent class list
  #   Author    : SephirothSpawn
  #   Call Info : Superclass name & Subclass name
  #-------------------------------------------------------------------------
  def self.add_subclass(superclass, subclass)
    @@subclasses[superclass] = []  unless @@subclasses.has_key?(superclass)
    @@subclasses[superclass] << subclass unless @@subclasses[self].include?(subclass)
  end
  #-------------------------------------------------------------------------
  # * Object.inherited
  #-------------------------------------------------------------------------
  def self.inherited(subclass)
    self.add_subclass(subclass.superclass, subclass)
  end
end


class Game_Character
  for turn in ['turn_down', 'turn_left', 'turn_right', 'turn_up']
    s  = "alias_method :seph_macl_turnbase_#{turn}, :#{turn};"
    s += "def #{turn};"
    s += "  turn_base;"
    s += "  seph_macl_turnbase_#{turn};"
    s += "end;"
    eval s
  end
  def turn_base
  end
end
Expand to see the code.
I have a little problem with the pathfinding sintax:

I use this: $game_map.events[1].run_path(10, 10)

and I get this:

Wrong number of arguments(2 for 0).
That was a mistake in the Script Heading. It should be:

find_path(x,y)
But i have a question, this Pathfinding is used to move the player or the event to a Position?, because I cant do that.

Can you explain a little better this pathfinding?
Yes, it works for any Game_Character object. It moves them to the dest x, y position or should...

*runs off*

(I am actually going to do some research and possibly improve this for the next update. I was working with pathfinding nodes, but that was before xmas break.)
Here I am and I went to all the trouble to update from 2.1 to 2.3 and I find that it's not working entirely.  Don't think about it too much if it doesn't seem simple (because I've made a lot of modifications to the project that you can't predict).  With fotz!'s pixel movement script, the front player in the party does not display properly and the pathfinding is not initializing properly.  And for some reason it made all text in the game shadowed.
The Pathfinding probably needs a little tweeking. With fotz!'s system, there might be a method name mixup. If you can make a demo, I can take a look. And the font is shadowed because of the settings right below the heading. All those constants are settings you can adjust. Just look for Default_Font_Shadow or something and set it to false. I merely turned it on because I think it looks a little better. lol
Wow, I'm really surprised to find very little for the < Window_Base classes, especially these methods... feel free to add them, I use them in all of my window scene scripts, it makes even the most boring Window scene 100x better.

...At least I didn't see these in the MACL, so many lines I could've easily scrolled past it @_@

Window_Base+ Show
#===============================================================================
# ** Window_Base
#-------------------------------------------------------------------------------
# * Additional Methods
#   o move_to()
#   o x_move_to()
#   o y_move_to()
#   o fade_opacity()
#   o upgrade_color
#   o downgrade_color
#===============================================================================
class Window_Base < Window
  #-----------------------------------------------------------------------------
  # * Move To (X, Y, Speed, Opacity)
  #-----------------------------------------------------------------------------
  # o Written by  : Kain Nobel
  # o Description : Moves this window to designated X and Y Coordinates.
  # o Call Info   : x coordinate, y coordinate
  # o Optional    : speed (1..100), opacity (0...255)
  #-----------------------------------------------------------------------------
  def move_to(new_x, new_y, speed = 10, opacity = nil)
    unless self.x == new_x
      self.x -= ((self.x - new_x + 9) / speed).abs if self.x > new_x
      self.x += ((self.x - new_x + 0) / speed).abs if self.x < new_x
    end
    unless self.y == new_y
      self.y -= ((self.y - new_y + 9) / speed).abs if self.y > new_y
      self.y += ((self.y - new_y + 0) / speed).abs if self.y < new_y
    end
    fade_opacity(opacity, speed) unless opacity.nil?
  end
  #-----------------------------------------------------------------------------
  # * X Move To (Destination, Speed, Opacity)
  #-----------------------------------------------------------------------------
  # o Written by  : Kain Nobel
  # o Description : Moves this window to designated X Coordinate.
  # o Call Info   : x coordinate
  # o Optional    : speed (1..100), opacity (0...255)
  #-----------------------------------------------------------------------------
  def x_move_to(n = 0, speed = 10, opacity = nil)
    unless self.x == n
      self.x -= ((self.x - n + 9) / speed).abs if self.x > n
      self.x += ((self.x - n + 0) / speed).abs if self.x < n
    end
    fade_opacity(opacity, speed) unless opacity.nil?
  end
  #-----------------------------------------------------------------------------
  # * Y Move To (Destination, Speed, Opacity)
  #-----------------------------------------------------------------------------
  # o Written by  : Kain Nobel
  # o Description : Moves this window to designated X Coordinate.
  # o Call Info   : x coordinate
  # o Optional    : speed (1..100), opacity (0...255)
  #-----------------------------------------------------------------------------
  def y_move_to(n = 0, speed = 10, opacity = nil)
    unless self.y == n
      self.y -= ((self.y - n + 9) / speed).abs if self.y > n
      self.y += ((self.y - n + 0) / speed).abs if self.y < n
    end
    fade_opacity(opacity, speed) unless opacity.nil?
  end
  #-----------------------------------------------------------------------------
  # * Fade Opacity
  #-----------------------------------------------------------------------------
  # o Written by  : Kain Nobel
  # o Description : Fades this windows opacity in a certain ammount of frames.
  # o Optional    : n (Integer), speed (Integer)
  #-----------------------------------------------------------------------------
  def fade_opacity(n = nil, speed = 10)
    unless self.opacity == n or n.nil?
      self.opacity -= ((self.opacity - n) / speed).abs if self.opacity > n
      self.opacity += ((self.opacity - n) / speed).abs if self.opacity < n
    end
  end
  #-----------------------------------------------------------------------------
  # * Get Upgrade Text Color
  #-----------------------------------------------------------------------------
  # o Written by  : Kain Nobel
  # o Description : Common CMS method, defines equipment "upgrade color"
  #-----------------------------------------------------------------------------
  def upgrade_color
    return Color.new(0, 255, 0, 255)
  end
  #-----------------------------------------------------------------------------
  # * Get Downgrade Text Color
  #-----------------------------------------------------------------------------
  # o Written by  : Kain Nobel
  # o Description : Common CMS method, defines equipment "downgrade color"
  #-----------------------------------------------------------------------------
  def downgrade_color
    return Color.new(255, 0, 0, 255)
  end
end
Expand to see the code.


Also, just a small addition to the initialize method in Window_Command. You call it like so...

@window_command = Window_Command.new(160, commands, 5) meaning that the window will show a max of 5 commands then scroll the rest.

Don't call the last arg and it'll just call it normally.

Window_Command+ Show
#===============================================================================
# ** Window_Command
#-------------------------------------------------------------------------------
#   This window deals with general command choices. This class's initialize
# method has been replaced to make command windows scrollable and default size
# to be set to a specified set of showable commands.
#===============================================================================
class Window_Command < Window_Selectable
  #-----------------------------------------------------------------------------
  # * Object Initialization
  #     width    : window width
  #     commands : command text string array
  #     size     : how many commands to be shown at a time (optional)
  #-----------------------------------------------------------------------------
  def initialize(width, commands, size = 1)
    # If Size isn't equal to 1, then use specified size to determine Command
    # Height, else return the commands size X 32
    height = size != 1 ? 32 + size * 32 : 32 + commands.size * 32
    # Compute window height from command quantity
    super(0, 0, width, height)
    @item_max = commands.size
    @commands = commands
    self.contents = Bitmap.new(width - 32, @item_max * 32)
    refresh
    self.index = 0
  end
end
Expand to see the code.
The move_to method is actually managed in Trickster's Movable module. As for the window command addition... its rather pointless. I mean, you can just alter the windows height to show how many commands pretty easily. Not to cut it off, I just don't see anyone using.
SephirothSpawn wrote:
As for the window command addition... its rather pointless. I mean, you can just alter the windows height to show how many commands pretty easily. Not to cut it off, I just don't see anyone using.


It's just a lazy way to do it, incase anybody doesn't want to measure heigth :P

I use it all the time and it doesn't cut-off the command window, it just scrolls the commands. Other than that, it probably is better left out of the MACL.
I don't understand how the move_to function would even work right.  It doesn't seem to be tied to def update at all.  So, do you have to call move_to every frame from within the scene?

The modification on Window_Command seems good, to me, except that instead of setting size to 1 by default it should be non numeric, like nil, in case somebody wanted a command window that was really only 1 command high.  But it probably is redundant otherwise, like the almighty said.
how to use flip_horizontaly thing on my window bitmap class?

and i had this error on my first attempt "Could not confert My_Windows to bitmap"
Without your code an description of what you are doing, I have no clue. And make a topic in the RGSS Support Forums. This topic is for development discussion, installation support, etc.
oh thanks, i'am figuring out my self on my second attempts
i'll cut this from your flip_horizontally! def
here's the code
def iqbal_animated_faces(actor, x, y)
    face = RPG::Cache.battler(actor.battler_name, actor.battler_hue)
    fw = face.width
    fh = face.height
    src_rect = Rect.new(0, 0, fw, fh)
    if actor.direction != 1
      self.contents.blt(x - fw / 23, y - fh, face, src_rect)
    else
      width.times do |i|
        src_rect.x = width - 1 - i
        self.contents.blt(i - fw / 23, y - fh, face, src_rect)
      end
    end
  end 
Expand to see the code.

unfortunately the x position of that face is also modified ... hmm i wonder

I'am sorry if i post this to this board but i really want to know about flip_horizontally example syntax inside your MACL
Ok. You just use this:

  def iqbal_animated_faces(actor, x, y)
    face = RPG::Cache.battler(actor.battler_name, actor.battler_hue)
    face.flip_horizontal! if actor.direction == 1
    self.contents.blt(x, y, face, face.rect)
  end
Expand to see the code.


Much of that code was unneeded. You will probably need to modify your x and y positions, it all depends on your scripts.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=9417