Skip to content

Commit

Permalink
[WIP] Making rulers wait on specific infils
Browse files Browse the repository at this point in the history
  • Loading branch information
Xymanek committed Nov 18, 2019
1 parent f12cf85 commit 61b5780
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CovertInfiltration/CovertInfiltration.x2proj
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@
<Content Include="Src\CovertInfiltration\Classes\X2Helper_Infiltration.uc">
<SubType>Content</SubType>
</Content>
<Content Include="Src\CovertInfiltration\Classes\X2Helper_Infiltration_DLC2.uc">
<SubType>Content</SubType>
</Content>
<Content Include="Src\CovertInfiltration\Classes\X2Helper_Infiltration_TemplateMod.uc">
<SubType>Content</SubType>
</Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,11 @@ static function XComGameState_HeadquartersProjectTrainAcademy GetAcademyProjectF
return none;
}

static function bool IsDLCLoaded (name DLCName)
{
// TODO
}

///////////////
/// Kill XP ///
///////////////
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//---------------------------------------------------------------------------------------
// AUTHOR: Xymanek
// PURPOSE: Houses functionality used for interacting with DLC2
// IMPORTANT: DO NOT call any method on this class if DLC2 isn't loaded
//---------------------------------------------------------------------------------------
// WOTCStrategyOverhaul Team
//---------------------------------------------------------------------------------------

class X2Helper_Infiltration_DLC2 extends Object;

static function StateObjectReference GetRulerOnInfiltration (StateObjectReference InfiltrationRef)
{
local XComGameState_AlienRulerManager RulerManager;
local StateObjectReference EmptyRef;
local int i;

RulerManager = XComGameState_AlienRulerManager(`XCOMHISTORY.GetSingleGameStateObjectForClass(class'XComGameState_AlienRulerManager'));
if (RulerManager == none) return EmptyRef;

i = RulerManager.AlienRulerLocations.Find('MissionRef', InfiltrationRef);
return i != INDEX_NONE ? RulerManager.AlienRulerLocations[i].RulerRef : EmptyRef;
}

static function bool InfiltrationHasRuler (StateObjectReference InfiltrationRef)
{
return GetRulerOnInfiltration(InfiltrationRef).ObjectID != 0;
}

static function PlaceRulerOnInfiltration (XComGameState NewGameState, XComGameState_MissionSiteInfiltration InfiltrationState)
{
local XComGameState_AlienRulerManager RulerManager;
local array<StateObjectReference> Candidates;
local AlienRulerLocation RulerLocation;
local StateObjectReference Candidate;
local XComGameState_Unit RulerState;
local XComGameStateHistory History;

if (InfiltrationHasRuler(InfiltrationState.GetReference()))
{
`RedScreen("CI: PlaceRulerOnInfiltration called for infil that already has a ruler, skipping");
return;
}

History = `XCOMHISTORY;
RulerManager = XComGameState_AlienRulerManager(History.GetSingleGameStateObjectForClass(class'XComGameState_AlienRulerManager'));

foreach RulerManager.ActiveAlienRulers(Candidate)
{
// Check that the ruler is not waiting on another mission
if (RulerManager.AlienRulerLocations.Find('RulerRef', Candidate) == INDEX_NONE)
{
// If we have DLC integration enabled, check that the ruler was seen once
// We cannot rely on AlienRulerLocations here since the ruler might be waiting for a facility to be built
if (class'X2Helpers_DLC_Day60'.static.IsXPackIntegrationEnabled())
{
RulerState = XComGameState_Unit(History.GetGameStateForObjectID(Candidate.ObjectID));

if (class'X2Helpers_DLC_Day60'.static.GetRulerNumAppearances(RulerState) > 0)
{
Candidates.AddItem(Candidate);
}
}
else
{
Candidates.AddItem(Candidate);
}
}
}

foreach Candidates(Candidate)
{
RulerState = XComGameState_Unit(History.GetGameStateForObjectID(Candidate.ObjectID));

if (RulerManager.RulerAppearRoll < RulerManager.GetRulerAppearChance(RulerState)) // TODO: Unprivate in CHL
{
RulerLocation.RulerRef = Candidate;
RulerLocation.MissionRef = InfiltrationState.GetReference();
RulerLocation.bActivated = true;
RulerLocation.bNeedsPopup = false;

RulerManager = XComGameState_AlienRulerManager(NewGameState.ModifyStateObject(class'XComGameState_AlienRulerManager', RulerManager.ObjectID));
RulerManager.AlienRulerLocations.AddItem(RulerLocation);

// The ruler is ready and waiting bwahahaha
return;
}
}
}

static function RemoveRulerFromInfiltration (XComGameState NewGameState, XComGameState_MissionSiteInfiltration InfiltrationState)
{
local XComGameState_AlienRulerManager RulerManager;
local int i;

RulerManager = XComGameState_AlienRulerManager(`XCOMHISTORY.GetSingleGameStateObjectForClass(class'XComGameState_AlienRulerManager'));
i = RulerManager.AlienRulerLocations.Find('MissionRef', InfiltrationState.GetReference());

