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

gania at orxonox.net gania at orxonox.net
Mon Nov 23 15:51:00 CET 2015


Author: gania
Date: 2015-11-23 15:50:59 +0100 (Mon, 23 Nov 2015)
New Revision: 10838

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/controllers/SectionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
   code/branches/campaignHS15/src/orxonox/worldentities/SpawnPoint.h
   code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.cc
   code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.h
Log:
Gani changed something

Modified: code/branches/campaignHS15/data/levels/AITest.oxw
===================================================================
--- code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-23 14:46:58 UTC (rev 10837)
+++ code/branches/campaignHS15/data/levels/AITest.oxw	2015-11-23 14:50:59 UTC (rev 10838)
@@ -31,8 +31,8 @@
   >
 
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
-    <SpawnPoint team=0 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
-    >
+    <TeamSpawnPoint team=1 position="-1000,-1000,-1000" lookat="1,1,-1" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    
 <!-- 
     <?lua
       for i = 0, 5, 1 do
@@ -51,44 +51,53 @@
     <?lua end ?> -->
  
     
-    <SpaceShip position="4000, 1500, -1000" lookat="0,0,0">
+    <SpaceShip position="4000, 1500, -1000" lookat="0,0,0" team=0>
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <DivisionController team=1 formationMode="wall" action="FIGHT">
+        <DivisionController formationMode="wall" action="PROTECT" protect="FUCK" team=0>
         </DivisionController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0">
+    <SpaceShip position="4000 ,1500, -1600 " lookat="0,0,0" team=0>
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <WingmanController team=1>
+        <WingmanController >
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="4000, 1500, -2200" lookat="0,0,0">
+    <SpaceShip position="4000, 1500, -2200" lookat="0,0,0" team=0>
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <WingmanController team=1>
+        <WingmanController >
         </WingmanController>
       </controller>
     </SpaceShip>
-    <SpaceShip position="4000, 1500, -2800 " lookat="0,0,0">
+    <SpaceShip position="4000, 1500, -2800 " lookat="0,0,0" team=0>
       <templates>
         <Template link=spaceshipassff />
       </templates>
       <controller>
-        <SectionController team=1>
+        <SectionController >
         </SectionController>
       </controller>
     </SpaceShip>
+    <SpaceShip position="-4000, 1500, -2800 " lookat="0,0,0" team=0 name="FUCK">
+      <templates>
+        <Template link=spaceshipassff />
+      </templates>
+      <controller>
+        <SectionController>
+        </SectionController>
+      </controller>
+    </SpaceShip>
     
-    <SpaceShip position="-4000, 1500, -5000" lookat="0,0,0">
+    <!-- <SpaceShip position="-4000, 1500, -5000" lookat="0,0,0">
       <templates>
         <Template link=spaceshipassff />
       </templates>
@@ -123,7 +132,7 @@
         <SectionController team=2>
         </SectionController>
       </controller>
-    </SpaceShip>
+    </SpaceShip> -->
 
     
    

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-23 14:46:58 UTC (rev 10837)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.cc	2015-11-23 14:50:59 UTC (rev 10838)
@@ -37,10 +37,17 @@
 #include "worldentities/pawns/SpaceShip.h"
 
 #include "Scene.h"
-#include <OgreRay.h>
-#include <OgreSceneQuery.h>
-#include <OgreCamera.h>
-#include <OgreSceneManager.h>
+
+#include "worldentities/pawns/TeamBaseMatchBase.h"
+#include "gametypes/TeamDeathmatch.h"
+#include "gametypes/Dynamicmatch.h"
+#include "gametypes/Mission.h"
+#include "gametypes/Gametype.h"
+#include "controllers/WaypointPatrolController.h"
+#include "controllers/NewHumanController.h"
+#include "controllers/DroneController.h"
+
+
 namespace orxonox
 {
 
@@ -50,8 +57,6 @@
 
     CommonController::CommonController( Context* context ): Controller( context )
     {
-
-       
         this->action_ = Action::FLY;
         this->stopLookingAtTarget();
        
@@ -69,8 +74,34 @@
         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, "enemy", setEnemyXML, getEnemyXML,  xmlelement, mode );
+    }
+    void CommonController::setProtectXML( std::string val )
+    {
+        for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
+        {
+            if ((*itP)->getName() == val)
+            {
+                this->setProtect (static_cast<ControllableEntity*>(*itP));
+            }
+        }
+    }
+    std::string CommonController::getProtectXML ()
+    {
+        if (!this->getProtect())
+            return "noProtectWasSet";
+        return this->getProtect()->getName();
+    }
 
+    void CommonController::setProtect (ControllableEntity* protect)
+    {
+        this->protect_ = protect;
     }
