Changeset 10368 in orxonox.OLD for trunk/src/world_entities/weapons
- Timestamp:
- Jan 25, 2007, 2:18:07 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
- 14 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 10 10 autom4te.cache 11 11 aclocal.m4 12 tags 13 test.bmp 14 config.sub 15 config.guess 16 OrxonoxPlayability.kdevses 17 OrxonoxPlayability.kdevelop.pcs
-
- Property svn:ignore
-
trunk/src/world_entities/weapons/weapon.cc
r9869 r10368 33 33 #include "resource_sound_buffer.h" 34 34 35 #include "elements/glgui_energywidget .h"35 #include "elements/glgui_energywidgetvertical.h" 36 36 37 37 ObjectListDefinition(Weapon); … … 119 119 } 120 120 121 this->soundSource = new OrxSound::SoundSource(this); //< Every Weapon has exacty one SoundSource. 122 this->emissionPoint.setParent(this); //< One EmissionPoint, that is a PNode connected to the weapon. You can set this to the exitting point of the Projectiles 123 this->emissionPoint.setName("EmissionPoint"); 124 this->emissionPoint.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 121 this->soundSource = new OrxSound::SoundSource(this); //< Every Weapon has exacty one SoundSource 122 123 this->barrels = 1; 124 this->segs = 1; 125 126 this->shootAnim = new Animation3D**[this->getBarrels()]; 127 for (int i = 0; i < this->getBarrels(); i++) 128 this->shootAnim[i] = new Animation3D* [this->getSegs()]; 129 130 this->emissionPoint = new PNode*[this->barrels]; 131 for(int i = 0; i < this->barrels; i++){ 132 this->emissionPoint[i] = new PNode; 133 this->emissionPoint[i]->setParent(this); //< One EmissionPoint, that is a PNode connected to the weapon. You can set this to the exitting point of the Projectiles 134 this->emissionPoint[i]->setName("EmissionPoint"); 135 this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 136 } 125 137 126 138 this->defaultTarget = NULL; //< Nothing is Targeted by default. … … 145 157 146 158 /** 159 * needed, if there are more than one barrel or segments 160 */ 161 void Weapon::init2() 162 { 163 if (this->barrels == 1 && this->segs == 1) 164 return; 165 166 delete this->emissionPoint[0]; 167 delete this->emissionPoint; 168 delete this->shootAnim[0]; 169 delete this->shootAnim; 170 171 this->shootAnim = new Animation3D**[this->barrels]; 172 this->emissionPoint = new PNode*[this->barrels]; 173 for(int i = 0; i < this->barrels; i++){ 174 this->emissionPoint[i] = new PNode; 175 this->emissionPoint[i]->setParent(this); //< One EmissionPoint, that is a PNode connected to the weapon. You can set this to the exitting point of the Projectiles 176 this->emissionPoint[i]->setName("EmissionPoint"); 177 this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 178 this->shootAnim[i] = new Animation3D* [this->segs]; 179 } 180 } 181 182 /** 183 * deconstructor for init2 184 */ 185 void Weapon::deconstr() 186 { 187 for(int i = 0; i < this->barrels; i++) { 188 delete this->emissionPoint[i]; 189 for (int j = 0; j < this->segs; j++) 190 delete this->shootAnim[i][j]; 191 delete this->shootAnim[i]; 192 } 193 194 delete this->emissionPoint; 195 delete this->shootAnim; 196 } 197 198 /** 147 199 * loads the Parameters of a Weapon 148 200 * @param root the XML-Element to load the Weapons settings from … … 154 206 LoadParam(root, "projectile", this, Weapon, setProjectileTypeC) 155 207 .describe("Sets the name of the Projectile to load onto the Entity"); 156 208 /* 157 209 LoadParam(root, "emission-point", this, Weapon, setEmissionPoint) 158 .describe("Sets the Point of emission of this weapon ");210 .describe("Sets the Point of emission of this weapon (1: EmmsionVector; 2: EmissionPoint)");*/ 159 211 160 212 LoadParam(root, "state-duration", this, Weapon, setStateDuration) … … 253 305 * @param point the Point relative to the mass-point of the Weapon 254 306 */ 307 void Weapon::setEmissionPoint(const Vector& point, int barrel) 308 { 309 this->emissionPoint[barrel]->setRelCoor(point); 310 } 311 255 312 void Weapon::setEmissionPoint(const Vector& point) 256 313 { 257 this->emissionPoint.setRelCoor(point); 258 } 259 314 this->emissionPoint[0]->setRelCoor(point); 315 } 260 316 261 317 /** … … 315 371 } 316 372 373 Animation3D* Weapon::getAnimation(int barrel, int seg, PNode* node) 374 { 375 if (barrel >= this->getBarrels() || seg >= this->getSegs()) // if the state is not known 376 return NULL; 377 378 if (unlikely(this->shootAnim[barrel][seg] == NULL)) // if the animation does not exist yet create it. 379 { 380 if (likely(node != NULL)) 381 return this->shootAnim[barrel][seg] = new Animation3D(node); 382 else 383 { 384 // PRINTF(2)("Node not defined for the Creation of the 3D-animation of state %s\n", stateToChar(state)); 385 return NULL; 386 } 387 } 388 else 389 return this->shootAnim[barrel][seg]; 390 } 391 317 392 OrxGui::GLGuiWidget* Weapon::getEnergyWidget() 318 393 { 319 if ( this->energyWidget == NULL)320 { 321 this->energyWidget = new OrxGui::GLGuiEnergyWidget ();322 this->energyWidget->setDisplayedName(this->getClassCName());394 if ( this->energyWidget == NULL) 395 { 396 this->energyWidget = new OrxGui::GLGuiEnergyWidgetVertical(); 397 //this->energyWidget->setDisplayedName(this->getClassCName()); 323 398 this->energyWidget->setSize2D( 20, 100); 324 399 this->energyWidget->setMaximum(this->getEnergyMax()); … … 352 427 if (likely(this->isActive())) 353 428 { 429 /** Disabled for releaseFire() from WM*/ 354 430 if (this->requestedAction != WA_NONE) 355 431 return; … … 378 454 { 379 455 this->energy += energyToAdd; 456 this->updateWidgets(); 380 457 return 0.0; 381 458 } … … 383 460 { 384 461 this->energy += maxAddEnergy; 462 this->updateWidgets(); 385 463 return energyToAdd - maxAddEnergy; 386 464 } 465 387 466 } 388 467 … … 431 510 break; 432 511 default: 433 PRINTF( 2)("Action %s Not Implemented yet \n", Weapon::actionToChar(action));512 PRINTF(5)("Action %s Not Implemented yet \n", Weapon::actionToChar(action)); 434 513 return false; 435 514 } … … 507 586 bool Weapon::fireW() 508 587 { 588 // printf("fireW Weapon\n"); 509 589 //if (likely(this->currentState != WS_INACTIVE)) 510 590 if (this->minCharge <= this->energy) … … 513 593 if (this->soundBuffers[WA_SHOOT].loaded()) 514 594 this->soundSource->play(this->soundBuffers[WA_SHOOT]); 515 this->updateWidgets();516 595 // fire 517 596 this->energy -= this->minCharge; … … 519 598 // setting up for the next state 520 599 this->enterState(WS_SHOOTING); 600 this->updateWidgets(); 521 601 } 522 602 else // reload if we still have the charge … … 538 618 unlikely(this->energy + this->ammoContainer->getStoredEnergy() < this->minCharge)) 539 619 { 540 this->requestAction(WA_DEACTIVATE);620 //this->requestAction(WA_DEACTIVATE); 541 621 this->execute(); 542 622 return false; -
trunk/src/world_entities/weapons/weapon.h
r9869 r10368 126 126 127 127 // EMISSION 128 /** keeping old functions*/ 129 void setEmissionPoint(const Vector& point, int barrel); 128 130 void setEmissionPoint(const Vector& point); 129 131 /** @see void setEmissionPoint(const Vector& point); */ 132 inline void setEmissionPoint(float x, float y, float z, int barrel) { this->setEmissionPoint(Vector(x, y, z), barrel); }; 130 133 inline void setEmissionPoint(float x, float y, float z) { this->setEmissionPoint(Vector(x, y, z)); }; 131 134 /** @returns the absolute Position of the EmissionPoint */ 132 inline const Vector& getEmissionPoint() const { return this->emissionPoint.getAbsCoor(); }; 135 inline const Vector& getEmissionPoint(int barrel) const { return this->emissionPoint[barrel]->getAbsCoor(); }; 136 inline const Vector& getEmissionPoint() const { return this->emissionPoint[0]->getAbsCoor(); }; 137 133 138 134 139 inline void setDefaultTarget(PNode* defaultTarget) { this->defaultTarget = defaultTarget; }; … … 158 163 159 164 Animation3D* getAnimation(WeaponState state, PNode* node = NULL); 165 Animation3D* getAnimation(int barrel, int seg, PNode* node); 160 166 Animation3D* copyAnimation(WeaponState from, WeaponState to); 161 167 … … 169 175 bool check() const; 170 176 void debug() const; 177 178 inline int getBarrels() {return this->barrels; }; 179 inline int getSegs() { return this->segs; }; 180 inline void setBarrels(int barrels) { this->barrels = barrels; }; 181 inline void setSegs(int segs) { this->segs = segs; }; 182 183 inline Animation3D* getShootAnim(int barrel, int seg) { return this->shootAnim[barrel][seg]; }; 184 inline void setShootAnim(int barrel, int seg, PNode* component) { this->shootAnim[barrel][seg] = this->getAnimation(barrel, seg, component); }; 185 186 void init2(); 187 void deconstr(); 171 188 172 189 protected: … … 184 201 static WeaponState charToState(const std::string& state); 185 202 static const char* stateToChar(WeaponState state); 203 204 186 205 187 206 private: … … 214 233 float maxCharge; //!< The maximal energy to be loaded onto one projectile (this is only availible if chargeable is enabled) 215 234 216 OrxGui::GLGuiEnergyWidget * energyWidget;235 OrxGui::GLGuiEnergyWidgetVertical* energyWidget; 217 236 218 237 PNode* defaultTarget; //!< A target for targeting Weapons. … … 230 249 OrxSound::SoundBuffer soundBuffers[WA_ACTION_COUNT]; //!< SoundBuffers for all actions @see WeaponAction. 231 250 232 PNode 251 PNode** emissionPoint; //!< The point, where the projectiles are emitted. (this is coppled with the Weapon by default) 233 252 234 253 bool hideInactive; //!< Hides the Weapon if it is inactive … … 237 256 ClassID projectile; //!< the projectile used for this weapon (since they should be generated via macro and the FastFactory, only the ClassID must be known.) 238 257 FastFactory* projectileFactory; //!< A factory, that produces and handles the projectiles. 258 259 int barrels; //!< # of barrels 260 int segs; //!< # of segments, one barrel has 261 Animation3D*** shootAnim; 262 239 263 }; 240 264 -
trunk/src/world_entities/weapons/weapon_manager.cc
r9869 r10368 103 103 104 104 this->currentConfigID = 0; 105 this->slotCount = 2;105 this->slotCount = WM_MAX_SLOTS; 106 106 //this->weaponChange; 107 107 … … 114 114 this->crossHairSizeAnim->addKeyFrame(100, .05, ANIM_LINEAR); 115 115 this->crossHairSizeAnim->addKeyFrame(50, .01, ANIM_LINEAR); 116 117 this->hideCrosshair(); 118 119 this->bFire = false; 120 } 121 122 void WeaponManager::showCrosshair() 123 { 124 this->crosshair->setVisibility( true); 125 } 126 127 void WeaponManager::hideCrosshair() 128 { 129 this->crosshair->setVisibility( false); 130 } 131 132 void WeaponManager::setRotationSpeed(float speed) 133 { 134 this->crosshair->setRotationSpeed(speed); 116 135 } 117 136 … … 300 319 if (this->parentEntity->isA(Playable::staticClassID())) 301 320 dynamic_cast<Playable*>(this->parentEntity)->weaponConfigChanged(); 321 302 322 weapon->setDefaultTarget(this->crosshair); 303 323 } … … 317 337 318 338 /** 319 * @brief does the same as the funtion inc lreaseAmmunition, added four your convenience339 * @brief does the same as the funtion increaseAmmunition, added four your convenience 320 340 * @param weapon, the Weapon to read the ammo-info about. 321 341 * @param ammo how much ammo to add. 322 342 */ 323 float WeaponManager::inc lreaseAmmunition(const Weapon* weapon, float ammo)343 float WeaponManager::increaseAmmunition(const Weapon* weapon, float ammo) 324 344 { 325 345 assert (weapon != NULL); … … 400 420 this->currentConfigID = weaponConfig; 401 421 PRINTF(4)("Changing weapon configuration: to %i\n", this->currentConfigID); 422 402 423 for (int i = 0; i < WM_MAX_SLOTS; i++) 403 424 this->currentSlotConfig[i].nextWeapon = this->configs[currentConfigID][i]; … … 410 431 void WeaponManager::fire() 411 432 { 433 // printf("firing WM: "); 412 434 Weapon* firingWeapon; 413 435 for(int i = 0; i < this->slotCount; i++) 414 436 { 437 // printf("%i ", i); 438 firingWeapon = this->currentSlotConfig[i].currentWeapon; 439 if( firingWeapon != NULL && firingWeapon->getCurrentState() == WS_SHOOTING) continue; 440 if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT); 441 } 442 // printf("\n"); 443 /* 444 this->crosshair->setRotationSpeed(500); 445 this->crossHairSizeAnim->replay(); 446 */ 447 } 448 449 /** 450 * triggers fire of all weapons in the current weaponconfig 451 */ 452 void WeaponManager::releaseFire() 453 { 454 Weapon* firingWeapon; 455 for(int i = 0; i < this->slotCount; i++) 456 { 415 457 firingWeapon = this->currentSlotConfig[i].currentWeapon; 416 if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT); 417 } 458 if( firingWeapon != NULL) firingWeapon->requestAction(WA_NONE); 459 } 460 461 /* 418 462 this->crosshair->setRotationSpeed(500); 419 463 this->crossHairSizeAnim->replay(); 420 } 421 464 */ 465 } 422 466 423 467 /** … … 429 473 Weapon* tickWeapon; 430 474 475 431 476 for(int i = 0; i < this->slotCount; i++) 432 477 { 433 /* 434 NICE LITTLE DEBUG FUNCTION435 if (this->currentSlotConfig[i].currentWeapon != NULL || this->currentSlotConfig[i].nextWeapon != NULL)478 479 //NICE LITTLE DEBUG FUNCTION 480 /* if (this->currentSlotConfig[i].currentWeapon != NULL || this->currentSlotConfig[i].nextWeapon != NULL) 436 481 printf("%p %p\n", this->currentSlotConfig[i].currentWeapon, this->currentSlotConfig[i].nextWeapon);*/ 437 482 … … 455 500 } 456 501 } 457 458 502 // switching to next Weapon 459 503 tickWeapon = this->currentSlotConfig[i].currentWeapon = this->currentSlotConfig[i].nextWeapon; 504 460 505 if (tickWeapon != NULL) 461 506 { 462 //if (this->parent != NULL)463 507 //if (this->parent != NULL) 508 tickWeapon->toList(this->parentEntity->getOMListNumber()); 464 509 tickWeapon->requestAction(WA_ACTIVATE); 465 510 this->currentSlotConfig[i].position.activateNode(); -
trunk/src/world_entities/weapons/weapon_manager.h
r9869 r10368 60 60 void loadWeapons(const TiXmlElement* root); 61 61 62 void showCrosshair(); 63 void hideCrosshair(); 64 void setRotationSpeed(float speed); 65 62 66 void setSlotCount(unsigned int slotCount); 63 67 unsigned int getSlotCount() const { return this->slotCount; }; … … 91 95 92 96 float increaseAmmunition(const ClassID& projectileType, float ammo); 93 float inc lreaseAmmunition(const Weapon* weapon, float ammo);97 float increaseAmmunition(const Weapon* weapon, float ammo); 94 98 95 99 /** @returns a fixed target namely the Crosshair's 3D position */ … … 99 103 //! @TODO: implement this function (maybe also in Weapon itself) 100 104 void releaseFire(); 105 //inline void setFire() { this->bFire = true; }; 101 106 102 107 void tick(float dt); … … 127 132 128 133 std::vector<CountPointer<AmmoContainer> > ammo; //!< Containers 134 135 bool bFire; 129 136 }; 130 137
Note: See TracChangeset
for help on using the changeset viewer.