[Orxonox-commit 4027] r8701 - in code/branches/ai/src: modules/weapons/projectiles orxonox/controllers orxonox/worldentities

jo at orxonox.net jo at orxonox.net
Thu Jun 9 23:40:55 CEST 2011


Author: jo
Date: 2011-06-09 23:40:54 +0200 (Thu, 09 Jun 2011)
New Revision: 8701

Modified:
   code/branches/ai/src/modules/weapons/projectiles/Rocket.cc
   code/branches/ai/src/orxonox/controllers/AIController.cc
   code/branches/ai/src/orxonox/controllers/AIController.h
   code/branches/ai/src/orxonox/controllers/ArtificialController.cc
   code/branches/ai/src/orxonox/controllers/ArtificialController.h
   code/branches/ai/src/orxonox/worldentities/ControllableEntity.cc
   code/branches/ai/src/orxonox/worldentities/ControllableEntity.h
Log:
First successful attempt, to make bots shoot rockets. Unfortunately they're shooting the wrong ones.

Modified: code/branches/ai/src/modules/weapons/projectiles/Rocket.cc
===================================================================
--- code/branches/ai/src/modules/weapons/projectiles/Rocket.cc	2011-06-06 06:15:38 UTC (rev 8700)
+++ code/branches/ai/src/modules/weapons/projectiles/Rocket.cc	2011-06-09 21:40:54 UTC (rev 8701)
@@ -58,6 +58,7 @@
         this->localAngularVelocity_ = 0;
         this->bDestroy_ = false;
         this->lifetime_ = 100;
