[Orxonox-commit 6122] r10780 - in code/branches/AI_HS15/src/orxonox: controllers worldentities/pawns

gania at orxonox.net gania at orxonox.net
Sun Nov 8 18:19:12 CET 2015


Author: gania
Date: 2015-11-08 18:19:12 +0100 (Sun, 08 Nov 2015)
New Revision: 10780

Modified:
   code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
   code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
   code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
   code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
   code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
   code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc
   code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.h
Log:
fixed firing direction

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-11-08 16:21:46 UTC (rev 10779)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc	2015-11-08 17:19:12 UTC (rev 10780)
@@ -35,7 +35,11 @@
 #include "weaponsystem/WeaponSlot.h"
 #include "worldentities/pawns/SpaceShip.h"
 
-
+#include "Scene.h"
+#include <OgreRay.h>
+#include <OgreSceneQuery.h>
+#include <OgreCamera.h>
+#include <OgreSceneManager.h>
 namespace orxonox
 {
 
@@ -47,6 +51,10 @@
     {
         this->bSetupWorked = false;
 
+        this->targetMask_.exclude(ClassByString("BaseObject"));
+        this->targetMask_.include(ClassByString("WorldEntity"));
+        this->targetMask_.exclude(ClassByString("Projectile"));
+
         RegisterObject(CommonController);
     }
 
@@ -233,7 +241,6 @@
                     copyTargetOrientation();
                 }
             }
-                    orxout (internal_error) << "MOVING" <<endl ;
 
             this->getControllableEntity()->moveFrontBack(1.2f*SPEED*factor);
         }
@@ -254,70 +261,39 @@
         else
             return (this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance);
     }
-    
-
-    bool CommonController::canFire()
+    bool CommonController::isLookingAtTarget(float angle) const
     {
-       
-        float tolerance = 50.0f;
-        
-        //check pointers
-        if (!this->getControllableEntity() || !this->target_ || !this->target_->getControllableEntity())
+        if (!this->getControllableEntity())
             return false;
-        
-        //check if this points in the direction of target_
 
-        Vector3 myPosition = this->getControllableEntity()->getWorldPosition();
-        Vector3 targetPosition = this->target_->getControllableEntity()->getWorldPosition();
-        
-        Vector3 differenceVector = targetPosition - myPosition;
-        float differenceLength = differenceVector.length();
-        
-        Vector3 myDirection = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT;
-        
-        float angle = getAngle (myPosition, myDirection, targetPosition);
-        float heightLength = sin(angle) * differenceLength;
+        return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle);
+    }
 
-        if (heightLength > tolerance)
+    bool CommonController::canFire()
+    {
+        if ( this->bShooting_ && this->isCloseAtTarget(3000) && this->isLookingAtTarget(math::pi / 20.0f) )
+        {
+            return true;
+        }
+        else
+        {
             return false;
-       
+        }
 
+    }
+    void CommonController::doFire()
+    {
+        if (!this->target_ || !this->getControllableEntity())
+            return;
+        static const float hardcoded_projectile_speed = 750;
 
-        //check if there are allies on the way
-        Vector3 allyPosition, allyDifference;
-        float allyDifferenceLength, allyAngle, allyHeightLength;
+        this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
+        this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
 
-        for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
-        {
-            if (!it->getControllableEntity())
-                continue;
-            if ((this->getControllableEntity()->getTeam() == (it)->getControllableEntity()->getTeam()))
-            {
-                allyPosition = it->getControllableEntity()->getWorldPosition();
-
-                allyDifference = allyPosition - myPosition;
-                allyDifferenceLength = allyDifference.length();
-
-                allyAngle = getAngle (myPosition, myDirection, allyPosition);
-
-                allyHeightLength = sin(allyAngle) * allyDifferenceLength;
-
-                if (allyAngle > math::pi /2)
-                    continue;
-                if (allyHeightLength <= tolerance)
-                    return false;
-            } 
-        }
-
         Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
         if (pawn)
-            pawn->setAimPosition(WorldEntity::FRONT);
+            pawn->setAimPosition(this->getControllableEntity()->getWorldPosition() + 4000*(this->getControllableEntity()->getOrientation() * WorldEntity::FRONT));
     
-        return true;
-
-    }
-    void CommonController::doFire()
-    {
         this->getControllableEntity()->fire(0);
     }
    

Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-11-08 16:21:46 UTC (rev 10779)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.h	2015-11-08 17:19:12 UTC (rev 10780)
@@ -33,6 +33,7 @@
 #include "controllers/Controller.h"
 #include "worldentities/ControllableEntity.h"
 #include "worldentities/pawns/Pawn.h"
+#include "core/ClassTreeMask.h"
 
 
 namespace orxonox
@@ -163,6 +164,9 @@
             Rank::Value rank_;
             ManeuverType::Value maneuverType_;
             Maneuver::Value maneuver_;
+
+            ClassTreeMask               targetMask_;
+
          
         private:
             

Modified: code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-11-08 16:21:46 UTC (rev 10779)
+++ code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc	2015-11-08 17:19:12 UTC (rev 10780)
@@ -67,7 +67,8 @@
         {
             this->moveToTargetPosition();
         }
-
+        if (this->bShooting_)
+            doFire();
         SUPER(DivisionController, tick, dt);
 
     }
@@ -96,10 +97,10 @@
             } 
         }
            */
-        
         if (canFire())
-            doFire();
-      
+           this->bShooting_ = true;
+        else
+            this->bShooting_ = false;
     }
 
     

Modified: code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-11-08 16:21:46 UTC (rev 10779)
+++ code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc	2015-11-08 17:19:12 UTC (rev 10780)
@@ -62,7 +62,8 @@
         {
             this->moveToTargetPosition();
         }
