Skip to content

Commit

Permalink
Addes random pools option for commanders choice and origins
Browse files Browse the repository at this point in the history
  • Loading branch information
Musashi1584 committed Apr 17, 2020
1 parent fc85dd1 commit 9860652
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 57 deletions.
4 changes: 4 additions & 0 deletions XCOM2RPGOverhaul/Config/XComMCM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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" }, \\
Expand All @@ -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" }, \\
}, \\
} \\
}
4 changes: 4 additions & 0 deletions XCOM2RPGOverhaul/Config/XComSecondWaveOptions.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"}}
12 changes: 12 additions & 0 deletions XCOM2RPGOverhaul/Localization/XCOM2RPGOverhaul.int
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -1379,18 +1379,45 @@ static function string GetClassSummary(XComGameState_Unit Unit)
function SpawnChooseSpecScreen(XComGameState_Unit UnitState)
{
local UIChooseSpecializations ChooseSpecScreen;
local array<SoldierSpecialization> TrainedSpecs;
local array<SoldierSpecialization> 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
);
}
Expand All @@ -1399,18 +1426,31 @@ function SpawnChooseAbilityScreen(XComGameState_Unit UnitState)
{
local UIChooseAbilities ChooseAbilityScreen;
local array<X2AbilityTemplate> RandomTemplates;
local array<X2AbilityTemplate> 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
);
}
Expand Down
42 changes: 8 additions & 34 deletions XCOM2RPGOverhaul/Src/XCOM2RPGOverhaul/Classes/UIChooseAbilities.uc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ class UIChooseAbilities extends UIChooseCommodity;
var array<X2AbilityTemplate> AbilitiesPool;
var array<X2AbilityTemplate> AbilitiesChosen;

simulated function InitChooseAbiltites(StateObjectReference UnitRef, int MaxAbilities, optional array<X2AbilityTemplate> OwnedAbiltites, optional delegate<AcceptAbilities> OnAccept)
simulated function InitChooseAbiltites(
StateObjectReference UnitRef,
int MaxAbilities,
array<X2AbilityTemplate> AvailableAbilities,
optional array<X2AbilityTemplate> OwnedAbiltites,
optional delegate<AcceptAbilities> OnAccept
)
{
super.InitChooseCommoditiesScreen(
UnitRef,
Expand All @@ -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<X2AbilityTemplate> GetAbilityTemplates(XComGameState_Unit Unit, optional XComGameState CheckGameState)
{
local X2AbilityTemplate AbilityTemplate;
local X2AbilityTemplateManager AbilityTemplateManager;
local array<X2AbilityTemplate> AbilityTemplates;
local array<SoldierClassRandomAbilityDeck> 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;
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ var array<int> SelectedItems;

var localized string m_strComplementarySpecializationInfo;

simulated function InitChooseSpecialization(StateObjectReference UnitRef, int MaxSpecs, array<SoldierSpecialization> OwnedSpecs, optional delegate<AcceptAbilities> OnAccept)
simulated function InitChooseSpecialization(
StateObjectReference UnitRef,
int MaxSpecs,
array<SoldierSpecialization> AvailableSpecs,
array<SoldierSpecialization> OwnedSpecs,
optional delegate<AcceptAbilities> OnAccept
)
{
local XComGameState_Unit UnitState;

super.InitChooseCommoditiesScreen(
UnitRef,
MaxSpecs,
ConvertToCommodities(OwnedSpecs),
OnAccept
);

UnitState = GetUnit();

SpecializationsPool.Length = 0;
SpecializationsPool = class'X2SoldierClassTemplatePlugin'.static.GetSpecializationsAvailableToSoldier(UnitState);
SpecializationsPool = AvailableSpecs;
CommodityPool = ConvertToCommodities(SpecializationsPool);

SpecializationsChosen.Length = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -86,17 +106,16 @@ static function AddStartingAbilities(
}

// Get Random specs for spec roulette
static function array<int> GetRandomSpecIndices(XComGameState_Unit UnitState)
static function array<int> GetRandomSpecIndices(XComGameState_Unit UnitState, int Count)
{
local array<SoldierSpecialization> Specs;
local int Count, RandomSlotIndex, Index, ComplementarySpecIndex;
local int RandomSlotIndex, Index, ComplementarySpecIndex;
local array<int> 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++)
Expand Down Expand Up @@ -145,9 +164,8 @@ static function array<int> GetRandomSpecIndices(XComGameState_Unit UnitState)

// Random Classes
// Select specializations for the soldier to randomly create a soldier class.
static function array<int> GetSpecIndices_ForRandomClass(XComGameState_Unit UnitState)
static function array<int> GetSpecIndices_ForRandomClass(XComGameState_Unit UnitState, int Count)
{
local int Count;
local array<X2UniversalSoldierClassInfo> AllSpecTemplates;
local array<X2UniversalSoldierClassInfo> ValidSpecTemplates;
local array<X2UniversalSoldierClassInfo> SelectedSpecTemplates;
Expand All @@ -161,8 +179,6 @@ static function array<int> 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);

// ########################################################
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,41 @@ static function array<X2AbilityTemplate> GetRandomStartingAbilities(XComGameStat
return Templates;
}


// Get all available starting abilities
static function array<X2AbilityTemplate> GetAllStartingAbilities(XComGameState_Unit Unit)
{
local X2AbilityTemplate AbilityTemplate;
local X2AbilityTemplateManager AbilityTemplateManager;
local array<X2AbilityTemplate> AbilityTemplates;
local array<SoldierClassRandomAbilityDeck> 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<X2AbilityTemplate> GetAbilityTemplatesForRank(XComGameState_Unit UnitState, int Rank)
{
Expand Down Expand Up @@ -243,6 +278,19 @@ static function int GetSpecializationIndex(XComGameState_Unit UnitState, name Sp
return Specs.Find('TemplateName', SpecTemplateName);
}


static function array<SoldierSpecialization> GetSpecializationsByIndex(XComGameState_Unit UnitState, array<int> IndexArray)
{
local int Index;
local array<SoldierSpecialization> Specs;

foreach IndexArray(Index)
{
Specs.AddItem(GetSpecializationBySlotFromAvailableSpecs(UnitState, Index));
}
return Specs;
}

static function array<SoldierSpecialization> GetComplementarySpecializations(XComGameState_Unit UnitState, SoldierSpecialization Spec)
{
local X2UniversalSoldierClassInfo SpecTemplate;
Expand Down

0 comments on commit 9860652

Please sign in to comment.