|
|
|
enum eZoneType |
|
{ |
|
STATIC = 1, |
|
DYNAMIC = 2 |
|
} |
|
|
|
|
|
class EffectAreaParams |
|
{ |
|
string m_ParamName = "Default setup"; |
|
string m_ParamTriggerType = "ContaminatedTrigger"; |
|
float m_ParamRadius = 100; |
|
float m_ParamPosHeight = 25; |
|
float m_ParamNegHeight = 10; |
|
int m_ParamInnerRings = 1; |
|
int m_ParamInnerSpace = 35; |
|
bool m_ParamOuterToggle = true; |
|
int m_ParamOuterSpace = 20; |
|
int m_ParamOuterOffset = -5; |
|
int m_ParamVertLayers = 0; |
|
int m_ParamVerticalOffset = 10; |
|
|
|
|
|
|
|
|
|
|
|
int m_ParamPartId = 0; |
|
int m_ParamAroundPartId = 0; |
|
int m_ParamTinyPartId = 0; |
|
|
|
string m_ParamPpeRequesterType = "PPERequester_ContaminatedAreaTint"; |
|
} |
|
|
|
|
|
class EffectArea : House |
|
{ |
|
|
|
string m_Name = "Default setup"; |
|
int m_Type = eZoneType.STATIC; |
|
vector m_Position; |
|
|
|
|
|
float m_Radius = 100; |
|
float m_PositiveHeight = 25; |
|
float m_NegativeHeight = 10; |
|
|
|
|
|
|
|
int m_InnerRings = 1; |
|
int m_InnerSpacing = 35; |
|
|
|
bool m_OuterRingToggle = true; |
|
int m_OuterRingOffset = -5; |
|
int m_OuterSpacing = 20; |
|
|
|
int m_VerticalLayers = 0; |
|
int m_VerticalOffset = 10; |
|
|
|
|
|
int m_ParticleID = ParticleList.CONTAMINATED_AREA_GAS_BIGASS; |
|
int m_AroundParticleID = ParticleList.CONTAMINATED_AREA_GAS_AROUND; |
|
int m_TinyParticleID = ParticleList.CONTAMINATED_AREA_GAS_TINY; |
|
string m_PPERequesterType; |
|
int m_PPERequesterIdx = -1; |
|
int m_EffectsPriority; |
|
|
|
|
|
string m_TriggerType = "ContaminatedTrigger"; |
|
EffectTrigger m_Trigger; |
|
|
|
ref array<Particle> m_ToxicClouds; |
|
|
|
|
|
|
|
|
|
|
|
|
|
void EffectArea() |
|
{ |
|
RegisterNetSyncVariableFloat("m_Radius", 0, 0, 2); |
|
RegisterNetSyncVariableFloat("m_PositiveHeight", 0, 0, 2); |
|
RegisterNetSyncVariableFloat("m_NegativeHeight", 0, 0, 2); |
|
|
|
RegisterNetSyncVariableInt("m_InnerRings"); |
|
RegisterNetSyncVariableInt("m_InnerSpacing"); |
|
RegisterNetSyncVariableInt("m_OuterRingOffset"); |
|
RegisterNetSyncVariableInt("m_OuterSpacing"); |
|
RegisterNetSyncVariableInt("m_VerticalLayers"); |
|
RegisterNetSyncVariableInt("m_VerticalOffset"); |
|
|
|
RegisterNetSyncVariableInt("m_ParticleID"); |
|
|
|
|
|
|
|
|
|
|
|
RegisterNetSyncVariableBool("m_OuterRingToggle"); |
|
} |
|
|
|
void ~EffectArea() |
|
{ |
|
|
|
} |
|
|
|
void SetupZoneData( EffectAreaParams params ) |
|
{ |
|
|
|
if ( params.m_ParamName != "" ) |
|
m_Name = params.m_ParamName; |
|
if ( params.m_ParamTriggerType != "" ) |
|
m_TriggerType = params.m_ParamTriggerType; |
|
|
|
if ( params.m_ParamRadius > 0 ) |
|
m_Radius = params.m_ParamRadius; |
|
if ( params.m_ParamPosHeight > -1 ) |
|
m_PositiveHeight = params.m_ParamPosHeight; |
|
if ( params.m_ParamNegHeight > -1 ) |
|
m_NegativeHeight = params.m_ParamNegHeight; |
|
|
|
m_InnerRings = params.m_ParamInnerRings; |
|
if ( params.m_ParamInnerSpace > -1 ) |
|
m_InnerSpacing = params.m_ParamInnerSpace; |
|
|
|
m_OuterRingToggle = params.m_ParamOuterToggle; |
|
if ( params.m_ParamOuterSpace > -1 ) |
|
m_OuterSpacing = params.m_ParamOuterSpace; |
|
m_OuterRingOffset = params.m_ParamOuterOffset; |
|
|
|
if ( params.m_ParamVertLayers > 0 ) |
|
m_VerticalLayers = params.m_ParamVertLayers; |
|
if ( params.m_ParamVerticalOffset > 0 ) |
|
m_VerticalOffset = params.m_ParamVerticalOffset; |
|
|
|
m_ParticleID = params.m_ParamPartId; |
|
m_AroundParticleID = params.m_ParamAroundPartId; |
|
m_TinyParticleID = params.m_ParamTinyPartId; |
|
|
|
if ( params.m_ParamPpeRequesterType != "" ) |
|
{ |
|
m_PPERequesterType = params.m_ParamPpeRequesterType; |
|
m_PPERequesterIdx = GetRequesterIndex(m_PPERequesterType); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetSynchDirty(); |
|
|
|
|
|
InitZone(); |
|
} |
|
|
|
void Tick() {}; |
|
|
|
|
|
|
|
override void OnCEUpdate() |
|
{ |
|
super.OnCEUpdate(); |
|
Tick(); |
|
} |
|
|
|
void InitZone() |
|
{ |
|
|
|
|
|
|
|
m_Position = GetWorldPosition(); |
|
|
|
if ( !GetGame().IsDedicatedServer() ) |
|
{ |
|
InitZoneClient(); |
|
} |
|
|
|
if ( GetGame().IsServer() ) |
|
{ |
|
InitZoneServer(); |
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
void InitZoneServer() {}; |
|
|
|
void InitZoneClient() {}; |
|
|
|
|
|
|
|
|
|
|
|
override bool CanPutInCargo( EntityAI parent ) |
|
{ |
|
return false; |
|
} |
|
|
|
override bool CanPutIntoHands( EntityAI parent ) |
|
{ |
|
return false; |
|
} |
|
|
|
override bool DisableVicinityIcon() |
|
{ |
|
return true; |
|
} |
|
|
|
override bool CanBeTargetedByAI( EntityAI ai ) |
|
{ |
|
return false; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PlaceParticles( vector pos, float radius, int nbRings, int innerSpacing, bool outerToggle, int outerSpacing, int outerOffset, int partId ) |
|
{ |
|
#ifdef NO_GUI |
|
return; |
|
#endif |
|
if (partId == 0) |
|
{ |
|
Error("[WARNING] :: [EffectArea PlaceParticles] :: no particle defined, skipping area particle generation" ); |
|
return; |
|
} |
|
|
|
bool snapFirstLayer = true; |
|
if ( m_Type == eZoneType.STATIC && pos[1] != GetGame().SurfaceRoadY( pos[0], pos[2] ) ) |
|
snapFirstLayer = false; |
|
|
|
|
|
|
|
if ( radius == 0 ) |
|
{ |
|
|
|
Error("[WARNING] :: [EffectArea PlaceParticles] :: Radius of contaminated zone is set to 0, this should not happen"); |
|
return; |
|
} |
|
|
|
if ( outerToggle && radius == outerOffset ) |
|
{ |
|
Error("[WARNING] :: [EffectArea PlaceParticles] :: Your outerOffset is EQUAL to your Radius, this will result in division by 0"); |
|
return; |
|
} |
|
|
|
|
|
if ( innerSpacing == 0 ) |
|
innerSpacing = 1; |
|
|
|
|
|
|
|
int partCounter = 0; |
|
int numberOfEmitters = 1; |
|
|
|
|
|
|
|
|
|
float angle = 0; |
|
|
|
ParticlePropertiesArray props = new ParticlePropertiesArray(); |
|
|
|
|
|
for ( int k = 0; k <= m_VerticalLayers; k++ ) |
|
{ |
|
vector partPos = pos; |
|
|
|
|
|
if ( k != 0 ) |
|
{ |
|
partPos[1] = partPos[1] + ( m_VerticalOffset * k ); |
|
} |
|
|
|
|
|
props.Insert(ParticleProperties(partPos, ParticlePropertiesFlags.PLAY_ON_CREATION, null, vector.Zero, this)); |
|
partCounter++; |
|
|
|
|
|
for ( int i = 1; i <= nbRings + outerToggle; i++ ) |
|
{ |
|
|
|
|
|
|
|
float angleIncrement; |
|
float ab; |
|
vector temp = vector.Zero; |
|
|
|
|
|
|
|
if ( i > nbRings ) |
|
{ |
|
ab = radius - outerOffset; |
|
|
|
|
|
angleIncrement = Math.Acos( 1 - ( ( outerSpacing * outerSpacing ) / ( 2 * Math.SqrInt(ab) ) ) ); |
|
temp[2] = temp[2] + ab; |
|
|
|
|
|
} |
|
else |
|
{ |
|
ab = ( radius / ( nbRings + 1 ) ) * i; |
|
|
|
|
|
angleIncrement = Math.Acos( 1 - ( ( innerSpacing * innerSpacing ) / ( 2 * Math.SqrInt(ab) ) ) ); |
|
temp[2] = temp[2] + ab; |
|
|
|
|
|
} |
|
|
|
for ( int j = 0; j <= ( Math.PI2 / angleIncrement ); j++ ) |
|
{ |
|
|
|
|
|
|
|
|
|
float sinAngle = Math.Sin( angle ); |
|
float cosAngle = Math.Cos( angle ); |
|
|
|
partPos = vector.RotateAroundZero( temp, vector.Up, cosAngle, sinAngle ); |
|
partPos += pos; |
|
|
|
|
|
if ( k == 0 && snapFirstLayer == true ) |
|
partPos[1] = GetGame().SurfaceY( partPos[0], partPos[2] ); |
|
else if ( k == 0 && snapFirstLayer == false ) |
|
partPos[1] = partPos[1] - m_NegativeHeight; |
|
|
|
|
|
if ( partPos[1] <= pos[1] + m_PositiveHeight && partPos[1] >= pos[1] - m_NegativeHeight ) |
|
{ |
|
|
|
props.Insert(ParticleProperties(partPos, ParticlePropertiesFlags.PLAY_ON_CREATION, null, GetGame().GetSurfaceOrientation( partPos[0], partPos[2] ), this)); |
|
|
|
++partCounter; |
|
} |
|
|
|
|
|
angle += angleIncrement; |
|
} |
|
|
|
angle = 0; |
|
} |
|
} |
|
|
|
m_ToxicClouds.Reserve(partCounter); |
|
|
|
ParticleManager gPM = ParticleManager.GetInstance(); |
|
|
|
array<ParticleSource> createdParticles = gPM.CreateParticlesByIdArr(partId, props, partCounter); |
|
if (createdParticles.Count() != partCounter) |
|
{ |
|
if (gPM.IsFinishedAllocating()) |
|
{ |
|
ErrorEx(string.Format("Not enough particles in pool for EffectArea: %1", m_Name)); |
|
OnParticleAllocation(gPM, createdParticles); |
|
} |
|
else |
|
{ |
|
gPM.GetEvents().Event_OnAllocation.Insert(OnParticleAllocation); |
|
} |
|
} |
|
else |
|
{ |
|
OnParticleAllocation(gPM, createdParticles); |
|
} |
|
|
|
|
|
} |
|
|
|
void OnParticleAllocation(ParticleManager pm, array<ParticleSource> particles) |
|
{ |
|
foreach (ParticleSource p : particles) |
|
{ |
|
if (p.GetOwner() == this) |
|
m_ToxicClouds.Insert(p); |
|
} |
|
} |
|
|
|
int GetRequesterIndex(string type) |
|
{ |
|
typename t = type.ToType(); |
|
if (!t) |
|
return - 1; |
|
PPERequesterBase req = PPERequesterBank.GetRequester(t); |
|
if (req) |
|
return req.GetRequesterIDX(); |
|
return -1; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
void CreateTrigger( vector pos, int radius ) |
|
{ |
|
|
|
pos[1] = pos[1] - m_NegativeHeight; |
|
|
|
|
|
if ( Class.CastTo( m_Trigger, GetGame().CreateObjectEx( m_TriggerType, pos, ECE_NONE ) ) ) |
|
{ |
|
|
|
m_Trigger.SetCollisionCylinder( radius, ( m_NegativeHeight + m_PositiveHeight ) ); |
|
|
|
|
|
if ( m_Trigger.IsInherited( EffectTrigger ) ) |
|
{ |
|
|
|
EffectTrigger.Cast( m_Trigger ).SetLocalEffects( m_AroundParticleID, m_TinyParticleID, m_PPERequesterIdx ); |
|
} |
|
m_Trigger.Init(this, m_EffectsPriority); |
|
|
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
override void EEDelete( EntityAI parent ) |
|
{ |
|
if ( m_Trigger ) |
|
{ |
|
GetGame().ObjectDelete( m_Trigger ); |
|
} |
|
|
|
|
|
if ( (GetGame().IsClient() || !GetGame().IsMultiplayer()) && m_ToxicClouds ) |
|
{ |
|
foreach ( Particle p : m_ToxicClouds ) |
|
{ |
|
p.Stop(); |
|
} |
|
} |
|
|
|
super.EEDelete( parent ); |
|
} |
|
|
|
void OnPlayerEnterServer(PlayerBase player, EffectTrigger trigger) |
|
{ |
|
player.IncreaseEffectAreaCount(); |
|
} |
|
void OnPlayerExitServer(PlayerBase player, EffectTrigger trigger) |
|
{ |
|
player.DecreaseEffectAreaCount(); |
|
} |
|
|
|
} |