[Orxonox-commit 3515] r8201 - in code/branches/spaceboundaries: data/levels src/orxonox/worldentities

kmaurus at orxonox.net kmaurus at orxonox.net
Thu Apr 7 16:11:20 CEST 2011


Author: kmaurus
Date: 2011-04-07 16:11:20 +0200 (Thu, 07 Apr 2011)
New Revision: 8201

Added:
   code/branches/spaceboundaries/data/levels/myTestLevel.oxw
Modified:
   code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
   code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
Log:
healthDecreasing added, position of SpaceBoundaries added to the radar

Added: code/branches/spaceboundaries/data/levels/myTestLevel.oxw
===================================================================
--- code/branches/spaceboundaries/data/levels/myTestLevel.oxw	                        (rev 0)
+++ code/branches/spaceboundaries/data/levels/myTestLevel.oxw	2011-04-07 14:11:20 UTC (rev 8201)
@@ -0,0 +1,38 @@
+<LevelInfo
+ name = "MyTestLevel"
+ description = "A level to test the Class SpaceBoundaries."
+ tags = "test"
+/>
+
+<?lua
+  include("stats.oxo")
+  include("HUDTemplates3.oxo")
+  include("templates/lodInformation.oxt")
+?>
+
+<?lua
+  include("templates/spaceshipAssff.oxt")
+  include("templates/spaceshipPirate.oxt")
+?>
+
+<Level
+ name         = "Sample"
+ description  = "Just a few tests"
+>
+  <templates>
+    <Template link=lodtemplate_default />
+  </templates>
+
+  <Scene
+    ambientlight = "0.8, 0.8, 0.8"
+    skybox       = "Orxonox/Starbox"
+  >
+
+    <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="0,0,0" lookat="200,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
+    
+    <SpaceBoundaries warnDistance="-1" maxDistance="200" healthDecrease="0.1" position="200,0,0"/>
+    
+  </Scene>
+</Level>
+

Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc	2011-04-07 10:55:24 UTC (rev 8200)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc	2011-04-07 14:11:20 UTC (rev 8201)
@@ -28,19 +28,15 @@
 
 #include "SpaceBoundaries.h"
 
-/* Folgender Block ist Copy-Paste und somit teilweise wohl unnoetig */
-#include "core/Template.h"
-#include "core/XMLPort.h"
-#include "gametypes/Gametype.h"
-#include "worldentities/pawns/Pawn.h"
-
-/* Eigene, spezifische include-Statements*/
 #include "worldentities/MobileEntity.h"
 #include "worldentities/ControllableEntity.h"
 #include "core/ObjectListIterator.h"
-#include <worldentities/pawns/Pawn.h>
-#include <infos/PlayerInfo.h>
+#include "core/XMLPort.h"
+#include "worldentities/pawns/Pawn.h"
+#include "infos/PlayerInfo.h"
+#include "interfaces/RadarViewable.h"
 
+
 //#include <OgreTextAreaOverlayElement.h>
 #include <OgreOverlayManager.h>
 //#include <overlays/OverlayText.h>
@@ -51,25 +47,27 @@
 
     SpaceBoundaries::SpaceBoundaries(BaseObject* creator) : StaticEntity(creator)
     {
+        /* Standardwerte, die zum Tragen kommen,
+         * falls im XML-File keine Werte spezifiziert wurden. */
+        this->setMaxDistance(3000);
+        this->setWarnDistance(2000);
+        this->setHealthDecrease(1);
+        
         RegisterObject(SpaceBoundaries);
-        COUT(0) << "Test ob Konstruktor aufgerufen wird." << std::endl; //!< message for debugging
+        
         // Show Boundaries on the radar.
+        this->centerRadar_ = new RadarViewable(this, this);
+        this->centerRadar_->setRadarObjectShape(RadarViewable::Dot);
+        this->centerRadar_->setRadarVisibility(false);
+        
 //         m_pColoredTextAreaOverlayElementFactory = new ColoredTextAreaOverlayElementFactory();
     }
     SpaceBoundaries::~SpaceBoundaries()
     {
+        delete this->centerRadar_;
 //        delete pColoredTextAreaOverlayElementFactory;
     }
     
-    void SpaceBoundaries::setCenter(Vector3 r)
-    {
-        this->center_ = r;
-    }
-    Vector3 SpaceBoundaries::getCenter()
-    {
-        return this->center_;
-    }
-    
     void SpaceBoundaries::setMaxDistance(float r)
     {
         this->maxDistance_ = r;
@@ -87,14 +85,23 @@
     {
         return this->warnDistance_;
     }
+    
+    void SpaceBoundaries::setHealthDecrease(float amount)
+    {
+        this->healthDecrease_ = amount/1000;
+    }
+    float SpaceBoundaries::getHealthDecrease()
+    {
+        return this->healthDecrease_;
+    }
 
     void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(SpaceBoundaries, XMLPort, xmlelement, mode);
 
-        XMLPortParam(SpaceBoundaries, "center", setCenter, getCenter, xmlelement, mode);
         XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode);
         XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode);
+        XMLPortParam(SpaceBoundaries, "healthDecrease", setHealthDecrease, getHealthDecrease, xmlelement, mode);
     }
     
     void SpaceBoundaries::tick(float dt)
