Skip to content

Commit

Permalink
Merge pull request Ziktofel#225 from EnvyDragon/mission-variants
Browse files Browse the repository at this point in the history
SC2: Generator for raceswap mission variants
  • Loading branch information
Ziktofel authored Jul 4, 2024
2 parents 66e8afa + ea64dac commit 13263d1
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 47 deletions.
18 changes: 16 additions & 2 deletions worlds/sc2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
SpearOfAdunPresence, SpearOfAdunPresentInNoBuild, SpearOfAdunAutonomouslyCastAbilityPresence,
SpearOfAdunAutonomouslyCastPresentInNoBuild, NerfUnitBaselines, LEGACY_GRID_ORDERS,
)
from .mission_tables import MissionFlag


if __name__ == "__main__":
Expand Down Expand Up @@ -1053,6 +1054,20 @@ def kerrigan_primal(ctx: SC2Context, kerrigan_level: int) -> bool:
return get_full_item_list()[item_names.KERRIGAN_PRIMAL_FORM].code in codes
return False


def get_mission_variant(mission_id: int) -> int:
mission_flags = lookup_id_to_mission[mission_id].flags
if MissionFlag.RaceSwap not in mission_flags:
return 0
if MissionFlag.Terran in mission_flags:
return 1
elif MissionFlag.Zerg in mission_flags:
return 2
elif MissionFlag.Protoss in mission_flags:
return 3
return 0


async def starcraft_launch(ctx: SC2Context, mission_id: int):
sc2_logger.info(f"Launching {lookup_id_to_mission[mission_id].mission_name}. If game does not launch check log file for errors.")

Expand Down Expand Up @@ -1101,9 +1116,8 @@ async def on_step(self, iteration: int):
kerrigan_level = get_kerrigan_level(self.ctx, start_items, missions_beaten)
kerrigan_options = calculate_kerrigan_options(self.ctx)
soa_options = caclulate_soa_options(self.ctx)
mission_variant = get_mission_variant(self.mission_id) # 0/1/2/3 for unchanged/Terran/Zerg/Protoss
uncollected_objectives: typing.List[int] = self.get_uncollected_objectives()
# TODO: Add logic to determine which variant, based on selected map ID
mission_variant = 0 # 0/1/2/3 for unchanged/Terran/Zerg/Protoss
if self.ctx.difficulty_override >= 0:
difficulty = calc_difficulty(self.ctx.difficulty_override)
else:
Expand Down
162 changes: 139 additions & 23 deletions worlds/sc2/locations.py

Large diffs are not rendered by default.

21 changes: 18 additions & 3 deletions worlds/sc2/mission_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class MissionFlag(IntFlag):
VsTerran = auto()
VsZerg = auto()
VsProtoss = auto()
HasRaceSwap = auto() # The mission has variants that use different factions from the vanilla experience.
RaceSwap = auto() # The mission uses different factions from the vanilla experience.

