Changeset 4892 in orxonox.OLD
- Timestamp:
- Jul 19, 2005, 4:59:58 PM (19 years ago)
- Location:
- orxonox/trunk/src/world_entities/weapons
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world_entities/weapons/test_bullet.cc
r4890 r4892 19 19 #include "test_bullet.h" 20 20 21 #include "world_entity.h"22 #include "weapon.h"23 #include "null_parent.h"24 21 #include "model.h" 25 22 #include "vector.h" -
orxonox/trunk/src/world_entities/weapons/test_bullet.h
r4890 r4892 14 14 class TestBullet : public Projectile 15 15 { 16 friend class World;17 18 16 public: 19 17 TestBullet (Weapon* weapon); -
orxonox/trunk/src/world_entities/weapons/weapon.cc
r4891 r4892 30 30 #include "sound_engine.h" 31 31 32 //////////////////// 33 // INITAILISATION // 34 // SETTING VALUES // 35 //////////////////// 32 36 /** 33 37 * standard constructor … … 74 78 this->requestedAction = WA_NONE; 75 79 this->soundSource = new SoundSource(this); 80 this->emissionPoint.setParent(this); 76 81 77 82 this->active = true; … … 86 91 } 87 92 93 94 /** 95 * sets the emissionPoint's relative position from the Weapon 96 * @param point the Point relative to the mass-point of the Weapon 97 */ 98 void Weapon::setEmissionPoint(const Vector& point) 99 { 100 this->emissionPoint.setRelCoor(point); 101 } 88 102 89 103 /** … … 112 126 } 113 127 128 ///////////////// 129 // EXECUTION // 130 // GAME ACTION // 131 ///////////////// 132 114 133 /** 115 134 * request an action that should be executed, … … 152 171 } 153 172 173 ////////////////////// 174 // WEAPON INTERNALS // 175 ////////////////////// 154 176 /** 155 177 * executes an action, and with it starts a new State. … … 169 191 { 170 192 case WA_SHOOT: 171 //if (likely(this->currentState != WS_INACTIVE)) 172 { 173 if (this->minCharge <= this->energyLoaded) 174 { 193 this->fireW(); 194 break; 195 case WA_CHARGE: 196 this->chargeW(); 197 break; 198 case WA_RELOAD: 199 this->reloadW(); 200 break; 201 case WA_DEACTIVATE: 202 this->deactivateW(); 203 break; 204 case WA_ACTIVATE: 205 this->activateW(); 206 break; 207 } 208 } 209 210 211 /** 212 * 213 * @return 214 */ 215 bool Weapon::activateW() 216 { 217 218 if (this->currentState == WS_INACTIVE) 219 { 220 // play Sound 221 if (this->soundBuffers[WA_ACTIVATE] != NULL) 222 this->soundSource->play(this->soundBuffers[WA_ACTIVATE]); 223 // activate 224 PRINTF(5)("Activating the Weapon %s\n", this->getName()); 225 this->activate(); 226 // setting up for next action 227 this->requestedAction = WA_NONE; 228 this->stateDuration = this->times[WA_ACTIVATE] + this->stateDuration; 229 } 230 } 231 232 233 /** 234 * 235 * @return 236 */ 237 bool Weapon::deactivateW() 238 { 239 if (this->currentState != WS_INACTIVE) 240 { 241 PRINTF(4)("Deactivating the Weapon %s\n", this->getName()); 242 // play Sound 243 if (this->soundBuffers[WA_DEACTIVATE] != NULL) 244 this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]); 245 // deactivate 246 this->deactivate(); 247 // setting up for next action 248 this->requestedAction = WA_NONE; 249 this->stateDuration = this->times[WA_DEACTIVATE] + this->stateDuration; 250 } 251 252 } 253 254 /** 255 * 256 * @return 257 */ 258 bool Weapon::chargeW() 259 { 260 if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge) 261 { 262 // playing Sound 263 if (this->soundBuffers[WA_CHARGE] != NULL) 264 this->soundSource->play(this->soundBuffers[WA_CHARGE]); 265 // charge 266 this->charge(); 267 // setting up for the next state 268 this->requestedAction = WA_NONE; 269 this->stateDuration = this->times[WA_CHARGE] + this->stateDuration; 270 } 271 else // deactivate the Weapon if we do not have enough energy 272 { 273 this->requestedAction = WA_NONE; 274 this->requestAction(WA_RELOAD); 275 } 276 277 } 278 279 /** 280 * 281 * @return 282 */ 283 bool Weapon::fireW() 284 { 285 //if (likely(this->currentState != WS_INACTIVE)) 286 if (this->minCharge <= this->energyLoaded) 287 { 175 288 // playing Sound 176 177 289 if (this->soundBuffers[WA_SHOOT] != NULL) 290 this->soundSource->play(this->soundBuffers[WA_SHOOT]); 178 291 // fire 179 this->fire(); 292 this->fire(); 293 this->energyLoaded -= this->minCharge; 180 294 // setting up for the next state 181 this->stateDuration = this->times[WA_SHOOT] + this->stateDuration; 182 this->requestedAction = WA_NONE; 183 } 184 else // reload if we still have the charge 185 { 186 this->requestedAction = WA_NONE; 187 this->requestAction(WA_RELOAD); 188 } 189 } 190 break; 191 case WA_CHARGE: 192 if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge) 193 { 194 // playing Sound 195 if (this->soundBuffers[WA_CHARGE] != NULL) 196 this->soundSource->play(this->soundBuffers[WA_CHARGE]); 197 // charge 198 this->charge(); 199 // setting up for the next state 200 this->requestedAction = WA_NONE; 201 this->stateDuration = this->times[WA_CHARGE] + this->stateDuration; 202 } 203 else // deactivate the Weapon if we do not have enough energy 204 { 205 this->requestedAction = WA_NONE; 206 this->requestAction(WA_RELOAD); 207 } 208 break; 209 case WA_RELOAD: 210 //if (this->currentState != WS_INACTIVE && this->energy + this->energyLoaded >= this->minCharge) 211 { 212 // playing Sound 213 if (this->soundBuffers[WA_RELOAD] != NULL) 214 this->soundSource->play(this->soundBuffers[WA_RELOAD]); 215 // reload 216 this->reload(); 217 // setting up for next action 218 this->requestedAction = WA_NONE; 219 this->stateDuration = this->times[WA_RELOAD] + this->stateDuration; 220 } 221 break; 222 case WA_DEACTIVATE: 223 if (this->currentState != WS_INACTIVE) 224 { 225 // play Sound 226 if (this->soundBuffers[WA_DEACTIVATE] != NULL) 227 this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]); 228 // deactivate 229 this->deactivate(); 230 // setting up for next action 231 this->requestedAction = WA_NONE; 232 this->stateDuration = this->times[WA_DEACTIVATE] + this->stateDuration; 233 } 234 break; 235 case WA_ACTIVATE: 236 if (this->currentState == WS_INACTIVE) 237 { 238 // play Sound 239 if (this->soundBuffers[WA_ACTIVATE] != NULL) 240 this->soundSource->play(this->soundBuffers[WA_ACTIVATE]); 241 // activate 242 this->activate(); 243 // setting up for next action 244 this->requestedAction = WA_NONE; 245 this->stateDuration = this->times[WA_ACTIVATE] + this->stateDuration; 246 } 247 break; 248 } 249 } 250 251 /** 252 * this activates the weapon 253 */ 254 void Weapon::activate() 255 { 256 PRINTF(4)("Activating the Weapon %s\n", this->getName()); 257 258 if (this->soundBuffers[WA_ACTIVATE] != NULL) 259 this->soundSource->play(this->soundBuffers[WA_ACTIVATE]); 260 } 261 262 263 /** 264 * this deactivates the weapon 265 */ 266 void Weapon::deactivate() 267 { 268 PRINTF(4)("Deactivating the Weapon %s\n", this->getName()); 269 270 if (this->soundBuffers[WA_DEACTIVATE] != NULL) 271 this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]); 272 } 273 274 void Weapon::fire() 275 { 276 this->energyLoaded -= this->minCharge; 277 278 if (this->soundBuffers[WA_SHOOT] != NULL) 279 this->soundSource->play(this->soundBuffers[WA_SHOOT]); 280 } 281 282 void Weapon::reload() 295 this->stateDuration = this->times[WA_SHOOT] + this->stateDuration; 296 this->requestedAction = WA_NONE; 297 } 298 else // reload if we still have the charge 299 { 300 this->requestedAction = WA_NONE; 301 this->requestAction(WA_RELOAD); 302 } 303 } 304 305 306 /** 307 * 308 * @return 309 */ 310 bool Weapon::reloadW() 283 311 { 284 312 PRINTF(4)("Reloading Weapon %s\n", this->getName()); 285 if ( this->energy + this->energyLoaded < this->minCharge)313 if (unlikely(this->energy + this->energyLoaded < this->minCharge)) 286 314 { 287 315 this->requestAction(WA_DEACTIVATE); 288 return ;316 return false; 289 317 } 290 318 291 319 float chargeSize = this->energyLoadedMax - this->energyLoaded; //!< The energy to be charged 320 321 if (this->soundBuffers[WA_RELOAD] != NULL) 322 this->soundSource->play(this->soundBuffers[WA_RELOAD]); 292 323 293 324 if (chargeSize > this->energy) … … 303 334 this->energy -= chargeSize; 304 335 } 305 if (this->soundBuffers[WA_RELOAD] != NULL) 306 this->soundSource->play(this->soundBuffers[WA_RELOAD]); 307 308 } 309 310 void Weapon::charge() 311 { 312 if (this->soundBuffers[WA_CHARGE] != NULL) 313 this->soundSource->play(this->soundBuffers[WA_CHARGE]); 314 315 } 316 317 318 /** 319 * is called, when the weapon is destroyed 320 * 321 * this is in conjunction with the hit function, so when a weapon is able to get 322 * hit, it can also be destoryed. 323 */ 324 void Weapon::destroy () 325 {} 336 this->reload(); 337 338 this->requestedAction = WA_NONE; 339 this->stateDuration = this->times[WA_RELOAD] + this->stateDuration; 340 341 } 326 342 327 343 -
orxonox/trunk/src/world_entities/weapons/weapon.h
r4891 r4892 19 19 #define _WEAPON_H 20 20 21 #include "base_object.h"22 21 #include "world_entity.h" 23 22 … … 91 90 Projectile* getProjectile() { return this->projectile; }; 92 91 92 void setEmissionPoint(const Vector& point); 93 /** @see void setEmissionPoint(const Vector& point); */ 94 inline void setEmissionPoint(float x, float y, float z) { this->setEmissionPoint(Vector(x,y,z)); }; 95 93 96 /** @param state the State to time @param duration the duration of the State */ 94 97 inline void setStateDuration(const char* state, float duration) { setStateDuration(charToState(state), duration); }; … … 101 104 /** @returns the current State of the Weapon */ 102 105 inline WeaponState getCurrentState() const { return this->currentState; }; 106 103 107 /** @param energyMax the maximum energy the Weapon can have @param energyLoadedMax the maximum energy in the weapon buffers */ 104 108 inline void setMaximumEnergy(float energyMax, float energyLoadedMax = 0.0) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; }; … … 108 112 void setActionSound(const char* action, const char* soundFile) { this->setActionSound(charToAction(action), soundFile); }; 109 113 110 virtual void destroy();111 114 112 115 … … 120 123 protected: 121 124 //! ACTION: these functions are handled by the Weapon itself, and must be called by requestAction(WeaponAction); 122 bool execute();123 virtual void activate();124 virtual void deactivate();125 virtual void fire() ;126 virtual void reload() ;127 virtual void charge();125 virtual void activate() {}; 126 virtual void deactivate() {}; 127 virtual void charge() {}; 128 virtual void fire() {}; 129 virtual void reload() {}; 130 virtual void destroy() {}; 128 131 129 132 … … 136 139 137 140 private: 141 /** executive functions, that handle timing with actions. 142 * This is for the action-functions in derived functions to be easy 143 * The main function is execute, that calls all the other functions 144 * for being fast, the Functions are private and as such will be inlined 145 * into the execute function. (this is work of the compiler) 146 */ 147 bool execute(); 148 bool activateW(); 149 bool deactivateW(); 150 bool chargeW(); 151 bool fireW(); 152 bool reloadW(); 153 138 154 bool nextActionValid() const; 139 155 … … 161 177 SoundBuffer* soundBuffers[WA_ACTION_COUNT]; //!< SoundBuffers for all actions @see WeaponAction. 162 178 179 PNode emissionPoint; //!< The point, where the projectiles are emitted. (this is coppled with the Weapon by default) 163 180 164 181 bool active; //!< states wheter the weapon is enabled or not
Note: See TracChangeset
for help on using the changeset viewer.