Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.