Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups2/src/orxonox/objects/pickup/BaseItem.cc @ 2972

Last change on this file since 2972 was 2972, checked in by danielh, 15 years ago

Update

  • Minor changes in BaseItem
  • Updated to NotificationQueue from trunk (compile error with old)
  • Added PickupInventory for GUI handling
  • Added basic support for toLua++ methods
  • Property svn:eol-style set to native
File size: 3.0 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 "PickupCollection.h"
37
38#include "core/CoreIncludes.h"
39#include "core/XMLPort.h"
40#include "objects/worldentities/pawns/Pawn.h"
41
42namespace orxonox
43{
44    /**
45        @brief Constructor. Registers the BaseItem.
46        @param creator Pointer to the object which created this item.
47    */
48    BaseItem::BaseItem(BaseObject* creator) : BaseObject(creator)
49    {
50        RegisterObject(BaseItem);
51
52        this->setOwner(0);
53        this->setPickupIdentifier(this->getName());
54    }
55    //! Deconstructor.
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, "guiTooltip", setGUITooltip, getGUITooltip, 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}
Note: See TracBrowser for help on using the repository browser.