@@ -103,14 +110,12 @@
         {
             MobileEntity* myMobileEntity = *item;
             Pawn* myItem = dynamic_cast<Pawn*>(myMobileEntity);
-            //COUT(0) << "Die for-Schleife wird erreicht!!!" << std::endl; //!< message for debugging
             if(myItem != NULL)
             {
                 float distance = computeDistance((WorldEntity*) myItem);
                 bool humanItem = this->isHumanPlayer(myItem);
-                COUT(0) << "Pawn wird erkannt!!!" << std::endl; //!< message for debugging
                 COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging
-                if(distance > this->warnDistance_ /*&& distance < this->maxDistance*/)
+                if(distance > this->warnDistance_ && distance < this->maxDistance_)
                 {
                     COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
                     if(humanItem)
@@ -118,16 +123,18 @@
                         COUT(0) << "humanItem ist true" << std::endl;
                         this->displayWarning("Attention! You are leaving the area!");
                     } else {
-                    
+                        
                     }
-                } else if(distance > maxDistance_)
+                }
+                if(distance > maxDistance_)
                 {
-                    // Decrease Health
                     if(humanItem)
                     {
-                        
+                        COUT(0) << "Health should be decreasing!" << std::endl;
+                        this->displayWarning("You are out of the area now!");
+                        myItem->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
                     } else {
-                    
+                        
                     }
                 }
             }
@@ -137,7 +144,7 @@
     float SpaceBoundaries::computeDistance(WorldEntity *item)
     {
         Vector3 itemPosition = item->getPosition();
-        return (itemPosition.distance(this->center_));
+        return (itemPosition.distance(this->getPosition()));
     }
     
     void SpaceBoundaries::displayWarning(const std::string warnText)
@@ -171,32 +178,12 @@
     {
         if(item != NULL)
         {
-            return item->getPlayer()->isHumanPlayer();
-        } else {
-            return false;
+            if(item->getPlayer())
+            {
+                return item->getPlayer()->isHumanPlayer();
+            }
         }
+        return false;
     }
     
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
 }

Modified: code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h
===================================================================
--- code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h	2011-04-07 10:55:24 UTC (rev 8200)
+++ code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h	2011-04-07 14:11:20 UTC (rev 8201)
@@ -25,17 +25,19 @@
  *      ...
  *
  */
+ 
+ /* TODO: - Markiere SpaceBoundaries-Position mit einem schoenen Objekt 
+          - Kugel-Model mal hinzufuegen, das nur sichtbar ist, wenn man genuegend nah an maxDistance dran ist
+          - Reflexion an obiger Kugel beim Versuch durchzudringen
+ */
 
 #ifndef _SpaceBoundaries_H__
 #define _SpaceBoundaries_H__
 
-/* Folgender Block ist Copy-Paste und somit teilweise wohl unnoetig */
-#include "OrxonoxPrereqs.h"
-#include "core/SubclassIdentifier.h"
-
 /* Einige, spezifische include-Statements */
 #include "core/CoreIncludes.h"
 #include "tools/interfaces/Tickable.h"
+#include "interfaces/RadarViewable.h"
 #include "worldentities/StaticEntity.h"
 #include "worldentities/WorldEntity.h"
 
@@ -43,7 +45,13 @@
 
 #include <string>
 
+/**
+ at brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area.
 
+       Four attributes can/should be defined in the XML-File:
+       'position', 'warnDistance', 'maxDistance', 'healthDecrease'.
+*/
+
 namespace orxonox
 {
     class _OrxonoxExport SpaceBoundaries : public StaticEntity, public Tickable
@@ -52,27 +60,32 @@
             SpaceBoundaries(BaseObject* creator);
             ~SpaceBoundaries();
             
-            void setCenter(Vector3 r);
-            Vector3 getCenter();
-            
             void setMaxDistance(float r);
             float getMaxDistance();
             
             void setWarnDistance(float r);
             float getWarnDistance();
+            
+            void setHealthDecrease(float amount);
+            float getHealthDecrease();
 
             void XMLPort(Element& xmlelement, XMLPort::Mode mode);
             
             void tick(float dt);
 
         private:
-            Vector3 center_;
-            float maxDistance_;
-            float warnDistance_;
+            float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'.
+            float warnDistance_; //!< Entfernung von 'this->getPosition()', ab der eine Warnung angezeigt wird, dass man bald das zulaessige Areal verlaesst.
+            
+            float healthDecrease_; //!< Mass fuer die Anzahl Health-Points, die nach ueberschreiten der Entfernung 'maxDistance_' von 'this->getPosition()' abgezogen werden.
+                                   //!< Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung)
+            
+            RadarViewable* centerRadar_; //!< Repraesentation von 'this->getPosition()' auf dem Radar.
         
-            float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'center' bezogen.
+            float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'this->getPosition()' bezogen.
             void displayWarning(const std::string warnText);
             bool isHumanPlayer(Pawn *item);
+            
  //           ColoredTextAreaOverlayElementFactory* pColoredTextAreaOverlayElementFactory;
     };
 }




More information about the Orxonox-commit mailing list