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