[Orxonox-commit 5389] r10052 - in code/branches/modularships: data/levels/templates src/orxonox src/orxonox/items src/orxonox/worldentities src/orxonox/worldentities/pawns
noep at orxonox.net
noep at orxonox.net
Thu May 8 16:20:26 CEST 2014
Author: noep
Date: 2014-05-08 16:20:26 +0200 (Thu, 08 May 2014)
New Revision: 10052
Added:
code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc
code/branches/modularships/src/orxonox/items/PartDestructionEvent.h
Modified:
code/branches/modularships/data/levels/templates/HeavyCruiser.oxt
code/branches/modularships/src/orxonox/OrxonoxPrereqs.h
code/branches/modularships/src/orxonox/items/CMakeLists.txt
code/branches/modularships/src/orxonox/items/ShipPart.cc
code/branches/modularships/src/orxonox/items/ShipPart.h
code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc
code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
Log:
Added PartDestructionEvent, possibly fixed one out of two runtimeerrors
Modified: code/branches/modularships/data/levels/templates/HeavyCruiser.oxt
===================================================================
--- code/branches/modularships/data/levels/templates/HeavyCruiser.oxt 2014-05-08 14:16:59 UTC (rev 10051)
+++ code/branches/modularships/data/levels/templates/HeavyCruiser.oxt 2014-05-08 14:20:26 UTC (rev 10052)
@@ -50,7 +50,11 @@
</engines>
<parts>
- <ShipPart name="frontL" initialhealth="10" damageabsorption="0.5" />
+ <ShipPart name="frontL" initialhealth="10" damageabsorption="0.5">
+ <destructionevents>
+ <PartDestructionEvent targetType="ship" targetParam="shieldhealth" operation="*" value="0.5"/>
+ </destructionevents>
+ </ShipPart>
<ShipPart name="frontR" initialhealth="10" damageabsorption="0.5" />
<ShipPart name="partL" initialhealth="10" damageabsorption="0.5" />
<ShipPart name="partR" initialhealth="10" damageabsorption="0.5" />
Modified: code/branches/modularships/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- code/branches/modularships/src/orxonox/OrxonoxPrereqs.h 2014-05-08 14:16:59 UTC (rev 10051)
+++ code/branches/modularships/src/orxonox/OrxonoxPrereqs.h 2014-05-08 14:20:26 UTC (rev 10052)
@@ -142,6 +142,7 @@
// items
class ShipPart;
+ class PartDestructionEvent;
class Engine;
class Item;
class MultiStateEngine;
Modified: code/branches/modularships/src/orxonox/items/CMakeLists.txt
===================================================================
--- code/branches/modularships/src/orxonox/items/CMakeLists.txt 2014-05-08 14:16:59 UTC (rev 10051)
+++ code/branches/modularships/src/orxonox/items/CMakeLists.txt 2014-05-08 14:20:26 UTC (rev 10052)
@@ -3,4 +3,5 @@
Engine.cc
MultiStateEngine.cc
ShipPart.cc
+ PartDestructionEvent.cc
)
Added: code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc
===================================================================
--- code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc (rev 0)
+++ code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc 2014-05-08 14:20:26 UTC (rev 10052)
@@ -0,0 +1,152 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Noe Pedrazzini
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "PartDestructionEvent.h"
+
+#include <algorithm>
+
+#include "core/CoreIncludes.h"
+#include "core/GameMode.h"
+#include "core/XMLPort.h"
+#include "network/NetworkFunction.h"
+#include "Item.h"
+#include "worldentities/pawns/Pawn.h"
+#include "worldentities/pawns/ModularSpaceShip.h"
+#include "gametypes/Gametype.h"
+
+
+namespace orxonox
+{
+ RegisterClass(PartDestructionEvent);
+
+ PartDestructionEvent::PartDestructionEvent(Context* context)
+ : Item(context)
+ {
+ RegisterObject(PartDestructionEvent);
+ this->isValid_ = false;
+ }
+
+ PartDestructionEvent::~PartDestructionEvent()
+ {
+
+ }
+
+ void PartDestructionEvent::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(PartDestructionEvent, XMLPort, xmlelement, mode);
+
+ XMLPortParam(PartDestructionEvent, "targetType", setTargetType, getTargetType, xmlelement, mode).defaultValues("NULL");
+ XMLPortParam(PartDestructionEvent, "targetName", setTargetName, getTargetName, xmlelement, mode).defaultValues("NULL");
+ XMLPortParam(PartDestructionEvent, "targetParam", setTargetParam, getTargetParam, xmlelement, mode).defaultValues("NULL");
+ XMLPortParam(PartDestructionEvent, "operation", setOperation, getOperation, xmlelement, mode).defaultValues("NULL");
+ XMLPortParam(PartDestructionEvent, "value", setEventValue, getEventValue, xmlelement, mode).defaultValues(0);
+
+ /*
+ XMLPortParam(PartDestructionEvent, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
+ XMLPortParam(PartDestructionEvent, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
+ XMLPortParam(PartDestructionEvent, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
+ */
+ }
+
+ void PartDestructionEvent::execute()
+ {
+ if(!this->isValid_)
+ {
+ //orxout(internal_warning) <<
+ return;
+ }
+
+
+ }
+
+ void PartDestructionEvent::setTargetType(std::string type)
+ {
+ // ship engine weapon
+ if ((type == "ship") || (type == "engine") || (type == "weapon"))
+ {
+ 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;
+ this->isValid_ = false;
+ return;
+ }
+
+ void PartDestructionEvent::setTargetName(std::string name)
+ {
+ // Error, if the target-type is "weapon" or "engine", but the name of said target was not defined.
+ if (((this->targetType_ == "weapon") || (this->targetType_ == "engine")) && (name == "NULL"))
+ {
+ orxout(internal_warning) << "The target-name of a PartDestructionEvent with target-type \"" << this->targetType_ << "\" needs to be defined!" << endl;
+ return;
+ }
+
+ this->targetName_ = name;
+ }
+
+ void PartDestructionEvent::setTargetParam(std::string param)
+ {
+ if (this->targetType_ == "NULL")
+ {
+ orxout(internal_warning) << "No valid target-type defined. Cannot set target-param for this PartDestructionEvent." << endl;
+ this->isValid_ = false;
+ return;
+ }
+
+ // ship: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate
+
+ // engine:
+
+ // weapon:
+
+ if (this->targetType_ == "ship")
+ {
+ if (param == "shieldhealth")
+ {
+ this->targetParam_ = param;
+ 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" << endl;
+ return;
+ }
+ }
+
+ void PartDestructionEvent::setOperation(std::string operation)
+ {
+ // * + - destroy
+ this->operation_ = operation;
+ }
+
+ void PartDestructionEvent::setEventValue(float value)
+ {
+ this->value_ = value;
+ }
+}
Added: code/branches/modularships/src/orxonox/items/PartDestructionEvent.h
===================================================================
--- code/branches/modularships/src/orxonox/items/PartDestructionEvent.h (rev 0)
+++ code/branches/modularships/src/orxonox/items/PartDestructionEvent.h 2014-05-08 14:20:26 UTC (rev 10052)
@@ -0,0 +1,90 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Noe Pedrazzini
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _PartDestructionEvent_H__
+#define _PartDestructionEvent_H__
+
+#include "OrxonoxPrereqs.h"
+#include "Item.h"
+
+#include <string>
+
+
+namespace orxonox // tolua_export
+{ // tolua_export
+ class _OrxonoxExport PartDestructionEvent // tolua_export
+ : public Item
+ { // tolua_export
+
+ public:
+
+ PartDestructionEvent(Context* context);
+ virtual ~PartDestructionEvent();
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+ void execute();
+
+ void setTargetType(std::string type);
+ inline std::string getTargetType()
+ { return this->targetType_; }
+
+ void setTargetName(std::string name);
+ inline std::string getTargetName()
+ { return this->targetName_; }
+
+ void setTargetParam(std::string param);
+ inline std::string getTargetParam()
+ { return this->targetName_; }
+
+ void setOperation(std::string operation);
+ inline std::string getOperation()
+ { return this->operation_; }
+
+ void setEventValue(float value);
+ inline float getEventValue()
+ { return this->value_; }
+
+ protected:
+
+ private:
+
+ bool isValid_;
+
+ std::string targetType_;
+ std::string targetName_;
+ std::string targetParam_;
+ std::string operation_;
+
+ float value_;
+
+
+ }; // tolua_export
+} // tolua_export
+
+#endif /* _PartDestructionEvent_H__ */
Modified: code/branches/modularships/src/orxonox/items/ShipPart.cc
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.cc 2014-05-08 14:16:59 UTC (rev 10051)
+++ code/branches/modularships/src/orxonox/items/ShipPart.cc 2014-05-08 14:20:26 UTC (rev 10052)
@@ -39,6 +39,7 @@
#include "worldentities/pawns/ModularSpaceShip.h"
#include "gametypes/Gametype.h"
#include "worldentities/StaticEntity.h"
+#include "items/PartDestructionEvent.h"
namespace orxonox
@@ -66,6 +67,8 @@
XMLPortParam(ShipPart, "damageabsorption", setDamageAbsorption, getDamageAbsorption, xmlelement, mode).defaultValues(0.5);
+ XMLPortObject(ShipPart, PartDestructionEvent, "destructionevents", addDestructionEvent, getDestructionEvent, xmlelement, mode);
+
/*
XMLPortParam(ShipPart, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
XMLPortParam(ShipPart, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);
@@ -143,6 +146,33 @@
}
}
+ /**
+ @brief
+ Add a PartDestructionEvent to the ShipPart.
+ @param engine
+ A pointer to the PartDestructionEvent to be added.
+ */
+ void ShipPart::addDestructionEvent(PartDestructionEvent* part)
+ {
+ OrxAssert(part != NULL, "The PartDestructionEvent cannot be NULL.");
+ this->eventList_.push_back(part);
+ //part->setParent(this);
+ }
+
+ /**
+ @brief
+ Get the i-th PartDestructionEvent of the ShipPart.
+ @return
+ Returns a pointer to the i-the PartDestructionEvent. NULL if there is no PartDestructionEvent with that index.
+ */
+ PartDestructionEvent* ShipPart::getDestructionEvent(unsigned int index)
+ {
+ if(this->eventList_.size() >= index)
+ return NULL;
+ else
+ return this->eventList_[index];
+ }
+
void ShipPart::setDamageAbsorption(float value)
{
this->damageAbsorption_ = value;
Modified: code/branches/modularships/src/orxonox/items/ShipPart.h
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.h 2014-05-08 14:16:59 UTC (rev 10051)
+++ code/branches/modularships/src/orxonox/items/ShipPart.h 2014-05-08 14:20:26 UTC (rev 10052)
@@ -31,6 +31,7 @@
#include "OrxonoxPrereqs.h"
#include "Item.h"
+#include "items/PartDestructionEvent.h"
#include <string>
@@ -58,6 +59,9 @@
StaticEntity* getEntity(unsigned int index);
bool hasEntity(StaticEntity* entity) const;
+ void addDestructionEvent(PartDestructionEvent* event);
+ PartDestructionEvent* getDestructionEvent(unsigned int index);
+
void printEntities(); // FIXME: (noep) remove debug
virtual void setDamageAbsorption(float value);
@@ -101,7 +105,9 @@
private:
std::vector<StaticEntity*> entityList_; // list of all entities which belong to this part
+ std::vector<PartDestructionEvent*> eventList_; // The list of all PartDestructionEvent assigned to this ShipPart.
+
}; // tolua_export
} // tolua_export
Modified: code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc 2014-05-08 14:16:59 UTC (rev 10051)
+++ code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc 2014-05-08 14:20:26 UTC (rev 10052)
@@ -118,6 +118,7 @@
*/
WorldEntity::~WorldEntity()
{
+ orxout() << "destroying " << this->getIdentifier()->getName() << endl;
if (this->isInitialized())
{
if (this->parent_)
Modified: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc 2014-05-08 14:16:59 UTC (rev 10051)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc 2014-05-08 14:20:26 UTC (rev 10052)
@@ -302,7 +302,7 @@
it++;
}
// Remove the part-entity assignment and detach the Entity of this ShipPart
- for (std::map<StaticEntity*, ShipPart*>::iterator itt = this->partMap_.begin(); itt != this->partMap_.end(); ++itt)
+ for (std::map<StaticEntity*, ShipPart*>::iterator itt = this->partMap_.begin(); itt != this->partMap_.end(); )
{
if (itt->second == part)
{
@@ -313,7 +313,9 @@
//itt->first->setCollisionResponse(false);
//itt->first->setCollisionType(None);
//itt->first->deactivatePhysics();
- this->partMap_.erase(itt);
+ this->partMap_.erase(itt++);
+ } else {
+ ++itt;
}
}
}
More information about the Orxonox-commit
mailing list