[Orxonox-commit 3140] r7833 - code/branches/ai/src/orxonox/controllers

jo at orxonox.net jo at orxonox.net
Thu Jan 27 19:50:17 CET 2011


Author: jo
Date: 2011-01-27 19:50:16 +0100 (Thu, 27 Jan 2011)
New Revision: 7833

Modified:
   code/branches/ai/src/orxonox/controllers/AIController.cc
   code/branches/ai/src/orxonox/controllers/ArtificialController.cc
   code/branches/ai/src/orxonox/controllers/ArtificialController.h
Log:
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.

Modified: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc	2011-01-27 14:58:04 UTC (rev 7832)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc	2011-01-27 18:50:16 UTC (rev 7833)
@@ -75,17 +75,17 @@
 
             // search enemy
             random = rnd(maxrand);
-            if (random < 15 && (!this->target_))
+            if (random < (15 + botlevel_* 2) && (!this->target_))
                 this->searchNewTarget();
 
             // forget enemy
             random = rnd(maxrand);
-            if (random < 5 && (this->target_))
+            if (random < (5/botlevel_) && (this->target_))
                 this->forgetTarget();
 
             // next enemy
             random = rnd(maxrand);
-            if (random < 10 && (this->target_))
+            if (random < (10 + botlevel_) && (this->target_))
                 this->searchNewTarget();
 
             // fly somewhere
@@ -105,12 +105,12 @@
 
             // shoot
             random = rnd(maxrand);
-            if (!(this->passive_) && random < 75 && (this->target_ && !this->bShooting_))
+            if (!(this->passive_) && random < (75 + botlevel_*3) && (this->target_ && !this->bShooting_))
                 this->bShooting_ = true;
 
             // stop shooting
             random = rnd(maxrand);
-            if (random < 25 && (this->bShooting_))
+            if (random < (25 - botlevel_*2 ) && (this->bShooting_))
                 this->bShooting_ = false;
 
         }
@@ -176,7 +176,6 @@
                 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
                     this->searchRandomTargetPosition();
 
-
                 // fly somewhere else
                 random = rnd(maxrand);
                 if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
@@ -192,7 +191,7 @@
 
                 // stop shooting
                 random = rnd(maxrand);
-                if (random < 25 && (this->bShooting_))
+                if (random < (25 - botlevel_*2 ) && (this->bShooting_))
                     this->bShooting_ = false;
 
             }

Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc	2011-01-27 14:58:04 UTC (rev 7832)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc	2011-01-27 18:50:16 UTC (rev 7833)
@@ -85,6 +85,7 @@
         this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
 	this->bSetupWorked = false;
 	this->numberOfWeapons = 0;
+	this->botlevel_ = 10.0f;
     }
 
     ArtificialController::~ArtificialController()
@@ -127,6 +128,7 @@
         XMLPortParam(ArtificialController, "formationFlight", setFormationFlight, getFormationFlight, xmlelement, mode).defaultValues(false);
         XMLPortParam(ArtificialController, "formationSize", setFormationSize, getFormationSize, xmlelement, mode).defaultValues(STANDARD_MAX_FORMATION_SIZE);
         XMLPortParam(ArtificialController, "passive", setPassive, getPassive, xmlelement, mode).defaultValues(false);
+	XMLPortParam(ArtificialController, "level", setBotLevel, getBotLevel, xmlelement, mode).defaultValues(1.0f);
     }
 
 // Documentation only here to get a faster overview for creating a useful documentation...
@@ -1017,7 +1019,9 @@
 
         return (team1 == team2 && team1 != -1);
     }
-    
+    /**
+        @brief DoFire is called when a bot should shoot and decides which weapon is used and whether the bot shoots at all.
+    */
     void ArtificialController::doFire()
     {
         if(!bSetupWorked)//setup: find out which weapons are active ! hard coded: laser is "0", lens flare is "1", ...
@@ -1026,9 +1030,9 @@
             if(numberOfWeapons>0)
                 bSetupWorked=true;
         }
-        else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
+        else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget(1000 + botlevel_*200) && this->isLookingAtTarget(math::pi / 20.0f))
         {
-            if (this->isCloseAtTarget(140) && this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[1]==1) )
+            if (this->isCloseAtTarget(130) && this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[1]==1) )
                 this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
 
           //default fire (laser)
@@ -1036,6 +1040,9 @@
                this->getControllableEntity()->fire(0);
         }
     }
+    /**
+        @brief Information gathering: Which weapons are ready to use?
+    */
     void ArtificialController::setupWeapons()
     {
         if(this->getControllableEntity())
@@ -1056,4 +1063,14 @@
             }
         }
     }
+    
+    void ArtificialController::setBotLevel(float level)
+    {
+        if (level < 1)
+	    this->botlevel_ = 1 ; 
+	else if (level > 10)
+	    this->botlevel_ = 10;
+	else
+            this->botlevel_ = level;
+    }
 }

Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.h	2011-01-27 14:58:04 UTC (rev 7832)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.h	2011-01-27 18:50:16 UTC (rev 7833)
@@ -79,6 +79,9 @@
             static void formationsize(const int size);
 	    
             virtual void doFire();
+	    void setBotLevel(float level=1.0f);
+	    inline float getBotLevel() const
+                { return this->botlevel_; }
 
         protected:
 
@@ -143,6 +146,7 @@
 	    
             int numberOfWeapons;
             int weapons[WeaponSystem::MAX_WEAPON_MODES];
+	    float botlevel_; //< Makes the level of a bot configurable. 
 
         private:
             void setupWeapons();




More information about the Orxonox-commit mailing list