Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2012merge/src/modules/pickup/CollectiblePickup.cc @ 9301

Last change on this file since 9301 was 9296, checked in by landauf, 12 years ago

remove dropped pickups from their collection

  • Property svn:eol-style set to native
File size: 3.3 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/**
30    @file CollectiblePickup.cc
31    @brief Implementation of the CollectiblePickup class.
32*/
33
34#include "CollectiblePickup.h"
35
36#include "core/CoreIncludes.h"
37
38#include "PickupCollection.h"
39
40namespace orxonox {
41
42    /**
43    @brief
44        Constructor.
45        Registers the object and initializes variables.
46    */
47    CollectiblePickup::CollectiblePickup() : collection_(NULL)
48    {
49        RegisterObject(CollectiblePickup);
50    }
51
52    /**
53    @brief
54        Destructor.
55    */
56    CollectiblePickup::~CollectiblePickup()
57    {
58        if (this->isInCollection())
59            this->collection_->removePickupable(this);
60    }
61
62    /**
63    @brief
64        Is called by the PickupCarrier when it is being destroyed.
65    */
66    void CollectiblePickup::carrierDestroyed(void)
67    {
68        if(!this->isInCollection())
69            this->Pickupable::destroy();
70        else // If the CollectiblePickup is part of a PickupCollection it is just dropped instead of destroyed.
71            this->drop(false);
72    }
73
74    /**
75    @brief
76        Is called when the pickup has transited from used to unused or the other way around.
77    */
78    void CollectiblePickup::changedUsed(void)
79    {
80        SUPER(CollectiblePickup, changedUsed);
81
82        if(this->isInCollection())
83            this->collection_->pickupChangedUsed(this->isUsed());
84    }
85
86    /**
87    @brief
88        Is called when the pickup has transited from picked up to dropped or the other way around.
89    */
90    void CollectiblePickup::changedPickedUp(void)
91    {
92        SUPER(CollectiblePickup, changedPickedUp);
93
94        if(this->isInCollection())
95        {
96            if (!this->isPickedUp())
97                this->collection_->removePickupable(this);
98            else
99                this->collection_->pickupChangedPickedUp(this->isPickedUp());
100        }
101    }
102
103    /**
104    @brief
105        Notifies this CollectiblePickup that it was added to a PickupCollection.
106    @param collection
107        A pointer to the PickupCollection to which the CollectiblePickup should be added.
108    */
109    void CollectiblePickup::wasAddedToCollection(PickupCollection* collection)
110    {
111        this->collection_ = collection;
112    }
113
114    /**
115    @brief
116        Notifies this CollectiblePickup that it was removed from its PickupCollection.
117    */
118    void CollectiblePickup::wasRemovedFromCollection(void)
119    {
120        this->collection_ = NULL;
121    }
122}
Note: See TracBrowser for help on using the repository browser.