File size: 3,109 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
/**
\brief Static data holder for certain ammo config values
\note Kept the names similar to what is in config, but it might be a little deceiving as this is mainly used for explosives
*/
class AmmoEffects
{
//! Key: Ammo class name; Data: ParticleList ID
static ref map<string, int> m_AmmoParticles;
//! Key: Ammo class name; Data: ParticleList ID
static ref map<string, typename> m_AmmoEffects;
/** \name Ammo particles
Methods regarding getting/playing ammo particle
*/
//@{
//! Get the ParticleList ID for the particle for this ammoType
static int GetAmmoParticleID(string ammoType)
{
int particleID;
// Search for it in the static map
if ( !m_AmmoParticles.Find(ammoType, particleID) )
{
// Load it in when we can't find it
string particleFileName;
GetGame().ConfigGetText(string.Format("cfgAmmo %1 particle", ammoType), particleFileName);
// If we found a valid entry, try looking for it in ParticleList
if ( particleFileName != "" )
{
particleID = ParticleList.GetParticleIDByName(particleFileName);
}
// Store it for next search
m_AmmoParticles.Insert(ammoType, particleID);
}
return particleID;
}
//! Attempt to play the ammo particle at pos if found, returns true on success
static bool PlayAmmoParticle(string ammoType, vector pos)
{
int particleID = GetAmmoParticleID(ammoType);
if (ParticleList.IsValidId(particleID))
{
return ParticleManager.GetInstance().PlayInWorld(particleID, pos) != null;
}
return false;
}
//@}
/** \name Ammo effects
Methods regarding getting/playing ammo effect
*/
//@{
//! Get the typename for the effect for this ammoType
static typename GetAmmoEffectTypename(string ammoType)
{
typename typeName;
// Search for it in the static map
if ( !m_AmmoEffects.Find(ammoType, typeName) )
{
// Load it in when we can't find it
string effectName;
GetGame().ConfigGetText(string.Format("cfgAmmo %1 effect", ammoType), effectName);
// If we found a valid entry, try looking for it in ParticleList
if ( effectName != "" )
{
typeName = effectName.ToType();
}
// Store it for next search
m_AmmoEffects.Insert(ammoType, typeName);
}
return typeName;
}
//! Attempt to play the ammo effect at pos if found, returns true on success
static bool PlayAmmoEffect(string ammoType, vector pos)
{
typename typeName = GetAmmoEffectTypename(ammoType);
if ( typeName )
{
Effect eff = Effect.Cast(typeName.Spawn());
if ( eff )
{
eff.SetAutodestroy(true);
return SEffectManager.PlayInWorld( eff, pos );
}
}
return false;
}
//@}
/** \name Lifetime
Creation and cleanup
*/
//@{
//! Initialize the containers: this is done this way, to have these not exist on server
static void Init()
{
m_AmmoParticles = new map<string, int>();
m_AmmoEffects = new map<string, typename>();
}
//! Clean up the data
static void Cleanup()
{
/* These ain't containing no refs, so whatever
m_AmmoParticles.Clear();
m_AmmoEffects.Clear();
*/
}
//@}
} |