Changeset 4880 in orxonox.OLD for orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc
- Timestamp:
- Jul 17, 2005, 2:17:09 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.