Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7833 for code/branches/ai/src


Ignore:
Timestamp:
Jan 27, 2011, 7:50:16 PM (14 years ago)
Author:
jo
Message:

The ai's strength can be modified by changing the value botlevel_ . The level can be adjusted between 1 (weak) and 10 (strong).
The next step is adding xml and console command functionality.

Location:
code/branches/ai/src/orxonox/controllers
Files:
3 edited

Legend:

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

    r7832 r7833  
    7676            // search enemy
    7777            random = rnd(maxrand);
    78             if (random < 15 && (!this->target_))
     78            if (random < (15 + botlevel_* 2) && (!this->target_))
    7979                this->searchNewTarget();
    8080
    8181            // forget enemy
    8282            random = rnd(maxrand);
    83             if (random < 5 && (this->target_))
     83            if (random < (5/botlevel_) && (this->target_))
    8484                this->forgetTarget();
    8585
    8686            // next enemy
    8787            random = rnd(maxrand);
    88             if (random < 10 && (this->target_))
     88            if (random < (10 + botlevel_) && (this->target_))
    8989                this->searchNewTarget();
    9090
     
    106106            // shoot
    107107            random = rnd(maxrand);
    108             if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))
     108            if (!(this->passive_) && random < (75 + botlevel_*3) && (this->target_ && !this->bShooting_))
    109109                this->bShooting_ = true;
    110110
    111111            // stop shooting
    112112            random = rnd(maxrand);
    113             if (random < 25 && (this->bShooting_))
     113            if (random < (25 - botlevel_*2 ) && (this->bShooting_))
    114114                this->bShooting_ = false;
    115115
     
    176176                if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    177177                    this->searchRandomTargetPosition();
    178 
    179178
    180179                // fly somewhere else
     
    193192                // stop shooting
    194193                random = rnd(maxrand);
    195                 if (random < 25 && (this->bShooting_))
     194                if (random < (25 - botlevel_*2 ) && (this->bShooting_))
    196195                    this->bShooting_ = false;
    197196
  • code/branches/ai/src/orxonox/controllers/ArtificialController.cc

    r7832 r7833  
    8686        this->bSetupWorked = false;
    8787        this->numberOfWeapons = 0;
     88        this->botlevel_ = 10.0f;
    8889    }
    8990
     
    128129        XMLPortParam(ArtificialController, "formationSize", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE);
    129130        XMLPortParam(ArtificialController, "passive", setPassive, getPassive, xmlelement, mode).defaultValues(false);
     131        XMLPortParam(ArtificialController, "level", setBotLevel, getBotLevel, xmlelement, mode).defaultValues(1.0f);
    130132    }
    131133
     
    10181020        return (team1 == team2 && team1 != -1);
    10191021    }
    1020    
     1022    /**
     1023        @brief DoFire is called when a bot should shoot and decides which weapon is used and whether the bot shoots at all.
     1024    */
    10211025    void ArtificialController::doFire()
    10221026    {
     
    10271031                bSetupWorked=true;
    10281032        }
    1029         else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
    1030         {
    1031             if (this->isCloseAtTarget(140) && this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[1]==1) )
     1033        else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget(1000 + botlevel_*200) && this->isLookingAtTarget(math::pi / 20.0f))
     1034        {
     1035            if (this->isCloseAtTarget(130) && this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[1]==1) )
    10321036                this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
    10331037
     
    10371041        }
    10381042    }
     1043    /**
     1044        @brief Information gathering: Which weapons are ready to use?
     1045    */
    10391046    void ArtificialController::setupWeapons()
    10401047    {
     
    10571064        }
    10581065    }
     1066   
     1067    void ArtificialController::setBotLevel(float level)
     1068    {
     1069        if (level < 1)
     1070            this->botlevel_ = 1 ;
     1071        else if (level > 10)
     1072            this->botlevel_ = 10;
     1073        else
     1074            this->botlevel_ = level;
     1075    }
    10591076}
  • code/branches/ai/src/orxonox/controllers/ArtificialController.h

    r7832 r7833  
    8080           
    8181            virtual void doFire();
     82            void setBotLevel(float level=1.0f);
     83            inline float getBotLevel() const
     84                { return this->botlevel_; }
    8285
    8386        protected:
     
    144147            int numberOfWeapons;
    145148            int weapons[WeaponSystem::MAX_WEAPON_MODES];
     149            float botlevel_; //< Makes the level of a bot configurable.
    146150
    147151        private:
Note: See TracChangeset for help on using the changeset viewer.