Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // doesn't worry about cases where intermediate fuel sources extend the range accordingly. Only a single fuel source is considered.
- //
- // functional assumptions:
- // getPosition() returns a position object
- // getNearestFuelSource() returns the fuel object of the nearest valid fuel
- // computeDistance(a,b) returns distance between two position objects
- // getTransitsFromTo(a,b) returns a list of transits from position a to b
- // queueTask(a) adds task to objects task queue
- currentRange = getCurrentShipRange()
- designRange = getShipDesignRange()
- queRange = 0
- thresholdRange = 0
- shipPos = getPosition(this)
- if (conditionalFuelOrderExists)
- thresholdRange = DesignRange * XX% // XX% being the threshold percentage in the conditional order
- else
- thresholdRange = DesignRange
- taskPos=null
- for task in desired que list
- {
- fuelPos = getPosition(getNearestFuelSource(shipPos))
- taskPos = getPosition(task)
- taskDist = computeDistance(shipPos,taskPos)
- shipFuelDist = computeDistance(shipPos,fuelPos)
- taskFuelDist = computeDistance(taskPos,fuelPos)
- if (currentRange - taskDist > thresholdRange // can I get there (at all/without conditional refuel aborting the trip)?
- && designRange - taskFuelDist > thresholdRange) // if I refuel, can I reach taskPos from fuelPos?
- {
- // Then yes, I can get there
- // Will I be low on fuel before/when i arrive?
- if (currentRange - taskDist < thresholdRange)
- {
- for transit in getTransitsFromTo(shipPos,fuelPos)
- queTask(transit)
- queTask(refuel)
- for transit in getTransitsFromTo(fuelPos,taskPos)
- queTask(transit)
- queueTask(task)
- }
- else
- queueTask(task)
- }
- else{
- // complain/react to unreachable task position
- }
- shipPos = taskPos
- fuelPos = getPosition(getNearestFuelSource(shipPos))
- }
Add Comment
Please, Sign In to add comment