Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pch/src/orxonox/objects/pickup/BaseItem.cc @ 3180

Last change on this file since 3180 was 3180, checked in by rgrieder, 15 years ago

Cleanup in pickup and quest (almost only cleaned the header file sections).

  • Property svn:eol-style set to native
File size: 3.1 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 *      Daniel 'Huty' Haggenmueller
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @brief Implementation of BaseItem (base-class for items/pickups).
32*/
33
34#include "BaseItem.h"
35
36#include "util/Debug.h"
37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
39#include "objects/worldentities/pawns/Pawn.h"
40
41namespace orxonox
42{
43    /**
44        @brief Constructor. Registers the BaseItem.
45        @param creator Pointer to the object which created this item.
46    */
47    BaseItem::BaseItem(BaseObject* creator) : BaseObject(creator)
48    {
49        RegisterObject(BaseItem);
50
51        this->setOwner(0);
52        this->setPickupIdentifier(this->getName());
53        this->setGUIImage("");
54        this->setGUIText("");
55    }
56    //! Destructor.
57    BaseItem::~BaseItem()
58    {
59    }
60
61    /**
62        @brief XMLPort for BaseItem.
63        @param xmlelement Element of the XML-file.
64        @param mode XMLPort mode to use.
65    */
66    void BaseItem::XMLPort(Element& xmlelement, XMLPort::Mode mode)
67    {
68        SUPER(BaseItem, XMLPort, xmlelement, mode);
69
70        XMLPortParam(BaseItem, "guiText", setGUIText, getGUIText, xmlelement, mode);
71        XMLPortParam(BaseItem, "guiImage", setGUIImage, getGUIImage, xmlelement, mode);
72    }
73
74    /**
75        @brief Method to add the item to a pawn.
76        @param pawn Pawn to which the item should get added.
77        @return Returns whether the pawn's PickupCollection accepted the item.
78    */
79    bool BaseItem::addTo(Pawn* pawn)
80    {
81        this->setOwner(pawn);
82
83        if (pawn->getPickups().add(this))
84        {
85            COUT(3) << "Added '" << this->getPickupIdentifier() << "' item." << std::endl;
86            return true;
87        }
88        return false;
89    }
90    /**
91        @brief Removes the item from a pawn.
92        @param pawn Pawn from which to remove the item.
93        @return Returns whether the pawn's PickupCollection was able to locate and remove the item.
94    */
95    bool BaseItem::removeFrom(Pawn* pawn)
96    {
97        this->setOwner(0);
98
99        COUT(3) << "Removing '" << this->getPickupIdentifier() << "' item." << std::endl;
100
101        pawn->getPickups().remove(this, false);
102
103        return true;
104    }
105
106    const std::string& BaseItem::getGUIText() const
107    {
108        return this->guiText_;
109    }
110}
Note: See TracBrowser for help on using the repository browser.