Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3870 in orxonox.OLD


Ignore:
Timestamp:
Apr 18, 2005, 3:37:42 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: reimplemented WeaponManager, made it as simple as possible. not yet all done

Location:
orxonox/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/story_entities/world.cc

    r3864 r3870  
    367367            trackManager->condition(2, LEFTRIGHT, this->localPlayer);
    368368            this->glmis->step();
    369 
    370369            break;
    371370          }
  • orxonox/trunk/src/world_entities/weapon.cc

    r3862 r3870  
    3030
    3131
     32/**
     33   \brief this initializes the weaponManager for a given nnumber of weapon slots
     34   \param number of weapon slots of the model/ship <= 8 (limitied)
     35*/
    3236WeaponManager::WeaponManager(int nrOfSlots)
    3337{
    3438  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 }
     39 
     40  this->currConfID = W_CONFIG1;
     41  this->configs[this->currConfID].bUsed = true;
     42}
     43
    4244
    4345WeaponManager::~WeaponManager()
    4446{
    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 {}
     47  /* i dont have to delete the weapons itself, because they are
     48     worldentities and therefore in the entities list of the world
     49  */
     50}
     51
     52
     53void WeaponManager::addWeapon(Weapon* weapon, int slotID, int configID)
     54{
     55  if( slotID == W_FREE_SLOT)
     56    {
     57      int freeSlot = this->getNextFreeSlot();
     58      if( freeSlot < 0 || freeSlot >= this->nrOfSlots)
     59        {
     60          PRINTF(0)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n");
     61          return;
     62        }
     63      this->configs[configID].slots[freeSlot] = weapon;
     64      return;
     65    }
     66  this->configs[configID].slots[slotID] = weapon;
     67  PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);
     68}
     69
    5770
    5871void WeaponManager::nextWeaponConf()
    59 {}
     72{
     73  for(; this->currConfID < W_MAX_CONFIGS && !this->configs[this->currConfID].bUsed; this->currConfID+=1)
     74    printf("");
     75}
     76
    6077
    6178void WeaponManager::prevWeaponConf()
     
    6380
    6481
    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 }
    72 
     82void WeaponManager::selectConfig(int confID)
     83{
     84  PRINTF(0)("There is no weapon config defined with the number W_CONF%i", confID);
     85}
     86
     87
     88
     89int WeaponManager::getNextFreeSlot()
     90{
     91  for( int i = 0; i < W_MAX_SLOTS; ++i)
     92    {
     93      if( this->configs[this->currConfID].slots[i] == NULL)
     94        return i;
     95    }
     96  return -1;
     97}
    7398
    7499
  • orxonox/trunk/src/world_entities/weapon.h

    r3862 r3870  
    3434
    3535#define W_MAX_SLOTS 8
    36 #define W_MAX_CONFS 4
     36#define W_MAX_CONFIGS 4
    3737
    3838class Projectile;
     
    4848} weaponSoundType;
    4949
     50
    5051//! 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};
     52#define W_SLOT0 0
     53#define W_SLOT1 1
     54#define W_SLOT2 2
     55#define W_SLOT3 3
     56#define W_SLOT4 4
     57#define W_SLOT5 5
     58#define W_SLOT6 6
     59#define W_SLOT7 7
     60#define W_FREE_SLOT 99
     61
    5362
    5463//! this is an identifier for the weapon config
    55 typedef enum configID {W_CONFIG0=0, W_CONFIG1,
    56                        W_CONFIG2, W_CONFIG3};
     64#define W_CONFIG0 0
     65#define W_CONFIG1 1
     66#define W_CONFIG2 2
     67#define W_CONFIG3 3
    5768
    5869//! this is a weapon Configuration: it has up to 8 slots
    5970typedef 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
     71  bool bUsed;                       //<! is set to true, if this configuration is
     72  Weapon* slots[8];
    6873};
    6974
     
    7479  ~WeaponManager();
    7580 
    76   void addWeapon(Weapon* weapon, slotID slot, configID config = W_CONFIG0);
    77   void addWeaponConfig(weaponConfig* config);
     81  void addWeapon(Weapon* weapon, int slotID = W_FREE_SLOT, int configID = W_CONFIG1);
    7882
    7983  void nextWeaponConf();
    8084  void prevWeaponConf();
    81   void selectConfig(configID config);
     85  void selectConfig(int configID);
    8286
    8387 private:
    8488  int nrOfConfigs;                      //<! number of configurations defined
    8589  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
     90  int currConfID;                    //<! the currently selected config
     91  weaponConfig configs[4];              //<! a list of four configurations
     92 
     93  int getNextFreeSlot();
    8894};
    8995
Note: See TracChangeset for help on using the changeset viewer.