Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/items/Engine.h @ 10078

Last change on this file since 10078 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 13.9 KB
RevLine 
[2254]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _Engine_H__
30#define _Engine_H__
31
32#include "OrxonoxPrereqs.h"
33
[8727]34#include "util/OrxAssert.h"
35
[2254]36#include "Item.h"
37
38namespace orxonox
39{
[8727]40
41    /**
42    @brief
43        The Engine class provides propulsion to the SpaceShip.
44       
45        There are many parameters that can be specified:
46        - The <b>relativePosition</b>, specifies the position relative to the center of the SpaceShip the Engine is mounted on.
47        - The <b>maximal speed</b>, there are four maximal speeds that can be specified: The <b>speedfront</b>, the maximal forward speed. The <b>speedback>, the maximal backward speed. The <b>speedleftright</b>, the maximal speed in y-direction of the SpaceShip coordinate frame. The <b>speedupdown</b>, the maximal speed in z-direction of the SpaceShip coordinate frame. All maximal speeds (naturally) have to be non-negative.
48        - The <b>acceleration</b>, there are five types of acceleration that can be specified: The <b>accelerationfront</b>, the forward acceleration. The <b>accelerationbrake</b>, the braking acceleration. The <b>accelerationback</b>, the backward acceleration. The <b>accelerationleftright</b>, the acceleration in y-direction. The <b>accelerationupdown</b>, the acceleration in z-direction. All accelerations have to be non-negative.
49        - The <b>boostfactor</b>, specifies the factor by which boosting increases the speed. This has to be non-negative, as well. Beware that maximal speeds can be overcome through boosting.
50        - The <b>template</b>, the name of the engine template. Allows for parameters of the Engine be set trough a template.
51       
52    @author
53        Fabian 'x3n' Landau
54    */
55    class _OrxonoxExport Engine : public Item
[2254]56    {
57        public:
[9667]58            Engine(Context* context);
[2254]59            virtual ~Engine();
60
61            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
[2478]62            void setConfigValues();
[2254]63
[8727]64            virtual void run(float dt); // Run the engine for a given time interval.
[2254]65
[8727]66            virtual void addToSpaceShip(SpaceShip* ship); // Adds the Engine to the input SpaceShip.
67            /**
68            @brief Get the SpaceShip this Engine is mounted on.
69            @return Returns a pointer to the SpaceShip. NULL if it isn't mounted on any ship.
70            */
[2254]71            inline SpaceShip* getShip() const
72                { return this->ship_; }
73
[8727]74            /**
75            @brief Set the relative position of the Engine.
76            @param position The relative position with respect to the SpaceShip it is mounted on.
77            */
[8706]78            inline void setRelativePosition(const Vector3 &position)
79                { this->relativePosition_ = position; }
[8727]80            /**
81            @brief Get the relative position of the Engine.
82            @return Returns the relative position with respect to the SpaceShip it is mounted on.
83            */
84            inline const Vector3& getRelativePosition() const
[8706]85                { return this->relativePosition_; }
86
[8727]87            /**
88            @brief Set the maximal forward speed of the Engine.
89            @param speed The speed to be set. Must be non-negative.
90            */
91            //TODO: Better OrxVerify()?
[2254]92            inline void setMaxSpeedFront(float speed)
[8727]93                { OrxAssert(speed >= 0.0f, "The input speed must be non-negative."); this->maxSpeedFront_ = speed; }
94            /**
95            @brief Set the maximal backward speed of the Engine.
96            @param speed The speed to be set. Must be non-negative.
97            */
[2254]98            inline void setMaxSpeedBack(float speed)
[8727]99                { OrxAssert(speed >= 0.0f, "The input speed must be non-negative."); this->maxSpeedBack_ = speed; }
100            /**
101            @brief Set the maximal left-right speed of the Engine.
102            @param speed The speed to be set. Must be non-negative.
103            */
[2254]104            inline void setMaxSpeedLeftRight(float speed)
[8727]105                { OrxAssert(speed >= 0.0f, "The input speed must be non-negative."); this->maxSpeedLeftRight_ = speed; }
106            /**
107            @brief Set the maximal up-down speed of the Engine.
108            @param speed The speed to be set. Must be non-negative.
109            */
[2254]110            inline void setMaxSpeedUpDown(float speed)
[8727]111                { OrxAssert(speed >= 0.0f, "The input speed must be non-negative."); this->maxSpeedUpDown_ = speed; }
[2254]112
[8727]113            /**
114            @brief Get the maximal forward speed of the Engine.
115            @return Returns the maximal forward speed of the Engine. Is non-negative.
116            */
[2256]117            inline float getMaxSpeedFront() const
118                { return this->maxSpeedFront_; }
[8727]119            /**
120            @brief Get the maximal backward speed of the Engine.
121            @return Returns the maximal backward speed of the Engine. Is non-negative.
122            */
[2256]123            inline float getMaxSpeedBack() const
124                { return this->maxSpeedBack_; }
[8727]125            /**
126            @brief Get the maximal left-right speed of the Engine.
127            @return Returns the maximal left-right speed of the Engine. Is non-negative.
128            */
[2256]129            inline float getMaxSpeedLeftRight() const
130                { return this->maxSpeedLeftRight_; }
[8727]131            /**
132            @brief Get the maximal up-down speed of the Engine.
133            @return Returns the maximal up-down speed of the Engine. Is non-negative.
134            */
[2256]135            inline float getMaxSpeedUpDown() const
136                { return this->maxSpeedUpDown_; }
137
[8727]138            /**
139            @brief Set the forward acceleration produced by the Engine.
140            @param acceleration The forward acceleration produced by the Engine. Must be non-negative.
141            */
[2254]142            inline void setAccelerationFront(float acceleration)
[8727]143                { OrxAssert(acceleration >= 0.0f, "The input acceleration must be non-negative."); this->accelerationFront_ = acceleration; }
144            /**
145            @brief Set the breaking acceleration produced by the Engine.
146            @param acceleration The breaking acceleration produced by the engine. Must be non-negative.
147            */
[2254]148            inline void setAccelerationBrake(float acceleration)
[8727]149                { OrxAssert(acceleration >= 0.0f, "The input acceleration must be non-negative."); this->accelerationBrake_ = acceleration; }
150            /**
151            @brief Set the backward acceleration produced by the Engine.
152            @param acceleration The backward acceleration produced by the Engine.
153            */
[2254]154            inline void setAccelerationBack(float acceleration)
[8727]155                { OrxAssert(acceleration >= 0.0f, "The input acceleration must be non-negative."); this->accelerationBack_ = acceleration; }
156            /**
157            @brief Set the left-right acceleration produced by the Engine.
158            @param acceleration The left-right acceleration produced by the Engine.
159            */
[2254]160            inline void setAccelerationLeftRight(float acceleration)
[8727]161                { OrxAssert(acceleration >= 0.0f, "The input acceleration must be non-negative."); this->accelerationLeftRight_ = acceleration; }
162            /**
163            @brief Set the up-down acceleration produced by the Engine.
164            @param acceleration The
165            */
[2254]166            inline void setAccelerationUpDown(float acceleration)
[8727]167                { OrxAssert(acceleration >= 0.0f, "The input acceleration must be non-negative."); this->accelerationUpDown_ = acceleration; }
[2254]168
[8727]169            /**
170            @brief Get the forward acceleration produced by the Engine.
171            @return Returns the forward acceleration produced by the Engine. Is non-negative.
172            */
[2256]173            inline float getAccelerationFront() const
174                { return this->accelerationFront_; }
[8727]175            /**
176            @brief Get the breaking acceleration produced by the Engine.
177            @return Returns the breaking acceleration produced by the Engine. Is non-negative.
178            */
[2256]179            inline float getAccelerationBrake() const
180                { return this->accelerationBrake_; }
[8727]181            /**
182            @brief Get the backward acceleration produced by the Engine.
183            @return Returns the backward acceleration produced by the Engine. Is non-negative.
184            */
[2256]185            inline float getAccelerationBack() const
186                { return this->accelerationBack_; }
[8727]187            /**
188            @brief Get the left-right acceleration produced by the Engine.
189            @return Returns the left-right acceleration produced by the Engine. Is non-negative.
190            */
[2256]191            inline float getAccelerationLeftRight() const
192                { return this->accelerationLeftRight_; }
[8727]193            /**
194            @brief Get the up-down acceleration produced by the Engine.
195            @return Returns the up-down acceleration produced by the Engine. Is non-negative.
196            */
[2256]197            inline float getAccelerationUpDown() const
198                { return this->accelerationUpDown_; }
199
[8727]200            /**
201            @brief Set the factor by which boosting increases the forward acceleration of the Engine.
202            @param factor The boost factor. Needs to be positive.
203            */
204            inline void setBoostFactor(float factor)
205                { OrxAssert(factor > 0.0f, "The input factor must be positive."); this->boostFactor_ = factor; }
206            /**
207            @brief Get the boost factor of the Engine.
208            @return Returns the factor by which boosting increases the forward acceleration of the Engine. Is positive.
209            */
210            inline float getBoostFactor() const
211                { return this->boostFactor_; }
212
213            /**
214            @brief Add to the additional forward speed factor.
215            @param factor The speed that is added to the additional forward speed. Must be non-negative.
216            */
217            inline void addSpeedAdd(float speed)
218                { this->speedAdd_ += speed; }
219            /**
220            @brief Add to the forward speed multiplication factor.
221            @param factor The factor by which the forward speed multiplication factor is multiplied. Must be non-negative.
222            */
223            inline void addSpeedMultiply(float factor)
224                { OrxAssert(factor >= 0.0f, "The factor must be non-negative."); this->speedMultiply_ *= factor; }
225
226            /**
227            @brief Get the additional forward speed.
228            @return Returns the additional forward speed.
229            */
[6709]230            inline float getSpeedAdd(void)
231                { return this->speedAdd_; }
[8727]232            /**
233            @brief Get the forward speed multiplication factor.
234            @return Returns the forward speed multiplication factor.
235            */
[6709]236            inline float getSpeedMultiply(void)
237                { return this->speedMultiply_; }
238
[8727]239            /**
240            @brief Set the engine template, that specifies the parameters for the Engine.
241            @param temp The name of the engine template.
242            */
[8706]243            inline void setEngineTemplate(const std::string& temp)
244                { this->engineTemplate_ = temp; this->loadEngineTemplate(); }
[8727]245            /**
246            @brief Get the engine template, that specifies the parameters for the Engine.
247            @return Returns the name of the engine template.
248            */
[8706]249            inline const std::string& getEngineTemplate() const
250                { return this->engineTemplate_; }
251
[6709]252        protected:
[8727]253            void loadEngineTemplate(); // Load the engine template.
[6709]254
[8727]255            virtual const Vector3& getSteering() const; // Get the steering direction imposed upon the Engine.
256
[2254]257        private:
[7163]258            void registerVariables();
[2254]259            void networkcallback_shipID();
260
[8727]261            std::string engineTemplate_; //!< The template that specifies the Engine's parameters.
[8706]262
[8727]263            SpaceShip* ship_; //!< A pointer to the SpaceShip the Engine is mounted on.
264            unsigned int shipID_; //!< Object ID of the SpaceShip the Engine is mounted on.
265            Vector3 relativePosition_; //!< The relative position of the Engine with respect to the SpaceShip it is mounted on.
[2254]266
[8727]267            float boostFactor_; //!< The factor by which boosting increases the forward acceleration.
[2254]268
[8727]269            float speedAdd_; //!< Additional forward speed. Is not bounded by the maximal forward speed.
270            float speedMultiply_; //!< Forward speed multiplication factor. Is not bounded by the maximal forward speed.
[6709]271
[8727]272            float maxSpeedFront_; //!< The maximal forward speed.
273            float maxSpeedBack_; //!< The maximal backward speed.
274            float maxSpeedLeftRight_; //!< The maximal left-right speed.
275            float maxSpeedUpDown_; //!< The maximal up-down speed.
[2254]276
[8727]277            float accelerationFront_; //!< Forward acceleration produced by the Engine.
278            float accelerationBrake_; //!< Breaking acceleration produced by the Engine.
279            float accelerationBack_; //!< Backward acceleration produced by the Engine.
280            float accelerationLeftRight_; //!< Left-right acceleration produced by the Engine.
281            float accelerationUpDown_; //!< Up-down acceleration produced by the Engine.
282
[2254]283    };
284}
285
286#endif /* _Engine_H__ */
Note: See TracBrowser for help on using the repository browser.