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 | * Damian 'Mozork' Frick |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file PickupRepresentation.h |
---|
31 | @brief Definition of the PickupRepresentation class. |
---|
32 | @ingroup Pickup |
---|
33 | */ |
---|
34 | |
---|
35 | #ifndef _PickupRepresentation_H__ |
---|
36 | #define _PickupRepresentation_H__ |
---|
37 | |
---|
38 | #include "PickupPrereqs.h" |
---|
39 | |
---|
40 | #include "core/XMLPort.h" |
---|
41 | #include "interfaces/Pickupable.h" |
---|
42 | #include "pickup/PickupIdentifier.h" |
---|
43 | #include "worldentities/StaticEntity.h" |
---|
44 | |
---|
45 | #include "PickupSpawner.h" |
---|
46 | |
---|
47 | #include "core/BaseObject.h" |
---|
48 | #include "network/synchronisable/Synchronisable.h" |
---|
49 | |
---|
50 | namespace orxonox // tolua_export |
---|
51 | { // tolua_export |
---|
52 | |
---|
53 | /** |
---|
54 | @brief |
---|
55 | The PickupRepresentation class represents a specific pickup type (identified by its @ref orxonox::PickupIdentififer "PickupIdentifier"). It defines the information displayed in the GUI (PickupInventory) and how @ref orxonox::PickupSpawner "PickupSpawners" that spawn the pickup type look like. |
---|
56 | They are created through XML and are registered with the @ref orxonox::PickupManager "PickupManager". |
---|
57 | |
---|
58 | Creating a PickupRepresentation in XML could look as follows: |
---|
59 | @code |
---|
60 | <PickupRepresentation |
---|
61 | name = "My awesome Pickup" |
---|
62 | description = "This is the most awesome Pickup ever to exist." |
---|
63 | spawnerTemplate = "awesomePickupRepresentation" |
---|
64 | inventoryRepresentation = "AwesomePickup" |
---|
65 | > |
---|
66 | <pickup> |
---|
67 | <SomePickup /> |
---|
68 | </pickup> |
---|
69 | </PickupRepresentation> |
---|
70 | @endcode |
---|
71 | As you might have noticed, there is a parameter called <em>spawnerTemplate</em> and also another parameter called <em>inventoryRepresentation</em>. Let's first explain the second one, <em>inventoryRepresentation</em>. |
---|
72 | - The <b>inventoryRepresentation</b> specifies the image that is displayed in the PickupInventory for the specific type of @ref orxonox::Pickupable "Pickupable". More technically, it is the name of an image located in the <code>PickupInventory.imageset</code>, which in turn is located in <code>data_extern/gui/imagesets/</code>. |
---|
73 | - The <b>spawnerTemplate</b> specifies how the type of @ref orxonox::Pickupable "Pickupable" (or more precisely the @ref orxonox::PickupSpawner "PickupSpawner", that spawns that type of @ref orxonox::Pickupable "Pickupable") is displayed ingame. It is a @ref orxnox::Template "Template" defined in XML. The <em>spawnerTemplate</em> can be specified as follows (keep in mind, that the template needs to have been specified before the definition of the PickupRepresentation that uses it). |
---|
74 | @code |
---|
75 | <Template name="awesomePickupRepresentation"> |
---|
76 | <PickupRepresentation> |
---|
77 | <spawner-representation> |
---|
78 | <StaticEntity> |
---|
79 | <attached> |
---|
80 | <!-- Here you can put all the objects which define the look of the spawner. --> |
---|
81 | </attached> |
---|
82 | </StaticEntity> |
---|
83 | </spawner-representation> |
---|
84 | </PickupRepresentation> |
---|
85 | </Template> |
---|
86 | @endcode |
---|
87 | |
---|
88 | For the purpose of them working over the network, they are synchronised. |
---|
89 | |
---|
90 | @author |
---|
91 | Damian 'Mozork' Frick |
---|
92 | |
---|
93 | @ingroup Pickup |
---|
94 | */ |
---|
95 | class _PickupExport PickupRepresentation // tolua_export |
---|
96 | : public BaseObject, public Synchronisable |
---|
97 | { // tolua_export |
---|
98 | |
---|
99 | public: |
---|
100 | PickupRepresentation(); //!< Constructor |
---|
101 | PickupRepresentation(BaseObject* creator); //!< Default constructor. |
---|
102 | virtual ~PickupRepresentation(); //!< Destructor. |
---|
103 | |
---|
104 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a PickupRepresentation object through XML. |
---|
105 | |
---|
106 | /** |
---|
107 | @brief Set the name of the Pickupable represented by this PickupRepresentation. |
---|
108 | @param name The name. |
---|
109 | */ |
---|
110 | inline void setPickupName(const std::string& name) |
---|
111 | { this->name_ = name; } |
---|
112 | /** |
---|
113 | @brief Set the description of the Pickupable represented by this PickupRepresentation. |
---|
114 | @param description The Description. |
---|
115 | */ |
---|
116 | inline void setPickupDescription(const std::string& description) |
---|
117 | { this->description_ = description; } |
---|
118 | /** |
---|
119 | @brief Set the spawnerTemplate of the Pickupable represented by this PickupRepresentation. |
---|
120 | The spawnerTemplate is a name of a template defined in XML that defines the StaticEntity that is the spawnerRepresentation of this PickupRepresentation. |
---|
121 | @param spawnerTemplate The name of the template. |
---|
122 | */ |
---|
123 | inline void setSpawnerTemplate(const std::string& spawnerTemplate) |
---|
124 | { this->spawnerTemplate_ = spawnerTemplate; } |
---|
125 | /** |
---|
126 | @brief Set the StaticEntity that defines how the PickupSpawner of the Pickupable represented by this PickupRepresentation looks like. |
---|
127 | This will be set by the spawnerTemplate. Setting it when creating the PickupRepresentation without creating a template and specifying its name will be futile, because through the course of the game many PickupSpawners for one specific pickup type may have to be created, thus the StaticEntity that is the spawnerRepresentation has to be generated (with the template) for every new PickupSpawner spawning the Pickupable represented by this PickupRepresentation. The spawnerRepresentation that is set here, however can only be used once. |
---|
128 | @param representation A pointer to the StaticEntity that is the spawnerRepresentation of this PickupRepresentation. |
---|
129 | */ |
---|
130 | inline void setSpawnerRepresentation(StaticEntity* representation) |
---|
131 | { this->spawnerRepresentation_ = representation; } |
---|
132 | /** |
---|
133 | @brief Set the image representing the pickup in the PickupInventory. |
---|
134 | @param image A string with the name of the image representing the pickup. |
---|
135 | */ |
---|
136 | inline void setInventoryRepresentation(const std::string& image) |
---|
137 | { this->inventoryRepresentation_ = image; } |
---|
138 | /** |
---|
139 | @brief Set the Pickupable that is represented by this PickupRepresentation. |
---|
140 | @param pickup A pointer to the Pickupable. |
---|
141 | */ |
---|
142 | inline void setPickup(Pickupable* pickup) |
---|
143 | { this->pickup_ = pickup; } |
---|
144 | |
---|
145 | /** |
---|
146 | @brief Get the name of the Pickupable represented by this PickupRepresentation. |
---|
147 | @return Returns the name. |
---|
148 | */ |
---|
149 | inline const std::string& getPickupName(void) { return this->name_; } // tolua_export |
---|
150 | /** |
---|
151 | @brief Get the description of the Pickupable represented by this PickupRepresentation. |
---|
152 | @return Returns the description. |
---|
153 | */ |
---|
154 | inline const std::string& getPickupDescription(void) { return this->description_; } // tolua_export |
---|
155 | /** |
---|
156 | @brief Get the name of spawnerTemplate the Pickupable represented by this PickupRepresentation. |
---|
157 | @return Returns the name of the spawnerTemplate. |
---|
158 | */ |
---|
159 | inline const std::string& getSpawnerTemplate(void) |
---|
160 | { return this->spawnerTemplate_; } |
---|
161 | /** |
---|
162 | @brief Get the StaticEntity that defines how the PickupSpawner of the Pickupable represented by this PickupRepresentation looks like. |
---|
163 | @param index The index. |
---|
164 | @return Returns (for index = 0) a pointer to the StaticEntity. For index > 0 it returns NULL. |
---|
165 | */ |
---|
166 | inline const StaticEntity* getSpawnerRepresentationIndex(unsigned int index) |
---|
167 | { if(index == 0) return this->spawnerRepresentation_; return NULL; } |
---|
168 | /** |
---|
169 | @brief Get the name of the image representing the pickup in the PickupInventory. |
---|
170 | @return Returns the name of the image as a string. |
---|
171 | */ |
---|
172 | inline const std::string& getInventoryRepresentation(void) { return this->inventoryRepresentation_; } // tolua_export |
---|
173 | /** |
---|
174 | @brief Get the Pickupable represented by this PickupRepresentation. |
---|
175 | @param index The index. |
---|
176 | @return Returns (for index = 0) a pointer to the Pickupable. For index > 0 it returns NULL. |
---|
177 | */ |
---|
178 | inline const Pickupable* getPickup(unsigned int index) |
---|
179 | { if(index == 0) return this->pickup_; return NULL; } |
---|
180 | |
---|
181 | StaticEntity* getSpawnerRepresentation(PickupSpawner* spawner); //!< Get a spawnerRepresentation for a specific PickupSpawner. |
---|
182 | |
---|
183 | private: |
---|
184 | void initialize(void); //!< Initializes the member variables of this PickupRepresentation. |
---|
185 | StaticEntity* getDefaultSpawnerRepresentation(PickupSpawner* spawner); //!< Get the default spawnerRepresentation for a specific PickupSpawner. |
---|
186 | |
---|
187 | void registerVariables(void); //!< Registers the variables that need to be synchronised. |
---|
188 | |
---|
189 | std::string name_; //!< The name of the Pickupable represented by this PickupRepresentation. |
---|
190 | std::string description_; //!< The description of the Pickupable represented by this PickupRepresentation. |
---|
191 | std::string spawnerTemplate_; //!< The name of the template of this PickupRepresentation. |
---|
192 | StaticEntity* spawnerRepresentation_; //!< The spawnerRepresentation of this PickupRepresentation. |
---|
193 | std::string inventoryRepresentation_; //!< The name of an image representing the pickup in the PickupInventory. |
---|
194 | |
---|
195 | Pickupable* pickup_; //!< The Pickupable that is represented by this PickupRepresentation. |
---|
196 | |
---|
197 | }; // tolua_export |
---|
198 | |
---|
199 | } // tolua_export |
---|
200 | |
---|
201 | #endif // _PickupRepresentation_H__ |
---|