Class: Race
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Race
- Defined in:
- lib/galaxy/models/race.rb
Instance Attribute Summary collapse
-
#order ⇒ Object
Returns the value of attribute order.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #battle_groups ⇒ Object
- #enemy? ⇒ Boolean (also: #war?)
- #friend? ⇒ Boolean (also: #ally?, #peace?)
-
#initialize(match, state) ⇒ Race
constructor
A new instance of Race.
- #key ⇒ Object
- #kill ⇒ Object
-
#rip? ⇒ Boolean
Boolean tests on Races.
-
#sciences ⇒ Object
Special collection accessors.
- #ships ⇒ Object (also: #designs, #ship_types)
-
#your? ⇒ Boolean
Redefining TODO or test if this is your other controlled Race (aka 3ombies).
Constructor Details
#initialize(match, state) ⇒ Race
Returns a new instance of Race.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/galaxy/models/race.rb', line 39 def initialize match, state case match.size when 10 then super({:name=>match[0], :drive=>match[1].to_f, :weapons=>match[2].to_f, :shields=>match[3].to_f, :cargo=>match[4].to_f, :pop=>match[5], :ind=>match[6].to_f, :num_planets=>match[7].to_i, :relation=>match[8], :vote=>match[9].to_f}) when 0 then # All init data must be given in a state hash super state end add if self.class.dataset # Add instantiated model to dataset if it is defined @order = Order.new self, 'zelikaka', state[:game], state[:turn] if your? end |
Instance Attribute Details
#order ⇒ Object
Returns the value of attribute order.
26 27 28 |
# File 'lib/galaxy/models/race.rb', line 26 def order @order end |
Instance Method Details
#<=>(other) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/galaxy/models/race.rb', line 74 def <=>(other) case other when nil then 1 when Race then num_planets == other.num_planets ? key <=> other.key : num_planets <=> other.num_planets when Product, Planet, Group, Bombing, Route, Fleet then - other <=> self when Integer then num_planets <=> other when String then self <=> other.downcase.to_sym when Symbol then return rip? ? 0 : 1 if other == :rip or other == :dead return !rip? ? 0 : 1if other == :alive or other == :active return enemy? ? 0 :1 if other == :enemy or other == :war return friend? ? 0 : 1 if other == :friend or other == :ally or other == :peace return your? ? 0 : 1 if other == :your or other == :yours or other == :controlled or other == :my or other == :mine return 0 if name.downcase.include? other.to_s key <=> other.to_s else raise ArgumentError, 'Comparison with a wrong type' end end |
#battle_groups ⇒ Object
60 |
# File 'lib/galaxy/models/race.rb', line 60 def battle_groups ; groups.find_all {|g| g and g.from_battle?} || [] end |
#enemy? ⇒ Boolean Also known as: war?
65 |
# File 'lib/galaxy/models/race.rb', line 65 def enemy? ; relation == 'War' end |
#friend? ⇒ Boolean Also known as: ally?, peace?
68 |
# File 'lib/galaxy/models/race.rb', line 68 def friend? ; not enemy? end |
#key ⇒ Object
51 |
# File 'lib/galaxy/models/race.rb', line 51 def key; name end |
#kill ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/galaxy/models/race.rb', line 28 def kill products.each {|m| m.kill} planets.each {|m| m.kill} fleets.each {|m| m.kill} routes.each {|m| m.kill} groups.each {|m| m.kill} bombings.each {|m| m.kill} incoming_bombings.each {|m| m.kill} super #puts "Warning: kill attempt failed for #{self}" unless end |
#rip? ⇒ Boolean
Boolean tests on Races
63 |
# File 'lib/galaxy/models/race.rb', line 63 def rip? ; name.split("_")[-1] == 'RIP' end |
#sciences ⇒ Object
Special collection accessors
54 |
# File 'lib/galaxy/models/race.rb', line 54 def sciences; products.find_all {|p| p and p.science?} || [] end |
#ships ⇒ Object Also known as: designs, ship_types
55 |
# File 'lib/galaxy/models/race.rb', line 55 def ships; products.find_all {|p| p and p.ship?} || [] end |
#your? ⇒ Boolean
Redefining TODO or test if this is your other controlled Race (aka 3ombies)
72 |
# File 'lib/galaxy/models/race.rb', line 72 def your? ; relation == '-' end |