+    ControllableEntity* CommonController::getProtect ()
+    {
+        return this->protect_;
+    }
     void CommonController::setActionXML( std::string val)
     {
         const std::string valUpper = getUppercase( val );
@@ -204,10 +235,10 @@
 
         Pawn* closestTarget = 0;
         float minDistance =  std::numeric_limits<float>::infinity();
-        
+        Gametype* gt = this->getGametype();
         for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
         {
-            if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
+            if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
                 continue;
 
             float distance = CommonController::distance (*itP, this->getControllableEntity());
@@ -668,11 +699,115 @@
             return std::numeric_limits<float>::infinity();
         return ( entity1->getPosition() - entity2->getPosition() ).length();
     }
-    bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2)
+    bool CommonController::sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
     {
-        if (!entity1 || !entity2)
+        /*if (!entity1 || !entity2)
             return false;
-        return entity1->getTeam() == entity2->getTeam();
+        return entity1->getTeam() == entity2->getTeam();*/
+        if (entity1 == entity2)
+            return true;
+
+        int team1 = entity1->getTeam();
+        int team2 = entity2->getTeam();
+
+        Controller* controller = 0;
+        if (entity1->getController())
+            controller = entity1->getController();
+        else
+            controller = entity1->getXMLController();
+        if (controller)
+        {
+            CommonController* ac = orxonox_cast<CommonController*>(controller);
+            if (ac)
+                team1 = ac->getTeam();
+        }
+
+        if (entity2->getController())
+            controller = entity2->getController();
+        else
+            controller = entity2->getXMLController();
+        if (controller)
+        {
+            CommonController* ac = orxonox_cast<CommonController*>(controller);
+            if (ac)
+                team2 = ac->getTeam();
+        }
+
+        TeamGametype* tdm = orxonox_cast<TeamGametype*>(gametype);
+        if (tdm)
+        {
+            if (entity1->getPlayer())
+                team1 = tdm->getTeam(entity1->getPlayer());
+
+            if (entity2->getPlayer())
+                team2 = tdm->getTeam(entity2->getPlayer());
+        }
+
+        TeamBaseMatchBase* base = 0;
+        base = orxonox_cast<TeamBaseMatchBase*>(entity1);
+        if (base)
+        {
+            switch (base->getState())
+            {
+                case BaseState::ControlTeam1:
+                    team1 = 0;
+                    break;
+                case BaseState::ControlTeam2:
+                    team1 = 1;
+                    break;
+                case BaseState::Uncontrolled:
+                default:
+                    team1 = -1;
+            }
+        }
+        base = orxonox_cast<TeamBaseMatchBase*>(entity2);
+        if (base)
+        {
+            switch (base->getState())
+            {
+                case BaseState::ControlTeam1:
+                    team2 = 0;
+                    break;
+                case BaseState::ControlTeam2:
+                    team2 = 1;
+                    break;
+                case BaseState::Uncontrolled:
+                default:
+                    team2 = -1;
+            }
+        }
+
+        DroneController* droneController = 0;
+        droneController = orxonox_cast<DroneController*>(entity1->getController());
+        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity2)
+            return true;
+        droneController = orxonox_cast<DroneController*>(entity2->getController());
+        if (droneController && static_cast<ControllableEntity*>(droneController->getOwner()) == entity1)
+            return true;
+        DroneController* droneController1 = orxonox_cast<DroneController*>(entity1->getController());
+        DroneController* droneController2 = orxonox_cast<DroneController*>(entity2->getController());
+        if (droneController1 && droneController2 && droneController1->getOwner() == droneController2->getOwner())
+            return true;
+
+        Dynamicmatch* dynamic = orxonox_cast<Dynamicmatch*>(gametype);
+        if (dynamic)
+        {
+            if (dynamic->notEnoughPigs||dynamic->notEnoughKillers||dynamic->notEnoughChasers) {return false;}
+
+            if (entity1->getPlayer())
+                team1 = dynamic->getParty(entity1->getPlayer());
+
+            if (entity2->getPlayer())
+                team2 = dynamic->getParty(entity2->getPlayer());
+
+            if (team1 ==-1 ||team2 ==-1 ) {return false;}
+            else if (team1 == dynamic->chaser && team2 != dynamic->chaser) {return false;}
+            else if (team1 == dynamic->piggy && team2 == dynamic->chaser) {return false;}
+            else if (team1 == dynamic->killer && team2 == dynamic->chaser) {return false;}
+            else return true;
+        }
+
+        return (team1 == team2 && team1 != -1);
     }
     void CommonController::doFire() 
     {

Modified: code/branches/campaignHS15/src/orxonox/controllers/CommonController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-23 14:46:58 UTC (rev 10837)
+++ code/branches/campaignHS15/src/orxonox/controllers/CommonController.h	2015-11-23 14:50:59 UTC (rev 10838)
@@ -102,6 +102,12 @@
                     inline Rank::Value getRank() const
                         { return this->rank_; }
                 //----[/Rank data]----
+                //----[Protect data]----
+                    void setProtectXML( std::string val );
+                    std::string getProtectXML ();
+                    void setProtect (ControllableEntity* protect);
+                    ControllableEntity* getProtect ();
+                //----[/Protect data]----
             //----[/XML data]----
 
             //----[Interaction with other Controllers]----
@@ -123,7 +129,7 @@
             //----[Helper functions]----
                 float randomInRange(float a, float b);
                 static float distance(ControllableEntity* entity1, ControllableEntity* entity2);
-                static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2);
+                static bool sameTeam (ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gt);
                 static bool isLooking( ControllableEntity* entityThatLooks, ControllableEntity* entityBeingLookedAt, float angle ) ;
 
                 float squaredDistanceToTarget() const;
@@ -167,13 +173,16 @@
                 Vector3 targetPosition_;
                 bool bHasTargetOrientation_;
                 Quaternion targetOrientation_;
-                // Vector3 destination_;
-                // bool bHasDestination;
+                
+                Vector3 destination_;
+                bool bHasDestination;
             //----[/where-to-fly information]----
-            
+            //----[protect information]----
+                WeakPtr<ControllableEntity> protect_;
+            //----[/protect information]----
             //----[who-to-kill information]----
                 WeakPtr<ControllableEntity> target_;
-                //WeakPtr<ControllableEntity> objectiveTarget_;
+                WeakPtr<ControllableEntity> enemy_;
 
                 bool bHasPositionOfTarget_;
                 Vector3 positionOfTarget_;

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-23 14:46:58 UTC (rev 10837)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-23 14:50:59 UTC (rev 10838)
@@ -132,7 +132,10 @@
         }
         else if (this->action_ == Action::PROTECT)
         {
-
+            if (this->getProtect())
+            {
+                orxout(internal_error) << "PROTECT FOUND" << endl;
+            }
         }
 
     }

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-11-23 14:46:58 UTC (rev 10837)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-11-23 14:50:59 UTC (rev 10838)
@@ -167,11 +167,11 @@
                     bool foundTarget = false;
                     //----new target should be close to division's target----
                     Vector3 divisionTargetPosition = this->myDivisionLeader_->getTarget()->getWorldPosition();
-                    
+                    Gametype* gt = this->getGametype();
                     for (ObjectList<Pawn>::iterator itP = ObjectList<Pawn>::begin(); itP; ++itP)
                     {
                         //----is enemy?----
-                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP)) )
+                        if ( CommonController::sameTeam (this->getControllableEntity(), static_cast<ControllableEntity*>(*itP), gt) )
                             continue;           
                         //----in range?----
                         if (((*itP)->getWorldPosition() - divisionTargetPosition).length() < 3000 && 

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-11-23 14:46:58 UTC (rev 10837)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-11-23 14:50:59 UTC (rev 10838)
@@ -134,7 +134,7 @@
         //----vars for finding the closest leader----
         CommonController* closestLeader = 0;
         float minDistance =  std::numeric_limits<float>::infinity();
-
+        Gametype* gt = this->getGametype();
         for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
         {
             //----0ptr or not a leader or dead?----
@@ -144,7 +144,7 @@
                 continue;
             
             //----same team?----
-            if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity()) )
+            if ( !CommonController::sameTeam (this->getControllableEntity(), (it)->getControllableEntity(), gt) )
                 continue;
             
             //----check distance----

Modified: code/branches/campaignHS15/src/orxonox/worldentities/SpawnPoint.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/SpawnPoint.h	2015-11-23 14:46:58 UTC (rev 10837)
+++ code/branches/campaignHS15/src/orxonox/worldentities/SpawnPoint.h	2015-11-23 14:50:59 UTC (rev 10838)
@@ -54,7 +54,7 @@
             inline Template* getTemplate() const
                 { return this->template_; }
 
-            Pawn* spawn();
+            virtual Pawn* spawn();
             void spawn(ControllableEntity* entity);
 
         private:

Modified: code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.cc	2015-11-23 14:46:58 UTC (rev 10837)
+++ code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.cc	2015-11-23 14:50:59 UTC (rev 10838)
@@ -48,4 +48,10 @@
 
         XMLPortParam(TeamSpawnPoint, "team", setTeamNumber, getTeamNumber, xmlelement, mode).defaultValues(0);
     }
+    Pawn* TeamSpawnPoint::spawn()
+    {
+        Pawn* entity = SpawnPoint::spawn();
+        static_cast<ControllableEntity*>(entity)->setTeam (this->teamNumber_);
+        return entity;
+    }
 }

Modified: code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.h	2015-11-23 14:46:58 UTC (rev 10837)
+++ code/branches/campaignHS15/src/orxonox/worldentities/TeamSpawnPoint.h	2015-11-23 14:50:59 UTC (rev 10838)
@@ -48,9 +48,10 @@
                 { this->teamNumber_ = team; }
             unsigned int getTeamNumber() const
                 { return this->teamNumber_; }
+            virtual Pawn* spawn();
 
         private:
-            unsigned int teamNumber_;
+            int teamNumber_;
     };
 }
 




More information about the Orxonox-commit mailing list