| [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" |
|---|
| [9290] | 37 | #include "PickupCollection.h" |
|---|
| [6538] | 38 | |
|---|
| [6474] | 39 | namespace orxonox |
|---|
| 40 | { |
|---|
| [7163] | 41 | |
|---|
| [6538] | 42 | /** |
|---|
| 43 | @brief |
|---|
| 44 | Constructor. Registers the object. |
|---|
| 45 | */ |
|---|
| [9290] | 46 | PickupCollectionIdentifier::PickupCollectionIdentifier(PickupCollection* collection) : PickupIdentifier(collection) |
|---|
| [6474] | 47 | { |
|---|
| 48 | RegisterObject(PickupCollectionIdentifier); |
|---|
| [9290] | 49 | |
|---|
| 50 | this->collection_ = collection; |
|---|
| [6474] | 51 | } |
|---|
| [7163] | 52 | |
|---|
| [6538] | 53 | /** |
|---|
| 54 | @brief |
|---|
| 55 | Destructor. |
|---|
| 56 | */ |
|---|
| [6474] | 57 | PickupCollectionIdentifier::~PickupCollectionIdentifier() |
|---|
| 58 | { |
|---|
| [7163] | 59 | |
|---|
| [6474] | 60 | } |
|---|
| 61 | |
|---|
| [6538] | 62 | /** |
|---|
| 63 | @brief |
|---|
| 64 | 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. |
|---|
| 65 | @param identifier |
|---|
| 66 | Pointer to the second PickupIdentifier, b. |
|---|
| 67 | @return |
|---|
| 68 | Returns an integer. 0 if the two compared PickupIdentifiers are the same, <0 if a < b and >0 if a > b. |
|---|
| 69 | */ |
|---|
| [6475] | 70 | int PickupCollectionIdentifier::compare(const PickupIdentifier* identifier) const |
|---|
| [6474] | 71 | { |
|---|
| [7494] | 72 | assert(identifier); |
|---|
| 73 | |
|---|
| [9297] | 74 | const PickupCollectionIdentifier* collectionIdentifier = orxonox_cast<const PickupCollectionIdentifier*>(identifier); |
|---|
| [7163] | 75 | |
|---|
| 76 | // If the input PickupIdentifier 'identifier' is no PickupCollectionIdentifier then just the two PickupIdentifiers are compared. |
|---|
| [6474] | 77 | if(collectionIdentifier == NULL) |
|---|
| 78 | { |
|---|
| [6519] | 79 | return this->PickupIdentifier::compare(identifier); |
|---|
| [6474] | 80 | } |
|---|
| [7163] | 81 | |
|---|
| 82 | // If the number of Pickupables each of the two PickupCollectionIdentifiers contain differ, the one with less is considered smaller. |
|---|
| [9290] | 83 | if(this->collection_->getPickups().size() != collectionIdentifier->collection_->getPickups().size()) |
|---|
| 84 | return this->collection_->getPickups().size()-collectionIdentifier->collection_->getPickups().size(); |
|---|
| [7163] | 85 | |
|---|
| 86 | // Compare the Pickupables of the two PickupCollectionIdentifiers one after the other. the one with the first 'smaller' one is considered smaller. |
|---|
| [9290] | 87 | std::list<CollectiblePickup*>::const_iterator it1 = this->collection_->getPickups().begin(); |
|---|
| 88 | std::list<CollectiblePickup*>::const_iterator it2 = collectionIdentifier->collection_->getPickups().begin(); |
|---|
| 89 | for( ; it1 != this->collection_->getPickups().end(); ++it1, ++it2) |
|---|
| [6474] | 90 | { |
|---|
| [9290] | 91 | const PickupIdentifier* id1 = (*it1)->getPickupIdentifier(); |
|---|
| 92 | const PickupIdentifier* id2 = (*it2)->getPickupIdentifier(); |
|---|
| [7163] | 93 | |
|---|
| [9290] | 94 | if(id1->compare(id2) < 0) |
|---|
| [6474] | 95 | return -1; |
|---|
| [9290] | 96 | if(id2->compare(id1) < 0) |
|---|
| [6474] | 97 | return 1; |
|---|
| 98 | } |
|---|
| [7163] | 99 | |
|---|
| [7533] | 100 | // This means they are equal. |
|---|
| [6474] | 101 | return 0; |
|---|
| 102 | } |
|---|
| [7163] | 103 | |
|---|
| [6474] | 104 | } |
|---|
| 105 | |
|---|