Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 25, 2005, 12:22:24 AM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: Slots are now PNodes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.cc

    r4952 r4953  
    2828#include "list.h"
    2929#include "t_animation.h"
     30#include "null_parent.h"
    3031
    3132using namespace std;
     
    3637 * @param number of weapon slots of the model/ship <= 8 (limitied)
    3738 */
    38 WeaponManager::WeaponManager(unsigned int slotCount)
     39WeaponManager::WeaponManager(PNode* parent)
    3940{
    4041  this->init();
    41   this->setSlotCount(slotCount);
     42  this->setParent(parent);
    4243}
    4344
     
    130131}
    131132
     133void WeaponManager::setParent(PNode* parent)
     134{
     135  if (parent == NULL)
     136    parent = NullParent::getInstance();
     137  this->parent = parent;
     138  if (this->parent != NULL)
     139  {
     140    for (int i = 0; i < WM_MAX_SLOTS; i++)
     141      this->parent->addChild(&this->currentSlotConfig[i].position);
     142  }
     143
     144}
    132145
    133146/**
     
    141154  else
    142155    this->slotCount = WM_MAX_SLOTS;
     156}
     157
     158void WeaponManager::setSlotPosition(int slot, const Vector& position)
     159{
     160  if (slot < this->slotCount)
     161    this->currentSlotConfig[slot].position.setRelCoor(position);
    143162}
    144163
     
    174193    }
    175194  }
     195
     196  //! @todo check if the weapon is already assigned to another config in another slot
     197
    176198  this->configs[configID][slotID] = weapon;
     199  if (this->parent != NULL)
     200    weapon->setParent(parent);
    177201  PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);
    178202}
     
    189213/**
    190214 * changes to the next weapon configuration
    191  *
    192  * if there are multiple weapon configurations defined by the manager, use this to switch between them
    193  * this function will deactivate the weapons first, change the config and reactivate them later
    194215 */
    195216void WeaponManager::nextWeaponConf()
     
    199220    this->currentConfigID = 0;
    200221  this->changeWeaponConfig(this->currentConfigID);
    201   this->debug();
    202 }
    203 
     222}
     223
     224/**
     225 * changes to the previous configuration
     226 */
    204227void WeaponManager::previousWeaponConfig()
    205228{
     
    208231    this->currentConfigID = WM_MAX_CONFIGS -1;
    209232  this->changeWeaponConfig(this->currentConfigID);
    210   this->debug();
    211 
    212 
    213 }
    214 
     233}
     234
     235/**
     236 * change to a desired configuration
     237 * @param weaponConfig the configuration to jump to.
     238 */
    215239void WeaponManager::changeWeaponConfig(int weaponConfig)
    216240{
     
    220244  {
    221245    this->currentSlotConfig[i].nextWeapon = this->configs[currentConfigID][i];
    222     if (this->currentSlotConfig[i].currentWeapon != NULL && this->currentSlotConfig[i].currentWeapon != this->currentSlotConfig[i].nextWeapon)
    223       (this->currentSlotConfig[i].currentWeapon->requestAction(WA_DEACTIVATE));
     246    if (this->currentSlotConfig[i].currentWeapon != this->currentSlotConfig[i].nextWeapon)
     247    {
     248      if (this->currentSlotConfig[i].currentWeapon != NULL)
     249        (this->currentSlotConfig[i].currentWeapon->requestAction(WA_DEACTIVATE));
     250      if (this->currentSlotConfig[i].nextWeapon != NULL && this->currentSlotConfig[i].nextWeapon->isActive())
     251        this->currentSlotConfig[i].nextWeapon = NULL;
     252    }
    224253  }
    225254}
     
    265294        tickWeapon = this->currentSlotConfig[i].currentWeapon = this->currentSlotConfig[i].nextWeapon;
    266295        if (tickWeapon != NULL)
     296        {
    267297          tickWeapon->requestAction(WA_ACTIVATE);
     298          tickWeapon->setParent(&this->currentSlotConfig[i].position);
     299        }
    268300      }
    269301    }
     
    308340
    309341
     342/**
     343 * outputs some nice debug information about the WeaponManager
     344 */
    310345void WeaponManager::debug() const
    311346{
Note: See TracChangeset for help on using the changeset viewer.