Skip to content

Commit

Permalink
Merge pull request #430 from lekeno/explocash
Browse files Browse the repository at this point in the history
Explocash
  • Loading branch information
lekeno authored Mar 5, 2022
2 parents e61b332 + e2b001e commit c3ded32
Show file tree
Hide file tree
Showing 10 changed files with 1,120 additions and 496 deletions.
6 changes: 3 additions & 3 deletions edr/edrbodiesofinterest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def points_of_interest(star_system, body_name):
if not star_system or not body_name:
return None
c_star_system = star_system.lower()
c_body_name = EDRBodiesOfInterest.__simplified_body_name(star_system, body_name)
c_body_name = EDRBodiesOfInterest.simplified_body_name(star_system, body_name)
return EDRBodiesOfInterest.BOI.get(c_star_system, {}).get(c_body_name, None)

@staticmethod
Expand All @@ -42,9 +42,9 @@ def closest_point_of_interest(star_system, body_name, attitude, planet_radius):


@staticmethod
def __simplified_body_name(star_system, body_name):
def simplified_body_name(star_system, body_name, empty_name_overrider=None):
if body_name.lower().startswith(star_system.lower()):
# Example: Pleione A 1 A => a 1 a
# Remove prefix + space
return body_name[len(star_system)+1:].lower()
return body_name[len(star_system)+1:].lower() or (empty_name_overrider if empty_name_overrider else body_name)
return body_name.lower()
133 changes: 118 additions & 15 deletions edr/edrclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import datetime
from sys import float_repr_style
import sys
import time
import random
import math
Expand Down Expand Up @@ -548,7 +549,7 @@ def noteworthy_about_system(self, fsdjump_event):
header = _('Noteworthy stellar bodies in {}').format(fsdjump_event['StarSystem'])

if not facts:
if self.player.in_bad_neighborhood() and (self.edrsystems.in_bubble(self.player.star_system) or self.edrsystems.in_colonia(self.player.star_system)):
if self.player.in_bad_neighborhood() and (self.edrsystems.in_bubble(self.player.star_system, 700) or self.edrsystems.in_colonia(self.player.star_system, 350)):
header = _(u"Anarchy system")
facts = [_(u"Crimes will not be reported.")]
else:
Expand All @@ -569,14 +570,44 @@ def noteworthy_about_body(self, star_system, body_name):
self.__notify(_(u'{} material densities on {}').format(qualifier, body_name), facts, clear_before = True)

def noteworthy_about_scan(self, scan_event):
if scan_event["event"] != "Scan" or scan_event["ScanType"] != "Detailed":
if scan_event["event"] != "Scan" or not scan_event["ScanType"] in ["Detailed", "Basic", "AutoScan"]:
return
if "Materials" not in scan_event or "BodyName" not in scan_event:

if "BodyName" not in scan_event:
return
facts = self.edrresourcefinder.assess_materials_density(scan_event["Materials"], self.player.inventory)

header = _(u'Noteworthy about {}').format(scan_event["BodyName"])
facts = []
if scan_event["BodyName"]:
star_system = scan_event.get("StarSystem", self.player.star_system)
value = self.edrsystems.body_value(star_system, scan_event["BodyName"])
if value:
flags = []
if "wasDiscovered" in value:
flags.append(_(u"[KNOWN]") if value["wasDiscovered"] else _(u"[FIRST DISCOVERED]"))

if "wasMapped" in value and "PlanetClass" in scan_event:
flags.append(_(u"[CHARTED]") if value["wasMapped"] else _(u"[UNCHARTED]"))

if value.get("wasEfficient", False):
flags.append(_(u"[EFF. BONUS]"))

flags = " ".join(flags)
if pretty_print_number(value["valueMax"]) != pretty_print_number(value["valueScanned"]):
facts.append(_("Estimated value: {} cr (mapped: {}) @ {} LS; {}").format(pretty_print_number(value["valueScanned"]), pretty_print_number(value["valueMax"]), pretty_print_number(value["distance"]), flags))
else:
facts.append(_("Estimated value: {} cr @ {} LS; {}").format(pretty_print_number(value["valueMax"]), pretty_print_number(value["distance"]), flags))

