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