Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3953 in orxonox.OLD for orxonox/branches/physics/src/world_entities


Ignore:
Timestamp:
Apr 25, 2005, 9:29:41 AM (20 years ago)
Author:
patrick
Message:

orxonox/branches/physics: merged with trunk - with command svn merge -r 3866:HEAD

Location:
orxonox/branches/physics/src/world_entities
Files:
7 edited
2 copied

Legend:

Unmodified
Added
Removed
  • orxonox/branches/physics/src/world_entities/player.cc

    r3811 r3953  
    3838Player::Player() : WorldEntity()
    3939{
    40   this->weapons = new tList<Weapon>();
    41   this->activeWeapon = NULL;
    4240  /*
    4341    this is the debug player - actualy we would have to make a new
     
    4644  */
    4745  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
    48   //this->model = (Model*)ResourceManager::getInstance()->load("models/weapon_packet.obj", OBJ, RP_CAMPAIGN);
    4946  travelSpeed = 15.0;
    5047  velocity = new Vector();
    5148  bUp = bDown = bLeft = bRight = bAscend = bDescend = false;
    5249  bFire = false;
     50  this->bWeaponChange = false;
    5351  acceleration = 10.0;
    5452  //weapons:
    55   Weapon* wpRight = new TestGun(this, new Vector(-2.6, 0.1, 3.0), new Quaternion(), 0);
    56   Weapon* wpLeft = new TestGun(this, new Vector(-2.6, 0.1, -3.0), new Quaternion(), 1);
    57   this->weapons->add(wpRight);
    58   this->activeWeapon = wpRight;
    59   this->activeWeaponL = wpLeft;
     53  this->weaponMan = new WeaponManager();
     54  Weapon* wpRight = new TestGun(this,Vector(-2.6, 0.1, 3.0), Quaternion(), 0);
     55  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
     56 
     57  this->weaponMan->addWeapon(wpRight, W_CONFIG0);
     58  this->weaponMan->addWeapon(wpLeft, W_CONFIG1);
     59  this->weaponMan->addWeapon(wpRight, W_CONFIG2);
     60  this->weaponMan->addWeapon(wpLeft, W_CONFIG2);
     61
    6062}
    6163
     
    6971     this only frees the memory allocated to save the list.
    7072  */
    71   delete this->weapons;
     73  delete this->weaponMan;
    7274}
    7375
     
    7981void Player::addWeapon(Weapon* weapon)
    8082{
    81   this->weapons->add(weapon);
     83  this->weaponMan->addWeapon(weapon);
    8284}
    8385
     
    8991void Player::removeWeapon(Weapon* weapon)
    9092{
    91   this->weapons->remove(weapon);
     93  this->weaponMan->removeWeapon(weapon);
    9294}
    9395
     
    151153  glPopMatrix();
    152154
    153   this->activeWeapon->draw();
    154   this->activeWeaponL->draw();
     155  this->weaponMan->draw();
    155156}
    156157
     
    163164{
    164165  /* link tick to weapon */
    165   this->activeWeapon->tick(time);
    166   this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE
     166  //this->activeWeapon->tick(time);
     167  //this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE
     168  this->weaponMan->tick(time);
    167169  // player controlled movement
    168170  this->move(time);
     
    180182  Vector accel(0.0, 0.0, 0.0);
    181183  /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */
    182  
    183184  /* calculate the direction in which the craft is heading  */
    184185  Vector direction (1.0, 0.0, 0.0);
     
    210211  if( this->bFire)
    211212    {
    212       //if(this->activeWeapon != NULL)
    213       this->activeWeapon->fire();
    214       //FIX THIS FIX FIIIIIIIIIIIX
    215       this->activeWeaponL->fire();
     213      this->weaponMan->fire();
    216214    }
    217   if( this->bWeaponChange && this->weapons->getSize() > 1)
     215  if( this->bWeaponChange)
    218216    {
    219       PRINTF(1)("changing the weapon of the player: deactivate old, activate new\n");
    220       this->activeWeapon->deactivate();
    221       //this->weapons->enumerate();  FIX: strang weapon change...
    222       this->activeWeapon = this->weapons->nextElement(this->activeWeapon);
    223       this->activeWeapon->activate();
     217      this->weaponMan->nextWeaponConf();
     218      this->bWeaponChange = false;
    224219    }
    225220}
     
    240235  if( !strcmp( cmd->cmd, "right")) this->bRight = !cmd->bUp;
    241236  if( !strcmp( cmd->cmd, "fire")) this->bFire = !cmd->bUp;
    242   if( !strcmp( cmd->cmd, "mode")) this->bWeaponChange = !cmd->bUp;
    243 }
     237  if( !strcmp( cmd->cmd, "mode")) if(cmd->bUp) this->bWeaponChange = !this->bWeaponChange;
     238}
  • orxonox/branches/physics/src/world_entities/player.h

    r3755 r3953  
    1111template<class T> class tList;
    1212class Weapon;
     13class WeaponManager;
    1314class Vector;
    1415class World;
     
    4950  Weapon* activeWeapon;  //!< the weapon that is currenty activated
    5051  Weapon* activeWeaponL;  //temporary -- FIX THIS
     52  WeaponManager* weaponMan; //!< the weapon manager: managing a list of weapon to wepaon-slot mapping
    5153
    5254  World* myWorld;        //!< reference to the world object
  • orxonox/branches/physics/src/world_entities/skybox.cc

    r3807 r3953  
    187187  model->addVertexNormal (-1.0, 0.0, 0.0);
    188188
    189   model->addUseMtl(material[0]);
    190   model->addFace (4, 3, 3,2,4, 4,3,4, 6,4,4, 5,1,4); // top
    191   model->addUseMtl(material[1]);
    192   model->addFace (4, 3, 7,4,2, 8,1,2, 2,2,2, 1,3,2); // bottom
    193   model->addUseMtl(material[2]);
    194   model->addFace (4, 3, 1,1,3, 2,2,3, 4,3,3, 3,4,3); // left
    195   model->addUseMtl(material[3]);
    196   model->addFace (4, 3, 5,3,1, 6,4,1, 8,1,1, 7,2,1); // right
    197   model->addUseMtl(material[4]);
    198   model->addFace (4, 3, 2,1,6, 8,2,6, 6,3,6, 4,4,6); // front
    199   model->addUseMtl(material[5]);
    200   model->addFace (4, 3, 7,1,5, 1,2,5, 3,3,5, 5,4,5); // back
     189  model->setMaterial(material[0]);
     190  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 3,2,4, 4,3,4, 6,4,4, 5,1,4); // top
     191  model->setMaterial(material[1]);
     192  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,4,2, 8,1,2, 2,2,2, 1,3,2); // bottom
     193  model->setMaterial(material[2]);
     194  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,3, 2,2,3, 4,3,3, 3,4,3); // left
     195  model->setMaterial(material[3]);
     196  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 5,3,1, 6,4,1, 8,1,1, 7,2,1); // right
     197  model->setMaterial(material[4]);
     198  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,1,6, 8,2,6, 6,3,6, 4,4,6); // front
     199  model->setMaterial(material[5]);
     200  model->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,1,5, 1,2,5, 3,3,5, 5,4,5); // back
    201201 
    202202  model->finalize();
  • orxonox/branches/physics/src/world_entities/test_gun.cc

    r3855 r3953  
    4040   creates a new weapon
    4141*/
    42 TestGun::TestGun (PNode* parent, Vector* coordinate, Quaternion* direction, int leftRight)
     42TestGun::TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight)
    4343  :  Weapon (parent, coordinate, direction)
    4444{
     
    4747  this->leftRight = leftRight;
    4848
    49   if( this->leftRight == 0)
    50     this->projOffset = new Vector(1.0, 0.0, -0.35);
    51   else if( this->leftRight == 1)
    52     this->projOffset = new Vector(1.0, 0.0, 0.5);
     49  this->objectComponent1 = new PNode();
     50  this->animation1 = new Animation3D(this->objectComponent1);
     51  parent->addChild(this->objectComponent1, PNODE_ALL);
    5352
     53  this->animation1->setInfinity(ANIM_INF_CONSTANT);
     54  // ANIM_LINEAR was ANIM_NEG_EXP
     55  if( this->leftRight == W_LEFT)
     56    {
     57      this->projectileOffset = Vector(1.0, 0.0, -0.35);
    5458
    55   this->dummy1 = new WorldEntity(); // a world entity that is not drawed: use this for the weapon
    56   this->animation = new Animation3D(dummy1);
     59      this->animation1->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR);
     60      this->animation1->addKeyFrame(Vector(-3.0, 0.1, 3.0), Quaternion(), 0.5, ANIM_LINEAR);
     61      this->animation1->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR);
     62    }
     63  else if( this->leftRight == W_RIGHT)
     64    {
     65      this->projectileOffset = Vector(1.0, 0.0, 0.5);
    5766
    58   parent->addChild(this->dummy1, PNODE_ALL);
    59 
    60   this->animation->setInfinity(ANIM_INF_CONSTANT);
    61   // ANIM_LINEAR was ANIM_NEG_EXP
    62   if( this->leftRight == 0)
    63     {
    64       this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR);
    65       this->animation->addKeyFrame(Vector(-3.0, 0.1, 3.0), Quaternion(), 0.5, ANIM_LINEAR);
    66       this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR);
     67      this->animation1->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.1, ANIM_LINEAR);
     68      this->animation1->addKeyFrame(Vector(-3.0, 0.1, -2.5), Quaternion(), 0.5, ANIM_LINEAR);
     69      this->animation1->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.1, ANIM_LINEAR);
    6770    }
    68   else if( this->leftRight == 1)
    69     {
    70       this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.1, ANIM_LINEAR);
    71       this->animation->addKeyFrame(Vector(-3.0, 0.1, -2.5), Quaternion(), 0.5, ANIM_LINEAR);
    72       this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.1, ANIM_LINEAR);
    73     }
    74   /*
    75   if( this->leftRight == 0)
    76     {
    77       this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.0, ANIM_NEG_EXP);
    78       this->animation->addKeyFrame(Vector(-3.0, 0.1, 3.0), Quaternion(), 0.1, ANIM_NEG_EXP);
    79       this->animation->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.5, ANIM_NEG_EXP);
    80     }
    81   else if( this->leftRight == 1)
    82     {
    83       this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.0, ANIM_NEG_EXP);
    84       this->animation->addKeyFrame(Vector(-3.0, 0.1, -2.5), Quaternion(), 0.1, ANIM_NEG_EXP);
    85       this->animation->addKeyFrame(Vector(-2.6, 0.1, -2.5), Quaternion(), 0.5, ANIM_NEG_EXP);
    86     }
    87   */
    8871}
    8972
     
    127110void TestGun::fire()
    128111{
    129   if( this->localTime < this->idleTime)
     112  if( !this->hasWeaponIdleTimeElapsed())
    130113    {
    131114      this->weaponIdle();
    132115      return;
    133116    }
     117
    134118  Projectile* pj = new TestBullet(this);
    135 
    136   pj->setAbsCoor(this->getAbsCoor() + *this->projOffset);
     119  pj->setAbsCoor(this->getAbsCoor() + this->projectileOffset);
    137120  pj->setAbsDir(this->getAbsDir());
    138 
    139121  pj->setFlightDirection(this->getAbsDir());
    140122  pj->setSpeed(this->getSpeed());
    141 
    142123  this->worldEntities->add(pj);
    143124  this->localTime = 0;
    144125 
    145   this->animation->replay();
     126  this->animation1->replay();
    146127}
    147128
     
    190171void TestGun::draw ()
    191172{
    192  
    193   /* draw gun body 1 */
     173  /* draw gun body */
    194174  glMatrixMode(GL_MODELVIEW);
    195175  glPushMatrix();
    196176  float matrix[4][4];
    197  
    198   if( this->leftRight == 0)
    199     {
    200       glTranslatef (this->getAbsCoor ().x,
    201                     this->getAbsCoor ().y,
    202                     this->getAbsCoor ().z);
    203      
    204       this->getAbsDir ().matrix (matrix);
    205       glMultMatrixf((float*)matrix);
    206       this->model->draw(1);
    207     }
    208   else if( this->leftRight == 1)
    209     {
    210       glTranslatef (this->getAbsCoor ().x,
    211                     this->getAbsCoor ().y,
    212                     this->getAbsCoor ().z);
    213      
    214       this->getAbsDir ().matrix (matrix);
    215       glMultMatrixf((float*)matrix);
    216       glScalef(1.0, 1.0, -1.0);
    217       this->model->draw(1);
    218     }
    219 
     177  glTranslatef (this->getAbsCoor ().x,
     178                this->getAbsCoor ().y,
     179                this->getAbsCoor ().z); 
     180  this->getAbsDir ().matrix (matrix);
     181  glMultMatrixf((float*)matrix);
     182  if( this->leftRight == W_RIGHT)
     183    glScalef(1.0, 1.0, -1.0);
     184  this->model->draw(1);
    220185  glPopMatrix();
    221186
    222 
    223   /* draw gun coil 1 */
     187  /* draw objectComponent1: gun coil - animated stuff */
    224188  glMatrixMode(GL_MODELVIEW);
    225189  glPushMatrix();
    226  
    227   glTranslatef (this->dummy1->getAbsCoor ().x,
    228                 this->dummy1->getAbsCoor ().y,
    229                 this->dummy1->getAbsCoor ().z);
    230 
    231   this->dummy1->getAbsDir ().matrix (matrix);
     190  glTranslatef (this->objectComponent1->getAbsCoor ().x,
     191                this->objectComponent1->getAbsCoor ().y,
     192                this->objectComponent1->getAbsCoor ().z);
     193  this->objectComponent1->getAbsDir ().matrix (matrix);
    232194  glMultMatrixf((float*)matrix);
    233195  this->model->draw(0);
  • orxonox/branches/physics/src/world_entities/test_gun.h

    r3855 r3953  
    3737
    3838 public:
    39   TestGun (PNode* parent, Vector* coordinate, Quaternion* direction, int leftRight);
     39  TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight);
    4040  virtual ~TestGun ();
    4141
     
    5151  virtual void draw(void);
    5252
    53  private:
    54   Animation3D* animation;
    55   Vector* projOffset;
    56   WorldEntity* dummy1;
    57   int leftRight;   // this will become an enum
     53
     54
    5855
    5956};
  • orxonox/branches/physics/src/world_entities/weapon.cc

    r3862 r3953  
    1616*/
    1717
     18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
    1819
    1920#include "weapon.h"
     
    3031
    3132
     33/**
     34   \brief this initializes the weaponManager for a given nnumber of weapon slots
     35   \param number of weapon slots of the model/ship <= 8 (limitied)
     36*/
    3237WeaponManager::WeaponManager(int nrOfSlots)
    3338{
     39  for(int i = 0; i < W_MAX_CONFIGS; ++i)
     40    {
     41      this->configs[i].bUsed = false;
     42      for(int j = 0; j < W_MAX_SLOTS; ++j)
     43        this->configs[i].slots[j] = NULL;
     44    }
    3445  this->nrOfSlots = nrOfSlots;
    35   this->nrOfConfigs = 1;
    36 
    37   for(int i = 0; i < W_MAX_CONFS; ++i)
    38     this->configs[i] = NULL;
    39   this->currentConfig = new weaponConfig;
    40   this->configs[0] = this->currentConfig;
    41 }
     46  this->currConfID = W_CONFIG0;
     47}
     48
    4249
    4350WeaponManager::~WeaponManager()
    4451{
    45 
    46 }
    47 
    48 void WeaponManager::addWeapon(Weapon* weapon, slotID slot, configID config)
    49 {
    50   if(this->configs[config] == NULL)
    51     PRINTF(0)("");
    52   //  this->configs[(int)config]->
    53 }
    54 
    55 void WeaponManager::addWeaponConfig(weaponConfig* config)
    56 {}
    57 
     52  /*
     53     i dont have to delete the weapons itself, because they are
     54     worldentities and therefore in the entities list of the world.
     55     world will clean them up for me
     56  */
     57  for(int i = 0; i < W_MAX_CONFIGS; ++i)
     58    {
     59      this->configs[i].bUsed = false;
     60      for(int j = 0; j < W_MAX_SLOTS; ++j)
     61        this->configs[i].slots[j] = NULL;
     62    }
     63}
     64
     65
     66/**
     67   \brief adds a weapon to the selected weaponconfiguration into the selected slot
     68   \param the weapon to add
     69   \param an identifier for the slot: number between 0..7 if not specified: slotID=next free slot
     70   \param an identifier for the weapon configuration, number between 0..3
     71
     72   if you add explicitly a weapon at config:n, slot:m, the weapon placed at this location will be
     73   replaced by the weapon specified. if you use the W_FREE_SLOT, the manager will look for a free
     74   slot in this weaponconfiguration. if there is non, the weapon won't be added and there will be
     75   a error message.
     76*/
     77void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID)
     78{
     79  if( slotID == W_FREE_SLOT)
     80    {
     81      int freeSlot = this->getNextFreeSlot( configID);
     82      if( freeSlot < 0 || freeSlot >= this->nrOfSlots)
     83        {
     84          PRINTF(0)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n");
     85          return;
     86        }
     87      PRINTF(3)("Added new Weapon to Config:%i/Slot:%i\n", configID, freeSlot);
     88      this->configs[configID].bUsed = true;
     89      this->configs[configID].slots[freeSlot] = weapon;
     90      return;
     91    }
     92  this->configs[configID].bUsed = true;
     93  this->configs[configID].slots[slotID] = weapon;
     94  PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);
     95}
     96
     97
     98void WeaponManager::removeWeapon(Weapon* weapon, int configID)
     99{
     100  /* empty */
     101}
     102
     103
     104/**
     105   \brief changes to the next weapon configuration
     106
     107   if there are multiple weapon configurations defined by the manager, use this to switch between them
     108   this function will deactivate the weapons first, change the config and reactivate them later
     109*/
    58110void WeaponManager::nextWeaponConf()
    59 {}
    60 
    61 void WeaponManager::prevWeaponConf()
    62 {}
    63 
    64 
    65 void WeaponManager::selectConfig(configID config)
    66 {
    67   if( this->configs[(int)config] != NULL)
    68     this->currentConfig = this->configs[(int)config];
    69   else
    70     PRINTF(0)("There is no weapon config defined with the number W_CONF%i", (int)config);
    71 }
     111{
     112  PRINTF(4)("Changing weapon configuration: from %i\n", this->currConfID);
     113
     114  Weapon* w;
     115  for(int i = 0; i < W_MAX_SLOTS; ++i)
     116    {
     117      w = this->configs[this->currConfID].slots[i];
     118      if( w != NULL) w->deactivate();
     119    }
     120  int i;
     121  for(i = this->currConfID + 1; i < W_MAX_CONFIGS && !this->configs[i].bUsed; ++i);
     122  if( i == W_MAX_CONFIGS) this->currConfID = W_CONFIG0;
     123  else this->currConfID = i; 
     124  PRINTF(4)("\tto %i\n", this->currConfID);
     125
     126  for(int i = 0; i < W_MAX_SLOTS; ++i)
     127    {
     128      w = this->configs[this->currConfID].slots[i];
     129      if( w != NULL) w->activate();
     130    }
     131}
     132
     133
     134
     135/**
     136   \brief triggers fire of all weapons in the current weaponconfig
     137*/
     138void WeaponManager::fire()
     139{
     140  Weapon* firingWeapon;
     141  for(int i = 0; i < W_MAX_SLOTS; ++i)
     142    {
     143      firingWeapon = this->configs[this->currConfID].slots[i];
     144      if( firingWeapon != NULL) firingWeapon->fire();
     145    }
     146}
     147
     148
     149/**
     150   \brief triggers tick of all weapons in the current weaponconfig
     151   \param second passed since last tick
     152*/
     153void WeaponManager::tick(float sec)
     154{
     155  Weapon* w;
     156  for(int i = 0; i < W_MAX_SLOTS; ++i)
     157    {
     158      w = this->configs[this->currConfID].slots[i];
     159      if( w != NULL) w->tick(sec);
     160    }
     161}
     162
     163
     164/**
     165   \brief triggers draw of all weapons in the current weaponconfig
     166*/
     167void WeaponManager::draw()
     168{
     169  Weapon* w;
     170  for(int i = 0; i < W_MAX_SLOTS; ++i)
     171    {
     172      w = this->configs[this->currConfID].slots[i];
     173      if( w != NULL) w->draw();
     174    }
     175}
     176
     177
     178/**
     179   \brief private gets the next free slot in a certain weaponconfig
     180   \param the selected weaponconfig
     181*/
     182int WeaponManager::getNextFreeSlot(int configID)
     183{
     184  for( int i = 0; i < W_MAX_SLOTS; ++i)
     185    {
     186      if( this->configs[configID].slots[i] == NULL)
     187        return i;
     188    }
     189  return -1;
     190}
     191
     192
     193
    72194
    73195
     
    78200   creates a new weapon
    79201*/
    80 Weapon::Weapon (PNode* parent, Vector* coordinate, Quaternion* direction)
     202Weapon::Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction)
    81203  : WorldEntity()
    82204{
    83205  parent->addChild(this, PNODE_ALL);
    84   this->setRelCoor(*coordinate);
    85   this->setRelDir(*direction);
     206  this->setRelCoor(coordinate);
     207  this->setRelDir(direction);
    86208  WorldInterface* wi = WorldInterface::getInstance();
    87209  this->worldEntities = wi->getEntityList();
     210
     211  this->objectComponent1 = NULL;
     212  this->objectComponent2 = NULL;
     213  this->objectComponent3 = NULL;
     214
     215  this->animation1 = NULL;
     216  this->animation2 = NULL;
     217  this->animation3 = NULL;
    88218}
    89219
     
    95225{
    96226  // model will be deleted from WorldEntity-destructor
     227  //this->worldEntities = NULL;
     228 
     229  /* dont delete objectComponentsX here, they will be killed when the pnodes are cleaned out */
     230
     231  /* all animations are deleted via the animation player*/
    97232}
    98233
     
    190325{}
    191326
    192 /**
    193    \brief sets a weapon idle time
    194    \param idle time in ms
    195 
    196    a weapon idle time is the time spend after a shoot until the weapon can
    197    shoot again
    198 */
    199 void Weapon::setWeaponIdleTime(float time)
    200 {
    201   this->idleTime = time;
    202 }
    203 
    204 /**
    205    \brief gets the weapon idle time
    206    \returns idle time in ms
    207 
    208    a weapon idle time is the time spend after a shoot until the weapon can
    209    shoot again
    210 */
    211 float Weapon::getWeaponIdleTime(void)
    212 {
    213   return this->idleTime;
    214 }
    215 
    216 /**
    217    \brief checks if the idle time is elapsed
    218    \return true if time is elapsed
    219 
    220    a weapon idle time is the time spend after a shoot until the weapon can
    221    shoot again
    222 */
    223 bool Weapon::hasWeaponIdleTimeElapsed(void)
    224 {
    225   return (this->localTime>this->idleTime)?true:false;
    226 }
    227 
    228 
    229 /**
    230    \brief fires the weapon
    231    
    232    this is called from the player.cc, when fire-button is been pushed
    233 */
    234 void Weapon::fire()
    235 {}
     327
     328
     329
    236330
    237331
  • orxonox/branches/physics/src/world_entities/weapon.h

    r3862 r3953  
    3434
    3535#define W_MAX_SLOTS 8
    36 #define W_MAX_CONFS 4
     36#define W_MAX_CONFIGS 4
    3737
    3838class Projectile;
    3939class Weapon;
     40class Animation3D;
    4041
    4142typedef enum {
     
    4849} weaponSoundType;
    4950
     51
    5052//! this is an identifier for the slot. there are up to 8 weapon slots -> this means there can't be more than 8 weapons at the same time
    51 typedef enum slotID {W_SLOT0=0, W_SLOT1, W_SLOT2, W_SLOT3,
    52                      W_SLOT4, W_SLOT5, W_SLOT6, W_SLOT7};
     53#define W_SLOT0 0
     54#define W_SLOT1 1
     55#define W_SLOT2 2
     56#define W_SLOT3 3
     57#define W_SLOT4 4
     58#define W_SLOT5 5
     59#define W_SLOT6 6
     60#define W_SLOT7 7
     61#define W_FREE_SLOT 99
     62
    5363
    5464//! this is an identifier for the weapon config
    55 typedef enum configID {W_CONFIG0=0, W_CONFIG1,
    56                        W_CONFIG2, W_CONFIG3};
     65#define W_CONFIG0 0
     66#define W_CONFIG1 1
     67#define W_CONFIG2 2
     68#define W_CONFIG3 3
     69
     70//! a weapon can be left or right sided
     71#define W_LEFT 0
     72#define W_RIGHT 1
    5773
    5874//! this is a weapon Configuration: it has up to 8 slots
    5975typedef struct weaponConfig {
    60   Weapon* slot1;                    //<! standard right side weapon
    61   Weapon* slot2;                    //<! standard left side weapon
    62   Weapon* slot3;                    //<! custom
    63   Weapon* slot4;                    //<! custom
    64   Weapon* slot5;                    //<! custom
    65   Weapon* slot6;                    //<! custom
    66   Weapon* slot7;                    //<! custom
    67   Weapon* slot8;                    //<! custom
     76  bool bUsed;                       //<! is set to true, if this configuration is
     77  Weapon* slots[8];
    6878};
    6979
     
    7484  ~WeaponManager();
    7585 
    76   void addWeapon(Weapon* weapon, slotID slot, configID config = W_CONFIG0);
    77   void addWeaponConfig(weaponConfig* config);
     86  void addWeapon(Weapon* weapon, int configID = W_CONFIG0, int slotID = W_FREE_SLOT);
     87  void removeWeapon(Weapon* weapon, int configID = W_CONFIG0);
     88  void nextWeaponConf();
    7889
    79   void nextWeaponConf();
    80   void prevWeaponConf();
    81   void selectConfig(configID config);
     90  void fire();
     91  void tick(float sec);
     92  void draw();
    8293
    8394 private:
    84   int nrOfConfigs;                      //<! number of configurations defined
    8595  int nrOfSlots;                        //<! number of weapon slots a ship has
    86   weaponConfig* currentConfig;          //<! the currently selected config
    87   weaponConfig* configs[4];             //<! a list of four configurations
     96  int currConfID;                       //<! the currently selected config
     97  weaponConfig configs[4];              //<! a list of four configurations
     98 
     99  int getNextFreeSlot(int configID);
    88100};
    89101
     
    93105
    94106 public:
    95   Weapon (PNode* parent, Vector* coordinate, Quaternion* direction);
     107  Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction);
    96108  virtual ~Weapon ();
    97109 
     
    107119  bool isActive(void);
    108120
    109   void setWeaponIdleTime(float time);
    110   float getWeaponIdleTime(void);
    111   bool hasWeaponIdleTimeElapsed(void);
    112121
     122  /**
     123     \brief sets a weapon idle time
     124     \param idle time in ms
     125     
     126     a weapon idle time is the time spend after a shoot until the weapon can
     127     shoot again
     128  */
     129  inline void setWeaponIdleTime(float time) { this->idleTime = time; }
     130  /**
     131     \brief gets the weapon idle time
     132     \returns idle time in ms
     133     
     134     a weapon idle time is the time spend after a shoot until the weapon can
     135     shoot again
     136  */
     137  inline float getWeaponIdleTime(void) const { return this->idleTime;}
     138  /**
     139     \brief checks if the idle time is elapsed
     140     \return true if time is elapsed
     141     
     142     a weapon idle time is the time spend after a shoot until the weapon can
     143   shoot again
     144  */
     145  inline bool hasWeaponIdleTimeElapsed(void) const { return (this->localTime>this->idleTime)?true:false; }
     146
     147  /**
     148     \brief fires the weapon
     149     
     150     this is called from the player.cc, when fire-button is been pushed
     151  */
    113152  virtual void fire(void) = 0;
    114153  virtual void hit (WorldEntity* weapon, Vector* loc);
     
    121160 protected:
    122161  tList<WorldEntity>* worldEntities;
    123   float localTime;
    124   float idleTime;
    125   float slowDownFactor;
     162  float localTime;                 //<! this is the local time. important for shooting attributes like frequency
     163  float idleTime;                  //<! the time a weapon needs before it can shoot again. eg. shooting frequency or actication/deactivateion delay
     164  float slowDownFactor;            //<! if the shooting frequency is a linear function of time...
     165
     166  PNode* objectComponent1;         //<! the gun is made of multiple parts, these PNodes represent their location and orientation
     167  PNode* objectComponent2;
     168  PNode* objectComponent3;
     169
     170  Animation3D* animation1;
     171  Animation3D* animation2;
     172  Animation3D* animation3;
     173
     174  Vector projectileOffset;
     175  int leftRight;   // this will become an enum
    126176
    127177 private:
    128   bool enabled;
    129   Projectile* projectile;
     178  bool enabled;                    //<! states if the weapon is enabled or not
     179  Projectile* projectile;          //<! the projectile used for this weapon
    130180  //WeaponSound sound;
    131181};
Note: See TracChangeset for help on using the changeset viewer.