lib/lacuna_util/task/build_excavators.rb
# TODO: should this be a configuration file option?
# Note: this number should not be more than 50 to avoid an issue with building
#   more than 50 ships per request.
should this be a configuration file option.
Note: this number should not be more than 50 to avoid an issue with building
more than 50 ships per request.
should this be a configuration file option . Note : this number should not be more than 50 to avoid an issue with building more than 50 ships per request .
def build_excavators(buildings, num_to_build)
        sy = Lacuna::Body.find_highest_building(buildings, 'Shipyard')
        buildable = Lacuna::Shipyard.get_buildable(sy['id'])
        if buildable['buildable']['excavator']['can'].to_i == 0
            Logger.log buildable['buildable']['excavator']['reason'][1]
            return
        end
        able = buildable['build_queue_max'].to_i - buildable['build_queue_used'].to_i
        num_to_build = able if num_to_build > able
        num_to_build = buildable['docks_available'] if num_to_build > buildable['docks_available']
        unless num_to_build > 0
            Logger.log "Not enough Shipyard or Space Port slots to build Excavators!"
            return
        end
        Logger.log "Building #{num_to_build} Excavators..."
        Lacuna::Shipyard.build_ship(sy['id'], 'excavator', num_to_build)
    end
def build_excavators ( buildings , num_to_build ) sy = Lacuna :: Body . find_highest_building ( buildings , 'Shipyard' ) buildable = Lacuna :: Shipyard . get_buildable ( sy [ 'id' ] ) if buildable [ 'buildable' ] [ 'excavator' ] [ 'can' ] . to_i == 0 Logger . log buildable [ 'buildable' ] [ 'excavator' ] [ 'reason' ] [ 1 ] return end able = buildable [ 'build_queue_max' ] . to_i - buildable [ 'build_queue_used' ] . to_i num_to_build = able if num_to_build > able num_to_build = buildable [ 'docks_available' ] if num_to_build > buildable [ 'docks_available' ] unless num_to_build > 0 Logger . log "Not enough Shipyard or Space Port slots to build Excavators!" return end Logger . log "Building #{num_to_build} Excavators..." Lacuna :: Shipyard . build_ship ( sy [ 'id' ] , 'excavator' , num_to_build ) end
TODO: should this be a configuration file option?
TODO : should this be a configuration file option?
# Ensure that this planet can build an Excavator. (Requires L11 Archeology) # Make sure the shipyard has enough slots to build the number of Excavators # desired. This includes Ships currently in the build queue. # Make sure there's enough docks on the planet to hold all the Excavators # that need to be built. # And now, let's do the deed.
buildings
num_to_build