[Orxonox-commit 5408] r10071 - in code/branches/modularships/src/orxonox: items worldentities/pawns
noep at orxonox.net
noep at orxonox.net
Thu May 22 14:18:48 CEST 2014
Author: noep
Date: 2014-05-22 14:18:47 +0200 (Thu, 22 May 2014)
New Revision: 10071
Modified:
code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc
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:
Removed all segfaults (or at least those we found...)
Modified: code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc
===================================================================
--- code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc 2014-05-22 11:41:32 UTC (rev 10070)
+++ code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc 2014-05-22 12:18:47 UTC (rev 10071)
@@ -142,6 +142,8 @@
{
switch (this->targetParam_) {
case null:
+ if (!this->parent_->getParent()->getShipPartByName(targetName_))
+ return;
this->parent_->getParent()->getShipPartByName(targetName_)->setEventExecution(false);
this->parent_->getParent()->killShipPart(targetName_);
break;
Modified: code/branches/modularships/src/orxonox/items/ShipPart.cc
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.cc 2014-05-22 11:41:32 UTC (rev 10070)
+++ code/branches/modularships/src/orxonox/items/ShipPart.cc 2014-05-22 12:18:47 UTC (rev 10071)
@@ -54,6 +54,7 @@
RegisterObject(ShipPart);
this->setAlive(true);
this->setEventExecution(true);
+ this->healthMem_ = 100;
}
ShipPart::~ShipPart()
@@ -101,6 +102,7 @@
// Remove this ShipPart from the parent.
this->parent_->removeShipPart(this);
+ delete this;
}
void ShipPart::explode()
@@ -202,6 +204,12 @@
this->health_ = health;
}
+ void ShipPart::setAlive(bool var)
+ {
+ this->alive_ = var;
+ orxout() << "ShipPart " << this->getName() << " alive_: " << this->alive_ << endl;
+ }
+
/**
@brief
Handles a received hit.
@@ -235,23 +243,27 @@
//this->death();
// (Ugly) Chatoutput of health, until a GUI for modularspaceships-shipparts is implemented.
- if (this->health_ < 0.2 * this->maxHealth_)
+ if ((this->health_ < 0.2 * this->maxHealth_) && (this->healthMem_ == 40))
{
+ this->healthMem_ = 20;
ChatManager::message("ShipPart " + this->getName() + " remaining health is 20%!");
return;
}
- if (this->health_ < 0.4 * this->maxHealth_)
+ if ((this->health_ < 0.4 * this->maxHealth_) && (this->healthMem_ == 60))
{
+ this->healthMem_ = 40;
ChatManager::message("ShipPart " + this->getName() + " remaining health is 40%!");
return;
}
- if (this->health_ < 0.6 * this->maxHealth_)
+ if ((this->health_ < 0.6 * this->maxHealth_) && (this->healthMem_ == 80))
{
+ this->healthMem_ = 60;
ChatManager::message("ShipPart " + this->getName() + " remaining health is 60%!");
return;
}
- if (this->health_ < 0.8 * this->maxHealth_)
+ if ((this->health_ < 0.8 * this->maxHealth_) && (this->healthMem_ == 100))
{
+ this->healthMem_ = 80;
ChatManager::message("ShipPart " + this->getName() + " remaining health is 80%!");
return;
}
Modified: code/branches/modularships/src/orxonox/items/ShipPart.h
===================================================================
--- code/branches/modularships/src/orxonox/items/ShipPart.h 2014-05-22 11:41:32 UTC (rev 10070)
+++ code/branches/modularships/src/orxonox/items/ShipPart.h 2014-05-22 12:18:47 UTC (rev 10071)
@@ -71,8 +71,7 @@
inline ModularSpaceShip* getParent()
{ return this->parent_; }
- inline void setAlive(bool var)
- { this->alive_ = var; }
+ void setAlive(bool var);
inline bool isAlive()
{ return this->alive_; }
@@ -124,6 +123,8 @@
bool alive_;
bool eventExecution_;
+ float healthMem_;
+
Vector3 explosionPosition_;
Modified: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc 2014-05-22 11:41:32 UTC (rev 10070)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc 2014-05-22 12:18:47 UTC (rev 10071)
@@ -49,7 +49,7 @@
namespace orxonox
{
- SetConsoleCommand("ModularSpaceShip", "killshippart", &ModularSpaceShip::killShipPart);
+ SetConsoleCommand("ModularSpaceShip", "killshippart", &ModularSpaceShip::killShipPartStatic);
RegisterClass(ModularSpaceShip);
@@ -173,17 +173,36 @@
/**
@brief
+ STATIC: Needed for consolecommand. 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::killShipPartStatic(std::string name)
+ {
+ for (std::map<StaticEntity*, ShipPart*>::const_iterator it = ModularSpaceShip::partMap_s->begin(); it != ModularSpaceShip::partMap_s->end(); ++it)
+ {
+ if (it->second->getName() == name)
+ {
+ it->second->setAlive(false);
+ return;
+ }
+ }
+ orxout(internal_warning) << "Could not apply damage to ShipPart \"" << name << "\". Part not found." << endl;
+ }
+
+ /**
+ @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)
+ for (std::map<StaticEntity*, ShipPart*>::const_iterator it = ModularSpaceShip::partMap_.begin(); it != ModularSpaceShip::partMap_.end(); ++it)
{
if (it->second->getName() == name)
{
- it->second->death();
+ it->second->setAlive(false);
return;
}
}
Modified: code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h 2014-05-22 11:41:32 UTC (rev 10070)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h 2014-05-22 12:18:47 UTC (rev 10071)
@@ -112,7 +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);
+ static void killShipPartStatic(std::string name);
+ void killShipPart(std::string name);
void addShipPart(ShipPart* part);
ShipPart* getShipPart(unsigned int index);
More information about the Orxonox-commit
mailing list