Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network6/src/modules/pickup/CollectiblePickup.cc @ 8098

Last change on this file since 8098 was 7494, checked in by dafrick, 14 years ago

Some documenting and cleaning up/re-organization in pickups module.

  • Property svn:eol-style set to native
File size: 4.7 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() : isInCollection_(false)
48    {
49        RegisterObject(CollectiblePickup);
50
51        this->collection_ = NULL;
52    }
53
54    /**
55    @brief
56        Destructor.
57    */
58    CollectiblePickup::~CollectiblePickup()
59    {
60
61    }
62
63    /**
64    @brief
65        Is called by OrxonoxClass::destroy() before the object is actually destroyed.
66    */
67    void CollectiblePickup::preDestroy(void)
68    {
69        this->Pickupable::preDestroy();
70
71        // The PickupCollection has to be destroyed as well.
72        if(this->isInCollection())
73            this->collection_->Pickupable::destroy();
74    }
75
76    /**
77    @brief
78        Destroys a Pickupable.
79    */
80    void CollectiblePickup::destroyPickup(void)
81    {
82        if(!this->isInCollection()) // If the CollectiblePickup is not in a PickupCollection the destroyPickup method of Pickupable is called.
83            this->Pickupable::destroyPickup();
84        else // Else the ColectiblePickup is dropped and disabled,
85        {
86            this->drop(false);
87            if(this->isInCollection() && this->isEnabled()) // It is only disabled if it is enabled and still ina PickupCollection after having been dropped.
88            {
89                this->setDisabled();
90                this->collection_->pickupDisabled();
91            }
92        }
93    }
94
95    /**
96    @brief
97        Is called by the PickupCarrier when it is being destroyed.
98    */
99    void CollectiblePickup::carrierDestroyed(void)
100    {
101        if(!this->isInCollection())
102            this->Pickupable::destroy();
103        else // If the CollectiblePickup is part of a PickupCollection it is just dropped instead of destroyed.
104            this->drop(false);
105    }
106
107    /**
108    @brief
109        Is called when the pickup has transited from used to unused or the other way around.
110    */
111    void CollectiblePickup::changedUsed(void)
112    {
113        SUPER(CollectiblePickup, changedUsed);
114
115        if(this->isInCollection())
116            this->collection_->pickupChangedUsed(this->isUsed());
117    }
118
119    /**
120    @brief
121        Is called when the pickup has transited from picked up to dropped or the other way around.
122    */
123    void CollectiblePickup::changedPickedUp(void)
124    {
125        SUPER(CollectiblePickup, changedPickedUp);
126
127        if(this->isInCollection())
128            this->collection_->pickupChangedPickedUp(this->isPickedUp());
129    }
130
131    /**
132    @brief
133        Adds this CollectiblePickup to the input PickupCollection.
134    @param collection
135        A pointer to the PickupCollection to which the CollectiblePickup should be added.
136    @return
137        Returns true if the CollectiblePickup was successfully added to the PickupCollection.
138    */
139    bool CollectiblePickup::addToCollection(PickupCollection* collection)
140    {
141        if(this->isInCollection() || collection == NULL) //If the CollectiblePickup already is in a PickupCollection or if the input pointer is NULL.
142            return false;
143
144        this->isInCollection_ = true;
145        this->collection_ = collection;
146        return true;
147    }
148
149    /**
150    @brief
151        Removes this CollectiblePickup from its PickupCollection.
152    @return
153        Returns true if the CollectiblePickup was succcessfully removed.
154    */
155    bool CollectiblePickup::removeFromCollection(void)
156    {
157        if(!this->isInCollection()) //If the CollectiblePickup is not in a PickupCollection.
158            return false;
159
160        this->isInCollection_ = false;
161        this->collection_ = NULL;
162        return true;
163    }
164
165}
Note: See TracBrowser for help on using the repository browser.