IceDragon200

[RUBY]MkRange

Jul 3rd, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.05 KB | None | 0 0
  1. # // 02/28/2012
  2. # // 02/28/2012
  3. module MkRange
  4.   module_function()
  5.   include RPG::BaseItem::Range::Constants
  6.   def diamond(range, min_range=0)
  7.     result = []
  8.     for x in (-range)..range
  9.       for y in (-range)..range
  10.         next if x.abs+y.abs > range
  11.         next if x.abs+y.abs < min_range
  12.         result << [x,y]
  13.       end
  14.     end  
  15.     result.uniq!
  16.     result
  17.   end  
  18.   def square(range, min_range)
  19.     result = []
  20.     for x in (-range)..range
  21.       for y in (-range)..range
  22.         next if((x.abs < min_range) || (y.abs < min_range))
  23.         result << [x,y]
  24.       end
  25.     end  
  26.     result.uniq!
  27.     result
  28.   end  
  29.   def line(range, min_range)
  30.     result = []
  31.     for i in (-range)..range
  32.       next if i < min_range
  33.       result << [ i, 0]
  34.       result << [ 0, i]
  35.     end  
  36.     result.uniq!
  37.     result
  38.   end
  39.   def by_id(id,*params)
  40.     case id
  41.     when RANGE_DIAMOND
  42.       diamond(*params)
  43.     when RANGE_SQUARE
  44.       square(*params)
  45.     when RANGE_LINE
  46.       line(*params)
  47.     else
  48.       []
  49.     end  
  50.   end  
  51. end
Advertisement
Add Comment
Please, Sign In to add comment