class Rsrb::Model::Location

Physical location in the world

Attributes

x[R]
y[R]
z[R]

Public Class Methods

new(x, y, z) click to toggle source
# File lib/rsrb/model/location.rb, line 8
def initialize(x, y, z)
  @x = x
  @y = y
  @z = z
end

Public Instance Methods

==(other) click to toggle source
# File lib/rsrb/model/location.rb, line 44
def ==(other)
  return unless other.instance_of? self.class
  @x == other.x && @y == other.y && @z == other.z
end
get_local_x(loc = self) click to toggle source
# File lib/rsrb/model/location.rb, line 14
def get_local_x(loc = self)
  @x - 8 * loc.get_region_x
end
get_local_y(loc = self) click to toggle source
# File lib/rsrb/model/location.rb, line 18
def get_local_y(loc = self)
  @y - 8 * loc.get_region_y
end
get_region_x() click to toggle source
# File lib/rsrb/model/location.rb, line 22
def get_region_x
  (@x >> 3) - 6
end
get_region_y() click to toggle source
# File lib/rsrb/model/location.rb, line 26
def get_region_y
  (@y >> 3) - 6
end
inspect() click to toggle source
# File lib/rsrb/model/location.rb, line 49
def inspect
  "[#{@x},#{@y},#{@z}]"
end
to_s() click to toggle source
# File lib/rsrb/model/location.rb, line 53
def to_s
  inspect
end
transform(x_offset, y_offset, z_offset) click to toggle source
# File lib/rsrb/model/location.rb, line 57
def transform(x_offset, y_offset, z_offset)
  Location.new(@x+x_offset, @y+y_offset, @z+z_offset)
end
within_distance?(loc) click to toggle source
# File lib/rsrb/model/location.rb, line 30
def within_distance?(loc)
  return false unless @z == loc.z
  dx = loc.x - @x
  dy = loc.y - @y
  (-15..14) === dx && (-15..14) === dy
end
within_interaction_distance?(loc) click to toggle source
# File lib/rsrb/model/location.rb, line 37
def within_interaction_distance?(loc)
  return false unless @z == loc.z
  dx = loc.x - @x
  dy = loc.y - @y
  (-3..2) === dx && (-3..2) === dy
end