Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 13, 2011, 9:42:03 PM (13 years ago)
Author:
jo
Message:

ai && weapons. Trying to identify each weapon installed on a spaceship.

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

Legend:

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

    r8736 r8757  
    3333
    3434#include "util/Math.h"
     35#include "util/Convert.h"
    3536#include "core/CoreIncludes.h"
    3637#include "core/XMLPort.h"
     
    10471048            float random = rnd(1);//
    10481049            if (this->isCloseAtTarget(130) && weapons[1] )
    1049             {//LENSFLARE: short range weapon     
     1050            {//LENSFLARE: short range weapon
    10501051                this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
    10511052            }
     
    10801081            if(pawn)
    10811082            {
     1083                this->analyseWeapons(pawn);
    10821084                for(unsigned int i=0; i < WeaponSystem::MAX_WEAPON_MODES; i++)
    10831085                {
    1084                     const std::string wpn = getWeaponname(i, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info.
     1086                    //const std::string wpn = getWeaponname(i, 0, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info.
    10851087                    /*if(wpn=="") //future, more generic implementation; until now, only LaserMunition works. Is this a bug??
    10861088                        weapons[i]=false;
     
    11101112    }
    11111113
    1112     const std::string& ArtificialController::getWeaponname(int i, Pawn* pawn)
     1114    const std::string ArtificialController::getWeaponname(int i, int u, Pawn* pawn)//Search through all wPacks,
    11131115    {//is there a way to minimize this long if-return structure, without triggering nullpointer exceptions?
    1114         if(!pawn) return "";
    1115         WeaponPack* wPack = pawn->getWeaponPack(i);
    1116         if(!wPack) return "";
     1116        if(!pawn) return "a";
     1117        WeaponPack* wPack = pawn->getWeaponPack(u);
     1118        if(!wPack) return "b";
    11171119        Weapon* wpn = wPack->getWeapon(i);
    1118         if(!wpn) return "";
    1119         WeaponMode* wMode = wpn->getWeaponmode(i);
    1120         if(!wMode) return "";
    1121         return wMode->getMunitionName();
     1120        if(!wpn && u<10 && i>0)
     1121        {
     1122            return this->getWeaponname(i, u+1, pawn);
     1123        }
     1124        else if(!wpn)
     1125            return "c";
     1126        //return wpn->getName();
     1127        WeaponMode* wMode = wpn->getWeaponmode(0);
     1128        if(!wMode) return "d";
     1129        return wMode->getMunitionName();//getName();
    11221130    }//pawn->getWeaponpack(i)->getWeapon(i)->getWeaponmode(i)->getMunitionName()
    1123 
    1124    
     1131    /**
     1132        @brief Display how a spaceship is equiped with weapons. TODO: why are only 3 out of 8 weapons displayed??
     1133    */
     1134    void ArtificialController::analyseWeapons(Pawn* pawn)
     1135    {
     1136        int max=10, i=0, j=0, k=0;
     1137        if(!pawn) {COUT(0)<<"NO PAWN"<<std::endl; return;}
     1138        while(i<max)
     1139        {
     1140            WeaponPack* wPack = pawn->getWeaponPack(i); //WeaponSet* wSet = pawn->getWeaponSet(i);
     1141            i++;
     1142            if(wPack==NULL) continue;
     1143            while(j<max)
     1144            {
     1145                Weapon* wpn = wPack->getWeapon(j);
     1146                j++;
     1147                if(wpn==NULL) continue;
     1148                while(k<max)
     1149                {
     1150                    WeaponMode* wMode = wpn->getWeaponmode(k);
     1151                    k++;
     1152                    if(wMode==NULL) continue;
     1153                    COUT(0)<<wMode->getName()<<": weaponpack "+multi_cast<std::string>(i-1)<<", weapon "<<multi_cast<std::string>(j-1)<<", weaponmode "<<multi_cast<std::string>(k-1)<<std::endl;
     1154                }
     1155            }
     1156        }
     1157    }
     1158
     1159
    11251160    void ArtificialController::setBotLevel(float level)
    11261161    {
    11271162        if (level < 0.0f)
    1128             this->botlevel_ = 0.0f; 
     1163            this->botlevel_ = 0.0f;
    11291164        else if (level > 1.0f)
    11301165            this->botlevel_ = 1.0f;
     
    11321167            this->botlevel_ = level;
    11331168    }
    1134    
     1169
    11351170    void ArtificialController::setAllBotLevel(float level)
    11361171    {
     
    11431178        this->mode_ = DEFAULT; //Vector-implementation: mode_.pop_back();
    11441179    }
    1145    
     1180
    11461181    void ArtificialController::boostControl()
    11471182    {
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.h

    r8741 r8757  
    8080
    8181            virtual void doFire();
    82             void setBotLevel(float level=1.0f);
    83             inline float getBotLevel() const
     82            void setBotLevel(float level=1.0f);
     83            inline float getBotLevel() const
    8484                { return this->botlevel_; }
    8585            static void setAllBotLevel(float level);
     
    157157            enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes
    158158            Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_;
    159             void setPreviousMode(); 
     159            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, Pawn* pawn); //<! Function that links a weapon's firemode to its name.
     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);
    162163            bool bSetupWorked; //<! If false, setupWeapons() is called.
    163164    };
Note: See TracChangeset for help on using the changeset viewer.