- Timestamp:
- May 14, 2014, 8:25:08 PM (11 years ago)
- Location:
- code/branches/modularships/src/orxonox/worldentities/pawns
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
r10054 r10055 37 37 #include "util/Math.h" 38 38 #include "gametypes/Gametype.h" 39 #include "core/command/ConsoleCommand.h" 39 40 40 41 #include "items/ShipPart.h" … … 48 49 namespace orxonox 49 50 { 51 SetConsoleCommand("ModularSpaceShip", "killshippart", &ModularSpaceShip::killShipPart); 52 50 53 RegisterClass(ModularSpaceShip); 51 54 55 std::map<StaticEntity*, ShipPart*>* ModularSpaceShip::partMap_s = 0; 56 52 57 ModularSpaceShip::ModularSpaceShip(Context* context) : SpaceShip(context) 53 58 { … … 55 60 56 61 this->registerVariables(); 62 63 ModularSpaceShip::partMap_s = &(this->partMap_); 57 64 58 65 } … … 77 84 } 78 85 86 /** 87 @brief 88 Searches for ShipParts matching to StaticEntities. 89 */ 79 90 void ModularSpaceShip::updatePartAssignment() 80 91 { … … 115 126 } 116 127 128 /** 129 @brief 130 Creates a new assignment for the given StaticEntity and ShipPart in the partMap_ 131 @param entity 132 A pointer to the StaticEntity 133 @param part 134 A pointer to the ShipPart. 135 */ 117 136 void ModularSpaceShip::addPartEntityAssignment(StaticEntity* entity, ShipPart* part) 118 137 { … … 150 169 } 151 170 152 //FIXME: (noep) finish 153 // void ModularSpaceShip::attach 154 171 /** 172 @brief 173 If the damage occurred on an attached StaticEntity, the damage is given to the corresponding ShipPart to handle. 174 */ 155 175 void ModularSpaceShip::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs) 156 176 { 157 /*orxout() << "Mdamage(): Collision detected on " << this->getRadarName() << ", btCS*: " << cs << endl;158 orxout() << "UserPtr of said collisionShape: " << cs->getUserPointer() << endl;159 160 161 // Print all attached objects & parts162 /*163 orxout() << " " << this->getName() << " has the following Objects attached:" << endl;164 165 for (int i=0; i<50; i++)166 {167 if (this->getAttachedObject(i)==NULL)168 break;169 orxout() << " " << i << ": " << this->getAttachedObject(i) << " (" << this->getAttachedObject(i)->getName() << ")";170 orxout() << endl;171 }172 173 orxout() << " Attached ShipParts:" << endl;174 for(unsigned int i=0; i < this->partList_.size(); i++)175 {176 orxout() << " " << i << ": " << this->partList_[i] << " (" << this->partList_[i]->getName() << ")" << endl;177 }*/178 179 180 //int collisionShapeIndex = this->isMyCollisionShape(cs);181 //orxout() << collisionShapeIndex << endl;182 183 //orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl;184 185 177 if (this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != NULL) 186 178 this->getPartOfEntity((StaticEntity*)(cs->getUserPointer()))->handleHit(damage, healthdamage, shielddamage, originator); 187 179 else 188 180 SpaceShip::damage(damage, healthdamage, shielddamage, originator, cs); 189 190 /* 191 // Applies multiplier given by the DamageBoost Pickup. 192 if (originator) 193 damage *= originator->getDamageMultiplier(); 194 195 if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator)) 196 { 197 if (shielddamage >= this->getShieldHealth()) 198 { 199 this->setShieldHealth(0); 200 this->setHealth(this->health_ - (healthdamage + damage)); 201 } 202 else 203 { 204 this->setShieldHealth(this->shieldHealth_ - shielddamage); 205 206 // remove remaining shieldAbsorpton-Part of damage from shield 207 shielddamage = damage * this->shieldAbsorption_; 208 shielddamage = std::min(this->getShieldHealth(),shielddamage); 209 this->setShieldHealth(this->shieldHealth_ - shielddamage); 210 211 // set remaining damage to health 212 this->setHealth(this->health_ - (damage - shielddamage) - healthdamage); 213 } 214 215 this->lastHitOriginator_ = originator; 216 }*/ 181 } 182 183 /** 184 @brief 185 Kills the ShipPart with the given name. Used from the console-command "ModularSpaceShip killshippart [string]". 186 @param name 187 The name of the part to be killed. 188 */ 189 void ModularSpaceShip::killShipPart(std::string name) 190 { 191 for (std::map<StaticEntity*, ShipPart*>::const_iterator it = ModularSpaceShip::partMap_s->begin(); it != ModularSpaceShip::partMap_s->end(); ++it) 192 { 193 if (it->second->getName() == name) 194 { 195 it->second->death(); 196 return; 197 } 198 } 199 orxout(internal_warning) << "Could not apply damage to ShipPart \"" << name << "\". Part not found." << endl; 217 200 } 218 201 … … 261 244 } 262 245 246 247 /** 248 @brief 249 Removes a ShipPart from the SpaceShip, destroying the corresponding StaticEntity 250 @param part 251 The ShipPart to be removed. 252 */ 263 253 void ModularSpaceShip::removeShipPart(ShipPart* part) 264 254 { … … 309 299 orxout() << "MSS: detach()" << endl; 310 300 311 this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);301 //this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0); 312 302 this->detachCollisionShape(object->collisionShape_); // after succeeding, causes a crash in the collision handling 313 303 //this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0); -
code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.h
r10054 r10055 113 113 virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL, const btCollisionShape* cs = NULL); 114 114 115 static void killShipPart(std::string name); 116 115 117 void addShipPart(ShipPart* part); 116 118 ShipPart* getShipPart(unsigned int index); … … 127 129 private: 128 130 void registerVariables(); 129 std::vector<ShipPart*> partList_; // The list of all Parts mounted on this ModularSpaceShip. 130 std::vector<SmartPtr<StaticEntity>*> entityPtrList_; 131 std::vector<SmartPtr<CollisionShape>*> csPtrList_; 132 std::map<StaticEntity*, ShipPart*> partMap_; 131 std::vector<ShipPart*> partList_; // The list of all Parts mounted on this ModularSpaceShip. 132 std::map<StaticEntity*, ShipPart*> partMap_; // Map of Part-Entity-assignments 133 static std::map<StaticEntity*, ShipPart*>* partMap_s; 133 134 134 135 };
Note: See TracChangeset
for help on using the changeset viewer.