[Orxonox-commit 5395] r10058 - in code/branches/modularships: data/levels/templates src/orxonox/controllers src/orxonox/items src/orxonox/worldentities src/orxonox/worldentities/pawns

noep at orxonox.net noep at orxonox.net
Thu May 15 15:53:11 CEST 2014


Author: noep
Date: 2014-05-15 15:53:11 +0200 (Thu, 15 May 2014)
New Revision: 10058

Modified:
   code/branches/modularships/data/levels/templates/HeavyCruiser.oxt
   code/branches/modularships/src/orxonox/controllers/NewHumanController.cc
   code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc
   code/branches/modularships/src/orxonox/items/PartDestructionEvent.h
   code/branches/modularships/src/orxonox/items/ShipPart.cc
   code/branches/modularships/src/orxonox/items/ShipPart.h
   code/branches/modularships/src/orxonox/worldentities/StaticEntity.cc
   code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
   code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h
   code/branches/modularships/src/orxonox/worldentities/pawns/SpaceShip.h
Log:
Expanded functionality of PartDestructionEvents, fixed cursor not showing when flying a ModularSpaceShip

Modified: code/branches/modularships/data/levels/templates/HeavyCruiser.oxt
===================================================================
--- code/branches/modularships/data/levels/templates/HeavyCruiser.oxt	2014-05-15 12:18:08 UTC (rev 10057)
+++ code/branches/modularships/data/levels/templates/HeavyCruiser.oxt	2014-05-15 13:53:11 UTC (rev 10058)
@@ -42,8 +42,7 @@
    angularDamping    = 0.5
   >
     <engines>
-      <MultiStateEngine position="85,0,0" template=HeavyCruiser_body_engine1 />
-      <MultiStateEngine position="-85,0,0" template=HeavyCruiser_body_engine1 />
+      <MultiStateEngine position="0,0,0" template=HeavyCruiser_body_engine1 />
 
       <MultiStateEngine position="-140,0,308" template=HeavyCruiser_sidearmL_engine1 />
       <MultiStateEngine position="140,0,308" template=HeavyCruiser_sidearmR_engine1 />
@@ -63,21 +62,43 @@
         <ShipPart name="partL" initialhealth="10" damageabsorption="0.5">
             <destructionevents>
                 <PartDestructionEvent targetType="ship" targetParam="boostpowerrate" operation="-" value="0.5" message="One of your ship's generators was destroyed!"/>
-            </destructionevents>
+		<PartDestructionEvent targetType="engine" targetName="bodyengine" targetParam="speedfront" operation="-" value="50"/>
+            	<PartDestructionEvent targetType="engine" targetName="bodyengine" targetParam="accelerationfront" operation="-" value="3"/>
+		<PartDestructionEvent targetType="engine" targetName="bodyengine" targetParam="boostfactor" operation="set" value="1"/>
+	    </destructionevents>
         </ShipPart>
         <ShipPart name="partR" initialhealth="10" damageabsorption="0.5">
             <destructionevents>
                 <PartDestructionEvent targetType="ship" targetParam="boostpowerrate" operation="-" value="0.5" message="One of your ship's generators was destroyed!"/>
+		<PartDestructionEvent targetType="engine" targetName="bodyengine" targetParam="speedfront" operation="-" value="50"/>
+            	<PartDestructionEvent targetType="engine" targetName="bodyengine" targetParam="accelerationfront" operation="-" value="3"/>
+		<PartDestructionEvent targetType="engine" targetName="bodyengine" targetParam="boostfactor" operation="set" value="1"/>
             </destructionevents>
         </ShipPart>
         <ShipPart name="sidearmL" initialhealth="20" damageabsorption="0.2">
             <destructionevents>
-                <!-- <PartDestructionEvent targetType="engine" targetName="HeavyCruiser_sidearmL_engine1" operation="destroy"/> -->
+                <PartDestructionEvent targetType="engine" targetName="sidearmLengine" operation="destroy" message="The left auxiliary engine was destroyed!"/>
+		<PartDestructionEvent targetType="part" targetName="sidearmLfront" operation="destroy"/>
+		<PartDestructionEvent targetType="ship" targetParam="rotationthrust" operation="-" value="0.04" />
             </destructionevents>
         </ShipPart>
