Changeset 6669 in orxonox.OLD for trunk/src/world_entities/weapons
- Timestamp:
- Jan 24, 2006, 2:26:15 PM (19 years ago)
- Location:
- trunk/src/world_entities/weapons
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/weapons/ammo_container.cc
r6664 r6669 32 32 this->setClassID(CL_AMMO_CONTAINER, "AmmoContainer"); 33 33 34 34 this->energy = 0.0; 35 this->maxEnergy = maxEnergy; 35 36 } 36 37 -
trunk/src/world_entities/weapons/ammo_container.h
r6655 r6669 22 22 virtual ~AmmoContainer(); 23 23 24 bool operator=(ClassID projectileType) const { return (this->projectileType == projectileType); }; 24 25 ClassID getProjectileType() const { return this->projectileType; }; 25 26 26 27 27 float increaseEnergy(float energy); -
trunk/src/world_entities/weapons/weapon.h
r6512 r6669 16 16 17 17 #include "world_entity.h" 18 #include "count_pointer.h" 19 #include "ammo_container.h" 18 20 19 21 // FORWARD DECLARATION … … 105 107 inline void setCapability(long capabilities) { this->capability = capabilities; }; 106 108 /** @returns the Capabilities of this Weapon */ 107 inline long getCapability() { return this->capability; };109 inline long getCapability() const { return this->capability; }; 108 110 void setProjectileType(ClassID projectile); 109 111 void setProjectileType(const char* projectile); … … 139 141 inline float getLoadedEnergyMax() const { return this->energyLoadedMax; }; 140 142 inline float getEnergyMax() const { return this->energyMax; }; 143 inline void setAmmoContainer(const CountPointer<AmmoContainer>& ammoContainer) { this->ammoContainer = ammoContainer;} 141 144 inline float getEnergy() const { return this->energy; }; 142 145 inline float getLoadedEnergy() const { return this->energyLoaded; }; … … 200 203 float energy; //!< The energy stored in the weapons secondary buffers (reserve) 201 204 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. 202 206 float energyMax; //!< The maximal energy that can be stored in the secondary buffers (reserveMax) 203 207 float energyLoadedMax; //!< The maximal energy that can be stored in the primary buffers -
trunk/src/world_entities/weapons/weapon_manager.cc
r6568 r6669 203 203 } 204 204 205 206 bool 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 } 205 213 206 214 /** … … 246 254 //! @todo check if the weapon is already assigned to another config in another slot 247 255 this->configs[configID][slotID] = weapon; 256 weapon->setAmmoContainer(this->getAmmoContainer(weapon->getProjectileType())); 248 257 if (this->parent != NULL) 249 258 { … … 420 429 /** 421 430 * private gets the next free slot in a certain weaponconfig 422 * @param the selected weaponconfig 431 * @param the selected weaponconfig -1 if none found 423 432 */ 424 433 int WeaponManager::getNextFreeSlot(int configID, long capability) … … 434 443 } 435 444 445 CountPointer<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 } 436 455 437 456 -
trunk/src/world_entities/weapons/weapon_manager.h
r6561 r6669 17 17 #include "crosshair.h" 18 18 #include "weapon.h" 19 20 #include "count_pointer.h" 21 #include "ammo_container.h" 19 22 20 23 // FORWARD DECLARATION … … 72 75 73 76 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); 75 78 void removeWeapon(Weapon* weapon, int configID = -1); 79 76 80 Weapon* getWeapon(int slotID) const { return (slotID >= 0 && slotID < this->slotCount)? this->currentSlotConfig[slotID].nextWeapon: NULL; }; 77 81 … … 82 86 void previousWeaponConfig(); 83 87 void changeWeaponConfig(int weaponConfig); 88 89 float addAmmunition(ClassID projectileType, float ammo); 90 84 91 85 92 /** @returns a fixed target namely the Crosshair's 3D position */ … … 97 104 // private: 98 105 int getNextFreeSlot(int configID, long capability = WTYPE_ALL); 106 CountPointer<AmmoContainer>& getAmmoContainer(ClassID projectileType); 99 107 100 108 private: … … 112 120 Crosshair* crosshair; //!< an aim. 113 121 tAnimation<Crosshair>* crossHairSizeAnim; //!< An animation for the crosshair (scaling) 122 123 std::vector<CountPointer<AmmoContainer> > ammo; //!< Containers 114 124 }; 115 125
Note: See TracChangeset
for help on using the changeset viewer.