Skip to content

Instantly share code, notes, and snippets.

@Sailias
Created July 12, 2012 16:24
Show Gist options
  • Save Sailias/3099142 to your computer and use it in GitHub Desktop.
Save Sailias/3099142 to your computer and use it in GitHub Desktop.
def distance_between(obj_a, obj_b)
p1 = GeoRuby::SimpleFeatures::Point.from_x_y(get_x(obj_a), get_y(obj_a))
p2 = GeoRuby::SimpleFeatures::Point.from_x_y(get_x(obj_b), get_y(obj_b))
p1.euclidian_distance(p2)
end
class PriceList < ActiveRecord::Base
self.table_name = 'price_list'
scope :with_code, lambda{|code|
where(:code => code)
}
def self.method_missing(m)
var = PriceList.with_code(m.to_s.upcase).first
if var
return var.cost
else
super
end
end
end
class TravellingShip < MyShip
attr_accessor :queue
def modify_speed
max_speed_allowed = Functions.get_numeric_variable('MAX_SHIP_SPEED')
if self.distance_from_objective > self.max_speed && self.max_speed < max_speed_allowed
upgrade_amount_available = max_speed_allowed - self.max_speed
# TODO: Find the price of refueling
price_to_refuel = 1
available_funds = Schemaverse.estimated_income - (Schemaverse.fuel_needed_for_next_tic * price_to_refuel)
upgrade_amount = available_funds <= upgrade_amount_available * PriceList.max_speed ? upgrade_amount_available : available_funds / PriceList.max_speed
self.upgrade('MAX_SHIP_SPEED', upgrade_amount.to_i) if upgrade_amount.to_i > 0
end
end
def process_queue
next_objective = queue.first
if explorer_ship.course_control(Functions.distance_between(self, next_objective) / 2, nil, next_objective)
self.objective = next_objective
queue.shift
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment