Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7208 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 3.8 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    {
[7163]69        // Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier.
[6475]70        PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier);
[6474]71        const PickupCollectionIdentifier* collectionIdentifier = dynamic_cast<PickupCollectionIdentifier*>(temp);
[7163]72
73        // If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared.
[6474]74        if(collectionIdentifier == NULL)
75        {
[6519]76            return this->PickupIdentifier::compare(identifier);
[6474]77        }
[7163]78
79        // If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller.
[6474]80        if(this->identifiers_.size() != collectionIdentifier->identifiers_.size())
81            return this->identifiers_.size()-collectionIdentifier->identifiers_.size();
[7163]82
83        // Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller.
[6474]84        std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it2 = collectionIdentifier->identifiers_.begin();
85        for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++)
86        {
[7163]87
[6475]88            if((*it)->compare(*it2) < 0)
[6474]89                return -1;
[6475]90            if((*it2)->compare(*it) < 0)
[6474]91                return 1;
92        }
[7163]93
[6538]94        //! Means they are equal.
[6474]95        return 0;
96    }
[7163]97
[6538]98    /**
99    @brief
100        Add a Pickupable to the PickupCollectionIdentifier.
101    @param
102        A pointer to the PickupIdentifier of the Pickupable to be added.
103    */
[6474]104    void PickupCollectionIdentifier::addPickup(const PickupIdentifier* identifier)
105    {
106        this->identifiers_.insert(identifier);
107    }
[7163]108
[6474]109}
110
Note: See TracBrowser for help on using the repository browser.