Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4885 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
Jul 18, 2005, 3:36:18 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the weaponSystem back to the trunk, because it seems safe
merged with command:
svn merge -r 4847:HEAD branches/weaponSystem/ trunk/
conflict in file src/world-entities/weapons/weapon.h resolved in favor of the weaponSystem

Location:
orxonox/trunk
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/orxonox.kdevelop

    r4662 r4885  
    55    <email>orxonox-dev@mail.datacore.ch</email>
    66    <version>$VERSION$</version>
    7     <projectmanagement>KDevAutoProject</projectmanagement>
     7    <projectmanagement>KDevCustomProject</projectmanagement>
    88    <primarylanguage>C++</primarylanguage>
    99    <ignoreparts/>
    10     <projectdirectory>.</projectdirectory>
    11     <absoluteprojectpath>false</absoluteprojectpath>
    12     <description/>
    13     <secondaryLanguages/>
    14     <versioncontrol/>
    1510  </general>
    16   <kdevautoproject>
    17     <general>
    18       <activetarget>src/subprojects/particles/particles</activetarget>
    19       <useconfiguration>default</useconfiguration>
    20     </general>
     11  <kdevcustomproject>
    2112    <run>
    22       <mainprogram>src/orxonox</mainprogram>
     13      <mainprogram>orxonox</mainprogram>
    2314      <directoryradio>executable</directoryradio>
    24       <customdirectory>/</customdirectory>
    25       <programargs/>
    26       <terminal>false</terminal>
    27       <autocompile>true</autocompile>
    28       <envvars/>
    29       <runarguments>
    30         <orxonox/>
    31       </runarguments>
    3215    </run>
    33     <configurations>
    34       <optimized>
    35         <builddir>optimized</builddir>
    36         <ccompiler>GccOptions</ccompiler>
    37         <cxxcompiler>GppOptions</cxxcompiler>
    38         <f77compiler>G77Options</f77compiler>
    39         <cxxflags>-O2 -g0</cxxflags>
    40       </optimized>
    41       <debug>
    42         <configargs>--enable-debug=full</configargs>
    43         <builddir>debug</builddir>
    44         <ccompiler>GccOptions</ccompiler>
    45         <cxxcompiler>GppOptions</cxxcompiler>
    46         <f77compiler>G77Options</f77compiler>
    47         <cxxflags>-O0 -g3</cxxflags>
    48         <envvars/>
    49       </debug>
    50       <default>
    51         <envvars/>
    52       </default>
    53     </configurations>
    54     <make>
    55       <envvars>
    56         <envvar value="1" name="WANT_AUTOCONF_2_5" />
    57         <envvar value="1" name="WANT_AUTOMAKE_1_6" />
    58       </envvars>
    59       <abortonerror>false</abortonerror>
    60       <numberofjobs>3</numberofjobs>
    61       <dontact>false</dontact>
    62       <makebin>make</makebin>
    63       <prio>0</prio>
    64     </make>
    65   </kdevautoproject>
     16  </kdevcustomproject>
    6617  <kdevdebugger>
    6718    <general>
    68       <dbgshell>libtool</dbgshell>
    69       <programargs/>
    70       <gdbpath/>
    71       <configGdbScript/>
    72       <runShellScript/>
    73       <runGdbScript/>
    74       <breakonloadinglibs>true</breakonloadinglibs>
    75       <separatetty>false</separatetty>
    76       <floatingtoolbar>false</floatingtoolbar>
     19      <dbgshell/>
    7720    </general>
    78     <display>
    79       <staticmembers>false</staticmembers>
    80       <demanglenames>true</demanglenames>
    81       <outputradix>10</outputradix>
    82     </display>
    8321  </kdevdebugger>
    8422  <kdevdoctreeview>
     
    14280      <includeTypes>true</includeTypes>
    14381      <includeEnums>true</includeEnums>
    144       <includeTypedefs>true</includeTypedefs>
     82      <includeTypedefs>false</includeTypedefs>
    14583      <automaticCodeCompletion>true</automaticCodeCompletion>
    14684      <automaticArgumentsHint>true</automaticArgumentsHint>
     
    15088      <headerCompletionDelay>250</headerCompletionDelay>
    15189    </codecompletion>
    152     <creategettersetter>
    153       <prefixGet/>
    154       <prefixSet>set</prefixSet>
    155       <prefixVariable>m_,_</prefixVariable>
    156       <parameterName>theValue</parameterName>
    157       <inlineGet>true</inlineGet>
    158       <inlineSet>true</inlineSet>
    159     </creategettersetter>
    16090  </kdevcppsupport>
    16191  <kdevfileview>
     
    16595    </groups>
    16696    <tree>
    167       <hidepatterns>*.o,*~</hidepatterns>
     97      <hidepatterns>*.o,*.lo,*~,*in</hidepatterns>
    16898      <hidenonprojectfiles>false</hidenonprojectfiles>
    16999    </tree>
    170100  </kdevfileview>
    171   <cppsupportpart>
    172     <filetemplates>
    173       <interfacesuffix>.h</interfacesuffix>
    174       <implementationsuffix>.cc</implementationsuffix>
    175     </filetemplates>
    176   </cppsupportpart>
    177   <kdevdocumentation>
    178     <projectdoc>
    179       <docsystem/>
    180       <docurl/>
    181       <usermanualurl/>
    182     </projectdoc>
    183   </kdevdocumentation>
    184   <ctagspart>
    185     <customArguments/>
    186     <customTagfilePath/>
    187   </ctagspart>
    188101</kdevelop>
  • orxonox/trunk/src/defs/debug.h

    r4852 r4885  
    6969#define DEBUG_MODULE_LIGHT              0
    7070#define DEBUG_MODULE_PLAYER             1
    71 #define DEBUG_MODULE_WEAPON             0
     71#define DEBUG_MODULE_WEAPON             4
    7272#define DEBUG_MODULE_MATH               0
    7373#define DEBUG_MODULE_FONT               1
  • orxonox/trunk/src/lib/sound/sound_engine.cc

    r4836 r4885  
    9191 *  creates a SoundSource at position sourceNode with the SoundBuffer buffer
    9292*/
    93 SoundSource::SoundSource(SoundBuffer* buffer, PNode* sourceNode)
     93SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer)
    9494{
    9595  this->setClassID(CL_SOUND_SOURCE, "SoundSource");
     
    106106  if ((result = alGetError()) != AL_NO_ERROR)
    107107    SoundEngine::PrintALErrorString(result);
    108   alSourcei (this->sourceID, AL_BUFFER,   this->buffer->getID());
     108  if (this->buffer != NULL)
     109    alSourcei (this->sourceID, AL_BUFFER,   this->buffer->getID());
    109110  alSourcef (this->sourceID, AL_PITCH,    1.0      );
    110111  alSourcef (this->sourceID, AL_GAIN,     1.0      );
     
    121122}
    122123
    123 
    124124/**
    125125 *  Plays back a SoundSource
     
    128128{
    129129  alSourcePlay(this->sourceID);
     130}
     131
     132/**
     133 * Plays back buffer on this Source
     134 * @param buffer the buffer to play back on this Source
     135 */
     136void SoundSource::play(const SoundBuffer* buffer)
     137{
     138  alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     139  alSourcePlay(this->sourceID);
     140
     141  if (unlikely(this->buffer != NULL))
     142    alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
    130143}
    131144
     
    230243SoundSource* SoundEngine::createSource(const char* fileName, PNode* sourceNode)
    231244{
    232   return new SoundSource((SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL), sourceNode);
     245  return new SoundSource(sourceNode, (SoundBuffer*)ResourceManager::getInstance()->load(fileName, WAV, RP_LEVEL));
    233246}
    234247
  • orxonox/trunk/src/lib/sound/sound_engine.h

    r4836 r4885  
    2727
    2828  /** @returns the ID of the buffer used in this SoundBuffer */
    29   inline ALuint getID() { return this->bufferID; }
     29  inline ALuint getID() const { return this->bufferID; }
    3030
    3131 private:
     
    4040{
    4141 public:
    42   SoundSource(SoundBuffer* buffer, PNode* sourceNode = NULL);
     42  SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL);
    4343  ~SoundSource();
    4444
    4545  // user interaction
    4646  void play();
     47  void play(const SoundBuffer* buffer);
    4748  void stop();
    4849  void pause();
     
    5354  inline ALuint getID() const { return this->sourceID; }
    5455  /** @returns the SoundBuffer of this Source */
    55   inline SoundBuffer* getBuffer() const { return this->buffer; }
     56  inline const SoundBuffer* getBuffer() const { return this->buffer; }
    5657  /** @returns the SourceNode of this Source */
    57   inline PNode* getNode() const { return this->sourceNode;}
     58  inline const PNode* getNode() const { return this->sourceNode;}
    5859
    5960  void setRolloffFactor(ALfloat rolloffFactor);
    6061
    6162 private:
    62   ALuint           sourceID;              //!< The ID of the Source
    63   SoundBuffer*     buffer;                //!< The buffer to play in this source.
    64   PNode*           sourceNode;            //!< The SourceNode represente the position/velocity... of this source.
     63  ALuint                 sourceID;              //!< The ID of the Source
     64  const SoundBuffer*     buffer;                //!< The buffer to play in this source.
     65  const PNode*           sourceNode;            //!< The SourceNode represente the position/velocity... of this source.
    6566};
    6667
  • orxonox/trunk/src/orxonox.cc

    r4872 r4885  
    5151#include <string.h>
    5252
    53 int verbose = 3;
     53int verbose = 4;
    5454
    5555using namespace std;
  • orxonox/trunk/src/story_entities/world.cc

    r4872 r4885  
    841841  while( entity != NULL )
    842842    {
    843       if( entity->bDraw ) entity->draw();
     843      if( entity->isVisible() ) entity->draw();
    844844      //entity = this->entities->nextElement();
    845845      entity = iterator->nextElement();
  • orxonox/trunk/src/util/animation/t_animation.h

    r4837 r4885  
    205205              this->nextKeyFrame = this->keyFrameList->nextElement(this->currentKeyFrame);
    206206
    207               printf("%p from:%f to:%f\n", this->currentKeyFrame,this->currentKeyFrame->value, this->nextKeyFrame->value);
     207              //printf("%p from:%f to:%f\n", this->currentKeyFrame,this->currentKeyFrame->value, this->nextKeyFrame->value);
    208208              this->setAnimFunc(this->currentKeyFrame->animFunc);
    209209            }
  • orxonox/trunk/src/util/loading/factory.h

    r4836 r4885  
    1515
    1616/*!
    17   \file factory.h
    18   \brief A loadable object handler
     17 * @file factory.h
     18 * @brief A loadable object handler
    1919*/
    2020
     
    3131
    3232/**
    33     Creates a factory to a Loadable Class.
    34     this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
    35   @todo make factoryName a BaseObject-parameter. (else it would be redundant)
     33 * Creates a factory to a Loadable Class.
     34 * this should be used at the beginning of all the Classes that should be loadable (in the cc-file)
    3635*/
    37 #define CREATE_FACTORY(CLASS_NAME) tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME)
     36#define CREATE_FACTORY(CLASS_NAME) \
     37    tFactory<CLASS_NAME>* global_##CLASS_NAME##_Factory = new tFactory<CLASS_NAME>(#CLASS_NAME)
    3838
    3939//! The Factory is a loadable object handler
     
    4848
    4949  static void registerFactory( Factory* factory);
    50   /** \brief sets the Next factory in the list @param nextFactory the next factory */
     50  /** sets the Next factory in the list @param nextFactory the next factory */
    5151  inline void setNext( Factory* nextFactory) { this->next = nextFactory; };
    5252  /** @returns the first factory */
     
    5454  /** @returns the next factory */
    5555  Factory* getNext() const { return this->next; };
    56 
    57 
    58   private:
    5956
    6057  private:
  • orxonox/trunk/src/util/loading/game_loader.cc

    r4838 r4885  
    1919#include "campaign.h"
    2020#include "world.h"
    21 #include "player.h"
    2221#include "orxonox.h"
    2322#include "camera.h"
  • orxonox/trunk/src/util/loading/game_loader.h

    r4836 r4885  
    11/*!
    2     \file game_loader.h
    3   *  loads campaigns, worlds and all other story_entities
     2 * @file game_loader.h
     3 *  loads campaigns, worlds and all other story_entities
    44*/
    55
     
    1818class Campaign;
    1919class World;
    20 class Camera;
    21 class CammandNode;
    2220class Factory;
    2321class TiXmlElement;
  • orxonox/trunk/src/world_entities/player.cc

    r4836 r4885  
    2323
    2424#include "weapon_manager.h"
    25 #include "weapon.h"
    2625#include "test_gun.h"
    2726#include "world.h"
    2827
    2928#include "list.h"
    30 #include "stdincl.h"
    3129
    3230#include "event_handler.h"
    3331
    34 #include "projectile.h"
    3532#include "event.h"
    3633
     
    4138
    4239/**
    43  *  creates a new Player
     40 * creates a new Player
    4441 * @param isFree if the player is free
    4542*/
    4643Player::Player()
    4744{
    48   /*
    49     this is the debug player - actualy we would have to make a new
    50      class derivated from Player for each player. for now, we just use
    51      the player.cc for debug also
    52   */
    5345  this->init();
    5446
     
    7567  delete this->weaponMan;
    7668}
    77 
    7869
    7970/**
     
    119110
    120111/**
    121  *
     112 * loads the Settings of a Player from an XML-element.
    122113 * @param root the XML-element to load the Player's properties from
    123114 */
     
    132123
    133124/**
    134  *  adds a weapon to the weapon list of player
     125 * adds a weapon to the weapon list of player
    135126 * @param weapon to add
    136127*/
     
    219210void Player::tick (float time)
    220211{
    221   //printf("%p\n", this);
    222   //this->getRelCoor().debug();
    223 
    224   /* link tick to weapon */
    225   //this->activeWeapon->tick(time);
    226   //this->activeWeaponL->tick(time); //FIX FIX DELETE REMOVE
    227   this->weaponMan->tick(time);
    228212  // player controlled movement
    229213  this->move(time);
     214
     215  this->weaponMan->tick(time);
    230216  // weapon system manipulation
    231   this->weapon();
     217  this->weaponAction();
    232218}
    233219
     
    255241  if( this->bRight &&  TrackManager::getInstance()->getWidth() > this->getRelCoor().z*2)
    256242    accel = accel + (orthDirection*acceleration);
    257   if( this->bAscend )
     243  if( this->bAscend ) { /* FIXME */ }
    258244  if( this->bDescend) {/* FIXME */} /* @todo up and down player movement */
    259245
     
    264250
    265251/**
    266  *  weapon manipulation by the player
    267 */
    268 void Player::weapon()
     252 * weapon manipulation by the player
     253*/
     254void Player::weaponAction()
    269255{
    270256  if( this->bFire)
     
    279265}
    280266
    281 
    282 /**
    283  *  The connection to the command node
    284  * @param cmd the Command unit from witch to map
    285 
    286    here the commands are mapped to the players movement/weaponary
    287 */
    288 void Player::command (Command* cmd)
    289 {
    290   PRINTF(3)("recieved command [%s]\n", cmd->cmd);
    291   if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_UP)) this->bUp = !cmd->bUp;
    292   if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_DOWN)) this->bDown = !cmd->bUp;
    293   if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_LEFT)) this->bLeft = !cmd->bUp;
    294   if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_RIGHT)) this->bRight = !cmd->bUp;
    295   if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_FIRE)) this->bFire = !cmd->bUp;
    296   if( !strcmp( cmd->cmd, CONFIG_NAME_PLAYER_NEXT_WEAPON)) if(cmd->bUp) this->bWeaponChange = !this->bWeaponChange;
    297 }
    298 
    299267/**
    300268 * @todo switch statement ??
     
    303271{
    304272  if( event.type == KeyMapper::PEV_UP)
    305     {
    306273      this->bUp = event.bPressed;
    307     }
    308274  else if( event.type == KeyMapper::PEV_DOWN)
    309     {
    310275      this->bDown = event.bPressed;
    311     }
    312276  else if( event.type == KeyMapper::PEV_RIGHT)
    313     {
    314277      this->bRight= event.bPressed;
    315     }
    316278  else if( event.type == KeyMapper::PEV_LEFT)
    317     {
    318279      this->bLeft = event.bPressed;
    319     }
    320280  else if( event.type == KeyMapper::PEV_FIRE1)
    321     {
    322        this->bFire = event.bPressed;
    323     }
     281      this->bFire = event.bPressed;
    324282  else if( event.type == KeyMapper::PEV_NEXT_WEAPON)
    325     {
    326283      if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange;
    327     }
    328 
    329 }
     284
     285}
  • orxonox/trunk/src/world_entities/player.h

    r4836 r4885  
    11/*!
    2     \file player.h
    3   * Implements a basic controllable WorldEntity
     2 * @file player.h
     3 * Implements a basic controllable WorldEntity
    44 */
    55
     
    1515class WeaponManager;
    1616class Vector;
    17 class World;
    1817class Event;
    19 class Crosshair;
    2018
    2119//! Basic controllable WorldEntity
     20/**
     21  *  this is the debug player - actualy we would have to make a new
     22     class derivated from Player for each player. for now, we just use
     23     the player.cc for debug also
     24*/
    2225class Player : public WorldEntity, public PhysicsInterface, public EventListener
    2326{
     
    4346    virtual void draw();
    4447
    45     virtual void command(Command* cmd);
    46 
    4748    virtual void process(const Event &event);
    4849
     
    5051  private:
    5152    void move(float time);
    52     void weapon();
     53    void weaponAction();
    5354
    5455
    5556  private:
    56     bool bUp;              //!< up button pressed.
    57     bool bDown;            //!< down button pressed.
    58     bool bLeft;            //!< left button pressed.
    59     bool bRight;           //!< right button pressed.
    60     bool bAscend;          //!< ascend button pressed.
    61     bool bDescend;         //!< descend button presses.
    62     bool bFire;            //!< fire button pressed.
    63     bool bWeaponChange;    //!< weapon change button pressed
     57    bool                  bUp;                //!< up button pressed.
     58    bool                  bDown;              //!< down button pressed.
     59    bool                  bLeft;              //!< left button pressed.
     60    bool                  bRight;             //!< right button pressed.
     61    bool                  bAscend;            //!< ascend button pressed.
     62    bool                  bDescend;           //!< descend button presses.
     63    bool                  bFire;              //!< fire button pressed.
     64    bool                  bWeaponChange;      //!< weapon change button pressed
    6465
    65     tList<Weapon>* weapons;//!< a list of weapon
    66     Weapon* activeWeapon;  //!< the weapon that is currenty activated
    67     Weapon* activeWeaponL;  //temporary -- FIX THIS
    68     WeaponManager* weaponMan; //!< the weapon manager: managing a list of weapon to wepaon-slot mapping
     66    WeaponManager*        weaponMan;          //!< the weapon manager: managing a list of weapon to wepaon-slot mapping
    6967
    70     World* myWorld;        //!< reference to the world object
    71 
    72     Vector* velocity;       //!< the velocity of the player.
    73     float travelSpeed;     //!< the current speed of the player (to make soft movement)
    74     float acceleration;    //!< the acceleration of the player.
    75 
    76     Crosshair*  crosshair; //!< the crosshair of the player
     68    Vector*               velocity;           //!< the velocity of the player.
     69    float                 travelSpeed;        //!< the current speed of the player (to make soft movement)
     70    float                 acceleration;       //!< the acceleration of the player.
    7771};
    7872
  • orxonox/trunk/src/world_entities/weapons/test_gun.cc

    r4836 r4885  
    5050
    5151  this->model = (Model*)ResourceManager::getInstance()->load("models/test_gun.obj", OBJ, RP_CAMPAIGN);
    52   this->idleTime = 0.2f;
    5352  this->leftRight = leftRight;
    5453
     
    9291      this->animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
    9392    }
    94 
     93/*
    9594  this->fireSound = (SoundBuffer*)ResourceManager::getInstance()->load("sound/shot1.wav", WAV);
    9695  this->weaponSource = new SoundSource(this->fireSound, this);
    97   this->weaponSource->setRolloffFactor(.1);
     96  this->weaponSource->setRolloffFactor(.1);*/
    9897  Projectile* p = new TestBullet(this);
    99 //  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
     98
     99  //  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
    100100  //ObjectManager::getInstance()->debug();
     101
     102  this->setStateDuration(WS_SHOOTING, .2);
     103
     104  this->energy = 100;
     105  this->minCharge = 2;
     106
     107  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
    101108}
    102109
     
    145152void TestGun::fire()
    146153{
    147   if( !this->hasWeaponIdleTimeElapsed())
    148     {
    149       this->weaponIdle();
    150       return;
    151     }
    152 
    153     Projectile* pj =  new TestBullet(this);//dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS));
    154   weaponSource->play();
     154  this->energyLoaded -= this->minCharge;
     155  Projectile* pj =  new TestBullet(this);//dynamic_cast<Projectile*>(ObjectManager::getInstance()->getFromDeadList(CL_TEST_BULLET & CL_MASK_LOWLEVEL_CLASS));
     156//  weaponSource->play();
    155157
    156158  pj->setAbsCoor(this->getAbsCoor() + this->projectileOffset);
     
    158160  pj->setVelocity(this->getVelocity());
    159161  State::getWorldEntityList()->add(pj);
    160   this->localTime = 0;
    161162
    162163  this->animation1->replay();
     
    184185void TestGun::destroy ()
    185186{}
    186 
    187 
    188 /**
    189  *  tick signal for time dependent/driven stuff
    190 */
    191 void TestGun::tick (float time)
    192 {
    193   this->localTime += time;
    194 }
    195187
    196188
  • orxonox/trunk/src/world_entities/weapons/test_gun.h

    r4836 r4885  
    3434class TestGun : public Weapon
    3535{
    36   friend class World;
    37 
    3836  public:
    3937    TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight);
     
    4745    virtual void destroy();
    4846
    49     virtual void tick(float time);
    5047    virtual void weaponIdle();
    5148    virtual void draw();
  • orxonox/trunk/src/world_entities/weapons/weapon.cc

    r4836 r4885  
    1313   main-programmer: Patrick Boenzli
    1414   co-programmer: Benjamin Grauer
    15 */
     15
     16   2005-07-15: Benjamin Grauer: restructurating the entire Class
     17*/
     18
     19#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
    1620
    1721#include "weapon.h"
     
    2327#include "list.h"
    2428#include "state.h"
    25 
    26 /**
    27  *  standard constructor
    28 
    29    creates a new weapon
     29#include "animation3d.h"
     30#include "sound_engine.h"
     31
     32/**
     33 * standard constructor
     34 *
     35 * creates a new weapon
    3036*/
    3137Weapon::Weapon (PNode* parent, const Vector& coordinate, const Quaternion& direction)
    3238{
     39  this->init();
    3340  parent->addChild(this, PNODE_ALL);
    3441  this->setRelCoor(coordinate);
     
    3643}
    3744
    38 
    39 /**
    40  *  standard deconstructor
     45/**
     46 * standard deconstructor
    4147*/
    4248Weapon::~Weapon ()
    4349{
    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 
    52 
    53 /**
    54   *  enables the weapon
    55 
    56     a weapon can be enabled/disabled because of various reasons. if a weapon is
    57     been enabled, it can interact in a world. elswhere it wont react to any
    58     action.
    59 */
    60 void Weapon::enable()
    61 {
    62   this->enabled = true;
    63 }
    64 
    65 
    66 /**
    67   *  disables the weapon
    68 
    69     a weapon can be enabled/disabled because of various reasons. if a weapon is
    70     been enabled, it can interact in a world. elswhere it wont react to any
    71     action.
    72 */
    73 void Weapon::disable()
    74 {
    75   this->enabled = false;
    76 }
    77 
    78 
    79 /**
    80   *  checks if the weapon is enabled
    81   * @returns true if enabled
    82 
    83     a weapon can be ebabled/disabled because of various reasons. if a weapon is
    84     been enabled, it can interact in a world. elswhere it wont react to any
    85     action.
    86 */
    87 bool Weapon::isEnabled()
    88 {
    89   return this->enabled;
    90 }
    91 
    92 
    93 /**
    94  *  sets a new projectile to the weapon
    95  * @param new projectile for this weapon
    96 
    97    weapon an projectile are independent, so you can combine them as you want
    98 */
    99 void Weapon::setProjectile(Projectile* projectile)
    100 {
    101   this->projectile = projectile;
    102 }
    103 
    104 
    105 /**
    106  *  sets a new projectile to the weapon
    107  * @returns the current projectile of this weapon
    108 
    109    weapon an projectile are independent, so you can combine them as you want
    110 */
    111 Projectile* Weapon::getProjectile()
    112 {
    113   return this->projectile;
    114 }
    115 
    116 
    117 /**
    118  *  this activates the weapon
    119 
    120    This is needed, since there can be more than one weapon on a ship. the
    121    activation can be connected with an animation. for example the weapon is
    122    been armed out.
     50  for (int i = 0; i < WS_STATE_COUNT; i++)
     51    if (this->animation[i])
     52      delete this->animation[i];
     53  for (int i = 0; i < WA_ACTION_COUNT; i++)
     54    if (this->soundBuffers[i])
     55      ResourceManager::getInstance()->unload(this->soundBuffers[i]);
     56}
     57
     58/**
     59 * initializes the Weapon with ALL default values
     60 */
     61void Weapon::init()
     62{
     63  this->currentState     = WS_INACTIVE;
     64  this->requestedAction  = WA_NONE;
     65  this->stateDuration    = 0.0;
     66  for (int i = 0; i < WS_STATE_COUNT; i++)
     67    {
     68      this->times[i] = 0.0;
     69      this->animation[i] = NULL;
     70    }
     71  for (int i = 0; i < WA_ACTION_COUNT; i++)
     72    this->soundBuffers[i] = NULL;
     73
     74  this->requestedAction = WA_NONE;
     75  this->soundSource = new SoundSource(this);
     76
     77  this->active = true;
     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;
     86}
     87
     88
     89void Weapon::setActionSound(WeaponAction action, const char* soundFile)
     90{
     91  if (action >= WA_ACTION_COUNT)
     92    return;
     93  else if (soundFile != NULL)
     94  {
     95    this->soundBuffers[action] = (SoundBuffer*)ResourceManager::getInstance()->load(soundFile, WAV);
     96    if (this->soundBuffers[action] != NULL)
     97    {
     98      PRINTF(4)("Loaded sound %s to action %s\n", soundFile, actionToChar(action));
     99    }
     100    else
     101    {
     102      PRINTF(4)("failed to load sound %s to %s\n", soundFile, actionToChar(action));
     103    }
     104  }
     105  else
     106    this->soundBuffers[action] = NULL;
     107}
     108
     109/**
     110 * request an action that should be executed,
     111 * @param action the next action to take
     112 *
     113 * This function must be called instead of the actions (like fire/reload...)
     114 * to make all the checks needed to have a usefull WeaponSystem.
     115 */
     116void Weapon::requestAction(WeaponAction action)
     117{
     118  if (this->requestedAction != WA_NONE)
     119    return;
     120  else
     121  {
     122    printf("next action will be %s in %f seconds\n", actionToChar(action), this->stateDuration);
     123    this->requestedAction = action;
     124  }
     125}
     126
     127bool Weapon::execute()
     128{
     129  this->stateDuration = this->times[this->requestedAction] + this->stateDuration;
     130
     131  PRINTF(4)("trying to execute action %s\n", actionToChar(this->requestedAction));
     132  this->debug();
     133
     134  switch (this->requestedAction)
     135  {
     136    case WA_SHOOT:
     137      //if (likely(this->currentState != WS_INACTIVE))
     138      {
     139        if (this->minCharge <= this->energyLoaded)
     140        {
     141          if (this->soundBuffers[WA_SHOOT] != NULL)
     142            this->soundSource->play(this->soundBuffers[WA_SHOOT]);
     143          this->fire();
     144          this->requestedAction = WA_NONE;
     145        }
     146        else  // reload if we still have the charge
     147        {
     148          this->requestedAction = WA_NONE;
     149          this->requestAction(WA_RELOAD);
     150        }
     151      }
     152      break;
     153    case WA_CHARGE:
     154      if ( this->currentState != WS_INACTIVE && this->energyLoaded >= this->minCharge)
     155      {
     156        if (this->soundBuffers[WA_CHARGE] != NULL)
     157         this->soundSource->play(this->soundBuffers[WA_CHARGE]);
     158        this->charge();
     159        this->requestedAction = WA_NONE;
     160      }
     161      else // deactivate the Weapon if we do not have enough energy
     162      {
     163        this->requestedAction = WA_NONE;
     164        this->requestAction(WA_RELOAD);
     165      }
     166      break;
     167    case WA_RELOAD:
     168      //if (this->currentState != WS_INACTIVE && this->energy + this->energyLoaded >= this->minCharge)
     169      {
     170        if (this->soundBuffers[WA_RELOAD] != NULL)
     171          this->soundSource->play(this->soundBuffers[WA_RELOAD]);
     172
     173        this->reload();
     174        this->requestedAction = WA_NONE;
     175      }
     176      break;
     177    case WA_DEACTIVATE:
     178      if (this->currentState != WS_INACTIVE)
     179      {
     180        if (this->soundBuffers[WA_DEACTIVATE] != NULL)
     181          this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]);
     182
     183        this->deactivate();
     184        this->requestedAction = WA_NONE;
     185      }
     186      break;
     187    case WA_ACTIVATE:
     188      if (this->currentState == WS_INACTIVE)
     189      {
     190        if (this->soundBuffers[WA_ACTIVATE] != NULL)
     191          this->soundSource->play(this->soundBuffers[WA_ACTIVATE]);
     192
     193        this->activate();
     194        this->requestedAction = WA_NONE;
     195      }
     196      break;
     197  }
     198}
     199
     200/**
     201 * this activates the weapon
    123202*/
    124203void Weapon::activate()
    125 {}
    126 
    127 
    128 /**
    129  *  this deactivates the weapon
    130 
    131    This is needed, since there can be more than one weapon on a ship. the
    132    activation can be connected with an animation. for example the weapon is
    133    been armed out.
     204{
     205  PRINTF(4)("Activating the Weapon %s\n", this->getName());
     206
     207  if (this->soundBuffers[WA_ACTIVATE] != NULL)
     208    this->soundSource->play(this->soundBuffers[WA_ACTIVATE]);
     209}
     210
     211
     212/**
     213 * this deactivates the weapon
    134214*/
    135215void Weapon::deactivate()
    136 {}
    137 
    138 /**
    139  *  asks if the current weapon is active
    140  * @returns true if it the weapon is active
    141 */
    142 bool Weapon::isActive()
    143 {}
    144 
    145 
    146 
    147 
    148 
    149 
    150 /**
    151  *  is called, when the weapon gets hit (=collide with something)
    152  * @param from which entity it is been hit
    153  * @param where it is been hit
    154 
    155    this may not be used, since it would make the game relay complicated when one
    156    can destroy the weapons of enemies or vice versa.
    157 */
    158 void Weapon::hit (WorldEntity* entity, const Vector& position)
    159 {}
     216{
     217  PRINTF(4)("Deactivating the Weapon %s\n", this->getName());
     218
     219  if (this->soundBuffers[WA_DEACTIVATE] != NULL)
     220    this->soundSource->play(this->soundBuffers[WA_DEACTIVATE]);
     221}
     222
     223void Weapon::fire()
     224{
     225  this->energyLoaded -= this->minCharge;
     226
     227  if (this->soundBuffers[WA_SHOOT] != NULL)
     228    this->soundSource->play(this->soundBuffers[WA_SHOOT]);
     229}
     230
     231void Weapon::reload()
     232{
     233  PRINTF(4)("Reloading Weapon %s\n", this->getName());
     234  if (this->energy + this->energyLoaded < this->minCharge)
     235  {
     236    this->requestAction(WA_DEACTIVATE);
     237    return;
     238  }
     239
     240  float chargeSize = this->energyLoadedMax - this->energyLoaded;       //!< The energy to be charged
     241
     242  if (chargeSize > this->energy)
     243  {
     244    this->energyLoaded += this->energy;
     245    this->energy = 0.0;
     246    PRINT(3)("Energy empty");
     247  }
     248  else
     249  {
     250    PRINTF(3)("Loaded %f energy into the Guns Buffer\n", chargeSize);
     251    this->energyLoaded += chargeSize;
     252    this->energy -= chargeSize;
     253  }
     254  if (this->soundBuffers[WA_RELOAD] != NULL)
     255    this->soundSource->play(this->soundBuffers[WA_RELOAD]);
     256
     257}
     258
     259void Weapon::charge()
     260{
     261  if (this->soundBuffers[WA_CHARGE] != NULL)
     262    this->soundSource->play(this->soundBuffers[WA_CHARGE]);
     263
     264}
    160265
    161266
    162267/**
    163268 *  is called, when the weapon is destroyed
    164 
    165    this is in conjunction with the hit function, so when a weapon is able to get
    166    hit, it can also be destoryed.
     269 *
     270 * this is in conjunction with the hit function, so when a weapon is able to get
     271 * hit, it can also be destoryed.
    167272*/
    168273void Weapon::destroy ()
     
    171276
    172277/**
    173  *  tick signal for time dependent/driven stuff
    174 */
    175 void Weapon::tick (float time)
    176 {}
    177 
    178 
    179 /**
    180  *  is called, when there is no fire button pressed
    181 */
    182 void Weapon::weaponIdle()
    183 {}
    184 
     278 * tick signal for time dependent/driven stuff
     279*/
     280void Weapon::tick(float dt)
     281{
     282  // setting up the timing properties
     283  this->stateDuration -= dt;
     284
     285  if (this->isActive())
     286  {
     287    if (this->stateDuration <= 0.0 && this->requestedAction != WA_NONE)
     288    {
     289      this->stateDuration = -dt;
     290      this->execute();
     291    }
     292  }
     293  else
     294    if (this->requestedAction == WA_ACTIVATE)
     295      this->activate();
     296
     297}
    185298
    186299/**
     
    190303{}
    191304
     305
     306
     307
     308
     309//////////////////////
     310// HELPER FUNCTIONS //
     311//////////////////////
     312// inclass
     313/**
     314 * checks if the next Action given is valid
     315 * @returns if the Action that comes next is valid
     316 * @todo more checks
     317 */
     318bool Weapon::nextActionValid() const
     319{
     320  if (this->currentState == WS_INACTIVE)
     321  {
     322    return (this->requestedAction == WA_ACTIVATE || this->requestedAction == WA_NONE);
     323  }
     324  else
     325    return true;
     326
     327}
     328
     329
     330/**
     331 * some nice debugging information about this Weapon
     332 */
     333void Weapon::debug() const
     334{
     335  PRINT(3)("Weapon-Debug %s, state: %s, nexAction: %s\n", this->getName(), Weapon::stateToChar(this->currentState), Weapon::actionToChar(requestedAction));
     336  PRINT(3)("Energy: max: %f; current: %f;  loadedMax: %f; loadedCurrent: %f; chargeMin: %f, chargeMax %f\n",
     337            this->energyMax, this->energy, this->energyLoadedMax, this->energyLoaded, this->minCharge, this->maxCharge);
     338}
     339
     340
     341// static
     342/**
     343 * Converts a String into an Action.
     344 * @param action the String input holding the Action.
     345 * @return The Action if known, WA_NONE otherwise.
     346 */
     347WeaponAction Weapon::charToAction(const char* action)
     348{
     349  if (!strcmp(action, "none"))
     350    return WA_NONE;
     351  else if (!strcmp(action, "shoot"))
     352    return WA_SHOOT;
     353  else if (!strcmp(action, "charge"))
     354    return WA_CHARGE;
     355  else if (!strcmp(action, "reload"))
     356    return WA_RELOAD;
     357  else if (!strcmp(action, "acitvate"))
     358    return WA_ACTIVATE;
     359  else if (!strcmp(action, "deactivate"))
     360    return WA_DEACTIVATE;
     361  else if (!strcmp(action, "special1"))
     362    return WA_SPECIAL1;
     363  else
     364    {
     365      PRINTF(2)("action %s could not be identified.\n", action);
     366      return WA_NONE;
     367    }
     368}
     369
     370/**
     371 * converts an action into a String
     372 * @param action the action to convert
     373 * @return a String matching the name of the action
     374 */
     375const char* Weapon::actionToChar(WeaponAction action)
     376{
     377  switch (action)
     378  {
     379    case WA_SHOOT:
     380      return "shoot";
     381      break;
     382    case WA_CHARGE:
     383      return "charge";
     384      break;
     385    case WA_RELOAD:
     386      return "reload";
     387      break;
     388    case WA_ACTIVATE:
     389      return "activate";
     390      break;
     391    case WA_DEACTIVATE:
     392      return "deactivate";
     393      break;
     394    case WA_SPECIAL1:
     395      return "special1";
     396      break;
     397    default:
     398      return "none";
     399      break;
     400  }
     401}
     402
     403/**
     404 * Converts a String into a State.
     405 * @param state the String input holding the State.
     406 * @return The State if known, WS_NONE otherwise.
     407 */
     408WeaponState Weapon::charToState(const char* state)
     409{
     410  if (!strcmp(state, "none"))
     411    return WS_NONE;
     412  else if (!strcmp(state, "shooting"))
     413    return WS_SHOOTING;
     414  else if (!strcmp(state, "charging"))
     415    return WS_CHARGING;
     416  else if (!strcmp(state, "reloading"))
     417    return WS_RELOADING;
     418  else if (!strcmp(state, "activating"))
     419    return WS_ACTIVATING;
     420  else if (!strcmp(state, "deactivating"))
     421    return WS_DEACTIVATING;
     422  else if (!strcmp(state, "inactive"))
     423    return WS_INACTIVE;
     424  else if (!strcmp(state, "idle"))
     425    return WS_IDLE;
     426  else
     427    {
     428      PRINTF(2)("state %s could not be identified.\n", state);
     429      return WS_NONE;
     430    }
     431}
     432
     433/**
     434 * converts a State into a String
     435 * @param state the state to convert
     436 * @return a String matching the name of the state
     437 */
     438const char* Weapon::stateToChar(WeaponState state)
     439{
     440  switch (state)
     441  {
     442    case WS_SHOOTING:
     443      return "shooting";
     444      break;
     445    case WS_CHARGING:
     446      return "charging";
     447      break;
     448    case WS_RELOADING:
     449      return "reloading";
     450      break;
     451    case WS_ACTIVATING:
     452      return "activating";
     453      break;
     454    case WS_DEACTIVATING:
     455      return "deactivating";
     456      break;
     457    case WS_IDLE:
     458      return "idle";
     459      break;
     460    default:
     461      return "none";
     462      break;
     463  }
     464}
  • orxonox/trunk/src/world_entities/weapons/weapon.h

    r4875 r4885  
    1212    weapon in this world:
    1313     o sound file/ressource: this is a pointer to the sound-file/ressource. however it may be represented
    14      o shooting animation
     14     o animations
    1515*/
    1616
     
    3939
    4040  WA_ACTION_COUNT  =    7     //!< This must match the count of enumerations-members.
    41 } WeaponActions;
     41} WeaponAction;
    4242
    4343//! An enumerator defining the States of a Weapon
     
    4545  WS_NONE          =    0,    //!< No State at all (if set, there is something wrong, or the weapon is not yet availiable)
    4646  WS_SHOOTING      =    1,    //!< The State of the Shooting
     47  WS_CHARGING      =    2,    //!< The state of charging th weapon
    4748  WS_RELOADING     =    3,    //!< The State of the Reloading
    4849  WS_ACTIVATING    =    4,    //!< The State in which the weapon gets activated
     
    6869class Weapon : public WorldEntity
    6970{
    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 ();
    7176
    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    ////////////////////
    7680
    77   void init();
    78   void loadParams(const TiXmlElement* root);
     81    void requestAction(WeaponAction action);
    7982
    80   void enable();
    81   void disable();
    82   bool isEnabled();
     83    /** @returns true if the Weapon is Active */
     84    inline bool isActive() const { return this->active; };
    8385
    84   void setProjectile(Projectile* projectile);
    85   Projectile* getProjectile();
     86    // FUNCTIONS TO SET THE WEAPONS PROPERTIES.
     87    /** @param projectile a projectile for this weapon */
     88    void setProjectile(Projectile* projectile) { this->projectile = projectile; };
     89    /** @returns The projectile if availiable */
     90    Projectile* getProjectile() { return this->projectile; };
    8691
    87   virtual void activate();
    88   virtual void deactivate();
    89   bool isActive();
     92    /** @param state the State to time @param duration the duration of the State */
     93    inline void setStateDuration(const char* state, float duration) { setStateDuration(charToState(state), duration); };
     94    /** @param state the State to time @param duration the duration of the State */
     95    inline void setStateDuration(WeaponState state, float duration) { /*(state < WS_STATE_COUNT)?*/this->times[state] = duration; };
     96    /** @param state The state to query @returns the Time the queried State takes to complete */
     97    inline float getStateDuration(WeaponState state) const { return (state < WS_STATE_COUNT)?this->times[state]:0.0; };
     98    /** @returns true if the time of the currentState is elapsed, false otherwise */
     99    inline bool stateTimeElapsed() const { return (this->stateDuration > this->times[currentState])?true:false; };
     100    /** @returns the current State of the Weapon */
     101    inline WeaponState getCurrentState() const { return this->currentState; };
     102    /** @param energyMax the maximum energy the Weapon can have @param energyLoadedMax the maximum energy in the weapon buffers */
     103    inline void setMaximumEnergy(float energyMax, float energyLoadedMax = 0.0) { this->energyMax = energyMax; this->energyLoadedMax = energyLoadedMax; };
     104
     105    void setActionSound(WeaponAction action, const char* soundFile);
     106    /** @see void setActionSound(WeaponAction action, const char* soundFile); */
     107    void setActionSound(const char* action, const char* soundFile) { this->setActionSound(charToAction(action), soundFile); };
     108
     109    virtual void destroy();
    90110
    91111
    92   /** @param idle time in ms  */
    93   inline void setWeaponIdleTime(float idleTime) { this->idleTime = idleTime; };
    94   /** @returns idle time in ms */
    95   inline float getWeaponIdleTime() const { return this->idleTime; };
    96   /** @return true if idletime is elapsed else otherwise */
    97   inline bool hasWeaponIdleTimeElapsed() const { return (this->localTime > this->idleTime)?true:false; };
     112    // FLOW
     113    virtual void tick(float dt);
     114    virtual void draw();
    98115
    99   /**  fires the weapon */
    100   virtual void fire() = 0;
    101   virtual void hit (WorldEntity* weapon, const Vector& loc);
    102   virtual void destroy();
     116    void debug() const;
    103117
    104   virtual void tick(float time);
    105   virtual void weaponIdle();
    106   virtual void draw();
     118  protected:
     119    // utility:
     120    static WeaponAction  charToAction(const char* action);
     121    static const char*   actionToChar(WeaponAction action);
     122    static WeaponState   charToState(const char* state);
     123    static const char*   stateToChar(WeaponState state);
    107124
    108  protected:
    109   float                localTime;                        //<! this is the local time. important for shooting attributes like frequency
    110   float                idleTime;                         //<! the time a weapon needs before it can shoot again. eg. shooting frequency or actication/deactivateion delay
    111   float                slowDownFactor;                   //<! if the shooting frequency is a linear function of time...
     125    //! ACTION: these functions are handled by the Weapon itself, and must be called by requestAction(WeaponAction);
     126    bool execute();
     127    virtual void activate();
     128    virtual void deactivate();
     129    virtual void fire();
     130    virtual void reload();
     131    virtual void charge();
    112132
    113   ////////////
    114   // PHASES //
    115   ////////////
    116   WeaponState          currentState;                     //!< The State the weapon is in.
    117   float                stateTime;                        //!< how long the state has teken until now.
    118   float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState.
    119   SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction.
    120   Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
     133  private:
     134    bool nextActionValid() const;
    121135
    122   SoundBuffer*         fireSound;
    123   SoundSource*         weaponSource;
     136  protected:
     137    SoundSource*         soundSource;
     138    // it is all about energy
     139    float                energy;
     140    float                energyLoaded;
     141    float                energyMax;
     142    float                energyLoadedMax;
     143    float                minCharge;
     144    float                maxCharge;
    124145
    125   float                minCharge;
    126   float                maxCharge;
     146    ////////////
     147    // PHASES //
     148    ////////////
     149  private:
     150    WeaponState          currentState;                     //!< The State the weapon is in.
     151    WeaponAction         requestedAction;                  //!< An action to try to Engage after the currentState ends.
     152    float                stateDuration;                    //!< how long the state has taken until now.
     153    float                times[WS_STATE_COUNT];            //!< Times to stay in the different States @see WeaponState.
     154    Animation3D*         animation[WS_STATE_COUNT];        //!< Animations for all the States (you can say yourself on what part of the gun this animation acts).
     155    SoundBuffer*         soundBuffers[WA_ACTION_COUNT];    //!< SoundBuffers for all actions @see WeaponAction.
    127156
    128  private:
    129    bool                 enabled;                         //<! states if the weapon is enabled or not
    130    Projectile*          projectile;                      //<! the projectile used for this weapon
    131   //WeaponSound sound;
    132 };
     157
     158    bool                 hideInactive;                    //!< Hides the Weapon if it is inactive
     159
     160    bool                 active;                          //!< states wheter the weapon is enabled or not
     161    Projectile*          projectile;                      //!< the projectile used for this weapon
     162  };
    133163
    134164#endif /* _WEAPON_H */
  • orxonox/trunk/src/world_entities/weapons/weapon_manager.cc

    r4849 r4885  
    201201      if( w1 != NULL )
    202202      {
    203         w1->deactivate();
     203        w1->requestAction(WA_DEACTIVATE);
    204204        printf("deactivating %i,%i\n", j,lastConfID);
    205205      }
    206206      if( w2 != NULL)
    207207      {
    208         w2->activate();
     208        w2->requestAction(WA_ACTIVATE);
    209209        printf("activating %i,%i\n", j, this->currConfID);
    210210      }
     
    223223  {
    224224    firingWeapon = this->configs[this->currConfID].slots[i];
    225     if( firingWeapon != NULL) firingWeapon->fire();
     225    if( firingWeapon != NULL) firingWeapon->requestAction(WA_SHOOT);
    226226  }
    227227  this->crosshair->setRotationSpeed(500);
  • orxonox/trunk/src/world_entities/world_entity.cc

    r4836 r4885  
    3838    this->loadParams(root);
    3939
    40   this->bDraw = true;
     40  this->setVisibiliy(true);
    4141}
    4242
     
    6262
    6363/**
    64  *  loads a Model onto a WorldEntity
     64 * loads a Model onto a WorldEntity
    6565 * @param fileName the name of the model to load
    6666*/
     
    7979
    8080/**
    81  *  sets the character attributes of a worldentity
     81 * sets the character attributes of a worldentity
    8282 * @param character attributes
    83 
    84    these attributes don't have to be set, only use them, if you need them
     83 *
     84 * these attributes don't have to be set, only use them, if you need them
    8585*/
    8686void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr)
     
    8989
    9090/**
    91  *  gets the Character attributes of this worldentity
     91 * gets the Character attributes of this worldentity
    9292 * @returns character attributes
    9393*/
     
    9595{}
    9696
    97 
    98 /**
    99  *  set the WorldEntity's collision hull
    100  * @param newhull: a pointer to a completely assembled CollisionCluster
    101 
    102    Any previously assigned collision hull will be deleted on reassignment
    103 */
    104 /*
    105 void WorldEntity::setCollision (CollisionCluster* newhull)
    106 {
    107   if( newhull == NULL) return;
    108   if( collisioncluster != NULL) delete collisioncluster;
    109   collisioncluster = newhull;
    110 }
    111 */
    112 
    113 
    114 /**
    115   *  process draw function
    116 */
    117 void WorldEntity::processDraw ()
    118 {
    119 
    120 }
    121 
    122 /**
    123  *  sets the drawable state of this entity.
    124  * @param bDraw TRUE if draweable, FALSE otherwise
    125 */
    126 void WorldEntity::setDrawable (bool bDraw)
    127 {
    128   this->bDraw = bDraw;
    129 }
    130 
    131 
    13297/**
    13398 *  this function is called, when two entities collide
    13499 * @param entity: the world entity with whom it collides
    135 
    136    Implement behaviour like damage application or other miscellaneous collision stuff in this function
     100 *
     101 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
    137102*/
    138103void WorldEntity::collideWith(WorldEntity* entity)
     
    146111 * @param weapon: the laser/rocket/shoot that hits.
    147112 * @param loc: place where it is hit
    148 
    149    calculate the damage depending
     113 *
     114 * calculate the damage depending
    150115*/
    151116void WorldEntity::hit(WorldEntity* weapon, Vector* loc) {}
     
    154119/**
    155120 *  this is called immediately after the Entity has been constructed and initialized
    156 
    157    Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here.
    158    DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted.
     121 *
     122 * Put any initialisation code that requires knowledge of location (placement if the Entity is free) and owner of the entity here.
     123 * DO NOT place such code in the constructor, those variables are set AFTER the entity is constucted.
    159124*/
    160125void WorldEntity::postSpawn ()
     
    165130/**
    166131 *  this method is called by the world if the WorldEntity leaves valid gamespace
    167 
    168    For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a
    169    place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy).
     132 *
     133 * For free entities this means it left the Track boundaries. With bound entities it means its Location adresses a
     134 * place that is not in the world anymore. In both cases you might have to take extreme measures (a.k.a. call destroy).
    170135*/
    171136void WorldEntity::leftWorld ()
     
    177142 *  this method is called every frame
    178143 * @param time: the time in seconds that has passed since the last tick
    179 
    180    Handle all stuff that should update with time inside this method (movement, animation, etc.)
     144 *
     145 * Handle all stuff that should update with time inside this method (movement, animation, etc.)
    181146*/
    182147void WorldEntity::tick(float time)
     
    184149}
    185150
    186 
    187151/**
    188152 *  the entity is drawn onto the screen with this function
    189 
    190    This is a central function of an entity: call it to let the entity painted to the screen. Just override this function with whatever you want to be drawn.
     153 *
     154 * This is a central function of an entity: call it to let the entity painted to the screen.
     155 * Just override this function with whatever you want to be drawn.
    191156*/
    192157void WorldEntity::draw()
     
    228193  glPopMatrix();
    229194}
    230 
    231 /**
    232  *  this handles incoming command messages
    233  * @param cmd: a pointer to the incoming Command structure
    234 
    235    Put all code that handles Command messages here, this will mainly be called by the assigned CommandNode but can also be used
    236    to send commands from one WorldEntity to another.
    237 */
    238 void WorldEntity::command (Command* cmd)
    239 {
    240 }
  • orxonox/trunk/src/world_entities/world_entity.h

    r4836 r4885  
    11/*!
    2     \file world_entity.h
    3   * Definition of the basic WorldEntity
     2 * @file world_entity.h
     3 * Definition of the basic WorldEntity
    44*/
    55
     
    88
    99#include "p_node.h"
    10 #include "comincl.h"
    1110#include "resource_manager.h"
    1211#include "factory.h"
     
    1615
    1716
    18 
     17// FORWARD DECLARATION
    1918class CharacterAttributes;
    2019class SoundEngine;
     
    2322
    2423
    25 //! Basic class from which all interactive stuff in the world is derived from
     24//! Basis-class all interactive stuff in the world is derived from
    2625class WorldEntity : public PNode
    2726{
    28   friend class World;
    29 
    3027 public:
    3128  WorldEntity(const TiXmlElement* root = NULL);
     
    3532  void loadModel(const char* fileName);
    3633
    37   //void setCollision (CollisionCluster* newhull);
    3834
    3935  //void addAbility(Ability* ability);
    4036  //void removeAbility(Ability* ability);
    41   void setDrawable (bool bDraw);
     37
     38  /** @param visibility if the Entity should be visible (been draw) */
     39  void setVisibiliy (bool visibility) { this->bVisible = visibility; };
     40  /** @returns true if the entity is visible, false otherwise */
     41  bool isVisible() const { return this->bVisible; };
    4242  void setCharacterAttributes(CharacterAttributes* charAttr);
    4343  CharacterAttributes* getCharacterAttributes();
     
    4848  virtual void hit (WorldEntity* weapon, Vector* loc);
    4949  virtual void collideWith (WorldEntity* entity);
    50   virtual void command (Command* cmd);
    5150
    5251  /** @returns the Count of Faces on this WorldEntity */
    5352  virtual unsigned int getFaceCount () const { if (this->model) return this->model->getFaceCount(); else return 0; };
    5453
    55   void processDraw ();
     54  virtual void tick (float time);
    5655  virtual void draw ();
    5756  void drawBVTree(int depth, int drawMode);
    58   virtual void tick (float time);
    5957
    6058 protected:
    61   Model* model;                       //!< The model that should be loaded for this entity.
    62   CharacterAttributes* charAttr;      //!< the character attributes of a world_entity
    63   BVTree*             obbTree;       //!< this is the obb tree reference needed for collision detection
     59  Model*                  model;            //!< The model that should be loaded for this entity.
     60  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
     61  BVTree*                 obbTree;          //!< this is the obb tree reference needed for collision detection
    6462
    6563 private:
    66   bool bCollide;                      //!< If it should be considered for the collisiontest.
    67   bool bDraw;                         //!< If it should be visible.
    68 
    69 
    70 
    71   //CollisionCluster* collisioncluster; //!< The collision-Cluster of this entity.
     64  bool                    bCollide;         //!< If it should be considered for the collisiontest.
     65  bool                    bVisible;         //!< If it should be visible.
    7266};
    7367
Note: See TracChangeset for help on using the changeset viewer.