[Orxonox-commit 2699] r7404 - in code/trunk: data/levels data/levels/old src/modules/notifications src/modules/objects
dafrick at orxonox.net
dafrick at orxonox.net
Sat Sep 11 14:42:47 CEST 2010
Author: dafrick
Date: 2010-09-11 14:42:47 +0200 (Sat, 11 Sep 2010)
New Revision: 7404
Added:
code/trunk/data/levels/notifications.oxw
Modified:
code/trunk/data/levels/Fight in our Back.oxw
code/trunk/data/levels/Quest_PirateAttack.oxw
code/trunk/data/levels/old/princessaeryn.oxw
code/trunk/data/levels/old/questsystem.oxw
code/trunk/data/levels/princessaeryn.oxw
code/trunk/data/levels/tutorial.oxw
code/trunk/src/modules/notifications/NotificationDispatcher.cc
code/trunk/src/modules/notifications/NotificationDispatcher.h
code/trunk/src/modules/objects/Script.cc
code/trunk/src/modules/objects/Script.h
Log:
Adding new level notifications.oxw, to "showcase", or at this stage rather "test" Notifications.
Restoring tutorial.oxw to its old state, before it was hijacked by me for testing.
Extending Script class. Now also normal orxonox code can be executed with it, the execution of code can be triggered with Triggers (obviously) and cod can also executed on load.
I needed this to load the NotificationLayer in levels where it is needed.
Also inserted a Script that loads the NotificationQueue to display Notifications in all levels it was needed.
Modified: code/trunk/data/levels/Fight in our Back.oxw
===================================================================
--- code/trunk/data/levels/Fight in our Back.oxw 2010-09-11 08:20:44 UTC (rev 7403)
+++ code/trunk/data/levels/Fight in our Back.oxw 2010-09-11 12:42:47 UTC (rev 7404)
@@ -68,6 +68,8 @@
skybox="Orxonox/skypanoramagen1"
>
+ <Script code="showGUI NotificationLayer false true" />
+
<!--Light: noch zu aendern -->
<Light type=directional position="0,0,0" direction="0, 0, 0" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 1.0, 0.9" />
Modified: code/trunk/data/levels/Quest_PirateAttack.oxw
===================================================================
--- code/trunk/data/levels/Quest_PirateAttack.oxw 2010-09-11 08:20:44 UTC (rev 7403)
+++ code/trunk/data/levels/Quest_PirateAttack.oxw 2010-09-11 12:42:47 UTC (rev 7404)
@@ -33,9 +33,12 @@
ambientlight = "0.3, 0.3, 0.3"
skybox = "Orxonox/skypanoramagen1"
>
- <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
-
-
+
+ <Script code="showGUI NotificationLayer false true" />
+
+ <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+
+
<GlobalQuest id="dbd02b4c-ab7c-46fd-bdaf-fd4c19ac1551">
<QuestDescription title="Fight for freedom"
description="Just a few hours ago, a group of pirates attacked an killed all your squad members. Now you are very angry and you want to take revenge. Find the pirates and kill them!"
Added: code/trunk/data/levels/notifications.oxw
===================================================================
--- code/trunk/data/levels/notifications.oxw (rev 0)
+++ code/trunk/data/levels/notifications.oxw 2010-09-11 12:42:47 UTC (rev 7404)
@@ -0,0 +1,50 @@
+<?lua
+ include("hudtemplates3.oxo")
+ include("stats.oxo")
+ include("templates/spaceship_assff.oxt")
+ include("templates/lodinformation.oxt")
+?>
+
+<Level
+ name = "Presentation"
+ description = "A simple testlevel"
+>
+ <templates>
+ <Template link=lodtemplate_default />
+ </templates>
+
+ <Scene
+ ambientlight = "0.5, 0.5, 0.5"
+ skybox = "Orxonox/skypanoramagen1"
+ >
+
+ <Script code="showGUI NotificationLayer false true" />
+
+ <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+
+ <CommandNotification preMessage="Move '" postMessage="' to look left." command="scale 1 rotateYaw">
+ <events>
+ <trigger>
+ <DistanceTrigger name=trigger position="0,0,-100" distance=10 target="Pawn" />
+ </trigger>
+ </events>
+ </CommandNotification>
+ <Billboard position="0,0,-100" colour="1.0,1.0,0" material="Examples/Flare" />
+
+ <SimpleNotification message="Awesome!!!">
+ <events>
+ <trigger>
+ <DistanceTrigger name=trigger position="0,0,100" distance=10 target="Pawn" />
+ </trigger>
+ </events>
+ </SimpleNotification>
+ <Billboard position="0,0,100" colour="1.0,0,1.0" material="Examples/Flare" />
+
+ <?lua
+ for i = 1, 10, 1 do
+ ?>
+ <SpawnPoint position="<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+ <?lua end ?>
+
+ </Scene>
+</Level>
Modified: code/trunk/data/levels/old/princessaeryn.oxw
===================================================================
--- code/trunk/data/levels/old/princessaeryn.oxw 2010-09-11 08:20:44 UTC (rev 7403)
+++ code/trunk/data/levels/old/princessaeryn.oxw 2010-09-11 12:42:47 UTC (rev 7404)
@@ -16,6 +16,9 @@
ambientlight = "0.3, 0.3, 0.3"
skybox = "Orxonox/skypanoramagen1"
>
+
+ <Script code="showGUI NotificationLayer false true" />
+
<Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
<Template name=turboitem baseclass=Turbo>
Modified: code/trunk/data/levels/old/questsystem.oxw
===================================================================
--- code/trunk/data/levels/old/questsystem.oxw 2010-09-11 08:20:44 UTC (rev 7403)
+++ code/trunk/data/levels/old/questsystem.oxw 2010-09-11 12:42:47 UTC (rev 7404)
@@ -13,6 +13,8 @@
skybox = "Orxonox/Starbox"
>
+ <Script code="showGUI NotificationLayer false true" />
+
<GlobalQuest id="b80c2c60-e62c-4637-80f8-5aa18dc93b34">
<QuestDescription title="The Main QUest" description="This is the main quest hooray. Solve it!" failMessage="You fail. Looser." completeMessage="You Win." />
<hints>
Modified: code/trunk/data/levels/princessaeryn.oxw
===================================================================
--- code/trunk/data/levels/princessaeryn.oxw 2010-09-11 08:20:44 UTC (rev 7403)
+++ code/trunk/data/levels/princessaeryn.oxw 2010-09-11 12:42:47 UTC (rev 7404)
@@ -22,6 +22,9 @@
ambientlight = "0.3, 0.3, 0.3"
skybox = "Orxonox/skypanoramagen1"
>
+
+ <Script code="showGUI NotificationLayer false true" /
+
<Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
<!-- Quest: -->
Modified: code/trunk/data/levels/tutorial.oxw
===================================================================
--- code/trunk/data/levels/tutorial.oxw 2010-09-11 08:20:44 UTC (rev 7403)
+++ code/trunk/data/levels/tutorial.oxw 2010-09-11 12:42:47 UTC (rev 7404)
@@ -18,28 +18,31 @@
skybox = "Orxonox/skypanoramagen1"
>
- <CommandNotification preMessage="Move '" postMessage="' to look left." command="scale 1 rotateYaw">
- <events>
- <trigger>
- <DistanceTrigger name=trigger position="0,0,-100" distance=10 target="Pawn" />
- </trigger>
- </events>
- </CommandNotification>
- <Billboard position="0,0,-100" colour="1.0,1.0,0" material="Examples/Flare" />
- <SimpleNotification message="Awesome!!!">
- <events>
- <trigger>
- <DistanceTrigger name=trigger position="0,0,100" distance=10 target="Pawn" />
- </trigger>
- </events>
- </SimpleNotification>
- <Billboard position="0,0,100" colour="1.0,0,1.0" material="Examples/Flare" />
-
+<Drone name="meineDrohne" primarythrust="80" auxilarythrust="10" rotationthrust="10" mass= "50" linearDamping = "0.9" angularDamping = "0.7">
+ <attached>
+ <Model scale="1" mesh="drone.mesh"/>
+ </attached>
+ <collisionShapes>
+ <BoxCollisionShape position="0,0,0" halfExtents="10, 10, 10" />
+ </collisionShapes>
+</Drone>
+
+ <Drone name="meineDrohne" primarythrust="80" auxilarythrust="10" rotationthrust="10" mass= "50" linearDamping = "0.9" angularDamping = "0.7">
+ <attached>
+ <Model scale="1" mesh="rocket.mesh"/>
+ </attached>
+ <collisionShapes>
+ <BoxCollisionShape position="0,0,0" halfExtents="10, 10, 10" />
+ </collisionShapes>
+ </Drone>
+
<Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+ <Model mesh="hs-w01.mesh" scale=10 position="0,0,-100" />
+ <Model mesh="hs-w01s.mesh" scale=10 position="0,0,-100" />
<?lua
for i = 1, 10, 1 do
@@ -47,6 +50,58 @@
<SpawnPoint position="<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>,<?lua print(math.random() * 1000 - 500) ?>" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
<?lua end ?>
+ <GlobalShader compositor="Bloom" visible=false>
+ <events>
+ <visibility>
+ <DistanceTrigger position="0,0,0" distance=30 target="Spectator" switch=true />
+ </visibility>
+ </events>
+ </GlobalShader>
+ <Model position="0,0,0" scale=8 mesh="ast1.mesh" />
+ <StaticEntity position="0,0,0" collisionType=static>
+ <collisionShapes>
+ <SphereCollisionShape radius="20" />
+ </collisionShapes>
+ </StaticEntity>
+<!--
+ <?lua
+ for i = 1, 70, 1 do
+ ?>
+ <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 1000 + 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+ <attached>
+ <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+ </attached>
+ </MovableEntity>
+ <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * -1000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+ <attached>
+ <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+ </attached>
+ </MovableEntity>
+
+ <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * 1000 + 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+ <attached>
+ <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+ </attached>
+ </MovableEntity>
+ <MovableEntity position="<?lua print(math.random() * 6000 - 3000)?>, <?lua print(math.random() * -1000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+ <attached>
+ <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+ </attached>
+ </MovableEntity>
+
+ <MovableEntity position="<?lua print(math.random() * 1000 + 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+ <attached>
+ <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+ </attached>
+ </MovableEntity>
+ <MovableEntity position="<?lua print(math.random() * -1000 - 3000)?>, <?lua print(math.random() * 6000 - 3000) ?>, <?lua print(math.random() * 6000 - 3000) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
+ <attached>
+ <Model scale="<?lua print(math.random() * 30 + 10) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
+ </attached>
+ </MovableEntity>
+ <?lua end ?>
+-->
+
</Scene>
</Level>
Modified: code/trunk/src/modules/notifications/NotificationDispatcher.cc
===================================================================
--- code/trunk/src/modules/notifications/NotificationDispatcher.cc 2010-09-11 08:20:44 UTC (rev 7403)
+++ code/trunk/src/modules/notifications/NotificationDispatcher.cc 2010-09-11 12:42:47 UTC (rev 7404)
@@ -71,18 +71,18 @@
@brief
Method for creating a NotificationDispatcher object through XML.
*/
- void NotificationDispatcher::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ void NotificationDispatcher::XMLPort(Element& xmlElement, XMLPort::Mode mode)
{
- SUPER(NotificationDispatcher, XMLPort, xmlelement, mode);
+ SUPER(NotificationDispatcher, XMLPort, xmlElement, mode);
- XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
+ XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlElement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
}
- void NotificationDispatcher::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
+ void NotificationDispatcher::XMLEventPort(Element& xmlElement, XMLPort::Mode mode)
{
- SUPER(NotificationDispatcher, XMLEventPort, xmlelement, mode);
+ SUPER(NotificationDispatcher, XMLEventPort, xmlElement, mode);
- XMLPortEventState(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode);
+ XMLPortEventState(NotificationDispatcher, BaseObject, "trigger", trigger, xmlElement, mode);
}
/**
Modified: code/trunk/src/modules/notifications/NotificationDispatcher.h
===================================================================
--- code/trunk/src/modules/notifications/NotificationDispatcher.h 2010-09-11 08:20:44 UTC (rev 7403)
+++ code/trunk/src/modules/notifications/NotificationDispatcher.h 2010-09-11 12:42:47 UTC (rev 7404)
@@ -54,8 +54,8 @@
NotificationDispatcher(BaseObject* creator); //!< Default constructor. Initializes the object.
virtual ~NotificationDispatcher(); //!< Destructor.
- virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a NotificationDispatcher object through XML.
- virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
+ virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); //!< Method for creating a NotificationDispatcher object through XML.
+ virtual void XMLEventPort(Element& xmlElement, XMLPort::Mode mode);
/**
@brief Get the sender of the Notification dispatched by this NotificationDispatcher.
Modified: code/trunk/src/modules/objects/Script.cc
===================================================================
--- code/trunk/src/modules/objects/Script.cc 2010-09-11 08:20:44 UTC (rev 7403)
+++ code/trunk/src/modules/objects/Script.cc 2010-09-11 12:42:47 UTC (rev 7404)
@@ -22,13 +22,15 @@
* Author:
* Benjamin Knecht
* Co-authors:
- * ...
+ * Damian 'Mozork' Frick
*
*/
#include "Script.h"
+#include "core/command/CommandExecutor.h"
#include "core/CoreIncludes.h"
+#include "core/EventIncludes.h"
#include "core/LuaState.h"
#include "core/XMLPort.h"
@@ -36,29 +38,167 @@
{
CreateFactory(Script);
+ // Initializing constants.
+ /*static*/ const std::string Script::NORMAL = "normal";
+ /*static*/ const std::string Script::LUA = "lua";
+
+ /**
+ @brief
+ Constructor. Registers and initializes the object.
+ @param creator
+ The creator of this object.
+ */
Script::Script(BaseObject* creator) : BaseObject(creator)
{
RegisterObject(Script);
- // Get a new LuaState
- luaState_ = new LuaState();
+ // Initialize variables.
+ this->luaState_ = NULL;
+ this->remainingExecutions_ = Script::INF;
+
}
+ /**
+ @brief
+ Destructor. Cleans up.
+ */
Script::~Script()
{
- if (this->isInitialized())
- delete luaState_;
+ if(this->isInitialized() && this->luaState_ != NULL)
+ delete this->luaState_;
}
- void Script::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ /**
+ @brief
+ Method for creating a Script object through XML.
+ @param xmlElement
+ The element.
+ @param mode
+ The mode.
+ */
+ void Script::XMLPort(Element& xmlElement, XMLPort::Mode mode)
{
- BaseObject::XMLPort(xmlelement, mode);
+ SUPER(Script, XMLPort, xmlElement, mode);
- XMLPortParam(Script, "code", setCode, getCode, xmlelement, mode);
+ XMLPortParam(Script, "code", setCode, getCode, xmlElement, mode);
+ XMLPortParamTemplate(Script, "mode", setMode, getMode, xmlElement, mode, const std::string&).defaultValues(Script::NORMAL);
+ XMLPortParam(Script, "onLoad", setOnLoad, isOnLoad, xmlElement, mode).defaultValues(true);
+ XMLPortParam(Script, "times", setTimes, getTimes, xmlElement, mode).defaultValues(Script::INF);
+
+ XMLPortEventSink(Script, BaseObject, "trigger", trigger, xmlElement, mode);
+
+ if(this->isOnLoad()) // If the object is onLoad the code is executed at once.
+ this->execute();
}
+ /**
+ @brief
+ Creates a port that can be used to channel events and react to them.
+ @param xmlElement
+ The element.
+ @param mode
+ The mode.
+ */
+ void Script::XMLEventPort(Element& xmlElement, XMLPort::Mode mode)
+ {
+ SUPER(Script, XMLEventPort, xmlElement, mode);
+
+ XMLPortEventState(Script, BaseObject, "trigger", trigger, xmlElement, mode);
+ }
+
+ /**
+ @brief
+ Is called when an event comes in trough the event port.
+ @param triggered
+ Whether the event is triggering or un-triggering.
+ */
+ void Script::trigger(bool triggered)
+ {
+ if(triggered) // If the event is triggering (instead of un-triggering) the code of this Script is executed.
+ this->execute();
+ }
+
+ /**
+ @brief
+ Executes the Scripts code, depending on the mode.
+ */
void Script::execute()
{
- luaState_->doString(code_);
+ if(this->times_ != Script::INF && this->remainingExecutions_ == 0)
+ return;
+
+ if(this->mode_ == ScriptMode::normal) // If the mode is 'normal'.
+ CommandExecutor::execute(this->code_);
+ else if(this->mode_ == ScriptMode::lua) // If it's 'lua'.
+ {
+ assert(this->luaState_);
+ this->luaState_->doString(this->code_);
+ }
+
+ if(this->times_ != Script::INF)
+ this->remainingExecutions_--;
}
+
+ /**
+ @brief
+ Sets the mode of the Script.
+ @param mode
+ The mode as a string.
+ */
+ void Script::setMode(const std::string& mode)
+ {
+ if(mode == Script::NORMAL)
+ this->setMode(ScriptMode::normal);
+ else if(mode == Script::LUA)
+ {
+ this->setMode(ScriptMode::lua);
+ // Creates a new LuaState.
+ if(this->luaState_ == NULL)
+ this->luaState_ = new LuaState();
+ }
+ else
+ {
+ COUT(2) << "Invalid mode '" << mode << "' in Script object." << std::endl;
+ this->setMode(ScriptMode::normal);
+ }
+ }
+
+ /**
+ @brief
+ Get the mode of the Script.
+ @return
+ Returns the mode as a string.
+ */
+ const std::string& Script::getMode(void)
+ {
+ switch(this->mode_)
+ {
+ case ScriptMode::normal:
+ return Script::NORMAL;
+ case ScriptMode::lua:
+ return Script::LUA;
+ }
+ }
+
+ /**
+ @brief
+ Set the number of times this Script is executed at the most.
+ -1 denotes infinity.
+ @param times
+ The number of times to be set.
+ */
+ void Script::setTimes(int times)
+ {
+ if(times >= -1)
+ {
+ this->times_ = times;
+ this->remainingExecutions_ = times;
+ }
+ else
+ {
+ COUT(2) << "Invalid times '" << times << "' in Script." << std::endl;
+ this->times_ = Script::INF;
+ }
+ }
+
}
Modified: code/trunk/src/modules/objects/Script.h
===================================================================
--- code/trunk/src/modules/objects/Script.h 2010-09-11 08:20:44 UTC (rev 7403)
+++ code/trunk/src/modules/objects/Script.h 2010-09-11 12:42:47 UTC (rev 7404)
@@ -22,7 +22,7 @@
* Author:
* Benjamin Knecht
* Co-authors:
- * ...
+ * Damian 'Mozork' Frick
*
*/
@@ -36,20 +36,114 @@
namespace orxonox
{
+
+ namespace ScriptMode
+ {
+ //! Modes of the Script class.
+ enum Value
+ {
+ normal,
+ lua
+ };
+ }
+
+ /**
+ @brief
+ The Script class lets you execute a piece of code, either the normal way or in lua, through XML. It can be specified whether the code is executed upon loading (creation) of the object. Additionally the code is executed each time a trigger event comes in.
+ There are three parameters:
+ 'code': The code that should be executed.
+ 'mode': The mode, specifying whether the set code should be executed the normal way ('normal') or in lua ('lua'). Default is 'normal'.
+ 'onLoad': Whether the code is executed upon loading (creation) of this object. Default is true.
+
+ Here are two examples illustrating the usage:
+ @code
+ <Script code="showGUI QuestGUI" />
+ @endcode
+ This would show the QuestGUI opon creation of the object. The mode is 'normal', not specified here since that is the default, also onLoad is true, also not specified, since it is the default as well.
+
+ @code
+ <Script code="hideGUI QuestGUI" mode="normal" onLoad="false">
+ <events>
+ <trigger>
+ <DistanceTrigger distance=10 target="Pawn" />
+ </trigger>
+ </events>
+ </Script>
+ @endcode
+ This would hide the QuestGUI as soon as a Pawn got in range of the DistanceTrigger. The mode is 'normal', it is specified here, but could be ommitted as well, since it is the default. OnLoad is false, that is why it can't be ommitted.
+ @author
+ Benjamin Knecht
+ Damian 'Mozork' Frick
+ */
class _ObjectsExport Script : public BaseObject
{
- public:
- Script(BaseObject* creator);
- ~Script();
- void XMLPort(Element& xmlelement, XMLPort::Mode mode);
- void execute();
+ public:
+ Script(BaseObject* creator);
+ virtual ~Script();
- void setCode(const std::string& code) { code_ = code; }
- const std::string& getCode() const { return code_; }
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a Script object through XML.
+ virtual void XMLEventPort(Element& xmlElement, XMLPort::Mode mode); //!< Creates a port that can be used to channel events and react to them.
- private:
- std::string code_;
- LuaState* luaState_;
+ void trigger(bool triggered); //!< Is called when an event comes in trough the event port.
+ void execute(); //!< Executes the Scripts code, depending on the mode.
+
+ /**
+ @brief Sets the code that is executed by this Script.
+ @param code The code that is executed by this Script.
+ */
+ inline void setCode(const std::string& code)
+ { code_ = code; }
+ /**
+ @brief Get the code that is executed by this Script.
+ @return Returns the code that is executed by this Script.
+ */
+ inline const std::string& getCode() const
+ { return code_; }
+
+ void setMode(const std::string& mode); //!< Sets the mode of the Script.
+ const std::string& getMode(void); //!< Get the mode of the Script.
+
+ /**
+ @brief Set whether this Script is executed onLoad or not.
+ @param onLoad if true the Script is executed onLoad, if false it's not.
+ */
+ inline void setOnLoad(bool onLoad)
+ { this->onLoad_ = onLoad; }
+ /**
+ @brief Get whether this Script is executed onLoad.
+ @return Returns true if this Script is executed onLoad, false if not.
+ */
+ inline bool isOnLoad(void)
+ { return this->onLoad_; }
+
+ void setTimes(int times); //!< Set the number of times this Script is executed at the most.
+ /**
+ @brief Get the number of times this Script is executed at the most.
+ @return Returns the number of times this Script is executed at the most. -1 denotes infinity.
+ */
+ inline int getTimes(void)
+ { return this->times_; }
+
+ private:
+ //! Static variables to avoid magic strings.
+ static const std::string NORMAL;
+ static const std::string LUA;
+ static const int INF = -1;
+
+ std::string code_; //!< The code that is executed by this Script.
+ ScriptMode::Value mode_; //!< The mode the Script is in. Determines whether the code is executed the normal way or in lua.
+ bool onLoad_; //!< Whether the Scripts code is executed upon loading (creation) of this Script.
+ int times_; //!< The number of times the Scripts code is executed at the most. -1 denotes infinity.
+
+ LuaState* luaState_; //!< The LuaState to execute the code in lua.
+ int remainingExecutions_; //!< The number of remainign executions. -1 denotes infinity.
+
+ /**
+ @brief Sets the mode of the Script.
+ @param mode The mode of the Script.
+ */
+ inline void setMode(ScriptMode::Value mode)
+ { this->mode_ = mode; }
};
}
More information about the Orxonox-commit
mailing list