Skip to content

Commit

Permalink
add default parameters to each behaviour class
Browse files Browse the repository at this point in the history
  • Loading branch information
Ctri-The-Third committed Jan 19, 2024
1 parent b8e3db5 commit 2180a4f
Show file tree
Hide file tree
Showing 29 changed files with 419 additions and 83 deletions.
7 changes: 5 additions & 2 deletions behaviours/_empty_behaviour.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def run(self):
self._run()
self.end()

def default_params_obj(self):
return_obj = super().default_params_obj()

def _run(self):
st = self.st
ship = self.ship # = st.ships_view_one(self.ship_name, True)
Expand All @@ -78,7 +81,7 @@ def _run(self):

bhvr = NewBehaviour(agent, ship, behaviour_params or {})

lock_ship(ship, "MANUAL", bhvr.st.db_client.connection, 60 * 24)
lock_ship(ship, "MANUAL", 60 * 24)

bhvr.run()
lock_ship(ship, "MANUAL", bhvr.st.db_client.connection, 0)
lock_ship(ship, "MANUAL", 0)
16 changes: 16 additions & 0 deletions behaviours/buy_and_deliver_or_sell.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ def __init__(

def run(self):
super().run()
self.ship = self.st.ships_view_one(self.ship_name)
self.sleep_until_ready()
self.st.logging_client.log_beginning(
BEHAVIOUR_NAME,
self.ship.name,
self.agent.credits,
behaviour_params=self.behaviour_params,
)
self._run()
self.end()

def default_params_obj(self):
return_obj = super().default_params_obj()
return return_obj

def _run(self):
st = self.st
ship = self.ship
agent = self.agent
Expand Down
21 changes: 17 additions & 4 deletions behaviours/buy_and_sell_dripfeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,25 @@ def __init__(

def run(self):
super().run()
self.ship = self.st.ships_view_one(self.ship_name)
self.sleep_until_ready()
self.st.logging_client.log_beginning(
BEHAVIOUR_NAME,
self.ship.name,
self.agent.credits,
behaviour_params=self.behaviour_params,
)
self._run()
self.end()

def default_params_obj(self):
return_obj = super().default_params_obj()
return return_obj

def _run(self):
st = self.st
ship = self.ship = self.st.ships_view_one(self.ship.name, True)
agent = self.agent
st.logging_client.log_beginning(
BEHAVIOUR_NAME, ship.name, agent.credits, self.behaviour_params
)

#
# setup initial parameters and preflight checks
Expand Down Expand Up @@ -178,7 +191,7 @@ def sell_half(self):
amount_to_sell = min(ship.cargo_units_used, tradegood.trade_volume)
self.sell_cargo(self.target_tradegood, amount_to_sell, sell_market_mkt)

def end(self, error):
def end(self, error=None):
super().end()
self.st.logging_client.log_ending(
BEHAVIOUR_NAME, self.ship.name, self.agent.credits
Expand Down
26 changes: 20 additions & 6 deletions behaviours/chill_and_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,28 @@ def __init__(
)
self.target_wp_s = behaviour_params["asteroid_wp"]

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["asteroid_wp"] = "X1-TEST-AB12"

return return_obj

def run(self):
self.ship = self.st.ships_view_one(self.ship_name)
self.sleep_until_ready()
self.st.logging_client.log_beginning(
BEHAVIOUR_NAME,
self.ship.name,
self.agent.credits,
behaviour_params=self.behaviour_params,
)
self._run()
self.end()

def _run(self):
st = self.st
ship = self.ship
agent = st.view_my_self()
st.logging_client.log_beginning(
BEHAVIOUR_NAME, ship.name, agent.credits, self.behaviour_params
)

target_wp = st.waypoints_view_one(self.target_wp_s)
if not target_wp:
self.st.sleep(SAFETY_PADDING)
Expand All @@ -67,6 +81,6 @@ def run(self):
ship = f"{agent}-{ship_number}"
behaviour_params = {"asteroid_wp": "X1-RV57-69965Z"}
bhvr = ChillAndSurvey(agent, ship, behaviour_params or {})
lock_ship(ship_number, "MANUAL", bhvr.st.db_client.connection, 60 * 24)
lock_ship(ship_number, "MANUAL", 60 * 24)
bhvr.run()
lock_ship(ship_number, "MANUAL", bhvr.st.db_client.connection, 0)
lock_ship(ship_number, "MANUAL", 0)
6 changes: 6 additions & 0 deletions behaviours/construct_a_jumpgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def run(self):
self._run()
self.end()

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["asteroid_wp"] = "X1-TEST-AB12"

return return_obj

def _run(self):
st = self.st
ship = self.ship
Expand Down
8 changes: 8 additions & 0 deletions behaviours/emergency_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(

def run(self):
super().run()
self.sleep_until_ready()
self.st.logging_client.log_beginning(
BEHAVIOUR_NAME,
self.ship.name,
Expand All @@ -60,6 +61,13 @@ def run(self):
self._run()
self.end()

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["asteroid_wp"] = "X1-TEST-GAS1"
return_obj["sell_wp"] = "X1-TEST-KMKT"

return return_obj

def _run(self):
st = self.st
ship = self.ship # = st.ships_view_one(self.ship_name, True)
Expand Down
8 changes: 8 additions & 0 deletions behaviours/evolve_supply_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ def __init__(
self.markets = {}
self.tg_s_markets = {}

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["target_tradegoods"] = ["CLOTHING", "FOOD"]
return_obj["max_tv"] = 180

return return_obj

def run(self):
super().run()
self.ship = self.st.ships_view_one(self.ship_name)
self.sleep_until_ready()
self.st.logging_client.log_beginning(
Expand Down
29 changes: 19 additions & 10 deletions behaviours/explore_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,27 @@ def __init__(

def run(self):
super().run()
ship = self.ship
st = self.st
agent = st.view_my_self()
# check all markets in the system
st.logging_client.log_beginning(
self.sleep_until_ready()
self.st.logging_client.log_beginning(
BEHAVIOUR_NAME,
ship.name,
agent.credits,
self.ship.name,
self.agent.credits,
behaviour_params=self.behaviour_params,
)
self._run()
self.end()

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["target_sys"] = "X1-BC28"

self.sleep_until_arrived()
return return_obj

def _run(self):
ship = self.ship
st = self.st
agent = st.view_my_self()
# check all markets in the system
o_sys = st.systems_view_one(ship.nav.system_symbol)

path = None
Expand Down Expand Up @@ -141,8 +150,8 @@ def find_unexplored_jumpgate(self):
behaviour_params = {"priority": 3.5, "target_sys": "X1-BC28"} # X1-TF72 X1-YF83
bhvr = ExploreSystem(agent, ship, behaviour_params or {})

lock_ship(ship, "MANUAL", bhvr.connection, duration=120)
lock_ship(ship, "MANUAL", duration=120)
set_logging(logging.DEBUG)

bhvr.run()
lock_ship(ship, "", bhvr.connection, duration=0)
lock_ship(ship, "", duration=0)
24 changes: 22 additions & 2 deletions behaviours/extract_and_chill.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,28 @@ def __init__(
self.cargo_to_target = self.behaviour_params.get("cargo_to_transfer", None)
self.cargo_to_jettison = self.behaviour_params.get("cargo_to_jettison", [])

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["cargo_to_transfer"] = ["*"]
return_obj["cargo_to_jettison"] = []

return return_obj

def run(self):
super().run()
self.ship = self.st.ships_view_one(self.ship_name)
self.sleep_until_ready()
self.st.logging_client.log_beginning(
BEHAVIOUR_NAME,
self.ship.name,
self.agent.credits,
behaviour_params=self.behaviour_params,
)

self._run()
self.end()

def _run(self):
# all threads should have this.

starting_credts = self.agent.credits
Expand Down Expand Up @@ -121,7 +141,7 @@ def run(self):
set_logging(logging.DEBUG)
behaviour_params = {"asteroid_wp": "X1-YG29-C39", "cargo_to_transfer": ["*"]}
bhvr = ExtractAndChill(agent, ship, behaviour_params)
lock_ship(ship, "MANUAL", bhvr.connection, duration=120)
lock_ship(ship, "MANUAL", duration=120)
set_logging(logging.DEBUG)
bhvr.run()
lock_ship(ship, "", bhvr.connection, duration=0)
lock_ship(ship, "", duration=0)
21 changes: 21 additions & 0 deletions behaviours/extract_and_fulfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,29 @@ def __init__(
)
self.logger = logging.getLogger("bhvr_extract_and_transfer")

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["asteroid_wp"] = "X1-TEST-AB12"
return_obj["cargo_to_transfer"] = ["*"]
return_obj["fulfil_wp"] = "X1-TEST-AB12"

return return_obj

def run(self):
super().run()
self.ship = self.st.ships_view_one(self.ship_name)
self.sleep_until_ready()
self.st.logging_client.log_beginning(
BEHAVIOUR_NAME,
self.ship.name,
self.agent.credits,
behaviour_params=self.behaviour_params,
)

self._run()
self.end()

def _run(self):
starting_credts = self.st.view_my_self().credits

st = self.st
Expand Down
19 changes: 19 additions & 0 deletions behaviours/extract_and_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,28 @@ def __init__(
)
self.logger = logging.getLogger("bhvr_extract_and_transfer")

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["asteroid_wp"] = "X1-TEST-AB12"
return_obj["cargo_to_transfer"] = ["*"]

return return_obj

def run(self):
super().run()
self.ship = self.st.ships_view_one(self.ship_name)
self.sleep_until_ready()
self.st.logging_client.log_beginning(
BEHAVIOUR_NAME,
self.ship.name,
self.agent.credits,
behaviour_params=self.behaviour_params,
)

self._run()
self.end()

def _run(self):
starting_credts = self.st.view_my_self().credits
# self.logger.info("NEEDLESS REQUEST - get inventory into DB")

Expand Down
3 changes: 3 additions & 0 deletions behaviours/generic_behaviour.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def run(self):

pass

def default_params_obj(self):
return {"priority": 5, "delay_start": 0}

def find_nearest_systems_by_waypoint_trait(
self,
source_system: System,
Expand Down
38 changes: 28 additions & 10 deletions behaviours/go_and_buy_a_ship.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,38 @@ def __init__(
connection,
)

self.target_ship_type = self.behaviour_params.get("ship_type", None)
self.target_wp = self.behaviour_params.get("target_wp", None)

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["ship_type"] = "SHIP_PROBE"
return_obj["target_wp"] = "X1-TEST-A2"

return return_obj

def run(self):
super().run()
st = self.st
ship = self.ship
agent = st.view_my_self()
st.logging_client.log_beginning(
self.ship = self.st.ships_view_one(self.ship_name)
self.sleep_until_ready()
self.st.logging_client.log_beginning(
BEHAVIOUR_NAME,
ship.name,
agent.credits,
self.ship.name,
self.agent.credits,
behaviour_params=self.behaviour_params,
)

target_ship_type = self.behaviour_params.get("ship_type", None)
target_wp = self.behaviour_params.get("target_wp", None)
self._run()
self.end()

def _run(self):
st = self.st
ship = self.ship
agent = st.view_my_self()

target_ship_type = self.target_ship_type
target_wp = self.target_wp

if target_wp:
target_wp = st.waypoints_view_one(target_wp)
elif not target_wp:
Expand Down Expand Up @@ -112,6 +130,6 @@ def find_shipyards(self, ship_symbol):
ship = f"{agent}-{ship_number}"
behaviour_params = {"ship_type": "SHIP_PROBE", "target_wp": "X1-GU20-C37"}
bhvr = GoAndBuyShip(agent, ship, behaviour_params or {})
lock_ship(ship, "MANUAL", bhvr.st.db_client.connection, 60 * 24)
lock_ship(ship, "MANUAL", 60 * 24)
bhvr.run()
lock_ship(ship, "MANUAL", bhvr.st.db_client.connection, 0)
lock_ship(ship, "MANUAL", 0)
7 changes: 7 additions & 0 deletions behaviours/manage_specific_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ def __init__(
self.starting_market_wp = None
self.markets = {}

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["target_tradegood"] = "FUEL"
return_obj["market_wp"] = "X1-TEST-A1"

return return_obj

def run(self):
super().run()
self.st.logging_client.log_beginning(
Expand Down
Loading

0 comments on commit 2180a4f

Please sign in to comment.