if "Materials" in scan_event:
mats_assessment = self.edrresourcefinder.assess_materials_density(scan_event["Materials"], self.player.inventory)
if mats_assessment:
facts.extend(mats_assessment)
qualifier = self.edrresourcefinder.raw_profile
if qualifier:
header = _(u'Noteworthy about {} ({} mats)').format(scan_event["BodyName"], qualifier)

if facts:
qualifier = self.edrresourcefinder.raw_profile or _("Noteworthy")
self.__notify(_(u'{} material densities on {}').format(qualifier, scan_event["BodyName"]), facts, clear_before = True)
self.__notify(header, facts, clear_before = True)


def register_fss_signals(self, system_address=None, override_star_system=None, force_reporting=False):
Expand All @@ -588,7 +619,9 @@ def register_fss_signals(self, system_address=None, override_star_system=None, f
new_fc = self.edrfssinsights.newly_found_fleet_carriers()
if new_fc:
# Report new FC to help with CG (e.g. unloading/loading commodities from newly arrived FC)
self.notify_with_details(_(u"{} newly arrived fleet carriers").format(len(new_fc)), ["{} : {}".format(callsign, new_fc[callsign]) for callsign in new_fc])
# TODO this one gets in the way of the system value notification...
# self.notify_with_details(_(u"Discovered {} fleet carriers").format(len(new_fc)), ["{} : {}".format(callsign, new_fc[callsign]) for callsign in new_fc])
pass
return
fc_report = self.edrfssinsights.fleet_carriers_report(force_reporting)
if fc_report is not None:
Expand Down Expand Up @@ -690,6 +723,7 @@ def destination_guidance(self, destination):
return

# check if body > 0 ?
# TODO value of system if different system
if self.body_guidance(self.player.star_system, name, passive=True):
return

Expand All @@ -711,7 +745,77 @@ def destination_guidance(self, destination):
callsign = m.group(1)
self.fc_in_current_system(callsign)
return

def system_value(self, star_system=None):
# avoid belts since it's noisy and worthless
if star_system is None:
star_system = self.player.star_system
sys_value = self.edrsystems.system_value(star_system)
if sys_value:
details = []
estimatedValue = pretty_print_number(sys_value["estimatedValue"]) if "estimatedValue" in sys_value else "?"
estimatedValueMapped = pretty_print_number(sys_value["estimatedValueMapped"]) if "estimatedValueMapped" in sys_value else "?"
if estimatedValueMapped != estimatedValue:
details.append(_("Scanned: {}, Mapped: {}").format(estimatedValue, estimatedValueMapped))
else:
details.append(_("Scanned: {}").format(estimatedValue))

valuableBodies = sorted(sys_value.get("valuableBodies", []), key=lambda b: b['valueMax'], reverse=True)

first_disco = 0
first_map = 0
top = 5
extra_details = []
for body in valuableBodies:
adjBodyName = EDRBodiesOfInterest.simplified_body_name(star_system, body.get("bodyName", "?"), " 0")
flags = []
if "wasDiscovered" in body and body["wasDiscovered"] == False:
first_disco += 1
if top:
flags.append(_(u"[FIRST SCAN]") if body.get("scanned", False) else _(u"[UNKNOWN]"))

if "wasMapped" in body and body["wasMapped"] == False and body.get("type", "") == "planet":
first_map += 1
if top:
flags.append(_(u"[FIRST MAP]") if body.get("mapped", False) else _(u"[UNCHARTED]"))

if top <= 0:
continue

flags = " ".join(flags)
if pretty_print_number(body["valueMax"]) != pretty_print_number(body["valueScanned"]):
extra_details.append(_("{}: {} (mapped: {}) @ {} LS {}").format(adjBodyName, pretty_print_number(body["valueScanned"]), pretty_print_number(body["valueMax"]), pretty_print_number(body["distance"]), flags))
else:
extra_details.append(_("{}: {} @ {} LS {}").format(adjBodyName, pretty_print_number(body["valueScanned"]), pretty_print_number(body["distance"]), flags))
top -= 1

# TODO l10n
firsts = ""
if first_disco or first_map:
if first_disco and first_map:
firsts = _("Unknown: {}, Uncharted: {}").format(first_disco, first_map)
elif first_disco:
firsts = _("Unknown: {}").format(first_disco)
else:
firsts = _("Uncharted: {}").format(first_map)
if "progress" in sys_value and sys_value["progress"] < 1.0 and sys_value.get("bodyCount", None):
body_count = sys_value["bodyCount"]
scanned_body_count = round(body_count * sys_value["progress"])
progress = int(sys_value["progress"]*100.0)
details.append(_("Discovered {}/{} {}% {}").format(scanned_body_count, body_count, progress, firsts))
elif first_disco or first_map:
details.append(firsts)

details.extend(extra_details)
self.__notify(_("Estimated value of {}").format(star_system), details, clear_before= True)

def saa_scan_complete(self, entry):
self.edrsystems.saa_scan_complete(self.player.star_system, entry)

def reflect_fss_discovery_scan(self, entry):
self.edrsystems.fss_discovery_scan_update(entry)



def show_navigation(self):
current = self.player.attitude
Expand All @@ -734,7 +838,7 @@ def show_navigation(self):
EDRLOG.log(u"No distance info out of System:{}, Body:{}, Place: {}, Radius:{}".format(location.star_system, location.body, location.place, radius), "DEBUG")
return

threshold = 1.0
threshold = 0.25
if self.player.piloted_vehicle is None:
threshold = 0.001
elif EDVehicleFactory.is_surface_vehicle(self.player.piloted_vehicle):
Expand Down Expand Up @@ -923,7 +1027,7 @@ def eval_backpack(self, passive=False):
if micro_resources:
details = self.__eval_micro_resources(micro_resources, from_backpack=True)
if details:
self.__notify("Backpack assessment", details, clear_before=True)
self.__notify(_("Backpack assessment"), details, clear_before=True)
elif not passive:
self.__notify(_("Backpack assessment"), [_(u"Nothing superfluous")], clear_before = True)
elif not passive:
Expand Down Expand Up @@ -1278,7 +1382,7 @@ def distance(self, from_system, to_system):
else:
self.status = _(u"distance failed")
details.append(_(u"Couldn't calculate a distance. Invalid or unknown system names?"))
self.__notify("Distance", details, clear_before = True)
self.__notify(_("Distance"), details, clear_before = True)


def blip(self, cmdr_name, blip):
Expand Down Expand Up @@ -2121,7 +2225,7 @@ def station_in_current_system(self, station_name, passive=False):
return True

def system_guidance(self, system_name, passive=False):
description = self.edrsystems.describe_system(system_name)
description = self.edrsystems.describe_system(system_name, self.player.star_system == system_name)
if not description:
if not passive:
self.__notify(_(u"EDR System Search"), [_("No info on System called {}").format(system_name)], clear_before=True)
Expand All @@ -2132,7 +2236,7 @@ def system_guidance(self, system_name, passive=False):
return True

def body_guidance(self, system_name, body_name, passive=False):
description = self.edrsystems.describe_body(system_name, body_name)
description = self.edrsystems.describe_body(system_name, body_name, self.player.star_system == system_name)
if not description:
if not passive:
self.__notify(_(u"EDR System Search"), [_("No info on Body called {}").format(body_name)], clear_before=True)
Expand Down Expand Up @@ -2309,10 +2413,9 @@ def configure_resourcefinder(self, raw_profile):
return result

def show_material_profiles(self):
# TODO clear before, also on the other material profile things
# TODO fsd profiles for instnace returns a ton of stuff...
# TODO verify clear before
profiles = self.edrresourcefinder.profiles()
self.__notify(_(u"Available materials profiles"), [" ;; ".join(profiles)])
self.__notify(_(u"Available materials profiles"), [" ;; ".join(profiles)], clear_before=True)

def search_resource(self, resource, star_system):
if not star_system:
Expand Down
1 change: 0 additions & 1 deletion edr/edrdiscord.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def __init__(self):
def json(self):
base = self.__dict__
base["embeds"] = [ embed.json() for embed in self.embeds]
# TODO files
return base

def valid(self):
Expand Down
23 changes: 5 additions & 18 deletions edr/edrfssinsights.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def __init__(self):
self.noteworthy = False
self.processed = 0
self.reported = False
print("init fss insights")
self.signals_seen = []

def reset(self, override_timestamp=None):
Expand All @@ -65,7 +64,7 @@ def reset(self, override_timestamp=None):

self.stations = set()
self.fleet_carriers = {}
self.recent_fleet_carriers
self.recent_fleet_carriers = {}
self.other_locations = set()
if override_timestamp:
self.timestamp.from_journal_timestamp(override_timestamp)
Expand All @@ -77,22 +76,19 @@ def reset(self, override_timestamp=None):
self.noteworthy = False
self.processed = 0
self.reported = False
print("reset fss insights")
self.signals_seen = []

def related_to(self, current_star_system):
return (self.star_system["name"] is None) or current_star_system == self.star_system["name"]

def update(self, current_star_system):
if current_star_system != self.star_system["name"]:
print("update")
self.reset()
self.star_system["address"] = None
self.star_system["name"] = None

def update_system(self, system_address, system_name):
if not self.same_system(system_address):
print("not same system")
self.reset()
self.star_system["address"] = system_address
if system_name is not None:
Expand All @@ -105,12 +101,10 @@ def same_system(self, system_address):
def process(self, fss_event):
system_address = fss_event.get("SystemAddress", None)
if system_address is None:
print("system address is none")
self.reset()
return False

if system_address != self.star_system["address"]:
print("system address is different {} vs {}".format(system_address, self.star_system["address"]))
self.reset(fss_event["timestamp"])
self.star_system["address"] = system_address
self.star_system["name"] = None
Expand All @@ -132,8 +126,7 @@ def __process(self, fss_event):
return False

self.signals_seen.append(signal_name)
print(self.signals_seen)


if fss_event.get("SignalName_Localised", None) is None:
self.__process_locations_fss(fss_event)
self.noteworthy = True
Expand Down Expand Up @@ -240,16 +233,16 @@ def summarize(self):

landables = []
if self.stations:
landables.append("Stations: {}".format(len(self.stations)))
landables.append(_("Stations: {}").format(len(self.stations)))

if self.fleet_carriers:
landables.append("FC: {}".format(len(self.fleet_carriers)))
landables.append(_("FC: {}").format(len(self.fleet_carriers)))

if landables:
summary.append("; ".join(landables))

if self.other_locations:
summary.append("Misc.: {}".format(len(self.other_locations)))
summary.append(_("Misc.: {}").format(len(self.other_locations)))

return summary

Expand Down Expand Up @@ -294,8 +287,6 @@ def fuzzy_match_fleet_carriers(self, callsign_or_name):
return {c: self.fleet_carriers[c] for c in self.fleet_carriers if (callsign_or_name.lower() in c.lower() or callsign_or_name.lower() in self.fleet_carriers[c].lower())}

def is_signal(self, name):
print("signals seen")
print(self.signals_seen)
return (name in self.signals_seen) or self.is_scenario_signal(name)

def no_signals(self):
Expand All @@ -305,10 +296,6 @@ def is_scenario_signal(self, name):
return bool(re.search('^\$[ -~]+;$', name))

def is_station(self, name):
print("is station?")
print(name)
print(self.stations)
# TODO some stations are not marked as IStation=True :/ (e.g outpost? and planetary things are not in the FSS stuff)
return name in self.stations

def is_main_star(self, name):
Expand Down
2 changes: 1 addition & 1 deletion edr/edrserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __get(self, endpoint, service, params=None, headers=None, attempts=3):
return EDRServer.SESSION.get(endpoint, params=params, headers=headers)
except requests.exceptions.RequestException as e:
last_connection_exception = e
EDRLOG.log(u"ConnectionException {} for GET EDR: attempts={}}".format(e, attempts), u"WARNING")
EDRLOG.log(u"ConnectionException {} for GET EDR: attempts={}".format(e, attempts), u"WARNING")
raise last_connection_exception

def __put(self, endpoint, service, json, params=None, headers=None, attempts=3):
Expand Down
1 change: 0 additions & 1 deletion edr/edrservicefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def nearby(self):
candidates = self.__search(systems, candidates)
if not (candidates and candidates.get('prime', None)):
EDRLOG.log(u"Couldn't find any prime candidate so far. Trying again after a shuffle", "DEBUG")
# TODO check colonia commands
shuffle(systems)
candidates = self.__search(systems, candidates)

Expand Down
Loading

0 comments on commit c3ded32

Please sign in to comment.