fix display campaign NP draw/break in participant table

This commit is contained in:
Maxime Réaux 2026-03-05 11:37:14 +01:00
parent 03f0e048af
commit b1bde76319
3 changed files with 22 additions and 35 deletions

View file

@ -67,7 +67,7 @@ class CampaignController:
for obj in war.get_all_objectives(): for obj in war.get_all_objectives():
objective_icon_maps[obj.id] = RankingIcon.compute_icons( objective_icon_maps[obj.id] = RankingIcon.compute_icons(
war, war,
ContextType.CAMPAIGN, ContextType.OBJECTIVE,
f"{camp.id}:{obj.id}", f"{camp.id}:{obj.id}",
scores, scores,
objective_id=obj.id, objective_id=obj.id,
@ -201,6 +201,7 @@ class CampaignController:
context_name=objective.name, context_name=objective.name,
) )
if not dialog.exec(): if not dialog.exec():
# FIXME lost tokens used for narrative tie-break (ContextType.OBJECTIVE)
TieResolver.cancel_tie_break( TieResolver.cancel_tie_break(
war, ContextType.CAMPAIGN, ctx.context_id, ctx.score_value war, ContextType.CAMPAIGN, ctx.context_id, ctx.score_value
) )

View file

@ -63,7 +63,7 @@ class WarController:
for obj in war.get_all_objectives(): for obj in war.get_all_objectives():
objective_icon_maps[obj.id] = RankingIcon.compute_icons( objective_icon_maps[obj.id] = RankingIcon.compute_icons(
war, war,
ContextType.WAR, ContextType.OBJECTIVE,
f"{war.id}:{obj.id}", f"{war.id}:{obj.id}",
scores, scores,
objective_id=obj.id, objective_id=obj.id,
@ -188,6 +188,7 @@ class WarController:
context_name=objective.name, context_name=objective.name,
) )
if not dialog.exec(): if not dialog.exec():
# FIXME lost tokens used for narrative tie-break (ContextType.OBJECTIVE)
TieResolver.cancel_tie_break( TieResolver.cancel_tie_break(
war, ContextType.WAR, ctx.context_id, ctx.score_value war, ContextType.WAR, ctx.context_id, ctx.score_value
) )

View file

@ -91,28 +91,25 @@ class TieResolver:
campaign_id: str, campaign_id: str,
objective_id: str, objective_id: str,
) -> List[TieContext]: ) -> List[TieContext]:
base_scores = ScoreService.compute_scores( scores = ScoreService.compute_scores(
war, war,
ContextType.CAMPAIGN, ContextType.CAMPAIGN,
campaign_id, campaign_id,
) )
scores = TieResolver._build_objective_scores(
base_scores,
objective_id,
)
buckets: DefaultDict[int, List[str]] = defaultdict(list) buckets: DefaultDict[int, List[str]] = defaultdict(list)
for pid, score in scores.items(): for pid, score in scores.items():
buckets[score.victory_points].append(pid) np_value = score.narrative_points.get(objective_id, 0)
buckets[np_value].append(pid)
ties: List[TieContext] = [] ties: List[TieContext] = []
context_id = f"{campaign_id}:{objective_id}" context_id = f"{campaign_id}:{objective_id}"
for score_value, participants in buckets.items(): for np_value, participants in buckets.items():
if len(participants) <= 1: if len(participants) <= 1:
continue continue
if TieResolver.is_tie_resolved( if TieResolver.is_tie_resolved(
war, war,
ContextType.OBJECTIVE, ContextType.OBJECTIVE,
context_id, context_id,
score_value, np_value,
): ):
continue continue
if not TieResolver.can_tie_be_resolved( if not TieResolver.can_tie_be_resolved(
@ -126,7 +123,7 @@ class TieResolver:
None, None,
ContextType.OBJECTIVE, ContextType.OBJECTIVE,
context_id, context_id,
score_value, np_value,
) )
) )
continue continue
@ -135,7 +132,7 @@ class TieResolver:
context_type=ContextType.OBJECTIVE, context_type=ContextType.OBJECTIVE,
context_id=context_id, context_id=context_id,
participants=participants, participants=participants,
score_value=score_value, score_value=np_value,
) )
) )
return ties return ties
@ -181,33 +178,33 @@ class TieResolver:
) -> List[TieContext]: ) -> List[TieContext]:
from warchron.model.result_checker import ResultChecker from warchron.model.result_checker import ResultChecker
base_scores = ScoreService.compute_scores( scores = ScoreService.compute_scores(
war, war,
ContextType.WAR, ContextType.WAR,
war.id, war.id,
) )
scores = TieResolver._build_objective_scores(
base_scores, def value_getter(score: ParticipantScore) -> int:
objective_id, return score.narrative_points.get(objective_id, 0)
)
ranking = ResultChecker.get_effective_ranking( ranking = ResultChecker.get_effective_ranking(
war, war,
ContextType.OBJECTIVE, ContextType.OBJECTIVE,
f"{war.id}:{objective_id}", f"{war.id}:{objective_id}",
scores, scores,
value_getter=lambda s: s.narrative_points.get(objective_id, 0), value_getter=value_getter,
) )
ties: List[TieContext] = [] ties: List[TieContext] = []
for _, group, _ in ranking: for _, group, _ in ranking:
if len(group) <= 1: if len(group) <= 1:
continue continue
score_value = scores[group[0]].victory_points np_value = value_getter(scores[group[0]])
context_id = f"{war.id}:{objective_id}" context_id = f"{war.id}:{objective_id}"
if TieResolver.is_tie_resolved( if TieResolver.is_tie_resolved(
war, war,
ContextType.OBJECTIVE, ContextType.OBJECTIVE,
context_id, context_id,
score_value, np_value,
): ):
continue continue
if not TieResolver.can_tie_be_resolved( if not TieResolver.can_tie_be_resolved(
@ -221,7 +218,7 @@ class TieResolver:
None, None,
ContextType.OBJECTIVE, ContextType.OBJECTIVE,
context_id, context_id,
score_value, np_value,
) )
) )
continue continue
@ -230,24 +227,11 @@ class TieResolver:
context_type=ContextType.OBJECTIVE, context_type=ContextType.OBJECTIVE,
context_id=context_id, context_id=context_id,
participants=group, participants=group,
score_value=score_value, score_value=np_value,
) )
) )
return ties return ties
@staticmethod
def _build_objective_scores(
base_scores: Dict[str, ParticipantScore],
objective_id: str,
) -> Dict[str, ParticipantScore]:
return {
pid: ParticipantScore(
victory_points=score.narrative_points.get(objective_id, 0),
narrative_points={},
)
for pid, score in base_scores.items()
}
@staticmethod @staticmethod
def apply_bids( def apply_bids(
war: War, war: War,
@ -269,6 +253,7 @@ class TieResolver:
) )
) )
# FIXME lost tokens used for narrative tie-break (ContextType.OBJECTIVE)
@staticmethod @staticmethod
def cancel_tie_break( def cancel_tie_break(
war: War, war: War,