Changeset 4880 in orxonox.OLD for orxonox/branches/weaponSystem/src
- Timestamp:
- Jul 17, 2005, 2:17:09 AM (19 years ago)
- Location:
- orxonox/branches/weaponSystem/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/weaponSystem/src/lib/sound/sound_engine.cc
r4836 r4880 120 120 alDeleteSources(1, &this->sourceID); 121 121 } 122 123 122 124 123 /** -
orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc
r4878 r4880 91 91 this->animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); 92 92 } 93 93 /* 94 94 this->fireSound = (SoundBuffer*)ResourceManager::getInstance()->load("sound/shot1.wav", WAV); 95 95 this->weaponSource = new SoundSource(this->fireSound, this); 96 this->weaponSource->setRolloffFactor(.1); 96 this->weaponSource->setRolloffFactor(.1);*/ 97 97 Projectile* p = new TestBullet(this); 98 98 // ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p); … … 182 182 void TestGun::destroy () 183 183 {} 184 185 186 /**187 * tick signal for time dependent/driven stuff188 */189 void TestGun::tick (float time)190 {191 this->stateTime += time;192 }193 184 194 185 -
orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.h
r4836 r4880 47 47 virtual void destroy(); 48 48 49 virtual void tick(float time);50 49 virtual void weaponIdle(); 51 50 virtual void draw(); -
orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc
r4879 r4880 13 13 main-programmer: Patrick Boenzli 14 14 co-programmer: Benjamin Grauer 15 16 2005-07-15: Benjamin Grauer: restructurating the entire Class 15 17 */ 16 18 … … 23 25 #include "list.h" 24 26 #include "state.h" 27 #include "animation3d.h" 28 #include "sound_engine.h" 25 29 26 30 /** … … 42 46 Weapon::~Weapon () 43 47 { 44 // model will be deleted from WorldEntity-destructor 45 //this->worldEntities = NULL; 46 47 /* dont delete objectComponentsX here, they will be killed when the pnodes are cleaned out */ 48 49 /* all animations are deleted via the animation player*/ 50 } 51 48 for (int i = 0; i < WS_STATE_COUNT; i++) 49 if (this->animation[i]) 50 delete this->animation[i]; 51 for (int i = 0; i < WA_ACTION_COUNT; i++) 52 if (this->soundBuffers[i]) 53 delete this->soundBuffers[i]; 54 } 55 56 /** 57 * initializes the Weapon with ALL default values 58 */ 52 59 void Weapon::init() 53 60 { 54 61 this->currentState = WS_INACTIVE; 55 this->state Time= 0.0;62 this->stateDuration = 0.0; 56 63 for (int i = 0; i < WS_STATE_COUNT; i++) 57 {58 this->times[i] = 0.0;59 this->animation[i] = NULL;60 }64 { 65 this->times[i] = 0.0; 66 this->animation[i] = NULL; 67 } 61 68 for (int i = 0; i < WA_ACTION_COUNT; i++) 62 69 this->soundBuffers[i] = NULL; 63 70 71 this->requestedAction = WA_NONE; 64 72 this->weaponSource = NULL; 65 this->minCharge ;66 this->maxCharge ;73 this->minCharge = 0.0; 74 this->maxCharge = 0.0; 67 75 68 76 this->active = false; … … 94 102 95 103 104 void Weapon::requestAction(WeaponAction action) 105 { 106 this->requestedAction = action; 107 } 108 109 bool Weapon::execute(WeaponAction action) 110 { 111 this->stateDuration = this->times[action] + this->stateDuration; 112 113 switch (action) 114 { 115 case WA_SHOOT: 116 this->fire(); 117 break; 118 case WA_CHARGE: 119 this->charge(); 120 break; 121 case WA_RELOAD: 122 this->reload(); 123 break; 124 case WA_DEACTIVATE: 125 this->deactivate(); 126 break; 127 case WA_ACTIVATE: 128 this->activate(); 129 break; 130 } 131 } 132 96 133 /** 97 134 * this activates the weapon 98 *99 * This is needed, since there can be more than one weapon on a ship. the100 * activation can be connected with an animation. for example the weapon is101 * been armed out.102 135 */ 103 136 void Weapon::activate() … … 107 140 /** 108 141 * this deactivates the weapon 109 *110 * This is needed, since there can be more than one weapon on a ship. the111 * activation can be connected with an animation. for example the weapon is112 * been armed out.113 142 */ 114 143 void Weapon::deactivate() 115 144 {} 116 145 117 /** 118 * is called, when the weapon gets hit (=collide with something) 119 * @param from which entity it is been hit 120 * @param where it is been hit 121 * 122 * this may not be used, since it would make the game relay complicated when one 123 * can destroy the weapons of enemies or vice versa. 124 */ 125 void Weapon::hit (WorldEntity* entity, const Vector& position) 126 {} 146 void Weapon::fire() 147 { 148 149 } 150 151 void Weapon::reload() 152 { 153 154 } 155 156 void Weapon::charge() 157 { 158 } 127 159 128 160 … … 138 170 139 171 /** 140 * tick signal for time dependent/driven stuff 141 */ 142 void Weapon::tick (float time) 143 {} 172 * tick signal for time dependent/driven stuff 173 */ 174 void Weapon::tick(float dt) 175 { 176 if (this->isActive()) 177 { 178 this->stateDuration -= dt; 179 180 if (this->stateDuration < 0.0) 181 this->execute(this->requestedAction); 182 } 183 else 184 if (this->requestedAction == WA_ACTIVATE) 185 this->activate(); 186 187 } 144 188 145 189 /** … … 153 197 154 198 199 ////////////////////// 200 // HELPER FUNCTIONS // 201 ////////////////////// 202 // inclass 203 /** 204 * checks if the next Action given is valid 205 * @returns if the Action that comes next is valid 206 * @todo more checks 207 */ 208 bool Weapon::nextActionValid() const 209 { 210 if (this->currentState == WS_INACTIVE) 211 { 212 return (this->requestedAction == WA_ACTIVATE || this->requestedAction == WA_NONE); 213 } 214 else 215 return true; 216 217 } 218 219 220 221 // static 155 222 /** 156 223 * Converts a String into an Action. … … 175 242 return WA_SPECIAL1; 176 243 else 177 {178 PRINTF(2)("action %s could not be identified.\n", action);179 return WA_NONE;180 }244 { 245 PRINTF(2)("action %s could not be identified.\n", action); 246 return WA_NONE; 247 } 181 248 } 182 249 … … 192 259 else if (!strcmp(state, "shooting")) 193 260 return WS_SHOOTING; 261 else if (!strcmp(state, "charging")) 262 return WS_CHARGING; 194 263 else if (!strcmp(state, "reloading")) 195 264 return WS_RELOADING; … … 203 272 return WS_IDLE; 204 273 else 205 { 206 PRINTF(2)("state %s could not be identified.\n", state); 207 return WS_NONE; 208 } 209 } 210 274 { 275 PRINTF(2)("state %s could not be identified.\n", state); 276 return WS_NONE; 277 } 278 } -
orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h
r4879 r4880 12 12 weapon in this world: 13 13 o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented 14 o shooting animation14 o animations 15 15 */ 16 16 … … 45 45 WS_NONE = 0, //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable) 46 46 WS_SHOOTING = 1, //!< The State of the Shooting 47 WS_CHARGING = 2, //!< The state of charging th weapon 47 48 WS_RELOADING = 3, //!< The State of the Reloading 48 49 WS_ACTIVATING = 4, //!< The State in which the weapon gets activated … … 68 69 class Weapon : public WorldEntity 69 70 { 70 friend class World; 71 public: 72 // INITIALISATION // 73 Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction); 74 Weapon(const TiXmlElement* root); 75 virtual ~Weapon (); 71 76 72 public: 73 Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction); 74 Weapon(const TiXmlElement* root); 75 virtual ~Weapon (); 77 void init(); 78 void loadParams(const TiXmlElement* root); 79 //////////////////// 76 80 77 void init(); 78 void loadParams(const TiXmlElement* root); 81 void requestAction(WeaponAction action); 79 82 80 void setProjectile(Projectile* projectile);81 Projectile* getProjectile();83 /** @returns true if the Weapon is Active */ 84 inline bool isActive() const { return this->active; }; 82 85 83 virtual void activate(); 84 virtual void deactivate(); 85 virtual void fire() = 0; 86 //virtual void reload(); 87 //virtual void charge(); 88 bool isActive() const { return this->active; }; 86 // FUNCTIONS TO SET THE WEAPONS PROPERTIES. 87 void setProjectile(Projectile* projectile); 88 Projectile* getProjectile(); 89 89 90 // FUNCTIONS TO SET THE WEAPONS PROPERTIES. 91 void setStateDuration(const char* state, float duration); 92 void setStateDuration(WeaponState state, float duration); 93 float getStateDuration(WeaponState state) { return (state < WS_STATE_COUNT)?this->times[state]:0.0; }; 94 /** @return true if idletime is elapsed, false otherwise */ 95 inline bool stateTimeElapsed() const { return (this->stateTime > this->times[currentState])?true:false; }; 90 /** @param state the State to time @param duration the duration of the State */ 91 inline void setStateDuration(const char* state, float duration) { setStateDuration(charToState(state), duration); }; 92 /** @param state the State to time @param duration the duration of the State */ 93 inline void setStateDuration(WeaponState state, float duration) { /*(state < WS_STATE_COUNT)?*/this->times[state] = duration; }; 94 /** @param state The state to query @returns the Time the queried State takes to complete */ 95 inline float getStateDuration(WeaponState state) const { return (state < WS_STATE_COUNT)?this->times[state]:0.0; }; 96 /** @returns true if the time of the currentState is elapsed, false otherwise */ 97 inline bool stateTimeElapsed() const { return (this->stateDuration > this->times[currentState])?true:false; }; 98 /** @returns the current State of the Weapon */ 99 inline WeaponState getCurrentState() const { return this->currentState; }; 96 100 97 /** fires the weapon */98 virtual void hit (WorldEntity* weapon, const Vector& loc);99 virtual void destroy();100 101 101 virtual void tick(float time);102 virtual void draw();103 102 104 private: 103 virtual void destroy(); 104 105 106 107 virtual void tick(float dt); 108 virtual void draw(); 109 110 protected: 105 111 static WeaponAction charToAction(const char* action); 106 112 static WeaponState charToState(const char* state); 107 113 108 114 109 protected: 110 //////////// 111 // PHASES // 112 //////////// 113 WeaponState currentState; //!< The State the weapon is in. 114 WeaponAction requestAction; //!< An action to try to Engage after the currentState ends. 115 float stateTime; //!< how long the state has taken until now. 116 float times[WS_STATE_COUNT]; //!< Times to stay in the different States @see WeaponState. 117 SoundBuffer* soundBuffers[WA_ACTION_COUNT]; //!< SoundBuffers for all actions @see WeaponAction. 118 Animation3D* animation[WS_STATE_COUNT]; //!< Animations for all the States (you can say yourself on what part of the gun this animation acts). 115 bool execute(WeaponAction action); 116 virtual void activate(); 117 virtual void deactivate(); 118 virtual void fire(); 119 virtual void reload(); 120 virtual void charge(); 119 121 120 SoundBuffer* fireSound;121 SoundSource* weaponSource;122 private: 123 bool nextActionValid() const; 122 124 123 float minCharge; 124 float maxCharge; 125 protected: 126 SoundSource* weaponSource; 127 float energy; 128 int energyI; 125 129 126 private: 127 bool active; //!< states wheter the weapon is enabled or not 128 Projectile* projectile; //!< the projectile used for this weapon 129 }; 130 //////////// 131 // PHASES // 132 //////////// 133 WeaponState currentState; //!< The State the weapon is in. 134 WeaponAction requestedAction; //!< An action to try to Engage after the currentState ends. 135 float stateDuration; //!< how long the state has taken until now. 136 float times[WS_STATE_COUNT]; //!< Times to stay in the different States @see WeaponState. 137 SoundBuffer* soundBuffers[WA_ACTION_COUNT]; //!< SoundBuffers for all actions @see WeaponAction. 138 Animation3D* animation[WS_STATE_COUNT]; //!< Animations for all the States (you can say yourself on what part of the gun this animation acts). 139 140 float minCharge; 141 float maxCharge; 142 143 bool hideInactive; //!< Hides the Weapon if it is inactive 144 145 private: 146 bool active; //!< states wheter the weapon is enabled or not 147 Projectile* projectile; //!< the projectile used for this weapon 148 }; 130 149 131 150 #endif /* _WEAPON_H */ -
orxonox/branches/weaponSystem/src/world_entities/weapons/weapon_manager.cc
r4849 r4880 201 201 if( w1 != NULL ) 202 202 { 203 w1-> deactivate();203 w1->requestAction(WA_DEACTIVATE); 204 204 printf("deactivating %i,%i\n", j,lastConfID); 205 205 } 206 206 if( w2 != NULL) 207 207 { 208 w2-> activate();208 w2->requestAction(WA_ACTIVATE); 209 209 printf("activating %i,%i\n", j, this->currConfID); 210 210 } … … 223 223 { 224 224 firingWeapon = this->configs[this->currConfID].slots[i]; 225 if( firingWeapon != NULL) firingWeapon-> fire();225 if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT); 226 226 } 227 227 this->crosshair->setRotationSpeed(500);
Note: See TracChangeset
for help on using the changeset viewer.