Skip to content

Commit

Permalink
Added Character Generator classes for resistance faction soldiers so …
Browse files Browse the repository at this point in the history
…that they can be refactored for better compatibility with the DLC Hook.

Additional commit for the previous one.

Refactored resistance soldier character generator classes for better compatibility with the DLC hook.

Update X2WOTCCommunityHighlander/Src/XComGame/Classes/X2DownloadableContentInfo.uc

Co-Authored-By: robojumper <robojumper@gmail.com>

Update XGCharacterGenerator.uc

Moved triggering the DLC hook into a separate method.

Update X2WOTCCommunityHighlander/Src/XComGame/Classes/X2DownloadableContentInfo.uc

Co-authored-by: Peter Ledbrook <peter@cacoethes.co.uk>

Update X2WOTCCommunityHighlander/Src/XComGame/Classes/X2DownloadableContentInfo.uc

Co-authored-by: Peter Ledbrook <peter@cacoethes.co.uk>

Update X2WOTCCommunityHighlander/Src/XComGame/Classes/XGCharacterGenerator_Skirmisher.uc

Co-authored-by: Peter Ledbrook <peter@cacoethes.co.uk>

Update X2WOTCCommunityHighlander/Src/XComGame/Classes/XGCharacterGenerator_Templar.uc

Co-authored-by: Peter Ledbrook <peter@cacoethes.co.uk>

Update X2WOTCCommunityHighlander/Src/XComGame/Classes/XGCharacterGenerator_Reaper.uc

Co-authored-by: Peter Ledbrook <peter@cacoethes.co.uk>

Update X2WOTCCommunityHighlander/Src/XComGame/Classes/XGCharacterGenerator_Reaper.uc

Co-authored-by: Peter Ledbrook <peter@cacoethes.co.uk>

Update X2WOTCCommunityHighlander/Src/XComGame/Classes/XGCharacterGenerator_Reaper.uc

Co-authored-by: Peter Ledbrook <peter@cacoethes.co.uk>

Made the helper function that calls the DLC Hook an instance one.
  • Loading branch information
Iridar authored and Iridar51 committed Jan 8, 2021
1 parent 4d6998e commit 2d83a4b
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -763,19 +763,19 @@ final function string GetDisplayName()
}
/// End Issue #524

