[Orxonox-commit 5360] r10023 - in code/branches/modularships: data/levels data/levels/templates src/orxonox src/orxonox/items src/orxonox/worldentities/pawns
noep at orxonox.net
noep at orxonox.net
Wed Apr 9 21:50:46 CEST 2014
Author: noep
Date: 2014-04-09 21:50:45 +0200 (Wed, 09 Apr 2014)
New Revision: 10023
Modified:
code/branches/modularships/data/levels/emptyLevel.oxw
code/branches/modularships/data/levels/templates/HeavyCruiser.oxt
code/branches/modularships/src/orxonox/OrxonoxPrereqs.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
code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc
code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h
Log:
ShipParts can "die" and detach the corresponding Entity while doing so. Issue: The Entity being detached while a hit on a collisionshape is being handled causes a runtime-error.
Modified: code/branches/modularships/data/levels/emptyLevel.oxw
===================================================================
--- code/branches/modularships/data/levels/emptyLevel.oxw 2014-04-03 14:05:52 UTC (rev 10022)
+++ code/branches/modularships/data/levels/emptyLevel.oxw 2014-04-09 19:50:45 UTC (rev 10023)
@@ -97,7 +97,7 @@
</templates>
</ModularSpaceShip>
- <ModularSpaceShip position="0,-1000,-200">
+ <ModularSpaceShip position="0,-1000,-200" health="1000" maxhealth="2000" initialhealth="1000">
<templates>
<Template link=HeavyCruiser />
</templates>
Modified: code/branches/modularships/data/levels/templates/HeavyCruiser.oxt
===================================================================
--- code/branches/modularships/data/levels/templates/HeavyCruiser.oxt 2014-04-03 14:05:52 UTC (rev 10022)
+++ code/branches/modularships/data/levels/templates/HeavyCruiser.oxt 2014-04-09 19:50:45 UTC (rev 10023)
@@ -10,9 +10,9 @@
spawnparticleduration = 3
explosionchunks = 6
- health = 100
- maxhealth = 200
- initialhealth = 100
+ health = 1000
+ maxhealth = 2000
+ initialhealth = 1000
shieldhealth = 100
initialshieldhealth = 30
@@ -50,8 +50,14 @@
</engines>
<parts>
- <ShipPart name="frontL" />
- <ShipPart name="frontR" />
+ <ShipPart name="frontL" health="100" damageabsorption="0.5" />
+ <ShipPart name="frontR" health="100" damageabsorption="0.5" />
+ <ShipPart name="partL" health="100" damageabsorption="0.5" />
+ <ShipPart name="partR" health="100" damageabsorption="0.5" />
+ <ShipPart name="sidearmL" health="201" damageabsorption="0.2" />
+ <ShipPart name="sidearmLfront" health="100" damageabsorption="0.5" />
+ <ShipPart name="sidearmR" health="200" damageabsorption="0.2" />
+ <ShipPart name="sidearmRfront" health="100" damageabsorption="0.5" />
</parts>
<attached>
@@ -60,6 +66,9 @@
<StaticEntity name="frontL" position="0,0,0" direction="0,0,0" collisionType=static mass=100 friction=0.01 >
<attached>
<Model mesh="HeavyCruiser_frontL.mesh" direction="-1,0,0" position="0,0,0" scale="40"/>
+ <BlinkingBillboard position="-75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
+ <BlinkingBillboard position="-74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
+ <BlinkingBillboard position="-73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
</attached>
<collisionShapes>
<BoxCollisionShape position="-80,33,-320" halfExtents="7,11,54" info="frontL"/>
@@ -70,6 +79,9 @@
<StaticEntity name="frontR" position="0,0,0" direction="0,0,0" collisionType=static mass=100 friction=0.01 >
<attached>
<Model mesh="HeavyCruiser_frontR.mesh" direction="-1,0,0" position="0,0,0" scale="40"/>
+ <BlinkingBillboard position="75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
+ <BlinkingBillboard position="74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
+ <BlinkingBillboard position="73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
</attached>
<collisionShapes>
<BoxCollisionShape position="80,33,-320" halfExtents="7,11,54" info="frontR"/>
@@ -175,13 +187,6 @@
</collisionShapes>
</StaticEntity>
- <!-- bay1 lights -->
- <BlinkingBillboard position="75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
- <BlinkingBillboard position="-75,30,-416" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.05 frequency=0.3 phase=240 quadratic=1 />
- <BlinkingBillboard position="74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
- <BlinkingBillboard position="-74,30,-402" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.1 frequency=0.3 phase=120 quadratic=1 />
- <BlinkingBillboard position="73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
- <BlinkingBillboard position="-73,30,-388" material="Examples/Flare" colour="0.8, 0.8, 0, 0.1" amplitude=0.15 frequency=0.3 phase=0 quadratic=1 />
<!-- front position lights -->
<BlinkingBillboard position="67,-5,-240" material="Examples/Flare" colour="0, 0.7, 0, 0.1" amplitude=0.3 frequency=0.15 phase=0 quadratic=1 />
<BlinkingBillboard position="-67,-5,-240" material="Examples/Flare" colour="0.7, 0, 0, 0.1" amplitude=0.3 frequency=0.15 phase=360 quadratic=1 />
Modified: code/branches/modularships/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- code/branches/modularships/src/orxonox/OrxonoxPrereqs.h 2014-04-03 14:05:52 UTC (rev 10022)
+++ code/branches/modularships/src/orxonox/OrxonoxPrereqs.h 2014-04-09 19:50:45 UTC (rev 10023)
@@ -141,6 +141,7 @@
class TeamColourable;
// items
+ class ShipPart;
class Engine;
class Item;
class MultiStateEngine;
@@ -188,6 +189,7 @@
class Destroyer;
class Pawn;
class SpaceShip;
+ class ModularSpaceShip;
class Spectator;
class TeamBaseMatchBase;
}
Modified: code/branches/modularships/src/orxonox/items/ShipPart.cc
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.cc 2014-04-03 14:05:52 UTC (rev 10022)
+++ code/branches/modularships/src/orxonox/items/ShipPart.cc 2014-04-09 19:50:45 UTC (rev 10023)
@@ -36,6 +36,7 @@
#include "network/NetworkFunction.h"
#include "Item.h"
#include "worldentities/pawns/Pawn.h"
+#include "worldentities/pawns/ModularSpaceShip.h"
#include "gametypes/Gametype.h"
#include "worldentities/StaticEntity.h"
@@ -55,7 +56,40 @@
}
+ void ShipPart::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(ShipPart, XMLPort, xmlelement, mode);
+ XMLPortParam(ShipPart, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
+ XMLPortParam(ShipPart, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
+ XMLPortParam(ShipPart, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
+
+ XMLPortParam(ShipPart, "damageabsorption", setDamageAbsorption, getDamageAbsorption, xmlelement, mode).defaultValues(0.5);
+
+ /*
+ XMLPortParam(ShipPart, "shieldhealth", setShieldHealth, getShieldHealth, xmlelement, mode).defaultValues(0);
+ XMLPortParam(ShipPart, "initialshieldhealth", setInitialShieldHealth, getInitialShieldHealth, xmlelement, mode).defaultValues(0);
+ XMLPortParam(ShipPart, "maxshieldhealth", setMaxShieldHealth, getMaxShieldHealth, xmlelement, mode).defaultValues(100);
+ XMLPortParam(ShipPart, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0);
+
+ XMLPortParam(ShipPart, "sShipPartparticlesource", setSShipPartParticleSource, getSShipPartParticleSource, xmlelement, mode);
+ XMLPortParam(ShipPart, "sShipPartparticleduration", setSShipPartParticleDuration, getSShipPartParticleDuration, xmlelement, mode).defaultValues(3.0f);
+ XMLPortParam(ShipPart, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
+
+ XMLPortParam(ShipPart, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0);
+ XMLPortParam(ShipPart, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f);
+
+ XMLPortParam(ShipPart, "explosionSound", setExplosionSound, getExplosionSound, xmlelement, mode);
+
+ XMLPortParam ( RadarViewable, "radarname", setRadarName, getRadarName, xmlelement, mode );
+ */
+ }
+
+ void ShipPart::death()
+ {
+ this->parent_->removeShipPart(this);
+ }
+
/**
@brief
Add a StaticEntity to the ShipPart.
@@ -113,6 +147,11 @@
this->damageAbsorption_ = value;
}
+ void ShipPart::setParent(ModularSpaceShip* ship)
+ {
+ this->parent_ = ship;
+ }
+
/**
@brief
Sets the health of the ShipPart.
@@ -151,6 +190,9 @@
parent_->setHealth(parent_->getHealth() - ((damage - shielddamage) - healthdamage) * (1- this->damageAbsorption_));
}
}
+ if (this->health_ < 0)
+ this->death();
+ orxout() << "Health of ShipPart " << this->getName() << " is " << this->getHealth() << endl;
}
Modified: code/branches/modularships/src/orxonox/items/ShipPart.h
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.h 2014-04-03 14:05:52 UTC (rev 10022)
+++ code/branches/modularships/src/orxonox/items/ShipPart.h 2014-04-09 19:50:45 UTC (rev 10023)
@@ -45,10 +45,12 @@
ShipPart(Context* context);
virtual ~ShipPart();
- //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
virtual void handleHit(float damage, float healthdamage, float shielddamage, Pawn* originator);
+ virtual void death();
+
//virtual void attachTo(Pawn* newParent);
//virtual void detach();
@@ -62,6 +64,10 @@
inline float getDamageAbsorption()
{ return this->damageAbsorption_; }
+ void setParent(ModularSpaceShip* ship);
+ inline ModularSpaceShip* getParent()
+ { return this->parent_; }
+
virtual void setHealth(float health);
inline void addHealth(float health)
{ this->setHealth(this->health_ + health); }
@@ -70,16 +76,28 @@
inline float getHealth() const
{ return this->health_; }
+ inline void setMaxHealth(float maxhealth)
+ { this->maxHealth_ = maxhealth; this->setHealth(this->health_); }
+ inline float getMaxHealth() const
+ { return this->maxHealth_; }
+ inline void setInitialHealth(float initialhealth)
+ { this->initialHealth_ = initialhealth; this->setHealth(initialhealth); }
+ inline float getInitialHealth() const
+ { return this->initialHealth_; }
+
+
// FIXME: (noep) Why doesn't this work? Works fine in Engine.h
//void addToSpaceShip(ModularSpaceShip* ship);
protected:
- Pawn* parent_;
+ ModularSpaceShip* parent_;
unsigned int parentID_; // Object ID of the SpaceShip the Part is mounted on.
float damageAbsorption_;
float health_;
+ float maxHealth_;
+ float initialHealth_;
private:
std::vector<StaticEntity*> entityList_; // list of all entities which belong to this part
Modified: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc 2014-04-03 14:05:52 UTC (rev 10022)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc 2014-04-09 19:50:45 UTC (rev 10023)
@@ -87,12 +87,21 @@
// if the name of the part matches the name of the object, add the object to that parts entitylist (unless it was already done).
if((this->partList_[j]->getName() == this->getAttachedObject(i)->getName()) && !this->partList_[j]->hasEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i))))
{
+ // The Entity is added to the part's entityList_
this->partList_[j]->addEntity(orxonox_cast<StaticEntity*>(this->getAttachedObject(i)));
+ // An entry in the partMap_ is created, assigning the part to the entity.
+ this->addPartEntityAssignment((StaticEntity*)(this->getAttachedObject(i)), this->partList_[j]);
orxout() << "A matching part-entity-pair with name " << this->partList_[j]->getName() << " was found!" << endl;
this->partList_[j]->printEntities(); // FIXME: (noep) remove debug
}
}
}
+
+ orxout() << "List of all assignments:" << endl;
+ for (std::map<StaticEntity*, ShipPart*>::const_iterator it = this->partMap_.begin(); it != this->partMap_.end(); ++it)
+ {
+ orxout() << "Entity: " << it->first << " Part: " << it->second << endl;
+ }
}
void ModularSpaceShip::attach(WorldEntity* object)
@@ -142,9 +151,12 @@
orxout() << "Mdamage(): Collision detected on " << this->getRadarName() << ", btCS*: " << cs << endl;
orxout() << "UserPtr of said collisionShape: " << cs->getUserPointer() << endl;
- // List all attached Objects
+
+ // Print all attached objects & parts
+ /*
orxout() << " " << this->getName() << " has the following Objects attached:" << endl;
- for (int i=0; i<10; i++)
+
+ for (int i=0; i<50; i++)
{
if (this->getAttachedObject(i)==NULL)
break;
@@ -156,18 +168,23 @@
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;
+ //orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;
+ orxout() << "CP_start" << 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);
+ else
+ SpaceShip::damage(damage, healthdamage, shielddamage, originator, cs);
+ orxout() << "CP_end" << endl;
+
/*
// Applies multiplier given by the DamageBoost Pickup.
if (originator)
@@ -207,6 +224,7 @@
{
OrxAssert(part != NULL, "The ShipPart cannot be NULL.");
this->partList_.push_back(part);
+ part->setParent(this);
//part->addToSpaceShip(this); //FIXME: (noep) add
this->updatePartAssignment();
}
@@ -241,4 +259,25 @@
return false;
}
+ void ModularSpaceShip::removeShipPart(ShipPart* part)
+ {
+ // Remove the part from the partList_
+ std::vector<ShipPart*>::iterator it = this->partList_.begin();
+ for(unsigned int i = 0; i < this->partList_.size(); i++)
+ {
+ if(this->partList_[i] == part)
+ this->partList_.erase(it);
+ 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)
+ {
+ if (itt->second == part)
+ {
+ this->detach(itt->first);
+ this->partMap_.erase(itt);
+ }
+ }
+ }
+
}
Modified: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h 2014-04-03 14:05:52 UTC (rev 10022)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h 2014-04-09 19:50:45 UTC (rev 10023)
@@ -47,7 +47,8 @@
/**
@brief
- The ModularSpaceShip is the principal entity through which the player interacts with the game. Its main function is to fly, however many things, such as @ref orxonox::Engine Engines or @ref orxonox::Weapon Weapons, can be attached to it.
+ The SpaceShip is the principal entity through which the player interacts with the game. Its main function is to fly, however many things, such as @ref orxonox::Engine Engines or @ref orxonox::Weapon Weapons, can be attached to it.
+ The ModularSpaceShip is an extension of a @ref orxonox::SpaceShip SpaceShip, which uses @ref orxonox::ShipPart ShipParts to allow entities attached to it to be destroyed individually.
There are several parameters that define the behavior of the ModularSpaceShip>
- The <b>rotationThrust</b>, specifies the force with which the ModularSpaceShip rotates.
@@ -55,7 +56,9 @@
- The <b>boost shaking</b>, when the ModularSpaceShip boosts, the camera shakes to create a more immersive effect. Two parameters can be used to adjust the effect. The <b>shakeFrequency</b> is the frequency with which the camera shakes. And the <b>shakeAmplitude</b> is the amount with which the camera shakes. Again these parameters must bee non-negative.
- The <b>lift</b> creates a more natural flight feeling through the addition of a lift force. There are again tow parameters that can be specified. The <b>lift</b> which is the lift force that is applied. And the <b>stallSpeed</b> which is the forward speed after which no more lift is generated.
- As mentioned @ref orxonox::Engine Engines can be mounted on the ModularSpaceShip. Here is a (primitive) example of a ModularSpaceShip defined in XML:
+ As mentioned @ref orxonox::Engine Engines can be mounted on the ModularSpaceShip.
+ 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 defined in XML:
@code
<ModularSpaceShip
rotationThrust = 50
@@ -76,6 +79,14 @@
linearDamping = 0.7
angularDamping = 0.9999999
>
+ <attached>
+ <StaticEntity name="wing" . . . />
+ <StaticEntity name="tail" . . . />
+ </attached>
+ <parts>
+ <ShipPart name="wing" . . . />
+ <ShipPart name="tail" . . . />
+ </parts>
<engines>
<Engine />
<Engine />
@@ -84,7 +95,7 @@
@endcode
@author
- Fabian 'x3n' Landau
+ Fabian 'x3n' Landau, Noe Pedrazzini
*/
class _OrxonoxExport ModularSpaceShip : public SpaceShip
{
@@ -104,6 +115,7 @@
void addShipPart(ShipPart* part);
ShipPart* getShipPart(unsigned int index);
bool hasShipPart(ShipPart* part) const;
+ void removeShipPart(ShipPart* part);
virtual void updatePartAssignment();
Modified: code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc 2014-04-03 14:05:52 UTC (rev 10022)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc 2014-04-09 19:50:45 UTC (rev 10023)
@@ -251,10 +251,11 @@
void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
{
- orxout() << "damage(): Collision detected on " << this->getName() << ", btCS*: " << cs << endl;
+ //FIXME: (noep) remove debug
+ //orxout() << "damage(): Collision detected on " << this->getName() << ", btCS*: " << cs << endl;
- int collisionShapeIndex = this->isMyCollisionShape(cs);
- orxout() << collisionShapeIndex << endl;
+ //int collisionShapeIndex = this->isMyCollisionShape(cs);
+ //orxout() << collisionShapeIndex << endl;
// Applies multiplier given by the DamageBoost Pickup.
if (originator)
@@ -586,7 +587,7 @@
// List all attached Objects
orxout() << " " << this->getName() << " has the following Objects attached:" << endl;
- for (int i=0; i<10; i++)
+ for (int i=0; i<50; i++)
{
if (this->getAttachedObject(i)==NULL)
break;
Modified: code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h 2014-04-03 14:05:52 UTC (rev 10022)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h 2014-04-09 19:50:45 UTC (rev 10023)
@@ -228,7 +228,7 @@
float spawnparticleduration_;
unsigned int numexplosionchunks_;
- virtual int isMyCollisionShape(const btCollisionShape* cs);
+ virtual int isMyCollisionShape(const btCollisionShape* cs); // FIXME: (noep) remove debug
void printBtChildShapes(btCompoundShape* cs, int indent, int subshape); // FIXME: (noep) remove debug
void printSpaces(int num); // FIXME: (noep) remove debug
int entityOfCollisionShape(const btCollisionShape* cs);
More information about the Orxonox-commit
mailing list