Skip to content

Commit

Permalink
Proper powerplay enemy check
Browse files Browse the repository at this point in the history
See issue #157
  • Loading branch information
lekeno committed Jun 6, 2018
1 parent 760de59 commit 0ef83fb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
14 changes: 13 additions & 1 deletion edr/edentities.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,30 @@ def __init__(self, pledged_to, time_pledged):
def is_enemy(self, power):
POWERS_AFFILIATION = {
"a_lavigny-duval": "Empire",
"arissa lavigny duval": "Empire",
"aisling_duval": "Empire",
"aisling duval": "Empire",
"archon_delaine": None,
"archon delaine": None,
"denton_patreus": "Empire",
"denton patreus": "Empire",
"edmund_mahon": "Alliance",
"edmund mahon": "Alliance",
"felicia_winters": "Federation",
"felicia winters": "Federation",
"li_yong-rui": None,
"li yong-rui": None,
"pranav_antal": None,
"pranav antal": None,
"yuri_grom": None,
"yuri grom": None,
"zachary_hudson": "Federation",
"zemina_torval": "Empire",
"zachary hudson": "Federation",
"zemina_torval": "Empire",
"zemina torval": "Empire",
}

power = power.lower()
if not (self.pledged_to in POWERS_AFFILIATION and power in POWERS_AFFILIATION):
return False
my_affiliation = POWERS_AFFILIATION[self.pledged_to]
Expand Down
22 changes: 11 additions & 11 deletions edr/edrclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,12 @@ def who(self, cmdr_name, autocreate=False):
profile = self.cmdr(cmdr_name, autocreate, check_inara_server=True)
if profile:
self.status = _(u"got info about {}").format(cmdr_name)
EDRLOG.log(u"Who {} : {}".format(cmdr_name, profile.short_profile()), "INFO")
EDRLOG.log(u"Who {} : {}".format(cmdr_name, profile.short_profile(self.player.powerplay)), "INFO")
legal = self.edrlegal.summarize_recents(profile.cid)
if legal:
self.__intel(cmdr_name, [profile.short_profile(), legal])
self.__intel(cmdr_name, [profile.short_profile(self.player.powerplay), legal])
else:
self.__intel(cmdr_name, [profile.short_profile()])
self.__intel(cmdr_name, [profile.short_profile(self.player.powerplay)])
else:
EDRLOG.log(u"Who {} : no info".format(cmdr_name), "INFO")
self.__intel(cmdr_name, [_("No info about {cmdr}").format(cmdr=cmdr_name)])
Expand All @@ -636,12 +636,12 @@ def blip(self, cmdr_name, blip):
return

profile = self.cmdr(cmdr_name, check_inara_server=True)
if profile and (self.player.name != cmdr_name) and profile.is_dangerous(self.player.power):
if profile and (self.player.name != cmdr_name) and profile.is_dangerous(self.player.powerplay):
self.status = _(u"{} is bad news.").format(cmdr_name)
if self.novel_enough_blip(cmdr_id, blip, cognitive = True):
self.__warning(_(u"Warning!"), [profile.short_profile()])
self.__warning(_(u"Warning!"), [profile.short_profile(self.player.powerplay)])
self.cognitive_blips_cache.set(cmdr_id, blip)
if self.is_anonymous() and profile.is_dangerous():
if self.is_anonymous() and profile.is_dangerous(self.player.powerplay):
self.advertise_full_account(_("You could have helped other EDR users by reporting this outlaw."))
elif self.is_anonymous():
self.advertise_full_account(_("You could have helped other EDR users by reporting this enemy."))
Expand Down Expand Up @@ -677,13 +677,13 @@ def scanned(self, cmdr_name, scan):
legal = self.edrlegal.summarize_recents(profile.cid)
bounty = edentities.EDBounty(scan["bounty"]) if scan["bounty"] else None
if profile and (self.player.name != cmdr_name):
if profile.is_dangerous(pledged_to=self.player.power):
if profile.is_dangerous(self.player.powerplay):
# Translators: this is shown via EDMC's EDR status line upon contact with a known outlaw
self.status = _(u"{} is bad news.").format(cmdr_name)
details = [profile.short_profile()]
details = [profile.short_profile(self.player.powerplay)]
status = ""
if scan["enemy"]:
status += _(u"Powerplay Enemy. ")
status += _(u"PP Enemy (weapons free). ")
if scan["bounty"]:
status += _(u"Wanted for {} cr").format(edentities.EDBounty(scan["bounty"]).pretty_print())
elif scan["wanted"]:
Expand All @@ -695,15 +695,15 @@ def scanned(self, cmdr_name, scan):
self.__warning(_(u"Warning!"), details)
elif self.intel_even_if_clean or (scan["wanted"] and bounty.is_significant()):
self.status = _(u"Intel for cmdr {}.").format(cmdr_name)
details = [profile.short_profile()]
details = [profile.short_profile(self.player.powerplay)]
if bounty:
details.append(_(u"Wanted for {} cr").format(edentities.EDBounty(scan["bounty"]).pretty_print()))
elif scan["wanted"]:
details.append(_(u"Wanted somewhere but it could be minor offenses."))
if legal:
details.append(legal)
self.__intel(_(u"Intel"), details)
if (self.is_anonymous() and (profile.is_dangerous() or (scan["wanted"] and bounty.is_significant()))):
if (self.is_anonymous() and (profile.is_dangerous(self.player.powerplay) or (scan["wanted"] and bounty.is_significant()))):
# Translators: this is shown to users who don't yet have an EDR account
self.advertise_full_account(_(u"You could have helped other EDR users by reporting this outlaw."))
elif self.is_anonymous() and scan["enemy"] and self.player.power:
Expand Down
18 changes: 12 additions & 6 deletions edr/edrcmdrprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,15 @@ def remove_memo(self):
self.dex_profile = None
return True

