class EliteUniverse::Planet
Constants
- CHARS
- ECONS
- GOVS
Public Class Methods
new(a, b, c)
click to toggle source
# File lib/elite_universe/planet.rb, line 26 def initialize a, b, c @w = [ a, b, c ] end
Public Instance Methods
economy()
click to toggle source
# File lib/elite_universe/planet.rb, line 42 def economy ECONS[econ_n] end
government()
click to toggle source
# File lib/elite_universe/planet.rb, line 38 def government GOVS[gov_n] end
location()
click to toggle source
# File lib/elite_universe/planet.rb, line 46 def location [@w[1] >> 8, @w[0] >> 8] end
name()
click to toggle source
# File lib/elite_universe/planet.rb, line 30 def name (@w[0] & 64 == 0 ? 2 : 3).times.inject([@w]) do |vs| vs << twist(vs[-1]) end.inject('') do |name, v| name += CHARS[(v[2] >> 8) & 31] end.tr('.', '').capitalize end
next()
click to toggle source
# File lib/elite_universe/planet.rb, line 57 def next EliteUniverse::Planet.new *(twist twist twist twist @w) end
technology()
click to toggle source
# File lib/elite_universe/planet.rb, line 50 def technology ((@w[1] >> 8 ) & 3) + (econ_n ^ 7) + (gov_n >> 1) + ((gov_n & 1) == 1 ? 2 : 1) end
Private Instance Methods
econ_n()
click to toggle source
# File lib/elite_universe/planet.rb, line 80 def econ_n ((@w[0] >> 8) & 7) | (gov_n <= 1 ? 2 : 0) end
gov_n()
click to toggle source
# File lib/elite_universe/planet.rb, line 76 def gov_n (@w[1] >> 3) & 7 end
twist(arr)
click to toggle source
# File lib/elite_universe/planet.rb, line 68 def twist arr [ arr[1], arr[2], (version_at_least('2.4.0') ? arr.sum : arr.inject(:+)) % 65536 ] end
version_at_least(version)
click to toggle source
# File lib/elite_universe/planet.rb, line 63 def version_at_least version # ... because I want to use new features if possible Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(version) end