Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4882 in orxonox.OLD


Ignore:
Timestamp:
Jul 17, 2005, 2:37:41 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: the energy system works

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'?>
    22<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>
    183  <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/>
    2010  </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>
    2323    <ignoretocs>
    2424      <toc>ada</toc>
     
    6565      <toc>KDE Libraries (Doxygen)</toc>
    6666    </ignoredoxygen>
    67  </kdevdoctreeview>
     67  </kdevdoctreeview>
    6868  <kdevfilecreate>
    6969    <filetypes/>
     
    7474    </useglobaltypes>
    7575  </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>
    76101</kdevelop>
  • orxonox/branches/weaponSystem/src/orxonox.cc

    r4872 r4882  
    5151#include <string.h>
    5252
    53 int verbose = 3;
     53int verbose = 4;
    5454
    5555using namespace std;
  • orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.cc

    r4881 r4882  
    100100
    101101  this->setStateDuration(WS_SHOOTING, 2);
     102
     103  this->energy = 100;
     104  this->minCharge = 2;
    102105}
    103106
     
    146149void TestGun::fire()
    147150{
     151  this->energyLoaded -= this->minCharge;
     152
    148153  Projectile* pj =  new TestBullet(this);//dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS));
    149154//  weaponSource->play();
  • orxonox/branches/weaponSystem/src/world_entities/weapons/test_gun.h

    r4880 r4882  
    3434class TestGun : public Weapon
    3535{
    36   friend class World;
    37 
    3836  public:
    3937    TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight);
  • orxonox/branches/weaponSystem/src/world_entities/weapons/weapon.cc

    r4881 r4882  
    6262{
    6363  this->currentState     = WS_INACTIVE;
     64  this->requestedAction  = WA_NONE;
    6465  this->stateDuration    = 0.0;
    6566  for (int i = 0; i < WS_STATE_COUNT; i++)
     
    7374  this->requestedAction = WA_NONE;
    7475  this->weaponSource = NULL;
    75   this->minCharge = 0.0;
    76   this->maxCharge = 0.0;
    7776
    7877  this->active = true;
    7978  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;
    8086}
    8187
     
    106112void Weapon::requestAction(WeaponAction action)
    107113{
    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  }
    110121}
    111122
     
    114125  this->stateDuration = this->times[this->requestedAction] + this->stateDuration;
    115126
    116   PRINT(3)("executing action %d\n", this->requestedAction);
     127  PRINTF(4)("trying to execute action %s\n", actionToChar(this->requestedAction));
     128  this->debug();
    117129
    118130  switch (this->requestedAction)
    119131  {
    120132    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      }
    122146      break;
    123147    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      }
    125158      break;
    126159    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      }
    128165      break;
    129166    case WA_DEACTIVATE:
    130       this->deactivate();
     167      if (this->currentState != WS_INACTIVE)
     168      {
     169        this->deactivate();
     170        this->requestedAction = WA_NONE;
     171      }
    131172      break;
    132173    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  }
    137181}
    138182
     
    141185*/
    142186void Weapon::activate()
    143 {}
     187{
     188  PRINTF(4)("Activating the Weapon %s\n", this->getName());
     189}
    144190
    145191
     
    148194*/
    149195void Weapon::deactivate()
    150 {}
     196{
     197  PRINTF(4)("Deactivating the Weapon %s\n", this->getName());
     198}
    151199
    152200void Weapon::fire()
    153201{
     202  this->energyLoaded -= this->minCharge;
    154203}
    155204
    156205void Weapon::reload()
    157206{
    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  }
    159228}
    160229
     
    185254  {
    186255    if (this->stateDuration <= 0.0 && this->requestedAction != WA_NONE)
     256    {
     257      this->stateDuration = -dt;
    187258      this->execute();
     259    }
    188260  }
    189261  else
     
    223295}
    224296
     297
     298/**
     299 * some nice debugging information about this Weapon
     300 */
     301void 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}
    225307
    226308
     
    252334      return WA_NONE;
    253335    }
     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 */
     343const 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  }
    254369}
    255370
     
    283398    }
    284399}
     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 */
     406const 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  
    9999    inline WeaponState getCurrentState() const { return this->currentState; };
    100100
    101 
     101    inline void setMaximumEnergy(float energyMax, float energyLoadedMax = 0.0) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; };
    102102
    103103    virtual void destroy();
    104104
    105105
    106 
     106    // FLOW
    107107    virtual void tick(float dt);
    108108    virtual void draw();
    109109
     110    void debug() const;
     111
    110112  protected:
     113    // utility:
    111114    static WeaponAction  charToAction(const char* action);
     115    static const char*   actionToChar(WeaponAction action);
    112116    static WeaponState   charToState(const char* state);
     117    static const char*   stateToChar(WeaponState state);
    113118
    114 
     119    //! ACTION: these functions are handled by the Weapon itself, and must be called by requestAction(WeaponAction);
    115120    bool execute();
    116121    virtual void activate();
     
    125130  protected:
    126131    SoundSource*         weaponSource;
     132    // it is all about energy
    127133    float                energy;
    128     int                  energyI;
     134    float                energyLoaded;
     135    float                energyMax;
     136    float                energyLoadedMax;
     137    float                minCharge;
     138    float                maxCharge;
    129139
    130140    ////////////
     
    138148    Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
    139149
    140     float                minCharge;
    141     float                maxCharge;
    142150
    143151    bool                 hideInactive;                    //!< Hides the Weapon if it is inactive
Note: See TracChangeset for help on using the changeset viewer.