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
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
33using namespace RoR;
34
35namespace Ogre {
36
37// Instantiate statics
43
44//-----------------------------------------------------------------------
46 : ParticleAffector(psys), mPsys(psys)
47{
48 mType = "ExtinguishableFire";
49
50 // defaults
51 mMiddlePoint = Vector3::ZERO;
52 mRadius = 1.0;
53 mIntensity = 3000.0;
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//-----------------------------------------------------------------------
93//-----------------------------------------------------------------------
94void 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
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//-----------------------------------------------------------------------
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}
194void ExtinguishableFireAffector::CmdMiddlePoint::doSet(void* target, const String& val)
195{
196 static_cast<ExtinguishableFireAffector*>(target)->setMiddlePoint(
197 StringConverter::parseVector3(val));
198}
199//-----------------------------------------------------------------------
201{
202 return StringConverter::toString(
203 static_cast<const ExtinguishableFireAffector*>(target)->getIntensity() );
204
205}
206void 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}
218void 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}
230void ExtinguishableFireAffector::CmdIntensityGrowth::doSet(void* target, const String& val)
231{
232 static_cast<ExtinguishableFireAffector*>(target)->setIntensityGrowth(
233 StringConverter::parseReal(val));
234}
235//-----------------------------------------------------------------------
236String ExtinguishableFireAffector::CmdRadius::doGet(const void* target) const
237{
238 return StringConverter::toString(
239 static_cast<const ExtinguishableFireAffector*>(target)->getRadius() );
240
241}
242void 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
Central state/object manager and communications hub.
Command object for intensity growth (see ParamCommand).
Command object for intensity (see ParamCommand).
Command object for maximum intensity (see ParamCommand).
Command object for middle point (see ParamCommand).
Command object for radius (see ParamCommand).
This class defines a ParticleAffector which deflects particles.
int fireEvent(std::string instanceName, float intensity)
Real getRadius(void) const
Gets the radius for the interaction with the FireExtiniguisher affector.
void setMaxIntensity(Real intensity)
Sets the maximum intensity.
Vector3 getMiddlePoint(void) const
Gets the sphere middle point.
static CmdMiddlePoint msMiddlePointCmd
Command objects.
Real getMaxIntensity(void) const
Gets the maximum intensity.
void setRadius(Real radius)
Sets the radius for the interaction with the FireExtiniguisher affector.
void setMiddlePoint(const Vector3 &pos)
Sets the sphere middle point.
Real getIntensityGrowth(void) const
Gets the intensity growth rate.
ExtinguishableFireAffector(ParticleSystem *psys)
Default constructor.
String objectInstanceName
The instance name of the parent object.
Real getIntensity(void) const
Gets the intensity.
void setIntensity(Real intensity)
Sets the intensity.
void setIntensityGrowth(Real intensity)
Sets the intensity growth rate.
void _affectParticles(ParticleSystem *pSystem, Real timeElapsed)
See ParticleAffector.
ScriptEngine * GetScriptEngine()