Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6671 in orxonox.OLD


Ignore:
Timestamp:
Jan 24, 2006, 2:52:25 PM (18 years ago)
Author:
bensch
Message:

WeaponManger now handles Ammo.
If a Weapon has NO ammo then the Ammo will be infinite

Location:
trunk/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/util/hud.cc

    r6512 r6671  
    126126    {
    127127      weapon->getEnergyWidget()->show();
    128       weapon->getLoadedEnergyWidget()->show();
    129128      this->weaponsWidgets.push_back(weapon->getEnergyWidget());
    130       this->weaponsWidgets.push_back(weapon->getLoadedEnergyWidget());
    131129    }
    132130  }
  • trunk/src/world_entities/weapons/aiming_turret.cc

    r6637 r6671  
    8686  this->setStateDuration(WS_DEACTIVATING, .4);
    8787
    88   this->setMaximumEnergy(10000, 50);
     88  this->setEnergyMax(10000);
    8989  this->increaseEnergy(100000);
    9090
  • trunk/src/world_entities/weapons/ammo_container.h

    r6669 r6671  
    2828  float decreaseEnergy(float energy);
    2929
     30  float getStoredEnergy() const { return this->energy; };
    3031  float getMaxEnergy() const { return this->maxEnergy; };
    3132
  • trunk/src/world_entities/weapons/cannon.cc

    r6517 r6671  
    8181  this->setStateDuration(WS_DEACTIVATING, .4);
    8282
    83   this->setMaximumEnergy(100, 20);
     83  this->setEnergyMax(100);
    8484  this->increaseEnergy(100);
    8585  //this->minCharge = 2;
  • trunk/src/world_entities/weapons/targeting_turret.cc

    r6637 r6671  
    8080  this->setStateDuration(WS_DEACTIVATING, .4);
    8181
    82   this->setMaximumEnergy(10000, 50);
     82  this->setEnergyMax(10000);
    8383  this->increaseEnergy(100000);
    8484
  • trunk/src/world_entities/weapons/test_gun.cc

    r6512 r6671  
    122122  this->setStateDuration(WS_DEACTIVATING, .4);
    123123
    124   this->setMaximumEnergy(1000, 100);
     124  this->setEnergyMax(1000);
    125125  this->increaseEnergy(1000);
    126126  //this->minCharge = 2;
  • trunk/src/world_entities/weapons/turret.cc

    r6589 r6671  
    8686  this->setStateDuration(WS_DEACTIVATING, .4);
    8787
    88   this->setMaximumEnergy(100, 5);
     88  this->setEnergyMax(100);
    8989  this->increaseEnergy(100);
    9090  //this->minCharge = 2;
  • trunk/src/world_entities/weapons/weapon.cc

    r6512 r6671  
    9595  this->maxCharge = 1.0;                           //< The maximum charge is also one unit.
    9696
    97   this->energyLoaded = .0;                         //< How much energy is loaded in the Gun. (Weapons must be charged befor usage)
    98   this->energyLoadedMax = 5.0;                     //< Each Weapon has a Maximum energy that can be charged onto it
    99   this->energy = .0;                               //< The secondary Buffer (before we have to reload)
     97  this->energy = 10;                               //< The secondary Buffer (before we have to reload)
    10098  this->energyMax = 10.0;                          //< How much energy can be carried
    10199  this->capability = WTYPE_ALL;                    //< The Weapon has all capabilities @see W_Capability.
    102100
    103101  this->energyWidget = NULL;
    104   this->energyLoadedWidget = NULL;
    105102}
    106103
     
    288285}
    289286
    290 
    291 GLGuiWidget* Weapon::getLoadedEnergyWidget()
    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 
    304287void Weapon::updateWidgets()
    305288{
     
    308291    this->energyWidget->setMaximum(this->energyMax);
    309292    this->energyWidget->setValue(this->energy);
    310   }
    311   if (this->energyLoadedWidget != NULL)
    312   {
    313     this->energyLoadedWidget->setMaximum(this->energyLoadedMax);
    314     this->energyLoadedWidget->setValue(this->energyLoaded);
    315293  }
    316294}
     
    392370  switch (action)
    393371  {
    394     case WA_SHOOT:
    395       return this->fireW();
    396       break;
    397     case WA_CHARGE:
    398       return this->chargeW();
    399       break;
    400     case WA_RELOAD:
    401       return this->reloadW();
    402       break;
    403     case WA_DEACTIVATE:
    404       return this->deactivateW();
    405       break;
    406     case WA_ACTIVATE:
    407       return this->activateW();
    408       break;
     372  case WA_SHOOT:
     373    return this->fireW();
     374    break;
     375  case WA_CHARGE:
     376    return this->chargeW();
     377    break;
     378  case WA_RELOAD:
     379    return this->reloadW();
     380    break;
     381  case WA_DEACTIVATE:
     382    return this->deactivateW();
     383    break;
     384  case WA_ACTIVATE:
     385    return this->activateW();
     386    break;
    409387  }
    410388}
     
    454432bool Weapon::chargeW()
    455433{
    456   if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge)
     434  if ( this->currentState != WS_INACTIVE && this->energy >= this->minCharge)
    457435  {
    458436    // playing Sound
     
    478456{
    479457  //if (likely(this->currentState != WS_INACTIVE))
    480   if (this->minCharge <= this->energyLoaded)
     458  if (this->minCharge <= this->energy)
    481459  {
    482460    // playing Sound
     
    485463    this->updateWidgets();
    486464    // fire
    487     this->energyLoaded -= this->minCharge;
     465    this->energy -= this->minCharge;
    488466    this->fire();
    489467    // setting up for the next state
     
    504482{
    505483  PRINTF(4)("Reloading Weapon %s\n", this->getName());
    506   if (unlikely(this->energy + this->energyLoaded < this->minCharge))
     484  if (this->ammoContainer.get() != NULL &&
     485        unlikely(this->energy + this->ammoContainer->getStoredEnergy() < this->minCharge))
    507486  {
    508487    this->requestAction(WA_DEACTIVATE);
     
    511490  }
    512491
    513   float chargeSize = this->energyLoadedMax - this->energyLoaded;       //!< The energy to be charged
    514492
    515493  if (this->soundBuffers[WA_RELOAD] != NULL)
    516494    this->soundSource->play(this->soundBuffers[WA_RELOAD]);
    517495
    518   if (chargeSize > this->energy)
    519   {
    520     this->energyLoaded += this->energy;
    521     this->energy = 0.0;
    522     PRINT(5)("Energy depleted\n");
    523   }
    524   else
    525   {
    526     PRINTF(5)("Loaded %f energy into the Guns Buffer\n", chargeSize);
    527     this->energyLoaded += chargeSize;
    528     this->energy -= chargeSize;
    529   }
    530 
     496  if (this->ammoContainer.get() != NULL)
     497    this->ammoContainer->fillWeapon(this);
     498  else
     499  {
     500    this->energy = this->energyMax;
     501  }
    531502  this->updateWidgets();
    532503  this->reload();
     
    614585{
    615586  PRINT(0)("Weapon-Debug %s, state: %s (duration: %fs), nextAction: %s\n", this->getName(), Weapon::stateToChar(this->currentState), this->stateDuration, Weapon::actionToChar(requestedAction));
    616   PRINT(0)("Energy: max: %f; current: %f;  loadedMax: %f; loadedCurrent: %f; chargeMin: %f, chargeMax %f\n",
    617            this->energyMax, this->energy, this->energyLoadedMax, this->energyLoaded, this->minCharge, this->maxCharge);
     587  PRINT(0)("Energy: max: %f; current: %f; chargeMin: %f, chargeMax %f\n",
     588           this->energyMax, this->energy, this->minCharge, this->maxCharge);
    618589
    619590
     
    660631  switch (action)
    661632  {
    662     case WA_SHOOT:
    663       return "shoot";
    664       break;
    665     case WA_CHARGE:
    666       return "charge";
    667       break;
    668     case WA_RELOAD:
    669       return "reload";
    670       break;
    671     case WA_ACTIVATE:
    672       return "activate";
    673       break;
    674     case WA_DEACTIVATE:
    675       return "deactivate";
    676       break;
    677     case WA_SPECIAL1:
    678       return "special1";
    679       break;
    680     default:
    681       return "none";
    682       break;
     633  case WA_SHOOT:
     634    return "shoot";
     635    break;
     636  case WA_CHARGE:
     637    return "charge";
     638    break;
     639  case WA_RELOAD:
     640    return "reload";
     641    break;
     642  case WA_ACTIVATE:
     643    return "activate";
     644    break;
     645  case WA_DEACTIVATE:
     646    return "deactivate";
     647    break;
     648  case WA_SPECIAL1:
     649    return "special1";
     650    break;
     651  default:
     652    return "none";
     653    break;
    683654  }
    684655}
     
    723694  switch (state)
    724695  {
    725     case WS_SHOOTING:
    726       return "shooting";
    727       break;
    728     case WS_CHARGING:
    729       return "charging";
    730       break;
    731     case WS_RELOADING:
    732       return "reloading";
    733       break;
    734     case WS_ACTIVATING:
    735       return "activating";
    736       break;
    737     case WS_DEACTIVATING:
    738       return "deactivating";
    739       break;
    740     case WS_IDLE:
    741       return "idle";
    742       break;
    743     case WS_INACTIVE:
    744       return "inactive";
    745       break;
    746     default:
    747       return "none";
    748       break;
    749   }
    750 }
     696  case WS_SHOOTING:
     697    return "shooting";
     698    break;
     699  case WS_CHARGING:
     700    return "charging";
     701    break;
     702  case WS_RELOADING:
     703    return "reloading";
     704    break;
     705  case WS_ACTIVATING:
     706    return "activating";
     707    break;
     708  case WS_DEACTIVATING:
     709    return "deactivating";
     710    break;
     711  case WS_IDLE:
     712    return "idle";
     713    break;
     714  case WS_INACTIVE:
     715    return "inactive";
     716    break;
     717  default:
     718    return "none";
     719    break;
     720  }
     721}
  • trunk/src/world_entities/weapons/weapon.h

    r6669 r6671  
    137137    inline WeaponState getCurrentState() const { return this->currentState; };
    138138
    139     /** @param energyMax the maximum energy the Weapon can have @param energyLoadedMax the maximum energy in the weapon buffers */
    140     inline void setMaximumEnergy(float energyMax, float energyLoadedMax) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; };
    141     inline float getLoadedEnergyMax() const { return this->energyLoadedMax; };
     139    /** @param energyMax the maximum energy the Weapon can have */
     140    inline void setEnergyMax(float energyMax) { this->energyMax = energyMax; };
     141    inline float getEnergy() const { return this->energy; };
    142142    inline float getEnergyMax() const { return this->energyMax; };
    143143    inline void setAmmoContainer(const CountPointer<AmmoContainer>& ammoContainer) { this->ammoContainer = ammoContainer;}
    144     inline float getEnergy() const { return this->energy; };
    145     inline float getLoadedEnergy() const { return this->energyLoaded; };
    146144
    147145    void setActionSound(WeaponAction action, const char* soundFile);
     
    153151
    154152    GLGuiWidget* getEnergyWidget();
    155     GLGuiWidget* getLoadedEnergyWidget();
    156153
    157154    // FLOW
     
    201198
    202199    // it is all about energy
    203     float                energy;                           //!< The energy stored in the weapons secondary buffers (reserve)
    204     float                energyLoaded;                     //!< The energy stored in the weapons primary buffers (fire without reload)
     200    float                energy;                           //!< The energy stored in the weapons buffers
     201    float                energyMax;                        //!< The maximal energy that can be stored in the secondary buffers (reserveMax)
    205202    CountPointer<AmmoContainer> ammoContainer;             //!< Pointer to the AmmoContainer this weapon grabs Energy from.
    206     float                energyMax;                        //!< The maximal energy that can be stored in the secondary buffers (reserveMax)
    207     float                energyLoadedMax;                  //!< The maximal energy that can be stored in the primary buffers
    208203    //! @todo move this to projectile
    209204    float                minCharge;                        //!< The minimal energy to be loaded onto one projectile if chargeable otherwise the power consumed by one projectile
     
    211206
    212207    GLGuiBar*            energyWidget;
    213     GLGuiBar*            energyLoadedWidget;
    214208
    215209    ////////////
Note: See TracChangeset for help on using the changeset viewer.