-        <ShipPart name="sidearmLfront" initialhealth="10" damageabsorption="0.5" />
-        <ShipPart name="sidearmR" initialhealth="20" damageabsorption="0.2" />
-        <ShipPart name="sidearmRfront" initialhealth="10" damageabsorption="0.5" />
+        <ShipPart name="sidearmLfront" initialhealth="10" damageabsorption="0.5">
+            <destructionevents>
+                <PartDestructionEvent targetType="engine" targetName="sidearmLengine" targetParam="boostfactor" operation="set" value="1" message="The left auxiliary engine lost it's booster!"/>
+            </destructionevents>
+	</ShipPart>
+        <ShipPart name="sidearmR" initialhealth="20" damageabsorption="0.2">
+            <destructionevents>
+                <PartDestructionEvent targetType="engine" targetName="sidearmRengine" operation="destroy" message="The right auxiliary engine was destroyed!"/>
+		<PartDestructionEvent targetType="part" targetName="sidearmRfront" operation="destroy"/> 
+		<PartDestructionEvent targetType="ship" targetParam="rotationthrust" operation="-" value="0.04" />           
+	    </destructionevents>
+	</ShipPart>
+        <ShipPart name="sidearmRfront" initialhealth="10" damageabsorption="0.5">
+            <destructionevents>
+                <PartDestructionEvent targetType="engine" targetName="sidearmRengine" targetParam="boostfactor" operation="set" value="1" message="The right auxiliary engine lost it's booster!"/>
+            </destructionevents>
+	</ShipPart>
     </parts>
     
     <attached>
@@ -389,6 +410,7 @@
 
 <Template name=HeavyCruiser_body_engine1 baseclass=MultiStateEngine>
   <MultiStateEngine
+   name		  = bodyengine
    boostfactor    = 2
 
    speedfront     = 150
@@ -483,6 +505,7 @@
 
 <Template name=HeavyCruiser_sidearmL_engine1 baseclass=MultiStateEngine>
   <MultiStateEngine
+   name		  = sidearmLengine
    boostfactor    = 2
 
    speedfront     = 300
@@ -532,6 +555,7 @@
 
 <Template name=HeavyCruiser_sidearmR_engine1 baseclass=MultiStateEngine>
   <MultiStateEngine
+   name		  = sidearmRengine
    boostfactor    = 2
 
    speedfront     = 300

