Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10437 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Jan 28, 2007, 1:30:45 PM (18 years ago)
Author:
patrick
Message:

weapon slot is now moved outside

Location:
trunk/src/world_entities
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/Makefile.am

    r10405 r10437  
    1212                     npcs/npc.cc\
    1313                     weapons/weapon_manager.cc\
     14                     weapons/weapon_slot.cc \
    1415                     weapons/crosshair.cc \
    1516                     weapons/weapon.cc\
     
    3637                 npcs/npc.h\
    3738                 weapons/weapon_manager.h\
     39                 weapons/weapon_slot.cc \
    3840                 weapons/crosshair.h \
    3941                 weapons/weapon.h\
  • trunk/src/world_entities/WorldEntities.am

    r10433 r10437  
    3535                world_entities/questGUI/quest.cc \
    3636                \
     37                world_entities/weapons/weapon_slot.cc \
    3738                world_entities/weapons/test_gun.cc \
    3839                world_entities/weapons/laser_cannon.cc \
     
    166167                questGUI/quest.h \
    167168                \
     169                weapons/weapon_slot.h \
    168170                weapons/test_gun.h \
    169171                weapons/laser_cannon.cc \
  • trunk/src/world_entities/mount_point.cc

    r10314 r10437  
    3737{
    3838  PRINTF(5)("Created mount point %s\n", name.c_str());
     39  this->registerObject(this, MountPoint::_objectList);
    3940
    4041  this->_name = name;
  • trunk/src/world_entities/weapons/weapon_manager.cc

    r10368 r10437  
    1515
    1616   2005-07-24: Benjamin Grauer: restructurate, so it can handle the new Weapons.
     17   2007-01-28: Patrick Boenzli: loadable slots
    1718*/
    1819
     
    2122#include "weapon_manager.h"
    2223#include "weapon.h"
     24#include "weapon_slot.h"
    2325#include "crosshair.h"
    2426
     
    7779  for (int i = 0; i < WM_MAX_SLOTS; i++)
    7880  {
    79     this->currentSlotConfig[i].capability = WTYPE_ALL;
    80     this->currentSlotConfig[i].currentWeapon = NULL;
    81     this->currentSlotConfig[i].nextWeapon = NULL;
     81    this->currentSlotConfig[i] = new WeaponSlot();
     82    this->currentSlotConfig[i]->setCapability(WTYPE_ALL);
     83    this->currentSlotConfig[i]->setCurrentWeapon(NULL);
     84    this->currentSlotConfig[i]->setNextWeapon(NULL);
    8285
    8386    // NAMING
     
    9396      sprintf(tmpName, "WeaponMan_slot%d", i);
    9497    }
    95     this->currentSlotConfig[i].position.setName(tmpName);
    96     this->currentSlotConfig[i].position.deactivateNode();
     98    this->currentSlotConfig[i]->setName(tmpName);
     99    this->currentSlotConfig[i]->deactivateNode();
    97100    delete[] tmpName;
    98101  }
     
    199202  {
    200203    for (int i = 0; i < WM_MAX_SLOTS; i++)
    201       this->parentNode->addChild(&this->currentSlotConfig[i].position);
     204      this->parentNode->addChild(this->currentSlotConfig[i]);
    202205  }
    203206
     
    227230  if (slot < this->slotCount)
    228231  {
    229     this->currentSlotConfig[slot].position.setRelCoor(position);
     232    this->currentSlotConfig[slot]->setRelCoor(position);
    230233
    231234    if (parent != NULL)
    232       this->currentSlotConfig[slot].position.setParent(parent);
     235      this->currentSlotConfig[slot]->setParent(parent);
    233236  }
    234237}
     
    243246{
    244247  if (slot < this->slotCount)
    245     this->currentSlotConfig[slot].position.setRelDir(rotation);
     248    this->currentSlotConfig[slot]->setRelDir(rotation);
    246249}
    247250
     
    298301  }
    299302
    300   if (!(this->currentSlotConfig[slotID].capability & weapon->getCapability() & WTYPE_ALLKINDS) &&
    301       this->currentSlotConfig[slotID].capability & weapon->getCapability() & WTYPE_ALLDIRS)
     303  if (!(this->currentSlotConfig[slotID]->getCapability() & weapon->getCapability() & WTYPE_ALLKINDS) &&
     304      this->currentSlotConfig[slotID]->getCapability() & weapon->getCapability() & WTYPE_ALLDIRS)
    302305  {
    303306    PRINTF(2)("Unable to add Weapon with wrong capatibility to Slot %d (W:%d M:%d)\n",
    304               slotID, weapon->getCapability(), this->currentSlotConfig[slotID].capability);
     307              slotID, weapon->getCapability(), this->currentSlotConfig[slotID]->getCapability());
    305308    return false;
    306309  }
     
    313316  weapon->setAmmoContainer(this->getAmmoContainer(weapon->getProjectileType()));
    314317  if(configID == this->currentConfigID)
    315     this->currentSlotConfig[slotID].nextWeapon = weapon;
     318    this->currentSlotConfig[slotID]->nextWeapon = weapon;
    316319  //if (this->parent != NULL)
    317320  {
     
    319322    if (this->parentEntity->isA(Playable::staticClassID()))
    320323      dynamic_cast<Playable*>(this->parentEntity)->weaponConfigChanged();
    321    
     324
    322325    weapon->setDefaultTarget(this->crosshair);
    323326  }
     
    352355 * sets the capabilities of a Slot
    353356 * @param slot the slot to set the capability
    354  * @param slotCapability the capability @see WM_SlotCapability
     357 * @param slotCapability the capability @see WeaponSlotCapability
    355358 */
    356359void WeaponManager::setSlotCapability(int slot, long slotCapability)
     
    358361  if (slot > slotCount)
    359362    return;
    360   this->currentSlotConfig[slot].capability = slotCapability;
     363  this->currentSlotConfig[slot]->setCapability(slotCapability);
    361364}
    362365
     
    381384          this->configs[i][j] = NULL;
    382385      }
    383       if (this->currentSlotConfig[j].currentWeapon == weapon)
     386      if (this->currentSlotConfig[j]->getCurrentWeapon() == weapon)
    384387      {
    385         this->currentSlotConfig[j].nextWeapon = NULL;
     388        this->currentSlotConfig[j]->setNextWeapon(NULL);
    386389      }
    387390    }
     
    422425
    423426  for (int i = 0; i < WM_MAX_SLOTS; i++)
    424     this->currentSlotConfig[i].nextWeapon = this->configs[currentConfigID][i];
     427    this->currentSlotConfig[i]->nextWeapon = this->configs[currentConfigID][i];
    425428}
    426429
     
    436439  {
    437440//     printf("%i ", i);
    438           firingWeapon = this->currentSlotConfig[i].currentWeapon;
     441          firingWeapon = this->currentSlotConfig[i]->getCurrentWeapon();
    439442      if( firingWeapon != NULL && firingWeapon->getCurrentState() == WS_SHOOTING) continue;
    440443          if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT);
     
    455458  for(int i = 0; i < this->slotCount; i++)
    456459  {
    457     firingWeapon = this->currentSlotConfig[i].currentWeapon;
     460    firingWeapon = this->currentSlotConfig[i]->currentWeapon;
    458461    if( firingWeapon != NULL) firingWeapon->requestAction(WA_NONE);
    459462  }
     
    478481
    479482    //NICE LITTLE DEBUG FUNCTION
    480     /*   if (this->currentSlotConfig[i].currentWeapon != NULL || this->currentSlotConfig[i].nextWeapon != NULL)
    481       printf("%p %p\n", this->currentSlotConfig[i].currentWeapon, this->currentSlotConfig[i].nextWeapon);*/
     483    /*   if (this->currentSlotConfig[i]->currentWeapon != NULL || this->currentSlotConfig[i]->nextWeapon != NULL)
     484      printf("%p %p\n", this->currentSlotConfig[i]->currentWeapon, this->currentSlotConfig[i]->nextWeapon);*/
    482485
    483486    // current Weapon in Slot i
    484     tickWeapon = this->currentSlotConfig[i].currentWeapon;
     487    tickWeapon = this->currentSlotConfig[i]->currentWeapon;
    485488    // On A change (current != next)
    486     if (tickWeapon != this->currentSlotConfig[i].nextWeapon)
     489    if (tickWeapon != this->currentSlotConfig[i]->nextWeapon)
    487490    {
    488491      // if a Weapon is Active in slot i, deactivate it.
     
    497500        {
    498501          tickWeapon->toList(OM_NULL);
    499           this->currentSlotConfig[i].currentWeapon = NULL;
     502          this->currentSlotConfig[i]->currentWeapon = NULL;
    500503        }
    501504      }
    502505      // switching to next Weapon
    503       tickWeapon = this->currentSlotConfig[i].currentWeapon = this->currentSlotConfig[i].nextWeapon;
    504      
     506      tickWeapon = this->currentSlotConfig[i]->currentWeapon = this->currentSlotConfig[i]->nextWeapon;
     507
    505508      if (tickWeapon != NULL)
    506509      {
     
    508511        tickWeapon->toList(this->parentEntity->getOMListNumber());
    509512        tickWeapon->requestAction(WA_ACTIVATE);
    510         this->currentSlotConfig[i].position.activateNode();
    511         tickWeapon->setParent(&this->currentSlotConfig[i].position);
     513        this->currentSlotConfig[i]->activateNode();
     514        tickWeapon->setParent(this->currentSlotConfig[i]);
    512515      }
    513516      else
    514         this->currentSlotConfig[i].position.deactivateNode();
     517        this->currentSlotConfig[i]->deactivateNode();
    515518      if (this->parentEntity != NULL && this->parentEntity->isA(Playable::staticClassID()))
    516519        dynamic_cast<Playable*>(this->parentEntity)->weaponConfigChanged();
    517520    }
    518521    else if (unlikely(tickWeapon != NULL && tickWeapon->getCurrentState() == WS_DEACTIVATING))
    519       this->currentSlotConfig[i].nextWeapon = NULL;
     522      this->currentSlotConfig[i]->nextWeapon = NULL;
    520523  }
    521524}
     
    531534  for (int i = 0; i < this->slotCount; i++)
    532535  {
    533     drawWeapon = this->currentSlotConfig[i].currentWeapon;
     536    drawWeapon = this->currentSlotConfig[i]->currentWeapon;
    534537    if( drawWeapon != NULL && drawWeapon->isVisible())
    535538      drawWeapon->draw();
     
    550553      {
    551554        if( this->configs[configID][i] == NULL &&
    552             (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) &&
    553             (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS))
     555            (this->currentSlotConfig[i]->getCapability() & capability & WTYPE_ALLKINDS) &&
     556            (this->currentSlotConfig[i]->getCapability() & capability & WTYPE_ALLDIRS))
    554557          return i;
    555558      }
     
    560563    {
    561564      if( this->configs[configID][i] == NULL &&
    562           (this->currentSlotConfig[i].capability & capability & WTYPE_ALLKINDS) &&
    563           (this->currentSlotConfig[i].capability & capability & WTYPE_ALLDIRS))
     565          (this->currentSlotConfig[i]->getCapability() & capability & WTYPE_ALLKINDS) &&
     566          (this->currentSlotConfig[i]->getCapability() & capability & WTYPE_ALLDIRS))
    564567        return i;
    565568    }
     
    604607  }
    605608}
     609
     610
     611long WeaponManager::getSlotCapability(int slot) const
     612{
     613  return this->currentSlotConfig[slot]->getCapability();
     614}
     615
     616const Vector& WeaponManager::getSlotPosition(int slot) const
     617{
     618  return this->currentSlotConfig[slot]->getRelCoor();
     619}
     620
     621Weapon* WeaponManager::getWeapon(int slotID) const
     622{
     623  return (slotID >= 0 && slotID < this->slotCount)? this->currentSlotConfig[slotID]->getNextWeapon(): NULL;
     624}
     625
     626
  • trunk/src/world_entities/weapons/weapon_manager.h

    r10368 r10437  
    2121#include "ammo_container.h"
    2222
     23
    2324// FORWARD DECLARATION
    2425template <class T> class tAnimation;
     26class WeaponSlot;
    2527
    2628#define    WM_MAX_SLOTS            10             //!< How many slots the WeaponManager has at its max
     
    4042class WeaponManager : public BaseObject {
    4143  ObjectListDeclaration(WeaponManager);
    42 
    43   //! an enumerator defining a Slot, where a Weapon can be stored inside.
    44   typedef struct
    45   {
    46     PNode         position;               //!< the relative Position to the position of the carrying entity. (const PNode* parent; of WeaponManager)
    47     long          capability;             //!< the capabilities of the Slot @see WM_SlotCapability.
    48 
    49     Weapon*       currentWeapon;          //!< The current weapon this slot is carrying.
    50     Weapon*       nextWeapon;             //!< either NULL or the next weapon that will be set (require currentWeapon to deactivate)
    51   } WM_Slot;
    5244
    5345  public:
     
    7062    void setSlotDirection(int slot, const Quaternion& rotation);
    7163    /** @param slot the slot to get the relative position from @returns the relative position of the Carrier to the Slot */
    72     const Vector& getSlotPosition(int slot) const { return this->currentSlotConfig[slot].position.getRelCoor(); };
     64    const Vector& getSlotPosition(int slot) const;
    7365    void setSlotCapability(int slot, long slotCapability);
    7466    /** @param slot the slot to get the capabilities from @returns the capabilies */
    75     long getSlotCapability(int slot) const { return this->currentSlotConfig[slot].capability; };
     67    long getSlotCapability(int slot) const;
    7668
    7769    void setParentEntity(WorldEntity* parent);
     
    8577    void removeWeapon(Weapon* weapon, int configID = -1);
    8678
    87     Weapon* getWeapon(int slotID) const { return (slotID >= 0 && slotID < this->slotCount)? this->currentSlotConfig[slotID].nextWeapon: NULL; };
     79    Weapon* getWeapon(int slotID) const;
    8880
    8981    // FIXME ::
     
    122114    int                     currentConfigID;                          //!< the currently selected config.
    123115    Weapon*                 configs[WM_MAX_CONFIGS][WM_MAX_SLOTS];    //!< An array of predefined configurations and assigned weapon.
    124     WM_Slot                 currentSlotConfig[WM_MAX_SLOTS];          //!< The currentConfigureation.
     116    WeaponSlot*             currentSlotConfig[WM_MAX_SLOTS];          //!< The currentConfigureation.
    125117
    126118    Weapon*                 availiableWeapons[WM_MAX_LOADED_WEAPONS]; //!< The availiable Weapons of this WeaponManager
Note: See TracChangeset for help on using the changeset viewer.