1 | /* has to be added to player |
---|
2 | multimap<std::string, Item*> Equipment;*/ |
---|
3 | |
---|
4 | #include "Item.h" |
---|
5 | #include "core/CoreIncludes.h" |
---|
6 | #include "core/XMLPort.h" |
---|
7 | #include "util/String.h" |
---|
8 | #include "objects/worldentities/pawns/Pawn.h" |
---|
9 | |
---|
10 | namespace orxonox |
---|
11 | { |
---|
12 | Item::Item(BaseObject* creator) : BaseObject(creator) |
---|
13 | { |
---|
14 | RegisterObject(Item); |
---|
15 | |
---|
16 | this->playerBaseClass_ = 0; |
---|
17 | } |
---|
18 | |
---|
19 | Item::~Item() |
---|
20 | { |
---|
21 | } |
---|
22 | void Item::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
23 | { |
---|
24 | SUPER(Item, XMLPort, xmlelement, mode); |
---|
25 | |
---|
26 | XMLPortParam(Item, "playerclass", setPlayerBaseClassName, getPlayerBaseClassName, xmlelement, mode); |
---|
27 | } |
---|
28 | |
---|
29 | void Item::addTo (Pawn* player) |
---|
30 | { |
---|
31 | if(checkSlot(player)==true) |
---|
32 | player->pickUp.Equipment.insert ( std::pair<std::string, Item*>(this->getName(),this) ); |
---|
33 | else |
---|
34 | COUT(3) << "swap?" << std::endl; |
---|
35 | } |
---|
36 | bool Item::remove(Pawn* player) |
---|
37 | { |
---|
38 | if(player->pickUp.Equipment.find(this->getName())!= player->pickUp.Equipment.end()) |
---|
39 | { |
---|
40 | std::multimap<std::string,Item*>::iterator it; |
---|
41 | it=player->pickUp.Equipment.find(this->getName()); |
---|
42 | player->pickUp.Equipment.erase (it); |
---|
43 | return true; |
---|
44 | } |
---|
45 | else |
---|
46 | return false; |
---|
47 | } |
---|
48 | bool Item::checkSlot(Pawn* player) |
---|
49 | { |
---|
50 | std::multimap<std::string,Item*>::iterator it; |
---|
51 | for ( it=player->pickUp.Equipment.begin() ; it != player->pickUp.Equipment.end(); it++ ) |
---|
52 | { |
---|
53 | if((*it).second->playerBaseClass_==this->playerBaseClass_) |
---|
54 | return false; |
---|
55 | } |
---|
56 | return true; |
---|
57 | } |
---|
58 | void Item::setPlayerBaseClassName(const std::string& name) |
---|
59 | { |
---|
60 | this->playerBaseClass_ = ClassByString(name); |
---|
61 | } |
---|
62 | |
---|
63 | const std::string& Item::getPlayerBaseClassName() const |
---|
64 | { |
---|
65 | if (this->playerBaseClass_) |
---|
66 | return this->playerBaseClass_->getName(); |
---|
67 | else |
---|
68 | return BLANKSTRING; |
---|
69 | } |
---|
70 | } |
---|