Class: Omega::Client::SolarSystem

Inherits:
Object
  • Object
show all
Includes:
TrackEntity, Trackable
Defined in:
lib/omega/client/entities/cosmos.rb

Overview

Omega client Cosmos::Entities::SolarSystem tracker

Instance Attribute Summary

Attributes included from Trackable

#entity, #event_handlers

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TrackEntity

clear_entities, entities, included, track_entity

Methods included from Trackable

#clear_handlers, #clear_handlers_for, #handle, #handles?, included, #method_missing, #node, node, #raise_event, #refresh

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Omega::Client::Trackable

Class Method Details

.with_fewest(args = {}) ⇒ Cosmos::Entities::SolarSystem?

Conveniency utility to return the system containing the fewest entities of the specified type

This will issue a server side request to retrieve entities (and systems they are in via the Client::Node automatically).

note this will only consider systems w/ entities, systems w/ none of the specified entity will not be returned


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/omega/client/entities/cosmos.rb', line 68

def self.with_fewest(args={})
  systems = []
  if(args[:type] == "Manufactured::Station")
    systems +=
      Omega::Client::Station.owned_by(args[:owned_by]).map { |s|
        [s.system_id, s.solar_system]
      }
  end

  system_map = Hash.new(0)
  systems.each { |n,s| system_map[n] += 1 }
  fewest = system_map.sort_by { |n,c| c }.first
  return nil if fewest.nil?
  fewest = fewest.first
  systems.find { |s| s.first == fewest }.last
end

Instance Method Details

#asteroidsObject

Wrap asteroids, refresh resources


40
41
42
43
44
45
# File 'lib/omega/client/entities/cosmos.rb', line 40

def asteroids
  self.entity.asteroids.collect { |ast|
    ast.resources = node.invoke('cosmos::get_resources', ast.id)
    ast
  }
end

#closest_neighbor_with_no(args = {}) ⇒ Cosmos::Entities::SolarSystem?

Conveniency utility to return the closest neighbor system with entities of the specified type

This will issue a server side request to retrieve entities and systems


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/omega/client/entities/cosmos.rb', line 94

def closest_neighbor_with_no(args={})
  entities = []
  entities = Omega::Client::Station.owned_by(args[:owned_by]) if(args[:type] == "Manufactured::Station")

  systems = [self]
  systems.each { |sys|
    # TODO sort jumpgates by distance from sys to endpoint
    sys.jump_gates.each { |jg|
      endpoint = Omega::Client::SolarSystem.get(jg.endpoint_id)
      if entities.find { |e| e.system_id == jg.endpoint_id }.nil?
        return endpoint
      elsif !systems.include?(jg.endpoint)
        systems << endpoint
      end
    }
  }

  return nil
end

#entitiesObject

Convenience utility, return manufactured entities in system

Always issues a server side request to retrieve entities


50
51
52
53
# File 'lib/omega/client/entities/cosmos.rb', line 50

def entities
  # TODO convert results to omega client entity representations?
  node.invoke('manufactured::get_entities', 'under', id)
end

#jump_gatesObject

Wrap jump gates, lookup endpoint id if missing


30
31
32
33
34
35
36
37
# File 'lib/omega/client/entities/cosmos.rb', line 30

def jump_gates
  @jump_gates ||=
    self.entity.jump_gates.collect { |jg|
      jg.endpoint =
        SolarSystem.cached(jg.endpoint_id) if jg.endpoint.nil?
      jg
    }
end