Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/pickup/PickupRepresentation.cc @ 7536

Last change on this file since 7536 was 7533, checked in by dafrick, 14 years ago

Documenting in pickups module.
Cleaning up in PickupManager.
Removed some obsolete functions in HumanController and ControllableEntity, which were remenants of the old pickups module.
Fixed a bug.

  • Property svn:eol-style set to native
File size: 7.1 KB
RevLine 
[6474]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
[6540]29/**
30    @file PickupRepresentation.cc
31    @brief Implementation of the PickupRepresentation class.
32*/
33
[6474]34#include "PickupRepresentation.h"
35
36#include "core/CoreIncludes.h"
[7504]37#include "core/GameMode.h"
[6475]38#include "graphics/Billboard.h"
39#include "util/StringUtils.h"
[6474]40#include "PickupManager.h"
41
42namespace orxonox
43{
[7163]44
[6474]45    CreateFactory(PickupRepresentation);
[7163]46
[6475]47    /**
48    @brief
49        Constructor. Registers the object and initializes its member variables.
50        This is primarily for use of the PickupManager in creating a default PickupRepresentation.
51    */
[7504]52    PickupRepresentation::PickupRepresentation() : BaseObject(NULL), Synchronisable(NULL), spawnerRepresentation_(NULL), pickup_(NULL)
[6474]53    {
54        RegisterObject(PickupRepresentation);
[7163]55
[6474]56        this->initialize();
[7504]57        this->setSyncMode(0x0);
[6474]58    }
[7163]59
[6475]60    /**
61    @brief
62        Default Constructor. Registers the object and initializes its member variables.
63    */
[7504]64    PickupRepresentation::PickupRepresentation(BaseObject* creator) : BaseObject(creator), Synchronisable(creator), spawnerRepresentation_(NULL), pickup_(NULL)
[6474]65    {
66        RegisterObject(PickupRepresentation);
[7163]67
[6474]68        this->initialize();
[7504]69        this->registerVariables();
70
71        PickupManager::getInstance().registerRepresentation(this); //!< Registers the PickupRepresentation with the PickupManager.
[6474]72    }
[7163]73
[6475]74    /**
75    @brief
76        Destructor.
77    */
[6474]78    PickupRepresentation::~PickupRepresentation()
79    {
[6475]80        if(this->spawnerRepresentation_ != NULL)
81            this->spawnerRepresentation_->destroy();
[7163]82
[7504]83        if(this->isInitialized())
84        {
[7533]85            //TODO: Also (network) unregister for master.
[7504]86            if(GameMode::isMaster() && this->pickup_ != NULL)
87            {
88                PickupManager::getInstance().unregisterRepresentation(this->pickup_->getPickupIdentifier(), this);
89            }
90            if(!GameMode::isMaster())
91            {
92                PickupManager::getInstance().unregisterRepresentation(this);
93            }
94        }
[6474]95    }
[7163]96
[6475]97    /**
98    @brief
99        Initializes the member variables of this PickupRepresentation.
100    */
[6474]101    void PickupRepresentation::initialize(void)
102    {
103        this->description_ = "This is a pickup.";
104        this->name_ = "Pickup";
105        this->spawnerTemplate_ = "";
[6711]106        this->inventoryRepresentation_ = "Default";
[6474]107    }
[7163]108
[7504]109    void PickupRepresentation::registerVariables(void)
110    {
111        registerVariable(this->description_, VariableDirection::ToClient);
112        registerVariable(this->name_, VariableDirection::ToClient);
113        registerVariable(this->inventoryRepresentation_, VariableDirection::ToClient);
114    }
115
[6475]116    /**
117    @brief
118        Method for creating a PickupRepresentation object through XML.
119    */
[6474]120    void PickupRepresentation::XMLPort(Element& xmlelement, XMLPort::Mode mode)
121    {
122        SUPER(PickupRepresentation, XMLPort, xmlelement, mode);
[7163]123
[6711]124        XMLPortParam(PickupRepresentation, "pickupName", setPickupName, getPickupName, xmlelement, mode);
125        XMLPortParam(PickupRepresentation, "pickupDescription", setPickupDescription, getPickupDescription, xmlelement, mode);
[6474]126        XMLPortParam(PickupRepresentation, "spawnerTemplate", setSpawnerTemplate, getSpawnerTemplate, xmlelement, mode);
[6711]127        XMLPortParam(PickupRepresentation, "inventoryRepresentation", setInventoryRepresentation, getInventoryRepresentation, xmlelement, mode);
[6474]128        XMLPortObject(PickupRepresentation, Pickupable, "pickup", setPickup, getPickup, xmlelement, mode);
129        XMLPortObject(PickupRepresentation, StaticEntity, "spawner-representation", setSpawnerRepresentation, getSpawnerRepresentationIndex, xmlelement, mode);
[7163]130
[7504]131        if(GameMode::isMaster())
132        {
133            PickupManager::getInstance().registerRepresentation(this->pickup_->getPickupIdentifier(), this); //!< Registers the PickupRepresentation with the PickupManager through the PickupIdentifier of the Pickupable it represents.
134        }
[7163]135
[6484]136        if(this->spawnerRepresentation_ != NULL)
137            this->spawnerRepresentation_->setVisible(false);
[7163]138
[6484]139        COUT(4) << "PickupRepresentation created: name: '" << this->name_ << "', description: '" << this->description_ << "', spawnerTemplate: '" << this->spawnerTemplate_ << "'." << std::endl;
[6474]140    }
[7163]141
[6475]142    /**
143    @brief
144        Get a spawnerRepresentation for a specific PickupSpawner.
145    @param spawner
146        A pointer to the PickupSpawner.
147    @return
148        Returns a pointer to the StaticEntity.
149    */
[6474]150    StaticEntity* PickupRepresentation::getSpawnerRepresentation(PickupSpawner* spawner)
151    {
152        if(this->spawnerRepresentation_ == NULL)
153        {
154            COUT(4) << "PickupRepresentation: No spawner representation found." << std::endl;
[6475]155            if(this->spawnerTemplate_ == BLANKSTRING)
[6474]156            {
157                COUT(4) << "PickupRepresentation: Spawner template is empty." << std::endl;
[6475]158                //!< If neither spawnerRepresentation nor spawnerTemplate was specified
[6474]159                return this->getDefaultSpawnerRepresentation(spawner);
160            }
161            this->addTemplate(this->spawnerTemplate_);
162        }
[7163]163
[6474]164        StaticEntity* representation = this->spawnerRepresentation_;
[6484]165        representation->setVisible(true);
[7163]166
[6474]167        this->addTemplate(this->spawnerTemplate_);
[6484]168        this->spawnerRepresentation_->setVisible(false);
[7163]169
[6474]170        return representation;
171    }
[7163]172
[6475]173    /**
174    @brief
175        Get the default spawnerRepresentation for a specific PickupSpawner.
176        Helper method of internal use.
177    @param spawner
178        A pointer to the PickupSpawner.
179    @return
180        Returns a pointer to the StaticEntity.
181    */
[6540]182    //TODO: Possibility to define default representation through XML.
[6474]183    StaticEntity* PickupRepresentation::getDefaultSpawnerRepresentation(PickupSpawner* spawner)
184    {
185        StaticEntity* representation = new StaticEntity(spawner);
[6512]186        Billboard* sphere = new Billboard(spawner);
[6676]187        sphere->setColour(ColourValue(0.95f, 0.85f, 0.27f));
[6512]188        sphere->setMaterial("Sphere2");
[6676]189        sphere->setScale(0.1f);
[6512]190        Billboard* icon = new Billboard(spawner);
[6676]191        icon->setColour(ColourValue(0.89f, 0.79f, 0.08f));
[6512]192        icon->setMaterial("Asterix");
193        icon->setScale(0.5);
194        sphere->attach(icon);
195        representation->attach(sphere);
[6474]196        return representation;
197    }
[7163]198
[6474]199}
Note: See TracBrowser for help on using the repository browser.