if (i != INDEX_NONE)
{
RulerManager = XComGameState_AlienRulerManager(NewGameState.ModifyStateObject(class'XComGameState_AlienRulerManager', RulerManager.ObjectID));
RulerManager.AlienRulerLocations.Remove(i, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function InitializeFromActivity (XComGameState NewGameState)

class'X2Helper_Infiltration'.static.InitalizeGeneratedMissionFromActivity(GetActivity());
SelectPlotAndBiome(); // Need to do this here so that we have plot type display on the loadout
PlaceRuler(NewGameState);

InitRegisterEvents();
}
Expand Down Expand Up @@ -640,6 +641,9 @@ function int GetChosenAppereanceChance()
return -1;
}

// Chosen cannot spawn if ruler is waiting on this mission
if (IsRulerPresent()) return 0;

BaseChance = CurrentChosen.GetChosenAppearChance();
if (BaseChance == 0) return 0;

Expand Down Expand Up @@ -751,7 +755,7 @@ protected function RemoveChosenTags ()
local XComGameState_AdventChosen ChosenState;
local XComGameState_MissionSite MissionState;
// Because PurgeMissionOfTags's argument is marked as "out" ¯\_(?)_/¯
// Because PurgeMissionOfTags's argument is marked as "out" \_(?)_/
MissionState = self;
foreach `XCOMHISTORY.IterateByClassType(class'XComGameState_AdventChosen', ChosenState)
Expand Down Expand Up @@ -829,6 +833,8 @@ function StartMission()
function RemoveEntity(XComGameState NewGameState)
{
super.RemoveEntity(NewGameState);
RemoveRuler(NewGameState);
UnRegisterFromEvents();
}
Expand All @@ -847,6 +853,36 @@ function XComGameState_CovertAction GetSpawningAction ()
return XComGameState_CovertAction(`XCOMHISTORY.GetGameStateForObjectID(GetActivity().SecondaryObjectRef.ObjectID));
}
////////////
/// DLC2 ///
////////////
function bool IsRulerPresent ()
{
if (class'X2Helper_Infiltration'.static.IsDLCLoaded('DLC_2'))
{
return class'X2Helper_Infiltration_DLC2'.static.InfiltrationHasRuler(GetReference());
}
return false;
}
protected function PlaceRuler (XComGameState NewGameState)
{
if (class'X2Helper_Infiltration'.static.IsDLCLoaded('DLC_2'))
{
class'X2Helper_Infiltration_DLC2'.static.PlaceRulerOnInfiltration(NewGameState, self);
}
}
protected function RemoveRuler (XComGameState NewGameState)
{
if (class'X2Helper_Infiltration'.static.IsDLCLoaded('DLC_2'))
{
class'X2Helper_Infiltration_DLC2'.static.RemoveRulerFromInfiltration(NewGameState, self);
}
}
////////////////////////
/// Event management ///
////////////////////////
Expand Down

0 comments on commit 61b5780

Please sign in to comment.