[Orxonox-commit 6189] r10847 - in code/branches/campaignHS15: data/levels src/orxonox/controllers src/orxonox/worldentities

gania at orxonox.net gania at orxonox.net
Tue Nov 24 11:54:47 CET 2015


Author: gania
Date: 2015-11-24 11:54:47 +0100 (Tue, 24 Nov 2015)
New Revision: 10847

Modified:
   code/branches/campaignHS15/data/levels/AITest.oxw
   code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
   code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
   code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
   code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc
   code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h
   code/branches/campaignHS15/src/orxonox/worldentities/CMakeLists.txt
Log:
I hope that you don't code today, that version is not compilable just yet

Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-23 21:21:04 UTC (rev 10846)
+++ code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-24 10:54:47 UTC (rev 10847)
@@ -50,8 +50,9 @@
     </SpaceShip>
     <?lua end ?> -->
  
-    
-    <SpaceShip position="4000, 1500, -1000" lookat="0,0,0" team=0>
+<!--                 <ActionPoint position="12,34,56" action="FIGHT" enemy="ss" />
+ -->
+    <SpaceShip position="2000, 1500, -1000" lookat="0,0,0" team=0 name="ss1">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -60,6 +61,20 @@
         </DivisionController>
       </controller>
     </SpaceShip>
+    <SpaceShip position="0, 1500, -1000" lookat="0,0,0" team=0 name="ss2">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <DivisionController team=12>
+          <actionpoints>
+            <Actionpoint position="12,34,56" action="PROTECT" protectMe=true />
+            <Actionpoint position="12,34,56" action="FLY" />
+          </actionpoints>
+        </DivisionController>
+      </controller>
+    </SpaceShip>
+    
    <!--  <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0" team=0>
       <templates>
         <Template link=spaceshipassff />

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-23 21:21:04 UTC (rev 10846)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-24 10:54:47 UTC (rev 10847)
@@ -59,7 +59,7 @@
     {
         this->action_ = Action::FLY;
         this->stopLookingAtTarget();
-       
+        this->attackRange_ = 2500;
         RegisterObject( CommonController );
     }
 
@@ -68,14 +68,30 @@
     {
         //orxout(internal_error) << "I died, my Rank is " << rank_ << endl;
     }
-   
+    void CommonController::backupAction()
+    {
+        this->actionpoints_.push_back (this->currentActionpoint_);
+    }
+    void CommonController::restoreAction()
+    {
+        this->currentActionpoint_ = this->actionpoints_.back();
+        this->actionpoints_.pop_back();
+    }
+    void CommonController::popAction()
+    {
+        this->currentActionpoint_ = actionpoints_.back();
+        actionpoints_.pop_back();
+    }
+
     void CommonController::XMLPort( Element& xmlelement, XMLPort::Mode mode )
     {
         SUPER( CommonController, XMLPort, xmlelement, mode );
         XMLPortParam( CommonController, "formationMode", setFormationModeXML, getFormationModeXML,  xmlelement, mode );
-        XMLPortParam( CommonController, "action", setActionXML, getActionXML,  xmlelement, mode );
-        XMLPortParam ( CommonController, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
+        //XMLPortParam( CommonController, "action", setActionXML, getActionXML,  xmlelement, mode );
+        //XMLPortParam ( CommonController, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
         //XMLPortParam ( CommonController, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
+        XMLPortObject(CommonController, WorldEntity, "actionpoints", addActionpoint, getActionpoint,  xmlelement, mode);
+
     }
     void CommonController::setProtectXML( std::string val )
     {
@@ -103,9 +119,21 @@
     {
         if (!this->getProtect())
             return "noProtectWasSet";
-        return this->getProtect()->getName();
+        return CommonController::getName (this->getProtect());
     }
+    std::string CommonController::getName(ControllableEntity* entity)
+    {
+        std::string name = entity->getName();
+        if (name == "")
+        {
+            const void * address = static_cast<const void*>(entity);
+            std::stringstream ss;
+            ss << address;  
+            name = ss.str();            
+        }
+        return name;
 
+    }
     void CommonController::setProtect (ControllableEntity* protect)
     {
         this->protect_ = protect;
@@ -125,6 +153,12 @@
             value = Action::FLY;
         else if ( valUpper == "PROTECT" )
             value = Action::PROTECT;
+        else if ( valUpper == "NONE" )
+            value = Action::NONE;
+        else if ( valUpper == "FIGHTALL" )
+            value = Action::FIGHTALL;
+        else if ( valUpper == "ATTACK" )
+            value = Action::ATTACK;
         else
             ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." );
         this->setAction( value );
@@ -148,8 +182,23 @@
                 return "PROTECT";
                 break;
             }
+            case Action::NONE:
+            {
+                return "NONE";
+                break;
+            }
+            case Action::FIGHTALL:
+            {
+                return "FIGHTALL";
+                break;
+            }
+            case Action::ATTACK:
+            {
+                return "ATTACK";
+                break;
+            }
             default:
-                return "FIGHT";
+                return "NONE";
                 break;
         }
     }
