Changeset 11052 for code/trunk/src/orxonox
- Timestamp:
- Jan 9, 2016, 6:26:20 PM (9 years ago)
- Location:
- code/trunk
- Files:
-
- 2 deleted
- 34 edited
- 22 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/OrxonoxPrereqs.h
r10624 r11052 167 167 class DefaultWeaponmodeLink; 168 168 class Munition; 169 class ReplenishingMunition; 169 170 class Weapon; 170 171 class WeaponMode; … … 175 176 176 177 // worldentities 177 class BigExplosion;178 178 class CameraPosition; 179 179 class ControllableEntity; -
code/trunk/src/orxonox/controllers/ArtificialController.cc
r10631 r11052 94 94 return; 95 95 96 static const float hardcoded_projectile_speed= 750;97 98 this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());96 static const float HARDCODED_PROJECTILE_SPEED = 750; 97 98 this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), HARDCODED_PROJECTILE_SPEED, this->target_->getWorldPosition(), this->target_->getVelocity()); 99 99 this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO); 100 100 -
code/trunk/src/orxonox/controllers/CMakeLists.txt
r10216 r11052 11 11 FormationController.cc 12 12 ControllerDirector.cc 13 DivisionController.cc 14 WingmanController.cc 15 SectionController.cc 16 CommonController.cc 17 ActionpointController.cc 18 FlyingController.cc 19 FightingController.cc 20 MasterController.cc 13 21 ) -
code/trunk/src/orxonox/controllers/FormationController.cc
r10631 r11052 277 277 } 278 278 279 Vector2 coord = get2DView coordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);279 Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 280 280 float distance = (target - this->getControllableEntity()->getPosition()).length(); 281 281 float rotateX = clamp(coord.x * 10, -1.0f, 1.0f); … … 970 970 if (controller) 971 971 { 972 if (controller->getIdentifier()->getName() == "MasterController") 973 return true; 972 974 FormationController* ac = orxonox_cast<FormationController*>(controller); 973 975 if (ac) … … 981 983 if (controller) 982 984 { 985 if (controller->getIdentifier()->getName() == "MasterController") 986 return true; 983 987 FormationController* ac = orxonox_cast<FormationController*>(controller); 984 988 if (ac) … … 1069 1073 return; 1070 1074 1071 Vector2 coord = get2DView coordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);1075 Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 1072 1076 float distance = (target - this->getControllableEntity()->getPosition()).length(); 1073 1077 -
code/trunk/src/orxonox/controllers/HumanController.cc
r10624 r11052 199 199 @brief 200 200 Starts the boosting mode. 201 Resets the boosting timeout and ells the ControllableEntity to boost (or not boost anymore).201 Resets the boosting timeout and tells the ControllableEntity to boost (or not boost anymore). 202 202 */ 203 203 void HumanController::startBoosting(void) -
code/trunk/src/orxonox/gametypes/Dynamicmatch.cc
r10624 r11052 86 86 } 87 87 88 Dynamicmatch::~Dynamicmatch() 89 { 90 for (std::set<Timer*>::iterator it = this->piggyTimers_.begin(); it != this->piggyTimers_.end(); ++it) 91 delete (*it); 92 } 93 88 94 void Dynamicmatch::setConfigValues() 89 95 { … … 312 318 spaceship->addSpeedFactor(5); 313 319 ExecutorPtr executor = createExecutor(createFunctor(&Dynamicmatch::resetSpeedFactor, this)); 314 executor->setDefaultValue(0, spaceship); 315 new Timer(10, false, executor, true); 320 Timer* timer = new Timer(10, false, executor); 321 executor->setDefaultValue(0, spaceship); // TODO: use WeakPtr because spaceship can be destroyed in the meantime 322 executor->setDefaultValue(1, timer); 323 this->piggyTimers_.insert(timer); 316 324 } 317 325 } … … 590 598 } 591 599 592 void Dynamicmatch::resetSpeedFactor(SpaceShip* spaceship )// helper function600 void Dynamicmatch::resetSpeedFactor(SpaceShip* spaceship, Timer* timer)// helper function 593 601 { 594 602 if (spaceship) … … 596 604 spaceship->addSpeedFactor(1.0f/5.0f); 597 605 } 606 607 this->piggyTimers_.erase(timer); 608 delete timer; 598 609 } 599 610 -
code/trunk/src/orxonox/gametypes/Dynamicmatch.h
r10624 r11052 33 33 34 34 #include <map> 35 #include <set> 35 36 #include <vector> 36 37 … … 45 46 public: 46 47 Dynamicmatch(Context* context); 47 virtual ~Dynamicmatch() {}48 virtual ~Dynamicmatch(); 48 49 49 50 bool notEnoughPigs; … … 77 78 virtual void rewardPig(); 78 79 void grantPigBoost(SpaceShip* spaceship); // Grant the piggy a boost. 79 void resetSpeedFactor(SpaceShip* spaceship );80 void resetSpeedFactor(SpaceShip* spaceship, Timer* timer); 80 81 void tick (float dt);// used to end the game 81 82 SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const; … … 88 89 std::map< PlayerInfo*, int > playerParty_; //player's parties are recorded here 89 90 std::vector<ColourValue> partyColours_; //aus TeamDeathmatch 91 std::set<Timer*> piggyTimers_; 90 92 unsigned int numberOf[3]; //array to count number of chasers, pigs, killers 91 93 float pointsPerTime; -
code/trunk/src/orxonox/infos/PlayerInfo.cc
r10624 r11052 202 202 203 203 this->changedControllableEntity(); 204 205 // HACK-ish 206 if(this->isHumanPlayer()) 207 entity->createHud(); 204 208 } 205 209 … … 252 256 if( !entity || this->previousControllableEntity_.size() == 0 ) 253 257 return; 258 259 entity->destroyHud(); // HACK-ish 254 260 255 261 this->controllableEntity_->setController(0); -
code/trunk/src/orxonox/items/ShipPart.cc
r10624 r11052 41 41 #include "worldentities/StaticEntity.h" 42 42 #include "items/PartDestructionEvent.h" 43 #include "worldentities/BigExplosion.h"44 43 #include "chat/ChatManager.h" 45 44 … … 105 104 void ShipPart::explode() 106 105 { 107 BigExplosion* chunk = new BigExplosion(this->getContext());108 chunk->setPosition(this->parent_->getPosition() + this->parent_->getOrientation() * (this->explosionPosition_));109 // chunk->setPosition(this->parent_->getPosition() + this->parent_->getOrientation() * Vector3(this->entityList_[0]->getLocalInertia()));110 chunk->setVelocity(this->parent_->getVelocity());106 // BigExplosion* chunk = new BigExplosion(this->getContext()); 107 // chunk->setPosition(this->parent_->getPosition() + this->parent_->getOrientation() * (this->explosionPosition_)); 108 // //chunk->setPosition(this->parent_->getPosition() + this->parent_->getOrientation() * Vector3(this->entityList_[0]->getLocalInertia())); 109 // chunk->setVelocity(this->parent_->getVelocity()); 111 110 112 111 // this->explosionSound_->setPosition(this->parent_->getPosition()); -
code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc
r10624 r11052 450 450 tempTx->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour); 451 451 } 452 453 void OrxonoxOverlay::setZOrder(unsigned short order) 454 { 455 if (this->overlay_) 456 { 457 this->overlay_->setZOrder(order); 458 } 459 } 452 460 } -
code/trunk/src/orxonox/overlays/OrxonoxOverlay.h
r9667 r11052 65 65 only for displaying a picture). 66 66 - Reacts to changes of the window aspect 67 - Last but not least: On demand you can tell the overlay to automatically res ale to correct for67 - Last but not least: On demand you can tell the overlay to automatically rescale to correct for 68 68 aspect distortion. E.g. if you play 1024x768 you wouldn't want a round object to be oval. 69 69 Remark: This can (due to the Ogre::Overlay transformation order) only work for angle that are … … 186 186 virtual void changedOverlayGroup() 187 187 { this->changedVisibility(); } 188 virtual void setZOrder(unsigned short order); 188 189 189 190 protected: -
code/trunk/src/orxonox/overlays/OverlayGroup.cc
r10624 r11052 42 42 namespace orxonox 43 43 { 44 namespace autocompletion 45 { 46 /** 47 @brief Returns the names of all currently existing OverlayGroups. 48 */ 49 ARGUMENT_COMPLETION_FUNCTION_DECLARATION(overlaygroupnames)(); 50 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(overlaygroupnames)() 51 { 52 ArgumentCompletionList names; 53 for (ObjectList<OverlayGroup>::iterator it = ObjectList<OverlayGroup>::begin(); it; ++it) 54 names.push_back(ArgumentCompletionListElement(it->getName(), getLowercase(it->getName()))); 55 return names; 56 } 57 } 58 59 SetConsoleCommand("OverlayGroup", "toggleVisibility", &OverlayGroup::toggleVisibility).argumentCompleter(0, autocompletion::overlaygroupnames()); 60 SetConsoleCommand("OverlayGroup", "show", &OverlayGroup::show ).argumentCompleter(0, autocompletion::overlaygroupnames()); 61 SetConsoleCommand("OverlayGroup", "scaleGroup", &OverlayGroup::scaleGroup ).argumentCompleter(0, autocompletion::overlaygroupnames()); 62 SetConsoleCommand("OverlayGroup", "scrollGroup", &OverlayGroup::scrollGroup ).argumentCompleter(0, autocompletion::overlaygroupnames()); 63 44 64 RegisterClass(OverlayGroup); 45 46 SetConsoleCommand("OverlayGroup", "toggleVisibility", &OverlayGroup::toggleVisibility);47 SetConsoleCommand("OverlayGroup", "show", &OverlayGroup::show);48 SetConsoleCommand("OverlayGroup", "scaleGroup", &OverlayGroup::scaleGroup);49 SetConsoleCommand("OverlayGroup", "scrollGroup", &OverlayGroup::scrollGroup);50 65 51 66 OverlayGroup::OverlayGroup(Context* context) -
code/trunk/src/orxonox/weaponsystem/CMakeLists.txt
r5781 r11052 1 1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 2 Munition.cc 3 ReplenishingMunition.cc 3 4 Weapon.cc 4 5 WeaponMode.cc -
code/trunk/src/orxonox/weaponsystem/Munition.cc
r9667 r11052 24 24 * Fabian 'x3n' Landau 25 25 * Co-authors: 26 * ...26 * Fabien Vultier 27 27 * 28 28 */ … … 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/command/Executor.h" 34 #include "core/XMLPort.h" 34 35 35 36 namespace orxonox … … 43 44 this->maxMunitionPerMagazine_ = 10; 44 45 this->maxMagazines_ = 10; 45 this->magazines_ = 10; 46 47 this->bUseSeparateMagazines_ = false; 48 this->bStackMunition_ = true; 46 this->unassignedMagazines_ = 10; 47 48 this->deployment_ = MunitionDeployment::Stack; 49 49 this->bAllowMunitionRefilling_ = true; 50 50 this->bAllowMultiMunitionRemovementUnderflow_ = true; 51 51 52 this->reloadTime_ = 0; 52 this->reloadTime_ = 0.5f; 53 54 this->lastFilledWeaponMode_ = NULL; 53 55 } 54 56 55 57 Munition::~Munition() 56 58 { 57 for (std::map<WeaponMode*, Magazine*>::iterator it = this-> currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)59 for (std::map<WeaponMode*, Magazine*>::iterator it = this->assignedMagazines_.begin(); it != this->assignedMagazines_.end(); ++it) 58 60 delete it->second; 59 61 } 60 62 63 void Munition::XMLPort(Element& xmlelement, XMLPort::Mode mode) 64 { 65 SUPER(Munition, XMLPort, xmlelement, mode); 66 67 XMLPortParam(Munition, "initialmagazines", setNumMagazines, getNumMagazines, xmlelement, mode); 68 XMLPortParam(Munition, "maxmagazines", setMaxMagazines, getMaxMagazines, xmlelement, mode); 69 XMLPortParam(Munition, "munitionpermagazine", setMaxMunitionPerMagazine, getMaxMunitionPerMagazine, xmlelement, mode); 70 } 71 61 72 Munition::Magazine* Munition::getMagazine(WeaponMode* user) const 62 73 { 63 if ( this->bUseSeparateMagazines_)74 if (deployment_ == MunitionDeployment::Separate) 64 75 { 65 76 // For separated magazines we definitively need a given user … … 68 79 69 80 // Use the map to get the magazine assigned to the given user 70 std::map<WeaponMode*, Magazine*>::const_iterator it = this-> currentMagazines_.find(user);71 if (it != this-> currentMagazines_.end())81 std::map<WeaponMode*, Magazine*>::const_iterator it = this->assignedMagazines_.find(user); 82 if (it != this->assignedMagazines_.end()) 72 83 return it->second; 73 84 } … … 75 86 { 76 87 // We don't use separate magazines for each user, so just take the first magazine 77 if (this-> currentMagazines_.size() > 0)78 return this-> currentMagazines_.begin()->second;88 if (this->assignedMagazines_.size() > 0) 89 return this->assignedMagazines_.begin()->second; 79 90 } 80 91 … … 87 98 if (magazine) 88 99 { 89 if ( this->bStackMunition_)100 if (deployment_ == MunitionDeployment::Stack) 90 101 // With stacked munition every magazine contributes to the total amount 91 return this->maxMunitionPerMagazine_ * this-> magazines_ + magazine->munition_;102 return this->maxMunitionPerMagazine_ * this->unassignedMagazines_ + magazine->munition_; 92 103 else 93 104 // Wihtout stacked munition we just consider the current magazine … … 109 120 unsigned int Munition::getNumMagazines() const 110 121 { 111 if ( this->bStackMunition_)122 if (deployment_ == MunitionDeployment::Stack) 112 123 { 113 124 // If we stack munition and the current magazine is still full, it counts too 114 125 Magazine* magazine = this->getMagazine(0); 115 126 if (magazine && magazine->munition_ == this->maxMunitionPerMagazine_) 116 return this->magazines_ + 1; 117 } 118 119 return this->magazines_; 127 return this->unassignedMagazines_ + 1; 128 } 129 130 return this->unassignedMagazines_; 131 } 132 133 void Munition::setNumMagazines(unsigned int numMagazines) 134 { 135 this->unassignedMagazines_ = numMagazines; 120 136 } 121 137 122 138 unsigned int Munition::getMaxMunition() const 123 139 { 124 if ( this->bStackMunition_)140 if (deployment_ == MunitionDeployment::Stack) 125 141 return this->maxMunitionPerMagazine_ * this->maxMagazines_; 126 142 else … … 135 151 unsigned int munition = magazine->munition_; 136 152 137 // If we stack munition, we con't care about the current magazine - we just need enough munition in total 138 if (this->bStackMunition_) 139 munition += this->maxMunitionPerMagazine_ * this->magazines_; 153 // If we stack munition, we don't care about the current magazine - we just need enough munition in total 154 if (deployment_ == MunitionDeployment::Stack) 155 { 156 munition += this->maxMunitionPerMagazine_ * this->unassignedMagazines_; 157 } 140 158 141 159 if (munition == 0) 160 { 142 161 // Absolutely no munition - no chance to take munition 143 162 return false; 163 } 144 164 else if (this->bAllowMultiMunitionRemovementUnderflow_) 165 { 145 166 // We're not empty AND we allow underflow, so this will always work 146 167 return true; 168 } 147 169 else 170 { 148 171 // We don't allow underflow, so we have to check the amount 149 172 return (munition >= amount); 173 } 174 150 175 } 151 176 return false; … … 169 194 { 170 195 // Not enough munition 171 if ( this->bStackMunition_)196 if (deployment_ == MunitionDeployment::Stack) 172 197 { 173 198 // We stack munition, so just take what we can and then load the next magazine … … 175 200 magazine->munition_ = 0; 176 201 177 if (this->reload( 0))202 if (this->reload(NULL)) 178 203 // Successfully reloaded, continue recursively 179 204 return this->takeMunition(amount, 0); … … 199 224 { 200 225 // As long as we have enough magazines (and don't stack munition) we can reload 201 return (this-> magazines_ > 0 && !this->bStackMunition_);226 return (this->unassignedMagazines_ > 0 && deployment_ != MunitionDeployment::Stack); 202 227 } 203 228 … … 207 232 if (magazine) 208 233 { 209 if ( this->bStackMunition_)234 if (deployment_ == MunitionDeployment::Stack) 210 235 // With stacked munition, we never have to reload 211 236 return false; … … 227 252 228 253 // Check if we actually can reload 229 if (this-> magazines_ == 0)254 if (this->unassignedMagazines_ == 0) 230 255 return false; 231 256 232 257 // If we use separate magazines for each user, we definitively need a user given 233 if ( this->bUseSeparateMagazines_&& !user)258 if (deployment_ == MunitionDeployment::Separate && !user) 234 259 return false; 235 260 236 261 // If we don't use separate magazines, set user to 0 237 if (!this->bUseSeparateMagazines_) 238 user = 0; 262 if (deployment_ != MunitionDeployment::Separate) 263 { 264 user = NULL; 265 } 239 266 240 267 // Remove the current magazine for the given user 241 std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.find(user); 242 if (it != this->currentMagazines_.end()) 243 { 268 std::map<WeaponMode*, Magazine*>::iterator it = this->assignedMagazines_.find(user); 269 if (it != this->assignedMagazines_.end()) 270 { 271 if (it->first == lastFilledWeaponMode_) 272 { 273 lastFilledWeaponMode_ = NULL; 274 } 244 275 delete it->second; 245 this-> currentMagazines_.erase(it);276 this->assignedMagazines_.erase(it); 246 277 } 247 278 248 279 // Load a new magazine 249 this-> currentMagazines_[user] = new Magazine(this, bUseReloadTime);250 this-> magazines_--;280 this->assignedMagazines_[user] = new Magazine(this, bUseReloadTime); 281 this->unassignedMagazines_--; 251 282 252 283 return true; … … 260 291 return false; 261 292 262 if ( this->bStackMunition_)293 if (deployment_ == MunitionDeployment::Stack) 263 294 { 264 295 // If we stack munition, we can always add munition until we reach the limit … … 268 299 { 269 300 // Return true if any of the current magazines is not full (loading counts as full although it returns 0 munition) 270 for (std::map<WeaponMode*, Magazine*>::const_iterator it = this-> currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)301 for (std::map<WeaponMode*, Magazine*>::const_iterator it = this->assignedMagazines_.begin(); it != this->assignedMagazines_.end(); ++it) 271 302 if (it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_) 272 303 return true; … … 281 312 return false; 282 313 283 if ( this->bStackMunition_)314 if (deployment_ == MunitionDeployment::Stack) 284 315 { 285 316 // Stacking munition means, if a magazine gets full, the munition adds to a new magazine 286 Magazine* magazine = this->getMagazine( 0);317 Magazine* magazine = this->getMagazine(NULL); 287 318 if (magazine) 288 319 { … … 294 325 { 295 326 magazine->munition_ -= this->maxMunitionPerMagazine_; 296 this-> magazines_++;327 this->unassignedMagazines_++; 297 328 } 298 329 299 // If we reached the limit, redu ze both magazines and munition to the maximum300 if (this-> magazines_ >= this->maxMagazines_)301 { 302 this-> magazines_ = this->maxMagazines_ - 1;330 // If we reached the limit, reduce both magazines and munition to the maximum 331 if (this->unassignedMagazines_ >= this->maxMagazines_) 332 { 333 this->unassignedMagazines_ = this->maxMagazines_; 303 334 magazine->munition_ = this->maxMunitionPerMagazine_; 304 335 } … … 312 343 else 313 344 { 345 std::map<WeaponMode*, Magazine*>::iterator it; 346 347 // If the pointer to the weapon mode whose magazine got munition added to is NULL, then set the iterator to the beginning of the map 348 // Otherwise set it to the next weapon mode 349 if (lastFilledWeaponMode_ == NULL) 350 { 351 it = this->assignedMagazines_.begin(); 352 } 353 else 354 { 355 it = this->assignedMagazines_.find(lastFilledWeaponMode_); 356 ++ it; 357 } 358 314 359 // Share the munition equally to the current magazines 360 bool firstLoop = true; 315 361 while (amount > 0) 316 362 { 317 363 bool change = false; 318 for (std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it)364 while (it != this->assignedMagazines_.end()) 319 365 { 320 366 // Add munition if the magazine isn't full (but only to loaded magazines) … … 323 369 it->second->munition_++; 324 370 amount--; 371 lastFilledWeaponMode_ = it->first; 325 372 change = true; 326 373 } 374 375 ++it; 327 376 } 328 377 329 378 // If there was no change in a loop, all magazines are full (or locked due to loading) 330 if (!change) 379 // Because the first loop does not start at the beginning of the map we have to treat is separately 380 if (!change && !firstLoop) 381 { 331 382 break; 383 } 384 385 it = this->assignedMagazines_.begin(); 386 firstLoop = false; 332 387 } 333 388 … … 340 395 // TODO: 'amount' is not used 341 396 342 if ( this->bStackMunition_)397 if (deployment_ == MunitionDeployment::Stack) 343 398 // If we stack munition, we can always add new magazines because they contribute directly to the munition 344 399 return (this->getNumMunition(0) < this->getMaxMunition()); 345 400 else 346 401 // If we don't stack munition, we're more limited 347 return ((this->currentMagazines_.size() + this->magazines_) < this->maxMagazines_); 348 } 349 350 bool Munition::addMagazines(unsigned int amount) 351 { 402 return ((this->assignedMagazines_.size() + this->unassignedMagazines_) < this->maxMagazines_); 403 } 404 405 unsigned int Munition::addMagazines(unsigned int amount) 406 { 407 unsigned int addedMagazines = 0; 408 352 409 if (!this->canAddMagazines(amount)) 353 return false;410 return 0; 354 411 355 412 // Calculate how many magazines are needed 356 int needed_magazines = this->maxMagazines_ - this-> magazines_ - this->currentMagazines_.size();413 int needed_magazines = this->maxMagazines_ - this->unassignedMagazines_ - this->assignedMagazines_.size(); 357 414 358 415 // If zero or less magazines are needed, we definitively don't need more magazines (unless we stack munition - then a magazine contributes directly to the munition) 359 if (needed_magazines <= 0 && !this->bStackMunition_)360 return false;416 if (needed_magazines <= 0 && deployment_ != MunitionDeployment::Stack) 417 return 0; 361 418 362 419 if (amount <= static_cast<unsigned int>(needed_magazines)) 363 420 { 364 421 // We need more magazines than we get, so just add them 365 this->magazines_ += amount; 422 this->unassignedMagazines_ += amount; 423 addedMagazines = amount; 366 424 } 367 425 else 368 426 { 369 427 // We get more magazines than we need, so just add the needed amount 370 this->magazines_ += needed_magazines; 371 if (this->bStackMunition_) 428 this->unassignedMagazines_ += needed_magazines; 429 addedMagazines = needed_magazines; 430 if (deployment_ == MunitionDeployment::Stack) 372 431 { 373 432 // We stack munition, so the additional amount contributes directly to the munition of the current magazine … … 378 437 } 379 438 380 return true; 439 // Reload as many empty magazines as possible 440 // Double loop and break is needed because the reload function changes the assigned magazines. This may confuse the iterator. 441 for (unsigned int i = 0; i < addedMagazines; ++i) 442 { 443 for (std::map<WeaponMode*, Magazine*>::iterator it = this->assignedMagazines_.begin(); it != this->assignedMagazines_.end(); ++it) 444 { 445 if (needReload(it->first)) 446 { 447 reload(it->first); 448 break; 449 } 450 } 451 } 452 453 return addedMagazines; 381 454 } 382 455 383 456 bool Munition::canRemoveMagazines(unsigned int amount) const 384 457 { 385 if ( this->bStackMunition_)386 { 387 if (this-> magazines_ >= amount)458 if (deployment_ == MunitionDeployment::Stack) 459 { 460 if (this->unassignedMagazines_ >= amount) 388 461 { 389 462 // We have enough magazines 390 463 return true; 391 464 } 392 else if (this-> magazines_ == amount - 1)465 else if (this->unassignedMagazines_ == amount - 1) 393 466 { 394 467 // We lack one magazine, check if the current magazine is still full, if yes we're fine … … 406 479 { 407 480 // In case we're not stacking munition, just check the number of magazines 408 return (this-> magazines_ >= amount);481 return (this->unassignedMagazines_ >= amount); 409 482 } 410 483 … … 417 490 return false; 418 491 419 if (this-> magazines_ >= amount)492 if (this->unassignedMagazines_ >= amount) 420 493 { 421 494 // We have enough magazines, just remove the amount 422 this-> magazines_ -= amount;423 } 424 else if ( this->bStackMunition_)495 this->unassignedMagazines_ -= amount; 496 } 497 else if (deployment_ == MunitionDeployment::Stack) 425 498 { 426 499 // We don't have enough magazines, but we're stacking munition, so additionally remove the bullets from the current magazine 427 this-> magazines_ = 0;500 this->unassignedMagazines_ = 0; 428 501 Magazine* magazine = this->getMagazine(0); 429 502 if (magazine) … … 437 510 { 438 511 // If we use separate magazines, we need a user 439 if ( this->bUseSeparateMagazines_&& !user)512 if (deployment_ == MunitionDeployment::Separate && !user) 440 513 return false; 441 514 442 515 // If we don't use separate magazines, set user to 0 443 if ( !this->bUseSeparateMagazines_)444 user = 0;516 if (deployment_ != MunitionDeployment::Separate) 517 user = NULL; 445 518 446 519 // Remove the current magazine for the given user 447 std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.find(user); 448 if (it != this->currentMagazines_.end()) 449 { 520 std::map<WeaponMode*, Magazine*>::iterator it = this->assignedMagazines_.find(user); 521 if (it != this->assignedMagazines_.end()) 522 { 523 if (it->first == lastFilledWeaponMode_) 524 { 525 lastFilledWeaponMode_ = NULL; 526 } 450 527 delete it->second; 451 this-> currentMagazines_.erase(it);528 this->assignedMagazines_.erase(it); 452 529 return true; 453 530 } … … 465 542 this->bLoaded_ = false; 466 543 467 if (bUseReloadTime && munition->reloadTime_ > 0 && !munition->bStackMunition_)544 if (bUseReloadTime && munition->reloadTime_ > 0 && munition->deployment_ != MunitionDeployment::Stack) 468 545 { 469 546 const ExecutorPtr& executor = createExecutor(createFunctor(&Magazine::loaded, this)); -
code/trunk/src/orxonox/weaponsystem/Munition.h
r9667 r11052 24 24 * Fabian 'x3n' Landau 25 25 * Co-authors: 26 * ...26 * Fabien Vultier 27 27 * 28 28 */ … … 39 39 namespace orxonox 40 40 { 41 namespace MunitionDeployment 42 { 43 enum Value 44 { 45 Separate, // Every comsuming weapon mode has its own magazine. It is possible that one weapon mode is out of ammo while another still has some. 46 Share, // All comsuming weapon modes take their munition from the same magazine. If this magazine is empty a new one is loaded. 47 Stack // There is only one magazine where all the munition is stored. Use this deployment mode for heavy weapons loke rockets, bombs, ... 48 }; 49 } 50 41 51 class _OrxonoxExport Munition : public BaseObject 42 { 52 { 43 53 struct Magazine 44 54 { … … 59 69 virtual ~Munition(); 60 70 71 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 72 61 73 unsigned int getNumMunition(WeaponMode* user) const; 62 74 unsigned int getNumMunitionInCurrentMagazine(WeaponMode* user) const; … … 68 80 inline unsigned int getMaxMunitionPerMagazine() const 69 81 { return this->maxMunitionPerMagazine_; } 82 inline MunitionDeployment::Value getMunitionDeployment() const 83 { return deployment_; } 84 70 85 71 86 bool canTakeMunition(unsigned int amount, WeaponMode* user) const; … … 82 97 83 98 bool canAddMagazines(unsigned int amount) const; 84 bool addMagazines(unsigned int amount); 99 /** 100 @brief Try to add magazines. 101 @param amount The amount of magazines tried to add. 102 @return The amount of magazines sucessfully added. 103 */ 104 unsigned int addMagazines(unsigned int amount); 85 105 86 106 bool canRemoveMagazines(unsigned int amount) const; … … 92 112 unsigned int maxMunitionPerMagazine_; 93 113 unsigned int maxMagazines_; 94 unsigned int magazines_;95 std::map<WeaponMode*, Magazine*> currentMagazines_;114 unsigned int unassignedMagazines_; // Number of magazines that are not assigned to a weapon mode. These are alway treated as full. 115 std::map<WeaponMode*, Magazine*> assignedMagazines_; // Maps weapon modes to magazines that are currently used. 96 116 97 bool bUseSeparateMagazines_;98 bool bStackMunition_; 117 MunitionDeployment::Value deployment_; // Defines the behaviour how munition and magazines are distributed to the consuming weapon modes. 118 99 119 bool bAllowMunitionRefilling_; 100 120 bool bAllowMultiMunitionRemovementUnderflow_; 101 121 102 float reloadTime_; 122 float reloadTime_; // The time needed to replace a magazine by a new one. 123 WeaponMode* lastFilledWeaponMode_; // Pointer to the weapon mode that got the last munition during the last call of addMunition. 103 124 104 125 private: 105 126 Magazine* getMagazine(WeaponMode* user) const; 127 inline void setMaxMagazines(unsigned int maxMagazines) 128 { this->maxMagazines_ = maxMagazines; } 129 inline void setMaxMunitionPerMagazine(unsigned int maxMunitionPerMagazine) 130 { this->maxMunitionPerMagazine_ = maxMunitionPerMagazine; } 131 void setNumMagazines(unsigned int numMagazines); 106 132 }; 107 133 } -
code/trunk/src/orxonox/weaponsystem/Weapon.cc
r10650 r11052 134 134 } 135 135 136 /** 137 @brief 138 Reload all @ref orxonox::WeaponMode weapon modes of this weapon. 139 */ 136 140 void Weapon::reload() 137 141 { … … 151 155 it->second->setWeapon(this); 152 156 } 157 158 void Weapon::updateMunition() 159 { 160 for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it) 161 it->second->updateMunition(); 162 } 153 163 } -
code/trunk/src/orxonox/weaponsystem/Weapon.h
r10650 r11052 57 57 void addWeaponmode(WeaponMode* weaponmode); 58 58 WeaponMode* getWeaponmode(unsigned int index) const; 59 inline std::multimap<unsigned int, WeaponMode*>* getAllWeaponmodes() 60 { return &weaponmodes_; } 61 inline int getNumWeaponModes() const 62 { return weaponmodes_.size(); } 59 63 60 64 /** … … 75 79 inline WeaponSlot * getWeaponSlot() const 76 80 { return this->weaponSlot_; } 81 void updateMunition(); 77 82 78 83 private: -
code/trunk/src/orxonox/weaponsystem/WeaponMode.cc
r10650 r11052 75 75 this->muzzleOrientation_ = Quaternion::IDENTITY; 76 76 77 hudImageString_ = "Orxonox/WSHUD_WM_Unknown"; 78 77 79 if( GameMode::isMaster() ) 78 80 { … … 125 127 this->bSoundAttached_ = true; 126 128 } 127 129 130 // Fireing is only possible if this weapon mode is not reloading and there is enough munition 128 131 if (!this->bReloading_ && this->munition_ && this->munition_->takeMunition(this->munitionPerShot_, this)) 129 132 { … … 134 137 if (this->munition_->reload(this)) 135 138 { 139 // If true, the weapon reloads in parallel to the magazine reloading 136 140 if (this->bParallelReload_) 141 { 142 // The time needed to reload is the maximum of the reload time of the weapon mode and the magazine. 137 143 tempReloadtime = std::max(this->reloadTime_, this->munition_->getReloadTime()); 144 } 138 145 else 146 { 147 // The time needed to reload is the sum of the reload time of the weapon mode and the magazine. 139 148 tempReloadtime = this->reloadTime_ + this->munition_->getReloadTime(); 149 } 140 150 } 141 151 } 142 152 153 // Mark this weapon mode as reloading and start the reload timer 143 154 this->bReloading_ = true; 144 155 this->reloadTimer_.setInterval(tempReloadtime); … … 232 243 } 233 244 else 234 this->munition_ = 0; 245 { 246 this->munition_ = NULL; 247 } 235 248 } 236 249 … … 283 296 } 284 297 285 void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume){ 286 if (this->defSndWpnFire_) { 298 void WeaponMode::setDefaultSoundWithVolume(const std::string& soundPath, const float soundVolume) 299 { 300 if (this->defSndWpnFire_) 301 { 287 302 this->defSndWpnFire_->setSource(soundPath); 288 303 this->defSndWpnFire_->setVolume(soundVolume); -
code/trunk/src/orxonox/weaponsystem/WeaponMode.h
r10650 r11052 38 38 #include "core/class/SubclassIdentifier.h" 39 39 #include "tools/Timer.h" 40 #include "Munition.h" 40 41 41 42 namespace orxonox … … 104 105 inline bool getParallelReload() const 105 106 { return this->bParallelReload_; } 107 inline bool getReloading() const 108 { return this->bReloading_; } 106 109 107 110 … … 147 150 Vector3 getTarget(); 148 151 152 inline const std::string& getHUDImageString() const 153 { return this->hudImageString_; } 154 155 void updateMunition(); 149 156 protected: 150 157 virtual void fire() = 0; … … 155 162 156 163 float reloadTime_; 157 bool bAutoReload_; 158 bool bParallelReload_; 164 bool bAutoReload_; // If true, the weapon reloads the magazine automatically. 165 bool bParallelReload_; // If true, the weapon reloads in parallel to the magazine reloading. 159 166 160 167 float damage_; … … 163 170 Vector3 muzzleOffset_; 164 171 165 private: 166 void updateMunition(); 172 std::string hudImageString_; 173 174 private: 167 175 void reloaded(); 168 176 … … 175 183 176 184 Timer reloadTimer_; 177 bool bReloading_; 185 bool bReloading_; // If true, this weapon mode is marked as reloading. 178 186 179 187 Vector3 muzzlePosition_; … … 181 189 182 190 WorldSound* defSndWpnFire_; 183 bool 191 bool bSoundAttached_; 184 192 }; 185 193 } -
code/trunk/src/orxonox/weaponsystem/WeaponPack.cc
r10650 r11052 124 124 } 125 125 126 std::vector<Weapon*>* WeaponPack::getAllWeapons() 127 { 128 return &weapons_; 129 } 130 126 131 void WeaponPack::addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link) 127 132 { … … 156 161 (*it)->setWeaponPack(this); 157 162 } 163 164 void WeaponPack::updateMunition() 165 { 166 for (std::vector<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 167 (*it)->updateMunition(); 168 } 158 169 } -
code/trunk/src/orxonox/weaponsystem/WeaponPack.h
r9667 r11052 52 52 void removeWeapon(Weapon * weapon); 53 53 Weapon * getWeapon(unsigned int index) const; 54 std::vector<Weapon*>* getAllWeapons(); 54 55 55 56 inline size_t getNumWeapons() const … … 65 66 inline WeaponSystem * getWeaponSystem() const 66 67 { return this->weaponSystem_; } 68 void updateMunition(); 67 69 68 70 private: -
code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc
r10650 r11052 240 240 } 241 241 242 std::vector<WeaponPack *> * WeaponSystem::getAllWeaponPacks() 243 { 244 return &weaponPacks_; 245 } 246 242 247 bool WeaponSystem::swapWeaponSlots(WeaponSlot * wSlot1, WeaponSlot * wSlot2) 243 248 { … … 310 315 return it->second; 311 316 } 312 else if (identifier->getIdentifier()->isA(Class(Munition)))313 {314 Munition* munition = identifier->fabricate(this->getContext());315 this->munitions_[identifier->getIdentifier()] = munition;316 return munition;317 }318 317 else 319 318 { 320 return 0; 319 return NULL; 320 } 321 } 322 323 void WeaponSystem::addMunition(Munition* munition) 324 { 325 if (munition == NULL) 326 { 327 return; 328 } 329 330 SubclassIdentifier<Munition> identifier = munition->getIdentifier(); 331 332 if (identifier) 333 { 334 this->munitions_[identifier] = munition; 335 updateMunition(); 336 } 337 else 338 { 339 orxout(internal_warning) << "Adding munition failed. identifier == NULL " << endl; 340 } 341 } 342 343 void WeaponSystem::updateMunition() 344 { 345 for (std::vector<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); ++it) 346 { 347 (*it)->updateMunition(); 321 348 } 322 349 } -
code/trunk/src/orxonox/weaponsystem/WeaponSystem.h
r10650 r11052 67 67 void removeWeaponPack(WeaponPack * wPack); 68 68 WeaponPack * getWeaponPack(unsigned int index) const; 69 std::vector<WeaponPack *> * getAllWeaponPacks(); 69 70 70 71 // configure slots and firemodes … … 76 77 77 78 Munition * getMunition(SubclassIdentifier<Munition> * identifier); 79 void addMunition(Munition* munition); 78 80 79 81 inline void setPawn(Pawn * pawn) … … 95 97 96 98 private: 99 void updateMunition(); 100 97 101 std::map<unsigned int, WeaponSet *> weaponSets_; 98 102 std::vector<WeaponSlot *> weaponSlots_; -
code/trunk/src/orxonox/worldentities/CMakeLists.txt
r8706 r11052 6 6 ControllableEntity.cc 7 7 Drone.cc 8 BigExplosion.cc9 8 EffectContainer.cc 10 9 ExplosionChunk.cc … … 12 11 SpawnPoint.cc 13 12 TeamSpawnPoint.cc 13 ExplosionPart.cc 14 Actionpoint.cc 14 15 ) 15 16 -
code/trunk/src/orxonox/worldentities/MobileEntity.h
r10437 r11052 47 47 linear velocity. Then the linear velocity is multiplied by the time since the last call of tick and then added to the position. The same happens with 48 48 the angular acceleration and velocity. With this procedure MobileEntities can change their position and orientation with time. 49 50 A MobileEntity can only have the collisition type WorldEntity::None, WorldEntity::Dynamic or WorldEntity::Kinematic. The collsion type WorldEntity::Static is illegal. 49 51 */ 50 52 -
code/trunk/src/orxonox/worldentities/SpawnPoint.h
r9667 r11052 55 55 { return this->template_; } 56 56 57 Pawn* spawn();57 virtual Pawn* spawn(); 58 58 void spawn(ControllableEntity* entity); 59 59 -
code/trunk/src/orxonox/worldentities/StaticEntity.h
r10437 r11052 44 44 it is called StaticEntity. It will keep the same position (always with respect to its parent) forever unless you call the 45 45 function @see setPosition to changee it. 46 47 A StaticEntity can only have the collisition type WorldEntity::None or WorldEntity::Static. The collsion types WorldEntity::Dynamic and WorldEntity::Kinematic are illegal. 46 48 */ 47 49 -
code/trunk/src/orxonox/worldentities/TeamSpawnPoint.cc
r9667 r11052 49 49 XMLPortParam(TeamSpawnPoint, "team", setTeamNumber, getTeamNumber, xmlelement, mode).defaultValues(0); 50 50 } 51 Pawn* TeamSpawnPoint::spawn() 52 { 53 Pawn* entity = SpawnPoint::spawn(); 54 static_cast<ControllableEntity*>(entity)->setTeam (this->teamNumber_); 55 return entity; 56 } 51 57 } -
code/trunk/src/orxonox/worldentities/TeamSpawnPoint.h
r9667 r11052 49 49 unsigned int getTeamNumber() const 50 50 { return this->teamNumber_; } 51 virtual Pawn* spawn(); 51 52 52 53 private: 53 unsignedint teamNumber_;54 int teamNumber_; 54 55 }; 55 56 } -
code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
r10650 r11052 34 34 #include "core/GameMode.h" 35 35 #include "core/XMLPort.h" 36 #include "core/EventIncludes.h" 36 37 #include "network/NetworkFunction.h" 37 38 … … 41 42 #include "graphics/ParticleSpawner.h" 42 43 #include "worldentities/ExplosionChunk.h" 43 #include "worldentities/ BigExplosion.h"44 #include "worldentities/ExplosionPart.h" 44 45 #include "weaponsystem/WeaponSystem.h" 45 46 #include "weaponsystem/WeaponSlot.h" 46 47 #include "weaponsystem/WeaponPack.h" 47 48 #include "weaponsystem/WeaponSet.h" 49 #include "weaponsystem/Munition.h" 48 50 #include "sound/WorldSound.h" 49 51 … … 61 63 62 64 this->bAlive_ = true; 63 this->b Reload_ = false;65 this->bVulnerable_ = true; 64 66 65 67 this->health_ = 0; … … 71 73 this->maxShieldHealth_ = 100; //otherwise shield might increase to float_max 72 74 this->shieldAbsorption_ = 0.5; 73 74 this->reloadRate_ = 0; 75 this->reloadWaitTime_ = 1.0f; 76 this->reloadWaitCountdown_ = 0; 75 this->shieldRechargeRate_ = 0; 76 this->shieldRechargeWaitTime_ = 1.0f; 77 this->shieldRechargeWaitCountdown_ = 0; 77 78 78 79 this->lastHitOriginator_ = 0; … … 84 85 85 86 this->aimPosition_ = Vector3::ZERO; 87 88 //this->explosionPartList_ = NULL; 86 89 87 90 if (GameMode::isMaster()) … … 135 138 XMLPortParam(Pawn, "shieldabsorption", setShieldAbsorption, getShieldAbsorption, xmlelement, mode).defaultValues(0); 136 139 140 XMLPortParam(Pawn, "vulnerable", setVulnerable, isVulnerable, xmlelement, mode).defaultValues(true); 141 137 142 XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode); 138 143 XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f); 139 XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues( 7);144 XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(0); 140 145 141 146 XMLPortObject(Pawn, WeaponSlot, "weaponslots", addWeaponSlot, getWeaponSlot, xmlelement, mode); 142 147 XMLPortObject(Pawn, WeaponSet, "weaponsets", addWeaponSet, getWeaponSet, xmlelement, mode); 143 XMLPortObject(Pawn, WeaponPack, "weapons", addWeaponPackXML, getWeaponPack, xmlelement, mode); 144 145 XMLPortParam(Pawn, "reloadrate", setReloadRate, getReloadRate, xmlelement, mode).defaultValues(0); 146 XMLPortParam(Pawn, "reloadwaittime", setReloadWaitTime, getReloadWaitTime, xmlelement, mode).defaultValues(1.0f); 148 XMLPortObject(Pawn, WeaponPack, "weaponpacks", addWeaponPackXML, getWeaponPack, xmlelement, mode); 149 XMLPortObject(Pawn, Munition, "munition", addMunitionXML, getMunitionXML, xmlelement, mode); 150 151 XMLPortObject(Pawn, ExplosionPart, "explosion", addExplosionPart, getExplosionPart, xmlelement, mode); 152 XMLPortParam(Pawn, "shieldrechargerate", setShieldRechargeRate, getShieldRechargeRate, xmlelement, mode).defaultValues(0); 153 XMLPortParam(Pawn, "shieldrechargewaittime", setShieldRechargeWaitTime, getShieldRechargeWaitTime, xmlelement, mode).defaultValues(1.0f); 147 154 148 155 XMLPortParam(Pawn, "explosionSound", setExplosionSound, getExplosionSound, xmlelement, mode); … … 151 158 } 152 159 160 void Pawn::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 161 { 162 SUPER(Pawn, XMLEventPort, xmlelement, mode); 163 164 XMLPortEventState(Pawn, BaseObject, "vulnerability", setVulnerable, xmlelement, mode); 165 } 166 153 167 void Pawn::registerVariables() 154 168 { 155 registerVariable(this->bAlive_, VariableDirection::ToClient); 156 registerVariable(this->health_, VariableDirection::ToClient); 157 registerVariable(this->maxHealth_, VariableDirection::ToClient); 158 registerVariable(this->shieldHealth_, VariableDirection::ToClient); 159 registerVariable(this->maxShieldHealth_, VariableDirection::ToClient); 160 registerVariable(this->shieldAbsorption_, VariableDirection::ToClient); 161 registerVariable(this->bReload_, VariableDirection::ToServer); 162 registerVariable(this->aimPosition_, VariableDirection::ToServer); // For the moment this variable gets only transfered to the server 169 registerVariable(this->bAlive_, VariableDirection::ToClient); 170 registerVariable(this->health_, VariableDirection::ToClient); 171 registerVariable(this->maxHealth_, VariableDirection::ToClient); 172 registerVariable(this->shieldHealth_, VariableDirection::ToClient); 173 registerVariable(this->maxShieldHealth_, VariableDirection::ToClient); 174 registerVariable(this->shieldAbsorption_, VariableDirection::ToClient); 175 registerVariable(this->aimPosition_, VariableDirection::ToServer); // For the moment this variable gets only transfered to the server 163 176 } 164 177 165 178 void Pawn::tick(float dt) 166 179 { 180 //BigExplosion* chunk = new BigExplosion(this->getContext()); 167 181 SUPER(Pawn, tick, dt); 168 182 169 this->bReload_ = false; 170 183 // Recharge the shield 171 184 // TODO: use the existing timer functions instead 172 if(this-> reloadWaitCountdown_ > 0)173 { 174 this->decrease ReloadCountdownTime(dt);175 } 176 else 177 { 178 this->addShieldHealth(this->get ReloadRate() * dt);179 this->reset ReloadCountdown();185 if(this->shieldRechargeWaitCountdown_ > 0) 186 { 187 this->decreaseShieldRechargeCountdownTime(dt); 188 } 189 else 190 { 191 this->addShieldHealth(this->getShieldRechargeRate() * dt); 192 this->resetShieldRechargeCountdown(); 180 193 } 181 194 … … 229 242 } 230 243 231 void Pawn::setReloadRate(float reloadrate) 232 { 233 this->reloadRate_ = reloadrate; 234 } 235 236 void Pawn::setReloadWaitTime(float reloadwaittime) 237 { 238 this->reloadWaitTime_ = reloadwaittime; 239 } 240 241 void Pawn::decreaseReloadCountdownTime(float dt) 242 { 243 this->reloadWaitCountdown_ -= dt; 244 void Pawn::setShieldRechargeRate(float shieldRechargeRate) 245 { 246 this->shieldRechargeRate_ = shieldRechargeRate; 247 } 248 249 void Pawn::setShieldRechargeWaitTime(float shieldRechargeWaitTime) 250 { 251 this->shieldRechargeWaitTime_ = shieldRechargeWaitTime; 252 } 253 254 void Pawn::decreaseShieldRechargeCountdownTime(float dt) 255 { 256 this->shieldRechargeWaitCountdown_ -= dt; 257 } 258 259 void Pawn::changedVulnerability() 260 { 261 244 262 } 245 263 246 264 void Pawn::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs) 247 265 { 266 // A pawn can only get damaged if it is vulnerable 267 if (!isVulnerable()) 268 { 269 return; 270 } 271 248 272 // Applies multiplier given by the DamageBoost Pickup. 249 273 if (originator) … … 252 276 if (this->getGametype() && this->getGametype()->allowPawnDamage(this, originator)) 253 277 { 278 // Health-damage cannot be absorbed by shields. 279 // Shield-damage only reduces shield health. 280 // Normal damage can be (partially) absorbed by shields. 281 254 282 if (shielddamage >= this->getShieldHealth()) 255 283 { … … 366 394 if (GameMode::isMaster()) 367 395 { 368 this->deatheffect();369 396 this->goWithStyle(); 370 397 } … … 373 400 void Pawn::goWithStyle() 374 401 { 402 375 403 this->bAlive_ = false; 376 404 this->setDestroyWhenPlayerLeft(false); 377 405 378 BigExplosion* chunk = new BigExplosion(this->getContext()); 379 chunk->setPosition(this->getPosition()); 380 chunk->setVelocity(this->getVelocity()); 406 while(!explosionPartList_.empty()) 407 { 408 explosionPartList_.back()->setPosition(this->getPosition()); 409 explosionPartList_.back()->setVelocity(this->getVelocity()); 410 explosionPartList_.back()->setOrientation(this->getOrientation()); 411 explosionPartList_.back()->Explode(); 412 explosionPartList_.pop_back(); 413 } 414 415 for (unsigned int i = 0; i < this->numexplosionchunks_; ++i) 416 { 417 ExplosionChunk* chunk = new ExplosionChunk(this->getContext()); 418 chunk->setPosition(this->getPosition()); 419 } 381 420 382 421 this->explosionSound_->setPosition(this->getPosition()); 383 422 this->explosionSound_->play(); 384 }385 void Pawn::deatheffect()386 {387 // play death effect388 /*{389 ParticleSpawner* effect = new ParticleSpawner(this->getContext());390 effect->setPosition(this->getPosition());391 effect->setOrientation(this->getOrientation());392 effect->setDestroyAfterLife(true);393 effect->setSource("Orxonox/explosion2b");394 effect->setLifetime(4.0f);395 }396 {397 ParticleSpawner* effect = new ParticleSpawner(this->getContext());398 effect->setPosition(this->getPosition());399 effect->setOrientation(this->getOrientation());400 effect->setDestroyAfterLife(true);401 effect->setSource("Orxonox/smoke6");402 effect->setLifetime(4.0f);403 }404 {405 ParticleSpawner* effect = new ParticleSpawner(this->getContext());406 effect->setPosition(this->getPosition());407 effect->setOrientation(this->getOrientation());408 effect->setDestroyAfterLife(true);409 effect->setSource("Orxonox/sparks");410 effect->setLifetime(4.0f);411 }*/412 413 414 {415 ParticleSpawner* effect = new ParticleSpawner(this->getContext());416 effect->setPosition(this->getPosition());417 effect->setOrientation(this->getOrientation());418 effect->setDestroyAfterLife(true);419 effect->setSource("orxonox/explosion_flash2");420 effect->setLifetime(5.0f);421 }422 {423 ParticleSpawner* effect = new ParticleSpawner(this->getContext());424 effect->setPosition(this->getPosition());425 effect->setOrientation(this->getOrientation());426 effect->setDestroyAfterLife(true);427 effect->setSource("orxonox/explosion_flame2");428 effect->setLifetime(5.0f);429 }430 {431 ParticleSpawner* effect = new ParticleSpawner(this->getContext());432 effect->setPosition(this->getPosition());433 effect->setOrientation(this->getOrientation());434 effect->setDestroyAfterLife(true);435 effect->setSource("orxonox/explosion_shockwave2");436 effect->scale(20);437 effect->setLifetime(5.0f);438 }{439 ParticleSpawner* effect = new ParticleSpawner(this->getContext());440 effect->setPosition(this->getPosition());441 effect->setOrientation(this->getOrientation());442 effect->setDestroyAfterLife(true);443 effect->setSource("orxonox/explosion_sparks2");444 effect->setLifetime(5.0f);445 }446 {447 ParticleSpawner* effect = new ParticleSpawner(this->getContext());448 effect->setPosition(this->getPosition());449 effect->setOrientation(this->getOrientation());450 effect->setDestroyAfterLife(true);451 effect->setSource("orxonox/explosion_streak2");452 effect->setLifetime(5.0f);453 }454 {455 ParticleSpawner* effect = new ParticleSpawner(this->getContext());456 effect->setPosition(this->getPosition());457 effect->setOrientation(this->getOrientation());458 effect->setDestroyAfterLife(true);459 effect->setSource("orxonox/explosion_afterglow");460 effect->scale(20);461 effect->setLifetime(5.0f);462 }463 464 465 for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)466 {467 ExplosionChunk* chunk = new ExplosionChunk(this->getContext());468 chunk->setPosition(this->getPosition());469 }470 423 } 471 424 … … 474 427 Check whether the Pawn has a @ref Orxonox::WeaponSystem and fire it with the specified firemode if it has one. 475 428 */ 429 476 430 void Pawn::fired(unsigned int firemode) 477 431 { 478 432 if (this->weaponSystem_) 479 433 this->weaponSystem_->fire(firemode); 480 }481 482 void Pawn::reload()483 {484 this->bReload_ = true;485 434 } 486 435 … … 491 440 this->spawneffect(); 492 441 } 442 443 444 void Pawn::addExplosionPart(ExplosionPart* ePart) 445 {this->explosionPartList_.push_back(ePart);} 446 447 448 ExplosionPart * Pawn::getExplosionPart() 449 {return this->explosionPartList_.back();} 450 451 493 452 494 453 /* WeaponSystem: … … 554 513 } 555 514 515 std::vector<WeaponPack *> * Pawn::getAllWeaponPacks() 516 { 517 if (this->weaponSystem_) 518 return this->weaponSystem_->getAllWeaponPacks(); 519 else 520 return 0; 521 } 522 523 void Pawn::addMunitionXML(Munition* munition) 524 { 525 if (this->weaponSystem_ && munition) 526 { 527 this->weaponSystem_->addMunition(munition); 528 } 529 } 530 531 Munition* Pawn::getMunitionXML() const 532 { 533 return NULL; 534 } 535 536 Munition* Pawn::getMunition(SubclassIdentifier<Munition> * identifier) 537 { 538 if (weaponSystem_) 539 { 540 return weaponSystem_->getMunition(identifier); 541 } 542 543 return NULL; 544 } 545 556 546 //Tell the Map (RadarViewable), if this is a playership 557 547 void Pawn::startLocalHumanControl() 558 548 { 559 // SUPER(ControllableEntity, changedPlayer());549 // SUPER(ControllableEntity, startLocalHumanControl()); 560 550 ControllableEntity::startLocalHumanControl(); 561 551 this->isHumanShip_ = true; -
code/trunk/src/orxonox/worldentities/pawns/Pawn.h
r10437 r11052 33 33 34 34 #include <string> 35 #include <vector> 35 36 #include "interfaces/PickupCarrier.h" 36 37 #include "interfaces/RadarViewable.h" 37 38 #include "worldentities/ControllableEntity.h" 39 #include "worldentities/ExplosionPart.h" 38 40 39 41 … … 42 44 /** 43 45 @brief 44 Everything in Orxono ythat has a health attribute is a Pawn. After a Pawn is spawned its health is set to46 Everything in Orxonox that has a health attribute is a Pawn. After a Pawn is spawned its health is set to 45 47 its initial health. In every call of the Pawns tick function the game checks whether the pawns health is at 46 48 or below zero. If it is, the pawn gets killed. 47 49 48 Pawns can carry pickups and fire weapons. The can also have shields.50 Pawns can carry pickups and fire weapons. They can also have shields. 49 51 50 52 Notice that every Pawn is a ControllableEntity. … … 62 64 63 65 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 66 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 64 67 virtual void tick(float dt); 65 68 … … 116 119 { return this->shieldAbsorption_; } 117 120 118 // TODO: Rename to shieldRechargeRate 119 virtual void setReloadRate(float reloadrate); 120 inline float getReloadRate() const 121 { return this->reloadRate_; } 122 123 virtual void setReloadWaitTime(float reloadwaittime); 124 inline float getReloadWaitTime() const 125 { return this->reloadWaitTime_; } 126 127 inline void resetReloadCountdown() 128 { this->reloadWaitCountdown_ = 0; } 129 130 inline void startReloadCountdown() 131 { this->reloadWaitCountdown_ = this->getReloadWaitTime(); } // TODO: Implement in Projectile.cc 132 133 virtual void decreaseReloadCountdownTime(float dt); 121 virtual void setShieldRechargeRate(float shieldRechargeRate); 122 inline float getShieldRechargeRate() const 123 { return this->shieldRechargeRate_; } 124 125 virtual void setShieldRechargeWaitTime(float shieldRechargeWaitTime); 126 inline float getShieldRechargeWaitTime() const 127 { return this->shieldRechargeWaitTime_; } 128 129 inline void resetShieldRechargeCountdown() 130 { this->shieldRechargeWaitCountdown_ = 0; } 131 132 inline void startShieldRechargeCountdown() 133 { this->shieldRechargeWaitCountdown_ = this->getShieldRechargeWaitTime(); } // TODO: Implement in Projectile.cc 134 135 virtual void decreaseShieldRechargeCountdownTime(float dt); 136 137 /** @brief Sets the state of the pawns vulnerability. @param bVulnerable */ 138 inline void setVulnerable(bool bVulnerable) 139 { 140 if (this->bVulnerable_ != bVulnerable) 141 { 142 this->bVulnerable_ = bVulnerable; 143 this->changedVulnerability(); 144 } 145 } 146 /** @brief Returns the state of the pawns vulnerability. @return The state of the vulnerability */ 147 inline const bool& isVulnerable() const { return this->bVulnerable_; } 148 /** @brief This function gets called if the vulnerability of the pawn changes. */ 149 virtual void changedVulnerability(); 134 150 135 151 inline ControllableEntity* getLastHitOriginator() const 136 152 { return this->lastHitOriginator_; } 137 153 138 //virtual void hit(Pawn* originator, const Vector3& force, float damage);139 //virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);140 154 virtual void hit(Pawn* originator, const Vector3& force, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); 141 155 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, const btCollisionShape* cs, float damage, float healthdamage = 0.0f, float shielddamage = 0.0f); … … 144 158 145 159 virtual void fired(unsigned int firemode); 146 virtual void reload();147 160 virtual void postSpawn(); 161 162 void addExplosionPart(ExplosionPart* ePart); 163 ExplosionPart * getExplosionPart(); 148 164 149 165 void addWeaponSlot(WeaponSlot * wSlot); … … 154 170 void addWeaponPackXML(WeaponPack * wPack); 155 171 WeaponPack * getWeaponPack(unsigned int index) const; 172 std::vector<WeaponPack *> * getAllWeaponPacks(); 173 174 void addMunitionXML(Munition* munition); 175 Munition* getMunitionXML() const; 176 177 Munition* getMunition(SubclassIdentifier<Munition> * identifier); 156 178 157 179 virtual void addedWeaponPack(WeaponPack* wPack) {} … … 194 216 const std::string& getExplosionSound(); 195 217 218 virtual const WeaponSystem* getWeaponSystem() const 219 { return this->weaponSystem_; } 220 196 221 protected: 197 222 virtual void preDestroy(); … … 204 229 virtual Controller* getSlave(); 205 230 virtual void goWithStyle(); 206 virtual void deatheffect();207 231 virtual void spawneffect(); 208 232 209 //virtual void damage(float damage, Pawn* originator = 0);210 233 virtual void damage(float damage, float healthdamage = 0.0f, float shielddamage = 0.0f, Pawn* originator = NULL, const btCollisionShape* cs = NULL); 211 234 212 235 bool bAlive_; 236 bool bVulnerable_; ///< If false the pawn may not ged damaged 213 237 214 238 virtual std::vector<PickupCarrier*>* getCarrierChildren(void) const … … 226 250 float initialShieldHealth_; 227 251 float shieldAbsorption_; ///< Has to be between 0 and 1 228 float reloadRate_;229 float reloadWaitTime_;230 float reloadWaitCountdown_;252 float shieldRechargeRate_; 253 float shieldRechargeWaitTime_; 254 float shieldRechargeWaitCountdown_; 231 255 232 256 float damageMultiplier_; ///< Used by the Damage Boost Pickup. … … 235 259 236 260 WeaponSystem* weaponSystem_; 237 bool bReload_;238 261 239 262 std::string spawnparticlesource_; 240 263 float spawnparticleduration_; 241 264 unsigned int numexplosionchunks_; 265 266 std::vector<ExplosionPart*> explosionPartList_; 242 267 243 268 private: -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc
r10216 r11052 115 115 116 116 XMLPortObject(SpaceShip, Engine, "engines", addEngine, getEngine, xmlelement, mode); 117 118 117 119 } 118 120 … … 297 299 } 298 300 } 301 302 void SpaceShip::gainBoostPower(float gainedBoostPower) 303 { 304 this->boostPower_ += gainedBoostPower; 305 306 if (this->boostPower_ > this->initialBoostPower_) 307 { 308 this->boostPower_ = this->initialBoostPower_; 309 } 310 311 // If the booster is in cooldown mode and we gained boost power, the abort the cooldown. 312 if (this->isBoostCoolingDown() && this->boostPower_ > 0.0f) 313 { 314 timer_.stopTimer(); 315 this->boostCooledDown(); 316 } 317 } 318 299 319 /** 300 320 @brief -
code/trunk/src/orxonox/worldentities/pawns/SpaceShip.h
r10437 r11052 53 53 - The <b>boost</b>, there are quite some parameters pertaining to boosting. The boost is a special move of the SpaceShip, where, for a limited amount of time, it can fly considerably faster than usual. The <b>boostPower</b> is the amount of power available for boosting. The <b>boostPowerRate</b> is the rate at which the boost power is replenished. The <b>boostRate</b> is the rate at which boosting uses power. And the <b>boostCooldownDuration</b> is the time the SpaceShip cannot boost, once all the boost power has been used up. Naturally all of these parameters must be non-negative. 54 54 - The <b>boost shaking</b>, when the SpaceShip 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. 55 - 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. 55 - The <b>lift</b> creates a more natural flight feeling through the addition of a lift force. There are again two 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. 56 57 A spaceship always needs to have the collision type "dynamic". Other collision types are illegal. 56 58 57 59 As mentioned @ref orxonox::Engine Engines can be mounted on the SpaceShip. Here is a (primitive) example of a SpaceShip defined in XML: … … 250 252 inline float getShakeAmplitude() const 251 253 { return this->shakeAmplitude_; } 254 /** 255 @brief Add boost power. Is non-negative. 256 @return Returns the current boost power. 257 */ 258 void gainBoostPower(float gainedBoostPower); 252 259 253 260 protected: … … 262 269 bool bBoostCooldown_; //!< Whether the SpaceShip is currently in boost cooldown, during which boosting is impossible. 263 270 float initialBoostPower_; //!< The initial (and maximal) boost power. 264 float boostPower_; //!< The current boost power. 271 float boostPower_; //!< The current boost power. If the boost power is reduced to zero the boost cooldown will start. 265 272 float boostPowerRate_; //!< The rate at which the boost power is recharged. 266 273 float boostRate_; //!< The rate at which boost power is used up. … … 289 296 std::vector<Engine*> engineList_; //!< The list of all Engines mounted on this SpaceShip. 290 297 291 Timer timer_; //!< Timer for the cooldown duration.298 Timer timer_; //!< Timer for the cooldown of the boost. 292 299 float shakeDt_; //!< Temporary variable for the shaking of the camera. 293 300 Vector3 cameraOriginalPosition_; //!< The original position of the camera before shaking it.
Note: See TracChangeset
for help on using the changeset viewer.