- Timestamp:
- Jul 17, 2005, 2:37:41 PM (19 years ago)
- Location:
- orxonox/branches/weaponSystem
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/weaponSystem/orxonox.kdevelop
r4877 r4882 1 <?xml version ="1.0"?>1 <?xml version = '1.0'?> 2 2 <kdevelop> 3 <general>4 <author>orxonox-crew:</author>5 <email>orxonox-dev@mail.datacore.ch</email>6 <version>$VERSION$</version>7 <projectmanagement>KDevCustomProject</projectmanagement>8 <primarylanguage>C++</primarylanguage>9 <ignoreparts>10 </ignoreparts>11 </general>12 <kdevcustomproject>13 <run>14 <mainprogram>orxonox</mainprogram>15 </run>16 </kdevcustomproject>17 <kdevdebugger>18 3 <general> 19 <dbgshell></dbgshell> 4 <author>orxonox-crew:</author> 5 <email>orxonox-dev@mail.datacore.ch</email> 6 <version>$VERSION$</version> 7 <projectmanagement>KDevCustomProject</projectmanagement> 8 <primarylanguage>C++</primarylanguage> 9 <ignoreparts/> 20 10 </general> 21 </kdevdebugger> 22 <kdevdoctreeview> 11 <kdevcustomproject> 12 <run> 13 <mainprogram>orxonox</mainprogram> 14 <directoryradio>executable</directoryradio> 15 </run> 16 </kdevcustomproject> 17 <kdevdebugger> 18 <general> 19 <dbgshell/> 20 </general> 21 </kdevdebugger> 22 <kdevdoctreeview> 23 23 <ignoretocs> 24 24 <toc>ada</toc> … … 65 65 <toc>KDE Libraries (Doxygen)</toc> 66 66 </ignoredoxygen> 67 </kdevdoctreeview>67 </kdevdoctreeview> 68 68 <kdevfilecreate> 69 69 <filetypes/> … … 74 74 </useglobaltypes> 75 75 </kdevfilecreate> 76 <kdevcppsupport> 77 <references/> 78 <codecompletion> 79 <includeGlobalFunctions>true</includeGlobalFunctions> 80 <includeTypes>true</includeTypes> 81 <includeEnums>true</includeEnums> 82 <includeTypedefs>false</includeTypedefs> 83 <automaticCodeCompletion>true</automaticCodeCompletion> 84 <automaticArgumentsHint>true</automaticArgumentsHint> 85 <automaticHeaderCompletion>true</automaticHeaderCompletion> 86 <codeCompletionDelay>250</codeCompletionDelay> 87 <argumentsHintDelay>400</argumentsHintDelay> 88 <headerCompletionDelay>250</headerCompletionDelay> 89 </codecompletion> 90 </kdevcppsupport> 91 <kdevfileview> 92 <groups> 93 <hidenonprojectfiles>false</hidenonprojectfiles> 94 <hidenonlocation>false</hidenonlocation> 95 </groups> 96 <tree> 97 <hidepatterns>*.o,*.lo,*~,*in</hidepatterns> 98 <hidenonprojectfiles>false</hidenonprojectfiles> 99 </tree> 100 </kdevfileview> 76 101 </kdevelop> -
orxonox/branches/weaponSystem/src/orxonox.cc
r4872 r4882 51 51 #include <string.h> 52 52 53 int verbose = 3;53 int verbose = 4; 54 54 55 55 using namespace std; -
orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc
r4881 r4882 100 100 101 101 this->setStateDuration(WS_SHOOTING, 2); 102 103 this->energy = 100; 104 this->minCharge = 2; 102 105 } 103 106 … … 146 149 void TestGun::fire() 147 150 { 151 this->energyLoaded -= this->minCharge; 152 148 153 Projectile* pj = new TestBullet(this);//dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS)); 149 154 // weaponSource->play(); -
orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.h
r4880 r4882 34 34 class TestGun : public Weapon 35 35 { 36 friend class World;37 38 36 public: 39 37 TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight); -
orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc
r4881 r4882 62 62 { 63 63 this->currentState = WS_INACTIVE; 64 this->requestedAction = WA_NONE; 64 65 this->stateDuration = 0.0; 65 66 for (int i = 0; i < WS_STATE_COUNT; i++) … … 73 74 this->requestedAction = WA_NONE; 74 75 this->weaponSource = NULL; 75 this->minCharge = 0.0;76 this->maxCharge = 0.0;77 76 78 77 this->active = true; 79 78 this->projectile = NULL; 79 80 this->minCharge = 1.0; 81 this->maxCharge = 1.0; 82 this->energyLoaded = .0; 83 this->energyLoadedMax = 10.0; 84 this->energy = .0; 85 this->energyMax = 100.0; 80 86 } 81 87 … … 106 112 void Weapon::requestAction(WeaponAction action) 107 113 { 108 printf("next action will be %d\n", action); 109 this->requestedAction = action; 114 if (this->requestedAction != WA_NONE) 115 return; 116 else 117 { 118 printf("next action will be %s in %f seconds\n", actionToChar(action), this->stateDuration); 119 this->requestedAction = action; 120 } 110 121 } 111 122 … … 114 125 this->stateDuration = this->times[this->requestedAction] + this->stateDuration; 115 126 116 PRINT(3)("executing action %d\n", this->requestedAction); 127 PRINTF(4)("trying to execute action %s\n", actionToChar(this->requestedAction)); 128 this->debug(); 117 129 118 130 switch (this->requestedAction) 119 131 { 120 132 case WA_SHOOT: 121 this->fire(); 133 //if (likely(this->currentState != WS_INACTIVE)) 134 { 135 if (this->minCharge < this->energyLoaded) 136 { 137 this->fire(); 138 this->requestedAction = WA_NONE; 139 } 140 else // reload if we still have the charge 141 { 142 this->requestedAction = WA_NONE; 143 this->requestAction(WA_RELOAD); 144 } 145 } 122 146 break; 123 147 case WA_CHARGE: 124 this->charge(); 148 if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge) 149 { 150 this->charge(); 151 this->requestedAction = WA_NONE; 152 } 153 else // deactivate the Weapon if we do not have enough energy 154 { 155 this->requestedAction = WA_NONE; 156 this->requestAction(WA_RELOAD); 157 } 125 158 break; 126 159 case WA_RELOAD: 127 this->reload(); 160 //if (this->currentState != WS_INACTIVE && this->energy + this->energyLoaded >= this->minCharge) 161 { 162 this->reload(); 163 this->requestedAction = WA_NONE; 164 } 128 165 break; 129 166 case WA_DEACTIVATE: 130 this->deactivate(); 167 if (this->currentState != WS_INACTIVE) 168 { 169 this->deactivate(); 170 this->requestedAction = WA_NONE; 171 } 131 172 break; 132 173 case WA_ACTIVATE: 133 this->activate(); 134 break; 135 } 136 this->requestedAction = WA_NONE; 174 if (this->currentState == WS_INACTIVE) 175 { 176 this->activate(); 177 this->requestedAction = WA_NONE; 178 } 179 break; 180 } 137 181 } 138 182 … … 141 185 */ 142 186 void Weapon::activate() 143 {} 187 { 188 PRINTF(4)("Activating the Weapon %s\n", this->getName()); 189 } 144 190 145 191 … … 148 194 */ 149 195 void Weapon::deactivate() 150 {} 196 { 197 PRINTF(4)("Deactivating the Weapon %s\n", this->getName()); 198 } 151 199 152 200 void Weapon::fire() 153 201 { 202 this->energyLoaded -= this->minCharge; 154 203 } 155 204 156 205 void Weapon::reload() 157 206 { 158 207 PRINTF(4)("Reloading Weapon %s\n", this->getName()); 208 if (this->energy + this->energyLoaded < this->minCharge) 209 { 210 this->requestAction(WA_DEACTIVATE); 211 return; 212 } 213 214 float chargeSize = this->energyLoadedMax - this->energyLoaded; //!< The energy to be charged 215 216 if (chargeSize > this->energy) 217 { 218 this->energyLoaded += this->energy; 219 this->energy = 0.0; 220 PRINT(3)("Energy empty"); 221 } 222 else 223 { 224 PRINTF(3)("Loaded %f energy into the Guns Buffer\n", chargeSize); 225 this->energyLoaded += chargeSize; 226 this->energy -= chargeSize; 227 } 159 228 } 160 229 … … 185 254 { 186 255 if (this->stateDuration <= 0.0 && this->requestedAction != WA_NONE) 256 { 257 this->stateDuration = -dt; 187 258 this->execute(); 259 } 188 260 } 189 261 else … … 223 295 } 224 296 297 298 /** 299 * some nice debugging information about this Weapon 300 */ 301 void Weapon::debug() const 302 { 303 PRINT(3)("Weapon-Debug %s, state: %s, nexAction: %s\n", this->getName(), Weapon::stateToChar(this->currentState), Weapon::actionToChar(requestedAction)); 304 PRINT(3)("Energy: max: %f; current: %f; loadedMax: %f; loadedCurrent: %f; chargeMin: %f, chargeMax %f\n", 305 this->energyMax, this->energy, this->energyLoadedMax, this->energyLoaded, this->minCharge, this->maxCharge); 306 } 225 307 226 308 … … 252 334 return WA_NONE; 253 335 } 336 } 337 338 /** 339 * converts an action into a String 340 * @param action the action to convert 341 * @return a String matching the name of the action 342 */ 343 const char* Weapon::actionToChar(WeaponAction action) 344 { 345 switch (action) 346 { 347 case WA_SHOOT: 348 return "shoot"; 349 break; 350 case WA_CHARGE: 351 return "charge"; 352 break; 353 case WA_RELOAD: 354 return "reload"; 355 break; 356 case WA_ACTIVATE: 357 return "activate"; 358 break; 359 case WA_DEACTIVATE: 360 return "deactivate"; 361 break; 362 case WA_SPECIAL1: 363 return "special1"; 364 break; 365 default: 366 return "none"; 367 break; 368 } 254 369 } 255 370 … … 283 398 } 284 399 } 400 401 /** 402 * converts a State into a String 403 * @param state the state to convert 404 * @return a String matching the name of the state 405 */ 406 const char* Weapon::stateToChar(WeaponState state) 407 { 408 switch (state) 409 { 410 case WS_SHOOTING: 411 return "shooting"; 412 break; 413 case WS_CHARGING: 414 return "charging"; 415 break; 416 case WS_RELOADING: 417 return "reloading"; 418 break; 419 case WS_ACTIVATING: 420 return "activating"; 421 break; 422 case WS_DEACTIVATING: 423 return "deactivating"; 424 break; 425 case WS_IDLE: 426 return "idle"; 427 break; 428 default: 429 return "none"; 430 break; 431 } 432 } -
orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.h
r4881 r4882 99 99 inline WeaponState getCurrentState() const { return this->currentState; }; 100 100 101 101 inline void setMaximumEnergy(float energyMax, float energyLoadedMax = 0.0) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; }; 102 102 103 103 virtual void destroy(); 104 104 105 105 106 106 // FLOW 107 107 virtual void tick(float dt); 108 108 virtual void draw(); 109 109 110 void debug() const; 111 110 112 protected: 113 // utility: 111 114 static WeaponAction charToAction(const char* action); 115 static const char* actionToChar(WeaponAction action); 112 116 static WeaponState charToState(const char* state); 117 static const char* stateToChar(WeaponState state); 113 118 114 119 //! ACTION: these functions are handled by the Weapon itself, and must be called by requestAction(WeaponAction); 115 120 bool execute(); 116 121 virtual void activate(); … … 125 130 protected: 126 131 SoundSource* weaponSource; 132 // it is all about energy 127 133 float energy; 128 int energyI; 134 float energyLoaded; 135 float energyMax; 136 float energyLoadedMax; 137 float minCharge; 138 float maxCharge; 129 139 130 140 //////////// … … 138 148 Animation3D* animation[WS_STATE_COUNT]; //!< Animations for all the States (you can say yourself on what part of the gun this animation acts). 139 149 140 float minCharge;141 float maxCharge;142 150 143 151 bool hideInactive; //!< Hides the Weapon if it is inactive
Note: See TracChangeset
for help on using the changeset viewer.