-
+        if (this->bShooting_)
+            doFire();
         
         SUPER(SectionController, tick, dt);
     }
@@ -85,9 +86,10 @@
         setTargetPositionOfWingman();
         if (this->target_ && this->myWingman_)
             this->myWingman_->setTarget(this->target_);
-
         if (canFire())
-            doFire();
+           this->bShooting_ = true;
+        else
+            this->bShooting_ = false;
                 
 
     }

Modified: code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-11-08 16:21:46 UTC (rev 10779)
+++ code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc	2015-11-08 17:19:12 UTC (rev 10780)
@@ -127,7 +127,8 @@
             this->moveToTargetPosition();
         } 
         
-       
+        if (this->bShooting_)
+            doFire();
         
         SUPER(WingmanController, tick, dt);
     }
@@ -151,9 +152,11 @@
         {
 
         }
-
         if (canFire())
-            doFire();
+           this->bShooting_ = true;
+        else
+            this->bShooting_ = false;
+          
     }
      
    

Modified: code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc	2015-11-08 16:21:46 UTC (rev 10779)
+++ code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.cc	2015-11-08 17:19:12 UTC (rev 10780)
@@ -298,7 +298,6 @@
         }
     }
 
-
     void Pawn::kill()
     {
         this->damage(this->health_);
@@ -319,14 +318,14 @@
         }
     }
 
-
     void Pawn::death()
     {
         this->setHealth(1);
         if (this->getGametype() && this->getGametype()->allowPawnDeath(this, this->lastHitOriginator_))
         {
-            // Set bAlive_ to false and wait for PawnManager to do the destruction
+            // Set bAlive_ to false and wait for destroyLater() to do the destruction
             this->bAlive_ = false;
+            this->destroyLater();
 
             this->setDestroyWhenPlayerLeft(false);
 
@@ -366,7 +365,7 @@
             }
             if (GameMode::isMaster())
             {
-//                this->deathEffect();
+                this->deatheffect();
                 this->goWithStyle();
             }
         }
@@ -386,7 +385,7 @@
     void Pawn::deatheffect()
     {
         // play death effect
-        {
+        /*{
             ParticleSpawner* effect = new ParticleSpawner(this->getContext());
             effect->setPosition(this->getPosition());
             effect->setOrientation(this->getOrientation());
@@ -409,7 +408,60 @@
             effect->setDestroyAfterLife(true);
             effect->setSource("Orxonox/sparks");
             effect->setLifetime(4.0f);
+        }*/
+        
+        
+        {
+            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
+            effect->setPosition(this->getPosition());
+            effect->setOrientation(this->getOrientation());
+            effect->setDestroyAfterLife(true);
+            effect->setSource("orxonox/explosion_flash2");
+            effect->setLifetime(5.0f);
         }
+        {
+            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
+            effect->setPosition(this->getPosition());
+            effect->setOrientation(this->getOrientation());
+            effect->setDestroyAfterLife(true);
+            effect->setSource("orxonox/explosion_flame2");
+            effect->setLifetime(5.0f);
+        }
+        {
+            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
+            effect->setPosition(this->getPosition());
+            effect->setOrientation(this->getOrientation());
+            effect->setDestroyAfterLife(true);
+            effect->setSource("orxonox/explosion_shockwave2");
+            effect->scale(20);
+            effect->setLifetime(5.0f);
+        }{
+            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
+            effect->setPosition(this->getPosition());
+            effect->setOrientation(this->getOrientation());
+            effect->setDestroyAfterLife(true);
+            effect->setSource("orxonox/explosion_sparks2");
+            effect->setLifetime(5.0f);
+        }
+        {
+            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
+            effect->setPosition(this->getPosition());
+            effect->setOrientation(this->getOrientation());
+            effect->setDestroyAfterLife(true);
+            effect->setSource("orxonox/explosion_streak2");
+            effect->setLifetime(5.0f);
+        }
+        {
+            ParticleSpawner* effect = new ParticleSpawner(this->getContext());
+            effect->setPosition(this->getPosition());
+            effect->setOrientation(this->getOrientation());
+            effect->setDestroyAfterLife(true);
+            effect->setSource("orxonox/explosion_afterglow");
+            effect->scale(20);
+            effect->setLifetime(5.0f);
+        }
+        
+        
         for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)
         {
             ExplosionChunk* chunk = new ExplosionChunk(this->getContext());
@@ -417,6 +469,10 @@
         }
     }
 
+    /**
+    @brief
+        Check whether the Pawn has a @ref Orxonox::WeaponSystem and fire it with the specified firemode if it has one.
+    */
     void Pawn::fired(unsigned int firemode)
     {
         if (this->weaponSystem_)

Modified: code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.h	2015-11-08 16:21:46 UTC (rev 10779)
+++ code/branches/AI_HS15/src/orxonox/worldentities/pawns/Pawn.h	2015-11-08 17:19:12 UTC (rev 10780)
@@ -38,7 +38,19 @@
 
 
 namespace orxonox // tolua_export
-{ // tolua_export
+{
+    /**
+    @brief
+        Everything in Orxonoy that has a health attribute is a Pawn. After a Pawn is spawned its health is set to
+        its initial health. In every call of the Pawns tick function the game checks whether the pawns health is at
+        or below zero. If it is, the pawn gets killed.
+
+        Pawns can carry pickups and fire weapons. The can also have shields.
+
+        Notice that every Pawn is a ControllableEntity.
+    */
+
+    // tolua_export
     class _OrxonoxExport Pawn // tolua_export
         : public ControllableEntity, public RadarViewable, public PickupCarrier
     { // tolua_export




More information about the Orxonox-commit mailing list