[Orxonox-commit 5392] r10055 - in code/branches/modularships: data/levels data/levels/templates src/orxonox/items src/orxonox/worldentities/pawns
noep at orxonox.net
noep at orxonox.net
Wed May 14 20:25:09 CEST 2014
Author: noep
Date: 2014-05-14 20:25:08 +0200 (Wed, 14 May 2014)
New Revision: 10055
Modified:
code/branches/modularships/data/levels/ModularShipsTest1.oxw
code/branches/modularships/data/levels/templates/HeavyCruiser.oxt
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/pawns/ModularSpaceShip.cc
code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h
Log:
Cleaned up code. Added console command "ModularSpaceShip killshippart [string]" which allows manual destruction of a ShipPart by name. Added more functionality to PartDestructionEvents.
Modified: code/branches/modularships/data/levels/ModularShipsTest1.oxw
===================================================================
--- code/branches/modularships/data/levels/ModularShipsTest1.oxw 2014-05-13 10:38:37 UTC (rev 10054)
+++ code/branches/modularships/data/levels/ModularShipsTest1.oxw 2014-05-14 18:25:08 UTC (rev 10055)
@@ -30,7 +30,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="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort />
+ <!-- <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort /> -->
+ <SpawnPoint team=0 position="-500,0,0" lookat="0,0,0" spawnclass=ModularSpaceShip pawndesign=HeavyCruiser />
<MovableEntity position="0,0,0" collisionType=dynamic scale=1 linearDamping=0.8 angularDamping=0 collisiondamage=0.005 enablecollisiondamage=true>
<attached>
Modified: code/branches/modularships/data/levels/templates/HeavyCruiser.oxt
===================================================================
--- code/branches/modularships/data/levels/templates/HeavyCruiser.oxt 2014-05-13 10:38:37 UTC (rev 10054)
+++ code/branches/modularships/data/levels/templates/HeavyCruiser.oxt 2014-05-14 18:25:08 UTC (rev 10055)
@@ -60,9 +60,21 @@
<PartDestructionEvent targetType="ship" targetParam="shieldhealth" operation="*" value="0.5"/>
</destructionevents>
</ShipPart>
- <ShipPart name="partL" initialhealth="10" damageabsorption="0.5" />
- <ShipPart name="partR" initialhealth="10" damageabsorption="0.5" />
- <ShipPart name="sidearmL" initialhealth="20" damageabsorption="0.2" />
+ <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>
+ </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!"/>
+ </destructionevents>
+ </ShipPart>
+ <ShipPart name="sidearmL" initialhealth="20" damageabsorption="0.2">
+ <destructionevents>
+ <!-- <PartDestructionEvent targetType="engine" targetName="HeavyCruiser_sidearmL_engine1" operation="destroy"/> -->
+ </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" />
Modified: code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc
===================================================================
--- code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc 2014-05-13 10:38:37 UTC (rev 10054)
+++ code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc 2014-05-14 18:25:08 UTC (rev 10055)
@@ -37,7 +37,9 @@
#include "Item.h"
#include "worldentities/pawns/Pawn.h"
#include "worldentities/pawns/ModularSpaceShip.h"
+#include "items/Engine.h"
#include "gametypes/Gametype.h"
+#include "chat/ChatManager.h"
namespace orxonox
@@ -62,9 +64,10 @@
XMLPortParam(PartDestructionEvent, "targetType", setTargetType, getTargetType, xmlelement, mode).defaultValues("NULL");
XMLPortParam(PartDestructionEvent, "targetName", setTargetName, getTargetName, xmlelement, mode).defaultValues("NULL");
+ XMLPortParam(PartDestructionEvent, "operation", setOperation, getOperation, 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, "message", setMessage, getMessage, xmlelement, mode).defaultValues("NULL");
/*
XMLPortParam(PartDestructionEvent, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
@@ -73,8 +76,14 @@
*/
}
+ /**
+ @brief
+ Executes this event.
+ */
void PartDestructionEvent::execute()
{
+ orxout() << "Executing PartDestructionEvent " << this->getName() << endl;
+
// Do not execute if this event is invalid
if(!isValid())
{
@@ -82,18 +91,58 @@
return;
}
+ // Output the destruction-message to the chat
+ if(this->message_ != "NULL")
+ ChatManager::message(this->message_);
+
+ // Modify parameters as configured for all cases
if (this->targetType_ == "ship")
{
switch (this->targetParam_) {
case shieldhealth:
this->parent_->getParent()->setShieldHealth(operate(this->parent_->getParent()->getShieldHealth()));
break;
+ case boostpower:
+ this->parent_->getParent()->setInitialBoostPower(operate(this->parent_->getParent()->getInitialBoostPower()));
+ break;
+ case boostpowerrate:
+ this->parent_->getParent()->setBoostPowerRate(operate(this->parent_->getParent()->getBoostPowerRate()));
+ break;
default:
break;
}
this->setValid(false);
return;
}
+
+ if (this->targetType_ == "engine")
+ {
+ 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;
+ }
+ }
+ 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;
+ }
+ break;
+ default:
+ break;
+ }
+ this->setValid(false);
+ return;
+ }
}
void PartDestructionEvent::setParent(ShipPart* part)
@@ -101,9 +150,14 @@
this->parent_ = part;
}
+ /**
+ @brief
+ Set type of the target
+ @param param
+ The desired target-type as string. Valid target-types: ship engine weapon
+ */
void PartDestructionEvent::setTargetType(std::string type)
{
- // ship engine weapon
if ((type == "ship") || (type == "engine") || (type == "weapon"))
{
this->targetType_ = type;
@@ -128,8 +182,15 @@
this->targetName_ = name;
}
+ /**
+ @brief
+ Set the operation to be applied.
+ @param param
+ The desired parameter as string. Valid parameters: c.f. @ref orxnox::PartDestructionEvent::TargetParam
+ */
void PartDestructionEvent::setTargetParam(std::string param)
{
+ // A target-type needs to be defined in order to choose a parameter.
if (this->targetType_ == "NULL")
{
orxout(internal_warning) << "No valid target-type defined. Cannot set target-param for this PartDestructionEvent." << endl;
@@ -137,12 +198,37 @@
return;
}
- // ship: shieldhealth maxshieldhealth shieldabsorption shieldrechargerate
+ // engine: NULL boostfactor speedfront accelerationfront
+ if (this->targetType_ == "engine")
+ {
+ if (param == "NULL")
+ {
+ this->targetParam_ = null;
+ return;
+ }
+ if (param == "boostfactor")
+ {
+ this->targetParam_ = boostfactor;
+ return;
+ }
+ if (param == "speedfront")
+ {
+ this->targetParam_ = speedfront;
+ return;
+ }
+ if (param == "accelerationfront")
+ {
+ this->targetParam_ = accelerationfront;
+ return;
+ }
- // engine:
+ orxout(internal_warning) << "\"" << param << "\" is not a valid target-param for a PartDestructionEvent with target-type \"engine\". Valid types are: boostfactor speedfront accelerationfront" << endl;
+ return;
+ }
// weapon:
+ // ship: shieldhealth (maxshieldhealth shieldabsorption shieldrechargerate) boostpower boostpowerrate
if (this->targetType_ == "ship")
{
if (param == "shieldhealth")
@@ -150,8 +236,18 @@
this->targetParam_ = shieldhealth;
return;
}
+ if (param == "boostpower")
+ {
+ this->targetParam_ = boostpower;
+ return;
+ }
+ if (param == "boostpowerrate")
+ {
+ this->targetParam_ = boostpowerrate;
+ 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;
+ 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;
return;
}
@@ -159,6 +255,12 @@
this->setValid(false);
}
+ /**
+ @brief
+ Set the operation to be applied.
+ @param operation
+ The desired operator as string. Valid operators: * + - destroy
+ */
void PartDestructionEvent::setOperation(std::string operation)
{
// * + - destroy
@@ -171,6 +273,26 @@
orxout(internal_warning) << "\"" << operation << "\" is not a valid operation for a PartDestructionEvent. Valid operations are: * + - destroy" << endl;
}
+ /**
+ @brief
+ Set the message to be shown upon execution of the vent.
+ @param msg
+ The desired message as string.
+ */
+ void PartDestructionEvent::setMessage(std::string msg)
+ {
+ this->message_ = msg;
+ }
+
+
+ /**
+ @brief
+ Apply the configured operation and value to an input.
+ @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"
+ */
float PartDestructionEvent::operate(float input)
{
if (this->operation_ == "*")
@@ -186,6 +308,12 @@
return 0;
}
+ /**
+ @brief
+ Sets the value applied with the chosen operation.
+ @param value
+ The value as float.
+ */
void PartDestructionEvent::setEventValue(float value)
{
this->value_ = value;
Modified: code/branches/modularships/src/orxonox/items/PartDestructionEvent.h
===================================================================
--- code/branches/modularships/src/orxonox/items/PartDestructionEvent.h 2014-05-13 10:38:37 UTC (rev 10054)
+++ code/branches/modularships/src/orxonox/items/PartDestructionEvent.h 2014-05-14 18:25:08 UTC (rev 10055)
@@ -37,18 +37,61 @@
namespace orxonox // tolua_export
{ // tolua_export
+ /**
+ @brief
+ In order to assign attached entities to a ShipPart, a ShipPart with the same name as the corresponding entity needs to be created in the <parts> tag.
+ Here is a (primitive) example of a ModularSpaceShip with ShipParts and PartDestructionEvents defined in XML:
+ @code
+ <ModularSpaceShip
+ ...
+ >
+ <attached>
+ <StaticEntity name="generator" . . . />
+ <StaticEntity name="tail" . . . />
+ </attached>
+ <parts>
+ <ShipPart name="generator" . . . >
+ <destructionevents>
+ <PartDestructionEvent targetType="ship" targetParam="boostpowerrate" operation="-" value="0.5" message="Your boost-regeneration is reduced!" />
+ </destructionevents>
+ </ShipPart>
+ <ShipPart name="tail" . . . >
+ <destructionevents>
+ <PartDestructionEvent ... />
+ </destructionevents>
+ </ShipPart>
+ </parts>
+ <engines>
+ <Engine />
+ <Engine />
+ </engines>
+ </ModularSpaceShip>
+ @endcode
+
+ @author
+ Fabian 'x3n' Landau, Noe Pedrazzini
+ */
class _OrxonoxExport PartDestructionEvent // tolua_export
: public Item
{ // tolua_export
public:
+ /**
+ @brief
+ List of all allowed parameters.
+ */
enum TargetParam
{
shieldhealth,
maxshieldhealth,
shieldabsorption,
shieldrechargerate,
+ boostpower, // Amount of available boost
+ boostpowerrate, // Recharge-rate of boost
+ boostfactor,
+ speedfront,
+ accelerationfront,
null
};
@@ -84,6 +127,10 @@
inline std::string getOperation()
{ return this->operation_; }
+ void setMessage(std::string msg);
+ inline std::string getMessage()
+ { return this->message_; }
+
float operate(float input);
void setEventValue(float value);
@@ -94,15 +141,16 @@
private:
- ShipPart* parent_;
- bool valid_;
+ ShipPart* parent_; //!< Pointer to the ShipPart this event belongs to
+ bool valid_; //!< Whether this event is valid or not.
- std::string targetType_;
- std::string targetName_;
- TargetParam targetParam_;
- std::string operation_;
+ std::string targetType_; //!< The type of the target. (ship weapon engine)
+ std::string targetName_; //!< The name of the target.
+ TargetParam targetParam_; //!< The parameter to be modified
+ std::string operation_; //!< The operation to be applied
+ float value_; //!< The value used to do the operation
+ std::string message_; //!< The message which is shown in chat when the event is executed.
- float value_;
}; // tolua_export
Modified: code/branches/modularships/src/orxonox/items/ShipPart.cc
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.cc 2014-05-13 10:38:37 UTC (rev 10054)
+++ code/branches/modularships/src/orxonox/items/ShipPart.cc 2014-05-14 18:25:08 UTC (rev 10055)
@@ -89,6 +89,12 @@
*/
}
+ /**
+ @brief
+ Is called when the ShipPart dies.
+ Executes PartDestructionEvents.
+ Tells the ModularSpaceShip to remove this ShipPart.
+ */
void ShipPart::death()
{
if (!(this->isAlive()))
Modified: code/branches/modularships/src/orxonox/items/ShipPart.h
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.h 2014-05-13 10:38:37 UTC (rev 10054)
+++ code/branches/modularships/src/orxonox/items/ShipPart.h 2014-05-14 18:25:08 UTC (rev 10055)
@@ -101,7 +101,7 @@
protected:
ModularSpaceShip* parent_;
- unsigned int parentID_; // Object ID of the SpaceShip the Part is mounted on.
+ unsigned int parentID_; // Object ID of the SpaceShip the Part is mounted on.
float damageAbsorption_;
float health_;
@@ -109,7 +109,7 @@
float initialHealth_;
private:
- std::vector<StaticEntity*> entityList_; // list of all entities which belong to this part
+ 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.
bool alive_;
Modified: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc 2014-05-13 10:38:37 UTC (rev 10054)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc 2014-05-14 18:25:08 UTC (rev 10055)
@@ -36,6 +36,7 @@
#include "core/XMLPort.h"
#include "util/Math.h"
#include "gametypes/Gametype.h"
+#include "core/command/ConsoleCommand.h"
#include "items/ShipPart.h"
#include "worldentities/StaticEntity.h"
@@ -47,14 +48,20 @@
namespace orxonox
{
+ SetConsoleCommand("ModularSpaceShip", "killshippart", &ModularSpaceShip::killShipPart);
+
RegisterClass(ModularSpaceShip);
+ std::map<StaticEntity*, ShipPart*>* ModularSpaceShip::partMap_s = 0;
+
ModularSpaceShip::ModularSpaceShip(Context* context) : SpaceShip(context)
{
RegisterObject(ModularSpaceShip);
this->registerVariables();
+ ModularSpaceShip::partMap_s = &(this->partMap_);
+
}
ModularSpaceShip::~ModularSpaceShip()
@@ -76,6 +83,10 @@
return;
}
+ /**
+ @brief
+ Searches for ShipParts matching to StaticEntities.
+ */
void ModularSpaceShip::updatePartAssignment()
{
// iterate through all attached objects
@@ -114,6 +125,14 @@
this->updatePartAssignment();
}
+ /**
+ @brief
+ Creates a new assignment for the given StaticEntity and ShipPart in the partMap_
+ @param entity
+ A pointer to the StaticEntity
+ @param part
+ A pointer to the ShipPart.
+ */
void ModularSpaceShip::addPartEntityAssignment(StaticEntity* entity, ShipPart* part)
{
if (!entity || !part)
@@ -149,71 +168,35 @@
return NULL;
}
- //FIXME: (noep) finish
- // void ModularSpaceShip::attach
-
+ /**
+ @brief
+ If the damage occurred on an attached StaticEntity, the damage is given to the corresponding ShipPart to handle.
+ */
void ModularSpaceShip::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
{
- /*orxout() << "Mdamage(): Collision detected on " << this->getRadarName() << ", btCS*: " << cs << endl;
- orxout() << "UserPtr of said collisionShape: " << cs->getUserPointer() << endl;
-
-
- // Print all attached objects & parts
- /*
- orxout() << " " << this->getName() << " has the following Objects attached:" << endl;
-
- for (int i=0; i<50; i++)
- {
- if (this->getAttachedObject(i)==NULL)
- break;
- orxout() << " " << i << ": " << this->getAttachedObject(i) << " (" << this->getAttachedObject(i)->getName() << ")";
- orxout() << endl;
- }
-
- orxout() << " Attached ShipParts:" << endl;
- for(unsigned int i=0; i < this->partList_.size(); i++)
- {
- orxout() << " " << i << ": " << this->partList_[i] << " (" << this->partList_[i]->getName() << ")" << endl;
- }*/
-
-
- //int collisionShapeIndex = this->isMyCollisionShape(cs);
- //orxout() << collisionShapeIndex << endl;
-
- //orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
-
if (this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != NULL)
this->getPartOfEntity((StaticEntity*)(cs->getUserPointer()))->handleHit(damage, healthdamage, shielddamage, originator);
else
SpaceShip::damage(damage, healthdamage, shielddamage, originator, cs);
+ }
- /*
- // Applies multiplier given by the DamageBoost Pickup.
- if (originator)
- damage *= originator->getDamageMultiplier();
-
- if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator))
+ /**
+ @brief
+ Kills the ShipPart with the given name. Used from the console-command "ModularSpaceShip killshippart [string]".
+ @param name
+ The name of the part to be killed.
+ */
+ void ModularSpaceShip::killShipPart(std::string name)
+ {
+ for (std::map<StaticEntity*, ShipPart*>::const_iterator it = ModularSpaceShip::partMap_s->begin(); it != ModularSpaceShip::partMap_s->end(); ++it)
{
- if (shielddamage >= this->getShieldHealth())
+ if (it->second->getName() == name)
{
- this->setShieldHealth(0);
- this->setHealth(this->health_ - (healthdamage + damage));
+ it->second->death();
+ return;
}
- else
- {
- this->setShieldHealth(this->shieldHealth_ - shielddamage);
-
- // remove remaining shieldAbsorpton-Part of damage from shield
- shielddamage = damage * this->shieldAbsorption_;
- shielddamage = std::min(this->getShieldHealth(),shielddamage);
- this->setShieldHealth(this->shieldHealth_ - shielddamage);
-
- // set remaining damage to health
- this->setHealth(this->health_ - (damage - shielddamage) - healthdamage);
- }
-
- this->lastHitOriginator_ = originator;
- }*/
+ }
+ orxout(internal_warning) << "Could not apply damage to ShipPart \"" << name << "\". Part not found." << endl;
}
/**
@@ -260,6 +243,13 @@
return false;
}
+
+ /**
+ @brief
+ Removes a ShipPart from the SpaceShip, destroying the corresponding StaticEntity
+ @param part
+ The ShipPart to be removed.
+ */
void ModularSpaceShip::removeShipPart(ShipPart* part)
{
// Remove the part from the partList_
@@ -308,7 +298,7 @@
// collision shapes
orxout() << "MSS: detach()" << endl;
- this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
+ //this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
this->detachCollisionShape(object->collisionShape_); // after succeeding, causes a crash in the collision handling
//this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);
Modified: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h 2014-05-13 10:38:37 UTC (rev 10054)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h 2014-05-14 18:25:08 UTC (rev 10055)
@@ -112,6 +112,8 @@
virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL, const btCollisionShape* cs = NULL);
+ static void killShipPart(std::string name);
+
void addShipPart(ShipPart* part);
ShipPart* getShipPart(unsigned int index);
bool hasShipPart(ShipPart* part) const;
@@ -126,10 +128,9 @@
private:
void registerVariables();
- std::vector<ShipPart*> partList_; // The list of all Parts mounted on this ModularSpaceShip.
- std::vector<SmartPtr<StaticEntity>*> entityPtrList_;
- std::vector<SmartPtr<CollisionShape>*> csPtrList_;
- std::map<StaticEntity*, ShipPart*> partMap_;
+ std::vector<ShipPart*> partList_; // The list of all Parts mounted on this ModularSpaceShip.
+ std::map<StaticEntity*, ShipPart*> partMap_; // Map of Part-Entity-assignments
+ static std::map<StaticEntity*, ShipPart*>* partMap_s;
};
}
More information about the Orxonox-commit
mailing list