Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8735 for code


Ignore:
Timestamp:
Jul 7, 2011, 3:59:54 PM (13 years ago)
Author:
jo
Message:

Adjust weapon behaviour if bot dies and is respawned with a different weaponsetting than before.

Location:
code/branches/ai2/src/orxonox
Files:
6 edited

Legend:

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

    r8733 r8735  
    205205        if (!this->isActive())
    206206            return;
    207 
     207        if(this->bDeathFlag_)//If a bot died recently, make him check his weaponsystem.
     208        {
     209            this->bSetupWorked = false;
     210            this->numberOfWeapons = 0;
     211            this->resetDeathFlag();
     212        }
    208213        float random;
    209214        float maxrand = 100.0f / ACTION_INTERVAL;
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.cc

    r8733 r8735  
    9090        this->bSetupWorked = false;
    9191        this->numberOfWeapons = 0;
    92         this->botlevel_ = 1.0f;
     92        this->botlevel_ = 0.5f;
    9393        this->mode_ = DEFAULT;////Vector-implementation: mode_.push_back(DEFAULT);
    9494        this->timeout_=0;
     
    10431043        else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
    10441044        {
    1045             if (this->isCloseAtTarget(130) &&(weapons[1]==1) )
     1045            if (this->isCloseAtTarget(130) &&weapons[1] )
    10461046            {//LENSFLARE: short range weapon     
    10471047                this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
    10481048            }
    1049             else if((weapons[3]==3)&& this->isCloseAtTarget(400) /*&&projectiles[3]*/ )
     1049            else if(weapons[3]&& this->isCloseAtTarget(400) /*&&projectiles[3]*/ )
    10501050            {//ROCKET: mid range weapon
    10511051                //TODO: How many rockets are available?
    10521052                this->mode_ = ROCKET;//Vector-implementation: mode_.push_back(ROCKET);
    1053                 this->getControllableEntity()->fire(3);//launch rocket BUG IS TRIGGERED HERE.
     1053                this->getControllableEntity()->fire(3);//launch rocket
    10541054                if(this->getControllableEntity()&&this->target_)//after fire(3) getControllableEntity() refers to the rocket!
    10551055                {
     
    10641064                this->projectiles[3]-=1;//decrease ammo !!
    10651065            }
    1066             else if ((weapons[0]==0))//LASER: default weapon
     1066            else if (weapons[0])//LASER: default weapon
    10671067                this->getControllableEntity()->fire(0);
    10681068        }
     
    10831083                    //const std::string wpn = getWeaponname(i, pawn); COUT(0)<<wpn<< std::endl;//Temporary debug info.
    10841084                    /*if(wpn=="")
    1085                         weapons[i]=-1;
     1085                        weapons[i]=false;
    10861086                    else if(wpn=="LaserMunition")//other munitiontypes are not defined yet :-(
    1087                         weapons[0]=0;
     1087                        weapons[0]=true;
    10881088                    else if(wpn=="FusionMunition")
    1089                         weapons[1]=1;
     1089                        weapons[1]=true;
    10901090                    else if(wpn=="TargetSeeking Rockets")
    1091                         weapons[2]=2;
    1092                     else if(wpn=="ROCKET")//TODO: insert right munition name
    1093                         weapons[3]=3;
     1091                        weapons[2]=true;
     1092                    else if(wpn=="RocketMunition")
     1093                        weapons[3]=true;
     1094                    else
     1095                        COUT(1)<< wpn << + << " has to be added in ArtificialController.cc as new weapon." << std::endl;
    10941096                    */
    10951097                    if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment!
    10961098                    {
    1097                         weapons[i]=i;
     1099                        weapons[i]=true;
    10981100                        projectiles[i]=1;//TODO: how to express infinite ammo? how to get data?? getWeaponmode(i)->getMunition()->getNumMunition(WeaponMode* user)
    10991101                          numberOfWeapons++;
    11001102                    }
    11011103                    else
    1102                         weapons[i]=-1;
     1104                        weapons[i]=-false;
    11031105                }
    11041106                 //pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
  • code/branches/ai2/src/orxonox/controllers/ArtificialController.h

    r8723 r8735  
    149149
    150150            int numberOfWeapons; //< Used for weapon init function. Displayes number of weapons available for a bot.
    151             int weapons[WeaponSystem::MAX_WEAPON_MODES];
    152             int projectiles[WeaponSystem::MAX_WEAPON_MODES];
     151            bool weapons[WeaponSystem::MAX_WEAPON_MODES]; //<! Displays if a weapon is available - managed by setupWeapons()
     152            int projectiles[WeaponSystem::MAX_WEAPON_MODES]; //<! Displays amount of projectiles. - managed by setupWeapons()
    153153            float botlevel_; //< Makes the level of a bot configurable.
    154154            float timeout_; //< Timeout for rocket usage. (If a rocket misses, a bot should stop using it.)
     
    156156            enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes
    157157            Mode mode_; //TODO: replace single value with stack-like implementation: std::vector<Mode> mode_;
    158             void setPreviousMode();
    159 
    160         private:
    161             void setupWeapons();
    162             const std::string& getWeaponname(int i, Pawn* pawn);
    163             bool bSetupWorked;
     158            void setPreviousMode();
     159            void setupWeapons(); //<! Defines which weapons are available for a bot. Is recalled whenever a bot was killed.
     160            const std::string& getWeaponname(int i, Pawn* pawn); //<! Function that links a weapon's firemode to its name.
     161            bool bSetupWorked; //<! If false, setupWeapons() is called.
    164162    };
    165163}
  • code/branches/ai2/src/orxonox/controllers/Controller.cc

    r6417 r8735  
    4242        this->controllableEntity_ = 0;
    4343        this->bGodMode_ = false;
     44        this->bDeathFlag_ = false;
    4445    }
    4546
  • code/branches/ai2/src/orxonox/controllers/Controller.h

    r8706 r8735  
    6363            inline ControllableEntity* getControllableEntity() const
    6464                { return this->controllableEntity_; }
     65            inline void setDeathFlag()
     66                { this->bDeathFlag_ = true; }
     67            inline void resetDeathFlag()
     68                { this->bDeathFlag_ = false; }
    6569            virtual void changedControllableEntity() {}
    6670
     
    7983            PlayerInfo* player_;
    8084            ControllableEntity* controllableEntity_;
     85            bool bDeathFlag_; //<! Signal, when a controlled entity died. Flag is set in Pawn.cc and used in AIController.
    8186        private:
    8287            bool bGodMode_;
  • code/branches/ai2/src/orxonox/worldentities/pawns/Pawn.cc

    r8706 r8735  
    304304        if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
    305305        {
     306            if ( this->getController()&& (!this->isHumanShip_) ) //announce death to the ai
     307            {
     308                 this->getController()->setDeathFlag();
     309            }
    306310            // Set bAlive_ to false and wait for PawnManager to do the destruction
    307311            this->bAlive_ = false;
Note: See TracChangeset for help on using the changeset viewer.