| [2094] | 1 | namespace orxonox | 
|---|
 | 2 | { | 
|---|
 | 3 |     const int maxweapons_ =2; //Weaponslots      (provisorisch) | 
|---|
 | 4 |     const int maxslots_= 50; //Inventoryslots (provisorisch) | 
|---|
| [2055] | 5 |  | 
|---|
 | 6 |  | 
|---|
| [2094] | 7 |     bool ShipEquipment::CheckifSpace() | 
|---|
 | 8 |     { | 
|---|
 | 9 |         if((Usable.size()+Trunk.size())>=maxslots_) | 
|---|
 | 10 |             return false; | 
|---|
 | 11 |         return true; | 
|---|
 | 12 |     } | 
|---|
| [2055] | 13 |  | 
|---|
| [2094] | 14 |     /* Checks if the Ship can pick an Item up. Permanents will give a "false" back unless the Ship doesnt carry a Item for that Slot (2 Weaponslots) yet.Others will be picked up unless there is no Space in the Trunk.*/ | 
|---|
| [2055] | 15 |  | 
|---|
| [2094] | 16 |     bool ShipEquipment::CheckifValid(Shipitem* toBeChecked) | 
|---|
 | 17 |     { | 
|---|
 | 18 |         switch(toBeChecked.CheckType()) | 
|---|
 | 19 |         { | 
|---|
 | 20 |         case Powerups: | 
|---|
 | 21 |             activatePowerUp(); //gibts noch nicht | 
|---|
 | 22 |             return true; | 
|---|
 | 23 |         case Permanent: | 
|---|
 | 24 |             switch (toBeChecked.CheckSubType()) | 
|---|
 | 25 |             { | 
|---|
 | 26 |             case Weapon: | 
|---|
 | 27 |                 int weaponcheck=0; | 
|---|
 | 28 |                 multimap<string, ShipItem*>::iterator it; | 
|---|
 | 29 |                 for ( it=Equipment.begin() ; it != Equipment.end(); it++ ){ | 
|---|
 | 30 |                     if((*it).second->CheckSubType()==Weapon) | 
|---|
 | 31 |                         weaponcheck++; | 
|---|
 | 32 |                 }; | 
|---|
 | 33 |                 if (weaponcheck>=maxweapons_){ | 
|---|
 | 34 |                     weaponcheck=0; | 
|---|
 | 35 |                     return false; | 
|---|
 | 36 |                 } | 
|---|
 | 37 |                 break; | 
|---|
 | 38 |             case Thrusters: | 
|---|
 | 39 |                 multimap<string, ShipItem*>::iterator it; | 
|---|
 | 40 |                 for ( it=Equipment.begin() ; it != Equipment.end(); it++ ){ | 
|---|
 | 41 |                     if((*it).second->CheckSubType()==Thrusters) | 
|---|
 | 42 |                         return false; | 
|---|
 | 43 |                 } | 
|---|
 | 44 |                 break; | 
|---|
 | 45 |             case Shields: | 
|---|
 | 46 |                 multimap<string, ShipItem*>::iterator it; | 
|---|
 | 47 |                 for ( it=Equipment.begin() ; it != Equipment.end(); it++ ){ | 
|---|
 | 48 |                     if((*it).second->CheckSubType()==Shields) | 
|---|
 | 49 |                         return false; | 
|---|
 | 50 |                 } | 
|---|
 | 51 |                 break; | 
|---|
 | 52 |             case Armor: | 
|---|
 | 53 |                 multimap<string, ShipItem*>::iterator it; | 
|---|
 | 54 |                 for ( it=Equipment.begin() ; it != Equipment.end(); it++ ){ | 
|---|
 | 55 |                     if((*it).second->CheckSubType()==Armor) | 
|---|
 | 56 |                         return false; | 
|---|
 | 57 |                 } | 
|---|
 | 58 |                 break; | 
|---|
 | 59 |             } | 
|---|
 | 60 |         case Useable: | 
|---|
 | 61 |             return CheckifSpace(); | 
|---|
 | 62 |         } | 
|---|
 | 63 |         return true; | 
|---|
 | 64 |     } | 
|---|
| [2055] | 65 |  | 
|---|
| [2094] | 66 |     /*Adds the Item to the Ship*/ | 
|---|
| [2662] | 67 |     void ShipEquipment::AddItem(ShipItem* toAddItem) | 
|---|
| [2094] | 68 |     { | 
|---|
 | 69 |         if(CheckifValid(toAddItem)==true) | 
|---|
 | 70 |         { | 
|---|
 | 71 |             switch(toAddItem.CheckType()) | 
|---|
 | 72 |             { | 
|---|
 | 73 |                 case Permanent: | 
|---|
 | 74 |                     Equipment.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); | 
|---|
 | 75 |                     break; | 
|---|
 | 76 |                 case Usable: | 
|---|
 | 77 |                     Usable.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); | 
|---|
 | 78 |                     break; | 
|---|
 | 79 |                 case Trunk: | 
|---|
 | 80 |                     Trunk.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); | 
|---|
 | 81 |                     break; | 
|---|
 | 82 |             } | 
