[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 | default:; |
---|
| 60 | } |
---|
| 61 | case Useable: |
---|
| 62 | return CheckifSpace(); |
---|
| 63 | case default:; |
---|
| 64 | } |
---|
| 65 | return true; |
---|
| 66 | } |
---|
[2055] | 67 | |
---|
[2094] | 68 | /*Adds the Item to the Ship*/ |
---|
| 69 | void ShipEquipment::AddItem(Shipitem* toAddItem) |
---|
| 70 | { |
---|
| 71 | if(CheckifValid(toAddItem)==true) |
---|
| 72 | { |
---|
| 73 | switch(toAddItem.CheckType()) |
---|
| 74 | { |
---|
| 75 | case Permanent: |
---|
| 76 | Equipment.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); |
---|
| 77 | break; |
---|
| 78 | case Usable: |
---|
| 79 | Usable.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); |
---|
| 80 | break; |
---|
| 81 | case Trunk: |
---|
| 82 | Trunk.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); |
---|
| 83 | break; |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | else if(toAddItem.CheckType()==Permanent) |
---|
| 87 | { |
---|
| 88 | if(CheckifSpace()==true) |
---|
| 89 | Trunk.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); |
---|
| 90 | } |
---|
| 91 | } |
---|
[2055] | 92 | } |
---|