Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/pickup/BaseItem.cc @ 5781

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

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

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