def is_dangerous(self, pledged_to=None):
def is_dangerous(self, powerplay=None):
if self.sqdrdex_profile:
return self.sqdrdex_profile._iff == "enemy"
if self.dex_profile:
return self.dex_profile._alignment == "outlaw"
if self._karma <= -250:
return True
if pledged_to and self.powerplay:
return pledged_to.lower() != self.powerplay.lower()
if powerplay and self.powerplay:
return powerplay.is_enemy(self.powerplay)
if self.alignment_hints and self.alignment_hints["outlaw"] > 0:
total_hints = sum([hints for hints in self.alignment_hints.values()])
return (total_hints > 10 and self.alignment_hints["outlaw"] / total_hints > .5)
Expand All @@ -357,7 +357,7 @@ def crowd_alignment(self):
return u"[!{} ?{} +{}]".format(self.alignment_hints["outlaw"], self.alignment_hints["neutral"], self.alignment_hints["enforcer"])
return u"[!{:.0%} ?{:.0%} +{:.0%}]".format(self.alignment_hints["outlaw"] / total_hints, self.alignment_hints["neutral"] / total_hints, self.alignment_hints["enforcer"] / total_hints)

def short_profile(self):
def short_profile(self, powerplay=None):
edr_parts = []
mapped_index = int(10*(self._karma + self.max_karma()) / (2.0*self.max_karma()))
lut = [_(u"Outlaw++++"), _(u"Outlaw+++"), _(u"Outlaw++"), _(u"Outlaw+"), _(u"Outlaw"), _(u"Neutral"), _(u"Enforcer"), _(u"Enforcer+"), _(u"Enforcer++"), _(u"Enforcer+++"), _(u"Enforcer++++")]
Expand All @@ -379,8 +379,11 @@ def short_profile(self):
if not (self.role is None or self.role == ""):
inara_parts.append(self.role)

powerplay_parts = []
if not (self.powerplay is None or self.powerplay == ""):
inara_parts.append(self.powerplay)
if powerplay and powerplay.is_enemy(self.powerplay):
powerplay_parts.append(_(u"powerplay|enemy"))

sqdex_parts = []
iff = self.sqdrdex_profile.iff if self.sqdrdex_profile else None
Expand Down Expand Up @@ -414,9 +417,12 @@ def short_profile(self):
result += u" ✪INR {}".format(", ".join(inara_parts))

if sqdex_parts:
result += u" ✪SDX {}".format(", ".join(sqdex_parts))
result += u" ✪SQN {}".format(", ".join(sqdex_parts))

if cdex_parts:
result += u" ✪CDX {}".format(", ".join(cdex_parts))
result += u" ✪CMD {}".format(", ".join(cdex_parts))

if powerplay_parts:
result += u" ✪PP {}".format(", ".join(powerplay_parts))

return result

0 comments on commit 0ef83fb

Please sign in to comment.