Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8762 for code/branches/ai2


Ignore:
Timestamp:
Jul 17, 2011, 11:43:20 PM (13 years ago)
Author:
jo
Message:

Weaponsetup now generic. Munition management has not jet been implemented.

Location:
code/branches/ai2/src/orxonox/controllers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.cc

    r8761 r8762  
    318318        this->bSetupWorked = false;        // reset weapon information
    319319        this->numberOfWeapons = 0;
    320         COUT(0)<<"ArtificialController::changedControllableEntity()"<<endl; //why is this function called more than once ??
     320        this->setupWeapons();
    321321    }
    322322
     
    10401040    void ArtificialController::doFire()
    10411041    {
    1042         if(!bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
     1042        if(!this->bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
    10431043        {
    10441044            this->setupWeapons();
    10451045            if(numberOfWeapons > 0)
    1046                 bSetupWorked = true;
     1046                this->bSetupWorked = true;
    10471047        }
    10481048        else if(this->getControllableEntity() && (numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
    10491049        {
    10501050            float random = rnd(1);//
    1051             if (this->isCloseAtTarget(130) && weapons[1] )
     1051            if (this->isCloseAtTarget(130) && (weaponModes[1]>-1) )
    10521052            {//LENSFLARE: short range weapon
    1053                 this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
    1054             }
    1055             else if(weapons[3] && this->isCloseAtTarget(400) && (projectiles[3] > 0) && (random < this->botlevel_) )
     1053                this->getControllableEntity()->fire(weaponModes[1]); //ai uses lens flare if they're close enough to the target
     1054            }
     1055            else if( (weaponModes[3]>-1) && this->isCloseAtTarget(400) && (projectiles[3] > 0) && (random < this->botlevel_) )
    10561056            {//ROCKET: mid range weapon
    10571057                this->mode_ = ROCKET; //Vector-implementation: mode_.push_back(ROCKET);
    1058                 this->getControllableEntity()->fire(3); //launch rocket
     1058                this->getControllableEntity()->fire(weaponModes[3]); //launch rocket
    10591059                if(this->getControllableEntity() && this->target_) //after fire(3) is called, getControllableEntity() refers to the rocket!
    10601060                {
     
    10681068                this->projectiles[3] -= 1; //decrease ammo
    10691069            }
    1070             else if (weapons[0])//LASER: default weapon
    1071                 this->getControllableEntity()->fire(0);
     1070            else if (weaponModes[0]>-1) //LASER: default weapon
     1071                this->getControllableEntity()->fire(weaponModes[0]);
    10721072        }
    10731073    }
     
    10831083            if(pawn)
    10841084            {
    1085                 this->analyseWeapons(pawn);
    1086                 for(unsigned int i=0; i < WeaponSystem::MAX_WEAPON_MODES; i++)
     1085                int max = WeaponSystem::MAX_WEAPON_MODES; // assumption: there are only so many weaponmodes possible
     1086                for(int x=0; x<max ;x++)
     1087                    weaponModes[x] = -1; // reset previous weapon information
     1088                this->numberOfWeapons = 0;
     1089                for(int l=0; l<max ;l++)
    10871090                {
    1088                     //const std::string wpn = getWeaponname(i, 0, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info.
    1089                     /*if(wpn=="") //future, more generic implementation; until now, only LaserMunition works. Is this a bug??
    1090                         weapons[i]=false;
    1091                     else if(wpn=="LaserMunition")//other munitiontypes are not defined yet :-(
    1092                         weapons[0]=true;
    1093                     else if(wpn=="FusionMunition")
    1094                         weapons[1]=true;
    1095                     else if(wpn=="TargetSeeking Rockets")
    1096                         weapons[2]=true;
    1097                     else if(wpn=="RocketMunition")
    1098                         weapons[3]=true;
    1099                     else
    1100                         COUT(1)<< wpn << + << " has to be added in ArtificialController.cc as new weapon." << std::endl;
    1101                     */
    1102                     if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment!
     1091                    WeaponSlot* wSlot = pawn->getWeaponSlot(l);
     1092                    if(wSlot==NULL) continue;
     1093                    for(int i=0; i<max; i++)
    11031094                    {
    1104                         weapons[i] = true;
    1105                         projectiles[i] = 10; //TODO: how to get data?? getWeaponmode(i)->getMunition()->getNumMunition(WeaponMode* user)
    1106                           numberOfWeapons++;
     1095                        WeaponMode* wMode = wSlot->getWeapon()->getWeaponmode(i);
     1096                        if(wMode == NULL) continue;
     1097                        this->numberOfWeapons++;
     1098                        if(wMode->getIdentifier()->getName() == "HsW01") // red laser <-> 0
     1099                            weaponModes[0] = wMode->getMode();
     1100                        else if(wMode->getIdentifier()->getName() == "LightningGun") // yellow energy  <-> 1
     1101                            weaponModes[1] = wMode->getMode();
     1102                        else if(wMode->getIdentifier()->getName() == "SimpleRocketFire") // target seeking rocktes <-> 2
     1103                            weaponModes[2] = wMode->getMode(); // not relevant jet, since doFire() doesn't support simple rockets
     1104                        else if(wMode->getIdentifier()->getName() == "RocketFire") // manual rockets <-> 3
     1105                            weaponModes[3] = wMode->getMode();
     1106                        else
     1107                            COUT(1)<< wMode->getIdentifier()->getName() << " has to be added in ArtificialController.cc as new weapon." << std::endl;
    11071108                    }
    1108                     else
    1109                         weapons[i] = false;
    11101109                }
    1111                  //pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
    1112             }
    1113         }
    1114     }
    1115 
    1116     const std::string ArtificialController::getWeaponname(int i, int u, Pawn* pawn)//Search through all wPacks,
    1117     {//is there a way to minimize this long if-return structure, without triggering nullpointer exceptions?
    1118         if(!pawn) return "a";
    1119         WeaponPack* wPack = pawn->getWeaponPack(u);
    1120         if(!wPack) return "b";
    1121         Weapon* wpn = wPack->getWeapon(i);
    1122         if(!wpn && u<10 && i>0)
    1123         {
    1124             return this->getWeaponname(i, u+1, pawn);
    1125         }
    1126         else if(!wpn)
    1127             return "c";
    1128         //return wpn->getName();
    1129         WeaponMode* wMode = wpn->getWeaponmode(0);
    1130         if(!wMode) return "d";
    1131         return wMode->getMunitionName();//getName();
    1132     }//pawn->getWeaponpack(i)->getWeapon(i)->getWeaponmode(i)->getMunitionName()
    1133     /**
    1134         @brief Display how a spaceship is equiped with weapons. TODO: why are only 3 out of 8 weapons displayed??
    1135     */
    1136     void ArtificialController::analyseWeapons(Pawn* pawn)
    1137     {
    1138         int max = 10;
    1139         if(!pawn) return;
    1140         for(int l=0; l<max ;l++)
    1141         {
    1142             WeaponSlot* wSlot = pawn->getWeaponSlot(l);
    1143             if(wSlot==NULL) continue;//{COUT(0)<<"WEAPONSLOT "<<l<< " failed"<<endl; continue;}
    1144             for(int i=0; i<max; i++)
    1145             {
    1146                  WeaponMode* wMode = wSlot->getWeapon()->getWeaponmode(i);
    1147                  if(wMode==NULL) continue;//{COUT(0)<<"WEAPONMODE "<<i<< " failed"<<endl;}
    1148                  COUT(0)<<wMode->getIdentifier()->getName()<< " using mode:"<<i<<endl;
    1149             }
     1110                if(numberOfWeapons>0)
     1111                    this->bSetupWorked = true;
     1112            }//pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
    11501113        }
    11511114    }
     
    11771140        SpaceShip* ship = orxonox_cast<SpaceShip*>(this->getControllableEntity());
    11781141        if(ship == NULL) return;
    1179         if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() )//upper limit ->boost
     1142        if(ship->getBoostPower()*1.5f > ship->getInitialBoostPower() ) //upper limit ->boost
    11801143            this->getControllableEntity()->boost(true);
    1181         else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower())//lower limit ->do not boost
     1144        else if(ship->getBoostPower()*4.0f < ship->getInitialBoostPower()) //lower limit ->do not boost
    11821145            this->getControllableEntity()->boost(false);
    11831146    }
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.h

    r8757 r8762  
    150150
    151151            int numberOfWeapons; //<! Used for weapon init function. Displayes number of weapons available for a bot.
    152             bool weapons[WeaponSystem::MAX_WEAPON_MODES]; //<! Displays if a weapon is available - managed by setupWeapons()
     152            int weaponModes[WeaponSystem::MAX_WEAPON_MODES]; //<! Links each "weapon" to it's weaponmode- managed by setupWeapons()
    153153            int projectiles[WeaponSystem::MAX_WEAPON_MODES]; //<! Displays amount of projectiles of each weapon. - managed by setupWeapons()
    154154            float botlevel_; //<! Makes the level of a bot configurable.
     
    159159            void setPreviousMode();
    160160            void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
    161             const std::string getWeaponname(int i, int u, Pawn* pawn); //<! Function that links a weapon's firemode to its name.
    162             void analyseWeapons(Pawn* pawn);
    163161            bool bSetupWorked; //<! If false, setupWeapons() is called.
    164162    };
Note: See TracChangeset for help on using the changeset viewer.