Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
FireExtinguisherAffector.cpp
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5
6 For more information, see http://www.rigsofrods.org/
7
8 Rigs of Rods is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 3, as
10 published by the Free Software Foundation.
11
12 Rigs of Rods is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#ifdef USE_ANGELSCRIPT
22
24
25#include "Application.h"
26
27#include <OgreParticleSystem.h>
28#include <OgreParticle.h>
29#include <OgreStringConverter.h>
30#include <OgreParticleSystemManager.h>
31#include <OgreParticle.h>
32
34
35
36namespace Ogre {
37
38// Instantiate statics
39FireExtinguisherAffector::CmdEffectiveness FireExtinguisherAffector::msEffectivenessCmd;
40
41//-----------------------------------------------------------------------
43 : ParticleAffector(psys)
44{
45 mType = "FireExtinguisher";
46
47 // defaults
48 mEffectiveness = 1.0;
49 mEfaf = 0;
50
51 // Set up parameters
52 if (createParamDictionary("FireExtinguisherAffector"))
53 {
54 addBaseParameters();
55 // Add extra paramaters
56 ParamDictionary* dict = getParamDictionary();
57 dict->addParameter(ParameterDef("effectiveness",
58 "How effective is your fire extinguisher? Anything higher than one is more effective than water while everything lower than one is less effective than water.",
59 PT_REAL), &msEffectivenessCmd);
60 }
61
62 // get fire affector factory
63 ParticleSystemManager::ParticleAffectorFactoryIterator pafi = ParticleSystemManager::getSingleton().getAffectorFactoryIterator();
64 ParticleAffectorFactory *paf;
65
66 while(pafi.hasMoreElements())
67 {
68 paf = pafi.getNext();
69 if ( paf->getName() == "ExtinguishableFire" )
70 {
72 break;
73 }
74 }
75 if (!mEfaf) LOG("ERROR: Couldn't find an ExtinguishableFireAffectorFactory instance. Was it registered in the content manager?");
76}
77//-----------------------------------------------------------------------
78void FireExtinguisherAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
79{
82
83 while(affIt.hasMoreElements())
84 {
85 fire = (ExtinguishableFireAffector*)affIt.getNext();
86
87 if (fire->isTemplate())
88 continue;
89
90 Real squaredRadius = Math::Pow(fire->getRadius(), 2);
91 Vector3 middlePoint = fire->getAbsoluteMiddlePoint();
92
93 ParticleIterator pi = pSystem->_getIterator();
94 Particle *p;
95 int fireHits = 0;
96 while (!pi.end())
97 {
98 p = pi.getNext();
99
100 if ( middlePoint.squaredDistance(p->mPosition) < squaredRadius )
101 {
102 // This particle is inside the fire, dispose of it in the next update
103 p->mTimeToLive = 0;
104 ++fireHits;
105 }
106 }
107 if (fireHits>0)
108 {
109 Real intensity = fire->reduceIntensity(fireHits*mEffectiveness);
110 if (intensity<0) delete fire->getParticleSystem();
111 }
112 }
113}
114//-----------------------------------------------------------------------
116{
117 mEffectiveness = effectiveness;
118}
119//-----------------------------------------------------------------------
121{
122 return mEffectiveness;
123}
124
125//-----------------------------------------------------------------------
126//-----------------------------------------------------------------------
127// Command objects
128//-----------------------------------------------------------------------
129//-----------------------------------------------------------------------
131{
132 return StringConverter::toString(
133 static_cast<const FireExtinguisherAffector*>(target)->getEffectiveness() );
134
135}
136void FireExtinguisherAffector::CmdEffectiveness::doSet(void* target, const String& val)
137{
138 static_cast<FireExtinguisherAffector*>(target)->setEffectiveness(
139 StringConverter::parseReal(val));
140}
141
142} // namespace Ogre
143
144
145#endif //USE_ANGELSCRIPT
146
Central state/object manager and communications hub.
void LOG(const char *msg)
Legacy alias - formerly a macro.
Factory class for DeflectorPlaneAffector.
affectorIterator getAffectorIterator()
Allow external access to the mFactories iterator.
VectorIterator< vector< ParticleAffector * >::type > affectorIterator
This class defines a ParticleAffector which deflects particles.
This class defines a ParticleAffector which deflects particles.
void setEffectiveness(Real effectiveness)
Sets the bounce value of the deflection.
ExtinguishableFireAffectorFactory * mEfaf
void _affectParticles(ParticleSystem *pSystem, Real timeElapsed)
See ParticleAffector.
Real getEffectiveness(void) const
Gets the bounce value of the deflection.
static CmdEffectiveness msEffectivenessCmd
Command objects.
FireExtinguisherAffector(ParticleSystem *psys)
Default constructor.
Real mEffectiveness
effectiveness factor (1 means as effective as water, everything higher is more effective while anythi...
Real getRadius(void) const
Gets the radius for the interaction with the FireExtiniguisher affector.