[2503] | 1 | #include "OrxonoxStableHeaders.h" |
---|
[2500] | 2 | #include "BaseItem.h" |
---|
[2294] | 3 | #include "ShipEquipment.h" |
---|
[2324] | 4 | #include "objects/worldentities/pawns/Pawn.h" |
---|
[2289] | 5 | |
---|
| 6 | |
---|
| 7 | namespace orxonox |
---|
| 8 | { |
---|
[2397] | 9 | /** |
---|
| 10 | @brief |
---|
| 11 | Insert a permanent Item to the Equipment. Is usually called by the addTo function in Items. |
---|
[2500] | 12 | |
---|
[2397] | 13 | @param item |
---|
| 14 | pointer to the item which is to be inserted. |
---|
[2324] | 15 | |
---|
[2397] | 16 | @return |
---|
| 17 | if new item has sucessfully been added it will return true, in any other case the return value is false. |
---|
| 18 | */ |
---|
[2500] | 19 | bool ShipEquipment::insert(BaseItem* item) |
---|
[2289] | 20 | { |
---|
[2389] | 21 | if(checkSlot(item)==NULL) |
---|
[2324] | 22 | { |
---|
[2500] | 23 | Equipment.insert ( std::pair<std::string, BaseItem*>(item->getName(),item) ); |
---|
[2324] | 24 | return true; |
---|
| 25 | } |
---|
[2389] | 26 | else |
---|
| 27 | { |
---|
| 28 | COUT(3) << "SWAP?" << endl; |
---|
[2500] | 29 | //Abfrage- irgendne ifschleife... |
---|
[2503] | 30 | if((checkSlot(item)->dropped(player))==true) |
---|
[2389] | 31 | { |
---|
[2500] | 32 | Equipment.insert ( std::pair<std::string, BaseItem*>(item->getName(),item) ); |
---|
[2389] | 33 | COUT(3) << "SWAPPED!" << endl; |
---|
| 34 | return true; |
---|
| 35 | } |
---|
[2324] | 36 | return false; |
---|
[2389] | 37 | } |
---|
[2342] | 38 | |
---|
[2324] | 39 | return false; |
---|
[2290] | 40 | }; |
---|
[2397] | 41 | |
---|
| 42 | /** |
---|
| 43 | @brief |
---|
| 44 | Erases a permanent Item in the Equipment. Is usually called by the remove/dropped function in Items. |
---|
[2500] | 45 | |
---|
[2397] | 46 | @param item |
---|
| 47 | pointer to the item which is to be erased. |
---|
| 48 | |
---|
| 49 | @return |
---|
| 50 | if new item has sucessfully been erased it will return true, in any other case the return value is false. |
---|
| 51 | */ |
---|
[2500] | 52 | bool ShipEquipment::erase (BaseItem* item) |
---|
[2290] | 53 | { |
---|
[2500] | 54 | std::multimap<std::string,BaseItem*>::iterator it = Equipment.find(item->getName()); |
---|
[2324] | 55 | if(it != Equipment.end()) |
---|
[2290] | 56 | { |
---|
| 57 | Equipment.erase (it); |
---|
| 58 | return true; |
---|
| 59 | } |
---|
[2342] | 60 | return false; |
---|
[2290] | 61 | }; |
---|
[2500] | 62 | /*void print(std::multimap<std::string, BaseItem*> eut) |
---|
[2342] | 63 | { |
---|
[2500] | 64 | std::multimap<std::string,BaseItem*>::iterator it; |
---|
[2342] | 65 | COUT(3) << "Liste:" << endl; |
---|
| 66 | for ( it=eut.begin() ; it != eut.end(); ++it ) |
---|
| 67 | COUT(3) << (*it).first << endl; |
---|
[2324] | 68 | |
---|
[2342] | 69 | }*/ |
---|
[2397] | 70 | /** |
---|
| 71 | @brief |
---|
| 72 | Erases all permanent Items in the Equipment. Its Triggered by hitting the L button. |
---|
| 73 | |
---|
| 74 | */ |
---|
[2324] | 75 | void ShipEquipment::eraseAll() |
---|
[2290] | 76 | { |
---|
[2342] | 77 | //print(Equipment); |
---|
[2500] | 78 | for (std::multimap<std::string,BaseItem*>::iterator it = Equipment.begin(); it != Equipment.end(); ) |
---|
[2324] | 79 | { |
---|
[2342] | 80 | |
---|
[2324] | 81 | (it++)->second->dropped(this->getPlayer()); |
---|
| 82 | } |
---|
[2342] | 83 | //print(Equipment); |
---|
[2324] | 84 | } |
---|
| 85 | |
---|
[2500] | 86 | BaseItem* ShipEquipment::checkSlot(BaseItem* item) |
---|
[2324] | 87 | { |
---|
[2500] | 88 | std::multimap<std::string,BaseItem*>::iterator it; |
---|
[2324] | 89 | for ( it= getPlayer()->getPickUp().getEquipment().begin() ; it != getPlayer()->getPickUp().getEquipment().end(); it++ ) |
---|
[2290] | 90 | { |
---|
[2342] | 91 | //if((*it).second->getPlayerBaseClass()==item->getPlayerBaseClass()) |
---|
| 92 | if(item->isExactlyA((*it).second->getIdentifier())) |
---|
[2389] | 93 | return (*it).second; |
---|
[2289] | 94 | } |
---|
[2389] | 95 | return NULL; |
---|
[2290] | 96 | }; |
---|
[2500] | 97 | |
---|
[2289] | 98 | } |
---|