Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6669 in orxonox.OLD for trunk/src/world_entities


Ignore:
Timestamp:
Jan 24, 2006, 2:26:15 PM (19 years ago)
Author:
bensch
Message:

some WeaponManager remake

Location:
trunk/src/world_entities
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/playable.cc

    r6589 r6669  
    5252void Playable::addWeapon(Weapon* weapon, int configID, int slotID)
    5353{
    54   this->weaponMan->addWeapon(weapon, configID, slotID);
     54  this->weaponMan->addWeapon(weapon);
    5555
    5656  this->weaponConfigChanged();
  • trunk/src/world_entities/weapons/ammo_container.cc

    r6664 r6669  
    3232   this->setClassID(CL_AMMO_CONTAINER, "AmmoContainer");
    3333
    34 
     34   this->energy = 0.0;
     35   this->maxEnergy = maxEnergy;
    3536}
    3637
  • trunk/src/world_entities/weapons/ammo_container.h

    r6655 r6669  
    2222  virtual ~AmmoContainer();
    2323
     24  bool operator=(ClassID projectileType) const { return (this->projectileType == projectileType); };
    2425  ClassID getProjectileType() const { return this->projectileType; };
    25 
    2626
    2727  float increaseEnergy(float energy);
  • trunk/src/world_entities/weapons/weapon.h

    r6512 r6669  
    1616
    1717#include "world_entity.h"
     18#include "count_pointer.h"
     19#include "ammo_container.h"
    1820
    1921// FORWARD DECLARATION
     
    105107    inline void setCapability(long capabilities) { this->capability = capabilities; };
    106108    /** @returns the Capabilities of this Weapon */
    107     inline long getCapability() { return this->capability; };
     109    inline long getCapability() const { return this->capability; };
    108110    void setProjectileType(ClassID projectile);
    109111    void setProjectileType(const char* projectile);
     
    139141    inline float getLoadedEnergyMax() const { return this->energyLoadedMax; };
    140142    inline float getEnergyMax() const { return this->energyMax; };
     143    inline void setAmmoContainer(const CountPointer<AmmoContainer>& ammoContainer) { this->ammoContainer = ammoContainer;}
    141144    inline float getEnergy() const { return this->energy; };
    142145    inline float getLoadedEnergy() const { return this->energyLoaded; };
     
    200203    float                energy;                           //!< The energy stored in the weapons secondary buffers (reserve)
    201204    float                energyLoaded;                     //!< The energy stored in the weapons primary buffers (fire without reload)
     205    CountPointer<AmmoContainer> ammoContainer;             //!< Pointer to the AmmoContainer this weapon grabs Energy from.
    202206    float                energyMax;                        //!< The maximal energy that can be stored in the secondary buffers (reserveMax)
    203207    float                energyLoadedMax;                  //!< The maximal energy that can be stored in the primary buffers
  • trunk/src/world_entities/weapons/weapon_manager.cc

    r6568 r6669  
    203203}
    204204
     205
     206bool WeaponManager::addWeapon(Weapon* weapon)
     207{
     208  int weaponConf = this->currentConfigID;
     209  int slot;
     210  if (slot = this->getNextFreeSlot(weaponConf, weapon->getCapability()) == -1 )
     211    this->addWeapon(weapon, weaponConf, slot);
     212}
    205213
    206214/**
     
    246254  //! @todo check if the weapon is already assigned to another config in another slot
    247255  this->configs[configID][slotID] = weapon;
     256  weapon->setAmmoContainer(this->getAmmoContainer(weapon->getProjectileType()));
    248257  if (this->parent != NULL)
    249258  {
     
    420429/**
    421430 * private gets the next free slot in a certain weaponconfig
    422  * @param the selected weaponconfig
     431 * @param the selected weaponconfig -1 if none found
    423432 */
    424433int WeaponManager::getNextFreeSlot(int configID, long capability)
     
    434443}
    435444
     445CountPointer<AmmoContainer>& WeaponManager::getAmmoContainer(ClassID projectileType)
     446{
     447  for (unsigned int i = 0; i < this->ammo.size(); i++)
     448  {
     449    if (this->ammo[i]->getProjectileType() == projectileType)
     450      return this->ammo[i];
     451  }
     452  this->ammo.push_back(CountPointer<AmmoContainer>(new AmmoContainer(projectileType)));
     453  return this->ammo.back();
     454}
    436455
    437456
  • trunk/src/world_entities/weapons/weapon_manager.h

    r6561 r6669  
    1717#include "crosshair.h"
    1818#include "weapon.h"
     19
     20#include "count_pointer.h"
     21#include "ammo_container.h"
    1922
    2023// FORWARD DECLARATION
     
    7275
    7376    bool addWeapon(Weapon* weapon);
    74     bool addWeapon(Weapon* weapon, int configID = -1, int slotID = -1);
     77    bool addWeapon(Weapon* weapon, int configID, int slotID = -1);
    7578    void removeWeapon(Weapon* weapon, int configID = -1);
     79
    7680    Weapon* getWeapon(int slotID) const { return (slotID >= 0 && slotID < this->slotCount)? this->currentSlotConfig[slotID].nextWeapon: NULL; };
    7781
     
    8286    void previousWeaponConfig();
    8387    void changeWeaponConfig(int weaponConfig);
     88
     89    float addAmmunition(ClassID projectileType, float ammo);
     90
    8491
    8592    /** @returns a fixed target namely the Crosshair's 3D position */
     
    97104 // private:
    98105    int getNextFreeSlot(int configID, long capability = WTYPE_ALL);
     106    CountPointer<AmmoContainer>& getAmmoContainer(ClassID projectileType);
    99107
    100108  private:
     
    112120    Crosshair*              crosshair;                                //!< an aim.
    113121    tAnimation<Crosshair>*  crossHairSizeAnim;                        //!< An animation for the crosshair (scaling)
     122
     123    std::vector<CountPointer<AmmoContainer> > ammo;                   //!< Containers
    114124};
    115125
Note: See TracChangeset for help on using the changeset viewer.