Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/weapons/weapon.cc @ 10771

Last change on this file since 10771 was 10771, checked in by nicolasc, 17 years ago

huge diff
cleaned the individual weapons, moved stuff to weapon.{cc,h}
and some minor fixes which popped up then and when

File size: 21.9 KB
Line 
1
2/*
3   orxonox - the future of 3D-vertical-scrollers
4
5   Copyright (C) 2004 orx
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12### File Specific
13   main-programmer: Patrick Boenzli
14   co-programmer: Benjamin Grauer
15
16   2005-07-15: Benjamin Grauer: restructurating the entire Class
17*/
18
19#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
20
21#include "weapon.h"
22
23#include "loading/fast_factory.h"
24#include "world_entities/projectiles/projectile.h"
25
26#include "util/loading/factory.h"
27#include "util/loading/load_param.h"
28#include "state.h"
29#include "animation3d.h"
30
31#include "sound_source.h"
32#include "sound_buffer.h"
33#include "resource_sound_buffer.h"
34
35#include "elements/glgui_energywidgetvertical.h"
36
37ObjectListDefinition(Weapon);
38
39////////////////////
40// INITAILISATION //
41// SETTING VALUES //
42////////////////////
43/**
44 * standard constructor
45 *
46 * creates a new weapon
47*/
48Weapon::Weapon ()
49{
50  this->init();
51}
52
53/**
54 * standard deconstructor
55*/
56Weapon::~Weapon ()
57{
58  for (int i = 0; i < WS_STATE_COUNT; i++)
59    if (this->animation[i] && Animation::objectList().exists(animation[i]))  //!< @todo this should check animation3D
60      delete this->animation[i];
61
62  if (OrxSound::SoundSource::objectList().exists(this->soundSource))
63    delete this->soundSource;
64
65//   for (int i = 0; i < MAX_BARRELS; i++)
66//   {
67//    delete [] this->shootAnim[i];
68//    delete [] this->objComp[i];
69//   }
70//   delete [] this->emissionPoint;
71//   delete [] this->shootAnim;
72//   delete [] this->objComp;
73
74}
75
76/**
77 * @brief creates a new Weapon of type weaponID and returns it.
78 * @param weaponID the WeaponID type to create.
79 * @returns the newly created Weapon.
80 */
81Weapon* Weapon::createWeapon(const ClassID& weaponID)
82{
83  BaseObject* createdObject = Factory::fabricate(weaponID);
84  if (createdObject != NULL)
85  {
86    if (createdObject->isA(Weapon::staticClassID()))
87      return dynamic_cast<Weapon*>(createdObject);
88    else
89    {
90      delete createdObject;
91      return NULL;
92    }
93  }
94  return NULL;
95}
96
97Weapon* Weapon::createWeapon(const std::string& weaponName)
98{
99  BaseObject* createdObject = Factory::fabricate(weaponName);
100  if (createdObject != NULL)
101  {
102    if (createdObject->isA(Weapon::staticClassID()))
103      return dynamic_cast<Weapon*>(createdObject);
104    else
105    {
106      delete createdObject;
107      return NULL;
108    }
109  }
110  return NULL;
111}
112
113
114/**
115 * initializes the Weapon with ALL default values
116 *
117 * This Sets the default values of the Weapon
118 */
119void Weapon::init()
120{
121  this->registerObject(this, Weapon::_objectList);
122  this->currentState     = WS_INACTIVE;            //< Normaly the Weapon is Inactive
123  this->requestedAction  = WA_NONE;                //< No action is requested by default
124  this->stateDuration    = 0.0;                    //< All the States have zero duration
125  for (int i = 0; i < WS_STATE_COUNT; i++)         //< Every State has:
126  {
127    this->times[i] = 0.0;                        //< An infinitesimal duration
128    this->animation[i] = NULL;                   //< No animation
129  }
130
131  this->soundSource = new OrxSound::SoundSource(this);       //< Every Weapon has exacty one SoundSource
132
133  this->barrels = 1;  // just to have an initial value
134  this->segs = 1;
135  this->activeBarrel = 0;
136
137  this->preferedSide = -1;
138  this->preferedSlot = -1;
139  this->side = -1;
140
141  //!< forward initialisation of animation and emissionpoints
142  for (int i = 0; i < MAX_BARRELS; i++){
143    this->emissionPoint[i] = new PNode;
144    this->emissionPoint[i]->setParent(this);  //Parenting emissionPoint to Weapons
145    this->emissionPoint[i]->setName("EmissionPoint");
146    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
147    for(int j = 0; j < MAX_SEGMENTS; j++)
148    {
149      this->objComp[i][j] = new PNode;
150      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
151      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
152    }
153  }
154
155  this->defaultTarget = NULL;                      //< Nothing is Targeted by default.
156
157  this->projectile = NullClass::staticClassID();         //< No Projectile Class is Connected to this weapon
158  this->projectileFactory = NULL;                  //< No Factory generating Projectiles is selected.
159
160  this->hideInactive = true;                       //< The Weapon will be hidden if it is inactive (by default)
161
162  this->minCharge = 1.0;                           //< The minimum charge the Weapon can hold is 1 unit.
163  this->maxCharge = 1.0;                           //< The maximum charge is also one unit.
164
165  this->energy = 10.0;                               //< The secondary Buffer (before we have to reload)
166  this->energyMax = 10.0;                          //< How much energy can be carried
167  this->capability = WTYPE_ALL;                    //< The Weapon has all capabilities @see W_Capability.
168
169  this->energyWidget = NULL;
170  isEnergyWidgetInitialized = false;
171
172  // set this object to be synchronized over network
173  //this->setSynchronized(true);
174}
175
176/**
177 * loads the Parameters of a Weapon
178 * @param root the XML-Element to load the Weapons settings from
179 */
180void Weapon::loadParams(const TiXmlElement* root)
181{
182  WorldEntity::loadParams(root);
183
184  LoadParam(root, "projectile", this, Weapon, setProjectileTypeC)
185  .describe("Sets the name of the Projectile to load onto the Entity");
186
187  LoadParam(root, "energy", this, Weapon, setEnergyMax)
188  .describe("number of shoots/ energy whatever");
189
190  LoadParam(root, "slot", this, Weapon, setPreferedSlot)
191  .describe("slot this weapon will be added");
192
193  LoadParam(root, "state-duration", this, Weapon, setStateDuration)
194  .describe("Sets the duration of a given state (1: state-Name; 2: duration in seconds)");
195
196  LoadParam(root, "action-sound", this, Weapon, setActionSound)
197  .describe("Sets a given sound to an action (1: action-Name; 2: name of the sound (relative to the Data-Path))");
198}
199
200
201/**
202 * sets the Projectile to use for this weapon.
203 * @param projectile The ID of the Projectile to use
204 * @returns true, if it was sucessfull, false on error
205 *
206 * be aware, that this function does not create Factories, as this is job of Projecitle/Bullet-classes.
207 * What it does, is telling the Weapon what Projectiles it can Emit.
208 */
209void Weapon::setProjectileType(const ClassID& projectile)
210{
211  this->projectile = projectile;
212  this->projectileFactory = FastFactory::searchFastFactory(projectile);
213  if (this->projectileFactory == NULL)
214  {
215    PRINTF(1)("unable to find FastFactory for the Projectile.\n");
216    return;
217  }
218  else
219  {
220    // grabbing Parameters from the Projectile to have them at hand here.
221    Projectile* pj = dynamic_cast<Projectile*>(this->projectileFactory->resurrect());
222    this->minCharge = pj->getMinEnergy();
223    this->maxCharge = pj->getHealthMax();
224    this->chargeable = pj->isChageable();
225    this->projectileFactory->kill(pj);
226  }
227}
228
229
230/**
231 * @see bool Weapon::setProjectile(ClassID projectile)
232 * @param projectile the Name of the Projectile.
233 */
234void Weapon::setProjectileTypeC(const std::string& projectile)
235{
236  FastFactory* tmpFac = FastFactory::searchFastFactory(projectile);
237  if (tmpFac != NULL)
238  {
239    this->setProjectileType(tmpFac->getStoredID());
240  }
241  else
242  {
243    PRINTF(1)("Projectile %s does not exist for weapon %s\n", projectile.c_str(), this->getCName());
244  }
245}
246
247
248/**
249 * prepares Projectiles of the Weapon
250 * @param count how many Projectiles to create (they will be stored in the ProjectileFactory)
251 */
252void Weapon::prepareProjectiles(unsigned int count)
253{
254  if (likely(this->projectileFactory != NULL))
255    projectileFactory->prepare(count);
256  else
257    PRINTF(2)("unable to create %d projectile for Weapon %s::%s\n", count, this->getClassCName(), this->getCName());
258}
259
260
261/**
262 * resurects and returns a Projectile
263 * @returns a Projectile on success, NULL on error
264 *
265 * errors: 1. (ProjectileFastFactory not Found)
266 *         2. No more Projectiles availiable.
267 */
268Projectile* Weapon::getProjectile()
269{
270  if (likely (this->projectileFactory != NULL))
271  {
272    Projectile* pj = dynamic_cast<Projectile*>(this->projectileFactory->resurrect());
273    pj->toList((OM_LIST)(this->getOMListNumber()+1));
274    return pj;
275  }
276  else
277  {
278    PRINTF(2)("No projectile defined for Weapon %s(%s) can't return any\n", this->getCName(), this->getClassCName());
279    return NULL;
280  }
281}
282
283
284/**
285 * sets the emissionPoint's relative position from the Weapon
286 * @param point the Point relative to the mass-point of the Weapon
287 * @param barrel (optional) define a specific barrel, default = 0
288 */
289void Weapon::setEmissionPoint(const Vector& point, int barrel)
290{
291  this->emissionPoint[barrel]->setRelCoor(point);
292}
293
294// void Weapon::setEmissionPoint(const Vector& point)
295// {
296//   this->emissionPoint[0]->setRelCoor(point);
297// }
298
299/**
300 * assigns a Sound-file to an action
301 * @param action the action the sound should be assigned too
302 * @param soundFile the soundFile's relative position to the data-directory (will be looked for by the ResourceManager)
303 */
304void Weapon::setActionSound(WeaponAction action, const std::string& soundFile)
305{
306  if (action >= WA_ACTION_COUNT)
307    return;
308
309  else if (!soundFile.empty())
310  {
311    this->soundBuffers[action] = OrxSound::ResourceSoundBuffer(soundFile);
312    if (this->soundBuffers[action].loaded())
313    {
314      PRINTF(4)("Loaded sound %s to action %s.\n", soundFile.c_str(), actionToChar(action));
315    }
316    else
317    {
318      PRINTF(2)("Failed to load sound %s to %s.\n.", soundFile.c_str(), actionToChar(action));
319    }
320  }
321  else
322    this->soundBuffers[action] = OrxSound::SoundBuffer();
323}
324
325
326/**
327 * creates/returns an Animation3D for a certain State.
328 * @param state what State should the Animation be created/returned for
329 * @param node the node this Animation should apply to. (NULL is fine if the animation was already created)
330 * @returns The created animation.Animation(), NULL on error (or if the animation does not yet exist).
331 *
332 * This function does only generate the Animation Object, and if set it will
333 * automatically be executed, when a certain State is reached.
334 * What this does not do, is set keyframes, you have to operate on the returned animation.
335 */
336Animation3D* Weapon::getAnimation(WeaponState state, PNode* node)
337{
338  if (state >= WS_STATE_COUNT) // if the state is not known
339    return NULL;
340
341  if (unlikely(this->animation[state] == NULL)) // if the animation does not exist yet create it.
342  {
343    if (likely(node != NULL))
344      return this->animation[state] = new Animation3D(node);
345    else
346    {
347      PRINTF(2)("Node not defined for the Creation of the 3D-animation of state %s\n", stateToChar(state));
348      return NULL;
349    }
350  }
351  else
352    return this->animation[state];
353}
354
355Animation3D* Weapon::getAnimation(int barrel, int seg, PNode* node)
356{
357  if (barrel >= this->getBarrels() || seg >= this->getSegs()) // if the state is not known
358    return NULL;
359
360  if (unlikely(this->shootAnim[barrel][seg] == NULL)) // if the animation does not exist yet create it.
361  {
362    if (likely(node != NULL))
363      return this->shootAnim[barrel][seg] = new Animation3D(node);
364    else
365    {
366//       PRINTF(2)("Node not defined for the Creation of the 3D-animation of state %s\n", stateToChar(state));
367      return NULL;
368    }
369  }
370  else
371    return this->shootAnim[barrel][seg];
372}
373
374OrxGui::GLGuiWidget* Weapon::getEnergyWidget()
375{
376  if ( this->energyWidget == NULL)
377  {
378    this->energyWidget = new OrxGui::GLGuiEnergyWidgetVertical();
379    //this->energyWidget->setDisplayedName(this->getClassCName());
380    this->energyWidget->setSize2D( 20, 100);
381    this->energyWidget->setMaximum(this->getEnergyMax());
382    this->energyWidget->setValue(this->getEnergy());
383  }
384  return this->energyWidget;
385}
386
387void Weapon::updateWidgets()
388{
389  if (this->energyWidget != NULL)
390  {
391    this->energyWidget->setMaximum(this->energyMax);
392    this->energyWidget->setValue(this->energy);
393  }
394}
395
396/////////////////
397//  EXECUTION  //
398// GAME ACTION //
399/////////////////
400/**
401 * request an action that should be executed,
402 * @param action the next action to take
403 *
404 * This function must be called instead of the actions (like fire/reload...)
405 * to make all the checks needed to have a usefull WeaponSystem.
406 */
407void Weapon::requestAction(WeaponAction action)
408{
409  if (likely(this->isActive()))
410  {
411    /** Disabled for releaseFire() from WM*/
412    if (this->requestedAction != WA_NONE)
413      return;
414    PRINTF(5)("%s: next action will be %s in %f seconds\n", this->getCName(), actionToChar(action), this->stateDuration);
415    this->requestedAction = action;
416  }
417  //else
418  else if (unlikely(action == WA_ACTIVATE))
419  {
420    this->currentState = WS_ACTIVATING;
421    this->requestedAction = WA_ACTIVATE;
422  }
423}
424
425
426/**
427 * adds energy to the Weapon
428 * @param energyToAdd The amount of energy
429 * @returns the amount of energy we did not pick up, because the weapon is already full
430 */
431float Weapon::increaseEnergy(float energyToAdd)
432{
433  float maxAddEnergy = this->energyMax - this->energy;
434
435  if (maxAddEnergy >= energyToAdd)
436  {
437    this->energy += energyToAdd;
438    this->updateWidgets();
439    return 0.0;
440  }
441  else
442  {
443    this->energy += maxAddEnergy;
444    this->updateWidgets();
445    return energyToAdd - maxAddEnergy;
446  }
447
448}
449
450
451////////////////////////////////////////////////////////////
452// WEAPON INTERNALS                                       //
453// These are functions, that no other Weapon should over- //
454// write. No class has direct Access to them, as it is    //
455// quite a complicated process, handling a Weapon from    //
456// the outside                                            //
457////////////////////////////////////////////////////////////
458/**
459 * executes an action, and with it starts a new State.
460 * @return true, if it worked, false otherwise
461 *
462 * This function checks, wheter the possibility of executing an action is valid,
463 * and does all the necessary stuff, to execute them. If an action does not succeed,
464 * it tries to go around it. (ex. shoot->noAmo->reload()->wait until shoot comes again)
465 */
466bool Weapon::execute()
467{
468#if DEBUG_LEVEL > 4
469  PRINTF(4)("trying to execute action %s\n", actionToChar(this->requestedAction));
470  this->debug();
471#endif
472
473  WeaponAction action = this->requestedAction;
474  this->requestedAction = WA_NONE;
475
476  switch (action)
477  {
478    case WA_SHOOT:
479    return this->fireW();
480    break;
481    case WA_CHARGE:
482    return this->chargeW();
483    break;
484    case WA_RELOAD:
485    return this->reloadW();
486    break;
487    case WA_DEACTIVATE:
488    return this->deactivateW();
489    break;
490    case WA_ACTIVATE:
491    return this->activateW();
492    break;
493    default:
494    PRINTF(5)("Action %s Not Implemented yet \n", Weapon::actionToChar(action));
495    return false;
496  }
497}
498
499/**
500 * checks and activates the Weapon.
501 * @return true on success.
502 */
503bool Weapon::activateW()
504{
505  //  if (this->currentState == WS_INACTIVE)
506  {
507    // play Sound
508    if (likely(this->soundBuffers[WA_ACTIVATE].loaded()))
509      this->soundSource->play(this->soundBuffers[WA_ACTIVATE]);
510    this->updateWidgets();
511    // activate
512    PRINTF(4)("Activating the Weapon %s\n", this->getCName());
513    this->activate();
514    // setting up for next action
515    this->enterState(WS_ACTIVATING);
516  }
517  return true;
518}
519
520/**
521 * checks and deactivates the Weapon
522 * @return true on success.
523 */
524bool Weapon::deactivateW()
525{
526  //  if (this->currentState != WS_INACTIVE)
527  {
528    PRINTF(4)("Deactivating the Weapon %s\n", this->getCName());
529    // play Sound
530    if (this->soundBuffers[WA_DEACTIVATE].loaded())
531      this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]);
532    // deactivate
533    this->deactivate();
534    this->enterState(WS_DEACTIVATING);
535  }
536
537  return true;
538}
539
540/**
541 * checks and charges the Weapon
542 * @return true on success.
543 */
544bool Weapon::chargeW()
545{
546  if ( this->currentState != WS_INACTIVE && this->energy >= this->minCharge)
547  {
548    // playing Sound
549    if (this->soundBuffers[WA_CHARGE].loaded())
550      this->soundSource->play(this->soundBuffers[WA_CHARGE]);
551
552    // charge
553    this->charge();
554    // setting up for the next state
555    this->enterState(WS_CHARGING);
556  }
557  else // deactivate the Weapon if we do not have enough energy
558  {
559    this->requestAction(WA_RELOAD);
560  }
561  return true;
562}
563
564/**
565 * checks and fires the Weapon
566 * @return true on success.
567 */
568bool Weapon::fireW()
569{
570//   printf("fireW Weapon\n");
571  //if (likely(this->currentState != WS_INACTIVE))
572  if (this->minCharge <= this->energy)
573  {
574    // playing Sound
575    if (this->soundBuffers[WA_SHOOT].loaded())
576      this->soundSource->play(this->soundBuffers[WA_SHOOT]);
577    // fire
578    this->energy -= this->minCharge;
579    this->fire();
580    // setting up for the next state
581    this->enterState(WS_SHOOTING);
582    this->updateWidgets();
583  }
584  else  // reload if we still have the charge
585  {
586    this->requestAction(WA_RELOAD);
587    this->execute();
588  }
589  return true;
590}
591
592/**
593 * checks and Reloads the Weapon
594 * @return true on success.
595 */
596bool Weapon::reloadW()
597{
598  PRINTF(4)("Reloading Weapon %s\n", this->getCName());
599  if (!this->ammoContainer.isNull() &&
600      unlikely(this->energy + this->ammoContainer->getStoredEnergy() < this->minCharge))
601  {
602    //this->requestAction(WA_DEACTIVATE);
603    this->execute();
604    return false;
605  }
606
607
608  if (this->soundBuffers[WA_RELOAD].loaded())
609    this->soundSource->play(this->soundBuffers[WA_RELOAD]);
610
611  if (!this->ammoContainer.isNull())
612    this->ammoContainer->fillWeapon(this);
613  else
614  {
615    this->energy = this->energyMax;
616  }
617  this->updateWidgets();
618  this->reload();
619  this->enterState(WS_RELOADING);
620
621  return true;
622}
623
624/**
625 * enters the requested State, plays back animations updates the timing.
626 * @param state the state to enter.
627 */
628inline void Weapon::enterState(WeaponState state)
629{
630  PRINTF(4)("ENTERING STATE %s\n", stateToChar(state));
631  // playing animation if availiable
632  if (likely(this->animation[state] != NULL))
633    this->animation[state]->replay();
634
635  this->stateDuration += this->times[state];
636  this->currentState = state;
637}
638
639///////////////////
640//  WORLD-ENTITY //
641// FUNCTIONALITY //
642///////////////////
643/**
644 * tick signal for time dependent/driven stuff
645*/
646bool Weapon::tickW(float dt)
647{
648  //printf("%s ", stateToChar(this->currentState));
649
650  // setting up the timing properties
651  this->stateDuration -= dt;
652
653  if (this->stateDuration <= 0.0)
654  {
655    if (unlikely (this->currentState == WS_DEACTIVATING))
656    {
657      this->currentState = WS_INACTIVE;
658      return false;
659    }
660    else
661      this->currentState = WS_IDLE;
662
663    if (this->requestedAction != WA_NONE)
664    {
665      this->stateDuration = -dt;
666      this->execute();
667    }
668  }
669  return true;
670}
671
672
673
674
675//////////////////////
676// HELPER FUNCTIONS //
677//////////////////////
678/**
679 * checks wether all the Weapons functions are valid, and if it is possible to go to action with it.
680 * @todo IMPLEMENT the Weapons Check
681 */
682bool Weapon::check() const
683{
684  bool retVal = true;
685
686  //  if (this->projectile == NULL)
687  {
688    PRINTF(1)("There was no projectile assigned to the Weapon.\n");
689    retVal = false;
690  }
691
692
693
694
695  return retVal;
696}
697
698/**
699 * some nice debugging information about this Weapon
700 */
701void Weapon::debug() const
702{
703  PRINT(0)("Weapon-Debug %s, state: %s (duration: %fs), nextAction: %s\n", this->getCName(), Weapon::stateToChar(this->currentState), this->stateDuration, Weapon::actionToChar(requestedAction));
704  PRINT(0)("Energy: max: %f; current: %f; chargeMin: %f, chargeMax %f\n",
705           this->energyMax, this->energy, this->minCharge, this->maxCharge);
706
707
708}
709
710////////////////////////////////////////////////////////
711// static Definitions (transormators for readability) //
712////////////////////////////////////////////////////////
713/**
714 * Converts a String into an Action.
715 * @param action the String input holding the Action.
716 * @return The Action if known, WA_NONE otherwise.
717 */
718WeaponAction Weapon::charToAction(const std::string& action)
719{
720  if (action == "none")
721    return WA_NONE;
722  else if (action == "shoot")
723    return WA_SHOOT;
724  else if (action == "charge")
725    return WA_CHARGE;
726  else if (action == "reload")
727    return WA_RELOAD;
728  else if (action == "acitvate")
729    return WA_ACTIVATE;
730  else if (action == "deactivate")
731    return WA_DEACTIVATE;
732  else if (action == "special1")
733    return WA_SPECIAL1;
734  else
735  {
736    PRINTF(2)("action %s could not be identified.\n", action.c_str());
737    return WA_NONE;
738  }
739}
740
741/**
742 * converts an action into a String
743 * @param action the action to convert
744 * @return a String matching the name of the action
745 */
746const char* Weapon::actionToChar(WeaponAction action)
747{
748  switch (action)
749  {
750    case WA_SHOOT:
751    return "shoot";
752    break;
753    case WA_CHARGE:
754    return "charge";
755    break;
756    case WA_RELOAD:
757    return "reload";
758    break;
759    case WA_ACTIVATE:
760    return "activate";
761    break;
762    case WA_DEACTIVATE:
763    return "deactivate";
764    break;
765    case WA_SPECIAL1:
766    return "special1";
767    break;
768    default:
769    return "none";
770    break;
771  }
772}
773
774/**
775 * Converts a String into a State.
776 * @param state the String input holding the State.
777 * @return The State if known, WS_NONE otherwise.
778 */
779WeaponState Weapon::charToState(const std::string& state)
780{
781  if (state == "none")
782    return WS_NONE;
783  else if (state == "shooting")
784    return WS_SHOOTING;
785  else if (state == "charging")
786    return WS_CHARGING;
787  else if (state == "reloading")
788    return WS_RELOADING;
789  else if (state == "activating")
790    return WS_ACTIVATING;
791  else if (state == "deactivating")
792    return WS_DEACTIVATING;
793  else if (state == "inactive")
794    return WS_INACTIVE;
795  else if (state == "idle")
796    return WS_IDLE;
797  else
798  {
799    PRINTF(2)("state %s could not be identified.\n", state.c_str());
800    return WS_NONE;
801  }
802}
803
804/**
805 * converts a State into a String
806 * @param state the state to convert
807 * @return a String matching the name of the state
808 */
809const char* Weapon::stateToChar(WeaponState state)
810{
811  switch (state)
812  {
813    case WS_SHOOTING:
814    return "shooting";
815    break;
816    case WS_CHARGING:
817    return "charging";
818    break;
819    case WS_RELOADING:
820    return "reloading";
821    break;
822    case WS_ACTIVATING:
823    return "activating";
824    break;
825    case WS_DEACTIVATING:
826    return "deactivating";
827    break;
828    case WS_IDLE:
829    return "idle";
830    break;
831    case WS_INACTIVE:
832    return "inactive";
833    break;
834    default:
835    return "none";
836    break;
837  }
838}
Note: See TracBrowser for help on using the repository browser.