Modified: code/branches/modularships/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/branches/modularships/src/orxonox/controllers/NewHumanController.cc	2014-05-15 12:18:08 UTC (rev 10057)
+++ code/branches/modularships/src/orxonox/controllers/NewHumanController.cc	2014-05-15 13:53:11 UTC (rev 10058)
@@ -219,7 +219,7 @@
 
                 if (!controlPaused_ )
                 {
-                    if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
+                    if (this->getControllableEntity() && ((this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || (this->getControllableEntity()->isExactlyA(ClassByString("ModularSpaceShip")))) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
                         this->showOverlays();
                     else if (this->getControllableEntity() &&  this->getControllableEntity()->isExactlyA(ClassByString("FpsPlayer")))
                     {
@@ -497,7 +497,7 @@
     {
         this->controlMode_ = 0;
         this->centerCursor();
-        if (this->getControllableEntity() && (this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
+        if (this->getControllableEntity() && ((this->getControllableEntity()->isExactlyA(ClassByString("SpaceShip")) || (this->getControllableEntity()->isExactlyA(ClassByString("ModularSpaceShip")))) || this->getControllableEntity()->isExactlyA(ClassByString("Rocket"))))
         {
             this->showOverlays_ = true;
             if (!this->controlPaused_)

Modified: code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc
===================================================================
--- code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc	2014-05-15 12:18:08 UTC (rev 10057)
+++ code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc	2014-05-15 13:53:11 UTC (rev 10058)
@@ -82,8 +82,6 @@
     */
     void PartDestructionEvent::execute()
     {
-        orxout() << "Executing PartDestructionEvent " << this->getName() << endl;
-
         // Do not execute if this event is invalid
         if(!isValid())
         {
@@ -108,6 +106,9 @@
             case boostpowerrate:
                 this->parent_->getParent()->setBoostPowerRate(operate(this->parent_->getParent()->getBoostPowerRate()));
                 break;
+            case rotationthrust:
+                this->parent_->getParent()->setRotationThrust(operate(this->parent_->getParent()->getRotationThrust()));
+                break;
             default:
                 break;
             }
@@ -119,30 +120,37 @@
         {
             switch (this->targetParam_) {
             case null:
-                for(unsigned int i = 0; i < this->parent_->getParent()->getEngineList().size(); i++) // FIXME: (noep) segfault on .size()
-                {
-                    if(this->parent_->getParent()->getEngine(i)->getName() == this->targetName_)
-                    {
-                        orxout() << "engine found" << endl;
-                        this->parent_->getParent()->removeEngine(this->parent_->getParent()->getEngine(i));
-                        break;
-                    }
-                }
+                this->parent_->getParent()->removeEngine(this->parent_->getParent()->getEngineByName(targetName_));
                 break;
             case boostfactor:
-                for(unsigned int i = 0; i < this->parent_->getParent()->getEngineList().size(); i++)
-                {
-                    if(this->parent_->getParent()->getEngine(i)->getName() == this->targetName_)
-                        this->parent_->getParent()->getEngine(i)->setBoostFactor(operate(this->parent_->getParent()->getEngine(i)->getBoostFactor()));
-                    break;
-                }
+                this->parent_->getParent()->getEngineByName(targetName_)->setBoostFactor(operate(this->parent_->getParent()->getEngineByName(targetName_)->getBoostFactor()));
                 break;
+            case speedfront:
+                this->parent_->getParent()->getEngineByName(targetName_)->setMaxSpeedFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getMaxSpeedFront()));
+                break;
+            case accelerationfront:
+                this->parent_->getParent()->getEngineByName(targetName_)->setAccelerationFront(operate(this->parent_->getParent()->getEngineByName(targetName_)->getAccelerationFront()));
+                break;
             default:
                 break;
             }
             this->setValid(false);
             return;
         }
+
+        if (this->targetType_ == "part")
+        {
+            switch (this->targetParam_) {
+            case null:
+                this->parent_->getParent()->getShipPartByName(targetName_)->setEventExecution(false);
+                this->parent_->getParent()->killShipPart(targetName_);
+                break;
+            default:
+                break;
+            }
+            this->setValid(false);
+            return;
+        }
     }
 
     void PartDestructionEvent::setParent(ShipPart* part)
@@ -158,14 +166,14 @@
     */
     void PartDestructionEvent::setTargetType(std::string type)
     {
-        if ((type == "ship") || (type == "engine") || (type == "weapon"))
+        if ((type == "ship") || (type == "engine") || (type == "weapon") || (type == "part"))
         {
             this->targetType_ = type;
             return;
         }
 
         // Error, if invalid target-type was entered.
-        orxout(internal_warning) << "\"" << type << "\" is not a valid target-type for a PartDestructionEvent. Valid types are: ship engine weapon" << endl;
+        orxout(internal_warning) << "\"" << type << "\" is not a valid target-type for a PartDestructionEvent. Valid types are: ship engine weapon part" << endl;
         this->setValid(false);
         return;
     }
@@ -228,7 +236,7 @@
 
         // weapon:
 
-        // ship: shieldhealth (maxshieldhealth shieldabsorption shieldrechargerate) boostpower boostpowerrate
+        // ship: shieldhealth (maxshieldhealth shieldabsorption shieldrechargerate) boostpower boostpowerrate rotationthrust
         if (this->targetType_ == "ship")
         {
             if (param == "shieldhealth")
@@ -246,11 +254,28 @@
                 this->targetParam_ = boostpowerrate;
                 return;
             }
+            if (param == "rotationthrust")
+            {
+                this->targetParam_ = rotationthrust;
+                return;
+            }
 
-            orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"ship\". Valid types are: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate boostpower boostpowerrate" << endl;
+            orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"ship\". Valid types are: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate boostpower boostpowerrate rotationthrust" << endl;
             return;
         }
 
+        if (this->targetType_ == "part")
+        {
+            if (param == "NULL")
+            {
+                this->targetParam_ = null;
+                return;
+            }
+
+            orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"part\". Valid types are: NULL (set operation to \"destroy\")" << endl;
+            return;
+        }
+
         orxout(internal_warning) << "No valid target-param defined. The chosen param is either invalid or not available for this target-type." << endl;
         this->setValid(false);
     }
@@ -264,13 +289,13 @@
     void PartDestructionEvent::setOperation(std::string operation)
     {
         // * + - destroy
-        if ((operation == "*") || (operation == "+") || (operation == "-") || (operation == "destroy"))
+        if ((operation == "*") || (operation == "+") || (operation == "-") || (operation == "set") || (operation == "destroy"))
         {
             this->operation_ = operation;
             return;
         }
         this->operation_ = "NULL";
-        orxout(internal_warning) << "\"" << operation << "\" is not a valid operation for a PartDestructionEvent. Valid operations are: * + - destroy" << endl;
+        orxout(internal_warning) << "\"" << operation << "\" is not a valid operation for a PartDestructionEvent. Valid operations are: * + - set destroy" << endl;
     }
 
     /**
@@ -291,7 +316,9 @@
     @param input
         The value which should be modified
     @return
-        Returns the product / sum / difference of input and configured value, or 0 if the operation is "destroy"
+        Returns the product / sum / difference of input and configured value,
+        the configured value if the operation is "set",
+        or 0 if the operation is "destroy"
     */
     float PartDestructionEvent::operate(float input)
     {
@@ -301,6 +328,8 @@
             return input + this->value_;
         if (this->operation_ == "-")
             return input - this->value_;
+        if (this->operation_ == "set")
+            return this->value_;
         if (this->operation_ == "destroy")
         {
             return 0;

Modified: code/branches/modularships/src/orxonox/items/PartDestructionEvent.h
===================================================================
--- code/branches/modularships/src/orxonox/items/PartDestructionEvent.h	2014-05-15 12:18:08 UTC (rev 10057)
+++ code/branches/modularships/src/orxonox/items/PartDestructionEvent.h	2014-05-15 13:53:11 UTC (rev 10058)
@@ -89,6 +89,7 @@
                 shieldrechargerate,
                 boostpower,         // Amount of available boost
                 boostpowerrate,     // Recharge-rate of boost
+                rotationthrust,
                 boostfactor,
                 speedfront,
                 accelerationfront,

Modified: code/branches/modularships/src/orxonox/items/ShipPart.cc
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.cc	2014-05-15 12:18:08 UTC (rev 10057)
+++ code/branches/modularships/src/orxonox/items/ShipPart.cc	2014-05-15 13:53:11 UTC (rev 10058)
@@ -51,6 +51,7 @@
     {
         RegisterObject(ShipPart);
         this->setAlive(true);
+        this->setEventExecution(true);
     }
 
     ShipPart::~ShipPart()
@@ -102,11 +103,13 @@
 
         this->setAlive(false);
 
-        // Execute all destruction events
-        for (unsigned int i = 0; i < this->eventList_.size(); i++)
+        if(eventExecution_)
         {
-            orxout() << "executing" << endl;
-            this->getDestructionEvent(i)->execute();
+            // Execute all destruction events
+            for (unsigned int i = 0; i < this->eventList_.size(); i++)
+            {
+                this->getDestructionEvent(i)->execute();
+            }
         }
 
         // Remove this ShipPart from the parent.

Modified: code/branches/modularships/src/orxonox/items/ShipPart.h
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.h	2014-05-15 12:18:08 UTC (rev 10057)
+++ code/branches/modularships/src/orxonox/items/ShipPart.h	2014-05-15 13:53:11 UTC (rev 10058)
@@ -77,6 +77,11 @@
             inline bool isAlive()
                 { return this->alive_; }
 
+            inline void setEventExecution(bool var)
+                { this->eventExecution_ = var; }
+            inline bool isEventExecution()
+                { return this->eventExecution_; }
+
             virtual void setHealth(float health);
             inline void addHealth(float health)
                 { this->setHealth(this->health_ + health); }
@@ -113,6 +118,7 @@
             std::vector<PartDestructionEvent*> eventList_;  // The list of all PartDestructionEvent assigned to this ShipPart.
 
             bool alive_;
+            bool eventExecution_;
 
 
     }; // tolua_export

Modified: code/branches/modularships/src/orxonox/worldentities/StaticEntity.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/StaticEntity.cc	2014-05-15 12:18:08 UTC (rev 10057)
+++ code/branches/modularships/src/orxonox/worldentities/StaticEntity.cc	2014-05-15 13:53:11 UTC (rev 10058)
@@ -33,6 +33,7 @@
 #include <BulletDynamics/Dynamics/btRigidBody.h>
 #include "util/OrxAssert.h"
 #include "core/CoreIncludes.h"
+#include "worldentities/BigExplosion.h"
 
 namespace orxonox
 {
@@ -114,4 +115,5 @@
         worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z));
         worldTrans.setRotation(btQuaternion(node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z, node_->getOrientation().w));
     }
+
 }

Modified: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc	2014-05-15 12:18:08 UTC (rev 10057)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc	2014-05-15 13:53:11 UTC (rev 10058)
@@ -39,6 +39,7 @@
 #include "core/command/ConsoleCommand.h"
 
 #include "items/ShipPart.h"
+#include "items/Engine.h"
 #include "worldentities/StaticEntity.h"
 #include "collisionshapes/WorldEntityCollisionShape.h"
 #include <BulletCollision/CollisionShapes/btCollisionShape.h>
@@ -229,6 +230,27 @@
 
     /**
     @brief
+        Looks for an attached ShipPart with a certain name.
+    @param name
+        The name of the ShipPart to be returned.
+    @return
+        Pointer to the ShipPart with the given name, or NULL if not found.
+    */
+    ShipPart* ModularSpaceShip::getShipPartByName(std::string name)
+    {
+        for(std::vector<ShipPart*>::iterator it = this->partList_.begin(); it != this->partList_.end(); ++it)
+        {
+            if(orxonox_cast<ShipPart*>(*it)->getName() == name)
+            {
+                return orxonox_cast<ShipPart*>(*it);
+            }
+        }
+        orxout(internal_warning) << "Couldn't find ShipPart with name \"" << name << "\"." << endl;
+        return NULL;
+    }
+
+    /**
+    @brief
         Check whether the SpaceShip has a particular Engine.
     @param engine
         A pointer to the Engine to be checked.
@@ -284,6 +306,27 @@
 
     /**
     @brief
+        Looks for an attached Engine with a certain name.
+    @param name
+        The name of the engine to be returned.
+    @return
+        Pointer to the engine with the given name, or NULL if not found.
+    */
+    Engine* ModularSpaceShip::getEngineByName(std::string name)
+    {
+        for(std::vector<Engine*>::iterator it = this->engineList_.begin(); it != this->engineList_.end(); ++it)
+        {
+            if(orxonox_cast<Engine*>(*it)->getName() == name)
+            {
+                return orxonox_cast<Engine*>(*it);
+            }
+        }
+        orxout(internal_warning) << "Couldn't find Engine with name \"" << name << "\"." << endl;
+        return NULL;
+    }
+
+    /**
+    @brief
         Detaches a child WorldEntity from this instance.
     */
     void ModularSpaceShip::detach(WorldEntity* object)
@@ -296,7 +339,6 @@
         }
 
         // collision shapes
-        orxout() << "MSS: detach()" << endl;
 
         //this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
         this->detachCollisionShape(object->collisionShape_);  // after succeeding, causes a crash in the collision handling
@@ -313,6 +355,5 @@
         this->children_.erase(it);        // this causes a crash when unloading the level. Or not?
 
         object->notifyDetached();
-        orxout() << "MSS: detach() completed." << endl;
     }
 }

