Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6438 in orxonox.OLD for trunk/src/world_entities/weapons/weapon.cc


Ignore:
Timestamp:
Jan 8, 2006, 1:51:55 PM (18 years ago)
Author:
bensch
Message:

trunk: widget war

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/weapons/weapon.cc

    r6435 r6438  
    3434#include "sound_buffer.h"
    3535
     36#include "glgui_bar.h"
     37
    3638////////////////////
    3739// INITAILISATION //
     
    7577  this->stateDuration    = 0.0;                    //< All the States have zero duration
    7678  for (int i = 0; i < WS_STATE_COUNT; i++)         //< Every State has:
    77     {
    78       this->times[i] = 0.0;                        //< An infinitesimal duration
    79       this->animation[i] = NULL;                   //< No animation
    80     }
     79  {
     80    this->times[i] = 0.0;                        //< An infinitesimal duration
     81    this->animation[i] = NULL;                   //< No animation
     82  }
    8183  for (int i = 0; i < WA_ACTION_COUNT; i++)
    8284    this->soundBuffers[i] = NULL;                  //< No Sounds
     
    98100  this->energyMax = 10.0;                          //< How much energy can be carried
    99101  this->capability = WTYPE_ALL;                    //< The Weapon has all capabilities @see W_Capability.
     102
     103  this->energyWidget = NULL;
     104  this->energyLoadedWidget = NULL;
    100105}
    101106
     
    109114
    110115  LoadParam(root, "projectile", this, Weapon, setProjectileType)
    111       .describe("Sets the name of the Projectile to load onto the Entity");
     116  .describe("Sets the name of the Projectile to load onto the Entity");
    112117
    113118  LoadParam(root, "emission-point", this, Weapon, setEmissionPoint)
    114       .describe("Sets the Point of emission of this weapon");
     119  .describe("Sets the Point of emission of this weapon");
    115120
    116121  LoadParam(root, "state-duration", this, Weapon, setStateDuration)
    117       .describe("Sets the duration of a given state (1: state-Name; 2: duration in seconds)");
     122  .describe("Sets the duration of a given state (1: state-Name; 2: duration in seconds)");
    118123
    119124  LoadParam(root, "action-sound", this, Weapon, setActionSound)
    120       .describe("Sets a given sound to an action (1: action-Name; 2: name of the sound (relative to the Data-Path))");
     125  .describe("Sets a given sound to an action (1: action-Name; 2: name of the sound (relative to the Data-Path))");
    121126}
    122127
     
    271276}
    272277
     278GLGuiWidget* Weapon::getEnergyWidget()
     279{
     280  if (this->energyWidget == NULL)
     281  {
     282    this->energyWidget = new GLGuiBar;
     283    this->energyWidget->setSize2D( 20, 100);
     284    this->energyWidget->setMaximum(this->getEnergyMax());
     285    this->energyWidget->setValue(this->getEnergy());
     286  }
     287  return this->energyWidget;
     288}
     289
     290
     291GLGuiWidget* Weapon::getMaxEnergyWidget()
     292{
     293  if (this->energyLoadedWidget == NULL)
     294  {
     295    this->energyLoadedWidget = new GLGuiBar;
     296    //this->energyLoadedWidget->setParent2D(this->bar);
     297    this->energyLoadedWidget->setRelCoor2D(20,0);
     298    this->energyLoadedWidget->setSize2D(10,50);
     299    this->energyLoadedWidget->setMaximum(this->getLoadedEnergyMax());
     300  }
     301  return this->energyLoadedWidget;
     302}
     303
     304void Weapon::updateWidgets()
     305{
     306  if (this->energyWidget != NULL)
     307  {
     308    this->energyWidget->setMaximum(this->energyMax);
     309    this->energyWidget->setValue(this->energy);
     310  }
     311  if (this->energyLoadedWidget != NULL)
     312  {
     313    this->energyLoadedWidget->setMaximum(this->energyLoadedMax);
     314    this->energyLoadedWidget->setValue(this->energyLoaded);
     315  }
     316}
     317
    273318/////////////////
    274319//  EXECUTION  //
     
    371416bool Weapon::activateW()
    372417{
    373 //  if (this->currentState == WS_INACTIVE)
     418  //  if (this->currentState == WS_INACTIVE)
    374419  {
    375420    // play Sound
    376421    if (likely(this->soundBuffers[WA_ACTIVATE] != NULL))
    377422      this->soundSource->play(this->soundBuffers[WA_ACTIVATE]);
    378         // activate
     423    // activate
    379424    PRINTF(4)("Activating the Weapon %s\n", this->getName());
    380425    this->activate();
     
    390435bool Weapon::deactivateW()
    391436{
    392 //  if (this->currentState != WS_INACTIVE)
     437  //  if (this->currentState != WS_INACTIVE)
    393438  {
    394439    PRINTF(4)("Deactivating the Weapon %s\n", this->getName());
    395         // play Sound
     440    // play Sound
    396441    if (this->soundBuffers[WA_DEACTIVATE] != NULL)
    397442      this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]);
     
    410455  if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge)
    411456  {
    412         // playing Sound
     457    // playing Sound
    413458    if (this->soundBuffers[WA_CHARGE] != NULL)
    414459      this->soundSource->play(this->soundBuffers[WA_CHARGE]);
    415460
    416         // charge
     461    // charge
    417462    this->charge();
    418         // setting up for the next state
     463    // setting up for the next state
    419464    this->enterState(WS_CHARGING);
    420465  }
     
    431476bool Weapon::fireW()
    432477{
    433      //if (likely(this->currentState != WS_INACTIVE))
     478  //if (likely(this->currentState != WS_INACTIVE))
    434479  if (this->minCharge <= this->energyLoaded)
    435480  {
    436           // playing Sound
     481    // playing Sound
    437482    if (this->soundBuffers[WA_SHOOT] != NULL)
    438483      this->soundSource->play(this->soundBuffers[WA_SHOOT]);
    439           // fire
     484    // fire
    440485    this->energyLoaded -= this->minCharge;
    441486    this->fire();
    442           // setting up for the next state
     487    // setting up for the next state
    443488    this->enterState(WS_SHOOTING);
    444489  }
     
    546591  bool retVal = true;
    547592
    548 //  if (this->projectile == NULL)
     593  //  if (this->projectile == NULL)
    549594  {
    550595    PRINTF(1)("There was no projectile assigned to the Weapon.\n");
     
    565610  PRINT(0)("Weapon-Debug %s, state: %s (duration: %fs), nextAction: %s\n", this->getName(), Weapon::stateToChar(this->currentState), this->stateDuration, Weapon::actionToChar(requestedAction));
    566611  PRINT(0)("Energy: max: %f; current: %f;  loadedMax: %f; loadedCurrent: %f; chargeMin: %f, chargeMax %f\n",
    567             this->energyMax, this->energy, this->energyLoadedMax, this->energyLoaded, this->minCharge, this->maxCharge);
     612           this->energyMax, this->energy, this->energyLoadedMax, this->energyLoaded, this->minCharge, this->maxCharge);
    568613
    569614
     
    595640    return WA_SPECIAL1;
    596641  else
    597     {
    598       PRINTF(2)("action %s could not be identified.\n", action);
    599       return WA_NONE;
    600     }
     642  {
     643    PRINTF(2)("action %s could not be identified.\n", action);
     644    return WA_NONE;
     645  }
    601646}
    602647
     
    658703    return WS_IDLE;
    659704  else
    660     {
    661       PRINTF(2)("state %s could not be identified.\n", state);
    662       return WS_NONE;
    663     }
     705  {
     706    PRINTF(2)("state %s could not be identified.\n", state);
     707    return WS_NONE;
     708  }
    664709}
    665710
Note: See TracChangeset for help on using the changeset viewer.