Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
arihant2math committed May 28, 2023
1 parent 7d7d180 commit 47f12f8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
1 change: 1 addition & 0 deletions example.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ships:
mining:
- "STARSTAR-1"
- "STARSTAR-2"

actions: # actions are per ship
Expand Down
15 changes: 7 additions & 8 deletions source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'Spacelang'
copyright = '2023, Ashwin Naren'
author = 'Ashwin Naren'
release = 'ALPHA'
project = "Spacelang"
copyright = "2023, Ashwin Naren"
author = "Ashwin Naren"
release = "ALPHA"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = []

templates_path = ['_templates']
templates_path = ["_templates"]
exclude_patterns = []



# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'furo'
html_static_path = ['_static']
html_theme = "furo"
html_static_path = ["_static"]
21 changes: 16 additions & 5 deletions spacelang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def __init__(self, name, data):
if type(d) == str:
self.steps[group].append(Step(d, None)) # TODO: Move to step class
else:
self.steps[group].append(Step(list(d.keys())[0], d[list(d.keys())[0]]))
self.steps[group].append(
Step(list(d.keys())[0], d[list(d.keys())[0]])
)

def run(self, ships, events, session):
for group in self.steps:
Expand All @@ -61,11 +63,18 @@ def run(self, session):
ships = {}
for group in self.ship_groups:
ships[group] = [Ship(ship, session) for ship in self.ship_groups[group]]
contains_onstart = len([trigger for trigger in self.triggers if trigger.name == "on_start"]) == 1
contains_onstart = (
len([trigger for trigger in self.triggers if trigger.name == "on_start"])
== 1
)
if contains_onstart:
on_start = [trigger for trigger in self.triggers if trigger.name == "on_start"][0]
on_start = [
trigger for trigger in self.triggers if trigger.name == "on_start"
][0]
logging.info("Processing trigger on_start")
thread = Thread(target=on_start.run, name="OnStart", args=(ships, self.events, session))
thread = Thread(
target=on_start.run, name="OnStart", args=(ships, self.events, session)
)
thread.start()
while True:
logging.debug("Checking triggers ...")
Expand All @@ -81,4 +90,6 @@ def load_text(stream):
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("pyrate_limiter").setLevel(logging.WARNING)
logging.basicConfig(format='[%(threadName)s] %(levelname)s: %(message)s', level=logging.DEBUG)
logging.basicConfig(
format="[%(threadName)s] %(levelname)s: %(message)s", level=logging.DEBUG
)
27 changes: 21 additions & 6 deletions spacelang/step/navigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from autotraders.map.waypoint import Waypoint


class WaypointQuery:
def __init__(self, args):
self.data = args
Expand All @@ -13,29 +14,43 @@ def query(self, ship, session):
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]
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:
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":
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))
((choice.x - ship_current_waypoint.x) ** 2)
+ ((choice.y - ship_current_waypoint.y) ** 2)
)
if distance < best:
best = distance
accepted = choice
Expand Down

0 comments on commit 47f12f8

Please sign in to comment.