[Orxonox-commit 6535] r11176 - in code/trunk/src/orxonox: . weaponsystem worldentities/pawns

fvultier at orxonox.net fvultier at orxonox.net
Thu Apr 28 15:45:32 CEST 2016


Author: fvultier
Date: 2016-04-28 15:45:32 +0200 (Thu, 28 Apr 2016)
New Revision: 11176

Modified:
   code/trunk/src/orxonox/Scene.h
   code/trunk/src/orxonox/weaponsystem/WeaponSystem.h
   code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
   code/trunk/src/orxonox/worldentities/pawns/Pawn.h
Log:
Added a debug console command that allows visualization of the weaponSlots.

Modified: code/trunk/src/orxonox/Scene.h
===================================================================
--- code/trunk/src/orxonox/Scene.h	2016-04-28 13:09:26 UTC (rev 11175)
+++ code/trunk/src/orxonox/Scene.h	2016-04-28 13:45:32 UTC (rev 11176)
@@ -47,6 +47,7 @@
 #include "core/object/Context.h"
 #include "network/synchronisable/Synchronisable.h"
 #include "tools/interfaces/Tickable.h"
+#include "core/command/ConsoleCommandIncludes.h"
 
 namespace orxonox
 {

Modified: code/trunk/src/orxonox/weaponsystem/WeaponSystem.h
===================================================================
--- code/trunk/src/orxonox/weaponsystem/WeaponSystem.h	2016-04-28 13:09:26 UTC (rev 11175)
+++ code/trunk/src/orxonox/weaponsystem/WeaponSystem.h	2016-04-28 13:45:32 UTC (rev 11176)
@@ -54,6 +54,8 @@
             void addWeaponSlot(WeaponSlot * wSlot);
             void removeWeaponSlot(WeaponSlot * wSlot);
             WeaponSlot * getWeaponSlot(unsigned int index) const;
+            inline const std::vector<WeaponSlot *>& getAllWeaponSlots() const
+                { return weaponSlots_; }
 
             // adding and removing WeaponSets
             bool addWeaponSet(WeaponSet * wSet);

Modified: code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/Pawn.cc	2016-04-28 13:09:26 UTC (rev 11175)
+++ code/trunk/src/orxonox/worldentities/pawns/Pawn.cc	2016-04-28 13:45:32 UTC (rev 11176)
@@ -48,6 +48,7 @@
 #include "weaponsystem/WeaponSet.h"
 #include "weaponsystem/Munition.h"
 #include "sound/WorldSound.h"
+#include "core/object/ObjectListIterator.h"
 
 #include "controllers/FormationController.h"
 
@@ -55,6 +56,8 @@
 {
     RegisterClass(Pawn);
 
+    SetConsoleCommand("Pawn", "debugDrawWeapons", &Pawn::consoleCommand_debugDrawWeapons).addShortcut();
+
     Pawn::Pawn(Context* context)
         : ControllableEntity(context)
         , RadarViewable(this, static_cast<WorldEntity*>(this))
@@ -167,6 +170,7 @@
     void Pawn::registerVariables()
     {
         registerVariable(this->bAlive_,            VariableDirection::ToClient);
+        registerVariable(this->bVulnerable_,       VariableDirection::ToClient);
         registerVariable(this->health_,            VariableDirection::ToClient);
         registerVariable(this->maxHealth_,         VariableDirection::ToClient);
         registerVariable(this->shieldHealth_,      VariableDirection::ToClient);
@@ -591,4 +595,57 @@
             assert(0);
         return BLANKSTRING;
     }
-}
+
+    void Pawn::drawWeapons(bool bDraw)
+    {
+        if (bDraw)
+        {
+            std::vector<WeaponSlot*> weaponSlots = weaponSystem_->getAllWeaponSlots();
+            int numWeaponSlots = weaponSlots.size();
+            Vector3 slotPosition = Vector3::ZERO;
+            Quaternion slotOrientation = Quaternion::IDENTITY;
+            Model* slotModel = nullptr;
+
+            for (int i = 0; i < numWeaponSlots; ++i)
+            {
+                slotPosition = weaponSlots.at(i)->getPosition();
+                slotOrientation = weaponSlots.at(i)->getOrientation();
+                slotModel = new Model(this->getContext());
+                slotModel->setMeshSource("Coordinates.mesh");
+                slotModel->setScale(3.0f);
+                slotModel->setOrientation(slotOrientation);
+                slotModel->setPosition(slotPosition);
+
+                this->attach(slotModel);
+                debugWeaponSlotModels_.push_back(slotModel);
+            }
+        }
+        else
+        {
+            // delete all debug models
+            for(Model* model : debugWeaponSlotModels_) 
+            {
+                model->destroy();
+            }
+            debugWeaponSlotModels_.clear();
+        }
+    }
+
+    /*static*/ void Pawn::consoleCommand_debugDrawWeapons(bool bDraw)
+    {
+        if (bDraw)
+        {
+            orxout() << "WeaponSlot visualization enabled." << endl;
+        }
+        else
+        {
+            orxout() << "WeaponSlot visualization disabled." << endl;
+        }
+
+        ObjectList<Pawn> pawnList;
+        for (ObjectListIterator<Pawn> it = pawnList.begin(); it != pawnList.end(); ++it)
+        {
+            it->drawWeapons(bDraw);
+        }
+    }
+}
\ No newline at end of file

Modified: code/trunk/src/orxonox/worldentities/pawns/Pawn.h
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/Pawn.h	2016-04-28 13:09:26 UTC (rev 11175)
+++ code/trunk/src/orxonox/worldentities/pawns/Pawn.h	2016-04-28 13:45:32 UTC (rev 11176)
@@ -217,6 +217,8 @@
             inline const WeaponSystem* getWeaponSystem() const
                 { return this->weaponSystem_; }
 
+            static void consoleCommand_debugDrawWeapons(bool bDraw);
+
         protected:
             virtual void preDestroy() override;
 
@@ -232,7 +234,7 @@
             virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = nullptr, const btCollisionShape* cs = nullptr);
 
             bool bAlive_;
-            bool bVulnerable_; ///< If false the pawn may not ged damaged
+            bool bVulnerable_; ///< If this is false, then the pawn may not take damage
 
             virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const override
                 { return new std::vector<PickupCarrier*>(); }
@@ -268,11 +270,14 @@
             void registerVariables();
             inline void setWeaponSystem(WeaponSystem* weaponsystem)
                 { this->weaponSystem_ = weaponsystem; }
+            void drawWeapons(bool bDraw);
 
             Vector3 aimPosition_;
 
             WorldSound* explosionSound_; // TODO: Does this really belong here? Maybe move it to BigExplosion?
 
+            std::vector<Model*> debugWeaponSlotModels_;
+
     }; // tolua_export
 } // tolua_export
 




More information about the Orxonox-commit mailing list