Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/kicklib/src/modules/pickup/PickupCollectionIdentifier.cc @ 7944

Last change on this file since 7944 was 7533, checked in by dafrick, 14 years ago

Documenting in pickups module.
Cleaning up in PickupManager.
Removed some obsolete functions in HumanController and ControllableEntity, which were remenants of the old pickups module.
Fixed a bug.

  • Property svn:eol-style set to native
File size: 3.9 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 PickupCollectionIdentifier.cc
31    @brief Implementation of PickupCollectionIdentifier.
32*/
33
34#include "core/CoreIncludes.h"
35
36#include "PickupCollectionIdentifier.h"
37
38namespace orxonox
39{
40
41    /**
42    @brief
43        Constructor. Registers the object.
44    */
45    PickupCollectionIdentifier::PickupCollectionIdentifier(Pickupable* pickup) : PickupIdentifier(pickup)
46    {
47        RegisterObject(PickupCollectionIdentifier);
48    }
49
50    /**
51    @brief
52        Destructor.
53    */
54    PickupCollectionIdentifier::~PickupCollectionIdentifier()
55    {
56
57    }
58
59    /**
60    @brief
61        Compares a PickupCollectionIdentifier with a PickupIdentifier and returns 0 if a == b, <0 if a < b and >0 if a > b for a.compare(b), where a is a PickupCollectionIdentifier and b is just some PickupIdentifier.
62    @param identifier
63        Pointer to the second PickupIdentifier, b.
64    @return
65        Returns an integer. 0 if the two compared PickupIdentifiers are the same, <0 if a < b and >0 if a > b.
66    */
67    int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const
68    {
69        assert(identifier);
70
71        // Slight un-niceity to cast the const PickupIdentifier to a const PickupCollectionIdentifier, but since we cast to a const, there is no harm done.
72        PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier);
73        const PickupCollectionIdentifier* collectionIdentifier = orxonox_cast<PickupCollectionIdentifier*>(temp);
74
75        // If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.
76        if(collectionIdentifier == NULL)
77        {
78            return this->PickupIdentifier::compare(identifier);
79        }
80
81        // If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
82        if(this->identifiers_.size() != collectionIdentifier->identifiers_.size())
83            return this->identifiers_.size()-collectionIdentifier->identifiers_.size();
84
85        // Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
86        std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it2 = collectionIdentifier->identifiers_.begin();
87        for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++)
88        {
89
90            if((*it)->compare(*it2) < 0)
91                return -1;
92            if((*it2)->compare(*it) < 0)
93                return 1;
94        }
95
96        // This means they are equal.
97        return 0;
98    }
99
100    /**
101    @brief
102        Add a Pickupable to the PickupCollectionIdentifier.
103    @param identifier
104        A pointer to the PickupIdentifier of the Pickupable to be added.
105    */
106    void PickupCollectionIdentifier::addPickup(const PickupIdentifier* identifier)
107    {
108        this->identifiers_.insert(identifier);
109    }
110
111}
112
Note: See TracBrowser for help on using the repository browser.