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 | #include "PickupIdentifier.h" |
---|
30 | |
---|
31 | #include "core/CoreIncludes.h" |
---|
32 | |
---|
33 | namespace orxonox |
---|
34 | { |
---|
35 | |
---|
36 | PickupIdentifier::PickupIdentifier() |
---|
37 | { |
---|
38 | RegisterRootObject(PickupIdentifier); |
---|
39 | |
---|
40 | |
---|
41 | } |
---|
42 | |
---|
43 | PickupIdentifier::~PickupIdentifier() |
---|
44 | { |
---|
45 | |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | @brief |
---|
50 | Compares two PickupIdentifiers and returns 0 if a == b, <0 if a < b and >0 if a > b for a.compare(b). |
---|
51 | @param identifier |
---|
52 | Pointer to the second PickupIdentifier, b. |
---|
53 | @return |
---|
54 | Returns an int. |
---|
55 | */ |
---|
56 | int PickupIdentifier::compare(const PickupIdentifier& identifier) const |
---|
57 | { |
---|
58 | if(!identifier.classIdentifier_->isExactlyA(this->classIdentifier_)) |
---|
59 | return this->classIdentifier_->getName().compare(identifier.classIdentifier_->getName()); |
---|
60 | |
---|
61 | if(!(this->parameters_.size() == identifier.parameters_.size())) |
---|
62 | { |
---|
63 | COUT(1) << "Something went wrong in PickupIdentifier!" << std::endl; |
---|
64 | return this->parameters_.size()-identifier.parameters_.size(); |
---|
65 | } |
---|
66 | |
---|
67 | for(std::map<std::string, std::string>::const_iterator it = this->parameters_.begin(); it != this->parameters_.end(); it++) |
---|
68 | { |
---|
69 | if(identifier.parameters_.find(it->first) == identifier.parameters_.end()) |
---|
70 | { |
---|
71 | COUT(1) << "Something went wrong in PickupIdentifier!" << std::endl; |
---|
72 | return -1; |
---|
73 | } |
---|
74 | if(identifier.parameters_.find(it->first)->second != it->second) |
---|
75 | return it->second.compare(identifier.parameters_.find(it->first)->second); |
---|
76 | } |
---|
77 | |
---|
78 | return false; |
---|
79 | } |
---|
80 | |
---|
81 | void PickupIdentifier::addClass(Identifier* identifier) |
---|
82 | { |
---|
83 | this->classIdentifier_ = identifier; |
---|
84 | } |
---|
85 | |
---|
86 | bool PickupIdentifier::addParameter(std::string & name, std::string & value) |
---|
87 | { |
---|
88 | if(!(this->parameters_.find(name) == this->parameters_.end())) |
---|
89 | { |
---|
90 | COUT(2) << "Request for adding a parameter that already exists for the PickupIdentififer was denied." << std::endl; |
---|
91 | return false; |
---|
92 | } |
---|
93 | |
---|
94 | this->parameters_[name] = value; |
---|
95 | |
---|
96 | return true; |
---|
97 | } |
---|
98 | |
---|
99 | } |
---|