-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93d555a
commit cc3dd09
Showing
5 changed files
with
107 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import math | ||
import time | ||
from datetime import datetime, timezone | ||
|
||
from autotraders.map.waypoint import Waypoint | ||
|
||
class WaypointQuery: | ||
def __init__(self, args): | ||
self.data = args | ||
|
||
def query(self, ship, session): | ||
if type(self.data["destination"]) is str: | ||
return self.data["destination"] | ||
else: | ||
choices, _ = Waypoint.all(ship.nav.location.system, session) | ||
ship_current_waypoint = [choice for choice in choices if choice.symbol == ship.nav.location][0] | ||
tmp = [] | ||
for choice in choices: | ||
if "trait" in self.data["destination"]: | ||
if len([trait for trait in choice.traits if | ||
trait.symbol == self.data["destination"]["trait"]]) != 0: | ||
tmp.append(choice) | ||
if "type" in self.data["destination"]: | ||
if choice.waypoint_type == self.data["destination"]["type"]: | ||
tmp.append(choice) | ||
choices = tmp | ||
if len(choices) == 0: | ||
raise Exception("0 possible waypoints") | ||
if "selection" not in self.data["destination"] or self.data["destination"][ | ||
"selection"] == "NEAREST": | ||
accepted = choices[0] | ||
best = 1000000 | ||
for choice in choices: | ||
if choice.symbol == ship.nav.location: | ||
accepted = choice | ||
best = -1 | ||
distance = math.sqrt( | ||
((choice.x - ship_current_waypoint.x) ** 2) + ((choice.y - ship_current_waypoint.y) ** 2)) | ||
if distance < best: | ||
best = distance | ||
accepted = choice | ||
else: | ||
accepted = choices[0] | ||
return accepted | ||
|
||
|
||
class Navigate: | ||
def __init__(self, args): | ||
self.data = args | ||
self.query = WaypointQuery(args) | ||
|
||
def execute(self, ship, session): | ||
accepted = self.query.query(ship, session) | ||
if str(accepted.symbol) != str(ship.nav.location): | ||
ship.navigate(str(accepted.symbol)) | ||
time.sleep(1) | ||
ship.update() | ||
if ship.nav.status == "IN_TRANSIT": | ||
time.sleep((ship.nav.route.arrival - datetime.now(timezone.utc)).seconds) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import logging | ||
|
||
from autotraders.ship import Ship | ||
|
||
|
||
class ShipCommand: | ||
def __init__(self, command, args): | ||
if type(args) is not dict: | ||
args = {} | ||
self.command = command | ||
self.fail_fast = args.get("fail-fast", True) | ||
|
||
def execute(self, ship: Ship): | ||
if self.command == "dock": | ||
ship.dock() | ||
elif self.command == "orbit": | ||
ship.orbit() | ||
elif self.command == "refuel": | ||
try: | ||
ship.refuel() | ||
except IOError as e: | ||
if self.fail_fast: | ||
raise e | ||
else: | ||
logging.warning(self.command + " failed to execute") | ||
elif self.command == "extract": | ||
try: | ||
ship.refuel() | ||
except IOError as e: | ||
if self.fail_fast: | ||
raise e | ||
else: | ||
logging.warning(self.command + " failed to execute") |