Orxonox  0.0.5 Codename: Arcturus
Script.h
Go to the documentation of this file.
1 
2 /*
3  * ORXONOX - the hottest 3D action shooter ever to exist
4  * > www.orxonox.net <
5  *
6  *
7  * License notice:
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  *
23  * Author:
24  * Benjamin Knecht
25  * Co-authors:
26  * Damian 'Mozork' Frick
27  *
28  */
29 
36 #ifndef _Script_H__
37 #define _Script_H__
38 
39 #include "objects/ObjectsPrereqs.h"
40 
41 #include <string>
42 #include <vector>
43 
44 #include "core/BaseObject.h"
46 
47 namespace orxonox
48 {
49 
53  enum class ScriptMode
54  {
55  normal,
56  lua
57  };
58 
92  {
93  public:
94  Script(Context* context);
95  virtual ~Script();
96 
97  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
98  virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode) override;
99 
100  bool trigger(bool triggered, BaseObject* trigger);
101  void execute(unsigned int clientId, bool onLoad = false);
102  static void executeHelper(const std::string& code, const std::string& mode, bool needsGraphics);
103 
108  inline void setCode(const std::string& code)
109  { code_ = code; }
114  inline const std::string& getCode() const
115  { return code_; }
116 
117  void setMode(const std::string& mode);
118  const std::string& getMode(void);
119 
124  inline void setOnLoad(bool onLoad)
125  { this->onLoad_ = onLoad; }
130  inline bool isOnLoad(void)
131  { return this->onLoad_; }
132 
133  void setTimes(int times);
134 
138  inline int getTimes(void)
139  { return this->times_; }
140 
145  void setNeedsGraphics(bool needsGraphics)
146  { this->needsGraphics_ = needsGraphics; }
151  bool getNeedsGraphics(void)
152  { return this->needsGraphics_; }
153 
158  void setForAll(bool forAll)
159  { this->forAll_ = forAll; }
164  bool isForAll(void)
165  { return this->forAll_; }
166 
167  virtual void clientConnected(unsigned int clientId) override;
168  virtual void clientDisconnected(unsigned int clientid) override {}
169 
170  private:
172  static const std::string NORMAL;
173  static const std::string LUA;
174  static const int INF;
175 
179  bool onLoad_;
180  int times_;
182  bool forAll_;
183 
185 
186  void modeChanged();
187 
192  inline void setMode(ScriptMode mode)
193  { this->mode_ = mode; }
194  };
195 }
196 
197 #endif /* _Script_H__ */
#define _ObjectsExport
Definition: ObjectsPrereqs.h:60
The BaseObject is the parent of all classes representing an instance in the game. ...
Definition: BaseObject.h:63
static const int INF
Definition: Script.h:174
ScriptMode
The mode a specific Script is in.
Definition: Script.h:53
bool forAll_
Whether the code is executed for all players (in a multiplayer setup) or just for the one triggering ...
Definition: Script.h:182
ScriptMode mode_
The mode the Script is in. Determines whether the code is executed the normal way or in lua...
Definition: Script.h:177
bool needsGraphics_
Whether the code to be executed needs graphics.
Definition: Script.h:181
The Scripts&#39; code is executed through the CommandExecutor.
::std::string string
Definition: gtest-port.h:756
std::string modeStr_
The mode the Script is in, as a string. Is used for networking purposes.
Definition: Script.h:178
static const std::string NORMAL
Static variables to avoid magic strings.
Definition: Script.h:172
int getTimes(void)
Get the number of times this Script is executed at the most.
Definition: Script.h:138
bool isForAll(void)
Get whether the Script executes its code for all players or just for the player triggering the Script...
Definition: Script.h:164
static const std::string LUA
Definition: Script.h:173
virtual void clientDisconnected(unsigned int clientid) override
Definition: Script.h:168
An abstract base class.
Definition: ClientConnectionListener.h:40
The Script class lets you execute a piece of code, either the normal way or in lua, through XML.
Definition: Script.h:91
xmlelement
Definition: Super.h:519
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
void setCode(const std::string &code)
Sets the code that is executed by this Script.
Definition: Script.h:108
bool onLoad_
Whether the Scripts code is executed upon loading (creation) of this Script.
Definition: Script.h:179
Mode
Definition: CorePrereqs.h:102
Declaration of BaseObject, the base class of all objects in Orxonox.
Definition: Context.h:45
void setMode(ScriptMode mode)
Sets the mode of the Script.
Definition: Script.h:192
Shared library macros, enums, constants and forward declarations for the objects module ...
void setNeedsGraphics(bool needsGraphics)
Set whether the code to be executed needs graphics to work.
Definition: Script.h:145
bool getNeedsGraphics(void)
Get whether the code to be executed needs graphics to work.
Definition: Script.h:151
void setForAll(bool forAll)
Set whether the code is executed for all players or just for the player triggering the Script...
Definition: Script.h:158
The Scripts&#39; code is executed through lua.
int remainingExecutions_
The number of remainign executions. -1 denotes infinity.
Definition: Script.h:184
bool isOnLoad(void)
Get whether this Script is executed onLoad.
Definition: Script.h:130
int times_
The number of times the Scripts code is executed at the most. -1 denotes infinity.
Definition: Script.h:180
void setOnLoad(bool onLoad)
Set whether this Script is executed onLoad or not.
Definition: Script.h:124
const std::string & getCode() const
Get the code that is executed by this Script.
Definition: Script.h:114
std::string code_
The code that is executed by this Script.
Definition: Script.h:176