Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickup3/src/modules/pickup/PickupCollectionIdentifier.cc @ 6480

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

Simplification in creation of PickupIdentifier.

File size: 2.5 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 *      ...
24 *   Co-authors:
25 *      ...
26 *
27*/
28
29#include "PickupCollectionIdentifier.h"
30
31#include "core/CoreIncludes.h"
32
33namespace orxonox
34{
35   
36    PickupCollectionIdentifier::PickupCollectionIdentifier(Pickupable* pickup) : PickupIdentifier(pickup)
37    {
38        RegisterObject(PickupCollectionIdentifier);
39    }
40   
41    PickupCollectionIdentifier::~PickupCollectionIdentifier()
42    {
43       
44    }
45
46    int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const
47    {
48        PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier);
49        const PickupCollectionIdentifier* collectionIdentifier = dynamic_cast<PickupCollectionIdentifier*>(temp);
50        if(collectionIdentifier == NULL)
51        {
52            return this->compare(identifier);
53        }
54       
55        if(this->identifiers_.size() != collectionIdentifier->identifiers_.size())
56            return this->identifiers_.size()-collectionIdentifier->identifiers_.size();
57       
58        std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it2 = collectionIdentifier->identifiers_.begin();
59        for(std::set<const PickupIdentifier*, PickupIdentifierCompare>::const_iterator it = this->identifiers_.begin(); it != this->identifiers_.end(); it++)
60        {
61           
62            if((*it)->compare(*it2) < 0)
63                return -1;
64            if((*it2)->compare(*it) < 0)
65                return 1;
66        }
67       
68        return 0;
69    }
70   
71    void PickupCollectionIdentifier::addPickup(const PickupIdentifier* identifier)
72    {
73        this->identifiers_.insert(identifier);
74    }
75   
76}
77
Note: See TracBrowser for help on using the repository browser.