Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2008, 9:14:14 PM (15 years ago)
Author:
landauf
Message:

found more tabs in pickups ;)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/objects/pickup/ShipEquipmentClasses.cc

    r2089 r2094  
    1 const int maxweapons_ =2; //Weaponslots  (provisorisch)
    2 const int maxslots_= 50; //Inventoryslots (provisorisch)
     1namespace orxonox
     2{
     3    const int maxweapons_ =2; //Weaponslots      (provisorisch)
     4    const int maxslots_= 50; //Inventoryslots (provisorisch)
    35
    46
    5 bool CheckifSpace(){
    6         if((Usable.size()+Trunk.size())>=maxslots_)
    7                 return false;
    8         return true;
     7    bool ShipEquipment::CheckifSpace()
     8    {
     9        if((Usable.size()+Trunk.size())>=maxslots_)
     10            return false;
     11        return true;
     12    }
    913
     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.*/
    1015
     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    }
     67
     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    }
    1192}
    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 }
Note: See TracChangeset for help on using the changeset viewer.