Changeset 4906 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons
- Timestamp:
- Jul 20, 2005, 1:41:19 AM (19 years ago)
- Location:
- orxonox/trunk/src/world_entities/weapons
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world_entities/weapons/test_gun.cc
r4895 r4906 70 70 animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT); 71 71 72 animation2->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0. 1, ANIM_LINEAR, ANIM_CONSTANT);73 animation2->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0. 1, ANIM_LINEAR, ANIM_CONSTANT);74 75 animation3->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0. 1, ANIM_LINEAR, ANIM_CONSTANT);76 animation3->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0. 1, ANIM_LINEAR, ANIM_CONSTANT);72 animation2->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); 73 animation2->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); 74 75 animation3->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); 76 animation3->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); 77 77 } 78 78 else if( this->leftRight == W_RIGHT) … … 100 100 //ObjectManager::getInstance()->debug(); 101 101 102 this->setStateDuration(WS_SHOOTING, . 2);103 this->setStateDuration(WS_RELOADING, .5);102 this->setStateDuration(WS_SHOOTING, .4); 103 this->setStateDuration(WS_RELOADING, 1); 104 104 //this->setStateDuration(WS_ACTIVATING, .4); 105 105 //this->setStateDuration(WS_DEACTIVATING, .4); -
orxonox/trunk/src/world_entities/weapons/weapon.cc
r4895 r4906 81 81 this->emissionPoint.setParent(this); 82 82 83 this->active = true;84 83 this->projectile = NULL; 84 85 this->hideInactive = true; 85 86 86 87 this->minCharge = 1.0; … … 171 172 void Weapon::requestAction(WeaponAction action) 172 173 { 173 if ( this->requestedAction != WA_NONE)174 return;175 else176 {174 if (likely(this->isActive())) 175 { 176 if (this->requestedAction != WA_NONE) 177 return; 177 178 printf("next action will be %s in %f seconds\n", actionToChar(action), this->stateDuration); 178 179 this->requestedAction = action; 180 } 181 //else 182 else if (unlikely(action == WA_ACTIVATE)) 183 { 184 this->currentState = WS_ACTIVATING; 185 this->requestAction(WA_ACTIVATE); 179 186 } 180 187 } … … 215 222 bool Weapon::execute() 216 223 { 217 224 #if DEBUG > 4 218 225 PRINTF(4)("trying to execute action %s\n", actionToChar(this->requestedAction)); 219 226 this->debug(); 227 #endif 220 228 221 229 switch (this->requestedAction) … … 246 254 bool Weapon::activateW() 247 255 { 248 //if (this->currentState == WS_INACTIVE)256 if (this->currentState == WS_INACTIVE) 249 257 { 250 258 // play Sound … … 256 264 PRINTF(4)("Activating the Weapon %s\n", this->getName()); 257 265 this->activate(); 258 this->active = true;259 266 // setting up for next action 267 this->currentState = WS_ACTIVATING; 260 268 this->stateDuration = this->times[WA_ACTIVATE] + this->stateDuration; 261 269 } … … 280 288 // deactivate 281 289 this->deactivate(); 282 this->active = false;283 290 // setting up for next action 291 this->currentState = WS_DEACTIVATING; 284 292 this->stateDuration = this->times[WA_DEACTIVATE] + this->stateDuration; 285 293 } … … 305 313 // setting up for the next state 306 314 this->requestedAction = WA_NONE; 315 this->currentState = WS_CHARGING; 307 316 this->stateDuration = this->times[WA_CHARGE] + this->stateDuration; 308 317 } … … 334 343 // setting up for the next state 335 344 this->stateDuration = this->times[WA_SHOOT] + this->stateDuration; 345 this->currentState = WS_SHOOTING; 336 346 this->requestedAction = WA_NONE; 337 347 } … … 379 389 380 390 this->requestedAction = WA_NONE; 391 this->currentState = WS_RELOADING; 381 392 this->stateDuration = this->times[WA_RELOAD] + this->stateDuration; 382 393 … … 387 398 * tick signal for time dependent/driven stuff 388 399 */ 389 void Weapon::tick (float dt)400 void Weapon::tickW(float dt) 390 401 { 391 402 // setting up the timing properties … … 394 405 if (this->isActive()) 395 406 { 396 if (this->stateDuration <= 0.0 && this->requestedAction != WA_NONE) 397 { 398 this->stateDuration = -dt; 399 this->execute(); 400 } 401 } 402 else 403 if (this->requestedAction == WA_ACTIVATE) 404 this->activate(); 405 407 if (this->stateDuration <= 0.0) 408 { 409 if (unlikely (this->currentState != WS_DEACTIVATING)) 410 this->currentState = WS_IDLE; 411 else 412 this->currentState = WS_INACTIVE; 413 414 if (this->requestedAction != WA_NONE) 415 { 416 this->stateDuration = -dt; 417 this->execute(); 418 } 419 } 420 } 421 tick(dt); 406 422 } 407 423 … … 569 585 return "idle"; 570 586 break; 587 case WS_INACTIVE: 588 return "inactive"; 589 break; 571 590 default: 572 591 return "none"; -
orxonox/trunk/src/world_entities/weapons/weapon.h
r4895 r4906 81 81 float increaseEnergy(float energyToAdd); 82 82 83 /** @returns true if the Weapon is Active */ 84 inline bool isActive() const { return this->active; }; 83 /** @returns true if the Weapon is Active (this is used to check if the weapon must be drawn)*/ 84 inline bool isActive() const { return (this->currentState == WS_INACTIVE)?false:true; }; 85 /** @returns true if the weapon must be drawn */ 86 inline bool isVisible() const { return (this->currentState != WS_INACTIVE || !this->hideInactive)?true:false; }; 85 87 86 88 // FUNCTIONS TO SET THE WEAPONS PROPERTIES. … … 113 115 114 116 Animation3D* getAnimation(WeaponState state, PNode* node = NULL); 117 Animation3D* copyAnimation(WeaponState from, WeaponState to); 115 118 116 119 // FLOW 117 virtual void tick(float dt); 120 void tickW(float dt); //!< this is a function that must be called by the weaponManager, or any other weaponHandler, all other functions are handled from within 121 virtual void tick(float dt) {}; 118 122 virtual void draw(); 119 123 … … 175 179 PNode emissionPoint; //!< The point, where the projectiles are emitted. (this is coppled with the Weapon by default) 176 180 177 bool active; //!< states wheter the weapon is enabled or not178 181 bool hideInactive; //!< Hides the Weapon if it is inactive 179 182 bool chargeable; //!< if the Weapon is charcheable -
orxonox/trunk/src/world_entities/weapons/weapon_manager.cc
r4895 r4906 75 75 this->configs[i].slots[j] = NULL; 76 76 } 77 this->currConfID = W _CONFIG0;77 this->currConfID = WM_CONFIG0; 78 78 79 79 … … 141 141 * 142 142 * if you add explicitly a weapon at config:n, slot:m, the weapon placed at this location will be 143 * replaced by the weapon specified. if you use the W _FREE_SLOT, the manager will look for a free143 * replaced by the weapon specified. if you use the WM_FREE_SLOT, the manager will look for a free 144 144 * slot in this weaponconfiguration. if there is non, the weapon won't be added and there will be 145 145 * a error message. … … 147 147 void WeaponManager::addWeapon(Weapon* weapon, int configID, int slotID) 148 148 { 149 if( slotID == W _FREE_SLOT)149 if( slotID == WM_FREE_SLOT) 150 150 { 151 151 int freeSlot = this->getNextFreeSlot( configID); … … 187 187 lastConfID = this->currConfID; 188 188 for(i = this->currConfID + 1; i < W_MAX_CONFIGS && !this->configs[i].bUsed; ++i); 189 if( i == W_MAX_CONFIGS) this->currConfID = W _CONFIG0;189 if( i == W_MAX_CONFIGS) this->currConfID = WM_CONFIG0; 190 190 else this->currConfID = i; 191 191 … … 241 241 { 242 242 Weapon* w; 243 for (int j = 0; j < 4; ++j)244 for(int i = 0; i < W_MAX_SLOTS; ++i)245 {246 w = this->configs[j].slots[i];247 if( w != NULL) w->tick(dt);243 for(int i = 0; i < W_MAX_SLOTS; ++i) 244 { 245 w = this->configs[this->currConfID].slots[i]; 246 if( w != NULL && w->isActive()) 247 w->tickW(dt); 248 248 } 249 249 … … 262 262 { 263 263 w = this->configs[j].slots[i]; 264 if( w != NULL )264 if( w != NULL && w->isVisible()) 265 265 w->draw(); 266 266 } -
orxonox/trunk/src/world_entities/weapons/weapon_manager.h
r4837 r4906 39 39 40 40 //! this is an identifier for the weapon config 41 #define W_CONFIG0 0 42 #define W_CONFIG1 1 43 #define W_CONFIG2 2 44 #define W_CONFIG3 3 41 typedef enum 42 { 43 WM_CONFIG0 = 0, 44 WM_CONFIG1 = 1, 45 WM_CONFIG2 = 2, 46 WM_CONFIG3 = 3, 45 47 48 WM_CONFIGCOUNT = 4 49 } WM_CONFIG; 46 50 47 51 //! 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 48 #define W_SLOT0 0 49 #define W_SLOT1 1 50 #define W_SLOT2 2 51 #define W_SLOT3 3 52 #define W_SLOT4 4 53 #define W_SLOT5 5 54 #define W_SLOT6 6 55 #define W_SLOT7 7 56 #define W_FREE_SLOT 99 52 typedef enum 53 { 54 WM_SLOT0 = 0, 55 WM_SLOT1 = 1, 56 WM_SLOT2 = 2, 57 WM_SLOT3 = 3, 58 WM_SLOT4 = 4, 59 WM_SLOT5 = 5, 60 WM_SLOT6 = 6, 61 WM_SLOT7 = 7, 57 62 63 WM_SLOT_COUNT = 8, 64 65 WM_FREE_SLOT = -1 66 } WM_SLOT; 58 67 59 68 //! this is a weapon Configuration: it has up to 8 slots … … 77 86 void setSlotCount(int nrOfSlots); 78 87 79 void addWeapon(Weapon* weapon, int configID = W _CONFIG0, int slotID = W_FREE_SLOT);80 void removeWeapon(Weapon* weapon, int configID = W _CONFIG0);88 void addWeapon(Weapon* weapon, int configID = WM_CONFIG0, int slotID = WM_FREE_SLOT); 89 void removeWeapon(Weapon* weapon, int configID = WM_CONFIG0); 81 90 void nextWeaponConf(); 82 91
Note: See TracChangeset
for help on using the changeset viewer.