Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4951 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Jul 24, 2005, 11:15:00 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: the new WeaponManager is online :)

Location:
orxonox/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/util/fast_factory.cc

    r4950 r4951  
    194194  {
    195195    PRINTF(2)("The deadList of Class %s is empty, this may be either because it has not been filled yet, or the cache is to small.\n" \
    196         "Fabricating a new %s", this->getName(), this->getName());
     196        "Fabricating a new %s\n", this->getName(), this->getName());
    197197    this->fabricate();
    198198    return this->resurrect();
  • orxonox/trunk/src/world_entities/player.cc

    r4926 r4951  
    4949  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
    5050
    51   this->weaponMan->addWeapon(wpRight, WM_CONFIG0, WM_SLOT0);
     51  this->weaponMan->addWeapon(wpRight);
    5252//  this->weaponMan->addWeapon(wpLeft, WM_CONFIG1, WM_SLOT1);
    5353//  this->weaponMan->addWeapon(wpRight, WM_CONFIG2);
     
    8383  Weapon* wpLeft = new TestGun(this, Vector(-2.6, 0.1, -3.0), Quaternion(), 1);
    8484
    85   this->weaponMan->addWeapon(wpRight, WM_CONFIG0, WM_SLOT0);
    86   this->weaponMan->addWeapon(wpLeft, WM_CONFIG1, WM_SLOT1);
    87   this->weaponMan->addWeapon(wpRight, WM_CONFIG2);
    88   this->weaponMan->addWeapon(wpLeft, WM_CONFIG2);
     85  this->weaponMan->addWeapon(wpRight, 0,0);
     86  this->weaponMan->addWeapon(wpLeft, 0, 1);
     87  this->weaponMan->addWeapon(wpLeft, 1, 1);
     88  this->weaponMan->addWeapon(wpRight, 2, 0);
     89/*  this->weaponMan->addWeapon(wpRight, WM_CONFIG2);
     90  this->weaponMan->addWeapon(wpLeft, WM_CONFIG2);*/
    8991}
    9092
     
    9698  this->setClassID(CL_PLAYER, "Player");
    9799
    98   this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
     100//  this->model = (Model*)ResourceManager::getInstance()->load("models/reaplow.obj", OBJ, RP_CAMPAIGN);
    99101  travelSpeed = 15.0;
    100102  velocity = new Vector();
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.cc

    r4949 r4951  
    1313   main-programmer: Patrick Boenzli
    1414   co-programmer: Benjamin Grauer
     15
     16   2005-07-24: Benjamin Grauer: restructurate, so it can handle the new Weapons.
    1517*/
    1618
     
    3436 * @param number of weapon slots of the model/ship <= 8 (limitied)
    3537 */
    36 WeaponManager::WeaponManager(int slotCount)
     38WeaponManager::WeaponManager(unsigned int slotCount)
    3739{
    3840  this->init();
    39   this->slotCount = slotCount;
     41  this->setSlotCount(slotCount);
    4042}
    4143
     
    5153WeaponManager::~WeaponManager()
    5254{
    53   /*
    54   i dont have to delete the weapons itself, because they are
    55   worldentities and therefore in the entities list of the world.
    56   world will clean them up for me
    57   */
    58   for(int i = 0; i < WM_MAX_CONFIGS; ++i)
    59   {
    60     this->configs[i].bUsed = false;
    61     for(int j = 0; j < WM_MAX_SLOTS; ++j)
    62       this->configs[i].slots[j] = NULL;
    63   }
    64 
    6555  // crosshair being a PNode it must not be deleted (this is because PNodes delete themselves.)
    6656  //delete this->crosshair;
     
    7464  this->setClassID(CL_WEAPON_MANAGER, "WeaponManager");
    7565
    76   for(int i = 0; i < WM_MAX_CONFIGS; ++i)
    77   {
    78     this->configs[i].bUsed = false;
    79     for(int j = 0; j < WM_MAX_SLOTS; ++j)
    80       this->configs[i].slots[j] = NULL;
    81   }
    82   this->currConfID = WM_CONFIG0;
    83 
    84 
    85 
    86 
     66  this->parent = NULL;
     67
     68  for (int i = 0; i < WM_MAX_CONFIGS; i++)
     69    for (int j = 0; j < WM_MAX_SLOTS; j++)
     70      this->configs[i][j] = NULL;
     71
     72  for (int i = 0; i < WM_MAX_SLOTS; i++)
     73  {
     74    this->currentSlotConfig[i].capability = WM_SLOTC_ALL;
     75    this->currentSlotConfig[i].currentWeapon = NULL;
     76    this->currentSlotConfig[i].nextWeapon = NULL;
     77  }
     78
     79  for (int i = 0; i < WM_MAX_LOADED_WEAPONS; i++)
     80    this->availiableWeapons[i] = NULL;
     81
     82
     83  this->currentConfigID = 0;
     84  this->slotCount = 2;
     85  this->weaponChange;
     86
     87  // CROSSHAIR INITIALISATION
    8788  this->crosshair = new Crosshair();
    8889
     
    101102{
    102103  static_cast<BaseObject*>(this)->loadParams(root);
    103 
     104/*
    104105  LoadParam<WeaponManager>(root, "slot-count", this, &WeaponManager::setSlotCount)
    105106      .describe("how many slots(cannons) the WeaponManager can handle");
     
    111112      // LoadParam<WeaponManager>(root, "Weapon", this, &WeaponManager::addWeapon);
    112113
    113   LOAD_PARAM_END_CYCLE;
     114  LOAD_PARAM_END_CYCLE;*/
    114115}
    115116
     
    134135 * @param slotCount the number of slots
    135136 */
    136 void WeaponManager::setSlotCount(int slotCount)
    137 {
    138   this->slotCount = slotCount;
     137void WeaponManager::setSlotCount(unsigned int slotCount)
     138{
     139  if (slotCount <= WM_MAX_SLOTS)
     140    this->slotCount = slotCount;
     141  else
     142    this->slotCount = WM_MAX_SLOTS;
    139143}
    140144
     
    152156void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID)
    153157{
    154   if( slotID == WM_FREE_SLOT)
    155   {
    156     int freeSlot = this->getNextFreeSlot( configID);
    157     if( freeSlot < 0 || freeSlot >= this->slotCount)
     158  if (unlikely(configID >= WM_MAX_CONFIGS || slotID >= (int)this->slotCount))
     159  {
     160    PRINTF(2)("Slot %d of config %d is not availiabe\n", slotID, configID);
     161    return;
     162  }
     163
     164  if (this->configs[configID][slotID] != NULL && configID > 0 && slotID > 0)
     165    PRINTF(3)("Weapon-slot %d/%d of %s already poulated, overwriting\n", configID, slotID, this->getName());
     166
     167  if (slotID == -1) // WM_FREE_SLOT
     168  {
     169    slotID = this->getNextFreeSlot(configID);
     170    if( slotID < 0 || slotID >= this->slotCount)
    158171    {
    159172      PRINTF(0)("There is no free slot in this WeaponConfig to dock this weapon at! Aborting\n");
    160173      return;
    161174    }
    162     PRINTF(3)("Added new Weapon to Config:%i/Slot:%i\n", configID, freeSlot);
    163     this->configs[configID].bUsed = true;
    164     this->configs[configID].slots[freeSlot] = weapon;
    165     return;
    166   }
    167   this->configs[configID].bUsed = true;
    168   this->configs[configID].slots[slotID] = weapon;
     175  }
     176  this->configs[configID][slotID] = weapon;
    169177  PRINTF(3)("Added a new Weapon to the WeaponManager: config %i/ slot %i\n", configID, slotID);
    170178}
     
    187195void WeaponManager::nextWeaponConf()
    188196{
    189   PRINTF(4)("Changing weapon configuration: from %i to next\n", this->currConfID);
    190 
    191   int i, lastConfID;
    192   lastConfID = this->currConfID;
    193   for(i = this->currConfID + 1; i < WM_MAX_CONFIGS && !this->configs[i].bUsed; ++i);
    194   if( i == WM_MAX_CONFIGS) this->currConfID = WM_CONFIG0;
    195   else this->currConfID = i;
    196 
    197 
    198   Weapon *w1, *w2;
    199   for(int j = 0; j < WM_MAX_SLOTS; ++j)
    200   {
    201     w1 = this->configs[lastConfID].slots[j];
    202     w2 = this->configs[this->currConfID].slots[j];
    203 
    204     if( w1 == w2)
     197  PRINTF(4)("Changing weapon configuration: from %i to next\n", this->currentConfigID);
     198
     199  ++this->currentConfigID;
     200  if (this->currentConfigID >= WM_MAX_CONFIGS)
     201    this->currentConfigID = 0;
     202
     203  for (int i = 0; i < WM_MAX_SLOTS; i++)
     204  {
     205    this->currentSlotConfig[i].nextWeapon = this->configs[currentConfigID][i];
     206    if (this->currentSlotConfig[i].currentWeapon != this->currentSlotConfig[i].nextWeapon && this->currentSlotConfig[i].currentWeapon != NULL)
     207      (this->currentSlotConfig[i].currentWeapon->requestAction(WA_DEACTIVATE));
     208  }
     209
     210  this->debug();
     211}
     212
     213
     214/**
     215 * triggers fire of all weapons in the current weaponconfig
     216 */
     217void WeaponManager::fire()
     218{
     219  Weapon* firingWeapon;
     220  for(int i = 0; i < this->slotCount; i++)
     221  {
     222    firingWeapon = this->currentSlotConfig[i].currentWeapon;
     223    if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT);
     224  }
     225  this->crosshair->setRotationSpeed(500);
     226  this->crossHairSizeAnim->replay();
     227}
     228
     229
     230/**
     231 * triggers tick of all weapons in the current weaponconfig
     232 * @param second passed since last tick
     233 */
     234void WeaponManager::tick(float dt)
     235{
     236  Weapon* tickWeapon;
     237
     238  // all weapons
     239  for(int i = 0; i < this->slotCount; i++)
     240  {
     241
     242    tickWeapon = this->currentSlotConfig[i].currentWeapon;
     243    if (tickWeapon != this->currentSlotConfig[i].nextWeapon) // if no change occures
    205244    {
    206       printf("no need for change\n");
    207     }
    208     else
    209     {
    210       if( w1 != NULL )
     245      if (tickWeapon != NULL && tickWeapon->isActive())
    211246      {
    212         w1->requestAction(WA_DEACTIVATE);
    213         printf("deactivating %i,%i\n", j,lastConfID);
     247        tickWeapon->requestAction(WA_DEACTIVATE);
    214248      }
    215       if( w2 != NULL)
     249      else
    216250      {
    217         w2->requestAction(WA_ACTIVATE);
    218         printf("activating %i,%i\n", j, this->currConfID);
     251        tickWeapon = this->currentSlotConfig[i].currentWeapon = this->currentSlotConfig[i].nextWeapon;
     252        if (tickWeapon != NULL)
     253          tickWeapon->requestAction(WA_ACTIVATE);
    219254      }
    220255    }
    221   }
    222 }
    223 
    224 
    225 /**
    226  * triggers fire of all weapons in the current weaponconfig
    227  */
    228 void WeaponManager::fire()
    229 {
    230   Weapon* firingWeapon;
    231   for(int i = 0; i < WM_MAX_SLOTS; ++i)
    232   {
    233     firingWeapon = this->configs[this->currConfID].slots[i];
    234     if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT);
    235   }
    236   this->crosshair->setRotationSpeed(500);
    237   this->crossHairSizeAnim->replay();
    238 }
    239 
    240 
    241 /**
    242  * triggers tick of all weapons in the current weaponconfig
    243  * @param second passed since last tick
    244  */
    245 void WeaponManager::tick(float dt)
    246 {
    247   Weapon* w;
    248   for(int i = 0; i < WM_MAX_SLOTS; ++i)
    249   {
    250     w = this->configs[this->currConfID].slots[i];
    251     if( w != NULL && w->isActive())
    252       w->tickW(dt);
     256
     257    if( tickWeapon != NULL && tickWeapon->isActive())
     258      tickWeapon->tickW(dt);
    253259  }
    254260
     
    260266 * triggers draw of all weapons in the current weaponconfig
    261267 */
    262 void WeaponManager::draw()
    263 {
    264   Weapon* w;
    265   for (int j = 0; j < 4; ++j )
    266   for(int i = 0; i < WM_MAX_SLOTS; ++i)
    267   {
    268     w = this->configs[j].slots[i];
    269     if( w != NULL && w->isVisible())
    270       w->draw();
     268void WeaponManager::draw() const
     269{
     270  Weapon* drawWeapon;
     271  for (int i = 0; i < this->slotCount; i++)
     272  {
     273    drawWeapon = this->currentSlotConfig[i].currentWeapon;
     274    if( drawWeapon != NULL && drawWeapon->isVisible())
     275      drawWeapon->draw();
    271276  }
    272277}
     
    279284int WeaponManager::getNextFreeSlot(int configID)
    280285{
    281   for( int i = 0; i < WM_MAX_SLOTS; ++i)
    282   {
    283     if( this->configs[configID].slots[i] == NULL)
     286  for( int i = 0; i < this->slotCount; ++i)
     287  {
     288    if( this->configs[configID][i] == NULL)
    284289      return i;
    285290  }
     
    287292}
    288293
     294
     295
     296void WeaponManager::debug() const
     297{
     298  PRINT(3)("WeaponManager Debug Information\n");
     299  PRINT(3)("-------------------------------\n");
     300  PRINT(3)("current Config is %d\n", this->currentConfigID);
     301  for (int i = 0; i < WM_MAX_CONFIGS; i++)
     302  {
     303    PRINT(3)("Listing Weapons in Configuration %d\n", i);
     304    for (int j = 0; j < WM_MAX_SLOTS; j++)
     305    {
     306      if (this->configs[i][j] != NULL)
     307        PRINT(3)("Slot %d loaded a %s\n", j, this->configs[i][j]->getClassName());
     308    }
     309  }
     310}
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.h

    r4950 r4951  
    2929#include "base_object.h"
    3030
     31#include "vector.h"
    3132
    3233// FORWARD DECLARATION
     34class PNode;
    3335class Weapon;
    3436class Crosshair;
    3537template <class T> class tAnimation;
    3638
    37 #define    WM_MAX_SLOTS            8                   //!< How many slots the WeaponManager has at its max
    38 #define    WM_MAX_CONFIGS          4                   //!< The maximum number of predefined Configurations
    39 #define    WM_MAX_LOADED_WEAPONS   20                  //!< The
    4039
    41 //! this is an identifier for the weapon config
     40#define    WM_MAX_SLOTS            8              //!< How many slots the WeaponManager has at its max
     41#define    WM_MAX_CONFIGS          4              //!< The maximum number of predefined Configurations
     42#define    WM_MAX_LOADED_WEAPONS   20             //!< The
     43
     44//! an enumerator defining capabilities of a WeaponSlot
    4245typedef enum
    4346{
    44   WM_CONFIG0           = 0,
    45   WM_CONFIG1           = 1,
    46   WM_CONFIG2           = 2,
    47   WM_CONFIG3           = 3,
     47  WM_SLOTC_DIRECTIONAL   = 0x00000001,           //!< if the Slot is able to carry directional weapons
     48  WM_SLOTC_TURRET        = 0x00000002,           //!< if the Slot is able to carry turrets
     49  WM_SLOTC_ALLKINDS      = 0x0000000f,           //!< if the Slot is able to carry all kinds of weapons
    4850
    49   WM_CONFIGCOUNT       = 4
    50 } WM_CONFIG;
     51  WM_SLOTC_FORWARD       = 0x00000010,           //!< if the Slot is able to carry weapons firing forward
     52  WM_SLOTC_BACKWARD      = 0x00000020,           //!< if the Slot is able to carry weapons firing backwards
     53  WM_SLOTC_LEFT          = 0x00000040,           //!< if the Slot is able to carry weapons firing to the left
     54  WM_SLOTC_RIGHT         = 0x00000080,           //!< if the Slot is able to carry weapons firing to the right
     55  WM_SLOTC_ALLDIRS       = 0x000000f0,           //!< this slot can fire into all directions
    5156
    52 //! 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
    53 typedef enum
    54 {
    55   WM_SLOT0              = 0,
    56   WM_SLOT1              = 1,
    57   WM_SLOT2              = 2,
    58   WM_SLOT3              = 3,
    59   WM_SLOT4              = 4,
    60   WM_SLOT5              = 5,
    61   WM_SLOT6              = 6,
    62   WM_SLOT7              = 7,
    63 
    64   WM_SLOT_COUNT         = 8,
    65 
    66   WM_FREE_SLOT          = -1
    67 } WM_SLOT;
    68 
    69 typedef enum
    70 {
    71   WM_SLOTC_DIRECTIONAL   = 1,
    72   WM_SLOTC_TURRET        = 2,
    73   WM_SLOTC_ALLKINDS      = 3,
    74 
    75   WM_SLOTC_FORWARD       = 4,
    76   WM_SLOTC_BACKWARD      = 8,
    77   WM_SLOTC_LEFT          = 16,
    78   WM_SLOTC_RIGHT         = 32,
    79   WM_SLOTC_ALLDIRS       = 60,
    80 
    81   WM_SLOTC_ALL           = 63,
     57  WM_SLOTC_ALL           = 0x000000ff,           //!< everything allowed in this slot
    8258} WM_SlotCapability;
    8359
    84 typedef struct WM_Slot
    85 {
    86   int           number;
    87   long          capability;
    88 
    89   Weapon*       currentWeapon;
    90   Weapon*       nextWeapon;
    91 };
    92 
    93 //! this is a weapon Configuration: it has up to 8 slots
     60//! an enumerator defining a Slot, where a Weapon can be stored inside.
    9461typedef struct
    9562{
    96   bool           bUsed;                       //!< is set to true, if this configuration is
    97   Weapon*        slots[WM_MAX_SLOTS];
    98 } weaponConfig;
     63  Vector        position;               //!< the relative Position to the position of the carrying entity. (const PNode* parent; of WeaponManager)
     64  long          capability;             //!< the capabilities of the Slot @see WM_SlotCapability.
    9965
     66  Weapon*       currentWeapon;          //!< The current weapon this slot is carrying.
     67  Weapon*       nextWeapon;             //!< either NULL or the next weapon that will be set (require currentWeapon to deactivate)
     68} WM_Slot;
    10069
    10170class WeaponManager : public BaseObject {
    10271  public:
    103     WeaponManager(int slotCount);
     72    WeaponManager(unsigned int slotCount);
    10473    WeaponManager(const TiXmlElement* root);
    10574    ~WeaponManager();
     
    10978    void loadWeapons(const TiXmlElement* root);
    11079
    111     void setSlotCount(int slotCount);
     80    // setting up the WeaponManager with the following functions
     81    void setSlotPosition(int slot, const Vector& position);
     82    void setSlotCapability(long slotCapability);
    11283
    113     void addWeapon(Weapon* weapon, int configID = WM_CONFIG0, int slotID = WM_FREE_SLOT);
    114     void removeWeapon(Weapon* weapon, int configID = WM_CONFIG0);
     84    void addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
     85    void removeWeapon(Weapon* weapon, int configID = -1);
     86
    11587    void nextWeaponConf();
    11688
    11789    void fire();
     90
    11891    void tick(float dt);
    119     void draw();
     92    void draw() const;
     93
     94    void debug() const;
    12095
    12196  private:
     97    void setSlotCount(unsigned int slotCount);
     98
    12299    int getNextFreeSlot(int configID);
    123100
    124101  private:
    125     Crosshair*              crosshair;               //!< an aim.
    126     tAnimation<Crosshair>*  crossHairSizeAnim;       //!< An animation for the crosshair (scaling)
     102    PNode*                  parent;                                  //!< The parent, this WeaponManager is connected to.
    127103
    128     int                     slotCount;               //!< number of weapon slots a ship has
    129     int                     currConfID;              //!< the currently selected config
    130     weaponConfig            configs[4];              //!< a list of four configurations
     104    int                     slotCount;                               //!< number of weapon slots the ship has.
     105    int                     currentConfigID;                         //!< the currently selected config.
     106    Weapon*                 configs[WM_MAX_CONFIGS][WM_MAX_SLOTS];   //!< An array of predefined configurations and assigned weapon.
     107    WM_Slot                 currentSlotConfig[WM_MAX_SLOTS];         //!< The currentConfigureation.
    131108
    132109    Weapon*                 availiableWeapons[WM_MAX_LOADED_WEAPONS];
     110
     111    bool                    weaponChange;
     112
     113    Crosshair*              crosshair;                               //!< an aim.
     114    tAnimation<Crosshair>*  crossHairSizeAnim;                       //!< An animation for the crosshair (scaling)
    133115};
Note: See TracChangeset for help on using the changeset viewer.