1 | const int maxweapons_ =2; //Weaponslots (provisorisch) |
---|
2 | const int maxslots_= 50; //Inventoryslots (provisorisch) |
---|
3 | |
---|
4 | |
---|
5 | bool CheckifSpace(){ |
---|
6 | if((Usable.size()+Trunk.size())>=maxslots_) |
---|
7 | return false; |
---|
8 | return true; |
---|
9 | |
---|
10 | |
---|
11 | } |
---|
12 | |
---|
13 | /* 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.*/ |
---|
14 | |
---|
15 | bool CheckifValid(Shipitem* toBeChecked){ |
---|
16 | |
---|
17 | switch(toBeChecked.CheckType()) |
---|
18 | { |
---|
19 | case Powerups: |
---|
20 | activatePowerUp(); //gibts noch nicht |
---|
21 | return true; |
---|
22 | case Permanent: |
---|
23 | switch (toBeChecked.CheckSubType()) |
---|
24 | { |
---|
25 | case Weapon: |
---|
26 | int weaponcheck=0; |
---|
27 | multimap<string, ShipItem*>::iterator it; |
---|
28 | for ( it=Equipment.begin() ; it != Equipment.end(); it++ ){ |
---|
29 | if((*it).second->CheckSubType()==Weapon) |
---|
30 | weaponcheck++; |
---|
31 | }; |
---|
32 | if (weaponcheck>=maxweapons_){ |
---|
33 | weaponcheck=0; |
---|
34 | return false; |
---|
35 | } |
---|
36 | case Thrusters: |
---|
37 | multimap<string, ShipItem*>::iterator it; |
---|
38 | for ( it=Equipment.begin() ; it != Equipment.end(); it++ ){ |
---|
39 | if((*it).second->CheckSubType()==Thrusters) |
---|
40 | return false; |
---|
41 | } |
---|
42 | case Shields: |
---|
43 | multimap<string, ShipItem*>::iterator it; |
---|
44 | for ( it=Equipment.begin() ; it != Equipment.end(); it++ ){ |
---|
45 | if((*it).second->CheckSubType()==Shields) |
---|
46 | return false; |
---|
47 | } |
---|
48 | case Armor: |
---|
49 | multimap<string, ShipItem*>::iterator it; |
---|
50 | for ( it=Equipment.begin() ; it != Equipment.end(); it++ ){ |
---|
51 | if((*it).second->CheckSubType()==Armor) |
---|
52 | return false; |
---|
53 | } |
---|
54 | } |
---|
55 | case Useable: |
---|
56 | return CheckifSpace(); |
---|
57 | } |
---|
58 | return true; |
---|
59 | } |
---|
60 | /*Adds the Item to the Ship*/ |
---|
61 | void AddItem(Shipitem* toAddItem){ |
---|
62 | if(CheckifValid(toAddItem)==true){ |
---|
63 | switch(toAddItem.CheckType()){ |
---|
64 | case Permanent: |
---|
65 | Equipment.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); |
---|
66 | break; |
---|
67 | case Usable: |
---|
68 | Usable.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); |
---|
69 | break; |
---|
70 | case Trunk: |
---|
71 | Trunk.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); |
---|
72 | break; |
---|
73 | } |
---|
74 | |
---|
75 | } |
---|
76 | else if(toAddItem.CheckType()==Permanent){ |
---|
77 | if(CheckifSpace()==true) |
---|
78 | Trunk.insert ( pair<std::string, ShipItem*>(toAddItem.itemname,*toAddItem) ); |
---|
79 | |
---|
80 | } |
---|
81 | |
---|
82 | } |
---|