+        this->bIsRocket=true;
 
         if (GameMode::isMaster())
         {
@@ -114,6 +115,7 @@
     */
     Rocket::~Rocket()
     {
+        this->bIsRocket=false;
         if(this->isInitialized())
         {
             if (GameMode::isMaster())

Modified: code/branches/ai/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.cc	2011-06-06 06:15:38 UTC (rev 8700)
+++ code/branches/ai/src/orxonox/controllers/AIController.cc	2011-06-09 21:40:54 UTC (rev 8701)
@@ -34,7 +34,7 @@
 #include "worldentities/ControllableEntity.h"
 #include "worldentities/pawns/Pawn.h"
 
-//Todo: Bot soll pickupspawner besuchen können, falls Pickup vorhanden
+//Todo: Bot soll pickupspawner besuchen können, falls Pickup vorhanden --modules/weapons/
 namespace orxonox
 {
     static const float ACTION_INTERVAL = 1.0f;
@@ -204,14 +204,52 @@
     {
         float random;
         float maxrand = 100.0f / ACTION_INTERVAL;
-	
+        
         if (!this->isActive())
             return;
 
-        if (this->state_ == MASTER)
-        {
-            if (this->specificMasterAction_ ==  NONE)
+        if(this->mode_ == DEFAULT)
+	{
+            if (this->state_ == MASTER)
             {
+                if (this->specificMasterAction_ ==  NONE)
+                {
+                    if (this->target_)
+                    {
+                        if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
+                            this->forgetTarget();
+                        else
+                        {
+                            this->aimAtTarget();
+                            random = rnd(maxrand);
+                            if(this->botlevel_*100 > random)
+                                this->follow();//If a bot is shooting a player, it shouldn't let him go away easily.
+                        }
+                    }
+
+                    if (this->bHasTargetPosition_)
+                        this->moveToTargetPosition();
+
+                    this->doFire();
+                }
+
+                if (this->specificMasterAction_  == TURN180)
+                    this->turn180();
+
+                if (this->specificMasterAction_ == SPIN)
+                    this->spin();
+                if (this->specificMasterAction_ == FOLLOW)
+                    this->follow();
+            }
+
+            if (this->state_ == SLAVE)
+            {
+                if (this->bHasTargetPosition_)
+                    this->moveToTargetPosition();
+            }
+
+            if (this->state_ == FREE)
+            {
                 if (this->target_)
                 {
                     if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
@@ -222,7 +260,7 @@
                         random = rnd(maxrand);
                         if(this->botlevel_*100 > random)
                             this->follow();//If a bot is shooting a player, it shouldn't let him go away easily.
-                    }
+                     }
                 }
 
                 if (this->bHasTargetPosition_)
@@ -230,44 +268,24 @@
 
                 this->doFire();
             }
-
-            if (this->specificMasterAction_  == TURN180)
-                    this->turn180();
-
-            if (this->specificMasterAction_ == SPIN)
-                    this->spin();
-            if (this->specificMasterAction_ == FOLLOW)
-                    this->follow();
-        }
-
-        if (this->state_ == SLAVE)
-        {
-            if (this->bHasTargetPosition_)
-                this->moveToTargetPosition();
-        }
-
-        if (this->state_ == FREE)
-        {
-            if (this->target_)
+        }//END_OF DEFAULT MODE
+        else if (this->mode_ == ROCKET)
+        {   
+            ControllableEntity *controllable = this->getControllableEntity(); 
+            if(controllable)
             {
-                if (!this->target_->getRadarVisibility()) /* So AI won't shoot invisible Spaceships */
-                    this->forgetTarget();
-                else
-                {
-                    this->aimAtTarget();
-                    random = rnd(maxrand);
-                    if(this->botlevel_*100 > random)
-                        this->follow();//If a bot is shooting a player, it shouldn't let him go away easily.
+                 if(controllable->getRocket())//Check wether the bot is controlling the rocket.
+                 {
+                     this->follow(); //TODO: CHECK: does follow make the bot crash into the target_ ?
                  }
+                 else
+                     this->mode_ = DEFAULT;//no rocket -> get out of rocket mode
             }
-
-            if (this->bHasTargetPosition_)
-                this->moveToTargetPosition();
-
-            this->doFire();
-        }
-
+            else
+                this->mode_ = DEFAULT;//If bot dies -> getControllableEntity == NULL -> get out of ROCKET mode
+        }//END_OF ROCKET MODE
         SUPER(AIController, tick, dt);
     }
 
 }
+

Modified: code/branches/ai/src/orxonox/controllers/AIController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/AIController.h	2011-06-06 06:15:38 UTC (rev 8700)
+++ code/branches/ai/src/orxonox/controllers/AIController.h	2011-06-09 21:40:54 UTC (rev 8701)
@@ -54,3 +54,4 @@
 }
 
 #endif /* _AIController_H__ */
+

Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.cc	2011-06-06 06:15:38 UTC (rev 8700)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.cc	2011-06-09 21:40:54 UTC (rev 8701)
@@ -87,6 +87,7 @@
 	this->bSetupWorked = false;
 	this->numberOfWeapons = 0;
 	this->botlevel_ = 1.0f;
+	this->mode_ = DEFAULT;
     }
 
     ArtificialController::~ArtificialController()
@@ -1033,18 +1034,27 @@
         }
         else if(this->getControllableEntity()&&(numberOfWeapons>0)&&this->bShooting_ && this->isCloseAtTarget((1 + 2*botlevel_)*1000) && this->isLookingAtTarget(math::pi / 20.0f))
         {
-            if (this->isCloseAtTarget(130) && this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[1]==1) )
+            /*if (this->isCloseAtTarget(130) && this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[1]==1) )
+            {//LENSFLARE: short range weapon     
                 this->getControllableEntity()->fire(1); //ai uses lens flare if they're close enough to the target
-
-          //default fire (laser)
-          else if ((weapons[0]==0))
-               this->getControllableEntity()->fire(0);
+            }
+            else if(this->isLookingAtTarget(math::pi / 20.0f)&&(weapons[3]==3)&& this->isCloseAtTarget(260) &&projectiles[3] )*/
+            {//ROCKET: mid range weapon
+                //TODO: Which weapon is the rocket? How many rockets are available?
+                this->mode_ = ROCKET;
+                //TODO: this->rockettimer->start()
+                this->getControllableEntity()->fire(3);//launch rocket
+                this->projectiles[3]-=1;//decrease ammo !!
+            }
+           
+            /*else if ((weapons[0]==0))//LASER: default weapon
+                this->getControllableEntity()->fire(0);*/
         }
     }
     /**
         @brief Information gathering: Which weapons are ready to use?
     */
