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