fix ignored campaign NP tie-break when closing war
This commit is contained in:
parent
b1bde76319
commit
72f80563f1
16 changed files with 314 additions and 219 deletions
|
|
@ -1,13 +1,9 @@
|
|||
from typing import List, Dict, Tuple, TYPE_CHECKING
|
||||
from typing import List, Dict, TYPE_CHECKING
|
||||
|
||||
from PyQt6.QtWidgets import QMessageBox, QDialog
|
||||
from PyQt6.QtGui import QIcon
|
||||
|
||||
from warchron.constants import (
|
||||
RefreshScope,
|
||||
ContextType,
|
||||
ItemType,
|
||||
)
|
||||
from warchron.constants import RefreshScope, ContextType, ItemType
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from warchron.controller.app_controller import AppController
|
||||
|
|
@ -67,8 +63,8 @@ class CampaignController:
|
|||
for obj in war.get_all_objectives():
|
||||
objective_icon_maps[obj.id] = RankingIcon.compute_icons(
|
||||
war,
|
||||
ContextType.OBJECTIVE,
|
||||
f"{camp.id}:{obj.id}",
|
||||
ContextType.CAMPAIGN,
|
||||
camp.id,
|
||||
scores,
|
||||
objective_id=obj.id,
|
||||
)
|
||||
|
|
@ -170,12 +166,10 @@ class CampaignController:
|
|||
|
||||
def resolve_ties(
|
||||
self, war: War, contexts: List[TieContext]
|
||||
) -> Dict[Tuple[ContextType, str, int | None], Dict[str, bool]]:
|
||||
) -> Dict[tuple[str, str, int | None], Dict[str, bool]]:
|
||||
bids_map = {}
|
||||
for ctx in contexts:
|
||||
active = TieResolver.get_active_participants(
|
||||
war, ctx.context_type, ctx.context_id, ctx.participants
|
||||
)
|
||||
active = TieResolver.get_active_participants(war, ctx, ctx.participants)
|
||||
players = [
|
||||
ParticipantOption(id=pid, name=self.app.model.get_participant_name(pid))
|
||||
for pid in active
|
||||
|
|
@ -189,9 +183,8 @@ class CampaignController:
|
|||
context_id=ctx.context_id,
|
||||
context_name=None,
|
||||
)
|
||||
if ctx.context_type == ContextType.OBJECTIVE:
|
||||
campaign_id, objective_id = ctx.context_id.split(":")
|
||||
objective = war.objectives[objective_id]
|
||||
if ctx.objective_id:
|
||||
objective = war.objectives[ctx.objective_id]
|
||||
dialog = TieDialog(
|
||||
parent=self.app.view,
|
||||
players=players,
|
||||
|
|
@ -202,13 +195,9 @@ class CampaignController:
|
|||
)
|
||||
if not dialog.exec():
|
||||
# FIXME lost tokens used for narrative tie-break (ContextType.OBJECTIVE)
|
||||
TieResolver.cancel_tie_break(
|
||||
war, ContextType.CAMPAIGN, ctx.context_id, ctx.score_value
|
||||
)
|
||||
TieResolver.cancel_tie_break(war, ctx)
|
||||
raise ForbiddenOperation("Tie resolution cancelled")
|
||||
bids_map[(ctx.context_type, ctx.context_id, ctx.score_value)] = (
|
||||
dialog.get_bids()
|
||||
)
|
||||
bids_map[ctx.key()] = dialog.get_bids()
|
||||
return bids_map
|
||||
|
||||
# Campaign participant methods
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ class RoundClosureWorkflow(ClosureWorkflow):
|
|||
while ties:
|
||||
bids_map = self.app.rounds.resolve_ties(war, ties)
|
||||
for tie in ties:
|
||||
bids = bids_map[(tie.context_type, tie.context_id, tie.score_value)]
|
||||
TieResolver.apply_bids(war, tie.context_type, tie.context_id, bids)
|
||||
bids = bids_map[tie.key()]
|
||||
TieResolver.apply_bids(war, tie, bids)
|
||||
TieResolver.resolve_tie_state(war, tie, bids)
|
||||
ties = TieResolver.find_battle_ties(war, round.id)
|
||||
for battle in round.battles.values():
|
||||
|
|
@ -40,8 +40,8 @@ class CampaignClosureWorkflow(ClosureWorkflow):
|
|||
while ties:
|
||||
bids_map = self.app.campaigns.resolve_ties(war, ties)
|
||||
for tie in ties:
|
||||
bids = bids_map[(tie.context_type, tie.context_id, tie.score_value)]
|
||||
TieResolver.apply_bids(war, tie.context_type, tie.context_id, bids)
|
||||
bids = bids_map[tie.key()]
|
||||
TieResolver.apply_bids(war, tie, bids)
|
||||
TieResolver.resolve_tie_state(war, tie, bids)
|
||||
ties = TieResolver.find_campaign_ties(war, campaign.id)
|
||||
for objective_id in war.objectives:
|
||||
|
|
@ -53,8 +53,8 @@ class CampaignClosureWorkflow(ClosureWorkflow):
|
|||
while ties:
|
||||
bids_map = self.app.campaigns.resolve_ties(war, ties)
|
||||
for tie in ties:
|
||||
bids = bids_map[(tie.context_type, tie.context_id, tie.score_value)]
|
||||
TieResolver.apply_bids(war, tie.context_type, tie.context_id, bids)
|
||||
bids = bids_map[tie.key()]
|
||||
TieResolver.apply_bids(war, tie, bids)
|
||||
TieResolver.resolve_tie_state(war, tie, bids)
|
||||
ties = TieResolver.find_campaign_objective_ties(
|
||||
war,
|
||||
|
|
@ -72,8 +72,8 @@ class WarClosureWorkflow(ClosureWorkflow):
|
|||
while ties:
|
||||
bids_map = self.app.wars.resolve_ties(war, ties)
|
||||
for tie in ties:
|
||||
bids = bids_map[(tie.context_type, tie.context_id, tie.score_value)]
|
||||
TieResolver.apply_bids(war, tie.context_type, tie.context_id, bids)
|
||||
bids = bids_map[tie.key()]
|
||||
TieResolver.apply_bids(war, tie, bids)
|
||||
TieResolver.resolve_tie_state(war, tie, bids)
|
||||
ties = TieResolver.find_war_ties(war)
|
||||
for objective_id in war.objectives:
|
||||
|
|
@ -84,8 +84,8 @@ class WarClosureWorkflow(ClosureWorkflow):
|
|||
while ties:
|
||||
bids_map = self.app.wars.resolve_ties(war, ties)
|
||||
for tie in ties:
|
||||
bids = bids_map[(tie.context_type, tie.context_id, tie.score_value)]
|
||||
TieResolver.apply_bids(war, tie.context_type, tie.context_id, bids)
|
||||
bids = bids_map[tie.key()]
|
||||
TieResolver.apply_bids(war, tie, bids)
|
||||
TieResolver.resolve_tie_state(war, tie, bids)
|
||||
ties = TieResolver.find_war_objective_ties(
|
||||
war,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from warchron.constants import (
|
|||
IconName,
|
||||
VP_RANK_TO_ICON,
|
||||
NP_RANK_TO_ICON,
|
||||
ScoreKind,
|
||||
)
|
||||
from warchron.model.war import War
|
||||
from warchron.model.score_service import ParticipantScore
|
||||
|
|
@ -31,14 +32,22 @@ class RankingIcon:
|
|||
return score.victory_points
|
||||
|
||||
icon_ranking = VP_RANK_TO_ICON
|
||||
score_kind = ScoreKind.VP
|
||||
else:
|
||||
|
||||
def value_getter(score: ParticipantScore) -> int:
|
||||
return score.narrative_points.get(objective_id, 0)
|
||||
|
||||
icon_ranking = NP_RANK_TO_ICON
|
||||
score_kind = ScoreKind.NP
|
||||
ranking = ResultChecker.get_effective_ranking(
|
||||
war, context_type, context_id, scores, value_getter=value_getter
|
||||
war,
|
||||
context_type,
|
||||
context_id,
|
||||
score_kind,
|
||||
scores,
|
||||
value_getter,
|
||||
objective_id,
|
||||
)
|
||||
icon_map: Dict[str, QIcon] = {}
|
||||
for rank, group, token_map in ranking:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import List, Dict, Tuple, TYPE_CHECKING
|
||||
from typing import List, Dict, TYPE_CHECKING
|
||||
|
||||
from PyQt6.QtWidgets import QDialog
|
||||
from PyQt6.QtWidgets import QMessageBox
|
||||
|
|
@ -105,9 +105,8 @@ class RoundController:
|
|||
if battle.is_draw():
|
||||
p1_icon = Icons.get(IconName.DRAW)
|
||||
p2_icon = Icons.get(IconName.DRAW)
|
||||
if TieResolver.was_tie_broken_by_tokens(
|
||||
war, ContextType.BATTLE, battle.sector_id
|
||||
):
|
||||
context = TieContext(ContextType.BATTLE, battle.sector_id)
|
||||
if TieResolver.was_tie_broken_by_tokens(war, context):
|
||||
effective_winner = ResultChecker.get_effective_winner_id(
|
||||
war, ContextType.BATTLE, battle.sector_id, None
|
||||
)
|
||||
|
|
@ -179,7 +178,7 @@ class RoundController:
|
|||
|
||||
def resolve_ties(
|
||||
self, war: War, contexts: List[TieContext]
|
||||
) -> Dict[Tuple[ContextType, str, int | None], Dict[str, bool]]:
|
||||
) -> Dict[tuple[str, str, int | None], Dict[str, bool]]:
|
||||
bids_map = {}
|
||||
for ctx in contexts:
|
||||
players = [
|
||||
|
|
@ -198,13 +197,9 @@ class RoundController:
|
|||
context_id=ctx.context_id,
|
||||
)
|
||||
if not dialog.exec():
|
||||
TieResolver.cancel_tie_break(
|
||||
war, ContextType.BATTLE, ctx.context_id, ctx.score_value
|
||||
)
|
||||
TieResolver.cancel_tie_break(war, ctx)
|
||||
raise ForbiddenOperation("Tie resolution cancelled")
|
||||
bids_map[(ctx.context_type, ctx.context_id, ctx.score_value)] = (
|
||||
dialog.get_bids()
|
||||
)
|
||||
bids_map[ctx.key()] = dialog.get_bids()
|
||||
return bids_map
|
||||
|
||||
# Choice methods
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import List, Tuple, TYPE_CHECKING, Dict
|
||||
from typing import List, TYPE_CHECKING, Dict
|
||||
|
||||
from PyQt6.QtWidgets import QMessageBox, QDialog
|
||||
from PyQt6.QtGui import QIcon
|
||||
|
|
@ -63,8 +63,8 @@ class WarController:
|
|||
for obj in war.get_all_objectives():
|
||||
objective_icon_maps[obj.id] = RankingIcon.compute_icons(
|
||||
war,
|
||||
ContextType.OBJECTIVE,
|
||||
f"{war.id}:{obj.id}",
|
||||
ContextType.WAR,
|
||||
war.id,
|
||||
scores,
|
||||
objective_id=obj.id,
|
||||
)
|
||||
|
|
@ -151,16 +151,14 @@ class WarController:
|
|||
RefreshScope.WARS_TREE, item_type=ItemType.WAR, item_id=war_id
|
||||
)
|
||||
|
||||
# FIXME tie dialog with all participant even without tie
|
||||
def resolve_ties(
|
||||
self, war: War, contexts: List[TieContext]
|
||||
) -> Dict[Tuple[ContextType, str, int | None], Dict[str, bool]]:
|
||||
) -> Dict[tuple[str, str, int | None], Dict[str, bool]]:
|
||||
bids_map = {}
|
||||
for ctx in contexts:
|
||||
active = TieResolver.get_active_participants(
|
||||
war,
|
||||
ctx.context_type,
|
||||
ctx.context_id,
|
||||
ctx,
|
||||
ctx.participants,
|
||||
)
|
||||
players = [
|
||||
|
|
@ -176,26 +174,21 @@ class WarController:
|
|||
context_id=ctx.context_id,
|
||||
context_name=None,
|
||||
)
|
||||
if ctx.context_type == ContextType.OBJECTIVE:
|
||||
_, objective_id = ctx.context_id.split(":")
|
||||
objective = war.objectives[objective_id]
|
||||
if ctx.objective_id:
|
||||
objective = war.objectives[ctx.objective_id]
|
||||
dialog = TieDialog(
|
||||
parent=self.app.view,
|
||||
players=players,
|
||||
counters=counters,
|
||||
context_type=ctx.context_type,
|
||||
context_id=ctx.context_id,
|
||||
context_name=objective.name,
|
||||
context_name=f"Objective tie: {objective.name}",
|
||||
)
|
||||
if not dialog.exec():
|
||||
# FIXME lost tokens used for narrative tie-break (ContextType.OBJECTIVE)
|
||||
TieResolver.cancel_tie_break(
|
||||
war, ContextType.WAR, ctx.context_id, ctx.score_value
|
||||
)
|
||||
TieResolver.cancel_tie_break(war, ctx)
|
||||
raise ForbiddenOperation("Tie resolution cancelled")
|
||||
bids_map[(ctx.context_type, ctx.context_id, ctx.score_value)] = (
|
||||
dialog.get_bids()
|
||||
)
|
||||
bids_map[ctx.key()] = dialog.get_bids()
|
||||
return bids_map
|
||||
|
||||
def set_major_value(self, value: int) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue