Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 25, 2006, 2:19:46 PM (18 years ago)
Author:
patrick
Message:

branches: removed spaceshipcontrol branche

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/world_entities/weapons/weapon.cc

    r6674 r6693  
    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  // set this object to be synchronized over network
     
    291288}
    292289
    293 
    294 GLGuiWidget* Weapon::getLoadedEnergyWidget()
    295 {
    296   if (this->energyLoadedWidget == NULL)
    297   {
    298     this->energyLoadedWidget = new GLGuiBar;
    299     //this->energyLoadedWidget->setParent2D(this->bar);
    300     this->energyLoadedWidget->setRelCoor2D(20,0);
    301     this->energyLoadedWidget->setSize2D(10,50);
    302     this->energyLoadedWidget->setMaximum(this->getLoadedEnergyMax());
    303   }
    304   return this->energyLoadedWidget;
    305 }
    306 
    307290void Weapon::updateWidgets()
    308291{
     
    311294    this->energyWidget->setMaximum(this->energyMax);
    312295    this->energyWidget->setValue(this->energy);
    313   }
    314   if (this->energyLoadedWidget != NULL)
    315   {
    316     this->energyLoadedWidget->setMaximum(this->energyLoadedMax);
    317     this->energyLoadedWidget->setValue(this->energyLoaded);
    318296  }
    319297}
     
    395373  switch (action)
    396374  {
    397     case WA_SHOOT:
    398       return this->fireW();
    399       break;
    400     case WA_CHARGE:
    401       return this->chargeW();
    402       break;
    403     case WA_RELOAD:
    404       return this->reloadW();
    405       break;
    406     case WA_DEACTIVATE:
    407       return this->deactivateW();
    408       break;
    409     case WA_ACTIVATE:
    410       return this->activateW();
    411       break;
     375  case WA_SHOOT:
     376    return this->fireW();
     377    break;
     378  case WA_CHARGE:
     379    return this->chargeW();
     380    break;
     381  case WA_RELOAD:
     382    return this->reloadW();
     383    break;
     384  case WA_DEACTIVATE:
     385    return this->deactivateW();
     386    break;
     387  case WA_ACTIVATE:
     388    return this->activateW();
     389    break;
    412390  }
    413391}
     
    457435bool Weapon::chargeW()
    458436{
    459   if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge)
     437  if ( this->currentState != WS_INACTIVE && this->energy >= this->minCharge)
    460438  {
    461439    // playing Sound
     
    481459{
    482460  //if (likely(this->currentState != WS_INACTIVE))
    483   if (this->minCharge <= this->energyLoaded)
     461  if (this->minCharge <= this->energy)
    484462  {
    485463    // playing Sound
     
    488466    this->updateWidgets();
    489467    // fire
    490     this->energyLoaded -= this->minCharge;
     468    this->energy -= this->minCharge;
    491469    this->fire();
    492470    // setting up for the next state
     
    507485{
    508486  PRINTF(4)("Reloading Weapon %s\n", this->getName());
    509   if (unlikely(this->energy + this->energyLoaded < this->minCharge))
     487  if (this->ammoContainer.get() != NULL &&
     488        unlikely(this->energy + this->ammoContainer->getStoredEnergy() < this->minCharge))
    510489  {
    511490    this->requestAction(WA_DEACTIVATE);
     
    514493  }
    515494
    516   float chargeSize = this->energyLoadedMax - this->energyLoaded;       //!< The energy to be charged
    517495
    518496  if (this->soundBuffers[WA_RELOAD] != NULL)
    519497    this->soundSource->play(this->soundBuffers[WA_RELOAD]);
    520498
    521   if (chargeSize > this->energy)
    522   {
    523     this->energyLoaded += this->energy;
    524     this->energy = 0.0;
    525     PRINT(5)("Energy depleted\n");
    526   }
    527   else
    528   {
    529     PRINTF(5)("Loaded %f energy into the Guns Buffer\n", chargeSize);
    530     this->energyLoaded += chargeSize;
    531     this->energy -= chargeSize;
    532   }
    533 
     499  if (this->ammoContainer.get() != NULL)
     500    this->ammoContainer->fillWeapon(this);
     501  else
     502  {
     503    this->energy = this->energyMax;
     504  }
    534505  this->updateWidgets();
    535506  this->reload();
     
    617588{
    618589  PRINT(0)("Weapon-Debug %s, state: %s (duration: %fs), nextAction: %s\n", this->getName(), Weapon::stateToChar(this->currentState), this->stateDuration, Weapon::actionToChar(requestedAction));
    619   PRINT(0)("Energy: max: %f; current: %f;  loadedMax: %f; loadedCurrent: %f; chargeMin: %f, chargeMax %f\n",
    620            this->energyMax, this->energy, this->energyLoadedMax, this->energyLoaded, this->minCharge, this->maxCharge);
     590  PRINT(0)("Energy: max: %f; current: %f; chargeMin: %f, chargeMax %f\n",
     591           this->energyMax, this->energy, this->minCharge, this->maxCharge);
    621592
    622593
     
    663634  switch (action)
    664635  {
    665     case WA_SHOOT:
    666       return "shoot";
    667       break;
    668     case WA_CHARGE:
    669       return "charge";
    670       break;
    671     case WA_RELOAD:
    672       return "reload";
    673       break;
    674     case WA_ACTIVATE:
    675       return "activate";
    676       break;
    677     case WA_DEACTIVATE:
    678       return "deactivate";
    679       break;
    680     case WA_SPECIAL1:
    681       return "special1";
    682       break;
    683     default:
    684       return "none";
    685       break;
     636  case WA_SHOOT:
     637    return "shoot";
     638    break;
     639  case WA_CHARGE:
     640    return "charge";
     641    break;
     642  case WA_RELOAD:
     643    return "reload";
     644    break;
     645  case WA_ACTIVATE:
     646    return "activate";
     647    break;
     648  case WA_DEACTIVATE:
     649    return "deactivate";
     650    break;
     651  case WA_SPECIAL1:
     652    return "special1";
     653    break;
     654  default:
     655    return "none";
     656    break;
    686657  }
    687658}
     
    726697  switch (state)
    727698  {
    728     case WS_SHOOTING:
    729       return "shooting";
    730       break;
    731     case WS_CHARGING:
    732       return "charging";
    733       break;
    734     case WS_RELOADING:
    735       return "reloading";
    736       break;
    737     case WS_ACTIVATING:
    738       return "activating";
    739       break;
    740     case WS_DEACTIVATING:
    741       return "deactivating";
    742       break;
    743     case WS_IDLE:
    744       return "idle";
    745       break;
    746     case WS_INACTIVE:
    747       return "inactive";
    748       break;
    749     default:
    750       return "none";
    751       break;
    752   }
    753 }
     699  case WS_SHOOTING:
     700    return "shooting";
     701    break;
     702  case WS_CHARGING:
     703    return "charging";
     704    break;
     705  case WS_RELOADING:
     706    return "reloading";
     707    break;
     708  case WS_ACTIVATING:
     709    return "activating";
     710    break;
     711  case WS_DEACTIVATING:
     712    return "deactivating";
     713    break;
     714  case WS_IDLE:
     715    return "idle";
     716    break;
     717  case WS_INACTIVE:
     718    return "inactive";
     719    break;
     720  default:
     721    return "none";
     722    break;
     723  }
     724}
Note: See TracChangeset for help on using the changeset viewer.