Class: Grueserve::Map

Inherits:
Object
  • Object
show all
Includes:
Debuggable
Defined in:
lib/grueserve/map.rb

Constant Summary

Constants included from Debuggable

Debuggable::LEVELS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Debuggable

format, level, level=, #method_missing, output, #report, #report_for, #reset, #reset_for, source_part, #time

Constructor Details

#initialize(path, application = nil) ⇒ Map

Returns a new instance of Map.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/grueserve/map.rb', line 37

def initialize(path, application = nil)
  @path = path
  @application = application
  @attributes = YAML.load(@path.join("attributes.yaml").read)
  init_lines("movement_obstacles")
  init_lines("visibility_obstacles")
  init_lines("bullet_obstacles")
  init_lines("hearing_obstacles")
  init_lines("fortifications")
  init_areas("speed_areas")
  init_areas("protection_areas")
  init_areas("hidden_areas")
  @hearing_distance_cutoff = (@attributes["hearing_distance_cutoff"] || 100).to_f
  @viewing_distance_limit = (@attributes["viewing_distance_limit"] || 1000).to_f
  @teams = @attributes["teams"].split
  @start_points = @teams.inject({}) do |sum, team|
    sum.merge(team => @attributes["#{team}_start_points"].split.collect do |point_string|
                coords = point_string.split(/,/)
                Geo::Point.new(coords.first.to_f, coords.last.to_f)
              end)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Grueserve::Debuggable

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



35
36
37
# File 'lib/grueserve/map.rb', line 35

def application
  @application
end

#teamsObject (readonly)

Returns the value of attribute teams.



35
36
37
# File 'lib/grueserve/map.rb', line 35

def teams
  @teams
end

Class Method Details

.blocks?(distance, profile) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/grueserve/map.rb', line 27

def self.blocks?(distance, profile)
  return true if profile >= 1
  return false if profile <= 0
  return rand < (profile - (1.0 / ((distance / 100) + (1.0 / profile))))
end

Instance Method Details

#bullet_intersection(line) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/grueserve/map.rb', line 100

def bullet_intersection(line)
  definite_stop = bullet_obstacles.closest_intersection(line)
  line.p2 = definite_stop.first if definite_stop
  fortifications.intersections(line).sort do |a,b|
    a.first.to(line.p1).abs <=> b.first.to(line.p1).abs
  end.each do |possible_stop|
    if self.class.blocks?(line.p1.to(possible_stop.first).abs, self[possible_stop.last] / 1000.0)
      return possible_stop.first
    end
  end
  return line.p2
end

#imgObject



96
97
98
# File 'lib/grueserve/map.rb', line 96

def img
  @path.join(@attributes["map"])
end

#noise_damp(line) ⇒ Object



113
114
115
116
117
118
# File 'lib/grueserve/map.rb', line 113

def noise_damp(line)
  obstacles_damp = hearing_obstacles.intersections(line).inject(1.0) do |sum, obstacle|
    sum * self[obstacle.last] / 1000.0
  end
  (1.0 / ([(line.abs / @hearing_distance_cutoff),1].max ** 2)) * obstacles_damp
end

#protection_factor(location) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/grueserve/map.rb', line 81

def protection_factor(location)
  rval = 1.0
  if area = protection_areas.first_container(location)
    rval *= self[area] / 1000.0
  end
  return rval
end

#send_binaries(client) ⇒ Object



74
75
76
77
78
79
# File 'lib/grueserve/map.rb', line 74

def send_binaries(client)
  Pathname.glob(@path.join("sprites").join("**").join("*")).each do |sprite_frame|
    client.send_bin(sprite_frame.basename, sprite_frame.read)
  end
  client.send_bin("map", img.read)
end

#size_of_team(team) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/grueserve/map.rb', line 60

def size_of_team(team)
  members = 0
  each_client do |client|
    members += 1 if client.team == team
  end
  return members
end

#smallest_teamObject



68
69
70
71
72
# File 'lib/grueserve/map.rb', line 68

def smallest_team
  return @teams.sort do |team1,team2|
    size_of_team(team1) <=> size_of_team(team2)
  end.first
end

#start_point(team, not_point = nil) ⇒ Object



89
90
91
92
93
94
# File 'lib/grueserve/map.rb', line 89

def start_point(team, not_point = nil)
  points_to_choose_from = @start_points[team].clone
  points_to_choose_from.delete(not_point) if not_point && points_to_choose_from.size > 1
  the_point = points_to_choose_from[rand(points_to_choose_from.size)]
  return Geo::Point.new(the_point.x, the_point.y)
end