Skip to content

Commit

Permalink
fuel management conductor conditionally orders refill tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ctri-The-Third committed Nov 6, 2023
1 parent 1a18857 commit 439e154
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
49 changes: 47 additions & 2 deletions conductor_fuel_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
BHVR_EXTRACT_AND_TRANSFER,
BHVR_CHILL_AND_SURVEY,
BHVR_BUY_AND_DELIVER_OR_SELL,
BHVR_REFUEL_ALL_IN_SYSTEM,
)
from behaviours.generic_behaviour import Behaviour as GenericBehaviour

Expand Down Expand Up @@ -120,10 +121,10 @@ def run(self):

def daily_update(self):
possible_ships = self.haulers + self.commanders
gas_giant = self.st.find_waypoints_by_type_one(
self.gas_giant = gas_giant = self.st.find_waypoints_by_type_one(
self.starting_system.symbol, "GAS_GIANT"
)
fuel_refinery = self.find_fuel_refineries(gas_giant)
self.fuel_refinery = fuel_refinery = self.find_fuel_refineries(gas_giant)
hydrocarbon_shipper = self.commanders[0]

# set behaviour - hydrocarbon shipper siphons hydrocarbon from export and sells to fuel refinery
Expand All @@ -138,9 +139,42 @@ def daily_update(self):
# if we have a fuel shipper, give it all the fuel shipping tasks possible
pass

#
# daily recon task
#

log_task(
self.connection,
BHVR_EXPLORE_SYSTEM,
[],
self.starting_system.symbol,
1,
self.current_agent_symbol,
{},
expiry=self.next_daily_update,
specific_ship_symbol=self.satellites[0].name,
)

def quarterly_update(self):
# if we have a fuel shipper, give it all the fuel shipping tasks possible
# if not, give the exporter a refuel task for 1 (maybe 2) points.
possible_ships = self.haulers + self.commanders
refueler = possible_ships[min(1, len(possible_ships) - 1)]
fuel_refinery = self.st.system_market(self.fuel_refinery)
fuel = fuel_refinery.get_tradegood("FUEL")
if fuel.supply in ("ABUNDANT", "HIGH"):
if self.any_refuels_needed():
log_task(
self.connection,
BHVR_REFUEL_ALL_IN_SYSTEM,
["35_CARGO"],
waypoint_slicer(self.gas_giant),
4,
self.current_agent_symbol,
{},
expiry=self.next_quarterly_update,
specific_ship_symbol=refueler.name,
)
pass

def minutely_update(self):
Expand Down Expand Up @@ -170,6 +204,17 @@ def find_fuel_refineries(self, relative_to: Waypoint = None) -> Waypoint:

return closest_refinery

def any_refuels_needed(self):
waypoints = self.st.find_waypoints_by_trait(
self.starting_system.symbol, "MARKETPLACE"
)
markets = [self.st.system_market(wp) for wp in waypoints]
for market in markets:
fuel = market.get_tradegood("FUEL")
if fuel.type == "EXCHANGE" and fuel.supply != "ABUNDANT":
return True
return False

def maybe_upgrade_ship(self):
# surveyors first, then extractors
return False
Expand Down
14 changes: 10 additions & 4 deletions dispatcherWK16.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
ChillAndSurvey,
BEHAVIOUR_NAME as BHVR_CHILL_AND_SURVEY,
)
from behaviours.refuel_all_fuel_exchanges_in_system import (
RefuelAllExchanges,
BEHAVIOUR_NAME as BHVR_REFUEL_ALL_IN_SYSTEM,
)
from behaviours.generic_behaviour import Behaviour
from straders_sdk.utils import try_execute_select, try_execute_upsert
from straders_sdk.pathfinder import PathFinder
Expand Down Expand Up @@ -186,11 +190,11 @@ def run(self):
self.client: SpaceTraders
self.client.set_current_agent(self.agents[0][1], self.agents[0][0])
self.client.ships_view(force=True)

# rather than tying this behaviour to the probe, this is executed at the dispatcher level.

ships_and_threads["scan_thread"] = threading.Thread(
target=self.maybe_scan_all_systems, daemon=True
target=self.maybe_scan_all_systems, daemon=True
)
ships_and_threads["scan_thread"].start()
startime = datetime.now()
Expand Down Expand Up @@ -478,6 +482,8 @@ def map_behaviour_to_class(
bhvr = FindMountsAndEquip(aname, sname, bhvr_params, session=self.session)
elif id == BHVR_CHILL_AND_SURVEY:
bhvr = ChillAndSurvey(aname, sname, bhvr_params, session=self.session)
elif id == BHVR_REFUEL_ALL_IN_SYSTEM:
bhvr = RefuelAllExchanges(aname, sname, bhvr_params, session=self.session)
else:
pass
return bhvr
Expand Down Expand Up @@ -510,8 +516,8 @@ def maybe_scan_all_systems(self):
st.system_market(waypoint)
if waypoint.type == "JUMP_GATE":
st.system_jumpgate(waypoint)
return

return
if got_em_all:
return
for i in range(1, math.ceil(api_systems / 20) + 1):
Expand Down
2 changes: 1 addition & 1 deletion spacetraders_sdk

0 comments on commit 439e154

Please sign in to comment.