123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- enum ESmokeGrenadeState
- {
- NO_SMOKE = 0
- START = 1,
- LOOP = 2,
- END = 3,
- //! ---
- COUNT = 4
- }
- class SmokeGrenadeBase extends Grenade_Base
- {
- protected ref Timer m_TimerSmokeStart;
- protected ref Timer m_TimerSmokeLoop;
- protected ref Timer m_TimerSmokeEnd;
-
- protected ref Timer m_TimerDefer;
-
- protected ESmokeGrenadeState m_SmokeGrenadeState;
- protected ESmokeGrenadeState m_LastSmokeGrenadeState;
- //! particle
- protected Particle m_ParticleSmoke;
- protected int m_ParticleSmokeCurrentId;
- protected int m_ParticleSmokeStartId;
- protected int m_ParticleSmokeLoopId;
- protected int m_ParticleSmokeEndId;
- protected vector m_ParticleSmokePosition;
-
- //! sounds
- protected EffectSound m_SoundSmoke;
- protected string m_SoundSmokeStartId;
- protected string m_SoundSmokeLoopId;
- protected string m_SoundSmokeEndId;
-
- //! Noise
- ref NoiseParams m_NoisePar;
- void SetParticleSmokeCurrent(int particle)
- {
- m_ParticleSmokeCurrentId = particle;
- }
-
- void SetParticleSmokeStart(int particle)
- {
- m_ParticleSmokeStartId = particle;
- }
- void SetParticleSmokeLoop(int particle)
- {
- m_ParticleSmokeLoopId = particle;
- }
- void SetParticleSmokeEnd(int particle)
- {
- m_ParticleSmokeEndId = particle;
- }
-
- void SetSoundSmokeStart(string sound)
- {
- m_SoundSmokeStartId = sound;
- }
- void SetSoundSmokeLoop(string sound)
- {
- m_SoundSmokeLoopId = sound;
- }
- void SetSoundSmokeEnd(string sound)
- {
- m_SoundSmokeEndId = sound;
- }
- protected void PlaySmokeParticle()
- {
- m_ParticleSmoke = ParticleManager.GetInstance().PlayOnObject(m_ParticleSmokeCurrentId, this, m_ParticlePosition, vector.Zero, true);
- }
- protected void SoundSmokeStart()
- {
- PlaySoundSetLoop(m_SoundSmoke, m_SoundSmokeStartId, 0.3, 1.0);
- }
-
- protected void SoundSmokeLoop()
- {
- PlaySoundSetLoop(m_SoundSmoke, m_SoundSmokeLoopId, 0.3, 1.0);
- }
- protected void SoundSmokeEnd()
- {
- PlaySoundSetLoop(m_SoundSmoke, m_SoundSmokeEndId, 1.0, 1.0);
- }
-
- //Stop
- protected void SoundSmokeStop()
- {
- StopSoundSet(m_SoundSmoke);
- }
- protected void DestroySmokeGrenade()
- {
- SetSmokeGrenadeState(ESmokeGrenadeState.NO_SMOKE);
-
- if ( GetGame().IsServer() )
- {
- SetHealth("", "", 0);
- }
- }
-
- protected void RefreshParticlesAndSounds()
- {
- ESmokeGrenadeState state = GetSmokeGrenadeState();
- if ( m_LastSmokeGrenadeState != state )
- {
- if ( state == ESmokeGrenadeState.START )
- {
- //Print("RefreshAudioVisual:: START");
- SoundSmokeEnd();
- SoundSmokeStart();
-
- DestroyParticle(m_ParticleSmoke);
- SetParticleSmokeCurrent(m_ParticleSmokeStartId);
- PlaySmokeParticle();
- }
- else if ( state == ESmokeGrenadeState.LOOP )
- {
- //Print("RefreshAudioVisual:: LOOP");
- SoundSmokeStop();
- SoundSmokeLoop();
-
- DestroyParticle(m_ParticleSmoke);
- SetParticleSmokeCurrent(m_ParticleSmokeLoopId);
- PlaySmokeParticle();
- }
- else if ( state == ESmokeGrenadeState.END )
- {
- //Print("RefreshAudioVisual:: END");
- SoundSmokeStop();
- SoundSmokeEnd();
-
- DestroyParticle(m_ParticleSmoke);
- SetParticleSmokeCurrent(m_ParticleSmokeEndId);
- PlaySmokeParticle();
- }
- else if ( state == ESmokeGrenadeState.NO_SMOKE )
- {
- //Print("RefreshAudioVisual:: NO_SMOKE");
- SoundSmokeStop();
- DestroyParticle(m_ParticleSmoke);
- }
-
- m_LastSmokeGrenadeState = state;
- }
- }
-
- override void Unpin()
- {
- super.Unpin();
-
- Activate();
- }
-
- override void OnActivateFinished()
- {
- if ( GetCompEM() && GetCompEM().CanWork() )
- {
- GetCompEM().SwitchOn();
- }
- }
-
- // When smoke starts
- override void OnWorkStart()
- {
- SetSmokeGrenadeState(ESmokeGrenadeState.START);
-
- if ( GetGame().IsServer() )
- {
- m_NoisePar = new NoiseParams();
- m_NoisePar.LoadFromPath("cfgVehicles " + GetType() + " NoiseSmokeGrenade");
- NoiseSystem noise = GetGame().GetNoiseSystem();
- if ( noise )
- {
- noise.AddNoisePos( this, GetPosition(), m_NoisePar, NoiseAIEvaluate.GetNoiseReduction(GetGame().GetWeather()) );
- }
- }
- Param1<ESmokeGrenadeState> par = new Param1<ESmokeGrenadeState>(ESmokeGrenadeState.LOOP);
- m_TimerSmokeLoop.Run(5.0, this, "SetSmokeGrenadeState", par);
- }
-
- //When grenade makes smoke
- override void OnWork(float consumed_energy)
- {
- if ( GetGame().IsServer() )
- {
- NoiseSystem noise = GetGame().GetNoiseSystem();
- if ( noise )
- {
- noise.AddNoisePos( this, GetPosition(), m_NoisePar, NoiseAIEvaluate.GetNoiseReduction(GetGame().GetWeather()));
- }
- }
- }
-
- // When the smoke stops
- override void OnWorkStop()
- {
- SetSmokeGrenadeState(ESmokeGrenadeState.END);
- //! defer timer
- m_TimerDefer.Run(5.0, this, "DestroySmokeGrenade");
- }
-
- override bool CanPutInCargo( EntityAI parent )
- {
- return !GetCompEM().IsWorking();
- }
-
- override void OnActivatedByItem(notnull ItemBase item)
- {
- GetCompEM().SwitchOn();
- }
- override void SetActions()
- {
- super.SetActions();
- RemoveAction(ActionPin);
- }
-
- override void OnVariablesSynchronized()
- {
- super.OnVariablesSynchronized();
- RefreshParticlesAndSounds();
- }
- override void OnExplosionEffects(Object source, Object directHit, int componentIndex, string surface, vector pos, vector surfNormal, float energyFactor, float explosionFactor, bool isWater, string ammoType) {}
-
- ESmokeGrenadeState GetSmokeGrenadeState()
- {
- return m_SmokeGrenadeState;
- }
- override void EEDelete(EntityAI parent)
- {
- super.EEDelete(parent);
- SoundSmokeStop();
- DestroyParticle(m_ParticleSmoke);
- }
- void SetSmokeGrenadeState(ESmokeGrenadeState state)
- {
- //Print("Setting SGS to: " + typename.EnumToString(ESmokeGrenadeState, state));
- if ( GetGame().IsServer() )
- {
- if ( m_SmokeGrenadeState != state )
- {
- m_SmokeGrenadeState = state;
-
- //synchronize
- SetSynchDirty();
- }
- }
- }
-
- void SmokeGrenadeBase()
- {
- m_SmokeGrenadeState = ESmokeGrenadeState.NO_SMOKE;
- m_TimerSmokeLoop = new Timer;
- m_TimerDefer = new Timer;
- SetAmmoType("");
- SetPinnable(false);
- SetGrenadeType(EGrenadeType.CHEMICAL);
- SetParticleSmokeStart(ParticleList.INVALID); //! no effect on base
- SetParticleSmokeLoop(ParticleList.INVALID); //! no effect on base
- SetParticleSmokeEnd(ParticleList.INVALID); //! no effect on base
- RegisterNetSyncVariableInt("m_SmokeGrenadeState", ESmokeGrenadeState.NO_SMOKE, ESmokeGrenadeState.COUNT);
- }
-
- void ~SmokeGrenadeBase();
- }
|