Skip to content

Commit

Permalink
Track cargo ejection for thargoid S&R, avoiding mis-tallying after ej…
Browse files Browse the repository at this point in the history
…ection. Fixes #140.
  • Loading branch information
aussig committed Sep 27, 2023
1 parent de4b4a8 commit 7aba391
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* Trade purchase is now reported in three brackets rather than two: 🅻 | 🅼 | 🅷
* Automatically attempt to track megaship scenarios. As with Ground CZs, the game doesn't give us enough information to detect whether you've actually **won** the scenario, so if you drop in and log a kill within 5 minutes, this is tallied as a win for the faction that's at war with the first ship you kill.

### Bug Fixes:

* Now handles cargo ejection for Thargoid S&R operations. Previously, it could mis-tally to the wrong system because it hadn't realised the cargo scooped in that system had been destroyed by ejection.


## v3.2.0-a2 - 2023-09-10

Expand Down
27 changes: 22 additions & 5 deletions bgstally/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def trade_sold(self, journal_entry:dict, state:State):
# Handle SandR tissue samples first
cargo_type:str = journal_entry.get('Type', "").lower()
if 'thargoidtissuesample' in cargo_type or 'thargoidscouttissuesample' in cargo_type:
self._search_and_rescue_handin('t', journal_entry.get('Count', 0))
self._search_and_rescue_handin('t', journal_entry.get('Count', 0), True)
# Fall through to BGS tracking for standard trade sale

faction = current_system['Factions'].get(state.station_faction)
Expand Down Expand Up @@ -837,6 +837,23 @@ def collect_cargo(self, journal_entry: dict, state: State):
self.dirty = True


def eject_cargo(self, journal_entry: dict):
"""
Handle cargo ejection for certain cargo types
"""
key:str = None

match journal_entry.get('Type', "").lower():
case 'damagedescapepod': key = 'dp'
case 'occupiedcryopod': key = 'op'
case 'usscargoblackbox': key = 'bb'
case _ as cargo_type if "thargoidtissuesample" in cargo_type or "thargoidscouttissuesample" in cargo_type: key = 't'

if key is None: return

self._search_and_rescue_handin(key, journal_entry.get('Count', 0), False)


def search_and_rescue(self, journal_entry: dict, state: State):
"""
Handle search and rescue hand-in
Expand All @@ -852,10 +869,10 @@ def search_and_rescue(self, journal_entry: dict, state: State):

if key is None or count == 0: return

self._search_and_rescue_handin(key, count)
self._search_and_rescue_handin(key, count, True)


def _search_and_rescue_handin(self, key:str, count:int):
def _search_and_rescue_handin(self, key:str, count:int, tally:bool):
"""
Tally a search and rescue handin. These can originate from SearchAndRescue or TradeSell events
"""
Expand All @@ -870,11 +887,11 @@ def _search_and_rescue_handin(self, key:str, count:int):
allocatable:int = min(count, system['TWSandR'][key]['scooped'])
if allocatable > 0:
system['TWSandR'][key]['scooped'] -= allocatable
system['TWSandR'][key]['delivered'] += allocatable
if tally: system['TWSandR'][key]['delivered'] += allocatable
count -= allocatable
self.dirty = True

self.bgstally.ui.show_system_report(system['SystemAddress'])
if tally: self.bgstally.ui.show_system_report(system['SystemAddress'])

# count can end up > 0 here - i.e. more S&R handed in than we originally logged as scooped. Ignore, as we don't know
# where it originally came from
Expand Down
4 changes: 4 additions & 0 deletions bgstally/bgstally.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def journal_entry(self, cmdr, is_beta, system, station, entry, state):
self.state.station_type = entry['StationType']
dirty = True

case 'EjectCargo':
activity.eject_cargo(entry)
dirty = True

case 'FactionKillBond' if state['Odyssey']:
activity.cb_received(entry, self.state)
dirty = True
Expand Down

0 comments on commit 7aba391

Please sign in to comment.