amram

aurora4x suggestion for automated refueling

Nov 5th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. // doesn't worry about cases where intermediate fuel sources extend the range accordingly. Only a single fuel source is considered.
  2. //
  3. // functional assumptions:
  4. // getPosition() returns a position object
  5. // getNearestFuelSource() returns the fuel object of the nearest valid fuel
  6. // computeDistance(a,b) returns distance between two position objects
  7. // getTransitsFromTo(a,b) returns a list of transits from position a to b
  8. // queueTask(a) adds task to objects task queue
  9.  
  10. currentRange = getCurrentShipRange()
  11. designRange = getShipDesignRange()
  12. queRange = 0
  13. thresholdRange = 0
  14. shipPos = getPosition(this)
  15.  
  16. if (conditionalFuelOrderExists)
  17. thresholdRange = DesignRange * XX% // XX% being the threshold percentage in the conditional order
  18. else
  19. thresholdRange = DesignRange
  20.  
  21. taskPos=null
  22. for task in desired que list
  23. {
  24. fuelPos = getPosition(getNearestFuelSource(shipPos))
  25. taskPos = getPosition(task)
  26. taskDist = computeDistance(shipPos,taskPos)
  27. shipFuelDist = computeDistance(shipPos,fuelPos)
  28. taskFuelDist = computeDistance(taskPos,fuelPos)
  29.  
  30. if (currentRange - taskDist > thresholdRange // can I get there (at all/without conditional refuel aborting the trip)?
  31. && designRange - taskFuelDist > thresholdRange) // if I refuel, can I reach taskPos from fuelPos?
  32. {
  33. // Then yes, I can get there
  34. // Will I be low on fuel before/when i arrive?
  35. if (currentRange - taskDist < thresholdRange)
  36. {
  37. for transit in getTransitsFromTo(shipPos,fuelPos)
  38. queTask(transit)
  39. queTask(refuel)
  40. for transit in getTransitsFromTo(fuelPos,taskPos)
  41. queTask(transit)
  42. queueTask(task)
  43. }
  44. else
  45. queueTask(task)
  46. }
  47. else{
  48. // complain/react to unreachable task position
  49. }
  50. shipPos = taskPos
  51. fuelPos = getPosition(getNearestFuelSource(shipPos))
  52. }
Add Comment
Please, Sign In to add comment