Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/modularships/src/orxonox/items/PartDestructionEvent.h @ 10055

Last change on this file since 10055 was 10055, checked in by noep, 10 years ago

Cleaned up code. Added console command "ModularSpaceShip killshippart [string]" which allows manual destruction of a ShipPart by name. Added more functionality to PartDestructionEvents.

File size: 5.4 KB
Line 
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 *      Noe Pedrazzini
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _PartDestructionEvent_H__
30#define _PartDestructionEvent_H__
31
32#include "OrxonoxPrereqs.h"
33#include "Item.h"
34
35#include <string>
36
37
38namespace orxonox // tolua_export
39{ // tolua_export
40    /**
41        @brief
42            In order to assign attached entities to a ShipPart, a ShipPart with the same name as the corresponding entity needs to be created in the <parts> tag.
43            Here is a (primitive) example of a ModularSpaceShip with ShipParts and PartDestructionEvents defined in XML:
44            @code
45            <ModularSpaceShip
46                ...
47                >
48                    <attached>
49                        <StaticEntity name="generator"  . . .  />
50                        <StaticEntity name="tail" . . . />
51                    </attached>
52                    <parts>
53                        <ShipPart name="generator" . . . >
54                            <destructionevents>
55                                <PartDestructionEvent targetType="ship" targetParam="boostpowerrate" operation="-" value="0.5" message="Your boost-regeneration is reduced!" />
56                            </destructionevents>
57                        </ShipPart>
58                        <ShipPart name="tail" . . . >
59                            <destructionevents>
60                                <PartDestructionEvent ... />
61                            </destructionevents>
62                        </ShipPart>
63                    </parts>
64                    <engines>
65                        <Engine />
66                        <Engine />
67                    </engines>
68                </ModularSpaceShip>
69            @endcode
70
71        @author
72            Fabian 'x3n' Landau, Noe Pedrazzini
73        */
74    class _OrxonoxExport PartDestructionEvent // tolua_export
75        : public Item
76    { // tolua_export
77
78        public:
79
80            /**
81                @brief
82                    List of all allowed parameters.
83                */
84            enum TargetParam
85            {
86                shieldhealth,
87                maxshieldhealth,
88                shieldabsorption,
89                shieldrechargerate,
90                boostpower,         // Amount of available boost
91                boostpowerrate,     // Recharge-rate of boost
92                boostfactor,
93                speedfront,
94                accelerationfront,
95                null
96            };
97
98            PartDestructionEvent(Context* context);
99            virtual ~PartDestructionEvent();
100
101            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
102
103            void execute();
104
105            inline void setValid(bool valid)
106                { this->valid_ = valid; }
107            inline bool isValid()
108                { return this->valid_; }
109
110            void setParent(ShipPart* parent);
111            inline ShipPart* getParent()
112                { return this->parent_; }
113
114            void setTargetType(std::string type);
115            inline std::string getTargetType()
116                { return this->targetType_; }
117
118            void setTargetName(std::string name);
119            inline std::string getTargetName()
120                { return this->targetName_; }
121
122            void setTargetParam(std::string param);
123            inline std::string getTargetParam()
124                { return this->targetName_; }
125
126            void setOperation(std::string operation);
127            inline std::string getOperation()
128                { return this->operation_; }
129
130            void setMessage(std::string msg);
131            inline std::string getMessage()
132                { return this->message_; }
133
134            float operate(float input);
135
136            void setEventValue(float value);
137            inline float getEventValue()
138                { return this->value_; }
139
140        protected:
141
142        private:
143
144            ShipPart* parent_;          //!< Pointer to the ShipPart this event belongs to
145            bool valid_;                //!< Whether this event is valid or not.
146
147            std::string targetType_;    //!< The type of the target. (ship weapon engine)
148            std::string targetName_;    //!< The name of the target.
149            TargetParam targetParam_;   //!< The parameter to be modified
150            std::string operation_;     //!< The operation to be applied
151            float value_;               //!< The value used to do the operation
152            std::string message_;       //!< The message which is shown in chat when the event is executed.
153
154
155
156    }; // tolua_export
157} // tolua_export
158
159#endif /* _PartDestructionEvent_H__ */
Note: See TracBrowser for help on using the repository browser.