Changeset 10053 for code/branches/modularships/src/orxonox
- Timestamp:
- May 13, 2014, 11:45:47 AM (11 years ago)
- Location:
- code/branches/modularships/src/orxonox
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/modularships/src/orxonox/Scene.cc
r10036 r10053 345 345 int index0, const btCollisionObject* colObj1, int partId1, int index1) 346 346 { 347 orxout() << "collisionCb()" << endl;348 349 347 // get the WorldEntity pointers 350 348 SmartPtr<WorldEntity> object0 = static_cast<WorldEntity*>(colObj0->getUserPointer()); … … 362 360 modified |= object1->collidesAgainst(object0, cs0, cp); 363 361 364 orxout() << "collisionCb() completed." << endl;365 366 362 return modified; 367 363 } -
code/branches/modularships/src/orxonox/items/PartDestructionEvent.cc
r10052 r10053 49 49 { 50 50 RegisterObject(PartDestructionEvent); 51 this-> isValid_ = false;51 this->setValid(true); 52 52 } 53 53 … … 76 76 void PartDestructionEvent::execute() 77 77 { 78 if(!this->isValid_) 78 // Do not execute if this event is invalid 79 if(!isValid()) 79 80 { 80 //orxout(internal_warning) <<81 orxout(internal_warning) << "Attempted to execute an invalid PartDestructionEvent!" << endl; 81 82 return; 82 83 } 83 84 85 if (this->targetType_ == "ship") 86 { 87 switch (this->targetParam_) { 88 case shieldhealth: 89 this->parent_->getParent()->setShieldHealth(operate(this->parent_->getParent()->getShieldHealth())); 90 break; 91 default: 92 break; 93 } 94 this->setValid(false); 95 return; 96 } 97 } 84 98 99 void PartDestructionEvent::setParent(ShipPart* part) 100 { 101 this->parent_ = part; 85 102 } 86 103 … … 95 112 96 113 // Error, if invalid target-type was entered. 97 orxout(internal_warning) << type <<" is not a valid target-type for a PartDestructionEvent. Valid types are: ship engine weapon" << endl;98 this-> isValid_ = false;114 orxout(internal_warning) << "\"" << type << "\" is not a valid target-type for a PartDestructionEvent. Valid types are: ship engine weapon" << endl; 115 this->setValid(false); 99 116 return; 100 117 } … … 117 134 { 118 135 orxout(internal_warning) << "No valid target-type defined. Cannot set target-param for this PartDestructionEvent." << endl; 119 this-> isValid_ = false;136 this->setValid(false); 120 137 return; 121 138 } … … 131 148 if (param == "shieldhealth") 132 149 { 133 this->targetParam_ = param;150 this->targetParam_ = shieldhealth; 134 151 return; 135 152 } 136 153 137 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;154 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; 138 155 return; 139 156 } 157 158 orxout(internal_warning) << "No valid target-param defined. The chosen param is either invalid or not available for this target-type." << endl; 159 this->setValid(false); 140 160 } 141 161 … … 143 163 { 144 164 // * + - destroy 145 this->operation_ = operation; 165 if ((operation == "*") || (operation == "+") || (operation == "-") || (operation == "destroy")) 166 { 167 this->operation_ = operation; 168 return; 169 } 170 this->operation_ = "NULL"; 171 orxout(internal_warning) << "\"" << operation << "\" is not a valid operation for a PartDestructionEvent. Valid operations are: * + - destroy" << endl; 172 } 173 174 float PartDestructionEvent::operate(float input) 175 { 176 if (this->operation_ == "*") 177 return input * this->value_; 178 if (this->operation_ == "+") 179 return input + this->value_; 180 if (this->operation_ == "-") 181 return input - this->value_; 182 if (this->operation_ == "destroy") 183 { 184 return 0; 185 } 186 return 0; 146 187 } 147 188 -
code/branches/modularships/src/orxonox/items/PartDestructionEvent.h
r10052 r10053 44 44 public: 45 45 46 enum TargetParam 47 { 48 shieldhealth, 49 maxshieldhealth, 50 shieldabsorption, 51 shieldrechargerate, 52 null 53 }; 54 46 55 PartDestructionEvent(Context* context); 47 56 virtual ~PartDestructionEvent(); … … 50 59 51 60 void execute(); 61 62 inline void setValid(bool valid) 63 { this->valid_ = valid; } 64 inline bool isValid() 65 { return this->valid_; } 66 67 void setParent(ShipPart* parent); 68 inline ShipPart* getParent() 69 { return this->parent_; } 52 70 53 71 void setTargetType(std::string type); … … 67 85 { return this->operation_; } 68 86 87 float operate(float input); 88 69 89 void setEventValue(float value); 70 90 inline float getEventValue() … … 75 95 private: 76 96 77 bool isValid_; 97 ShipPart* parent_; 98 bool valid_; 78 99 79 100 std::string targetType_; 80 101 std::string targetName_; 81 std::stringtargetParam_;102 TargetParam targetParam_; 82 103 std::string operation_; 83 104 -
code/branches/modularships/src/orxonox/items/ShipPart.cc
r10052 r10053 51 51 { 52 52 RegisterObject(ShipPart); 53 this->setAlive(true); 53 54 } 54 55 … … 91 92 void ShipPart::death() 92 93 { 94 if (!(this->isAlive())) 95 return; 96 97 this->setAlive(false); 98 99 // Execute all destruction events 100 for (unsigned int i = 0; i < this->eventList_.size(); i++) 101 { 102 orxout() << "executing" << endl; 103 this->getDestructionEvent(i)->execute(); 104 } 105 106 // Remove this ShipPart from the parent. 93 107 this->parent_->removeShipPart(this); 94 108 orxout() << this->getName() << " has died." << endl; … … 105 119 OrxAssert(entity != NULL, "The Entity cannot be NULL."); 106 120 this->entityList_.push_back(entity); 107 //part->addToSpaceShip(this); //FIXME: (noep) add108 121 } 109 122 … … 153 166 A pointer to the PartDestructionEvent to be added. 154 167 */ 155 void ShipPart::addDestructionEvent(PartDestructionEvent* part)156 { 157 OrxAssert( part != NULL, "The PartDestructionEvent cannot be NULL.");158 this->eventList_.push_back(part);159 //part->setParent(this);168 void ShipPart::addDestructionEvent(PartDestructionEvent* event) 169 { 170 OrxAssert(event != NULL, "The PartDestructionEvent cannot be NULL."); 171 event->setParent(this); 172 this->eventList_.push_back(event); 160 173 } 161 174 … … 168 181 PartDestructionEvent* ShipPart::getDestructionEvent(unsigned int index) 169 182 { 170 if(this->eventList_.size() >= index)183 if(this->eventList_.size() <= index) 171 184 return NULL; 172 185 else … … 200 213 { 201 214 orxout() << "ShipPart " <<this->getName() << " is handling a hit!" << endl; 215 202 216 if (parent_->getGametype() && parent_->getGametype()->allowPawnDamage(parent_, originator)) 203 217 { -
code/branches/modularships/src/orxonox/items/ShipPart.h
r10052 r10053 73 73 { return this->parent_; } 74 74 75 inline void setAlive(bool var) 76 { this->alive_ = var; } 77 inline bool isAlive() 78 { return this->alive_; } 79 75 80 virtual void setHealth(float health); 76 81 inline void addHealth(float health) … … 108 113 std::vector<PartDestructionEvent*> eventList_; // The list of all PartDestructionEvent assigned to this ShipPart. 109 114 115 bool alive_; 116 110 117 111 118 }; // tolua_export -
code/branches/modularships/src/orxonox/worldentities/WorldEntity.cc
r10052 r10053 119 119 WorldEntity::~WorldEntity() 120 120 { 121 orxout() << "destroying " << this->getIdentifier()->getName() << endl;122 121 if (this->isInitialized()) 123 122 { … … 581 580 { 582 581 // Note: The collision shapes may not be detached with this function! 583 orxout() << "WE: detachCS()" << endl;584 582 this->collisionShape_->detach(shape); 585 583 // Note: this->collisionShape_ already notifies us of any changes. -
code/branches/modularships/src/orxonox/worldentities/pawns/ModularSpaceShip.cc
r10052 r10053 133 133 this->entityPtrList_.push_back(one); 134 134 135 this->createCSPtrList(this->getWorldEntityCollisionShape());135 //this->createCSPtrList(this->getWorldEntityCollisionShape()); 136 136 137 137 orxout() << "New entity-part assignment created!" << endl; … … 139 139 140 140 // This should add smartPointers to all (Orxonox)Collisionshapes of this SpaceShip, preventing them fromg etting deleted. Might not work due to weird acting getAttachedShape 141 void ModularSpaceShip::createCSPtrList(CompoundCollisionShape* cs) 141 void ModularSpaceShip::createCSPtrList(CompoundCollisionShape* cs) // FIXME: (noep) remove debug 142 142 { 143 143 for (int i=0; i < cs->getNumChildShapes(); i++) … … 208 208 //orxout() << "ShipPart of Entity " << cs->getUserPointer() << ": " << this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) << endl; 209 209 210 orxout() << "CP before handleHit" << endl;211 212 210 if (this->getPartOfEntity((StaticEntity*)(cs->getUserPointer())) != NULL) 213 211 this->getPartOfEntity((StaticEntity*)(cs->getUserPointer()))->handleHit(damage, healthdamage, shielddamage, originator); … … 255 253 this->partList_.push_back(part); 256 254 part->setParent(this); 257 //part->addToSpaceShip(this); //FIXME: (noep) add258 255 this->updatePartAssignment(); 259 256 } … … 267 264 ShipPart* ModularSpaceShip::getShipPart(unsigned int index) 268 265 { 269 if(this->partList_.size() >= index)266 if(this->partList_.size() <= index) 270 267 return NULL; 271 268 else … … 339 336 this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0); 340 337 this->detachCollisionShape(object->collisionShape_); // after succeeding, causes a crash in the collision handling 341 this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0);338 //this->printBtChildShapes((btCompoundShape*)(this->getWorldEntityCollisionShape()->getCollisionShape()), 2, 0); 342 339 343 340 // mass
Note: See TracChangeset
for help on using the changeset viewer.