Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to send sound alerts data to allies #1169

Merged
merged 9 commits into from
Aug 17, 2023
14 changes: 14 additions & 0 deletions X2WOTCCommunityHighlander/Src/XComGame/Classes/CHHelpers.uc
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ var config int NoiseAlertSoundRange;
var config array<name> AdditionalAIBTActionPointTypes;
// End Issue #510

// variable for issue #620
var config bool bConsiderAlliesforSoundAlerts;

// Variable for Issue #724
var config array<name> ValidReserveAPForUnitFlag;

Expand Down Expand Up @@ -994,3 +997,14 @@ static final function array<SoldierClassAbilityType> RebuildSoldierClassAbilityT
return AbilityTypes;
}
// End Issue #815

/// HL-Docs: ref:ConsiderAlliesforSoundAlerts
// start issue #620
static function bool ConsiderAlliesforSoundAlerts()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there are a particular reason you created a function to check the value of a config variable?

You could just do class'CHHelpers'.default.bConsiderAlliesforSoundAlerts wherever you need to check this.

But even if using a function, it can be simplified to:

static function bool ConsiderAlliesforSoundAlerts()
{
    return default.bConsiderAlliesforSoundAlerts;
}

Also, your function has no return value for when default.bConsiderAlliesforSoundAlerts is false. It will still return false as that is the default value for bool values, but it's not a proper way to do things.

{
if(default.bConsiderAlliesforSoundAlerts)
{
return true;
}
}
// end issue #620
Original file line number Diff line number Diff line change
Expand Up @@ -9667,7 +9667,24 @@ function EventListenerReturn OnAbilityActivated(Object EventData, Object EventSo
GetKeystoneVisibilityLocation(SoundTileLocation);
}

GetEnemiesInRange(SoundTileLocation, SoundRange, Enemies);
/// HL-Docs: feature:ConsiderAlliesforSoundAlerts; issue:620; tags:tactical
/// if enabled then use our private function GetUnitsInRange
/// Gather the units in sound range of this weapon to include sound from allied weapon fire.
/// By default the base game code only checks for sound from enemy units
/// But it makes sense that sound can be heard from anyone firing a weapon, not just enemies
/// Note that this will not have any affect unless a mod has turned on
/// yellow alerts in ShouldEnemyFactionsTriggerAlertsOutsidePlayerVision in XComGameState_AIUnitData
/// Since by default alert data is not recorded for sound outside of XCom's vision
// start issue #620
if( class'CHHelpers'.static.ConsiderAlliesforSoundAlerts() )
{
GetUnitsInRange(SoundTileLocation, SoundRange, Enemies);
}
else
{ // Default behavior
GetEnemiesInRange(SoundTileLocation, SoundRange, Enemies);
}
// end issue #620

`LogAI("Weapon sound @ Tile("$SoundTileLocation.X$","@SoundTileLocation.Y$","@SoundTileLocation.Z$") - Found"@Enemies.Length@"enemies in range ("$SoundRange$" meters)");
foreach Enemies(EnemyRef)
Expand Down Expand Up @@ -10861,6 +10878,47 @@ function GetUnitsInRangeOnTeam(ETeam Team, TTile kLocation, int nMeters, out arr
}
// End Issue #510

/// HL-Docs: ref:ConsiderAlliesforSoundAlerts
// start issue #620
// Copied from XComGameState_Unit::GetEnemiesInRange, except will include all units within
// the specified range.
private function GetUnitsInRange(TTile kLocation, int nMeters, out array<StateObjectReference> OutEnemies)
{
local vector vCenter, vLoc;
local float fDistSq;
local XComGameState_Unit kUnit;
local XComGameStateHistory History;
local eTeam Team;
local float AudioDistanceRadius, UnitHearingRadius, RadiiSumSquared;

History = `XCOMHISTORY;
vCenter = `XWORLD.GetPositionFromTileCoordinates(kLocation);
AudioDistanceRadius = `METERSTOUNITS(nMeters);
fDistSq = Square(AudioDistanceRadius);

foreach History.IterateByClassType(class'XComGameState_Unit', kUnit)
{
Team = kUnit.GetTeam();
if( Team != eTeam_Neutral && kUnit.IsAlive() )
{
vLoc = `XWORLD.GetPositionFromTileCoordinates(kUnit.TileLocation);
UnitHearingRadius = kUnit.GetCurrentStat(eStat_HearingRadius);

RadiiSumSquared = fDistSq;
if( UnitHearingRadius != 0 )
{
RadiiSumSquared = Square(AudioDistanceRadius + UnitHearingRadius);
}

if( VSizeSq(vLoc - vCenter) < RadiiSumSquared )
{
OutEnemies.AddItem(kUnit.GetReference());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're collecting units, not enemies, would make sense for the array to be called OutUnits rather than OutEnemies.

}
}
}
}
// end issue #620

native function float GetConcealmentDetectionDistance(const ref XComGameState_Unit DetectorUnit);

simulated function bool CanFlank(bool bAllowMelee = false)
Expand Down