From 986065258c66c7bafbf3e615755e8d1ffc6217c0 Mon Sep 17 00:00:00 2001 From: Henning Waberg Date: Fri, 17 Apr 2020 14:24:09 +0200 Subject: [PATCH] Addes random pools option for commanders choice and origins --- XCOM2RPGOverhaul/Config/XComMCM.ini | 4 ++ .../Config/XComSecondWaveOptions.ini | 4 ++ .../Localization/XCOM2RPGOverhaul.int | 12 +++++ .../Classes/RPGO_UIArmory_PromotionHero.uc | 52 ++++++++++++++++--- .../Classes/UIChooseAbilities.uc | 42 +++------------ .../Classes/UIChooseSpecializations.uc | 14 ++--- .../Classes/X2SecondWaveConfigOptions.uc | 38 ++++++++++---- .../Classes/X2SoldierClassTemplatePlugin.uc | 48 +++++++++++++++++ 8 files changed, 157 insertions(+), 57 deletions(-) diff --git a/XCOM2RPGOverhaul/Config/XComMCM.ini b/XCOM2RPGOverhaul/Config/XComMCM.ini index 638459c..7885377 100644 --- a/XCOM2RPGOverhaul/Config/XComMCM.ini +++ b/XCOM2RPGOverhaul/Config/XComMCM.ini @@ -28,6 +28,8 @@ "SWO_COMMANDERS_CHOICE":{ \\ "COMMANDERS_CHOICE_SPEC_COUNT":{ "Type": "Spinner", "Options": "1, 2, 3, 4, 5, 6, 7, 8, 9, 10" }, \\ "COMMANDERS_CHOICE_SPEC_COUNT_COMBI":{ "Type": "Spinner", "Options": "1, 2, 3, 4, 5, 6, 7, 8, 9, 10" }, \\ + "COMMANDERS_CHOICE_RANDOM_POOL_ENABLED": { "Type": "Checkbox" }, \\ + "COMMANDERS_CHOICE_RANDOM_POOL_COUNT":{ "Type": "Spinner", "Options": "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20" }, \\ }, \\ "SWO_SPECIALIZATION_ROULETTE":{ \\ "SPEC_ROULETTE_RANDOM_SPEC_COUNT":{ "Type": "Spinner", "Options": "1, 2, 3, 4, 5, 6, 7, 8, 9, 10" }, \\ @@ -40,6 +42,8 @@ "SWO_ORIGINS":{ \\ "ORIGINS_CHOICE_ABILITY_COUNT":{ "Type": "Spinner", "Options": "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10" }, \\ "ORIGINS_ADDITIONAL_RANDOM_ABILTIES":{ "Type": "Spinner", "Options": "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10" }, \\ + "ORIGINS_RANDOM_POOL_ENABLED": { "Type": "Checkbox" }, \\ + "ORIGINS_RANDOM_POOL_COUNT":{ "Type": "Spinner", "Options": "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20" }, \\ }, \\ } \\ } \ No newline at end of file diff --git a/XCOM2RPGOverhaul/Config/XComSecondWaveOptions.ini b/XCOM2RPGOverhaul/Config/XComSecondWaveOptions.ini index dd51231..bfb6910 100644 --- a/XCOM2RPGOverhaul/Config/XComSecondWaveOptions.ini +++ b/XCOM2RPGOverhaul/Config/XComSecondWaveOptions.ini @@ -6,6 +6,8 @@ ; ---------------------- Commanders Choice ----------------------- ; How many specs can be chosen on squaddie +ConfigProperties = {"COMMANDERS_CHOICE_SPEC_COUNT":{"Value":"3"}} ++ConfigProperties = {"COMMANDERS_CHOICE_RANDOM_POOL_ENABLED":{"Value":"false"}} ++ConfigProperties = {"COMMANDERS_CHOICE_RANDOM_POOL_COUNT":{"Value":"10"}} ; How many random specs and choosable specs ; if spec roulette and commander choice is enabled simultaniously @@ -26,3 +28,5 @@ +ConfigProperties = {"ORIGINS_CHOICE_ABILITY_COUNT":{"Value":"2"}} ; Add this number of random abilties on top of the chose ones +ConfigProperties = {"ORIGINS_ADDITIONAL_RANDOM_ABILTIES":{"Value":"0"}} ++ConfigProperties = {"ORIGINS_RANDOM_POOL_ENABLED":{"Value":"false"}} ++ConfigProperties = {"ORIGINS_RANDOM_POOL_COUNT":{"Value":"10"}} diff --git a/XCOM2RPGOverhaul/Localization/XCOM2RPGOverhaul.int b/XCOM2RPGOverhaul/Localization/XCOM2RPGOverhaul.int index fea285f..048db92 100644 --- a/XCOM2RPGOverhaul/Localization/XCOM2RPGOverhaul.int +++ b/XCOM2RPGOverhaul/Localization/XCOM2RPGOverhaul.int @@ -284,6 +284,12 @@ SPEC_ROULETTE_RANDOM_SPEC_COUNT_COMBI_TOOLTIP="Amount of random specializations COMMANDERS_CHOICE_SPEC_COUNT_COMBI_LABEL="Combined" COMMANDERS_CHOICE_SPEC_COUNT_COMBI_TOOLTIP="Amount of chosen specializations if spec roulette and commander choice is enabled simultaniously" +COMMANDERS_CHOICE_RANDOM_POOL_ENABLED_LABEL="Random pool" +COMMANDERS_CHOICE_RANDOM_POOL_ENABLED_TOOLTIP="When enabled you can only choose from a limited random pool of specs instead of all available specializations." + +COMMANDERS_CHOICE_RANDOM_POOL_COUNT_LABEL="Random pool size" +COMMANDERS_CHOICE_RANDOM_POOL_COUNT_TOOLTIP="This determines that size of the random pool. It should always be bigger than the number of commanders choice specs above. If you have the random classes swo enabled, its algorithm will be used for randomization." + TRAINING_ROULETTE_MIN_RANK_LABEL="Min Rank" TRAINING_ROULETTE_MIN_RANK_TOOLTIP="Start to randomize from this rank on" @@ -295,3 +301,9 @@ ORIGINS_CHOICE_ABILITY_COUNT_TOOLTIP=" How many starting abilities you want to c ORIGINS_ADDITIONAL_RANDOM_ABILTIES_LABEL="Random Abilities" ORIGINS_ADDITIONAL_RANDOM_ABILTIES_TOOLTIP="Add this number of random abilties on top of the chose ones" + +ORIGINS_RANDOM_POOL_ENABLED_LABEL="Random pool" +ORIGINS_RANDOM_POOL_ENABLED_TOOLTIP="When enabled you can only choose from a limited random pool of abilities instead of all available starting abilities" + +ORIGINS_RANDOM_POOL_COUNT_LABEL="Random pool size" +ORIGINS_RANDOM_POOL_COUNT_TOOLTIP="This determines that size of the random pool. It should always be bigger than the sum of chosen and random abilities above" \ No newline at end of file diff --git a/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/RPGO_UIArmory_PromotionHero.uc b/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/RPGO_UIArmory_PromotionHero.uc index 015ce85..330a48a 100644 --- a/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/RPGO_UIArmory_PromotionHero.uc +++ b/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/RPGO_UIArmory_PromotionHero.uc @@ -1379,18 +1379,45 @@ static function string GetClassSummary(XComGameState_Unit Unit) function SpawnChooseSpecScreen(XComGameState_Unit UnitState) { local UIChooseSpecializations ChooseSpecScreen; - local array TrainedSpecs; + local array TrainedSpecs, AvailableSpecs; + local int RandomPoolSize; if (`SecondWaveEnabled('RPGOSpecRoulette') || `SecondWaveEnabled('RPGO_SWO_RandomClasses')) { TrainedSpecs = class'X2SoldierClassTemplatePlugin'.static.GetAssignedSpecializations(UnitState); } + if (class'X2SecondWaveConfigOptions'.static.IsCommandersChoiceRandomPoolEnabled()) + { + TrainedSpecs.Length = 0; + RandomPoolSize = class'X2SecondWaveConfigOptions'.static.GetCommandersChoiceRandomPoolCount(); + + if (`SecondWaveEnabled('RPGO_SWO_RandomClasses')) + { + AvailableSpecs = class'X2SoldierClassTemplatePlugin'.static.GetSpecializationsByIndex( + UnitState, + class'X2SecondWaveConfigOptions'.static.GetSpecIndices_ForRandomClass(UnitState, RandomPoolSize) + ); + } + else + { + AvailableSpecs = class'X2SoldierClassTemplatePlugin'.static.GetSpecializationsByIndex( + UnitState, + class'X2SecondWaveConfigOptions'.static.GetRandomSpecIndices(UnitState, RandomPoolSize) + ); + } + } + else + { + AvailableSpecs = class'X2SoldierClassTemplatePlugin'.static.GetSpecializationsAvailableToSoldier(UnitState); + } + ChooseSpecScreen = Spawn(class'UIChooseSpecializations', Movie.Pres); Movie.Stack.Push(ChooseSpecScreen, Movie.Pres.Get3DMovie()); ChooseSpecScreen.InitChooseSpecialization( UnitState.GetReference(), class'X2SecondWaveConfigOptions'.static.GetCommandersChoiceCount(), + AvailableSpecs, TrainedSpecs ); } @@ -1399,18 +1426,31 @@ function SpawnChooseAbilityScreen(XComGameState_Unit UnitState) { local UIChooseAbilities ChooseAbilityScreen; local array RandomTemplates; + local array AvailableTemplates; - - RandomTemplates = class'X2SoldierClassTemplatePlugin'.static.GetRandomStartingAbilities( - UnitState, - class'RPGO_SWO_UserSettingsConfigManager'.static.GetConfigIntValue("ORIGINS_ADDITIONAL_RANDOM_ABILTIES") - ); + if (class'X2SecondWaveConfigOptions'.static.IsOriginsRandomPoolEnabled()) + { + AvailableTemplates = class'X2SoldierClassTemplatePlugin'.static.GetRandomStartingAbilities( + UnitState, + class'X2SecondWaveConfigOptions'.static.GetOriginsRandomPoolCount() + ); + } + else + { + RandomTemplates = class'X2SoldierClassTemplatePlugin'.static.GetRandomStartingAbilities( + UnitState, + class'X2SecondWaveConfigOptions'.static.GetOriginsRandomAbiltiesCount() + ); + AvailableTemplates = class'X2SoldierClassTemplatePlugin'.static.GetAllStartingAbilities(UnitState); + } + ChooseAbilityScreen = Spawn(class'UIChooseAbilities', Movie.Pres); Movie.Stack.Push(ChooseAbilityScreen, Movie.Pres.Get3DMovie()); ChooseAbilityScreen.InitChooseAbiltites( UnitState.GetReference(), class'X2SecondWaveConfigOptions'.static.GetOriginsAbiltiesCount(), + AvailableTemplates, RandomTemplates ); } diff --git a/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/UIChooseAbilities.uc b/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/UIChooseAbilities.uc index 655f34d..787be8d 100644 --- a/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/UIChooseAbilities.uc +++ b/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/UIChooseAbilities.uc @@ -3,7 +3,13 @@ class UIChooseAbilities extends UIChooseCommodity; var array AbilitiesPool; var array AbilitiesChosen; -simulated function InitChooseAbiltites(StateObjectReference UnitRef, int MaxAbilities, optional array OwnedAbiltites, optional delegate OnAccept) +simulated function InitChooseAbiltites( + StateObjectReference UnitRef, + int MaxAbilities, + array AvailableAbilities, + optional array OwnedAbiltites, + optional delegate OnAccept +) { super.InitChooseCommoditiesScreen( UnitRef, @@ -16,45 +22,13 @@ simulated function InitChooseAbiltites(StateObjectReference UnitRef, int MaxAbil CommoditiesChosen = ConvertToCommodities(AbilitiesChosen); AbilitiesPool.Length = 0; - AbilitiesPool = GetAbilityTemplates(GetUnit()); + AbilitiesPool = AvailableAbilities; AbilitiesPool.Sort(SortAbiltiesByName); CommodityPool = ConvertToCommodities(AbilitiesPool); PopulateData(); } -simulated function array GetAbilityTemplates(XComGameState_Unit Unit, optional XComGameState CheckGameState) -{ - local X2AbilityTemplate AbilityTemplate; - local X2AbilityTemplateManager AbilityTemplateManager; - local array AbilityTemplates; - local array RandomAbilityDecks; - local SoldierClassRandomAbilityDeck Deck; - local SoldierClassAbilityType AbilityType; - - if(Unit.IsSoldier()) - { - AbilityTemplateManager = class'X2AbilityTemplateManager'.static.GetAbilityTemplateManager(); - - RandomAbilityDecks = Unit.GetSoldierClassTemplate().RandomAbilityDecks; - - foreach RandomAbilityDecks(Deck) - { - foreach Deck.Abilities(AbilityType) - { - AbilityTemplate = AbilityTemplateManager.FindAbilityTemplate(AbilityType.AbilityName); - if(AbilityTemplate != none && - !AbilityTemplate.bDontDisplayInAbilitySummary && - AbilityTemplate.ConditionsEverValidForUnit(Unit, true) ) - { - AbilityTemplate.DefaultSourceItemSlot = AbilityType.ApplyToWeaponSlot; - AbilityTemplates.AddItem(AbilityTemplate); - } - } - } - } - return AbilityTemplates; -} diff --git a/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/UIChooseSpecializations.uc b/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/UIChooseSpecializations.uc index bd9894f..2206446 100644 --- a/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/UIChooseSpecializations.uc +++ b/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/UIChooseSpecializations.uc @@ -7,10 +7,14 @@ var array SelectedItems; var localized string m_strComplementarySpecializationInfo; -simulated function InitChooseSpecialization(StateObjectReference UnitRef, int MaxSpecs, array OwnedSpecs, optional delegate OnAccept) +simulated function InitChooseSpecialization( + StateObjectReference UnitRef, + int MaxSpecs, + array AvailableSpecs, + array OwnedSpecs, + optional delegate OnAccept +) { - local XComGameState_Unit UnitState; - super.InitChooseCommoditiesScreen( UnitRef, MaxSpecs, @@ -18,10 +22,8 @@ simulated function InitChooseSpecialization(StateObjectReference UnitRef, int Ma OnAccept ); - UnitState = GetUnit(); - SpecializationsPool.Length = 0; - SpecializationsPool = class'X2SoldierClassTemplatePlugin'.static.GetSpecializationsAvailableToSoldier(UnitState); + SpecializationsPool = AvailableSpecs; CommodityPool = ConvertToCommodities(SpecializationsPool); SpecializationsChosen.Length = 0; diff --git a/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/X2SecondWaveConfigOptions.uc b/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/X2SecondWaveConfigOptions.uc index 44a4082..d0f1b0b 100644 --- a/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/X2SecondWaveConfigOptions.uc +++ b/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/X2SecondWaveConfigOptions.uc @@ -47,12 +47,32 @@ static function int GetCommandersChoiceCount() static function int GetOriginsAbiltiesCount() { - return class'RPGO_SWO_UserSettingsConfigManager'.static.GetConfigIntValue("ORIGINS_CHOICE_ABILITY_COUNT"); + return class'RPGO_SWO_UserSettingsConfigManager'.static.GetConfigIntValue("ORIGINS_CHOICE_ABILITY_COUNT"); } static function int GetOriginsRandomAbiltiesCount() { - return class'RPGO_SWO_UserSettingsConfigManager'.static.GetConfigIntValue("ORIGINS_ADDITIONAL_RANDOM_ABILTIES"); + return class'RPGO_SWO_UserSettingsConfigManager'.static.GetConfigIntValue("ORIGINS_ADDITIONAL_RANDOM_ABILTIES"); +} + +static function int GetOriginsRandomPoolCount() +{ + return class'RPGO_SWO_UserSettingsConfigManager'.static.GetConfigIntValue("ORIGINS_RANDOM_POOL_COUNT"); +} + +static function bool IsOriginsRandomPoolEnabled() +{ + return class'RPGO_SWO_UserSettingsConfigManager'.static.GetConfigBoolValue("ORIGINS_RANDOM_POOL_ENABLED"); +} + +static function int GetCommandersChoiceRandomPoolCount() +{ + return class'RPGO_SWO_UserSettingsConfigManager'.static.GetConfigIntValue("COMMANDERS_CHOICE_RANDOM_POOL_COUNT"); +} + +static function bool IsCommandersChoiceRandomPoolEnabled() +{ + return class'RPGO_SWO_UserSettingsConfigManager'.static.GetConfigBoolValue("COMMANDERS_CHOICE_RANDOM_POOL_ENABLED"); } static function AddStartingAbilities( @@ -86,17 +106,16 @@ static function AddStartingAbilities( } // Get Random specs for spec roulette -static function array GetRandomSpecIndices(XComGameState_Unit UnitState) +static function array GetRandomSpecIndices(XComGameState_Unit UnitState, int Count) { local array Specs; - local int Count, RandomSlotIndex, Index, ComplementarySpecIndex; + local int RandomSlotIndex, Index, ComplementarySpecIndex; local array RandomAbilitySlotIndices; local X2UniversalSoldierClassInfo SpecTemplate; local name ForceComplementarySpec; `LOG(default.class @ GetFuncName() @ "Start profiling",, 'RPG'); - Count = GetSpecRouletteCount(); Specs = class'X2SoldierClassTemplatePlugin'.static.GetSpecializationsAvailableToSoldier(UnitState); for (Index = 0; Index < Count; Index++) @@ -145,9 +164,8 @@ static function array GetRandomSpecIndices(XComGameState_Unit UnitState) // Random Classes // Select specializations for the soldier to randomly create a soldier class. -static function array GetSpecIndices_ForRandomClass(XComGameState_Unit UnitState) +static function array GetSpecIndices_ForRandomClass(XComGameState_Unit UnitState, int Count) { - local int Count; local array AllSpecTemplates; local array ValidSpecTemplates; local array SelectedSpecTemplates; @@ -161,8 +179,6 @@ static function array GetSpecIndices_ForRandomClass(XComGameState_Unit Unit `LOG("=====================================================",, 'RPG'); `LOG("Building random class for: " @ UnitState.GetFullName(),, 'RPG'); - // Minimum number of specs we should assign to the soldier, configured with MCM. - Count = GetSpecRouletteCount(); AllSpecTemplates = class'X2SoldierClassTemplatePlugin'.static.GetSpecializationTemplatesAvailableToSoldier(UnitState); // ######################################################## @@ -332,11 +348,11 @@ static function BuildRandomSpecAbilityTree(XComGameState_Unit UnitState, optiona // Random Classes if (`SecondWaveEnabled('RPGO_SWO_RandomClasses')) { - BuildSpecAbilityTree(UnitState, GetSpecIndices_ForRandomClass(UnitState), true, bRandomizePerkOrder); + BuildSpecAbilityTree(UnitState, GetSpecIndices_ForRandomClass(UnitState, GetSpecRouletteCount()), true, bRandomizePerkOrder); } else { - BuildSpecAbilityTree(UnitState, GetRandomSpecIndices(UnitState), true, bRandomizePerkOrder); + BuildSpecAbilityTree(UnitState, GetRandomSpecIndices(UnitState, GetSpecRouletteCount()), true, bRandomizePerkOrder); } } diff --git a/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/X2SoldierClassTemplatePlugin.uc b/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/X2SoldierClassTemplatePlugin.uc index b70e1b3..688bc58 100644 --- a/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/X2SoldierClassTemplatePlugin.uc +++ b/XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/X2SoldierClassTemplatePlugin.uc @@ -36,6 +36,41 @@ static function array GetRandomStartingAbilities(XComGameStat return Templates; } + +// Get all available starting abilities +static function array GetAllStartingAbilities(XComGameState_Unit Unit) +{ + local X2AbilityTemplate AbilityTemplate; + local X2AbilityTemplateManager AbilityTemplateManager; + local array AbilityTemplates; + local array LocalRandomAbilityDecks; + local SoldierClassRandomAbilityDeck Deck; + local SoldierClassAbilityType AbilityType; + + if(Unit.IsSoldier()) + { + AbilityTemplateManager = class'X2AbilityTemplateManager'.static.GetAbilityTemplateManager(); + + LocalRandomAbilityDecks = Unit.GetSoldierClassTemplate().RandomAbilityDecks; + + foreach LocalRandomAbilityDecks(Deck) + { + foreach Deck.Abilities(AbilityType) + { + AbilityTemplate = AbilityTemplateManager.FindAbilityTemplate(AbilityType.AbilityName); + if(AbilityTemplate != none && + !AbilityTemplate.bDontDisplayInAbilitySummary && + AbilityTemplate.ConditionsEverValidForUnit(Unit, true) ) + { + AbilityTemplate.DefaultSourceItemSlot = AbilityType.ApplyToWeaponSlot; + AbilityTemplates.AddItem(AbilityTemplate); + } + } + } + } + return AbilityTemplates; +} + // Get all owned ability templates for rank static function array GetAbilityTemplatesForRank(XComGameState_Unit UnitState, int Rank) { @@ -243,6 +278,19 @@ static function int GetSpecializationIndex(XComGameState_Unit UnitState, name Sp return Specs.Find('TemplateName', SpecTemplateName); } + +static function array GetSpecializationsByIndex(XComGameState_Unit UnitState, array IndexArray) +{ + local int Index; + local array Specs; + + foreach IndexArray(Index) + { + Specs.AddItem(GetSpecializationBySlotFromAvailableSpecs(UnitState, Index)); + } + return Specs; +} + static function array GetComplementarySpecializations(XComGameState_Unit UnitState, SoldierSpecialization Spec) { local X2UniversalSoldierClassInfo SpecTemplate;