Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9061 in orxonox.OLD for trunk/src/world_entities/npcs


Ignore:
Timestamp:
Jul 3, 2006, 6:39:10 PM (18 years ago)
Author:
patrick
Message:

merged the single_player branche to trunk

Location:
trunk/src/world_entities/npcs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/npcs/generic_npc.cc

    r9027 r9061  
    4040                        ->addMethod("turnTo", ExecutorLua1<GenericNPC,float>(&GenericNPC::turnTo))
    4141                        ->addMethod("finalGoalReached", ExecutorLua0ret<GenericNPC,bool>(&GenericNPC::finalGoalReached))
     42                        ->addMethod("stop", ExecutorLua0<GenericNPC>(&GenericNPC::stop))
     43                        ->addMethod("resume", ExecutorLua0<GenericNPC>(&GenericNPC::resume))
     44                        ->addMethod("playAnimation", ExecutorLua2<GenericNPC,int,int>(&GenericNPC::playAnimation))
    4245                        // Display
    4346                        ->addMethod("hide", ExecutorLua0<WorldEntity>(&WorldEntity::hide))
     
    4952                        ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
    5053                        ->addMethod("setAbsDir", ExecutorLua4<PNode,float,float,float,float>(&PNode::setAbsDir))
    51 
    5254                       );
    5355
     
    8890  time = 30.0f;
    8991
     92  this->behaviourList = new std::list<GenericNPC::Anim>;
     93
    9094  // collision reaction registration
    9195//   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
     
    170174 * @param filename: name of the file
    171175 */
    172 void GenericNPC::playSound(std::string filename)
     176void GenericNPC::playSound(const std::string& filename)
    173177{}
    174178
     
    179183 */
    180184void GenericNPC::stop()
    181 {}
    182 
    183 
    184 
     185{
     186  this->animationStack.push(this->behaviourList);
     187  this->behaviourList = new std::list<GenericNPC::Anim>;
     188}
     189
     190
     191/**
     192 * continue the generic animation
     193 */
     194void GenericNPC::resume()
     195{
     196  //if()
     197  delete this->behaviourList;
     198  this->behaviourList = this->animationStack.top();
     199  this->animationStack.pop();
     200}
     201
     202
     203/**
     204 * each animation has to be initialized here
     205 */
    185206void GenericNPC::initNPC()
    186207{
    187 
    188   this->unsubscribeReaction();
    189 
    190   if (!this->behaviourList.empty())
    191   {
    192     GenericNPC::Anim currentAnimation = this->behaviourList.front();
    193 
    194     switch(this->behaviourList.front().type)
     208  if (!this->behaviourList->empty())
     209  {
     210    GenericNPC::Anim currentAnimation = this->behaviourList->front();
     211
     212    switch(this->behaviourList->front().type)
    195213    {
    196214      case Walk:
     
    213231
    214232        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     233        dir.y = 0.0f;
     234        dir.getNormalized();
    215235        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
    216236
     
    224244
    225245        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     246        dir.y = 0.0f;
     247        dir.getNormalized();
    226248        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
    227249
     
    250272void GenericNPC::nextStep()
    251273{
    252   if (!this->behaviourList.empty())
    253     this->behaviourList.pop_front();
     274  if (!this->behaviourList->empty())
     275    this->behaviourList->pop_front();
    254276  else
    255277    return;
    256278
    257279
    258   if (!this->behaviourList.empty())
    259   {
    260     GenericNPC::Anim currentAnimation = this->behaviourList.front();
     280  if (!this->behaviourList->empty())
     281  {
     282    GenericNPC::Anim currentAnimation = this->behaviourList->front();
    261283
    262284    switch( currentAnimation.type)
     
    266288        if( this->getAnimation() != RUN)
    267289          this->setAnimation(RUN, MD2_ANIM_LOOP);
     290
    268291
    269292        Vector dir = (currentAnimation.v - this->getAbsCoor());
     
    281304
    282305        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     306        dir.y = 0.0f;
     307        dir.getNormalized();
    283308        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
    284309
     
    292317
    293318        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     319        dir.y = 0.0f;
     320        dir.getNormalized();
    294321        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
    295322
     
    332359  anim.speed = 30.0f;
    333360
    334   if( this->behaviourList.empty())
    335   {
    336     this->behaviourList.push_back(anim);
     361  if( this->behaviourList->empty())
     362  {
     363    this->behaviourList->push_back(anim);
    337364    this->initNPC();
    338365  }
    339366  else
    340     this->behaviourList.push_back(anim);
     367    this->behaviourList->push_back(anim);
    341368}
    342369
     
    356383  anim.speed = 60.0f;
    357384
    358   if( this->behaviourList.empty())
    359   {
    360     this->behaviourList.push_back(anim);
     385  if( this->behaviourList->empty())
     386  {
     387    this->behaviourList->push_back(anim);
    361388    this->initNPC();
    362389  }
    363390  else
    364     this->behaviourList.push_back(anim);
     391    this->behaviourList->push_back(anim);
    365392}
    366393
     
    377404  anim.type = Crouch;
    378405
    379   if( this->behaviourList.empty())
    380   {
    381     this->behaviourList.push_back(anim);
     406  if( this->behaviourList->empty())
     407  {
     408    this->behaviourList->push_back(anim);
    382409    this->initNPC();
    383410  }
    384411  else
    385     this->behaviourList.push_back(anim);
     412    this->behaviourList->push_back(anim);
    386413}
    387414void GenericNPC::crouchTo(float x, float y, float z)
     
    398425  anim.type = TurnTo;
    399426
    400   if( this->behaviourList.empty())
    401   {
    402     this->behaviourList.push_back(anim);
     427  if( this->behaviourList->empty())
     428  {
     429    this->behaviourList->push_back(anim);
    403430    this->initNPC();
    404431  }
    405432  else
    406     this->behaviourList.push_back(anim);
     433    this->behaviourList->push_back(anim);
    407434}
    408435
     
    419446  anim.type = LookAt;
    420447
    421   if( this->behaviourList.empty())
    422   {
    423     this->behaviourList.push_back(anim);
     448  if( this->behaviourList->empty())
     449  {
     450    this->behaviourList->push_back(anim);
    424451    this->initNPC();
    425452  }
    426453  else
    427     this->behaviourList.push_back(anim);
     454    this->behaviourList->push_back(anim);
    428455}
    429456
     
    466493
    467494
    468   if (!this->behaviourList.empty())
    469   {
    470     GenericNPC::Anim currentAnimation = this->behaviourList.front();
     495  if (!this->behaviourList->empty())
     496  {
     497    GenericNPC::Anim currentAnimation = this->behaviourList->front();
    471498
    472499    switch( currentAnimation.type)
     
    475502        {
    476503          Vector dest = currentAnimation.v - this->getAbsCoor();
     504          dest.y = 0.0f;
    477505          if (dest.len() < .5)
    478506          {
     
    481509          else
    482510          {
    483             dest.y = 0.0f;
    484             this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
     511            Vector move = dest.getNormalized() * currentAnimation.speed * dt;
     512            this->shiftCoor(move);
    485513          }
    486514        }
     
    528556
    529557  // physical falling of the player
    530 //   if( !this->isOnGround())
    531 //   {
    532 //     this->fallVelocity += 300.0f * dt;
    533 //     velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity;
    534 //    // PRINTF(0)("%s is not on ground\n", this->getName());
    535 //     this->shiftCoor(Vector(0, -this->fallVelocity * dt,0));
    536 //   }
    537 //   else
    538 //   {
    539 //     this->fallVelocity = 0.0f;
    540 //   }
    541 
    542 
     558  if( !this->isOnGround())
     559  {
     560    this->fallVelocity += 300.0f * dt;
     561    //velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity;
     562   // PRINTF(0)("%s is not on ground\n", this->getName());
     563    this->shiftCoor(Vector(0, -this->fallVelocity * dt,0));
     564
     565  }
     566  else
     567  {
     568    this->fallVelocity = 0.0f;
     569  }
    543570
    544571}
  • trunk/src/world_entities/npcs/generic_npc.h

    r9003 r9061  
    1212
    1313#include "sound_source.h"
     14
     15#include <stack>
     16
    1417
    1518namespace OrxSound{ class SoundSource; }
     
    3538
    3639
    37   bool finalGoalReached() { return this->behaviourList.empty(); };
     40  bool finalGoalReached() { return this->behaviourList->empty(); };
    3841
    3942  /* npc controlling functions to be Queued */
     
    5255  /* stopping the movement */
    5356  void stop();
     57  void resume();
    5458  void nextStep();
    5559
     
    6872  /* some generic control funtions */
    6973  void playAnimation(int animationIndex, int animPlaybackMode);
    70   void playSound(std::string filename);
    71   void playSound(int i);
     74  void playSound(const std::string& filename);
    7275
    7376  virtual void tick (float time);
     
    123126   float                                   soundVolume;
    124127
    125    std::list<GenericNPC::Anim>             behaviourList;
     128   std::list<GenericNPC::Anim>*            behaviourList;
     129   std::stack<std::list<GenericNPC::Anim>*> animationStack;
    126130   Vector                                  destCoor;
    127131   Quaternion                              destDir;
Note: See TracChangeset for help on using the changeset viewer.