@@ -236,10 +285,75 @@
         }
        
     }
+    void CommonController::addActionpoint(WorldEntity* actionpoint)
+    {
+        std::string actionName;
+        Vector3 position;
+        std::string targetName;
+        this->actionpoints_.push_back(actionpoint);
+        if (static_cast<Actionpoint*> (actionpoint))
+        {
+            Actionpoint* ap = static_cast<Actionpoint*> (actionpoint);
+            actionName = ap->getActionXML();
+            targetName = ap->get
+            Action::Value value;
+            
+            if ( valUpper == "FIGHT" )
+            {
+                value = Action::FIGHT;
+
+            }
+            else if ( valUpper == "FLY" )
+            {
+                value = Action::FLY;
+
+            }
+            else if ( valUpper == "PROTECT" )
+            {
+                value = Action::PROTECT;
+
+            }
+            else if ( valUpper == "NONE" )
+            {
+                value = Action::NONE;
+
+            }
+            else if ( valUpper == "FIGHTALL" )
+            {
+                value = Action::FIGHTALL;
+
+            }
+            else if ( valUpper == "ATTACK" )
+            {
+                value = Action::ATTACK;
+
+            }
+            else
+                ThrowException( ParseError, std::string( "Attempting to set an unknown Action: '" )+ val + "'." );
+            this->setAction( value );
+        }
+        else
+        {
+            actionName = "FLY";
+        }
+        
+    }
+
+    WorldEntity* CommonController::getActionpoint(unsigned int index) const
+    {
+        if (index < this->actionpoints_.size())
+            return this->actionpoints_[index];
+        else
+            return 0;
+    }
     void CommonController::setClosestTarget()
     {
+        this->setTarget (closestTarget()); 
+    }
+    ControllableEntity* CommonController::closestTarget()
+    {
         if (!this->getControllableEntity())
-            return;
+            return 0;
 
         Pawn* closestTarget = 0;
         float minDistance =  std::numeric_limits<float>::infinity();
@@ -258,8 +372,9 @@
         }
         if (closestTarget)
         {
-           (this)->setTarget(static_cast<ControllableEntity*>(closestTarget));
-        }   
+           return static_cast<ControllableEntity*>(closestTarget);
+        } 
+        return 0;  
     }
     void CommonController::maneuver() 
     {

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-23 21:21:04 UTC (rev 10846)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-24 10:54:47 UTC (rev 10847)
@@ -38,8 +38,8 @@
 #include "tools/Timer.h"
 #include "tools/interfaces/Tickable.h"
 #include <limits>
+#include "worldentities/Actionpoint.h"
 
-
 namespace orxonox
 {
 
@@ -62,7 +62,7 @@
     {  
         enum Value
         {
-            FLY, FIGHT, PROTECT
+            NONE, FLY, FIGHT, PROTECT, FIGHTALL, ATTACK
         };
     }
  
@@ -110,6 +110,10 @@
                     void setProtect (ControllableEntity* protect);
                     ControllableEntity* getProtect ();
                 //----[/Protect data]----
+                //----[Actionpoint data]----
+                    void addActionpoint(WorldEntity* waypoint);
+                    WorldEntity* getActionpoint(unsigned int index) const;
+                //----[/Actionpoint data]----
             //----[/XML data]----
 
             //----[Interaction with other Controllers]----
@@ -133,6 +137,7 @@
                 static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
                 static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
                 static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
+                static std::string getName( ControllableEntity* entity ) ;
 
                 float squaredDistanceToTarget() const;
                 bool isLookingAtTarget(float angle) const;
@@ -165,6 +170,7 @@
                 bool canFire();
                 void doFire();
                 void setClosestTarget();
+                ControllableEntity* closestTarget();
 
                 bool bShooting_;
                 int maneuverCounter_;         
@@ -176,27 +182,33 @@
                 bool bHasTargetOrientation_;
                 Quaternion targetOrientation_;
                 
-                Vector3 destination_;
-                bool bHasDestination;
+               
             //----[/where-to-fly information]----
             //----[protect information]----
                 WeakPtr<ControllableEntity> protect_;
             //----[/protect information]----
             //----[who-to-kill information]----
                 WeakPtr<ControllableEntity> target_;
-                WeakPtr<ControllableEntity> enemy_;
-
+               
                 bool bHasPositionOfTarget_;
                 Vector3 positionOfTarget_;
                 bool bHasOrientationOfTarget_;
                 Quaternion orientationOfTarget_;
             //----[/who-to-kill information]----
 
+            //----[Actionpoint information]----
+                std::vector<WeakPtr<WorldEntity> > actionpoints_;
+                float squaredaccuracy_;
+                <tuple<Action::Value ,std::string ,Vector3 > > currentActionpoint_;
+                std::vector<tuple<Action::Value ,std::string ,Vector3 > > parsedActionpoints_;
+            //----[/Actionpoint information]----
             //----["Private" variables]----
                 FormationMode::Value formationMode_;
                 Rank::Value rank_;
                 std::string protectName_;
                 Action::Value action_;
+                int attackRange_;
+                
             //----[/"Private" variables]----               
     };
 }

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-23 21:21:04 UTC (rev 10846)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-24 10:54:47 UTC (rev 10847)
@@ -75,18 +75,75 @@
     {
 
         
-        if (this->action_ == Action::FIGHT)
+  /*      if (this->target_)
         {
+            if (CommonController::distance (this->getControllableEntity(), newTarget) < 
+                CommonController::distance (this->getControllableEntity(), target_))
+            {
+                Actionpoint* ap = new Actionpoint(this->getContext());
+                ap->setPosition (0, 0, 0);
+                ap->setActionXML ("FIGHT");
+                //ap->setEnemyXML(CommonController::getName(newTarget));
+                this->addActionpoint (ap);
+            }
+
+        }*/
+        //----Whatever ship is doing, if there are targets close to it and its own target is far away, fight them----
+        //analog to attack move
+        if (this->action_ != Action::FIGHT && this->action_ != Action::FIGHTALL)
+        {
+            if ((this->target_ && CommonController::distance (this->getControllableEntity(), this->target_) > this->attackRange_) ||
+             !this->target_)
+            {
+                ControllableEntity* newTarget = this->closestTarget();
+                if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+                {
+                    this->backupAction();
+                    this->setAction (Action::FIGHT, newTarget);
+                }
+            }
+        }
+        //action is NONE whenever ships finishes current action, 
+        //if it was fighting before because enemies were close, resume what it was doing
+        //otherwise try to execute next action
+        if (this->action_ == Action::NONE)
+        {
+            if (this->bBackuped_)
+            {
+                this->restoreAction();
+            } else if (!this->actionpoints_.empty())
+            {
+                this->popAction();
+            }
+        }
+        if (this->action_ == Action::FIGHT || this->action_ == Action::FIGHTALL)
+        {
             if (!this->hasTarget())
             {
                 //----find a target----
-                this->setClosestTarget(); 
+                if (this->action_ == Action::FIGHT)
+                {
+                    ControllableEntity* newTarget = this->closestTarget();
+                    if (newTarget && CommonController::distance (this->getControllableEntity(), newTarget) < this->attackRange_)
+                    {
+                        this->setAction (Action::FIGHT, newTarget);
+                    }
+                    else
+                    {
+                        this->setAction (Action::NONE);
+                    }
+                }
+                else if (this->action_ == Action::FIGHTALL)
+                {
+                    this->setClosestTarget();                     
+                }
+
             }
-            else
+            else if (this->hasTarget())
             {
                 //----fly in formation if far enough----
                 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();         
-                if (diffVector.length() > 3000)
+                if (diffVector.length() > this->attackRange_)
                 {
                     this->setTargetPositionOfWingman();
                     this->setTargetPositionOfFollower();                    
@@ -131,6 +188,10 @@
                         this->setProtect (static_cast<ControllableEntity*>(*itP));
                     }
                 }
+                if (!this->getProtect())
+                {
+                    this->setAction (Action::NONE);
+                }
             }
             else
             {

Modified: code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc	2015-11-23 21:21:04 UTC (rev 10846)
+++ code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.cc	2015-11-24 10:54:47 UTC (rev 10847)
@@ -26,27 +26,27 @@
  *
  */
 
-#include "ActionPoint.h"
+#include "Actionpoint.h"
 
 #include "core/CoreIncludes.h"
 #include "core/XMLPort.h"
 
 namespace orxonox
 {
-    RegisterClass(ActionPoint);
+    RegisterClass(Actionpoint);
 
-    ActionPoint::ActionPoint(Context* context) : StaticEntity(context)
+    Actionpoint::Actionpoint(Context* context) : StaticEntity(context)
     {
-        RegisterObject(ActionPoint);
+        RegisterObject(Actionpoint);
 
     }
     //usage:
     // <DivisionController team=12>
-    //     <actionpoints>
-    //          <ActionPoint position="12,34,56" action="FIGHT" enemy="enemyName" />, position irrelevant
-    //          <ActionPoint position="12,34,56" action="PROTECT" protect="protectName" />, position irrelevant
-    //          <ActionPoint position="12,34,56" action="FLY" />, position relevant: makes ship fly to the position of ActionPoint
-    //     </actionpoints>
+    //     <Actionpoints>
+    //          <Actionpoint position="12,34,56" action="FIGHT" enemy="enemyName" />, position irrelevant
+    //          <Actionpoint position="12,34,56" action="PROTECT" protect="protectName" />, position irrelevant
+    //          <Actionpoint position="12,34,56" action="FLY" />, position relevant: makes ship fly to the position of Actionpoint
+    //     </Actionpoints>
     // </DivisonController>
     //DivisionController will firstly fight enemy that it will find by name "enemyName", if finds nothing or when beats enemy,
     //it will protect ship that it will find by name "protectName", when it's dead or if it doesn't find the ship,
@@ -55,57 +55,73 @@
     //At all the times it will check if there are enemies near DivisionController, if yes, it will fight them
     //another usage:
     // <DivisionController team=12>
-    //     <actionpoints>
-    //          <ActionPoint position="12,34,56" action="PROTECT" protectMe=true />, position irrelevant
-    //          <ActionPoint position="12,34,56" action="FIGHT" fightAll=true />, position irrelevant
-    //     </actionpoints>
+    //     <Actionpoints>
+    //          <Actionpoint position="12,34,56" action="PROTECT" protectMe=true />, position irrelevant
+    //          <Actionpoint position="12,34,56" action="FIGHT" fightAll=true />, position irrelevant
+    //     </Actionpoints>
     // </DivisonController>
     //DivisionController will protect the first NewHumanController it finds, when it dies or if no controller found,
     //it will fight closest enemies one after another
-    void ActionPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    void Actionpoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
-        SUPER(ActionPoint, XMLPort, xmlelement, mode);
+        SUPER(Actionpoint, XMLPort, xmlelement, mode);
         
-        XMLPortParam( ActionPoint, "action", setActionXML, getActionXML,  xmlelement, mode );
-        XMLPortParam( ActionPoint, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
-        XMLPortParam( ActionPoint, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
-        XMLPortParam( ActionPoint, "protectMe", setProtectMeXML, getProtectMeXML,  xmlelement, mode ).defaultValues(false);
-        XMLPortParam( ActionPoint, "fightAll", setFightAllXML, getFightAllXML,  xmlelement, mode ).defaultValues(false);
+        XMLPortParam( Actionpoint, "action", setActionXML, getActionXML,  xmlelement, mode );
+        XMLPortParam( Actionpoint, "protect", setProtectXML, getProtectXML,  xmlelement, mode );
+        XMLPortParam( Actionpoint, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
+        XMLPortParam( Actionpoint, "protectMe", setProtectMeXML, getProtectMeXML,  xmlelement, mode ).defaultValues(false);
+        XMLPortParam( Actionpoint, "fightAll", setFightAllXML, getFightAllXML,  xmlelement, mode ).defaultValues(false);
 
     }
-    void ActionPoint::setActionXML( std::string val)
+    void Actionpoint::setActionXML( std::string val)
     {
         this->actionName_ = getUppercase( val );
+        orxout(internal_error) << "action = " << this->actionName_ << endl;
     }
 
-    std::string ActionPoint::getActionXML()
+    std::string Actionpoint::getActionXML()
     {
         return this->actionName_;
     }
-    void ActionPoint::setProtectXML( std::string val)
+    void Actionpoint::setProtectXML( std::string val)
     {
         this->protectName_ = getUppercase( val );
     }
 
-    std::string ActionPoint::getProtectXML()
+    std::string Actionpoint::getProtectXML()
     {
         return this->protectName_;
     }
-    void ActionPoint::setEnemyXML( std::string val)
+    void Actionpoint::setEnemyXML( std::string val)
     {
         this->enemyName_ = getUppercase( val );
     }
 
-    std::string ActionPoint::getEnemyXML()
+    std::string Actionpoint::getEnemyXML()
     {
         return this->enemyName_;
     }
-
-    void ActionPoint::setTargetPosition(const Vector3& target)
+    void Actionpoint::setProtect( ControllableEntity* protect)
     {
+        this->protect_ = protect;
+    }
+    ControllableEntity* Actionpoint::getProtect()
+    {
+        return this->protect_;
+    }
+    void Actionpoint::setEnemy( ControllableEntity* enemy)
+    {
+        this->enemy_ = enemy;
+    }
+    ControllableEntity* Actionpoint::getEnemy()
+    {
+        return this->enemy_;
+    }
+    void Actionpoint::setTargetPosition(const Vector3& target)
+    {
         this->targetPosition_ = target;
     }
-    Vector3 ActionPoint::getTargetPosition ()
+    Vector3 Actionpoint::getTargetPosition ()
     {
         return this->targetPosition_;
     }

Modified: code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h	2015-11-23 21:21:04 UTC (rev 10846)
+++ code/branches/campaignHS15/src/orxonox/worldentities/ActionPoint.h	2015-11-24 10:54:47 UTC (rev 10847)
@@ -32,8 +32,8 @@
     @ingroup Objects
 */
 
-#ifndef _ActionPoint_H__
-#define _ActionPoint_H__
+#ifndef _Actionpoint_H__
+#define _Actionpoint_H__
 
 #include "OrxonoxPrereqs.h"
 
@@ -44,11 +44,11 @@
 namespace orxonox
 {
  
-    class _OrxonoxExport ActionPoint : public StaticEntity
+    class _OrxonoxExport Actionpoint : public StaticEntity
     {
         public:
-            ActionPoint(Context* context);
-            virtual ~ActionPoint() {}
+            Actionpoint(Context* context);
+            virtual ~Actionpoint() {}
 
             //----[XML data]----
                 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
@@ -86,7 +86,10 @@
                     }
                 //----[/FightAll data]----
             //----[/XML data]----
-
+                void setProtect( ControllableEntity* protect);
+                ControllableEntity* getProtect();
+                void setEnemy( ControllableEntity* enemy);
+                ControllableEntity* getEnemy();
             //----["Waypoints" data]----
                 void setTargetPosition(const Vector3& target);
                 Vector3 getTargetPosition ();
@@ -97,10 +100,13 @@
             std::string actionName_;
             std::string protectName_;
             std::string enemyName_;
+            WeakPtr<ControllableEntity> protect_;
+            WeakPtr<ControllableEntity> enemy_;
+
             bool protectMe_;
             bool fightAll_;
             Vector3 targetPosition_;
     };
 }
 
-#endif /* _ActionPoint_H__ */
+#endif /* _Actionpoint_H__ */

Modified: code/branches/campaignHS15/src/orxonox/worldentities/CMakeLists.txt
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/CMakeLists.txt	2015-11-23 21:21:04 UTC (rev 10846)
+++ code/branches/campaignHS15/src/orxonox/worldentities/CMakeLists.txt	2015-11-24 10:54:47 UTC (rev 10847)
@@ -11,7 +11,7 @@
   CameraPosition.cc
   SpawnPoint.cc
   TeamSpawnPoint.cc
-  ActionPoint.cc
+  Actionpoint.cc
 )
 
 ADD_SUBDIRECTORY(pawns)




More information about the Orxonox-commit mailing list