Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickup3/src/modules/pickup/PickupRepresentation.cc @ 6477

Last change on this file since 6477 was 6475, checked in by dafrick, 15 years ago

Additional documentation, code niceifying and potential bug fixing. Also: Renamed DroppedItem to DroppedPickup.

File size: 5.2 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 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27*/
28
29#include "PickupRepresentation.h"
30
31#include "core/CoreIncludes.h"
32#include "graphics/Billboard.h"
33#include "util/StringUtils.h"
34#include "PickupManager.h"
35
36namespace orxonox
37{
38   
39    CreateFactory(PickupRepresentation);
40   
41    /**
42    @brief
43        Constructor. Registers the object and initializes its member variables.
44        This is primarily for use of the PickupManager in creating a default PickupRepresentation.
45    */
46    PickupRepresentation::PickupRepresentation() : BaseObject(this)
47    {
48        RegisterObject(PickupRepresentation);
49       
50        this->initialize();
51    }
52   
53    /**
54    @brief
55        Default Constructor. Registers the object and initializes its member variables.
56    */
57    PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator)
58    {
59        RegisterObject(PickupRepresentation);
60       
61        this->initialize();
62    }
63   
64    /**
65    @brief
66        Destructor.
67    */
68    PickupRepresentation::~PickupRepresentation()
69    {
70        if(this->spawnerRepresentation_ != NULL)
71            this->spawnerRepresentation_->destroy();
72    }
73   
74    /**
75    @brief
76        Initializes the member variables of this PickupRepresentation.
77    */
78    void PickupRepresentation::initialize(void)
79    {
80        this->description_ = "This is a pickup.";
81        this->name_ = "Pickup";
82        this->spawnerTemplate_ = "";
83        this->spawnerRepresentation_ = NULL;
84        this->pickup_ = NULL;
85    }
86   
87    /**
88    @brief
89        Method for creating a PickupRepresentation object through XML.
90    */
91    void PickupRepresentation::XMLPort(Element& xmlelement, XMLPort::Mode mode)
92    {
93        SUPER(PickupRepresentation, XMLPort, xmlelement, mode);
94       
95        XMLPortParam(PickupRepresentation, "name", setName, getName, xmlelement, mode);
96        XMLPortParam(PickupRepresentation, "description", setDescription, getDescription, xmlelement, mode);
97        XMLPortParam(PickupRepresentation, "spawnerTemplate", setSpawnerTemplate, getSpawnerTemplate, xmlelement, mode);
98        XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode);
99        XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode);
100       
101        PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this); //!< Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents.
102    }
103   
104    /**
105    @brief
106        Get a spawnerRepresentation for a specific PickupSpawner.
107    @param spawner
108        A pointer to the PickupSpawner.
109    @return
110        Returns a pointer to the StaticEntity.
111    */
112    StaticEntity* PickupRepresentation::getSpawnerRepresentation(PickupSpawner* spawner)
113    {
114        if(this->spawnerRepresentation_ == NULL)
115        {
116            COUT(4) << "PickupRepresentation: No spawner representation found." << std::endl;
117            if(this->spawnerTemplate_ == BLANKSTRING)
118            {
119                COUT(4) << "PickupRepresentation: Spawner template is empty." << std::endl;
120                //!< If neither spawnerRepresentation nor spawnerTemplate was specified
121                return this->getDefaultSpawnerRepresentation(spawner);
122            }
123            this->addTemplate(this->spawnerTemplate_);
124        }
125       
126        StaticEntity* representation = this->spawnerRepresentation_;
127       
128        this->addTemplate(this->spawnerTemplate_);
129       
130        return representation;
131    }
132   
133    /**
134    @brief
135        Get the default spawnerRepresentation for a specific PickupSpawner.
136        Helper method of internal use.
137    @param spawner
138        A pointer to the PickupSpawner.
139    @return
140        Returns a pointer to the StaticEntity.
141    */
142    //TODO: Think of more elegant solution.
143    StaticEntity* PickupRepresentation::getDefaultSpawnerRepresentation(PickupSpawner* spawner)
144    {
145        StaticEntity* representation = new StaticEntity(spawner);
146        //TODO: Nicer...
147        Billboard* billboard = new Billboard(spawner);
148        billboard->setColour(ColourValue(1.0, 0.0, 0.0));
149        billboard->setMaterial("Examples/Flare");
150        representation->attach(billboard);
151        return representation;
152    }
153   
154}
Note: See TracBrowser for help on using the repository browser.