Class: MiniMap
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MiniMap
- Defined in:
- app/models/mini_map.rb
Overview
This class describes a mini map.
Instance Method Summary (collapse)
-
- (Integer) find_new_road
Return end_mini_map_id if new root find trial is successfull.
-
- (Boolean) finding_new_road?
Return true of false whether new root find trial is already execited or not.
-
- (Integer) foods_total
Return the total number of foods in mini_map_cells.
-
- (Boolean) fortress_squads_num
Return the number of squads which are assigned to the fortress on this map.
-
- (Integer) fortress_status
Return true or false whether fortress_cells is blank or not.
-
- (Boolean) fortress_traps_num
Return the number of traps which are installed to the fortress on this map.
-
- (Boolean) guard_mission_active?
Return true or false whether guard mission for this mini map is existing or not.
-
- (Integer) moneys_total
Return the total number of moneys in mini_map_cells.
-
- (Integer) productions_total
Return the total number of productions in mini_map_cells.
-
- (Array) sp_resources_all
Return all the sp_resources in mini_map_cells.
-
- (String) sp_resources_txt
Return the description of sp_resource in mini_map_cells.
-
- (Boolean) status
Return true or false whether mini_map_cells is blank or not.
-
- (String) status_txt
Return the description whether mini_map_cells is blank or not.
Instance Method Details
- (Integer) find_new_road
Return end_mini_map_id if new root find trial is successfull.
100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/models/mini_map.rb', line 100 def find_new_road return nil if finding_new_road? return nil if Params::NEW_ROOT_FIND_PERCENTAGE < rand(Params::PERCENT_DENOMINATOR) found_mini_map_ids = mini_map_roads.collect{|r| r.end_mini_map_id} found_mini_map_ids << id not_found_mini_map_ids = MiniMap.all.collect{|m| m.id} - found_mini_map_ids end_mini_map_id = not_found_mini_map_ids[rand(not_found_mini_map_ids.size)] return end_mini_map_id end |
- (Boolean) finding_new_road?
Return true of false whether new root find trial is already execited or not.
92 93 94 95 96 |
# File 'app/models/mini_map.rb', line 92 def finding_new_road? new_root_find_queue = ProductionQueue.find_by_symbol_and_queue_id(:new_root_find.to_s, id) return true unless new_root_find_queue.blank? return false end |
- (Integer) foods_total
Return the total number of foods in mini_map_cells.
29 30 31 32 33 34 35 36 37 |
# File 'app/models/mini_map.rb', line 29 def foods_total foods_total = 0 mini_map_cells.each do |cell| foods_total += cell.terrain.food foods_total += cell.sp_resource.food unless cell.sp_resource.blank? foods_total += cell.construction.food unless cell.construction.blank? end return foods_total end |
- (Boolean) fortress_squads_num
Return the number of squads which are assigned to the fortress on this map.
121 122 123 124 125 126 127 128 |
# File 'app/models/mini_map.rb', line 121 def fortress_squads_num return 0 unless fortress_status squads = Array.new fortress_cells.each do |cell| squads << cell.squad unless cell.squad_id.blank? end return squads.size end |
- (Integer) fortress_status
Return true or false whether fortress_cells is blank or not.
114 115 116 117 |
# File 'app/models/mini_map.rb', line 114 def fortress_status return false if fortress_cells.blank? return true end |
- (Boolean) fortress_traps_num
Return the number of traps which are installed to the fortress on this map.
132 133 134 135 136 137 138 139 |
# File 'app/models/mini_map.rb', line 132 def fortress_traps_num return 0 unless fortress_status traps = Array.new fortress_cells.each do |cell| traps << cell.squad unless cell.squad_id.blank? end return traps.size end |
- (Boolean) guard_mission_active?
Return true or false whether guard mission for this mini map is existing or not.
143 144 145 146 147 148 |
# File 'app/models/mini_map.rb', line 143 def guard_mission_active? missions.each do |mission| return true if mission.category_symbol == :guard.to_s and mission.status_symbol == :on_going.to_s end return false end |
- (Integer) moneys_total
Return the total number of moneys in mini_map_cells.
53 54 55 56 57 58 59 60 61 |
# File 'app/models/mini_map.rb', line 53 def moneys_total moneys_total = 0 mini_map_cells.each do |cell| moneys_total += cell.terrain.money moneys_total += cell.sp_resource.money unless cell.sp_resource.blank? moneys_total += cell.construction.money unless cell.construction.blank? end return moneys_total end |
- (Integer) productions_total
Return the total number of productions in mini_map_cells.
41 42 43 44 45 46 47 48 49 |
# File 'app/models/mini_map.rb', line 41 def productions_total productions_total = 0 mini_map_cells.each do |cell| productions_total += cell.terrain.production productions_total += cell.sp_resource.production unless cell.sp_resource.blank? productions_total += cell.construction.production unless cell.construction.blank? end return productions_total end |
- (Array) sp_resources_all
Return all the sp_resources in mini_map_cells.
65 66 67 68 69 70 71 |
# File 'app/models/mini_map.rb', line 65 def sp_resources_all sp_resources = Array.new mini_map_cells.each do |cell| sp_resources << cell.sp_resource unless cell.sp_resource.blank? end return sp_resources.uniq end |
- (String) sp_resources_txt
Return the description of sp_resource in mini_map_cells. Duplicated sp_resource is displayed only once.
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/mini_map.rb', line 76 def sp_resources_txt sp_resources_txt = '' sp_resources = Hash.new mini_map_cells.each do |cell| if not cell.sp_resource.blank? and sp_resources[cell.sp_resource.symbol].blank? sp_resources[cell.sp_resource.symbol] = cell.sp_resource.name sp_resources_txt += cell.sp_resource.name sp_resources_txt += ',' end end sp_resources_txt.chop! if sp_resources_txt.last == ',' return sp_resources_txt end |
- (Boolean) status
Return true or false whether mini_map_cells is blank or not.
15 16 17 18 |
# File 'app/models/mini_map.rb', line 15 def status return false if mini_map_cells.blank? return true end |
- (String) status_txt
Return the description whether mini_map_cells is blank or not.
22 23 24 25 |
# File 'app/models/mini_map.rb', line 22 def status_txt return I18n.t('activerecord.attributes.mini_map.cells_filled') if status return I18n.t('activerecord.attributes.mini_map.cells_blank') end |