/// Start Issue #783
/// <summary>
// Start Issue #783
// <summary>
/// Called from XGCharacterGenerator:CreateTSoldier
/// Has no return value, just modify the CharGen.kSoldier directly.
/// HL-Docs: feature:ModifyGeneratedUnitAppearance; issue:783; tags:Customization
/// HL-Docs: feature:ModifyGeneratedUnitAppearance; issue:783; tags:customization
/// This DLC hook allows mods to make arbitrary changes to unit appearance after it has been generated by the Character Generator.
/// The main argument of the hook function is the instance of the XGCharacterGenerator.
/// It contains the "kSoldier" property, which stores the generated appearance, and can be modified by the hook.
/// You can also use the methods in the Character Generator if you want to "redo" some parts of the generation process.
/// However, it's important *not* to call the CreateTSoldier() method, as this will retrigger the hook, potentially causing an inception loop and crashing the game.
/// The UnitState and the GameState will be passed with the event only if this CreateTSoldier() function was called from CreateTSoldierFromUnit(),
/// which normally happens only in the shell code (TQL / Challenge Mode / Character Pool).
/// </summary>
// </summary>
static function ModifyGeneratedUnitAppearance(XGCharacterGenerator CharGen, optional name CharacterTemplateName, optional EGender eForceGender, optional name nmCountry = '', optional int iRace = -1, optional name ArmorName, optional XComGameState_Unit UnitState, optional XComGameState UseGameState)
{}
/// End Issue #783
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,6 @@ function TSoldier CreateTSoldier( optional name CharacterTemplateName, optional
local X2SimpleBodyPartFilter BodyPartFilter;
local X2CharacterTemplate CharacterTemplate;
local TAppearance DefaultAppearance;
// Start variables for issue #783
local array<X2DownloadableContentInfo> DLCInfos;
local int i;
// End variables for issue #783

kSoldier.kAppearance = DefaultAppearance;

Expand Down Expand Up @@ -408,16 +404,26 @@ function TSoldier CreateTSoldier( optional name CharacterTemplateName, optional
BioCountryName = kSoldier.nmCountry;

// Start issue #783
ModifyGeneratedUnitAppearance(CharacterTemplateName, eForceGender, nmCountry, iRace, ArmorName);
// End issue #783

return kSoldier;
}

// Start issue #783
private function ModifyGeneratedUnitAppearance(optional name CharacterTemplateName, optional EGender eForceGender, optional name nmCountry = '', optional int iRace = -1, optional name ArmorName)
{
local array<X2DownloadableContentInfo> DLCInfos;
local int i;

/// HL-Docs: ref:ModifyGeneratedUnitAppearance; issue:783
DLCInfos = `ONLINEEVENTMGR.GetDLCInfos(false);
for (i = 0; i < DLCInfos.Length; i++)
{
DLCInfos[i].ModifyGeneratedUnitAppearance(self, CharacterTemplateName, eForceGender, nmCountry, iRace, ArmorName, GenerateAppearanceForUnitState, GenerateAppearanceForGameState);
}
// End issue #783

return kSoldier;
}
// End issue #783

static function Name GetLanguageByString(optional string strLanguage="")
{
Expand Down Expand Up @@ -1063,4 +1069,4 @@ function string GenerateNickname(X2SoldierClassTemplate Template, int iGender)
}

return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
class XGCharacterGenerator_Reaper extends XGCharacterGenerator
dependson(X2StrategyGameRulesetDataStructures) config(NameList);

var config array<int> PrimaryArmorColors;
var config array<int> SecondaryArmorColors;
var config array<name> MaleHeads;
var config array<Name> FemaleHeads;
var config array<name> MaleHelmets;
var config array<name> FemaleHelmets;
var config array<name> MaleLeftArms;
var config array<name> MaleRightArms;
var config array<name> FemaleLeftArms;
var config array<name> FemaleRightArms;


function bool IsSoldier(name CharacterTemplateName)
{
return true;
}

function X2CharacterTemplate SetCharacterTemplate(name CharacterTemplateName, name ArmorName)
{
MatchArmorTemplateForTorso = (ArmorName == '') ? 'ReaperArmor' : ArmorName;
MatchCharacterTemplateForTorso = 'NoCharacterTemplateName'; //Force the selector to use the armor type to filter torsos

return class'X2CharacterTemplateManager'.static.GetCharacterTemplateManager().FindCharacterTemplate('ReaperSoldier');
}

// Start issue #783
// Normally this function calls the super.CreateTSoldier, and then manually sets the country and nickname.
// In order to make the DLC hook for this issue more compatible with resistance faction soldiers,
// this functionality has been moved into SetCountry() and GenerateName() methods which will be called by super.CreateTSoldier.
function TSoldier CreateTSoldier(optional name CharacterTemplateName, optional EGender eForceGender, optional name nmCountry = '', optional int iRace = -1, optional name ArmorName)
{
kSoldier = super.CreateTSoldier('ReaperSoldier', eForceGender, nmCountry, iRace, ArmorName);
return kSoldier;
}

function SetCountry(name nmCountry)
{
kSoldier.nmCountry = 'Country_Reaper';
kSoldier.kAppearance.nmFlag = kSoldier.nmCountry; // needs to be copied here for pawns -- jboswell
}

function GenerateName(int iGender, name CountryName, out string strFirst, out string strLast, optional int iRace = -1)
{
local X2SoldierClassTemplateManager ClassMgr;
local X2SoldierClassTemplate ClassTemplate;

super.GenerateName(kSoldier.kAppearance.iGender, kSoldier.nmCountry, kSoldier.strFirstName, kSoldier.strLastName, kSoldier.kAppearance.iRace);

ClassMgr = class'X2SoldierClassTemplateManager'.static.GetSoldierClassTemplateManager();
ClassTemplate = ClassMgr.FindSoldierClassTemplate('Reaper');
kSoldier.strNickName = GenerateNickname(ClassTemplate, kSoldier.kAppearance.iGender);
}
// End issue #783

function SetRace(int iRace)
{
kSoldier.kAppearance.iRace = eRace_Caucasian;
}

function SetHead(X2SimpleBodyPartFilter BodyPartFilter, X2CharacterTemplate CharacterTemplate)
{
super.SetHead(BodyPartFilter, CharacterTemplate);

if (kSoldier.kAppearance.iGender == eGender_Male)
{
kSoldier.kAppearance.nmHead = default.MaleHeads[`SYNC_RAND(default.MaleHeads.Length)];
}
else
{
kSoldier.kAppearance.nmHead = default.FemaleHeads[`SYNC_RAND(default.FemaleHeads.Length)];
}
}

function SetArmsLegsAndDeco(X2SimpleBodyPartFilter BodyPartFilter)
{
super.SetArmsLegsAndDeco(BodyPartFilter);

if(kSoldier.kAppearance.iGender == eGender_Male)
{
kSoldier.kAppearance.nmLeftArm = default.MaleLeftArms[`SYNC_RAND(default.MaleLeftArms.Length)];
kSoldier.kAppearance.nmRightArm = default.MaleRightArms[`SYNC_RAND(default.MaleRightArms.Length)];
}
else
{
kSoldier.kAppearance.nmLeftArm = default.FemaleLeftArms[`SYNC_RAND(default.FemaleLeftArms.Length)];
kSoldier.kAppearance.nmRightArm = default.FemaleRightArms[`SYNC_RAND(default.FemaleRightArms.Length)];
}
}

function SetAccessories(X2SimpleBodyPartFilter BodyPartFilter, name CharacterTemplateName)
{
super.SetAccessories(BodyPartFilter, CharacterTemplateName);

if(kSoldier.kAppearance.iGender == eGender_Male)
{
kSoldier.kAppearance.nmHelmet = default.MaleHelmets[`SYNC_RAND(default.MaleHelmets.Length)];
}
else
{
kSoldier.kAppearance.nmHelmet = default.FemaleHelmets[`SYNC_RAND(default.FemaleHelmets.Length)];
}
}

function SetArmorTints(X2CharacterTemplate CharacterTemplate)
{
super.SetArmorTints(CharacterTemplate);

kSoldier.kAppearance.iArmorTint = default.PrimaryArmorColors[`SYNC_RAND(default.PrimaryArmorColors.Length)];
kSoldier.kAppearance.iArmorTintSecondary = default.SecondaryArmorColors[`SYNC_RAND(default.SecondaryArmorColors.Length)];
}

function SetVoice(name CharacterTemplateName, name CountryName)
{
if (IsSoldier(CharacterTemplateName))
{
kSoldier.kAppearance.nmVoice = GetVoiceFromCountryAndGenderAndCharacter(CountryName, kSoldier.kAppearance.iGender, CharacterTemplateName);

if (kSoldier.kAppearance.nmVoice == '')
{
if (kSoldier.kAppearance.iGender == eGender_Male)
{
kSoldier.kAppearance.nmVoice = 'ReaperMaleVoice1_Localized';
}
else
{
kSoldier.kAppearance.nmVoice = 'ReaperFemaleVoice1_Localized';
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
class XGCharacterGenerator_Skirmisher extends XGCharacterGenerator
dependson(X2StrategyGameRulesetDataStructures);

var config array<int> PrimaryArmorColors;
var config array<int> SecondaryArmorColors;
var config array<name> MaleHelmets;
var config array<name> FemaleHelmets;

function bool IsSoldier(name CharacterTemplateName)
{
return true;
}

function X2CharacterTemplate SetCharacterTemplate(name CharacterTemplateName, name ArmorName)
{
MatchArmorTemplateForTorso = (ArmorName == '') ? 'SkirmisherArmor' : ArmorName;
MatchCharacterTemplateForTorso = 'NoCharacterTemplateName'; //Force the selector to use the armor type to filter torsos

return class'X2CharacterTemplateManager'.static.GetCharacterTemplateManager().FindCharacterTemplate('SkirmisherSoldier');
}

// Start issue #783
// Normally this function calls the super.CreateTSoldier, and then manually sets the country and nickname.
// In order to make the DLC hook for this issue more compatible with resistance faction soldiers,
// this functionality has been moved into SetCountry() and GenerateName() methods which will be called by super.CreateTSoldier.
function TSoldier CreateTSoldier(optional name CharacterTemplateName, optional EGender eForceGender, optional name nmCountry = '', optional int iRace = -1, optional name ArmorName)
{
kSoldier = super.CreateTSoldier('SkirmisherSoldier', eForceGender, nmCountry, iRace, ArmorName);
return kSoldier;
}

function SetCountry(name nmCountry)
{
kSoldier.nmCountry = 'Country_Skirmisher';
kSoldier.kAppearance.nmFlag = kSoldier.nmCountry; // needs to be copied here for pawns -- jboswell
}

function GenerateName( int iGender, name CountryName, out string strFirst, out string strLast, optional int iRace = -1 )
{
local X2SoldierClassTemplateManager ClassMgr;
local X2SoldierClassTemplate ClassTemplate;

super.GenerateName( kSoldier.kAppearance.iGender, kSoldier.nmCountry, kSoldier.strFirstName, kSoldier.strLastName, kSoldier.kAppearance.iRace );

ClassMgr = class'X2SoldierClassTemplateManager'.static.GetSoldierClassTemplateManager();
ClassTemplate = ClassMgr.FindSoldierClassTemplate('Skirmisher');
kSoldier.strNickName = GenerateNickname(ClassTemplate, kSoldier.kAppearance.iGender);
}
// End issue #783

function SetAccessories(X2SimpleBodyPartFilter BodyPartFilter, name CharacterTemplateName)
{
local X2BodyPartTemplateManager PartTemplateManager;

PartTemplateManager = class'X2BodyPartTemplateManager'.static.GetBodyPartTemplateManager();

//Turn off most customization options for Skirmishers
SetBodyPartToFirstInArray(PartTemplateManager, kSoldier.kAppearance.nmPatterns, "Patterns", BodyPartFilter.FilterAny);
SetBodyPartToFirstInArray(PartTemplateManager, kSoldier.kAppearance.nmWeaponPattern, "Patterns", BodyPartFilter.FilterAny);
SetBodyPartToFirstInArray(PartTemplateManager, kSoldier.kAppearance.nmTattoo_LeftArm, "Tattoos", BodyPartFilter.FilterAny);
SetBodyPartToFirstInArray(PartTemplateManager, kSoldier.kAppearance.nmTattoo_RightArm, "Tattoos", BodyPartFilter.FilterAny);
SetBodyPartToFirstInArray(PartTemplateManager, kSoldier.kAppearance.nmHaircut, "Hair", BodyPartFilter.FilterAny);
SetBodyPartToFirstInArray(PartTemplateManager, kSoldier.kAppearance.nmBeard, "Beards", BodyPartFilter.FilterAny);
SetBodyPartToFirstInArray(PartTemplateManager, kSoldier.kAppearance.nmHelmet, "Helmets", BodyPartFilter.FilterAny);
SetBodyPartToFirstInArray(PartTemplateManager, kSoldier.kAppearance.nmFacePropLower, "FacePropsLower", BodyPartFilter.FilterAny);
SetBodyPartToFirstInArray(PartTemplateManager, kSoldier.kAppearance.nmFacePropUpper, "FacePropsUpper", BodyPartFilter.FilterAny);

// Randomly choose a Skirmisher scar
RandomizeSetBodyPart(PartTemplateManager, kSoldier.kAppearance.nmScars, "Scars", BodyPartFilter.FilterByCharacter);

if (kSoldier.kAppearance.iGender == eGender_Male)
{
kSoldier.kAppearance.nmHelmet = default.MaleHelmets[`SYNC_RAND(default.MaleHelmets.Length)];
}
else
{
kSoldier.kAppearance.nmHelmet = default.FemaleHelmets[`SYNC_RAND(default.FemaleHelmets.Length)];
}
}

function SetArmorTints(X2CharacterTemplate CharacterTemplate)
{
super.SetArmorTints(CharacterTemplate);

kSoldier.kAppearance.iArmorTint = default.PrimaryArmorColors[`SYNC_RAND(default.PrimaryArmorColors.Length)];
kSoldier.kAppearance.iArmorTintSecondary = default.SecondaryArmorColors[`SYNC_RAND(default.SecondaryArmorColors.Length)];
}

function SetVoice(name CharacterTemplateName, name CountryName)
{
if (IsSoldier(CharacterTemplateName))
{
kSoldier.kAppearance.nmVoice = GetVoiceFromCountryAndGenderAndCharacter(CountryName, kSoldier.kAppearance.iGender, CharacterTemplateName);

if (kSoldier.kAppearance.nmVoice == '')
{
if (kSoldier.kAppearance.iGender == eGender_Male)
{
kSoldier.kAppearance.nmVoice = 'SkirmisherMaleVoice1_Localized';
}
else
{
kSoldier.kAppearance.nmVoice = 'SkirmisherFemaleVoice1_Localized';
}
}
}
}
Loading

0 comments on commit 2d83a4b

Please sign in to comment.