|---|
 | 83 |         } | 
|---|
 | 84 |         else if(toAddItem.CheckType()==Permanent) | 
|---|
 | 85 |         { | 
|---|
 | 86 |             if(CheckifSpace()==true) | 
|---|
 | 87 |                 Trunk.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); | 
|---|
 | 88 |         } | 
|---|
 | 89 |     } | 
|---|
| [2662] | 90 |  | 
|---|
 | 91 |     /*Adds the Item to the Ship*/ | 
|---|
 | 92 |     void ShipEquipment::AddItem(Shipitem* toAddItem) | 
|---|
 | 93 |     { | 
|---|
 | 94 |         if(CheckifValid(toAddItem)==true) | 
|---|
 | 95 |         { | 
|---|
 | 96 |             switch(toAddItem.CheckType()){ | 
|---|
 | 97 |                 case Permanent: | 
|---|
 | 98 |                     Equipment.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,toAddItem) ); | 
|---|
 | 99 |                     break; | 
|---|
 | 100 |                 case Usable: | 
|---|
 | 101 |                     Usable.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,toAddItem) ); | 
|---|
 | 102 |                     break; | 
|---|
 | 103 |                 case Trunk: | 
|---|
 | 104 |                     Trunk.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,toAddItem) ); | 
|---|
 | 105 |                     break; | 
|---|
 | 106 |             } | 
|---|
 | 107 |         } | 
|---|
 | 108 |         else if(toAddItem.CheckType()==Permanent) | 
|---|
 | 109 |         { | 
|---|
 | 110 |             if(CheckifSpace()==true) | 
|---|
 | 111 |                 Trunk.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,toAddItem) ); | 
|---|
 | 112 |         } | 
|---|
 | 113 |     } | 
|---|
 | 114 |  | 
|---|
 | 115 |     void ShipEquipment::SwitchItem(Permanent* toSwitchItem) | 
|---|
 | 116 |     { | 
|---|
 | 117 |         multimap<string, ShipItem*>::iterator it; | 
|---|
 | 118 |         string equippedname; | 
|---|
 | 119 |         equippedname=GetNameofPermanent(toSwitchItem.CheckSubType()); | 
|---|
 | 120 |         it=Equipment.find(equippedname); | 
|---|
 | 121 |         Trunk.insert (find(equippedname)); | 
|---|
 | 122 |         Equipment.erase (it); | 
|---|
 | 123 |         Equipment.insert(pair<std::string, ShipItem*>(toSwitchItem.itemname,toSwitchItem) | 
|---|
 | 124 |     } | 
|---|
 | 125 |  | 
|---|
 | 126 |     string ShipEquipment::GetNameofPermanent (subItemTypePermanent NametoGet) | 
|---|
 | 127 |     { | 
|---|
 | 128 |         multimap<string, ShipItem*>::iterator it; | 
|---|
 | 129 |         for ( it=Equipment.begin() ; it != Equipment.end(); it++ ){ | 
|---|
 | 130 |             if((*it).second->CheckSubType()==NametoGet){ | 
|---|
 | 131 |                 return (*it).first.itemname; | 
|---|
 | 132 |             } | 
|---|
 | 133 |         } | 
|---|
 | 134 |         return 0; | 
|---|
 | 135 |     } | 
|---|
| [2055] | 136 | } | 
|---|