AiAlly = AiTerranAlly|AiZergAlly|AiProtossAlly
TimedDefense = AutoScroller|Defense
Expand Down Expand Up @@ -99,13 +101,13 @@ def __init__(self, mission_id: int, name: str, campaign: SC2Campaign, area: str,

# Wings of Liberty
LIBERATION_DAY = 1, "Liberation Day", SC2Campaign.WOL, "Mar Sara", SC2Race.ANY, MissionPools.STARTER, "ap_liberation_day", MissionFlag.Terran|MissionFlag.NoBuild|MissionFlag.VsTerran
THE_OUTLAWS = 2, "The Outlaws", SC2Campaign.WOL, "Mar Sara", SC2Race.TERRAN, MissionPools.EASY, "ap_the_outlaws", MissionFlag.Terran|MissionFlag.VsTerran
ZERO_HOUR = 3, "Zero Hour", SC2Campaign.WOL, "Mar Sara", SC2Race.TERRAN, MissionPools.EASY, "ap_zero_hour", MissionFlag.Terran|MissionFlag.TimedDefense|MissionFlag.VsZerg
THE_OUTLAWS = 2, "The Outlaws (Terran)", SC2Campaign.WOL, "Mar Sara", SC2Race.TERRAN, MissionPools.EASY, "ap_the_outlaws", MissionFlag.Terran|MissionFlag.VsTerran|MissionFlag.HasRaceSwap
ZERO_HOUR = 3, "Zero Hour (Terran)", SC2Campaign.WOL, "Mar Sara", SC2Race.TERRAN, MissionPools.EASY, "ap_zero_hour", MissionFlag.Terran|MissionFlag.TimedDefense|MissionFlag.VsZerg|MissionFlag.HasRaceSwap
EVACUATION = 4, "Evacuation", SC2Campaign.WOL, "Colonist", SC2Race.TERRAN, MissionPools.EASY, "ap_evacuation", MissionFlag.Terran|MissionFlag.AutoScroller|MissionFlag.VsZerg
OUTBREAK = 5, "Outbreak", SC2Campaign.WOL, "Colonist", SC2Race.TERRAN, MissionPools.EASY, "ap_outbreak", MissionFlag.Terran|MissionFlag.Defense|MissionFlag.VsZerg
SAFE_HAVEN = 6, "Safe Haven", SC2Campaign.WOL, "Colonist", SC2Race.TERRAN, MissionPools.MEDIUM, "ap_safe_haven", MissionFlag.Terran|MissionFlag.Countdown|MissionFlag.VsProtoss
HAVENS_FALL = 7, "Haven's Fall", SC2Campaign.WOL, "Colonist", SC2Race.TERRAN, MissionPools.MEDIUM, "ap_havens_fall", MissionFlag.Terran|MissionFlag.VsZerg
SMASH_AND_GRAB = 8, "Smash and Grab", SC2Campaign.WOL, "Artifact", SC2Race.TERRAN, MissionPools.EASY, "ap_smash_and_grab", MissionFlag.Terran|MissionFlag.Countdown|MissionFlag.VsPZ
SMASH_AND_GRAB = 8, "Smash and Grab (Terran)", SC2Campaign.WOL, "Artifact", SC2Race.TERRAN, MissionPools.EASY, "ap_smash_and_grab", MissionFlag.Terran|MissionFlag.Countdown|MissionFlag.VsPZ|MissionFlag.HasRaceSwap
THE_DIG = 9, "The Dig", SC2Campaign.WOL, "Artifact", SC2Race.TERRAN, MissionPools.MEDIUM, "ap_the_dig", MissionFlag.Terran|MissionFlag.TimedDefense|MissionFlag.VsProtoss
THE_MOEBIUS_FACTOR = 10, "The Moebius Factor", SC2Campaign.WOL, "Artifact", SC2Race.TERRAN, MissionPools.MEDIUM, "ap_the_moebius_factor", MissionFlag.Terran|MissionFlag.Countdown|MissionFlag.VsZerg
SUPERNOVA = 11, "Supernova", SC2Campaign.WOL, "Artifact", SC2Race.TERRAN, MissionPools.HARD, "ap_supernova", MissionFlag.Terran|MissionFlag.Countdown|MissionFlag.VsProtoss
Expand Down Expand Up @@ -194,6 +196,19 @@ def __init__(self, mission_id: int, name: str, campaign: SC2Campaign, area: str,
DARK_SKIES = 82, "Dark Skies", SC2Campaign.NCO, "_3", SC2Race.TERRAN, MissionPools.HARD, "ap_dark_skies", MissionFlag.Terran|MissionFlag.Nova|MissionFlag.TimedDefense|MissionFlag.VsProtoss
END_GAME = 83, "End Game", SC2Campaign.NCO, "_3", SC2Race.TERRAN, MissionPools.VERY_HARD, "ap_end_game", MissionFlag.Terran|MissionFlag.Nova|MissionFlag.Defense|MissionFlag.VsTerran

# Race-Swapped Variants
# 84/85 - Liberation Day
THE_OUTLAWS_Z = 86, "The Outlaws (Zerg)", SC2Campaign.WOL, "Mar Sara", SC2Race.ZERG, MissionPools.EASY, "ap_the_outlaws", MissionFlag.Zerg|MissionFlag.VsTerran|MissionFlag.RaceSwap
THE_OUTLAWS_P = 87, "The Outlaws (Protoss)", SC2Campaign.WOL, "Mar Sara", SC2Race.PROTOSS, MissionPools.EASY, "ap_the_outlaws", MissionFlag.Protoss|MissionFlag.VsTerran|MissionFlag.RaceSwap
ZERO_HOUR_Z = 88, "Zero Hour (Zerg)", SC2Campaign.WOL, "Mar Sara", SC2Race.ZERG, MissionPools.EASY, "ap_zero_hour", MissionFlag.Zerg|MissionFlag.TimedDefense|MissionFlag.VsZerg|MissionFlag.RaceSwap
ZERO_HOUR_P = 89, "Zero Hour (Protoss)", SC2Campaign.WOL, "Mar Sara", SC2Race.PROTOSS, MissionPools.EASY, "ap_zero_hour", MissionFlag.Protoss|MissionFlag.TimedDefense|MissionFlag.VsZerg|MissionFlag.RaceSwap
# 90/91 - Evacuation
# 92/93 - Outbreak
# 94/95 - Safe Haven
# 96/97 - Haven's Fall
SMASH_AND_GRAB_Z = 98, "Smash and Grab (Zerg)", SC2Campaign.WOL, "Artifact", SC2Race.ZERG, MissionPools.EASY, "ap_smash_and_grab", MissionFlag.Zerg|MissionFlag.Countdown|MissionFlag.VsPZ|MissionFlag.RaceSwap
SMASH_AND_GRAB_P = 99, "Smash and Grab (Protoss)", SC2Campaign.WOL, "Artifact", SC2Race.PROTOSS, MissionPools.EASY, "ap_smash_and_grab", MissionFlag.Protoss|MissionFlag.Countdown|MissionFlag.VsPZ|MissionFlag.RaceSwap


class MissionConnection:
campaign: SC2Campaign
Expand Down
27 changes: 24 additions & 3 deletions worlds/sc2/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class MaximumCampaignSize(Range):
"""
display_name = "Maximum Campaign Size"
range_start = 1
range_end = 83
range_end = 89
default = 83


Expand Down Expand Up @@ -260,6 +260,23 @@ class EnableNCOMissions(DefaultOnToggle):
display_name = "Enable Nova Covert Ops missions"


class EnableRaceSwapVariants(Choice):
"""
Allow mission variants where you play a faction other than the one the map was initially
designed for. NOTE: Cutscenes are always skipped on race-swapped mission variants.
Disabled: Don't shuffle any non-vanilla map variants into the pool.
Shuffle All: Each version of a map can appear in the same pool (so a map can appear up to 3 times as different races)
("Pick Just One At Random" coming soon)
"""
display_name = "Enable Race-Swapped Mission Variants"
option_disabled = 0
# TODO: Implement pick-one logic
# option_pick_one = 1
option_shuffle_all = 2
default = option_disabled


class ShuffleCampaigns(DefaultOnToggle):
"""
Shuffles the missions between campaigns if enabled.
Expand Down Expand Up @@ -911,13 +928,15 @@ class Starcraft2Options(PerGameCommonOptions):
player_color_protoss: PlayerColorProtoss
player_color_zerg: PlayerColorZerg
player_color_zerg_primal: PlayerColorZergPrimal
selected_races: SelectRaces
enable_wol_missions: EnableWolMissions
enable_prophecy_missions: EnableProphecyMissions
enable_hots_missions: EnableHotsMissions
enable_lotv_prologue_missions: EnableLotVPrologueMissions
enable_lotv_missions: EnableLotVMissions
enable_epilogue_missions: EnableEpilogueMissions
enable_nco_missions: EnableNCOMissions
enable_race_swap: EnableRaceSwapVariants
shuffle_campaigns: ShuffleCampaigns
shuffle_no_build: ShuffleNoBuild
starter_unit: StarterUnit
Expand Down Expand Up @@ -1003,7 +1022,7 @@ def get_enabled_campaigns(world: 'SC2World') -> Set[SC2Campaign]:
enabled_campaigns.add(SC2Campaign.EPILOGUE)
if get_option_value(world, "enable_nco_missions"):
enabled_campaigns.add(SC2Campaign.NCO)
return set([campaign for campaign in enabled_campaigns if campaign.race in get_enabled_races(world)])
return enabled_campaigns


def get_disabled_campaigns(world: 'SC2World') -> Set[SC2Campaign]:
Expand All @@ -1019,6 +1038,8 @@ def get_disabled_flags(world: 'SC2World') -> MissionFlag:
# filter out no-build missions
if not get_option_value(world, "shuffle_no_build"):
excluded |= MissionFlag.NoBuild
if get_option_value(world, "enable_race_swap") == EnableRaceSwapVariants.option_disabled:
excluded |= MissionFlag.RaceSwap
# TODO: add more flags to potentially exclude once we have a way to get that from the player
return MissionFlag(excluded)

Expand All @@ -1042,7 +1063,7 @@ def get_excluded_missions(world: 'SC2World') -> Set[SC2Mission]:
[mission for mission in SC2Mission if
mission.pool == MissionPools.VERY_HARD and mission.campaign != SC2Campaign.EPILOGUE]
)
# Omitting No-Build missions if not shuffling no-build
# Omitting missions with flags we don't want
if disabled_flags:
excluded_missions = excluded_missions.union(get_missions_with_any_flags_in_list(disabled_flags))
# Omitting missions not in enabled campaigns
Expand Down
26 changes: 13 additions & 13 deletions worlds/sc2/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,38 @@ def wol_cleared_missions(state: CollectionState, mission_count: int) -> bool:
player: int = world.player
if SC2Campaign.WOL in enabled_campaigns:
connect(world, names, 'Menu', 'Liberation Day')
connect(world, names, 'Liberation Day', 'The Outlaws',
connect(world, names, 'Liberation Day', 'The Outlaws (Terran)',
lambda state: state.has("Beat Liberation Day", player))
connect(world, names, 'The Outlaws', 'Zero Hour',
lambda state: state.has("Beat The Outlaws", player))
connect(world, names, 'Zero Hour', 'Evacuation',
lambda state: state.has("Beat Zero Hour", player))
connect(world, names, 'The Outlaws (Terran)', 'Zero Hour (Terran)',
lambda state: state.has("Beat The Outlaws (Terran)", player))
connect(world, names, 'Zero Hour (Terran)', 'Evacuation',
lambda state: state.has("Beat Zero Hour (Terran)", player))
connect(world, names, 'Evacuation', 'Outbreak',
lambda state: state.has("Beat Evacuation", player))
connect(world, names, "Outbreak", "Safe Haven",
lambda state: wol_cleared_missions(state, 7) and state.has("Beat Outbreak", player))
connect(world, names, "Outbreak", "Haven's Fall",
lambda state: wol_cleared_missions(state, 7) and state.has("Beat Outbreak", player))
connect(world, names, 'Zero Hour', 'Smash and Grab',
lambda state: state.has("Beat Zero Hour", player))
connect(world, names, 'Smash and Grab', 'The Dig',
lambda state: wol_cleared_missions(state, 8) and state.has("Beat Smash and Grab", player))
connect(world, names, 'Zero Hour (Terran)', 'Smash and Grab (Terran)',
lambda state: state.has("Beat Zero Hour (Terran)", player))
connect(world, names, 'Smash and Grab (Terran)', 'The Dig',
lambda state: wol_cleared_missions(state, 8) and state.has("Beat Smash and Grab (Terran)", player))
connect(world, names, 'The Dig', 'The Moebius Factor',
lambda state: wol_cleared_missions(state, 11) and state.has("Beat The Dig", player))
connect(world, names, 'The Moebius Factor', 'Supernova',
lambda state: wol_cleared_missions(state, 14) and state.has("Beat The Moebius Factor", player))
connect(world, names, 'Supernova', 'Maw of the Void',
lambda state: state.has("Beat Supernova", player))
connect(world, names, 'Zero Hour', "Devil's Playground",
lambda state: wol_cleared_missions(state, 4) and state.has("Beat Zero Hour", player))
connect(world, names, 'Zero Hour (Terran)', "Devil's Playground",
lambda state: wol_cleared_missions(state, 4) and state.has("Beat Zero Hour (Terran)", player))
connect(world, names, "Devil's Playground", 'Welcome to the Jungle',
lambda state: state.has("Beat Devil's Playground", player))
connect(world, names, "Welcome to the Jungle", 'Breakout',
lambda state: wol_cleared_missions(state, 8) and state.has("Beat Welcome to the Jungle", player))
connect(world, names, "Welcome to the Jungle", 'Ghost of a Chance',
lambda state: wol_cleared_missions(state, 8) and state.has("Beat Welcome to the Jungle", player))
connect(world, names, "Zero Hour", 'The Great Train Robbery',
lambda state: wol_cleared_missions(state, 6) and state.has("Beat Zero Hour", player))
connect(world, names, "Zero Hour (Terran)", 'The Great Train Robbery',
lambda state: wol_cleared_missions(state, 6) and state.has("Beat Zero Hour (Terran)", player))
connect(world, names, 'The Great Train Robbery', 'Cutthroat',
lambda state: state.has("Beat The Great Train Robbery", player))
connect(world, names, 'Cutthroat', 'Engine of Destruction',
Expand Down
4 changes: 2 additions & 2 deletions worlds/sc2/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from BaseClasses import CollectionState
from .options import get_option_value, RequiredTactics, kerrigan_unit_available, AllInMap, \
GrantStoryTech, GrantStoryLevels, TakeOverAIAllies, SpearOfAdunAutonomouslyCastAbilityPresence, \
get_enabled_campaigns, MissionOrder, EnableMorphling
get_enabled_campaigns, MissionOrder, EnableMorphling, get_enabled_races
from .items import get_basic_units, defense_ratings, zerg_defense_ratings, kerrigan_actives, air_defense_ratings, \
kerrigan_levels, get_full_item_list
from .mission_tables import SC2Race, SC2Campaign
Expand Down Expand Up @@ -939,7 +939,7 @@ def __init__(self, world: 'SC2World'):
self.advanced_tactics = self.logic_level != RequiredTactics.option_standard
self.take_over_ai_allies = get_option_value(world, "take_over_ai_allies") == TakeOverAIAllies.option_true
self.kerrigan_unit_available = get_option_value(world, 'kerrigan_presence') in kerrigan_unit_available \
and SC2Campaign.HOTS in get_enabled_campaigns(world)
and SC2Campaign.HOTS in get_enabled_campaigns(world) and SC2Race.ZERG in get_enabled_races(world)
self.kerrigan_levels_per_mission_completed = get_option_value(world, "kerrigan_levels_per_mission_completed")
self.kerrigan_levels_per_mission_completed_cap = get_option_value(world, "kerrigan_levels_per_mission_completed_cap")
self.kerrigan_total_level_cap = get_option_value(world, "kerrigan_total_level_cap")
Expand Down
3 changes: 2 additions & 1 deletion worlds/sc2/test/test_usecases.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ def test_excluding_zerg_excludes_campaigns_and_items(self) -> None:
for item_name in world_item_names:
self.assertNotEqual(items.item_table[item_name].race, mission_tables.SC2Race.ZERG,
f"{item_name} is a ZERG item!")
for region in world_regions:
# have to manually exclude the only non-zerg HotS mission...
for region in filter(lambda region: region != "With Friends Like These", world_regions):
self.assertNotIn(mission_tables.lookup_name_to_mission[region].campaign,
([mission_tables.SC2Campaign.HOTS]),
f"{region} is a ZERG mission!")
Expand Down

0 comments on commit 13263d1

Please sign in to comment.