Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 17, 2005, 2:17:09 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/weaponSystem: more functionality, but firing does not work anymore… this will soon be fixed

File:
1 edited

Legend:

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

    r4879 r4880  
    1313   main-programmer: Patrick Boenzli
    1414   co-programmer: Benjamin Grauer
     15
     16   2005-07-15: Benjamin Grauer: restructurating the entire Class
    1517*/
    1618
     
    2325#include "list.h"
    2426#include "state.h"
     27#include "animation3d.h"
     28#include "sound_engine.h"
    2529
    2630/**
     
    4246Weapon::~Weapon ()
    4347{
    44   // model will be deleted from WorldEntity-destructor
    45   //this->worldEntities = NULL;
    46 
    47   /* dont delete objectComponentsX here, they will be killed when the pnodes are cleaned out */
    48 
    49   /* all animations are deleted via the animation player*/
    50 }
    51 
     48  for (int i = 0; i < WS_STATE_COUNT; i++)
     49    if (this->animation[i])
     50      delete this->animation[i];
     51  for (int i = 0; i < WA_ACTION_COUNT; i++)
     52    if (this->soundBuffers[i])
     53      delete this->soundBuffers[i];
     54}
     55
     56/**
     57 * initializes the Weapon with ALL default values
     58 */
    5259void Weapon::init()
    5360{
    5461  this->currentState     = WS_INACTIVE;
    55   this->stateTime        = 0.0;
     62  this->stateDuration    = 0.0;
    5663  for (int i = 0; i < WS_STATE_COUNT; i++)
    57   {
    58     this->times[i] = 0.0;
    59     this->animation[i] = NULL;
    60   }
     64    {
     65      this->times[i] = 0.0;
     66      this->animation[i] = NULL;
     67    }
    6168  for (int i = 0; i < WA_ACTION_COUNT; i++)
    6269    this->soundBuffers[i] = NULL;
    6370
     71  this->requestedAction = WA_NONE;
    6472  this->weaponSource = NULL;
    65   this->minCharge;
    66   this->maxCharge;
     73  this->minCharge = 0.0;
     74  this->maxCharge = 0.0;
    6775
    6876  this->active = false;
     
    94102
    95103
     104void Weapon::requestAction(WeaponAction action)
     105{
     106  this->requestedAction = action;
     107}
     108
     109bool Weapon::execute(WeaponAction action)
     110{
     111  this->stateDuration = this->times[action] + this->stateDuration;
     112
     113  switch (action)
     114  {
     115    case WA_SHOOT:
     116      this->fire();
     117      break;
     118    case WA_CHARGE:
     119      this->charge();
     120      break;
     121    case WA_RELOAD:
     122      this->reload();
     123      break;
     124    case WA_DEACTIVATE:
     125      this->deactivate();
     126      break;
     127    case WA_ACTIVATE:
     128      this->activate();
     129      break;
     130  }
     131}
     132
    96133/**
    97134 * this activates the weapon
    98  *
    99  * This is needed, since there can be more than one weapon on a ship. the
    100  * activation can be connected with an animation. for example the weapon is
    101  * been armed out.
    102135*/
    103136void Weapon::activate()
     
    107140/**
    108141 * this deactivates the weapon
    109  *
    110  * This is needed, since there can be more than one weapon on a ship. the
    111  * activation can be connected with an animation. for example the weapon is
    112  * been armed out.
    113142*/
    114143void Weapon::deactivate()
    115144{}
    116145
    117 /**
    118  * is called, when the weapon gets hit (=collide with something)
    119  * @param from which entity it is been hit
    120  * @param where it is been hit
    121  *
    122  * this may not be used, since it would make the game relay complicated when one
    123  * can destroy the weapons of enemies or vice versa.
    124 */
    125 void Weapon::hit (WorldEntity* entity, const Vector& position)
    126 {}
     146void Weapon::fire()
     147{
     148
     149}
     150
     151void Weapon::reload()
     152{
     153
     154}
     155
     156void Weapon::charge()
     157{
     158}
    127159
    128160
     
    138170
    139171/**
    140  *  tick signal for time dependent/driven stuff
    141 */
    142 void Weapon::tick (float time)
    143 {}
     172 * tick signal for time dependent/driven stuff
     173*/
     174void Weapon::tick(float dt)
     175{
     176  if (this->isActive())
     177  {
     178    this->stateDuration -= dt;
     179
     180    if (this->stateDuration < 0.0)
     181      this->execute(this->requestedAction);
     182  }
     183  else
     184    if (this->requestedAction == WA_ACTIVATE)
     185      this->activate();
     186
     187}
    144188
    145189/**
     
    153197
    154198
     199//////////////////////
     200// HELPER FUNCTIONS //
     201//////////////////////
     202// inclass
     203/**
     204 * checks if the next Action given is valid
     205 * @returns if the Action that comes next is valid
     206 * @todo more checks
     207 */
     208bool Weapon::nextActionValid() const
     209{
     210  if (this->currentState == WS_INACTIVE)
     211  {
     212    return (this->requestedAction == WA_ACTIVATE || this->requestedAction == WA_NONE);
     213  }
     214  else
     215    return true;
     216
     217}
     218
     219
     220
     221// static
    155222/**
    156223 * Converts a String into an Action.
     
    175242    return WA_SPECIAL1;
    176243  else
    177   {
    178     PRINTF(2)("action %s could not be identified.\n", action);
    179     return WA_NONE;
    180   }
     244    {
     245      PRINTF(2)("action %s could not be identified.\n", action);
     246      return WA_NONE;
     247    }
    181248}
    182249
     
    192259  else if (!strcmp(state, "shooting"))
    193260    return WS_SHOOTING;
     261  else if (!strcmp(state, "charging"))
     262    return WS_CHARGING;
    194263  else if (!strcmp(state, "reloading"))
    195264    return WS_RELOADING;
     
    203272    return WS_IDLE;
    204273  else
    205   {
    206     PRINTF(2)("state %s could not be identified.\n", state);
    207     return WS_NONE;
    208   }
    209 }
    210 
     274    {
     275      PRINTF(2)("state %s could not be identified.\n", state);
     276      return WS_NONE;
     277    }
     278}
Note: See TracChangeset for help on using the changeset viewer.