Modified: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h	2014-05-15 12:18:08 UTC (rev 10057)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h	2014-05-15 13:53:11 UTC (rev 10058)
@@ -116,9 +116,16 @@
 
             void addShipPart(ShipPart* part);
             ShipPart* getShipPart(unsigned int index);
+            ShipPart* getShipPartByName(std::string name);
             bool hasShipPart(ShipPart* part) const;
             void removeShipPart(ShipPart* part);
 
+            inline void setRotationThrust(float val)
+                { this->rotationThrust_ = val; }
+            inline float getRotationThrust()
+                { return this->rotationThrust_; }
+
+            Engine* getEngineByName(std::string name);
             void detach(WorldEntity* object);
 
             virtual void updatePartAssignment();

Modified: code/branches/modularships/src/orxonox/worldentities/pawns/SpaceShip.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/SpaceShip.h	2014-05-15 12:18:08 UTC (rev 10057)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/SpaceShip.h	2014-05-15 13:53:11 UTC (rev 10058)
@@ -269,6 +269,8 @@
             float lift_;       //!< The amount of lift that is added.
             float stallSpeed_; //!< The forward speed where no more lift is added.
 
+            std::vector<Engine*> engineList_; //!< The list of all Engines mounted on this SpaceShip.
+
         private:
             void registerVariables();
             virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
@@ -284,8 +286,6 @@
             void backupCamera(); // Save the original position and orientation of the camera.
             void resetCamera(); // Reset the camera to its original position.
 
-            std::vector<Engine*> engineList_; //!< The list of all Engines mounted on this SpaceShip.
-
             Timer timer_;                          //!< Timer for the cooldown duration.
             float shakeDt_;                        //!< Temporary variable for the shaking of the camera.
             Vector3 cameraOriginalPosition_;       //!< The original position of the camera before shaking it.




More information about the Orxonox-commit mailing list