-    void ArtificialController::setupWeapons()
+    void ArtificialController::setupWeapons() //TODO: Make this function generic!! (at the moment is is based on conventions)
     {
         if(this->getControllableEntity())
         {
@@ -1056,11 +1066,13 @@
                       if(pawn->getWeaponSet(i)) //main part: find which weapons a pawn can use; hard coded at the moment!
                       {
                           weapons[i]=i;
+			  projectiles[i]=1;//TODO: how to express infinite ammo? how to get data??
                           numberOfWeapons++;
                       }
                       else
                           weapons[i]=-1;
                  }
+                 //pawn->weaponSystem_->getMunition(SubclassIdentifier< Munition > *identifier)->getNumMunition (WeaponMode *user);
             }
         }
     }
@@ -1069,10 +1081,10 @@
     void ArtificialController::setBotLevel(float level)
     {
         if (level < 0.0f)
-	    this->botlevel_ = 0.0f; 
-	else if (level > 1.0f)
-	    this->botlevel_ = 1.0f;
-	else
+            this->botlevel_ = 0.0f; 
+        else if (level > 1.0f)
+            this->botlevel_ = 1.0f;
+        else
             this->botlevel_ = level;
     }
     
@@ -1083,3 +1095,4 @@
     }
     
 }
+

Modified: code/branches/ai/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/branches/ai/src/orxonox/controllers/ArtificialController.h	2011-06-06 06:15:38 UTC (rev 8700)
+++ code/branches/ai/src/orxonox/controllers/ArtificialController.h	2011-06-09 21:40:54 UTC (rev 8701)
@@ -145,10 +145,14 @@
             WeakPtr<Pawn> target_;
             bool bShooting_;
 	    
-            int numberOfWeapons;
+            int numberOfWeapons;//< Used for weapon init function. Displayes number of weapons available for a bot.
             int weapons[WeaponSystem::MAX_WEAPON_MODES];
+	    int projectiles[WeaponSystem::MAX_WEAPON_MODES];
 	    float botlevel_; //< Makes the level of a bot configurable. 
 
+            enum Mode {DEFAULT, ROCKET, DEFENCE, MOVING};//TODO; implement DEFENCE, MOVING modes
+            Mode mode_;
+
         private:
             void setupWeapons();
             bool bSetupWorked;
@@ -156,3 +160,4 @@
 }
 
 #endif /* _ArtificialController_H__ */
+

Modified: code/branches/ai/src/orxonox/worldentities/ControllableEntity.cc
===================================================================
--- code/branches/ai/src/orxonox/worldentities/ControllableEntity.cc	2011-06-06 06:15:38 UTC (rev 8700)
+++ code/branches/ai/src/orxonox/worldentities/ControllableEntity.cc	2011-06-09 21:40:54 UTC (rev 8701)
@@ -87,6 +87,7 @@
         this->setConfigValues();
         this->setPriority( Priority::VeryHigh );
         this->registerVariables();
+        this->bIsRocket=false;
     }
 
     ControllableEntity::~ControllableEntity()

Modified: code/branches/ai/src/orxonox/worldentities/ControllableEntity.h
===================================================================
--- code/branches/ai/src/orxonox/worldentities/ControllableEntity.h	2011-06-06 06:15:38 UTC (rev 8700)
+++ code/branches/ai/src/orxonox/worldentities/ControllableEntity.h	2011-06-09 21:40:54 UTC (rev 8701)
@@ -154,6 +154,8 @@
             virtual WorldEntity* getTarget()
                 { return this->target_.get(); }
             void setTargetInternal( uint32_t targetID );
+            inline bool getRocket() const
+                {return this-> bIsRocket;}
 
         protected:
             virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead
@@ -167,6 +169,7 @@
                 { this->hudtemplate_ = name; }
 
             Ogre::SceneNode* cameraPositionRootNode_;
+            bool bIsRocket; //Workaround to see, if the controllable entity is a Rocket.
 
         private:
             void registerVariables();




More information about the Orxonox-commit mailing list