Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.