Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/pickup/PickupCollectionIdentifier.cc @ 9264

Last change on this file since 9264 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
RevLine 
[6474]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:
[6538]23 *      Damian 'Mozork' Frick
[6474]24 *   Co-authors:
25 *      ...
26 *
27*/
28
[6538]29/**
30    @file PickupCollectionIdentifier.cc
31    @brief Implementation of PickupCollectionIdentifier.
32*/
[6474]33
34#include "core/CoreIncludes.h"
35
[6538]36#include "PickupCollectionIdentifier.h"
37
[6474]38namespace orxonox
39{
[7163]40
[6538]41    /**
42    @brief
43        Constructor. Registers the object.
44    */
[6480]45    PickupCollectionIdentifier::PickupCollectionIdentifier(Pickupable* pickup) : PickupIdentifier(pickup)
[6474]46    {
47        RegisterObject(PickupCollectionIdentifier);
48    }
[7163]49
[6538]50    /**
51    @brief
52        Destructor.
53    */
[6474]54    PickupCollectionIdentifier::~PickupCollectionIdentifier()
55    {
[7163]56
[6474]57    }
58
[6538]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    */
[6475]67    int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const
[6474]68    {
[7494]69        assert(identifier);
70
[7533]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.
[6475]72        PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier);
[7494]73        const PickupCollectionIdentifier* collectionIdentifier = orxonox_cast<PickupCollectionIdentifier*>(temp);
[7163]74
75        // If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.
[6474]76        if(collectionIdentifier == NULL)
77        {
[6519]78            return this->PickupIdentifier::compare(identifier);
[6474]79        }
[7163]80
81        // If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
[6474]82        if(this->identifiers_.size() != collectionIdentifier->identifiers_.size())
83            return this->identifiers_.size()-collectionIdentifier->identifiers_.size();
[7163]84
85        // Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
[6474]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        {
[7163]89
[6475]90            if((*it)->compare(*it2) < 0)
[6474]91                return -1;
[6475]92            if((*it2)->compare(*it) < 0)
[6474]93                return 1;
94        }
[7163]95
[7533]96        // This means they are equal.
[6474]97        return 0;
98    }
[7163]99
[6538]100    /**
101    @brief
102        Add a Pickupable to the PickupCollectionIdentifier.
[7401]103    @param identifier
[6538]104        A pointer to the PickupIdentifier of the Pickupable to be added.
105    */
[6474]106    void PickupCollectionIdentifier::addPickup(const PickupIdentifier* identifier)
107    {
108        this->identifiers_.insert(identifier);
109    }
[7163]110
[6474]111}
112
Note: See TracBrowser for help on using the repository browser.