Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jul 2, 2006, 1:36:13 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the single_player_map branche back
merged with command:
svn merge -r8896:HEAD https://svn.orxonox.net/orxonox/branches/single_player_map .
no conflicts

Location:
trunk/src/world_entities/npcs
Files:
3 edited
4 copied

Legend:

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

    r8894 r9003  
    1717#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
    1818
     19#include "generic_npc.h"
     20
    1921
    2022#include "util/loading/factory.h"
     
    2830#include "loading/resource_manager.h"
    2931
    30 #include "generic_npc.h"
    31 
    32 #include "animation/animation3d.h"
    33 
    34 using namespace std;
    35 
    36 
    3732
    3833CREATE_FACTORY(GenericNPC, CL_GENERIC_NPC);
     
    4035#include "script_class.h"
    4136CREATE_SCRIPTABLE_CLASS(GenericNPC, CL_GENERIC_NPC,
    42                        // Move
    43                         addMethod("walkTo", ExecutorLua3ret<GenericNPC,float,float,float,float>(&GenericNPC::walkTo))
    44                         ->addMethod("setTime", ExecutorLua1<GenericNPC,float>(&GenericNPC::setTime))
    45                         ->addMethod("turnTo", ExecutorLua4ret<GenericNPC,bool,float,float,float,float>(&GenericNPC::turnTo))
    46                        // Display
     37                        // Move
     38                        addMethod("walkTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::walkTo))
     39                        ->addMethod("runTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::runTo))
     40                        ->addMethod("turnTo", ExecutorLua1<GenericNPC,float>(&GenericNPC::turnTo))
     41                        ->addMethod("finalGoalReached", ExecutorLua0ret<GenericNPC,bool>(&GenericNPC::finalGoalReached))
     42                        // Display
    4743                        ->addMethod("hide", ExecutorLua0<WorldEntity>(&WorldEntity::hide))
    4844                        ->addMethod("unhide", ExecutorLua0<WorldEntity>(&WorldEntity::unhide))
    49                        // Coordinates
     45                        // Coordinates
    5046                        ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
    5147                        ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
     
    5349                        ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor))
    5450                        ->addMethod("setAbsDir", ExecutorLua4<PNode,float,float,float,float>(&PNode::setAbsDir))
    55                            
     51
    5652                       );
    5753
     
    6258 */
    6359GenericNPC::GenericNPC(const TiXmlElement* root)
    64   : NPC(root)
     60    : NPC(root)
    6561{
    6662  this->init();
     
    7167
    7268
    73 GenericNPC::GenericNPC()
    74   : NPC(NULL)
    75 {
    76 
    77 }
    78 
    7969/**
    8070 * deconstructor
    8171 */
    8272GenericNPC::~GenericNPC ()
    83 {
    84   if( this->currentAnim != NULL)
    85     delete this->currentAnim;
    86 }
     73{}
    8774
    8875
     
    10087
    10188  time = 30.0f;
     89
    10290  // collision reaction registration
    103 //   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
     91  this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
    10492}
    10593
     
    128116
    129117
     118
     119/**
     120 * @returns the current animation number
     121 */
     122int GenericNPC::getAnimation()
     123{
     124  if( likely(this->getModel(0) != NULL))
     125    return ((InteractiveModel*)this->getModel(0))->getAnimation();
     126  else
     127    return -1;
     128}
     129
     130
     131
     132/**
     133 * @returns true if animation is finished
     134 */
     135bool GenericNPC::isAnimationFinished()
     136{
     137  if( likely(this->getModel(0) != NULL))
     138    return ((InteractiveModel*)this->getModel(0))->isAnimationFinished();
     139  else
     140    return false;
     141}
     142
     143
     144/**
     145 * sets the animation speed of this entity
     146 */
     147void GenericNPC::setAnimationSpeed(float speed)
     148{
     149  if( likely(this->getModel(0) != NULL))
     150    ((InteractiveModel*)this->getModel(0))->setAnimationSpeed(speed);
     151}
     152
     153
     154
    130155/**
    131156 * sets the animation of this npc
     
    146171 */
    147172void GenericNPC::playSound(std::string filename)
    148 {
    149 
    150 }
    151 
    152 
    153 /**
    154  * walt to
    155  * @param coordinate: coordinate to go to
    156  */
    157 float GenericNPC::walkTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    158 {
    159   Vector destCoor = Vector(x, y, z);
    160   Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
    161 
    162   // check if this is the current goal
    163   if( this->destCoor != destCoor || this->destDir != destDir)
    164   {
    165     this->destCoor = destCoor;
    166     this->destDir = destDir;
    167 
    168     //float time = 100.0f;
    169 
    170     if( this->currentAnim != NULL)
    171       delete this->currentAnim;
    172 
    173     this->currentAnim = new Animation3D(this);
    174     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f, ANIM_LINEAR, ANIM_LINEAR);
    175     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    176     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    177 
    178     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    179     this->currentAnim->play();
    180 
    181     this->setAnimation(RUN, MD2_ANIM_LOOP);
    182   }
    183 
    184   // calculate the distance
    185   Vector distance = this->getAbsCoor() - this->destCoor;
    186   return distance.len();
    187 }
    188 
    189 
    190 /**
    191  * walk to a specific place with direction
    192  *
    193  * @param x: x coordinate to go to
    194  * @param y: y coordinate to go to
    195  * @param z: z coordinate to go to
    196  *
    197  * without turning itself
    198  */
    199 float GenericNPC::walkTo(float x, float y, float z)
    200 {
    201   Quaternion q = this->getAbsDir();
    202 
    203   //printf("%s moving to %f, %f, %f \n",this->getName(),x,y,z);
    204 
    205   return this->walkTo(x, y, z, q.w, q.v.x, q.v.y, q.v.z);
    206 }
    207 
    208 /**
    209  * walk to a specific place with direction
    210  *
    211  * @param x: x coordinate to go to
    212  * @param y: y coordinate to go to
    213  * @param qu: angle to rotate
    214  * @param qx: x coordinate of rotation vector
    215  * @param qy: y coordinate of rotation vector
    216  * @param qz: z coordinate of rotation vector
    217  *
    218  */
    219 float GenericNPC::walkTo(float x, float y, float qu, float qx, float qy, float qz)
    220 {
    221   return this->walkTo(x, y, 0.0f, qu, qx, qy, qz);
    222 }
    223 
    224 
    225 /**
    226  * walk to a specific place with direction
    227  *
    228  * @param coor: vector place
    229  * @param dir: direction
    230  *
    231  */
    232 float GenericNPC::walkTo(const Vector& coor, const Quaternion& dir)
    233 {
    234   return this->walkTo(coor.x, coor.y, coor.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
    235 }
    236 
    237 
    238 
    239 /**
    240  * run to a specific place with direction
    241  *
    242  * @param x: x coordinate to go to
    243  * @param y: y coordinate to go to
    244  * @param z: z coordinate to go to
    245  * @param qu: angle to rotate
    246  * @param qx: x coordinate of rotation vector
    247  * @param qy: y coordinate of rotation vector
    248  * @param qz: z coordinate of rotation vector
    249  *
    250  */
    251 float GenericNPC::runTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    252 {
    253   Vector destCoor = Vector(x, y, z);
    254   Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
    255 
    256   // check if this is the current goal
    257   if( this->destCoor != destCoor || this->destDir != destDir)
    258   {
    259     this->destCoor = destCoor;
    260     this->destDir = destDir;
    261 
    262     float time = 5.0f;
    263 
    264     if( this->currentAnim != NULL)
    265       delete this->currentAnim;
    266 
    267     this->currentAnim = new Animation3D(this);
    268     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    269     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    270 
    271 
    272     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    273     this->currentAnim->play();
    274 
    275     this->setAnimation(RUN, MD2_ANIM_LOOP);
    276   }
    277 
    278   // calculate the distance
    279   Vector distance = this->getAbsCoor() - this->destCoor;
    280   return distance.len();
    281 }
    282 
    283 
    284 /**
    285  * run to a specific place with direction
    286  *
    287  * @param x: x coordinate to go to
    288  * @param y: y coordinate to go to
    289  * @param qu: angle to rotate
    290  * @param qx: x coordinate of rotation vector
    291  * @param qy: y coordinate of rotation vector
    292  * @param qz: z coordinate of rotation vector
    293  *
    294  */
    295 float GenericNPC::runTo(float x, float y, float qu, float qx, float qy, float qz)
    296 {
    297   this->runTo(x, y, 0.0f, qu, qx, qy, qz);
    298 }
    299 
    300 
    301 /**
    302  * run to a specific place with direction
    303  *
    304  * @param coor: vector place
    305  * @param dir: direction
    306  *
    307  */
    308 float GenericNPC::runTo(const Vector& coordinate, const Quaternion& dir)
    309 {
    310   this->runTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
    311 }
    312 
    313 
    314 /**
    315  * crouch to a specific place with direction
    316  *
    317  * @param x: x coordinate to go to
    318  * @param y: y coordinate to go to
    319  * @param z: z coordinate to go to
    320  * @param qu: angle to rotate
    321  * @param qx: x coordinate of rotation vector
    322  * @param qy: y coordinate of rotation vector
    323  * @param qz: z coordinate of rotation vector
    324  *
    325  */
    326 float GenericNPC::crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz)
    327 {
    328   Vector destCoor = Vector(x, y, z);
    329   Quaternion destDir = Quaternion(Vector(qx, qy, qz), qu);
    330 
    331   // check if this is the current goal
    332   if( this->destCoor != destCoor || this->destDir != destDir)
    333   {
    334     this->destCoor = destCoor;
    335     this->destDir = destDir;
    336 
    337 
    338     if( this->currentAnim != NULL)
    339       delete this->currentAnim;
    340 
    341     this->currentAnim = new Animation3D(this);
    342     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    343     this->currentAnim->addKeyFrame(this->destCoor, this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    344 
    345 
    346     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    347     this->currentAnim->play();
    348 
    349     this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
    350   }
    351 
    352   // calculate the distance
    353   Vector distance = this->getAbsCoor() - this->destCoor;
    354   return distance.len();
    355 }
    356 
    357 
    358 /**
    359  * couch to a specific place with direction
    360  *
    361  * @param x: x coordinate to go to
    362  * @param y: y coordinate to go to
    363  * @param qu: angle to rotate
    364  * @param qx: x coordinate of rotation vector
    365  * @param qy: y coordinate of rotation vector
    366  * @param qz: z coordinate of rotation vector
    367  *
    368  */
    369 float GenericNPC::crouchTo(float x, float y, float qu, float qx, float qy, float qz)
    370 {
    371   this->crouchTo(x, y, 0.0f, qu, qx, qy, qz);
    372 }
    373 
    374 
    375 
    376 /**
    377  * crouch to a specific place with direction
    378  *
    379  * @param coor: vector place
    380  * @param dir: direction
    381  *
    382  */
    383 float GenericNPC::crouchTo(const Vector& coordinate, const Quaternion& dir)
    384 {
    385   this->crouchTo(coordinate.x, coordinate.y, coordinate.z, dir.w, dir.v.x, dir.v.y, dir.v.z);
    386 }
     173{}
     174
    387175
    388176
     
    391179 */
    392180void GenericNPC::stop()
    393 {
    394   if( this->currentAnim != NULL)
    395   {
    396     this->currentAnim->stop();
    397     delete this->currentAnim;
    398     this->currentAnim = NULL;
    399 
     181{}
     182
     183
     184
     185void GenericNPC::initNPC()
     186{
     187  if (!this->behaviourList.empty())
     188  {
     189    GenericNPC::Anim currentAnimation = this->behaviourList.front();
     190
     191    switch(this->behaviourList.front().type)
     192    {
     193      case Walk:
     194      {
     195        if( this->getAnimation() != RUN)
     196          this->setAnimation(RUN, MD2_ANIM_LOOP);
     197
     198        Vector dir = (currentAnimation.v - this->getAbsCoor());
     199        dir.y = 0.0f;
     200        dir.getNormalized();
     201        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
     202
     203        this->setAnimationSpeed(0.5f);
     204      }
     205        break;
     206      case Run:
     207      {
     208        if( this->getAnimation() != RUN)
     209          this->setAnimation(RUN, MD2_ANIM_LOOP);
     210
     211        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     212        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
     213
     214        this->setAnimationSpeed(1.0f);
     215      }
     216        break;
     217      case Crouch:
     218      {
     219        if( this->getAnimation() != CROUCH_WALK)
     220          this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
     221
     222        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     223        this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)));
     224
     225        this->setAnimationSpeed(1.0f);
     226      }
     227        break;
     228      case LookAt:
     229        if( this->getAnimation() != STAND)
     230          this->setAnimation(STAND, MD2_ANIM_LOOP);
     231        break;
     232      case Shoot:
     233        if( this->getAnimation() != STAND)
     234          this->setAnimation(STAND, MD2_ANIM_LOOP);
     235        break;
     236
     237      default:
     238        if( this->getAnimation() != STAND)
     239          this->setAnimation(STAND, MD2_ANIM_LOOP);
     240        break;
     241
     242    }
     243  }
     244}
     245
     246
     247void GenericNPC::nextStep()
     248{
     249  if (!this->behaviourList.empty())
     250    this->behaviourList.pop_front();
     251  else
     252    return;
     253
     254
     255  if (!this->behaviourList.empty())
     256  {
     257    GenericNPC::Anim currentAnimation = this->behaviourList.front();
     258
     259    switch( currentAnimation.type)
     260    {
     261      case Walk:
     262      {
     263        if( this->getAnimation() != RUN)
     264          this->setAnimation(RUN, MD2_ANIM_LOOP);
     265
     266        Vector dir = (currentAnimation.v - this->getAbsCoor());
     267        dir.y = 0.0f;
     268        dir.getNormalized();
     269        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
     270
     271        this->setAnimationSpeed(0.5f);
     272      }
     273        break;
     274      case Run:
     275      {
     276        if( this->getAnimation() != RUN)
     277          this->setAnimation(RUN, MD2_ANIM_LOOP);
     278
     279        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     280        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
     281
     282        this->setAnimationSpeed(1.0f);
     283      }
     284        break;
     285      case Crouch:
     286      {
     287        if( this->getAnimation() != CROUCH_WALK)
     288          this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
     289
     290        Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized();
     291        this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0);
     292
     293        this->setAnimationSpeed(1.0f);
     294      }
     295        break;
     296      case LookAt:
     297      {
     298        if( this->getAnimation() != STAND)
     299          this->setAnimation(STAND, MD2_ANIM_LOOP);
     300      }
     301        break;
     302      case Shoot:
     303        if( this->getAnimation() != STAND)
     304        this->setAnimation(STAND, MD2_ANIM_LOOP);
     305        break;
     306
     307      default:
     308        if( this->getAnimation() != STAND)
     309        this->setAnimation(STAND, MD2_ANIM_LOOP);
     310        break;
     311
     312    }
     313  }
     314  else
     315  {
    400316    this->setAnimation(STAND, MD2_ANIM_LOOP);
    401317  }
    402318}
     319
     320
     321
     322
     323void GenericNPC::walkTo(const Vector& coordinate)
     324{
     325
     326  GenericNPC::Anim anim;
     327  anim.v = coordinate;
     328  anim.type = Walk;
     329  anim.speed = 30.0f;
     330
     331  if( this->behaviourList.empty())
     332  {
     333    this->behaviourList.push_back(anim);
     334    this->initNPC();
     335  }
     336  else
     337    this->behaviourList.push_back(anim);
     338}
     339
     340void GenericNPC::walkTo(float x, float y, float z)
     341{
     342  //printf("Walking to %f, %f, %f \n",x,y,z);
     343  this->walkTo(Vector(x,y,z));
     344
     345}
     346
     347/* running functions */
     348void GenericNPC::runTo(const Vector& coordinate)
     349{
     350  GenericNPC::Anim anim;
     351  anim.v = coordinate;
     352  anim.type = Run;
     353  anim.speed = 60.0f;
     354
     355  if( this->behaviourList.empty())
     356  {
     357    this->behaviourList.push_back(anim);
     358    this->initNPC();
     359  }
     360  else
     361    this->behaviourList.push_back(anim);
     362}
     363
     364void GenericNPC::runTo(float x, float y, float z)
     365{
     366  this->runTo(Vector(x,y,z));
     367}
     368
     369/* couching functinos */
     370void GenericNPC::crouchTo(const Vector& coordinate)
     371{
     372  GenericNPC::Anim anim;
     373  anim.v = coordinate;
     374  anim.type = Crouch;
     375
     376  if( this->behaviourList.empty())
     377  {
     378    this->behaviourList.push_back(anim);
     379    this->initNPC();
     380  }
     381  else
     382    this->behaviourList.push_back(anim);
     383}
     384void GenericNPC::crouchTo(float x, float y, float z)
     385{
     386  this->crouchTo(Vector(x,y,z));
     387}
     388
     389
     390
     391void GenericNPC::turnTo(float degreeInY)
     392{
     393  GenericNPC::Anim anim;
     394  anim.q = Quaternion(Vector(0,1,0), degreeInY);
     395  anim.type = TurnTo;
     396
     397  if( this->behaviourList.empty())
     398  {
     399    this->behaviourList.push_back(anim);
     400    this->initNPC();
     401  }
     402  else
     403    this->behaviourList.push_back(anim);
     404}
     405
    403406
    404407
     
    407410 * @param worldEntity: the worldentity to look at
    408411 */
    409 float GenericNPC::lookAt(WorldEntity* worldEntity)
    410 {}
    411 
    412 
    413 /**
    414  * turns to a given direction
    415  */
    416 bool GenericNPC::turnTo(float qu, float qx, float qy, float qz)
    417 {
    418   Quaternion destDir = Quaternion(Vector(qx, qy, qz).getNormalized(), qu);
    419 
    420   printf("Turning: %f, %f, %f, %f \n",qu,qx,qy,qz);
    421   // check if this is the current goal
    422   if( this->destDir != destDir)
    423   {
    424 //     if( this->currentAnim != NULL)
    425 //       this->currentAnim->stop();
    426 //
    427     PRINTF(0)("SET ANIMATION\n");
    428     this->destDir = destDir;
    429 //
    430 
    431 
    432     if( this->currentAnim != NULL)
    433       delete this->currentAnim;
    434 
    435     this->setAbsDir(destDir);
    436 /*
    437     this->currentAnim = new Animation3D(this);
    438     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), 0.0f, ANIM_LINEAR, ANIM_LINEAR);
    439     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->getAbsDir(), time, ANIM_LINEAR, ANIM_LINEAR);
    440     this->currentAnim->addKeyFrame(this->getAbsCoor(), this->destDir, time, ANIM_LINEAR, ANIM_LINEAR);
    441 
    442 
    443     this->currentAnim->setInfinity(ANIM_INF_CONSTANT);
    444     this->currentAnim->play();*/
    445 
    446     this->setAnimation(STAND, MD2_ANIM_LOOP);
    447   }
    448 
    449   // calculate the distance
    450   Vector distance = this->getAbsCoor() - this->destCoor;
    451   return distance.len();
    452 }
     412void GenericNPC::lookAt(WorldEntity* worldEntity)
     413{
     414  GenericNPC::Anim anim;
     415  anim.entity = worldEntity;
     416  anim.type = LookAt;
     417
     418  if( this->behaviourList.empty())
     419  {
     420    this->behaviourList.push_back(anim);
     421    this->initNPC();
     422  }
     423  else
     424    this->behaviourList.push_back(anim);
     425}
     426
    453427
    454428
     
    459433 * @param dialogNr: sound nr to be played (from the xml load tags)
    460434 */
    461 float GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)
     435void GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)
    462436{}
    463437
     
    483457 * @param time: time in seconds expirded since the last tick
    484458 */
    485 void GenericNPC::tick (float time)
     459void GenericNPC::tick (float dt)
    486460{
    487461  if( likely(this->getModel(0) != NULL))
    488     ((InteractiveModel*)this->getModel(0))->tick(time);
     462    ((InteractiveModel*)this->getModel(0))->tick(dt);
     463
     464
     465  if (!this->behaviourList.empty())
     466  {
     467    GenericNPC::Anim currentAnimation = this->behaviourList.front();
     468
     469    switch( currentAnimation.type)
     470    {
     471      case Walk:
     472        {
     473          Vector dest = currentAnimation.v - this->getAbsCoor();
     474          if (dest.len() < .5)
     475            this->nextStep();
     476          else
     477          {
     478            dest.y = 0.0f;
     479            this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
     480
     481          }
     482        }
     483        break;
     484
     485      case Run:
     486      {
     487        Vector dest = currentAnimation.v - this->getAbsCoor();
     488        if (dest.len() < .5)
     489          this->nextStep();
     490        else
     491        {
     492          this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
     493        }
     494      }
     495      break;
     496
     497      case Crouch:
     498      {
     499        Vector dest = currentAnimation.v - this->getAbsCoor();
     500        if (dest.len() < .5)
     501          this->nextStep();
     502        else
     503        {
     504          this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt);
     505        }
     506      }
     507      break;
     508
     509      case TurnTo:
     510        //Quaternion direction = this->
     511        break;
     512
     513      case LookAt:
     514        break;
     515
     516      case Shoot:
     517        break;
     518
     519      default:
     520        break;
     521
     522    }
     523  }
     524
     525  // physical falling of the player
     526  if( !this->isOnGround())
     527  {
     528    this->fallVelocity += 300.0f * dt;
     529    velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity;
     530   // PRINTF(0)("%s is not on ground\n", this->getName());
     531  }
     532  else
     533  {
     534    this->fallVelocity = 0.0f;
     535  }
     536
     537  this->shiftCoor(Vector(0, -this->fallVelocity * dt,0));
    489538
    490539}
     
    495544{
    496545  int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX);
     546
     547  this->setAnimationSpeed(1.0f);
    497548
    498549  if( randi == 1)
  • trunk/src/world_entities/npcs/generic_npc.h

    r8894 r9003  
    1010#include "npc.h"
    1111
    12 #include <string>
    1312
    1413#include "sound_source.h"
    15 
    16 #include "vector.h"
    17 #include "quaternion.h"
    18 
    1914
    2015namespace OrxSound{ class SoundSource; }
     
    2722class GenericNPC : public NPC
    2823{
     24
     25
    2926 public:
    30   GenericNPC();
    31   GenericNPC(const TiXmlElement* root);
     27  GenericNPC(const TiXmlElement* root = NULL);
    3228  virtual ~GenericNPC ();
    3329
    34   void init();
    3530  virtual void loadParams(const TiXmlElement* root);
    3631
    37   void setAnimation(int animationIndex, int animPlaybackMode);
    3832  /** sets the sound volume to @param vol: volume of the sound */
    3933  inline void setVolume(float vol) { this->soundVolume = vol; }
    4034
    4135
    42   /* npc controlling functions */
    4336
     37  bool finalGoalReached() { return this->behaviourList.empty(); };
     38
     39  /* npc controlling functions to be Queued */
    4440  /* walking functions */
    45   float walkTo(const Vector& coordinate, const Quaternion& dir);
    46   float walkTo(float x, float y, float z);
    47   float walkTo(float x, float y, float z, float qu, float qx, float qy, float qz);
    48   float walkTo(float x, float y, float qu, float qx, float qy, float qz);
     41  void walkTo(const Vector& coordinate);
     42  void walkTo(float x, float y, float z);
    4943
    5044  /* running functions */
    51   float runTo(const Vector& coordinate, const Quaternion& dir);
    52   float runTo(float x, float y, float z, float qu, float qx, float qy, float qz);
    53   float runTo(float x, float y, float qu, float qx, float qy, float qz);
     45  void runTo(const Vector& coordinate);
     46  void runTo(float x, float y, float z);
    5447
    5548  /* couching functinos */
    56   float crouchTo(const Vector& coordinate, const Quaternion& dir);
    57   float crouchTo(float x, float y, float z, float qu, float qx, float qy, float qz);
    58   float crouchTo(float x, float y, float qu, float qx, float qy, float qz);
     49  void crouchTo(const Vector& coordinate);
     50  void crouchTo(float x, float y, float z);
    5951
    6052  /* stopping the movement */
    6153  void stop();
     54  void nextStep();
    6255
    6356  /* some oriantation functions */
    64   float lookAt(WorldEntity* worldEntity);
    65   bool turnTo(float qu, float qx, float qy, float qz);
     57  void lookAt(WorldEntity* worldEntity);
     58  void turnTo(float qu, float qx, float qy, float qz);
     59  void turnTo(float degreeInY);
    6660
    6761  /* talking funcitons*/
    68   float talkTo(WorldEntity* worldEntity, int dialogNr);
     62  void talkTo(WorldEntity* worldEntity, int dialogNr);
    6963
    7064  /* shooting functions */
     
    7771  void playSound(int i);
    7872
    79   void setTime(float newTime){ this->time = newTime; };
    80  
    8173  virtual void tick (float time);
    8274
     
    8476  void destroy();
    8577
     78  private:
     79    void init();
     80
     81    void setAnimation(int animationIndex, int animPlaybackMode);
     82    int getAnimation();
     83    bool isAnimationFinished();
     84    void setAnimationSpeed(float speed);
     85
     86    void initNPC();
     87
    8688
    8789 private:
     90
     91   typedef enum {
     92    Walk,
     93    Run,
     94    Crouch,
     95    Jump,
     96    TurnTo,
     97    LookAt,
     98    TalkTo,
     99
     100    Shoot,
     101
     102
     103   } AnimType;
     104
     105   typedef struct Anim
     106   {
     107     Vector        v;
     108     Quaternion    q;
     109
     110
     111     WorldEntity*  entity;
     112     float         speed;
     113
     114
     115     AnimType      type;
     116   };
     117   typedef std::list<GenericNPC::Anim>     genNPCAnimList;
     118
     119
     120
    88121   OrxSound::SoundSource                   soundSource;
    89122   OrxSound::SoundBuffer*                  soundBuffer;
    90123   float                                   soundVolume;
    91124
     125   std::list<GenericNPC::Anim>             behaviourList;
    92126   Vector                                  destCoor;
    93127   Quaternion                              destDir;
     
    95129   Animation3D*                            currentAnim;
    96130   float                                   time;          //!< Duration of the action
     131   float                                   fallVelocity;
    97132};
    98133
  • trunk/src/world_entities/npcs/npc.cc

    r8894 r9003  
    2929
    3030  this->toList(OM_GROUP_00);
     31
    3132}
    3233
Note: See TracChangeset for help on using the changeset viewer.