Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6693 in orxonox.OLD for branches/network/src/world_entities/weapons


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

branches: removed spaceshipcontrol branche

Location:
branches/network/src/world_entities/weapons
Files:
12 edited
2 copied

Legend:

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

    r6512 r6693  
    7373  this->source = NULL;
    7474
     75  this->range = 0;
     76  this->angle = 0;
    7577  this->anim = new tAnimation<Aim>(this, &Aim::setSize);
    7678  this->anim->setInfinity(ANIM_INF_CONSTANT);
     
    101103}
    102104
    103 void Aim::searchTarget(float range)
     105void Aim::searchTarget()
    104106{
    105107  std::list<WorldEntity*>::iterator entity;
    106 
     108  Vector diffVec(0.0, 0.0, 0.0);
     109  diffVec = ( this->getAbsCoor() - this->source->getAbsCoor() );
     110
     111//only look for target if the aim hasn`t locked a target yet or if the actual target is out of range
     112  if( this == PNode::getNullParent() || diffVec.len() > range  || ( acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) ) > angle))
    107113  for (entity = State::getObjectManager()->getObjectList(OM_GROUP_00).begin();
    108114       entity != State::getObjectManager()->getObjectList(OM_GROUP_00).end();
    109115       entity ++)
    110116  {
    111     if (this->source->getAbsCoor().x < (*entity)->getAbsCoor().x && (this->source->getAbsCoor() - (*entity)->getAbsCoor()).len() < range)
     117    diffVec = ( (*entity)->getAbsCoor() - this->source->getAbsCoor() );
     118
     119    if ( diffVec.len() < range  &&  acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) ) < angle)
    112120    {
    113121      if (this->getParent() != (*entity))
     
    119127    }
    120128  }
    121 }
    122 
     129//if no target found:
     130  this->setParent(PNode::getNullParent());
     131}
    123132
    124133
     
    155164
    156165
    157   if (this->source->getAbsCoor().x > this->getAbsCoor().x )
    158     this->searchTarget(1000);
     166//  if (this->source->getAbsCoor().x > this->getAbsCoor().x )
     167     this->searchTarget();
    159168//   float z = 0.0f;
    160169//   glReadPixels ((int)this->getAbsCoor2D().x,
  • branches/network/src/world_entities/weapons/aim.h

    r6512 r6693  
    3838  inline PNode* getTarget(PNode* target) { return this->getParent(); };
    3939
    40   void searchTarget(float range);
     40  void searchTarget();
     41
     42  void setRange(float range){this->range = range;};
     43  void setAngle(float angle){this->angle = angle;};
    4144
    4245  void setSize(float size);
     
    5356   tAnimation<Aim>* anim;
    5457
     58   float            range;                //!<
     59   float            angle;                //!<
     60
    5561   PNode*           source;               //!< Where this Shot has come from.
    5662
  • branches/network/src/world_entities/weapons/aiming_turret.cc

    r6512 r6693  
    8686  this->setStateDuration(WS_DEACTIVATING, .4);
    8787
    88   this->setMaximumEnergy(10000, 50);
     88  this->setEnergyMax(10000);
    8989  this->increaseEnergy(100000);
    9090
     
    9898  this->target = new Aim(this);
    9999  this->target->setVisibility(false);
     100  this->target->setRange(100);
     101  this->target->setAngle(M_PI);
    100102}
    101103
     
    146148  pj->setAbsDir(this->getAbsDir());
    147149  pj->activate();
    148   this->target->searchTarget(100);
     150  this->target->searchTarget();
    149151}
    150152
  • branches/network/src/world_entities/weapons/cannon.cc

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

    r6675 r6693  
    8181  this->setStateDuration(WS_DEACTIVATING, .4);
    8282
    83   this->setMaximumEnergy(10000, 50);
     83  this->setEnergyMax(10000);
    8484  this->increaseEnergy(100000);
    8585
     
    9393  this->target = new Aim(this);
    9494  this->target->setVisibility(false);
    95 
     95  this->target->setRange(100);
     96  this->target->setAngle(M_PI_4/2);
     97  this->lockedTime = 0;
     98  this->neededLockTime = 2;
     99  this->lockedTarget->setParent(PNode::getNullParent());
    96100  this->loadModel("models/guns/turret2.obj");
    97101
     
    120124void TargetingTurret::tick(float dt)
    121125{
     126  if( lockedTime >= neededLockTime )
     127   {
     128    lockedTarget = this->target->getParent();
     129    lockedTime = 0;
     130   }
    122131
    123132  this->target->tick(dt);
     133
     134  if(this->target->getParent() == PNode::getNullParent())
     135   lockedTime = 0;
     136  else
     137   lockedTime += dt;
     138
    124139}
    125140
     
    138153  pj->setAbsDir(this->getAbsDir());
    139154  pj->activate();
    140   this->target->searchTarget(100);
     155  this->target->searchTarget();
    141156}
    142157
  • branches/network/src/world_entities/weapons/targeting_turret.h

    r6512 r6693  
    3232
    3333  private:
    34     Aim*          target;
    35   };
     34    Aim*           target;
     35    PNode*         lockedTarget;
     36    float          lockedTime;
     37    float          neededLockTime;
     38  };
    3639
    3740#endif /* _TARGETING_TURRET_H */
  • branches/network/src/world_entities/weapons/test_gun.cc

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

    r6589 r6693  
    8686  this->setStateDuration(WS_DEACTIVATING, .4);
    8787
    88   this->setMaximumEnergy(100, 5);
     88  this->setEnergyMax(100);
    8989  this->increaseEnergy(100);
    9090  //this->minCharge = 2;
  • 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}
  • branches/network/src/world_entities/weapons/weapon.h

    r6512 r6693  
    1616
    1717#include "world_entity.h"
     18#include "count_pointer.h"
     19#include "ammo_container.h"
    1820
    1921// FORWARD DECLARATION
     
    105107    inline void setCapability(long capabilities) { this->capability = capabilities; };
    106108    /** @returns the Capabilities of this Weapon */
    107     inline long getCapability() { return this->capability; };
     109    inline long getCapability() const { return this->capability; };
    108110    void setProjectileType(ClassID projectile);
    109111    void setProjectileType(const char* projectile);
     
    135137    inline WeaponState getCurrentState() const { return this->currentState; };
    136138
    137     /** @param energyMax the maximum energy the Weapon can have @param energyLoadedMax the maximum energy in the weapon buffers */
    138     inline void setMaximumEnergy(float energyMax, float energyLoadedMax) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; };
    139     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; };
    140142    inline float getEnergyMax() const { return this->energyMax; };
    141     inline float getEnergy() const { return this->energy; };
    142     inline float getLoadedEnergy() const { return this->energyLoaded; };
     143    inline void setAmmoContainer(const CountPointer<AmmoContainer>& ammoContainer) { this->ammoContainer = ammoContainer;}
    143144
    144145    void setActionSound(WeaponAction action, const char* soundFile);
     
    150151
    151152    GLGuiWidget* getEnergyWidget();
    152     GLGuiWidget* getLoadedEnergyWidget();
    153153
    154154    // FLOW
     
    198198
    199199    // it is all about energy
    200     float                energy;                           //!< The energy stored in the weapons secondary buffers (reserve)
    201     float                energyLoaded;                     //!< The energy stored in the weapons primary buffers (fire without reload)
     200    float                energy;                           //!< The energy stored in the weapons buffers
    202201    float                energyMax;                        //!< The maximal energy that can be stored in the secondary buffers (reserveMax)
    203     float                energyLoadedMax;                  //!< The maximal energy that can be stored in the primary buffers
     202    CountPointer<AmmoContainer> ammoContainer;             //!< Pointer to the AmmoContainer this weapon grabs Energy from.
    204203    //! @todo move this to projectile
    205204    float                minCharge;                        //!< The minimal energy to be loaded onto one projectile if chargeable otherwise the power consumed by one projectile
     
    207206
    208207    GLGuiBar*            energyWidget;
    209     GLGuiBar*            energyLoadedWidget;
    210208
    211209    ////////////
  • branches/network/src/world_entities/weapons/weapon_manager.cc

    r6568 r6693  
    217217bool WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID)
    218218{
     219  assert(weapon != NULL);
     220
    219221  if (unlikely(configID >= WM_MAX_CONFIGS || slotID >= (int)this->slotCount))
    220222  {
    221     PRINTF(2)("Slot %d of config %d is not availiabe (max: %d)\n", slotID, configID, this->slotCount);
     223    PRINTF(2)("Slot %d of config %d is not availiabe (max: %d) searching for suitable slot\n", slotID, configID, this->slotCount);
     224    if (configID >= WM_MAX_CONFIGS)
     225      configID = -1;
     226    if (slotID >= (int)this->slotCount)
     227      slotID = -1;
     228  }
     229  // if no ConfigID is supplied set to Current Config.
     230  if (configID <= -1)
     231    configID = this->currentConfigID;
     232  //
     233  if (configID > -1 && slotID == -1)
     234  {
     235    slotID = this->getNextFreeSlot(configID, weapon->getCapability());
     236    if (slotID == -1)
     237      configID = -1;
     238  }
     239
     240  if (configID > 0 && slotID > 0 && this->configs[configID][slotID] != NULL)
     241  {
     242    PRINTF(3)("Weapon-slot %d/%d of %s already poulated, remove weapon (%s::%s) first\n", configID, slotID, this->getName(), weapon->getClassName(), weapon->getName());
    222243    return false;
    223244  }
    224245
    225   if (this->configs[configID][slotID] != NULL && configID > 0 && slotID > 0)
    226     PRINTF(3)("Weapon-slot %d/%d of %s already poulated, overwriting\n", configID, slotID, this->getName());
    227 
    228   if (slotID == -1) // WM_FREE_SLOT
     246  if (slotID <= -1) // WM_FREE_SLOT
    229247  {
    230248    slotID = this->getNextFreeSlot(configID, weapon->getCapability());
     
    245263
    246264  //! @todo check if the weapon is already assigned to another config in another slot
     265  assert(this->configs[configID][slotID] == NULL);
     266
    247267  this->configs[configID][slotID] = weapon;
     268  weapon->setAmmoContainer(this->getAmmoContainer(weapon->getProjectileType()));
    248269  if (this->parent != NULL)
    249270  {
    250271    this->parent->addChild(weapon);
    251272  }
    252   PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);
     273  PRINTF(3)("Added a new Weapon (%s::%s) to the WeaponManager: config %i/ slot %i\n", weapon->getClassName(), weapon->getName(), configID, slotID);
    253274  return true;
    254275}
     
    420441/**
    421442 * private gets the next free slot in a certain weaponconfig
    422  * @param the selected weaponconfig
     443 * @param the selected weaponconfig -1 if none found
    423444 */
    424445int WeaponManager::getNextFreeSlot(int configID, long capability)
    425446{
    426   for( int i = 0; i < this->slotCount; ++i)
    427   {
    428     if( this->configs[configID][i] == NULL &&
    429         (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) &&
    430         (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS))
    431       return i;
     447  if (configID == -1)
     448  {
     449    for (configID = 0; configID < WM_MAX_CONFIGS; configID++)
     450      for( int i = 0; i < this->slotCount; ++i)
     451      {
     452        if( this->configs[configID][i] == NULL &&
     453            (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) &&
     454            (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS))
     455          return i;
     456    }
     457  }
     458  else
     459  {
     460    for( int i = 0; i < this->slotCount; ++i)
     461    {
     462      if( this->configs[configID][i] == NULL &&
     463          (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) &&
     464          (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS))
     465        return i;
     466    }
    432467  }
    433468  return -1;
    434469}
    435470
     471CountPointer<AmmoContainer>& WeaponManager::getAmmoContainer(ClassID projectileType)
     472{
     473  for (unsigned int i = 0; i < this->ammo.size(); i++)
     474  {
     475    if (this->ammo[i]->getProjectileType() == projectileType)
     476      return this->ammo[i];
     477  }
     478  this->ammo.push_back(CountPointer<AmmoContainer>(new AmmoContainer(projectileType)));
     479  return this->ammo.back();
     480}
    436481
    437482
  • branches/network/src/world_entities/weapons/weapon_manager.h

    r6561 r6693  
    1717#include "crosshair.h"
    1818#include "weapon.h"
     19
     20#include "count_pointer.h"
     21#include "ammo_container.h"
    1922
    2023// FORWARD DECLARATION
     
    7174    PNode* getParent() const { return this->parent; };
    7275
    73     bool addWeapon(Weapon* weapon);
    7476    bool addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
    7577    void removeWeapon(Weapon* weapon, int configID = -1);
     78
    7679    Weapon* getWeapon(int slotID) const { return (slotID >= 0 && slotID < this->slotCount)? this->currentSlotConfig[slotID].nextWeapon: NULL; };
    7780
     
    8285    void previousWeaponConfig();
    8386    void changeWeaponConfig(int weaponConfig);
     87
     88    float addAmmunition(ClassID projectileType, float ammo);
     89
    8490
    8591    /** @returns a fixed target namely the Crosshair's 3D position */
     
    97103 // private:
    98104    int getNextFreeSlot(int configID, long capability = WTYPE_ALL);
     105    CountPointer<AmmoContainer>& getAmmoContainer(ClassID projectileType);
    99106
    100107  private:
     
    112119    Crosshair*              crosshair;                                //!< an aim.
    113120    tAnimation<Crosshair>*  crossHairSizeAnim;                        //!< An animation for the crosshair (scaling)
     121
     122    std::vector<CountPointer<AmmoContainer> > ammo;                   //!< Containers
    114123};
    115124
Note: See TracChangeset for help on using the changeset viewer.