Changeset 2918 for code/branches/weapons/src
- Timestamp:
- Apr 18, 2009, 6:14:52 PM (16 years ago)
- Location:
- code/branches/weapons/src/orxonox
- Files:
-
- 4 added
- 2 deleted
- 26 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/weapons/src/orxonox/OrxonoxPrereqs.h
r2915 r2918 157 157 class WeaponPack; 158 158 class Weapon; 159 class WeaponMode; 159 160 class DefaultWeaponmodeLink; 161 162 class LaserFire; 163 class FusionFire; 164 165 class ReplenishingMunition; 160 166 class Munition; 161 class LaserGun;162 167 class LaserGunMunition; 163 168 class FusionMunition; -
code/branches/weapons/src/orxonox/objects/controllers/HumanController.cc
r2912 r2918 46 46 SetConsoleCommand(HumanController, rotateRoll, true).setAsInputCommand(); 47 47 SetConsoleCommand(HumanController, fire, true).keybindMode(KeybindMode::OnHold); 48 SetConsoleCommand(HumanController, reload, true); 48 49 SetConsoleCommand(HumanController, boost, true).keybindMode(KeybindMode::OnHold); 49 50 SetConsoleCommand(HumanController, greet, true); … … 114 115 } 115 116 117 void HumanController::reload() 118 { 119 if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) 120 HumanController::localController_s->controllableEntity_->reload(); 121 } 122 116 123 void HumanController::boost() 117 124 { -
code/branches/weapons/src/orxonox/objects/controllers/HumanController.h
r2912 r2918 52 52 53 53 static void fire(unsigned int firemode); 54 static void reload(); 54 55 55 56 static void boost(); -
code/branches/weapons/src/orxonox/objects/weaponSystem/CMakeLists.txt
r2915 r2918 2 2 Munition.cc 3 3 Weapon.cc 4 WeaponMode.cc 4 5 WeaponPack.cc 5 6 WeaponSet.cc -
code/branches/weapons/src/orxonox/objects/weaponSystem/Munition.cc
r2912 r2918 20 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 21 * 22 * Author :22 * Authors: 23 23 * Martin Polak 24 * Fabian 'x3n' Landau 24 25 * Co-authors: 25 26 * ... … … 40 41 RegisterObject(Munition); 41 42 43 this->maxMunitionPerMagazine_ = 10; 44 this->maxMagazines_ = 10; 45 this->magazines_ = 10; 46 47 this->bUseSeparateMagazines_ = false; 48 this->bStackMunition_ = true; 49 this->bAllowMunitionRefilling_ = true; 50 this->bAllowMultiMunitionRemovementUnderflow_ = true; 51 52 this->reloadTime_ = 0; 53 42 54 COUT(0) << "+Munition" << std::endl; 43 55 } … … 45 57 Munition::~Munition() 46 58 { 59 for (std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it) 60 delete it->second; 61 47 62 COUT(0) << "~Munition" << std::endl; 48 63 } 49 64 50 unsigned int Munition::bullets() 51 { 52 if (this->bullets_ > 0) 53 return bullets_; 65 Munition::Magazine* Munition::getMagazine(WeaponMode* user) const 66 { 67 if (this->bUseSeparateMagazines_) 68 { 69 // For separated magazines we definitively need a given user 70 if (!user) 71 return 0; 72 73 // Use the map to get the magazine assigned to the given user 74 std::map<WeaponMode*, Magazine*>::const_iterator it = this->currentMagazines_.find(user); 75 if (it != this->currentMagazines_.end()) 76 return it->second; 77 } 78 else 79 { 80 // We don't use separate magazines for each user, so just take the first magazine 81 if (this->currentMagazines_.size() > 0) 82 return this->currentMagazines_.begin()->second; 83 } 84 85 return 0; 86 } 87 88 unsigned int Munition::getNumMunition(WeaponMode* user) const 89 { 90 Magazine* magazine = this->getMagazine(user); 91 if (magazine) 92 { 93 if (this->bStackMunition_) 94 // With stacked munition every magazine contributes to the total amount 95 return this->maxMunitionPerMagazine_ * this->magazines_ + magazine->munition_; 96 else 97 // Wihtout stacked munition we just consider the current magazine 98 return magazine->munition_; 99 } 100 return 0; 101 } 102 103 unsigned int Munition::getNumMunitionInCurrentMagazine(WeaponMode* user) const 104 { 105 // In contrast to getNumMunition() we really just consider the current magazine, even if we're stacking munition 106 Magazine* magazine = this->getMagazine(user); 107 if (magazine) 108 return magazine->munition_; 54 109 else 55 110 return 0; 56 111 } 57 112 58 unsigned int Munition::magazines() 59 { 60 if (this->magazines_ > 0) 61 return magazines_; 62 else 63 return 0; 64 } 65 66 void Munition::setMaxBullets(unsigned int amount) 67 { this->maxBullets_ = amount; } 68 69 void Munition::setMaxMagazines(unsigned int amount) 70 { this->maxMagazines_ = amount; } 71 72 void Munition::removeBullets(unsigned int amount) 73 { 74 if ( this->bullets_ != 0 ) 75 this->bullets_ = this->bullets_ - amount; 76 } 77 78 void Munition::removeMagazines(unsigned int amount) 79 { 80 if ( this->magazines_ != 0 ) 81 this->magazines_ = this->magazines_ - amount; 82 } 83 84 void Munition::addBullets(unsigned int amount) 85 { 86 if ( this->bullets_ == this->maxBullets_ ) 87 { 88 //cannot add bullets to actual magazine 89 } 90 else 91 this->bullets_ = this->bullets_ + amount; 92 } 93 94 void Munition::addMagazines(unsigned int amount) 95 { 96 if ( this->magazines_ == this->maxMagazines_ ) 97 { 98 //no more capacity for another magazine 99 } 100 else 101 this->magazines_ = this->magazines_ + amount; 102 } 103 104 105 void Munition::fillBullets() 106 { 107 this->bullets_ = this->maxBullets_; 108 } 109 110 void Munition::fillMagazines() 111 { 112 this->magazines_ = this->maxMagazines_; 113 unsigned int Munition::getNumMagazines() const 114 { 115 if (this->bStackMunition_) 116 { 117 // If we stack munition and the current magazine is still full, it counts too 118 Magazine* magazine = this->getMagazine(0); 119 if (magazine && magazine->munition_ == this->maxMunitionPerMagazine_) 120 return this->magazines_ + 1; 121 } 122 123 return this->magazines_; 124 } 125 126 unsigned int Munition::getMaxMunition() const 127 { 128 if (this->bStackMunition_) 129 return this->maxMunitionPerMagazine_ * this->maxMagazines_; 130 else 131 return this->maxMunitionPerMagazine_; 132 } 133 134 bool Munition::canTakeMunition(unsigned int amount, WeaponMode* user) const 135 { 136 Magazine* magazine = this->getMagazine(user); 137 if (magazine && magazine->bLoaded_) 138 { 139 unsigned int munition = magazine->munition_; 140 141 // If we stack munition, we con't care about the current magazine - we just need enough munition in total 142 if (this->bStackMunition_) 143 munition += this->maxMunitionPerMagazine_ * this->magazines_; 144 145 if (munition == 0) 146 // Absolutely no munition - no chance to take munition 147 return false; 148 else if (this->bAllowMultiMunitionRemovementUnderflow_) 149 // We're not empty AND we allow underflow, so this will always work 150 return true; 151 else 152 // We don't allow underflow, so we have to check the amount 153 return (munition >= amount); 154 } 155 return false; 156 } 157 158 bool Munition::takeMunition(unsigned int amount, WeaponMode* user) 159 { 160 if (!this->canTakeMunition(amount, user)) 161 return false; 162 163 Magazine* magazine = this->getMagazine(user); 164 if (magazine && magazine->bLoaded_) 165 { 166 if (magazine->munition_ >= amount) 167 { 168 // Enough munition 169 magazine->munition_ -= amount; 170 return true; 171 } 172 else 173 { 174 // Not enough munition 175 if (this->bStackMunition_) 176 { 177 // We stack munition, so just take what we can and then load the next magazine 178 amount -= magazine->munition_; 179 magazine->munition_ = 0; 180 181 if (this->reload(0)) 182 // Successfully reloaded, continue recursively 183 return this->takeMunition(amount, 0); 184 else 185 // We don't have more magazines, so let's just hope we allow underflow 186 return this->bAllowMultiMunitionRemovementUnderflow_; 187 } 188 else 189 { 190 // We don't stack, so we can only take munition if this is allowed 191 if (magazine->munition_ > 0 && this->bAllowMultiMunitionRemovementUnderflow_) 192 { 193 magazine->munition_ -= 0; 194 return true; 195 } 196 } 197 } 198 } 199 return false; 200 } 201 202 bool Munition::canReload() const 203 { 204 // As long as we have enough magazines (and don't stack munition) we can reload 205 return (this->magazines_ > 0 && !this->bStackMunition_); 206 } 207 208 bool Munition::needReload(WeaponMode* user) const 209 { 210 Magazine* magazine = this->getMagazine(user); 211 if (magazine) 212 { 213 if (this->bStackMunition_) 214 // With stacked munition, we never have to reload 215 return false; 216 else 217 // We need to reload if an already loaded magazine is empty 218 return (magazine->bLoaded_ && magazine->munition_ == 0); 219 } 220 else 221 // No magazine - we definitively need to reload 222 return true; 223 } 224 225 bool Munition::reload(WeaponMode* user, bool bUseReloadTime) 226 { 227 // Don't reload if we're already reloading 228 Magazine* magazine = this->getMagazine(user); 229 if (magazine && !magazine->bLoaded_) 230 return false; 231 232 // Check if we actually can reload 233 if (this->magazines_ == 0) 234 return false; 235 236 // If we use separate magazines for each user, we definitively need a user given 237 if (this->bUseSeparateMagazines_ && !user) 238 return false; 239 240 // If we don't use separate magazines, set user to 0 241 if (!this->bUseSeparateMagazines_) 242 user = 0; 243 244 // Remove the current magazine for the given user 245 std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.find(user); 246 if (it != this->currentMagazines_.end()) 247 { 248 delete it->second; 249 this->currentMagazines_.erase(it); 250 } 251 252 // Load a new magazine 253 this->currentMagazines_[user] = new Magazine(this, bUseReloadTime); 254 this->magazines_--; 255 256 return true; 257 } 258 259 bool Munition::canAddMunition(unsigned int amount) const 260 { 261 if (!this->bAllowMunitionRefilling_) 262 return false; 263 264 if (this->bStackMunition_) 265 { 266 // If we stack munition, we can always add munition until we reach the limit 267 return (this->getNumMunition(0) < this->getMaxMunition()); 268 } 269 else 270 { 271 // Return true if any of the current magazines is not full (loading counts as full although it returns 0 munition) 272 for (std::map<WeaponMode*, Magazine*>::const_iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it) 273 if (it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_) 274 return true; 275 } 276 277 return false; 278 } 279 280 bool Munition::addMunition(unsigned int amount) 281 { 282 if (!this->canAddMunition(amount)) 283 return false; 284 285 if (this->bStackMunition_) 286 { 287 // Stacking munition means, if a magazine gets full, the munition adds to a new magazine 288 Magazine* magazine = this->getMagazine(0); 289 if (magazine) 290 { 291 // Add the whole amount 292 magazine->munition_ += amount; 293 294 // Add new magazines if the current magazine is overfull 295 while (magazine->munition_ > this->maxMunitionPerMagazine_) 296 { 297 magazine->munition_ -= this->maxMunitionPerMagazine_; 298 this->magazines_++; 299 } 300 301 // If we reached the limit, reduze both magazines and munition to the maximum 302 if (this->magazines_ >= this->maxMagazines_) 303 { 304 this->magazines_ = this->maxMagazines_ - 1; 305 magazine->munition_ = this->maxMunitionPerMagazine_; 306 } 307 308 return true; 309 } 310 311 // Something went wrong 312 return false; 313 } 314 else 315 { 316 // Share the munition equally to the current magazines 317 while (amount > 0) 318 { 319 bool change = false; 320 for (std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.begin(); it != this->currentMagazines_.end(); ++it) 321 { 322 // Add munition if the magazine isn't full (but only to loaded magazines) 323 if (amount > 0 && it->second->munition_ < this->maxMunitionPerMagazine_ && it->second->bLoaded_) 324 { 325 it->second->munition_++; 326 amount--; 327 change = true; 328 } 329 } 330 331 // If there was no change in a loop, all magazines are full (or locked due to loading) 332 if (!change) 333 break; 334 } 335 336 return true; 337 } 338 } 339 340 bool Munition::canAddMagazines(unsigned int amount) const 341 { 342 if (this->bStackMunition_) 343 // If we stack munition, we can always add new magazines because they contribute directly to the munition 344 return (this->getNumMunition(0) < this->getMaxMunition()); 345 else 346 // 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 { 352 if (!this->canAddMagazines(amount)) 353 return false; 354 355 // Calculate how many magazines are needed 356 int needed_magazines = this->maxMagazines_ - this->magazines_ - this->currentMagazines_.size(); 357 358 // 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; 361 362 if (amount <= needed_magazines) 363 { 364 // We need more magazines than we get, so just add them 365 this->magazines_ += amount; 366 } 367 else 368 { 369 // We get more magazines than we need, so just add the needed amount 370 this->magazines_ += needed_magazines; 371 if (this->bStackMunition_) 372 { 373 // We stack munition, so the additional amount contributes directly to the munition of the current magazine 374 Magazine* magazine = this->getMagazine(0); 375 if (magazine) 376 magazine->munition_ = this->maxMunitionPerMagazine_; 377 } 378 } 379 380 return true; 381 } 382 383 bool Munition::canRemoveMagazines(unsigned int amount) const 384 { 385 if (this->bStackMunition_) 386 { 387 if (this->magazines_ >= amount) 388 { 389 // We have enough magazines 390 return true; 391 } 392 else if (this->magazines_ == amount - 1) 393 { 394 // We lack one magazine, check if the current magazine is still full, if yes we're fine 395 Magazine* magazine = this->getMagazine(0); 396 if (magazine && magazine->munition_ == this->maxMunitionPerMagazine_) 397 return true; 398 } 399 else 400 { 401 // We don't have enough magazines 402 return false; 403 } 404 } 405 else 406 { 407 // In case we're not stacking munition, just check the number of magazines 408 return (this->magazines_ >= amount); 409 } 410 } 411 412 bool Munition::removeMagazines(unsigned int amount) 413 { 414 if (!this->canRemoveMagazines(amount)) 415 return false; 416 417 if (this->magazines_ >= amount) 418 { 419 // We have enough magazines, just remove the amount 420 this->magazines_ -= amount; 421 } 422 else if (this->bStackMunition_) 423 { 424 // We don't have enough magazines, but we're stacking munition, so additionally remove the bullets from the current magazine 425 this->magazines_ = 0; 426 Magazine* magazine = this->getMagazine(0); 427 if (magazine) 428 magazine->munition_ = 0; 429 } 430 431 return true; 432 } 433 434 bool Munition::dropMagazine(WeaponMode* user) 435 { 436 // If we use separate magazines, we need a user 437 if (this->bUseSeparateMagazines_ && !user) 438 return false; 439 440 // If we don't use separate magazines, set user to 0 441 if (!this->bUseSeparateMagazines_) 442 user = 0; 443 444 // Remove the current magazine for the given user 445 std::map<WeaponMode*, Magazine*>::iterator it = this->currentMagazines_.find(user); 446 if (it != this->currentMagazines_.end()) 447 { 448 delete it->second; 449 this->currentMagazines_.erase(it); 450 return true; 451 } 452 453 return false; 454 } 455 456 457 ///////////////////// 458 // Magazine struct // 459 ///////////////////// 460 Munition::Magazine::Magazine(Munition* munition, bool bUseReloadTime) 461 { 462 this->munition_ = 0; 463 this->bLoaded_ = false; 464 465 if (bUseReloadTime && (munition->reloadTime_ > 0 || munition->bStackMunition_)) 466 { 467 ExecutorMember<Magazine>* executor = createExecutor(createFunctor(&Magazine::loaded)); 468 executor->setDefaultValues(munition); 469 470 this->loadTimer_.setTimer(munition->reloadTime_, false, this, executor); 471 } 472 else 473 this->loaded(munition); 474 } 475 476 void Munition::Magazine::loaded(Munition* munition) 477 { 478 this->bLoaded_ = true; 479 this->munition_ = munition->maxMunitionPerMagazine_; 113 480 } 114 481 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/Munition.h
r2912 r2918 20 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 21 * 22 * Author :22 * Authors: 23 23 * Martin Polak 24 * Fabian 'x3n' Landau 24 25 * Co-authors: 25 26 * ... … … 31 32 32 33 #include "OrxonoxPrereqs.h" 34 35 #include <map> 36 33 37 #include "core/BaseObject.h" 38 #include "tools/Timer.h" 34 39 35 40 namespace orxonox … … 37 42 class _OrxonoxExport Munition : public BaseObject 38 43 { 44 struct Magazine 45 { 46 public: 47 Magazine(Munition* munition, bool bUseReloadTime = true); 48 49 unsigned int munition_; 50 Timer<Magazine> loadTimer_; 51 bool bLoaded_; 52 53 private: 54 void loaded(Munition* munition); 55 }; 56 39 57 public: 40 58 Munition(BaseObject* creator); 41 59 virtual ~Munition(); 42 60 43 void setMaxBullets(unsigned int amount); 44 void setMaxMagazines(unsigned int amount); 61 unsigned int getNumMunition(WeaponMode* user) const; 62 unsigned int getNumMunitionInCurrentMagazine(WeaponMode* user) const; 63 unsigned int getNumMagazines() const; 45 64 46 void fillBullets(); 47 void fillMagazines(); 65 unsigned int getMaxMunition() const; 66 inline unsigned int getMaxMagazines() const 67 { return this->maxMagazines_; } 68 inline unsigned int getMaxMunitionPerMagazine() const 69 { return this->maxMunitionPerMagazine_; } 48 70 49 unsigned int bullets();50 unsigned int magazines();71 bool canTakeMunition(unsigned int amount, WeaponMode* user) const; 72 bool takeMunition(unsigned int amount, WeaponMode* user); 51 73 52 void removeBullets(unsigned int k); 53 void removeMagazines(unsigned int k); 54 void addBullets(unsigned int k); 55 void addMagazines(unsigned int k); 74 bool canReload() const; 75 bool needReload(WeaponMode* user) const; 76 bool reload(WeaponMode* user, bool bUseReloadTime = true); 77 inline float getReloadTime() const 78 { return this->reloadTime_; } 79 80 bool canAddMunition(unsigned int amount) const; 81 bool addMunition(unsigned int amount); 82 83 bool canAddMagazines(unsigned int amount) const; 84 bool addMagazines(unsigned int amount); 85 86 bool canRemoveMagazines(unsigned int amount) const; 87 bool removeMagazines(unsigned int amount); 88 89 bool dropMagazine(WeaponMode* user); 90 91 protected: 92 unsigned int maxMunitionPerMagazine_; 93 unsigned int maxMagazines_; 94 unsigned int magazines_; 95 std::map<WeaponMode*, Magazine*> currentMagazines_; 96 97 bool bUseSeparateMagazines_; 98 bool bStackMunition_; 99 bool bAllowMunitionRefilling_; 100 bool bAllowMultiMunitionRemovementUnderflow_; 101 102 float reloadTime_; 56 103 57 104 private: 58 59 protected: 60 unsigned int bullets_; 61 unsigned int magazines_; 62 unsigned int maxBullets_; 63 unsigned int maxMagazines_; 105 Magazine* getMagazine(WeaponMode* user) const; 64 106 }; 65 107 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.cc
r2915 r2918 22 22 * Author: 23 23 * Martin Polak 24 * Fabian 'x3n' Landau 24 25 * Co-authors: 25 26 * ... … … 33 34 #include "core/XMLPort.h" 34 35 35 #include " Munition.h"36 #include "WeaponMode.h" 36 37 #include "WeaponPack.h" 37 38 #include "WeaponSystem.h" … … 45 46 RegisterObject(Weapon); 46 47 47 this->bulletReadyToShoot_ = true;48 this->magazineReadyToShoot_ = true;49 this->weaponSystem_ = 0;50 48 this->weaponPack_ = 0; 51 49 this->weaponSlot_ = 0; 52 this->bulletLoadingTime_ = 0;53 this->magazineLoadingTime_ = 0;54 50 this->bReloading_ = false; 55 this->bulletAmount_= 0; 56 this->magazineAmount_ = 0; 57 this->munition_ = 0; 58 this->unlimitedMunition_ = false; 59 this->setObjectMode(0x0); 51 this->reloadingWeaponmode_ = WeaponSystem::WEAPON_MODE_UNASSIGNED; 52 53 this->reloadTimer_.setTimer(0.0f, false, this, createExecutor(createFunctor(&Weapon::reloaded))); 54 this->reloadTimer_.stopTimer(); 60 55 61 56 COUT(0) << "+Weapon" << std::endl; … … 65 60 { 66 61 COUT(0) << "~Weapon" << std::endl; 67 if (this->isInitialized() && this->weaponPack_) 68 this->weaponPack_->removeWeapon(this); 62 63 if (this->isInitialized()) 64 { 65 if (this->weaponPack_) 66 this->weaponPack_->removeWeapon(this); 67 68 for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it) 69 delete it->second; 70 } 69 71 } 70 72 … … 73 75 SUPER(Weapon, XMLPort, xmlelement, mode); 74 76 75 XMLPortParam(Weapon, "munitionType", setMunitionType, getMunitionType, xmlelement, mode); 76 XMLPortParam(Weapon, "bulletLoadingTime", setBulletLoadingTime, getBulletLoadingTime, xmlelement, mode); 77 XMLPortParam(Weapon, "magazineLoadingTime", setMagazineLoadingTime, getMagazineLoadingTime, xmlelement, mode); 78 XMLPortParam(Weapon, "bullets", setBulletAmount, getBulletAmount, xmlelement, mode); 79 XMLPortParam(Weapon, "magazines", setMagazineAmount, getMagazineAmount, xmlelement, mode); 80 XMLPortParam(Weapon, "unlimitedMunition", setUnlimitedMunition, getUnlimitedMunition, xmlelement, mode); 77 XMLPortObject(Weapon, WeaponMode, "", addWeaponmode, getWeaponmode, xmlelement, mode); 81 78 } 82 79 83 void Weapon:: setWeapon()80 void Weapon::addWeaponmode(WeaponMode* weaponmode) 84 81 { 85 this->munition_->fillBullets(); 86 this->munition_->fillMagazines(); 82 if (!weaponmode) 83 return; 84 85 this->weaponmodes_.insert(std::pair<unsigned int, WeaponMode*>(weaponmode->getMode(), weaponmode)); 86 weaponmode->setWeapon(this); 87 87 } 88 88 89 void Weapon::setMunition()89 WeaponMode* Weapon::getWeaponmode(unsigned int index) const 90 90 { 91 this->munition_->setMaxBullets(this->bulletAmount_); 92 this->munition_->setMaxMagazines(this->magazineAmount_); 91 unsigned int i = 0; 92 for (std::multimap<unsigned int, WeaponMode*>::const_iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it) 93 { 94 if (i == index) 95 return it->second; 96 97 ++i; 98 } 99 return 0; 93 100 } 94 101 95 void Weapon::fire( )102 void Weapon::fire(unsigned int mode) 96 103 { 97 if ( this->bulletReadyToShoot_ && this->magazineReadyToShoot_ && !this->bReloading_) 104 // To avoid firing with more than one mode at the same time, we lock the weapon (reloading) for 105 // all modes except the one which is currently reloading. 106 // 107 // Example: 108 // WeaponMode A -> mode 0 109 // WeaponMode B -> mode 0 110 // WeaponMode C -> mode 1 111 // 112 // -> A and B can fire at the same time, but C has to wait until both (A and B) have reloaded 113 // -> If C fires, A and B have to wait until C has reloaded 114 // 115 // Note: The reloading of each WeaponMode is internally handled by each A, B and C. 116 // The reloading of the weapon is only performed to avoid firing with different modes at the same time. 117 if (this->bReloading_ && this->reloadingWeaponmode_ != mode) 118 return; 119 120 std::multimap<unsigned int, WeaponMode*>::iterator start = this->weaponmodes_.lower_bound(mode); 121 std::multimap<unsigned int, WeaponMode*>::iterator end = this->weaponmodes_.upper_bound(mode); 122 123 for (std::multimap<unsigned int, WeaponMode*>::iterator it = start; it != end; ++it) 98 124 { 99 this->bulletReadyToShoot_ = false;100 if ( this->unlimitedMunition_== true)125 float reloading_time = 0; 126 if (it->second->fire(&reloading_time)) 101 127 { 102 //shoot 103 this->reloadBullet(); 104 this->createProjectile(); 105 } 106 else 107 { 108 if ( this->munition_->bullets() > 0) 109 { 110 //shoot and reload 111 this->takeBullets(); 112 this->reloadBullet(); 113 this->createProjectile(); 114 } 115 //if there are no bullets, but magazines 116 else if ( this->munition_->magazines() > 0 && this->munition_->bullets() == 0 ) 117 { 118 //reload magazine 119 this->takeMagazines(); 120 this->reloadMagazine(); 121 } 122 else 123 { 124 //no magazines 125 } 126 } 127 } 128 else 129 { 130 //weapon not reloaded 131 } 128 this->bReloading_ = true; 129 this->reloadingWeaponmode_ = mode; 132 130 133 } 134 135 136 //weapon reloading 137 void Weapon::bulletTimer(float bulletLoadingTime) 138 { 139 this->bReloading_ = true; 140 this->bulletReloadTimer_.setTimer( bulletLoadingTime , false , this , createExecutor(createFunctor(&Weapon::bulletReloaded))); 141 } 142 void Weapon::magazineTimer(float magazineLoadingTime) 143 { 144 this->bReloading_ = true; 145 this->magazineReloadTimer_.setTimer( magazineLoadingTime , false , this , createExecutor(createFunctor(&Weapon::magazineReloaded))); 146 } 147 148 void Weapon::bulletReloaded() 149 { 150 this->bReloading_ = false; 151 this->bulletReadyToShoot_ = true; 152 } 153 154 void Weapon::magazineReloaded() 155 { 156 this->bReloading_ = false; 157 this->munition_->fillBullets(); 158 } 159 160 161 162 void Weapon::attachNeededMunition(const std::string& munitionName) 163 { 164 /* if munition type already exists attach it, else create a new one of this type and attach it to the weapon and to the WeaponSystem 165 */ 166 if (this->weaponSystem_) 167 { 168 //getMunitionType returns 0 if there is no such munitionType 169 Munition* munition = this->weaponSystem_->getMunitionType(munitionName); 170 if ( munition ) 171 { 172 this->munition_ = munition; 173 this->setMunition(); 174 } 175 else 176 { 177 //create new munition with identifier because there is no such munitionType 178 this->munitionIdentifier_ = ClassByString(munitionName); 179 this->munition_ = this->munitionIdentifier_.fabricate(this); 180 this->weaponSystem_->setNewMunition(munitionName, this->munition_); 181 this->setMunition(); 131 this->reloadTimer_.setInterval(reloading_time); 132 this->reloadTimer_.startTimer(); 182 133 } 183 134 } 184 135 } 185 136 186 187 Munition * Weapon::getAttachedMunition(const std::string& munitionType) 137 void Weapon::reload() 188 138 { 189 this->munition_ = this->weaponSystem_->getMunitionType(munitionType);190 return this->munition_;139 for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it) 140 it->second->reload(); 191 141 } 192 142 143 void Weapon::reloaded() 144 { 145 this->bReloading_ = false; 146 this->reloadingWeaponmode_ = WeaponSystem::WEAPON_MODE_UNASSIGNED; 147 } 193 148 194 //these function are defined in the weapon classes 195 void Weapon::takeBullets() { }; 196 void Weapon::createProjectile() { }; 197 void Weapon::takeMagazines() { }; 198 void Weapon::reloadBullet() { }; 199 void Weapon::reloadMagazine() { }; 200 201 202 //get and set functions for XMLPort 203 void Weapon::setMunitionType(const std::string& munitionType) 204 { this->munitionType_ = munitionType; } 205 206 const std::string& Weapon::getMunitionType() const 207 { return this->munitionType_; } 208 209 void Weapon::setBulletLoadingTime(float loadingTime) 210 { this->bulletLoadingTime_ = loadingTime; } 211 212 const float Weapon::getBulletLoadingTime() const 213 { return this->bulletLoadingTime_; } 214 215 void Weapon::setMagazineLoadingTime(float loadingTime) 216 { this->magazineLoadingTime_ = loadingTime; } 217 218 const float Weapon::getMagazineLoadingTime() const 219 { return this->magazineLoadingTime_; } 220 221 void Weapon::setBulletAmount(unsigned int amount) 222 { this->bulletAmount_ = amount; } 223 224 const unsigned int Weapon::getBulletAmount() const 225 { return this->bulletAmount_; } 226 227 void Weapon::setMagazineAmount(unsigned int amount) 228 { this->magazineAmount_ = amount; } 229 230 const unsigned int Weapon::getMagazineAmount() const 231 { return this->magazineAmount_; } 232 233 void Weapon::setUnlimitedMunition(bool unlimitedMunition) 234 { this->unlimitedMunition_ = unlimitedMunition; } 235 236 const bool Weapon::getUnlimitedMunition() const 237 { return this->unlimitedMunition_; } 238 149 void Weapon::notifyWeaponModes() 150 { 151 for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it) 152 it->second->setWeapon(this); 153 } 239 154 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/Weapon.h
r2914 r2918 22 22 * Author: 23 23 * Martin Polak 24 * Fabian 'x3n' Landau 24 25 * Co-authors: 25 26 * ... … … 34 35 35 36 #include "tools/Timer.h" 36 #include "core/Identifier.h"37 37 38 38 namespace orxonox … … 46 46 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 47 47 48 virtual void fire(); 49 void attachNeededMunition(const std::string& munitionType); 50 Munition * getAttachedMunition(const std::string& munitiontype); 48 void fire(unsigned int mode); 49 void reload(); 51 50 52 //reloading 53 void bulletTimer(float bulletLoadingTime); 54 void magazineTimer(float magazineLoadingTime); 55 void bulletReloaded(); 56 void magazineReloaded(); 51 void addWeaponmode(WeaponMode* weaponmode); 52 WeaponMode* getWeaponmode(unsigned int index) const; 57 53 58 //XMLPort functions 59 virtual void setMunitionType(const std::string& munitionType); 60 virtual const std::string& getMunitionType() const; 61 virtual void setBulletLoadingTime(float loadingTime); 62 virtual const float getBulletLoadingTime() const; 63 virtual void setMagazineLoadingTime(float loadingTime); 64 virtual const float getMagazineLoadingTime() const; 65 virtual void setBulletAmount(unsigned int amount); 66 virtual const unsigned int getBulletAmount() const; 67 virtual void setMagazineAmount(unsigned int amount); 68 virtual const unsigned int getMagazineAmount() const; 69 virtual void setUnlimitedMunition(bool unlimitedMunition); 70 virtual const bool getUnlimitedMunition() const; 71 72 //weapon actions 73 virtual void takeBullets(); 74 virtual void takeMagazines(); 75 virtual void createProjectile(); 76 virtual void reloadBullet(); 77 virtual void reloadMagazine(); 78 79 //manually set or reset 80 virtual void setWeapon(); 81 virtual void setMunition(); 82 83 inline void setWeaponSystem(WeaponSystem *weaponSystem) 84 { this->weaponSystem_ = weaponSystem; }; 85 inline WeaponSystem * getWeaponSystem() const 86 { return this->weaponSystem_; }; 87 88 inline void setWeaponPack(WeaponPack *weaponPack) 89 { this->weaponPack_ = weaponPack; }; 54 inline void setWeaponPack(WeaponPack * weaponPack) 55 { this->weaponPack_ = weaponPack; this->notifyWeaponModes(); } 90 56 inline WeaponPack * getWeaponPack() const 91 { return this->weaponPack_; } ;57 { return this->weaponPack_; } 92 58 93 59 inline void setWeaponSlot(WeaponSlot * wSlot) … … 96 62 { return this->weaponSlot_; } 97 63 98 protected: 64 private: 65 void reloaded(); 66 void notifyWeaponModes(); 67 68 WeaponPack* weaponPack_; 69 WeaponSlot* weaponSlot_; 70 std::multimap<unsigned int, WeaponMode*> weaponmodes_; 71 72 Timer<Weapon> reloadTimer_; 99 73 bool bReloading_; 100 bool bulletReadyToShoot_; 101 bool magazineReadyToShoot_; 102 bool unlimitedMunition_; 103 float bulletLoadingTime_; 104 float magazineLoadingTime_; 105 unsigned int bulletAmount_; 106 unsigned int magazineAmount_; 107 std::string munitionType_; 108 109 WeaponSlot * weaponSlot_; 110 Munition * munition_; 111 WeaponSystem * weaponSystem_; 112 WeaponPack* weaponPack_; 113 114 SubclassIdentifier<Munition> munitionIdentifier_; 115 116 Timer<Weapon> bulletReloadTimer_; 117 Timer<Weapon> magazineReloadTimer_; 74 unsigned int reloadingWeaponmode_; 118 75 }; 119 76 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.cc
r2915 r2918 72 72 SUPER(WeaponPack, XMLPort, xmlelement, mode); 73 73 74 XMLPortObject (WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode);74 XMLPortObjectExtended(WeaponPack, Weapon, "", addWeapon, getWeapon, xmlelement, mode, false, false); 75 75 XMLPortObject(WeaponPack, DefaultWeaponmodeLink, "links", addDefaultWeaponmodeLink, getDefaultWeaponmodeLink, xmlelement, mode); 76 76 } … … 79 79 { 80 80 for (std::set<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 81 (*it)->fire(); 81 (*it)->fire(weaponmode); 82 } 83 84 void WeaponPack::reload() 85 { 86 for (std::set<Weapon *>::iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 87 (*it)->reload(); 82 88 } 83 89 … … 114 120 } 115 121 116 void WeaponPack::setWeaponSystemToAllWeapons()117 {118 for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)119 (*it)->setWeaponSystem(this->weaponSystem_);120 }121 122 void WeaponPack::attachNeededMunitionToAllWeapons()123 {124 for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it)125 {126 (*it)->attachNeededMunition((*it)->getMunitionType());127 (*it)->setWeapon();128 }129 }130 131 122 void WeaponPack::addDefaultWeaponmodeLink(DefaultWeaponmodeLink* link) 132 123 { … … 155 146 return WeaponSystem::WEAPON_MODE_UNASSIGNED; 156 147 } 148 149 void WeaponPack::notifyWeapons() 150 { 151 for (std::set<Weapon *>::const_iterator it = this->weapons_.begin(); it != this->weapons_.end(); ++it) 152 (*it)->setWeaponPack(this); 153 } 157 154 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponPack.h
r2915 r2918 48 48 49 49 void fire(unsigned int weaponmode); 50 void reload(); 50 51 51 52 void addWeapon(Weapon * weapon); … … 61 62 unsigned int getDesiredWeaponmode(unsigned int firemode) const; 62 63 63 inline void setWeaponSystem(WeaponSystem *weaponSystem) 64 { 65 this->weaponSystem_ = weaponSystem; 66 this->setWeaponSystemToAllWeapons(); 67 this->attachNeededMunitionToAllWeapons(); 68 } 64 inline void setWeaponSystem(WeaponSystem * weaponSystem) 65 { this->weaponSystem_ = weaponSystem; this->notifyWeapons(); } 69 66 inline WeaponSystem * getWeaponSystem() const 70 67 { return this->weaponSystem_; } 71 68 72 69 private: 73 void setWeaponSystemToAllWeapons(); 74 void attachNeededMunitionToAllWeapons(); 70 void notifyWeapons(); 75 71 76 72 std::set<Weapon *> weapons_; -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.cc
r2915 r2918 64 64 XMLPortParam(WeaponSet, "firemode", setDesiredFiremode, getDesiredFiremode, xmlelement, mode); 65 65 } 66 /*67 void WeaponSet::attachWeaponPack(WeaponPack *wPack)68 {69 if ( this->weaponSystem_->getWeaponSlotSize()>0 && wPack->getSize()>0 && ( wPack->getSize() <= this->weaponSystem_->getWeaponSlotSize() ) )70 {71 this->attachedWeaponPack_ = wPack;72 int wPackWeapon = 0; //WeaponCounter for Attaching73 74 //should be possible to choose which slot to use75 //attach every weapon of the weaponPack to a weaponSlot76 for ( int i=0; i < wPack->getSize() ; i++ )77 {78 //at the moment this function only works for one weaponPack in the entire WeaponSystem...79 //it also takes the first free weaponSlot...80 if ( this->weaponSystem_->getWeaponSlot(i)->getAttachedWeapon() == 0 && this->weaponSystem_->getWeaponSlot(i) != 0) //if slot not full81 {82 this->setWeaponSlots_.push_back( this->weaponSystem_->getWeaponSlot(i) );83 this->weaponSystem_->getWeaponSlot(i)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );84 this->weaponSystem_->getPawn()->attach( wPack->getWeaponPointer(wPackWeapon) );85 wPackWeapon++;86 }87 else88 {89 for (int k=0; k < this->weaponSystem_->getWeaponSlotSize(); k++)90 {91 if ( this->weaponSystem_->getWeaponSlot(k)->getAttachedWeapon() == 0 )92 {93 this->setWeaponSlots_.push_back( this->weaponSystem_->getWeaponSlot(k) );94 this->weaponSystem_->getWeaponSlot(k)->attachWeapon( wPack->getWeaponPointer(wPackWeapon) );95 this->weaponSystem_->getPawn()->attach( wPack->getWeaponPointer(wPackWeapon) );96 wPackWeapon++;97 }98 }99 }100 }101 }102 }103 */104 66 105 67 void WeaponSet::fire() … … 109 71 if (it->second != WeaponSystem::WEAPON_MODE_UNASSIGNED) 110 72 it->first->fire(it->second); 73 } 74 75 void WeaponSet::reload() 76 { 77 // fire all WeaponPacks with their defined weaponmode 78 for (std::map<WeaponPack*, unsigned int>::iterator it = this->weaponpacks_.begin(); it != this->weaponpacks_.end(); ++it) 79 it->first->reload(); 111 80 } 112 81 -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSet.h
r2914 r2918 47 47 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 48 48 49 // void attachWeaponPack(WeaponPack *wPack);50 51 49 void fire(); 50 void reload(); 52 51 53 52 void setWeaponmodeLink(WeaponPack* weaponpack, unsigned int weaponmode); … … 66 65 67 66 private: 68 WeaponSystem * weaponSystem_;67 WeaponSystem * weaponSystem_; 69 68 unsigned int desiredFiremode_; 70 69 std::map<WeaponPack*, unsigned int> weaponpacks_; -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSlot.cc
r2914 r2918 64 64 SUPER(WeaponSlot, XMLPort, xmlelement, mode); 65 65 66 // ...66 // In the future, there might be parameters like allowed weapon types or max size of the weapon 67 67 } 68 68 -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.cc
r2915 r2918 37 37 #include "WeaponSet.h" 38 38 #include "Weapon.h" 39 #include "Munition.h" 39 40 40 41 /* WeaponSystem … … 63 64 this->pawn_->setWeaponSystem(0); 64 65 65 // for (std::map<unsigned int, WeaponSet*>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); )66 // delete (it++)->second;67 66 while (!this->weaponSets_.empty()) 68 67 delete (this->weaponSets_.begin()->second); 69 68 70 // for (std::set<WeaponPack*>::iterator it = this->weaponPacks_.begin(); it != this->weaponPacks_.end(); )71 // delete (*(it++));72 69 while (!this->weaponPacks_.empty()) 73 70 delete (*this->weaponPacks_.begin()); 74 71 75 // for (std::vector<WeaponSlot*>::iterator it = this->weaponSlots_.begin(); it != this->weaponSlots_.end(); )76 // delete (*(it++));77 72 while (!this->weaponSlots_.empty()) 78 73 delete (*this->weaponSlots_.begin()); 74 75 while (!this->munitions_.empty()) 76 { delete (this->munitions_.begin()->second); this->munitions_.erase(this->munitions_.begin()); } 79 77 } 80 78 } … … 284 282 } 285 283 286 void WeaponSystem::setNewMunition(const std::string& munitionType, Munition * munitionToAdd)287 {288 this->munitionSet_[munitionType] = munitionToAdd;289 }290 291 292 //returns the Pointer to the munitionType, if this munitionType doesn't exist returns 0, see Weapon::attachNeededMunition293 Munition * WeaponSystem::getMunitionType(const std::string& munitionType) const294 {295 std::map<std::string, Munition *>::const_iterator it = this->munitionSet_.find(munitionType);296 if (it != this->munitionSet_.end())297 return it->second;298 else299 return 0;300 }301 302 284 void WeaponSystem::fire(unsigned int firemode) 303 285 { … … 306 288 it->second->fire(); 307 289 } 290 291 void WeaponSystem::reload() 292 { 293 for (std::map<unsigned int, WeaponSet *>::iterator it = this->weaponSets_.begin(); it != this->weaponSets_.end(); ++it) 294 it->second->reload(); 295 } 296 297 Munition * WeaponSystem::getMunition(SubclassIdentifier<Munition> * identifier) 298 { 299 if (!identifier || !identifier->getIdentifier()) 300 return 0; 301 302 std::map<Identifier *, Munition *>::iterator it = this->munitions_.find(identifier->getIdentifier()); 303 if (it != this->munitions_.end()) 304 { 305 return it->second; 306 } 307 else if (identifier->getIdentifier()->isA(Class(Munition))) 308 { 309 Munition* munition = identifier->fabricate(this); 310 this->munitions_[identifier->getIdentifier()] = munition; 311 return munition; 312 } 313 else 314 { 315 return 0; 316 } 317 } 308 318 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/WeaponSystem.h
r2915 r2918 69 69 70 70 void fire(unsigned int firemode); 71 void reload(); 71 72 72 73 void setNewMunition(const std::string& munitionType, Munition * munitionToAdd); 74 void setNewSharedMunition(const std::string& munitionType, Munition * munitionToAdd); 75 Munition * getMunitionType(const std::string& munitionType) const; 73 Munition * getMunition(SubclassIdentifier<Munition> * identifier); 76 74 77 75 inline void setPawn(Pawn * pawn) … … 96 94 std::vector<WeaponSlot *> weaponSlots_; 97 95 std::set<WeaponPack *> weaponPacks_; 98 std::map< std::string, Munition *> munitionSet_;96 std::map<Identifier *, Munition *> munitions_; 99 97 Pawn * pawn_; 100 98 }; -
code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/CMakeLists.txt
r2893 r2918 1 1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 ReplenishingMunition.cc 2 3 LaserGunMunition.cc 3 4 FusionMunition.cc -
code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/FusionMunition.cc
r2912 r2918 40 40 RegisterObject(FusionMunition); 41 41 42 //default if not defined in XML 43 this->maxBullets_ = 10; 44 this->maxMagazines_ = 100; 42 this->maxMunitionPerMagazine_ = 10; 43 this->maxMagazines_ = 10; 44 this->magazines_ = 10; 45 46 this->bUseSeparateMagazines_ = true; 47 this->bStackMunition_ = false; 48 this->reloadTime_ = 1.0f; 49 50 this->bAllowMunitionRefilling_ = true; 51 this->bAllowMultiMunitionRemovementUnderflow_ = true; 45 52 } 46 47 FusionMunition::~FusionMunition()48 {49 }50 51 void FusionMunition::XMLPort(Element& xmlelement, XMLPort::Mode mode)52 {53 54 }55 56 53 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/FusionMunition.h
r2912 r2918 39 39 public: 40 40 FusionMunition(BaseObject* creator); 41 virtual ~FusionMunition(); 42 43 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 44 45 46 private: 47 48 41 virtual ~FusionMunition() {} 49 42 }; 50 43 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.cc
r2912 r2918 36 36 CreateFactory(LaserGunMunition); 37 37 38 LaserGunMunition::LaserGunMunition(BaseObject* creator) : Munition(creator)38 LaserGunMunition::LaserGunMunition(BaseObject* creator) : ReplenishingMunition(creator) 39 39 { 40 40 RegisterObject(LaserGunMunition); 41 41 42 //default if not defined in XML 43 this->maxBullets_ = 40; 44 this->maxMagazines_ = 100; 42 this->maxMunitionPerMagazine_ = 20; 43 this->maxMagazines_ = 1; 44 this->magazines_ = 1; 45 46 this->bUseSeparateMagazines_ = false; 47 this->bStackMunition_ = true; 48 49 this->bAllowMunitionRefilling_ = true; 50 this->bAllowMultiMunitionRemovementUnderflow_ = true; 51 52 this->replenishIntervall_ = 0.5f; 53 this->replenishMunitionAmount_ = 1; 45 54 } 46 47 LaserGunMunition::~LaserGunMunition()48 {49 }50 51 void LaserGunMunition::XMLPort(Element& xmlelement, XMLPort::Mode mode)52 {53 54 }55 56 55 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/munitions/LaserGunMunition.h
r2912 r2918 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include " objects/weaponSystem/Munition.h"33 #include "ReplenishingMunition.h" 34 34 35 35 namespace orxonox 36 36 { 37 class _OrxonoxExport LaserGunMunition : public Munition37 class _OrxonoxExport LaserGunMunition : public ReplenishingMunition 38 38 { 39 39 public: 40 40 LaserGunMunition(BaseObject* creator); 41 virtual ~LaserGunMunition(); 42 43 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 44 45 46 private: 47 48 41 virtual ~LaserGunMunition() {} 49 42 }; 50 43 } -
code/branches/weapons/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc
r2896 r2918 101 101 if (!this->bDestroy_ && GameMode::isMaster()) 102 102 { 103 if (otherObject == this->owner_) 104 return true; 105 103 106 this->bDestroy_ = true; 104 107 -
code/branches/weapons/src/orxonox/objects/weaponSystem/projectiles/Projectile.h
r2662 r2918 51 51 virtual void destroyedPawn(Pawn* pawn); 52 52 53 inline void setDamage(float damage) 54 { this->damage_ = damage; } 55 inline float getDamage() const 56 { return this->damage_; } 57 53 58 inline void setOwner(Pawn* owner) 54 59 { this->owner_ = owner; } -
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/CMakeLists.txt
r2710 r2918 1 1 ADD_SOURCE_FILES(ORXONOX_SRC_FILES 2 Fusion.cc 3 LaserGun.cc 4 # Missile.cc 2 FusionFire.cc 3 LaserFire.cc 5 4 ) -
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/FusionFire.cc
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/gui/src/orxonox/objects/weaponSystem/weapons/Fusion.cc merged eligible /code/branches/pickups/src/orxonox/objects/weaponSystem/weapons/Fusion.cc merged eligible /code/branches/pickups2/src/orxonox/objects/weaponSystem/weapons/Fusion.cc merged eligible /code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.cc merged eligible /code/branches/buildsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 1874-2276,2278-2400 /code/branches/buildsystem2/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2506-2658 /code/branches/buildsystem3/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2662-2708 /code/branches/ceguilua/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 1802-1808 /code/branches/core3/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 1572-1739 /code/branches/gcc43/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 1580 /code/branches/input/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 1629-1636 /code/branches/lodfinal/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2372-2411 /code/branches/miniprojects/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2754-2824 /code/branches/network/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2356 /code/branches/network64/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2210-2355 /code/branches/objecthierarchy/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 1911-2085,2100,2110-2169 /code/branches/objecthierarchy2/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2171-2479 /code/branches/overlay/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2117-2385 /code/branches/physics/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 1912-2055,2107-2439 /code/branches/physics_merge/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2436-2457 /code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2369-2652,2654-2660 /code/branches/questsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 1894-2088 /code/branches/questsystem2/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2107-2259 /code/branches/script_trigger/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 1295-1953,1955 /code/branches/weapon/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 1925-2094 /code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/Fusion.cc 2107-2488
r2914 r2918 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include "Fusion .h"30 #include "FusionFire.h" 31 31 32 32 #include "core/CoreIncludes.h" 33 #include "objects/weaponSystem/projectiles/BillboardProjectile.h" 33 34 34 #include "objects/weaponSystem/ Munition.h"35 #include "objects/weaponSystem/ projectiles/ParticleProjectile.h"35 #include "objects/weaponSystem/Weapon.h" 36 #include "objects/weaponSystem/WeaponPack.h" 36 37 #include "objects/weaponSystem/WeaponSystem.h" 37 38 38 39 namespace orxonox 39 40 { 40 CreateFactory(Fusion );41 CreateFactory(FusionFire); 41 42 42 Fusion ::Fusion(BaseObject* creator) : Weapon(creator)43 FusionFire::FusionFire(BaseObject* creator) : WeaponMode(creator) 43 44 { 44 RegisterObject(Fusion );45 RegisterObject(FusionFire); 45 46 47 this->reloadTime_ = 1.0; 48 this->bParallelReload_ = false; 49 this->damage_ = 40; 46 50 this->speed_ = 1250; 47 51 52 this->setMunitionName("FusionMunition"); 48 53 } 49 54 50 Fusion::~Fusion()55 void FusionFire::fire() 51 56 { 52 }57 BillboardProjectile* projectile = new BillboardProjectile(this); 53 58 54 void Fusion::takeBullets() 55 { 56 //COUT(0) << "Fusion::takeBullets" << std::endl; 57 this->munition_->removeBullets(1); 58 this->bulletTimer(this->bulletLoadingTime_); 59 } 59 projectile->setOrientation(this->getMuzzleOrientation()); 60 projectile->setPosition(this->getMuzzlePosition()); 61 projectile->setVelocity(this->getMuzzleDirection() * this->speed_); 60 62 61 void Fusion::takeMagazines() 62 { 63 this->munition_->removeMagazines(1); 64 this->magazineTimer(this->magazineLoadingTime_); 65 } 66 67 void Fusion::createProjectile() 68 { 69 //COUT(0) << "Fusion::createProjectile" << std::endl; 70 BillboardProjectile* projectile = new ParticleProjectile(this); 71 projectile->setOrientation(this->getWorldOrientation()); 72 projectile->setPosition(this->getWorldPosition()); 73 projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_); 74 projectile->setOwner(this->getWeaponSystem()->getPawn()); 63 projectile->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()); 64 projectile->setDamage(this->getDamage()); 65 projectile->setColour(ColourValue(1.0f, 0.7f, 0.3f, 1.0f)); 75 66 } 76 67 } -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/FusionFire.h
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/gui/src/orxonox/objects/weaponSystem/weapons/Fusion.h merged eligible /code/branches/pickups/src/orxonox/objects/weaponSystem/weapons/Fusion.h merged eligible /code/branches/pickups2/src/orxonox/objects/weaponSystem/weapons/Fusion.h merged eligible /code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.h merged eligible /code/branches/buildsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.h 1874-2276,2278-2400 /code/branches/buildsystem2/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2506-2658 /code/branches/buildsystem3/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2662-2708 /code/branches/ceguilua/src/orxonox/objects/weaponSystem/weapons/Fusion.h 1802-1808 /code/branches/core3/src/orxonox/objects/weaponSystem/weapons/Fusion.h 1572-1739 /code/branches/gcc43/src/orxonox/objects/weaponSystem/weapons/Fusion.h 1580 /code/branches/input/src/orxonox/objects/weaponSystem/weapons/Fusion.h 1629-1636 /code/branches/lodfinal/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2372-2411 /code/branches/miniprojects/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2754-2824 /code/branches/network/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2356 /code/branches/network64/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2210-2355 /code/branches/objecthierarchy/src/orxonox/objects/weaponSystem/weapons/Fusion.h 1911-2085,2100,2110-2169 /code/branches/objecthierarchy2/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2171-2479 /code/branches/overlay/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2117-2385 /code/branches/physics/src/orxonox/objects/weaponSystem/weapons/Fusion.h 1912-2055,2107-2439 /code/branches/physics_merge/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2436-2457 /code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2369-2652,2654-2660 /code/branches/questsystem/src/orxonox/objects/weaponSystem/weapons/Fusion.h 1894-2088 /code/branches/questsystem2/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2107-2259 /code/branches/script_trigger/src/orxonox/objects/weaponSystem/weapons/Fusion.h 1295-1953,1955 /code/branches/weapon/src/orxonox/objects/weaponSystem/weapons/Fusion.h 1925-2094 /code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/Fusion.h 2107-2488
r2914 r2918 27 27 */ 28 28 29 #ifndef _Fusion _H__30 #define _Fusion _H__29 #ifndef _FusionFire_H__ 30 #define _FusionFire_H__ 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "objects/weaponSystem/Weapon .h"33 #include "objects/weaponSystem/WeaponMode.h" 34 34 35 35 namespace orxonox 36 36 { 37 class _OrxonoxExport Fusion : public Weapon37 class _OrxonoxExport FusionFire : public WeaponMode 38 38 { 39 39 public: 40 Fusion (BaseObject* creator);41 virtual ~Fusion ();40 FusionFire(BaseObject* creator); 41 virtual ~FusionFire() {} 42 42 43 virtual void takeBullets(); 44 virtual void takeMagazines(); 45 virtual void createProjectile(); 43 virtual void fire(); 46 44 47 45 private: 48 46 float speed_; 49 50 47 }; 51 48 } 52 49 53 #endif /* _Fusion _H__ */50 #endif /* _FusionFire_H__ */ -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/LaserFire.cc
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/gui/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc merged eligible /code/branches/lodfinal/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc merged eligible /code/branches/pickups/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc merged eligible /code/branches/pickups2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc merged eligible /code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc merged eligible /code/branches/buildsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 1874-2276,2278-2400 /code/branches/buildsystem2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2506-2658 /code/branches/buildsystem3/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2662-2708 /code/branches/ceguilua/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 1802-1808 /code/branches/core3/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 1572-1739 /code/branches/gcc43/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 1580 /code/branches/input/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 1629-1636 /code/branches/miniprojects/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2754-2824 /code/branches/network/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2356 /code/branches/network64/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2210-2355 /code/branches/objecthierarchy/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 1911-2085,2100,2110-2169 /code/branches/objecthierarchy2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2171-2479 /code/branches/overlay/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2117-2385 /code/branches/physics/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 1912-2055,2107-2439 /code/branches/physics_merge/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2436-2457 /code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2369-2652,2654-2660 /code/branches/questsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 1894-2088 /code/branches/questsystem2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2107-2259 /code/branches/script_trigger/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 1295-1953,1955 /code/branches/weapon/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 1925-2094 /code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.cc 2107-2488
r2914 r2918 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include "Laser Gun.h"30 #include "LaserFire.h" 31 31 32 32 #include "core/CoreIncludes.h" 33 #include "objects/weaponSystem/projectiles/ParticleProjectile.h" 33 34 34 #include "objects/weaponSystem/ Munition.h"35 #include "objects/weaponSystem/ projectiles/ParticleProjectile.h"35 #include "objects/weaponSystem/Weapon.h" 36 #include "objects/weaponSystem/WeaponPack.h" 36 37 #include "objects/weaponSystem/WeaponSystem.h" 37 38 38 39 namespace orxonox 39 40 { 40 CreateFactory(Laser Gun);41 CreateFactory(LaserFire); 41 42 42 Laser Gun::LaserGun(BaseObject* creator) : Weapon(creator)43 LaserFire::LaserFire(BaseObject* creator) : WeaponMode(creator) 43 44 { 44 RegisterObject(Laser Gun);45 RegisterObject(LaserFire); 45 46 47 this->reloadTime_ = 0.25; 48 this->damage_ = 15; 46 49 this->speed_ = 1250; 47 50 51 this->setMunitionName("LaserGunMunition"); 48 52 } 49 53 50 LaserGun::~LaserGun()54 void LaserFire::fire() 51 55 { 52 }56 ParticleProjectile* projectile = new ParticleProjectile(this); 53 57 54 void LaserGun::reloadBullet() 55 { 56 this->bulletTimer(this->bulletLoadingTime_); 57 } 58 projectile->setOrientation(this->getMuzzleOrientation()); 59 projectile->setPosition(this->getMuzzlePosition()); 60 projectile->setVelocity(this->getMuzzleDirection() * this->speed_); 58 61 59 void LaserGun::reloadMagazine() 60 { 61 this->magazineTimer(this->magazineLoadingTime_); 62 } 63 64 void LaserGun::takeBullets() 65 { 66 this->munition_->removeBullets(1); 67 } 68 69 void LaserGun::takeMagazines() 70 { 71 this->munition_->removeMagazines(1); 72 } 73 74 void LaserGun::createProjectile() 75 { 76 BillboardProjectile* projectile = new ParticleProjectile(this); 77 projectile->setOrientation(this->getWorldOrientation()); 78 projectile->setPosition(this->getWorldPosition()); 79 projectile->setVelocity(this->getWorldOrientation() * WorldEntity::FRONT * this->speed_); 80 projectile->setOwner(this->getWeaponSystem()->getPawn()); 62 projectile->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()); 63 projectile->setDamage(this->getDamage()); 81 64 } 82 65 } -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/branches/weapons/src/orxonox/objects/weaponSystem/weapons/LaserFire.h
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/code/branches/gui/src/orxonox/objects/weaponSystem/weapons/LaserGun.h merged eligible /code/branches/lodfinal/src/orxonox/objects/weaponSystem/weapons/LaserGun.h merged eligible /code/branches/pickups/src/orxonox/objects/weaponSystem/weapons/LaserGun.h merged eligible /code/branches/pickups2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h merged eligible /code/branches/weaponsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.h merged eligible /code/branches/buildsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 1874-2276,2278-2400 /code/branches/buildsystem2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2506-2658 /code/branches/buildsystem3/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2662-2708 /code/branches/ceguilua/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 1802-1808 /code/branches/core3/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 1572-1739 /code/branches/gcc43/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 1580 /code/branches/input/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 1629-1636 /code/branches/miniprojects/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2754-2824 /code/branches/network/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2356 /code/branches/network64/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2210-2355 /code/branches/objecthierarchy/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 1911-2085,2100,2110-2169 /code/branches/objecthierarchy2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2171-2479 /code/branches/overlay/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2117-2385 /code/branches/physics/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 1912-2055,2107-2439 /code/branches/physics_merge/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2436-2457 /code/branches/presentation/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2369-2652,2654-2660 /code/branches/questsystem/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 1894-2088 /code/branches/questsystem2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2107-2259 /code/branches/script_trigger/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 1295-1953,1955 /code/branches/weapon/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 1925-2094 /code/branches/weapon2/src/orxonox/objects/weaponSystem/weapons/LaserGun.h 2107-2488
r2914 r2918 27 27 */ 28 28 29 #ifndef _Laser Gun_H__30 #define _Laser Gun_H__29 #ifndef _LaserFire_H__ 30 #define _LaserFire_H__ 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "objects/weaponSystem/Weapon .h"33 #include "objects/weaponSystem/WeaponMode.h" 34 34 35 35 namespace orxonox 36 36 { 37 class _OrxonoxExport Laser Gun : public Weapon37 class _OrxonoxExport LaserFire : public WeaponMode 38 38 { 39 39 public: 40 Laser Gun(BaseObject* creator);41 virtual ~Laser Gun();40 LaserFire(BaseObject* creator); 41 virtual ~LaserFire() {} 42 42 43 virtual void takeBullets(); 44 virtual void takeMagazines(); 45 virtual void createProjectile(); 46 virtual void reloadBullet(); 47 virtual void reloadMagazine(); 43 virtual void fire(); 48 44 49 45 private: 50 46 float speed_; 51 52 47 }; 53 48 } 54 49 55 #endif /* _Laser Gun_H__ */50 #endif /* _LaserFire_H__ */ -
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
code/branches/weapons/src/orxonox/objects/worldentities/ControllableEntity.h
r2912 r2918 82 82 83 83 virtual void fire(unsigned int firemode) {} 84 virtual void reload() {} 84 85 85 86 virtual void boost() {} -
code/branches/weapons/src/orxonox/objects/worldentities/pawns/Pawn.cc
r2914 r2918 56 56 this->fire_ = 0x0; 57 57 this->firehack_ = 0x0; 58 this->bReload_ = false; 58 59 59 60 this->health_ = 0; … … 115 116 registerVariable(this->initialHealth_, variableDirection::toclient); 116 117 registerVariable(this->fire_, variableDirection::toserver); 118 registerVariable(this->bReload_, variableDirection::toserver); 117 119 } 118 120 … … 121 123 SUPER(Pawn, tick, dt); 122 124 123 if (this->weaponSystem_ )125 if (this->weaponSystem_ && GameMode::isMaster()) 124 126 { 125 127 for (unsigned int firemode = 0; firemode < WeaponSystem::MAX_FIRE_MODES; firemode++) 126 128 if (this->fire_ & WeaponSystem::getFiremodeMask(firemode)) 127 129 this->weaponSystem_->fire(firemode); 128 } 130 131 if (this->bReload_) 132 this->weaponSystem_->reload(); 133 } 134 129 135 this->fire_ = this->firehack_; 130 136 this->firehack_ = 0x0; 137 this->bReload_ = false; 131 138 132 139 if (this->health_ <= 0) … … 258 265 } 259 266 267 void Pawn::reload() 268 { 269 this->bReload_ = true; 270 } 271 260 272 void Pawn::postSpawn() 261 273 { -
code/branches/weapons/src/orxonox/objects/worldentities/pawns/Pawn.h
r2914 r2918 81 81 82 82 virtual void fire(unsigned int firemode); 83 virtual void reload(); 83 84 virtual void postSpawn(); 84 85 … … 131 132 unsigned int fire_; 132 133 unsigned int firehack_; 134 bool bReload_; 133 135 134 136 std::string spawnparticlesource_;
Note: See TracChangeset
for help on using the changeset viewer.