Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10368 in orxonox.OLD for trunk/src/world_entities/weapons


Ignore:
Timestamp:
Jan 25, 2007, 2:18:07 PM (17 years ago)
Author:
patrick
Message:

merged the branche playability into the trunk

Location:
trunk
Files:
5 edited
14 copied

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        1010autom4te.cache
        1111aclocal.m4
         12tags
         13test.bmp
         14config.sub
         15config.guess
         16OrxonoxPlayability.kdevses
         17OrxonoxPlayability.kdevelop.pcs
  • trunk/src/world_entities/weapons/weapon.cc

    r9869 r10368  
    3333#include "resource_sound_buffer.h"
    3434
    35 #include "elements/glgui_energywidget.h"
     35#include "elements/glgui_energywidgetvertical.h"
    3636
    3737ObjectListDefinition(Weapon);
     
    119119  }
    120120
    121   this->soundSource = new OrxSound::SoundSource(this);       //< Every Weapon has exacty one SoundSource.
    122   this->emissionPoint.setParent(this);             //< One EmissionPoint, that is a PNode connected to the weapon. You can set this to the exitting point of the Projectiles
    123   this->emissionPoint.setName("EmissionPoint");
    124   this->emissionPoint.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     121  this->soundSource = new OrxSound::SoundSource(this);       //< Every Weapon has exacty one SoundSource
     122
     123  this->barrels = 1;
     124  this->segs = 1;
     125
     126  this->shootAnim = new Animation3D**[this->getBarrels()];
     127  for (int i = 0; i < this->getBarrels(); i++)
     128    this->shootAnim[i] = new Animation3D* [this->getSegs()];
     129
     130  this->emissionPoint = new PNode*[this->barrels];
     131  for(int i = 0; i < this->barrels; i++){
     132    this->emissionPoint[i] = new PNode;
     133    this->emissionPoint[i]->setParent(this);             //< One EmissionPoint, that is a PNode connected to the weapon. You can set this to the exitting point of the Projectiles
     134    this->emissionPoint[i]->setName("EmissionPoint");
     135    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     136  }
    125137
    126138  this->defaultTarget = NULL;                      //< Nothing is Targeted by default.
     
    145157
    146158/**
     159 * needed, if there are more than one barrel or segments
     160 */
     161void Weapon::init2()
     162{
     163  if (this->barrels == 1 && this->segs == 1)
     164    return;
     165
     166  delete this->emissionPoint[0];
     167  delete this->emissionPoint;
     168  delete this->shootAnim[0];
     169  delete this->shootAnim;
     170
     171  this->shootAnim = new Animation3D**[this->barrels];
     172  this->emissionPoint = new PNode*[this->barrels];
     173  for(int i = 0; i < this->barrels; i++){
     174    this->emissionPoint[i] = new PNode;
     175    this->emissionPoint[i]->setParent(this);             //< One EmissionPoint, that is a PNode connected to the weapon. You can set this to the exitting point of the Projectiles
     176    this->emissionPoint[i]->setName("EmissionPoint");
     177    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     178    this->shootAnim[i] = new Animation3D* [this->segs];
     179  }
     180}
     181
     182/**
     183 * deconstructor for init2
     184 */
     185void Weapon::deconstr()
     186{
     187  for(int i = 0; i < this->barrels; i++) {
     188    delete this->emissionPoint[i];
     189    for (int j = 0; j < this->segs; j++)
     190      delete this->shootAnim[i][j];
     191    delete this->shootAnim[i];
     192  }
     193
     194  delete this->emissionPoint;
     195  delete this->shootAnim;
     196}
     197
     198/**
    147199 * loads the Parameters of a Weapon
    148200 * @param root the XML-Element to load the Weapons settings from
     
    154206  LoadParam(root, "projectile", this, Weapon, setProjectileTypeC)
    155207  .describe("Sets the name of the Projectile to load onto the Entity");
    156 
     208/*
    157209  LoadParam(root, "emission-point", this, Weapon, setEmissionPoint)
    158   .describe("Sets the Point of emission of this weapon");
     210  .describe("Sets the Point of emission of this weapon (1: EmmsionVector; 2: EmissionPoint)");*/
    159211
    160212  LoadParam(root, "state-duration", this, Weapon, setStateDuration)
     
    253305 * @param point the Point relative to the mass-point of the Weapon
    254306 */
     307void Weapon::setEmissionPoint(const Vector& point, int barrel)
     308{
     309  this->emissionPoint[barrel]->setRelCoor(point);
     310}
     311
    255312void Weapon::setEmissionPoint(const Vector& point)
    256313{
    257   this->emissionPoint.setRelCoor(point);
    258 }
    259 
     314  this->emissionPoint[0]->setRelCoor(point);
     315}
    260316
    261317/**
     
    315371}
    316372
     373Animation3D* Weapon::getAnimation(int barrel, int seg, PNode* node)
     374{
     375  if (barrel >= this->getBarrels() || seg >= this->getSegs()) // if the state is not known
     376    return NULL;
     377
     378  if (unlikely(this->shootAnim[barrel][seg] == NULL)) // if the animation does not exist yet create it.
     379  {
     380    if (likely(node != NULL))
     381      return this->shootAnim[barrel][seg] = new Animation3D(node);
     382    else
     383    {
     384//       PRINTF(2)("Node not defined for the Creation of the 3D-animation of state %s\n", stateToChar(state));
     385      return NULL;
     386    }
     387  }
     388  else
     389    return this->shootAnim[barrel][seg];
     390}
     391
    317392OrxGui::GLGuiWidget* Weapon::getEnergyWidget()
    318393{
    319   if (this->energyWidget == NULL)
    320   {
    321     this->energyWidget = new OrxGui::GLGuiEnergyWidget();
    322     this->energyWidget->setDisplayedName(this->getClassCName());
     394  if ( this->energyWidget == NULL)
     395  {
     396    this->energyWidget = new OrxGui::GLGuiEnergyWidgetVertical();
     397    //this->energyWidget->setDisplayedName(this->getClassCName());
    323398    this->energyWidget->setSize2D( 20, 100);
    324399    this->energyWidget->setMaximum(this->getEnergyMax());
     
    352427  if (likely(this->isActive()))
    353428  {
     429    /** Disabled for releaseFire() from WM*/
    354430    if (this->requestedAction != WA_NONE)
    355431      return;
     
    378454  {
    379455    this->energy += energyToAdd;
     456    this->updateWidgets();
    380457    return 0.0;
    381458  }
     
    383460  {
    384461    this->energy += maxAddEnergy;
     462    this->updateWidgets();
    385463    return energyToAdd - maxAddEnergy;
    386464  }
     465 
    387466}
    388467
     
    431510    break;
    432511    default:
    433     PRINTF(2)("Action %s Not Implemented yet \n", Weapon::actionToChar(action));
     512    PRINTF(5)("Action %s Not Implemented yet \n", Weapon::actionToChar(action));
    434513    return false;
    435514  }
     
    507586bool Weapon::fireW()
    508587{
     588//   printf("fireW Weapon\n");
    509589  //if (likely(this->currentState != WS_INACTIVE))
    510590  if (this->minCharge <= this->energy)
     
    513593    if (this->soundBuffers[WA_SHOOT].loaded())
    514594      this->soundSource->play(this->soundBuffers[WA_SHOOT]);
    515     this->updateWidgets();
    516595    // fire
    517596    this->energy -= this->minCharge;
     
    519598    // setting up for the next state
    520599    this->enterState(WS_SHOOTING);
     600    this->updateWidgets();
    521601  }
    522602  else  // reload if we still have the charge
     
    538618      unlikely(this->energy + this->ammoContainer->getStoredEnergy() < this->minCharge))
    539619  {
    540     this->requestAction(WA_DEACTIVATE);
     620    //this->requestAction(WA_DEACTIVATE);
    541621    this->execute();
    542622    return false;
  • trunk/src/world_entities/weapons/weapon.h

    r9869 r10368  
    126126
    127127    // EMISSION
     128    /** keeping old functions*/
     129    void setEmissionPoint(const Vector& point, int barrel);
    128130    void setEmissionPoint(const Vector& point);
    129131    /** @see void setEmissionPoint(const Vector& point); */
     132    inline void setEmissionPoint(float x, float y, float z, int barrel) { this->setEmissionPoint(Vector(x, y, z), barrel); };
    130133    inline void setEmissionPoint(float x, float y, float z) { this->setEmissionPoint(Vector(x, y, z)); };
    131134    /** @returns the absolute Position of the EmissionPoint */
    132     inline const Vector& getEmissionPoint() const { return this->emissionPoint.getAbsCoor(); };
     135    inline const Vector& getEmissionPoint(int barrel) const { return this->emissionPoint[barrel]->getAbsCoor(); };
     136    inline const Vector& getEmissionPoint() const { return this->emissionPoint[0]->getAbsCoor(); };
     137
    133138
    134139    inline void setDefaultTarget(PNode* defaultTarget) { this->defaultTarget = defaultTarget; };
     
    158163
    159164    Animation3D* getAnimation(WeaponState state, PNode* node = NULL);
     165    Animation3D* getAnimation(int barrel, int seg, PNode* node);
    160166    Animation3D* copyAnimation(WeaponState from, WeaponState to);
    161167
     
    169175    bool check() const;
    170176    void debug() const;
     177
     178    inline int getBarrels() {return this->barrels; };
     179    inline int getSegs() { return this->segs; };
     180    inline void setBarrels(int barrels) { this->barrels = barrels; };
     181    inline void setSegs(int segs) { this->segs = segs; };
     182
     183    inline Animation3D* getShootAnim(int barrel, int seg) { return this->shootAnim[barrel][seg]; };
     184    inline void setShootAnim(int barrel, int seg, PNode* component) { this->shootAnim[barrel][seg] = this->getAnimation(barrel, seg, component); };
     185
     186    void init2();
     187    void deconstr();
    171188
    172189  protected:
     
    184201    static WeaponState   charToState(const std::string& state);
    185202    static const char*   stateToChar(WeaponState state);
     203
     204
    186205
    187206  private:
     
    214233    float                maxCharge;                        //!< The maximal energy to be loaded onto one projectile (this is only availible if chargeable is enabled)
    215234
    216     OrxGui::GLGuiEnergyWidget* energyWidget;
     235    OrxGui::GLGuiEnergyWidgetVertical* energyWidget;
    217236
    218237    PNode*               defaultTarget;                    //!< A target for targeting Weapons.
     
    230249    OrxSound::SoundBuffer  soundBuffers[WA_ACTION_COUNT];   //!< SoundBuffers for all actions @see WeaponAction.
    231250
    232     PNode                  emissionPoint;                   //!< The point, where the projectiles are emitted. (this is coppled with the Weapon by default)
     251    PNode**                emissionPoint;                   //!< The point, where the projectiles are emitted. (this is coppled with the Weapon by default)
    233252
    234253    bool                   hideInactive;                    //!< Hides the Weapon if it is inactive
     
    237256    ClassID                projectile;                      //!< the projectile used for this weapon (since they should be generated via macro and the FastFactory, only the ClassID must be known.)
    238257    FastFactory*           projectileFactory;               //!< A factory, that produces and handles the projectiles.
     258
     259    int                    barrels;                         //!< # of barrels
     260    int                    segs;                             //!< # of segments, one barrel has
     261    Animation3D***         shootAnim;
     262
    239263  };
    240264
  • trunk/src/world_entities/weapons/weapon_manager.cc

    r9869 r10368  
    103103
    104104  this->currentConfigID = 0;
    105   this->slotCount = 2;
     105  this->slotCount = WM_MAX_SLOTS;
    106106  //this->weaponChange;
    107107
     
    114114  this->crossHairSizeAnim->addKeyFrame(100, .05, ANIM_LINEAR);
    115115  this->crossHairSizeAnim->addKeyFrame(50, .01, ANIM_LINEAR);
     116
     117  this->hideCrosshair();
     118
     119  this->bFire = false;
     120}
     121
     122void WeaponManager::showCrosshair()
     123{
     124  this->crosshair->setVisibility( true);
     125}
     126
     127void WeaponManager::hideCrosshair()
     128{
     129  this->crosshair->setVisibility( false);
     130}
     131
     132void WeaponManager::setRotationSpeed(float speed)
     133{
     134  this->crosshair->setRotationSpeed(speed);
    116135}
    117136
     
    300319    if (this->parentEntity->isA(Playable::staticClassID()))
    301320      dynamic_cast<Playable*>(this->parentEntity)->weaponConfigChanged();
     321   
    302322    weapon->setDefaultTarget(this->crosshair);
    303323  }
     
    317337
    318338/**
    319  * @brief does the same as the funtion inclreaseAmmunition, added four your convenience
     339 * @brief does the same as the funtion increaseAmmunition, added four your convenience
    320340 * @param weapon, the Weapon to read the ammo-info about.
    321341 * @param ammo how much ammo to add.
    322342 */
    323 float WeaponManager::inclreaseAmmunition(const Weapon* weapon, float ammo)
     343float WeaponManager::increaseAmmunition(const Weapon* weapon, float ammo)
    324344{
    325345  assert (weapon != NULL);
     
    400420  this->currentConfigID = weaponConfig;
    401421  PRINTF(4)("Changing weapon configuration: to %i\n", this->currentConfigID);
     422
    402423  for (int i = 0; i < WM_MAX_SLOTS; i++)
    403424    this->currentSlotConfig[i].nextWeapon = this->configs[currentConfigID][i];
     
    410431void WeaponManager::fire()
    411432{
     433//   printf("firing WM: ");
    412434  Weapon* firingWeapon;
    413435  for(int i = 0; i < this->slotCount; i++)
    414436  {
     437//     printf("%i ", i);
     438          firingWeapon = this->currentSlotConfig[i].currentWeapon;
     439      if( firingWeapon != NULL && firingWeapon->getCurrentState() == WS_SHOOTING) continue;
     440          if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT);
     441  }
     442//   printf("\n");
     443  /*
     444        this->crosshair->setRotationSpeed(500);
     445        this->crossHairSizeAnim->replay();
     446  */
     447}
     448
     449/**
     450 * triggers fire of all weapons in the current weaponconfig
     451 */
     452void WeaponManager::releaseFire()
     453{
     454  Weapon* firingWeapon;
     455  for(int i = 0; i < this->slotCount; i++)
     456  {
    415457    firingWeapon = this->currentSlotConfig[i].currentWeapon;
    416     if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT);
    417   }
     458    if( firingWeapon != NULL) firingWeapon->requestAction(WA_NONE);
     459  }
     460
     461  /*
    418462  this->crosshair->setRotationSpeed(500);
    419463  this->crossHairSizeAnim->replay();
    420 }
    421 
     464  */
     465}
    422466
    423467/**
     
    429473  Weapon* tickWeapon;
    430474
     475
    431476  for(int i = 0; i < this->slotCount; i++)
    432477  {
    433 /*
    434     NICE LITTLE DEBUG FUNCTION
    435        if (this->currentSlotConfig[i].currentWeapon != NULL || this->currentSlotConfig[i].nextWeapon != NULL)
     478
     479    //NICE LITTLE DEBUG FUNCTION
     480    /*   if (this->currentSlotConfig[i].currentWeapon != NULL || this->currentSlotConfig[i].nextWeapon != NULL)
    436481      printf("%p %p\n", this->currentSlotConfig[i].currentWeapon, this->currentSlotConfig[i].nextWeapon);*/
    437482
     
    455500        }
    456501      }
    457 
    458502      // switching to next Weapon
    459503      tickWeapon = this->currentSlotConfig[i].currentWeapon = this->currentSlotConfig[i].nextWeapon;
     504     
    460505      if (tickWeapon != NULL)
    461506      {
    462            //        if (this->parent != NULL)
    463           tickWeapon->toList(this->parentEntity->getOMListNumber());
     507        //if (this->parent != NULL)
     508        tickWeapon->toList(this->parentEntity->getOMListNumber());
    464509        tickWeapon->requestAction(WA_ACTIVATE);
    465510        this->currentSlotConfig[i].position.activateNode();
  • trunk/src/world_entities/weapons/weapon_manager.h

    r9869 r10368  
    6060    void loadWeapons(const TiXmlElement* root);
    6161
     62    void showCrosshair();
     63    void hideCrosshair();
     64    void setRotationSpeed(float speed);
     65
    6266    void setSlotCount(unsigned int slotCount);
    6367    unsigned int getSlotCount() const { return this->slotCount; };
     
    9195
    9296    float increaseAmmunition(const ClassID& projectileType, float ammo);
    93     float inclreaseAmmunition(const Weapon* weapon, float ammo);
     97    float increaseAmmunition(const Weapon* weapon, float ammo);
    9498
    9599    /** @returns a fixed target namely the Crosshair's 3D position */
     
    99103    //! @TODO: implement this function (maybe also in Weapon itself)
    100104    void releaseFire();
     105    //inline void setFire() { this->bFire = true; };
    101106
    102107    void tick(float dt);
     
    127132
    128133    std::vector<CountPointer<AmmoContainer> > ammo;                   //!< Containers
     134
     135    bool                    bFire;
    129136};
    130137
Note: See TracChangeset for help on using the changeset viewer.