RigsofRods
Soft-body Physics Simulation
ExtinguishableFireAffector.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 #include "ScriptEngine.h"
27 
28 #include <OgreParticleSystem.h>
29 #include <OgreParticle.h>
30 #include <OgreStringConverter.h>
31 #include <OgreSceneNode.h>
32 
33 using namespace RoR;
34 
35 namespace Ogre {
36 
37 // Instantiate statics
38 ExtinguishableFireAffector::CmdMiddlePoint ExtinguishableFireAffector::msMiddlePointCmd;
39 ExtinguishableFireAffector::CmdIntensity ExtinguishableFireAffector::msIntensityCmd;
40 ExtinguishableFireAffector::CmdMaxIntensity ExtinguishableFireAffector::msMaxIntensityCmd;
41 ExtinguishableFireAffector::CmdIntensityGrowth ExtinguishableFireAffector::msIntensityGrowthCmd;
42 ExtinguishableFireAffector::CmdRadius ExtinguishableFireAffector::msRadiusCmd;
43 
44 //-----------------------------------------------------------------------
45 ExtinguishableFireAffector::ExtinguishableFireAffector(ParticleSystem* psys)
46  : ParticleAffector(psys), mPsys(psys)
47 {
48  mType = "ExtinguishableFire";
49 
50  // defaults
51  mMiddlePoint = Vector3::ZERO;
52  mRadius = 1.0;
53  mIntensity = 3000.0;
55  mIntensityGrowth = 10;
56  mMaxIntensity = 4000.0;
58  firstFrame = true;
59 
60  // Set up parameters
61  if (createParamDictionary("ExtinguishableFireAffector"))
62  {
63  addBaseParameters();
64  // Add extra paramaters
65  ParamDictionary* dict = getParamDictionary();
66  dict->addParameter(ParameterDef("middle_point",
67  "The middle point of the sphere on which water particles will interact.",
68  PT_VECTOR3), &msMiddlePointCmd);
69  dict->addParameter(ParameterDef("intensity",
70  "The amount of water particles that a fire can withstand before being extinguished.",
71  PT_REAL), &msIntensityCmd);
72  dict->addParameter(ParameterDef("max_intensity",
73  "The maximum intensity the fire can grow to.",
74  PT_REAL), &msMaxIntensityCmd);
75  dict->addParameter(ParameterDef("intensity_growth",
76  "The amount by which the intensity of the fire grows per second.",
77  PT_REAL), &msMaxIntensityCmd);
78  dict->addParameter(ParameterDef("radius",
79  "The radius of the sphere.",
80  PT_REAL), &msRadiusCmd);
81  }
82 
83  // predefine objectInstanceName
84  objectInstanceName = "unknown";
85 
87 }
88 //-----------------------------------------------------------------------
90 {
92 }
93 //-----------------------------------------------------------------------
94 void ExtinguishableFireAffector::_affectParticles(ParticleSystem* pSystem, Real timeElapsed)
95 {
96  if (firstFrame)
97  {
98  originalDimensions = Vector2(pSystem->getDefaultWidth(), pSystem->getDefaultHeight());
100  firstFrame = false;
101  }
102 
103  if (mIntensity < 0)
104  {
105  // The fire is extinguished (normally, this particleSystem should get deleted by the fire extinguisher, before this can happen)
106  mPsys->removeAllEmitters();
107  }
108  else
109  {
111  // No water is hitting the fire at the moment, so let's increase the fire intensity a little bit
112  mIntensity += mIntensityGrowth*timeElapsed;
114  }
115 
117  {
118  // update the fire
120  updateIntensityRequired = false;
122  }
123  }
124 }
125 //-----------------------------------------------------------------------
127 {
128  mMiddlePoint = pos;
129 }
130 //-----------------------------------------------------------------------
132 {
133  mIntensity = intensity;
134 }
135 //-----------------------------------------------------------------------
137 {
138  mMaxIntensity = intensity;
139 }
140 //-----------------------------------------------------------------------
142 {
143  mIntensityGrowth = intensity;
144 }
145 //-----------------------------------------------------------------------
147 {
148  mRadius = radius;
149 }
150 
151 //-----------------------------------------------------------------------
153 {
154  return mMiddlePoint;
155 }
156 //-----------------------------------------------------------------------
158 {
159  Node* node = mPsys->getParentNode();
160  if (!node) return mMiddlePoint;
161  return node->convertLocalToWorldPosition(mMiddlePoint);;
162 }
163 //-----------------------------------------------------------------------
165 {
166  return mIntensity;
167 }
168 //-----------------------------------------------------------------------
170 {
171  return mMaxIntensity;
172 }
173 //-----------------------------------------------------------------------
175 {
176  return mIntensityGrowth;
177 }
178 //-----------------------------------------------------------------------
180 {
181  return mRadius;
182 }
183 
184 //-----------------------------------------------------------------------
185 //-----------------------------------------------------------------------
186 // Command objects
187 //-----------------------------------------------------------------------
188 //-----------------------------------------------------------------------
190 {
191  return StringConverter::toString(
192  static_cast<const ExtinguishableFireAffector*>(target)->getMiddlePoint() );
193 }
194 void ExtinguishableFireAffector::CmdMiddlePoint::doSet(void* target, const String& val)
195 {
196  static_cast<ExtinguishableFireAffector*>(target)->setMiddlePoint(
197  StringConverter::parseVector3(val));
198 }
199 //-----------------------------------------------------------------------
200 String ExtinguishableFireAffector::CmdIntensity::doGet(const void* target) const
201 {
202  return StringConverter::toString(
203  static_cast<const ExtinguishableFireAffector*>(target)->getIntensity() );
204 
205 }
206 void ExtinguishableFireAffector::CmdIntensity::doSet(void* target, const String& val)
207 {
208  static_cast<ExtinguishableFireAffector*>(target)->setIntensity(
209  StringConverter::parseReal(val));
210 }
211 //-----------------------------------------------------------------------
213 {
214  return StringConverter::toString(
215  static_cast<const ExtinguishableFireAffector*>(target)->getMaxIntensity() );
216 
217 }
218 void ExtinguishableFireAffector::CmdMaxIntensity::doSet(void* target, const String& val)
219 {
220  static_cast<ExtinguishableFireAffector*>(target)->setMaxIntensity(
221  StringConverter::parseReal(val));
222 }
223 //-----------------------------------------------------------------------
225 {
226  return StringConverter::toString(
227  static_cast<const ExtinguishableFireAffector*>(target)->getIntensityGrowth() );
228 
229 }
230 void ExtinguishableFireAffector::CmdIntensityGrowth::doSet(void* target, const String& val)
231 {
232  static_cast<ExtinguishableFireAffector*>(target)->setIntensityGrowth(
233  StringConverter::parseReal(val));
234 }
235 //-----------------------------------------------------------------------
236 String ExtinguishableFireAffector::CmdRadius::doGet(const void* target) const
237 {
238  return StringConverter::toString(
239  static_cast<const ExtinguishableFireAffector*>(target)->getRadius() );
240 
241 }
242 void ExtinguishableFireAffector::CmdRadius::doSet(void* target, const String& val)
243 {
244  static_cast<ExtinguishableFireAffector*>(target)->setRadius(
245  StringConverter::parseReal(val));
246 }
247 //------------------------------------------------------------------------
249 {
250  return !(mPsys->getParentNode());
251 }
253 {
254  mIntensity -= amount;
256  return mIntensity;
257 }
258 
259 }
260 
261 #endif // USE_ANGELSCRIPT
Ogre::ExtinguishableFireAffector::CmdMiddlePoint::doSet
void doSet(void *target, const String &val)
Definition: ExtinguishableFireAffector.cpp:194
Ogre::ExtinguishableFireAffector::mMiddlePoint
Vector3 mMiddlePoint
sphere middle point
Definition: ExtinguishableFireAffector.h:145
Ogre::ExtinguishableFireAffector::originalIntensity
Real originalIntensity
Definition: ExtinguishableFireAffector.h:155
Ogre::ExtinguishableFireAffector::setMiddlePoint
void setMiddlePoint(const Vector3 &pos)
Sets the sphere middle point.
Definition: ExtinguishableFireAffector.cpp:126
Ogre::ExtinguishableFireAffector::getIntensityGrowth
Real getIntensityGrowth(void) const
Gets the intensity growth rate.
Definition: ExtinguishableFireAffector.cpp:174
Ogre::ExtinguishableFireAffector::setIntensity
void setIntensity(Real intensity)
Sets the intensity.
Definition: ExtinguishableFireAffector.cpp:131
Ogre::ExtinguishableFireAffector::getRadius
Real getRadius(void) const
Gets the radius for the interaction with the FireExtiniguisher affector.
Definition: ExtinguishableFireAffector.cpp:179
Ogre::ExtinguishableFireAffector::CmdMiddlePoint::doGet
String doGet(const void *target) const
Definition: ExtinguishableFireAffector.cpp:189
ExtinguishableFireAffector.h
Ogre::ExtinguishableFireAffector::getAbsoluteMiddlePoint
Vector3 getAbsoluteMiddlePoint(void) const
Definition: ExtinguishableFireAffector.cpp:157
Ogre::ExtinguishableFireAffector::msRadiusCmd
static CmdRadius msRadiusCmd
Definition: ExtinguishableFireAffector.h:141
Ogre::ExtinguishableFireAffector::setMaxIntensity
void setMaxIntensity(Real intensity)
Sets the maximum intensity.
Definition: ExtinguishableFireAffector.cpp:136
Ogre::ExtinguishableFireAffector::mPsys
ParticleSystem * mPsys
Definition: ExtinguishableFireAffector.h:153
RoR::App::GetScriptEngine
ScriptEngine * GetScriptEngine()
Definition: Application.cpp:278
Ogre::ExtinguishableFireAffector::msMaxIntensityCmd
static CmdMaxIntensity msMaxIntensityCmd
Definition: ExtinguishableFireAffector.h:139
Ogre::ExtinguishableFireAffector::mIntensityGrowth
Real mIntensityGrowth
Definition: ExtinguishableFireAffector.h:159
Ogre::ExtinguishableFireAffector::mRadius
Real mRadius
radius of the sphere
Definition: ExtinguishableFireAffector.h:148
Ogre::ExtinguishableFireAffector::CmdIntensity
Command object for intensity (see ParamCommand).
Definition: ExtinguishableFireAffector.h:57
Ogre::ExtinguishableFireAffector::CmdMiddlePoint
Command object for middle point (see ParamCommand).
Definition: ExtinguishableFireAffector.h:49
Ogre::ExtinguishableFireAffector::msIntensityCmd
static CmdIntensity msIntensityCmd
Definition: ExtinguishableFireAffector.h:138
Ogre::ExtinguishableFireAffector::CmdIntensityGrowth::doGet
String doGet(const void *target) const
Definition: ExtinguishableFireAffector.cpp:224
ScriptEngine.h
Ogre::ExtinguishableFireAffector::getMaxIntensity
Real getMaxIntensity(void) const
Gets the maximum intensity.
Definition: ExtinguishableFireAffector.cpp:169
Ogre::ExtinguishableFireAffector::reduceIntensity
Real reduceIntensity(Real amount)
Definition: ExtinguishableFireAffector.cpp:252
Ogre::ExtinguishableFireAffector::CmdRadius
Command object for radius (see ParamCommand).
Definition: ExtinguishableFireAffector.h:81
Ogre::ExtinguishableFireAffector::CmdMaxIntensity::doSet
void doSet(void *target, const String &val)
Definition: ExtinguishableFireAffector.cpp:218
Ogre::ExtinguishableFireAffector::CmdIntensity::doGet
String doGet(const void *target) const
Definition: ExtinguishableFireAffector.cpp:200
Application.h
Central state/object manager and communications hub.
Ogre::ExtinguishableFireAffector::msMiddlePointCmd
static CmdMiddlePoint msMiddlePointCmd
Command objects.
Definition: ExtinguishableFireAffector.h:134
Ogre::ExtinguishableFireAffector::getMiddlePoint
Vector3 getMiddlePoint(void) const
Gets the sphere middle point.
Definition: ExtinguishableFireAffector.cpp:152
Ogre::ExtinguishableFireAffector::CmdIntensityGrowth
Command object for intensity growth (see ParamCommand).
Definition: ExtinguishableFireAffector.h:73
Ogre::ExtinguishableFireAffector::CmdRadius::doSet
void doSet(void *target, const String &val)
Definition: ExtinguishableFireAffector.cpp:242
Ogre::ExtinguishableFireAffector
This class defines a ParticleAffector which deflects particles.
Definition: ExtinguishableFireAffector.h:45
Ogre::ExtinguishableFireAffector::isTemplate
bool isTemplate() const
Definition: ExtinguishableFireAffector.cpp:248
Ogre::ExtinguishableFireAffector::getIntensity
Real getIntensity(void) const
Gets the intensity.
Definition: ExtinguishableFireAffector.cpp:164
Ogre::ExtinguishableFireAffector::setIntensityGrowth
void setIntensityGrowth(Real intensity)
Sets the intensity growth rate.
Definition: ExtinguishableFireAffector.cpp:141
RoR::ScriptEngine::fireEvent
int fireEvent(std::string instanceName, float intensity)
Definition: ScriptEngine.cpp:413
Ogre::ExtinguishableFireAffector::CmdIntensity::doSet
void doSet(void *target, const String &val)
Definition: ExtinguishableFireAffector.cpp:206
Ogre::ExtinguishableFireAffector::updateIntensityRequired
bool updateIntensityRequired
Definition: ExtinguishableFireAffector.h:156
Ogre::ExtinguishableFireAffector::CmdRadius::doGet
String doGet(const void *target) const
Definition: ExtinguishableFireAffector.cpp:236
Ogre::ExtinguishableFireAffector::setRadius
void setRadius(Real radius)
Sets the radius for the interaction with the FireExtiniguisher affector.
Definition: ExtinguishableFireAffector.cpp:146
Ogre::ExtinguishableFireAffector::~ExtinguishableFireAffector
~ExtinguishableFireAffector()
Destructor.
Definition: ExtinguishableFireAffector.cpp:89
Ogre::ExtinguishableFireAffector::objectInstanceName
String objectInstanceName
The instance name of the parent object.
Definition: ExtinguishableFireAffector.h:163
Ogre
Definition: ExtinguishableFireAffector.cpp:35
Ogre::ExtinguishableFireAffector::firstFrame
bool firstFrame
Definition: ExtinguishableFireAffector.h:158
Ogre::ExtinguishableFireAffector::CmdIntensityGrowth::doSet
void doSet(void *target, const String &val)
Definition: ExtinguishableFireAffector.cpp:230
Ogre::ExtinguishableFireAffector::mIntensity
Real mIntensity
Intensity of the fire.
Definition: ExtinguishableFireAffector.h:151
Ogre::ExtinguishableFireAffector::CmdMaxIntensity
Command object for maximum intensity (see ParamCommand).
Definition: ExtinguishableFireAffector.h:65
Ogre::ExtinguishableFireAffector::mMaxIntensity
Real mMaxIntensity
Definition: ExtinguishableFireAffector.h:160
Ogre::ExtinguishableFireAffector::_affectParticles
void _affectParticles(ParticleSystem *pSystem, Real timeElapsed)
See ParticleAffector.
Definition: ExtinguishableFireAffector.cpp:94
Ogre::ExtinguishableFireAffector::originalDimensions
Vector2 originalDimensions
Definition: ExtinguishableFireAffector.h:157
Ogre::ExtinguishableFireAffector::CmdMaxIntensity::doGet
String doGet(const void *target) const
Definition: ExtinguishableFireAffector.cpp:212
RoR
Definition: AppContext.h:36