Skip to content

Commit

Permalink
SC2: For non-campaign order pick one of the hardest missions as goal (A…
Browse files Browse the repository at this point in the history
…rchipelagoMW#3180)

This allows End Game as the goal even if long campaigns are present
  • Loading branch information
Ziktofel authored and James Schurig committed Jun 13, 2024
1 parent 78304c5 commit 105e54a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
7 changes: 3 additions & 4 deletions worlds/sc2/MissionTables.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ class SC2CampaignGoal(NamedTuple):
SC2Campaign.PROLOGUE: SC2CampaignGoal(SC2Mission.EVIL_AWOKEN, "Evil Awoken: Victory"),
SC2Campaign.LOTV: SC2CampaignGoal(SC2Mission.SALVATION, "Salvation: Victory"),
SC2Campaign.EPILOGUE: None,
SC2Campaign.NCO: None,
SC2Campaign.NCO: SC2CampaignGoal(SC2Mission.END_GAME, "End Game: Victory"),
}

campaign_alt_final_mission_locations: Dict[SC2Campaign, Dict[SC2Mission, str]] = {
Expand Down Expand Up @@ -683,7 +683,6 @@ class SC2CampaignGoal(NamedTuple):
SC2Mission.THE_ESSENCE_OF_ETERNITY: "The Essence of Eternity: Victory",
},
SC2Campaign.NCO: {
SC2Mission.END_GAME: "End Game: Victory",
SC2Mission.FLASHPOINT: "Flashpoint: Victory",
SC2Mission.DARK_SKIES: "Dark Skies: Victory",
SC2Mission.NIGHT_TERRORS: "Night Terrors: Victory",
Expand All @@ -709,10 +708,10 @@ def get_goal_location(mission: SC2Mission) -> Union[str, None]:
return primary_campaign_goal.location

campaign_alt_goals = campaign_alt_final_mission_locations[campaign]
if campaign_alt_goals is not None:
if campaign_alt_goals is not None and mission in campaign_alt_goals:
return campaign_alt_goals.get(mission)

return None
return mission.mission_name + ": Victory"


def get_campaign_potential_goal_missions(campaign: SC2Campaign) -> List[SC2Mission]:
Expand Down
48 changes: 33 additions & 15 deletions worlds/sc2/PoolFilter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Dict, List, Set, Union, Tuple
from typing import Callable, Dict, List, Set, Union, Tuple, Optional
from BaseClasses import Item, Location
from .Items import get_full_item_list, spider_mine_sources, second_pass_placeable_items, progressive_if_nco, \
progressive_if_ext, spear_of_adun_calldowns, spear_of_adun_castable_passives, nova_equipment
Expand Down Expand Up @@ -69,21 +69,39 @@ def filter_missions(world: World) -> Dict[MissionPools, List[SC2Mission]]:
return mission_pools

# Finding the goal map
goal_priorities = {campaign: get_campaign_goal_priority(campaign, excluded_missions) for campaign in enabled_campaigns}
goal_level = max(goal_priorities.values())
candidate_campaigns: List[SC2Campaign] = [campaign for campaign, goal_priority in goal_priorities.items() if goal_priority == goal_level]
candidate_campaigns.sort(key=lambda it: it.id)
goal_campaign = world.random.choice(candidate_campaigns)
primary_goal = campaign_final_mission_locations[goal_campaign]
if primary_goal is None or primary_goal.mission in excluded_missions:
# No primary goal or its mission is excluded
candidate_missions = list(campaign_alt_final_mission_locations[goal_campaign].keys())
candidate_missions = [mission for mission in candidate_missions if mission not in excluded_missions]
if len(candidate_missions) == 0:
raise Exception("There are no valid goal missions. Please exclude fewer missions.")
goal_mission = world.random.choice(candidate_missions)
goal_mission: Optional[SC2Mission] = None
if mission_order_type in campaign_depending_orders:
# Prefer long campaigns over shorter ones and harder missions over easier ones
goal_priorities = {campaign: get_campaign_goal_priority(campaign, excluded_missions) for campaign in enabled_campaigns}
goal_level = max(goal_priorities.values())
candidate_campaigns: List[SC2Campaign] = [campaign for campaign, goal_priority in goal_priorities.items() if goal_priority == goal_level]
candidate_campaigns.sort(key=lambda it: it.id)

goal_campaign = world.random.choice(candidate_campaigns)
primary_goal = campaign_final_mission_locations[goal_campaign]
if primary_goal is None or primary_goal.mission in excluded_missions:
# No primary goal or its mission is excluded
candidate_missions = list(campaign_alt_final_mission_locations[goal_campaign].keys())
candidate_missions = [mission for mission in candidate_missions if mission not in excluded_missions]
if len(candidate_missions) == 0:
raise Exception("There are no valid goal missions. Please exclude fewer missions.")
goal_mission = world.random.choice(candidate_missions)
else:
goal_mission = primary_goal.mission
else:
goal_mission = primary_goal.mission
# Find one of the missions with the hardest difficulty
available_missions: List[SC2Mission] = \
[mission for mission in SC2Mission
if (mission not in excluded_missions and mission.campaign in enabled_campaigns)]
available_missions.sort(key=lambda it: it.id)
# Loop over pools, from hardest to easiest
for mission_pool in range(MissionPools.VERY_HARD, MissionPools.STARTER - 1, -1):
pool_missions: List[SC2Mission] = [mission for mission in available_missions if mission.pool == mission_pool]
if pool_missions:
goal_mission = world.random.choice(pool_missions)
break
if goal_mission is None:
raise Exception("There are no valid goal missions. Please exclude fewer missions.")

# Excluding missions
for difficulty, mission_pool in mission_pools.items():
Expand Down

0 comments on commit 105e54a

Please sign in to comment.