Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 29, 2006, 4:30:32 PM (18 years ago)
Author:
bensch
Message:

walk should work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/single_player_map/src/world_entities/npcs/generic_npc.cc

    r8909 r8913  
    3535#include "script_class.h"
    3636CREATE_SCRIPTABLE_CLASS(GenericNPC, CL_GENERIC_NPC,
    37                        // Move
     37                        // Move
    3838                        addMethod("walkTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::walkTo))
    3939                        ->addMethod("turnTo", ExecutorLua1<GenericNPC,float>(&GenericNPC::turnTo))
    40                        // Display
     40                        // Display
    4141                        ->addMethod("hide", ExecutorLua0<WorldEntity>(&WorldEntity::hide))
    4242                        ->addMethod("unhide", ExecutorLua0<WorldEntity>(&WorldEntity::unhide))
    43                        // Coordinates
     43                        // Coordinates
    4444                        ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX))
    4545                        ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY))
     
    5656 */
    5757GenericNPC::GenericNPC(const TiXmlElement* root)
    58   : NPC(root)
     58    : NPC(root)
    5959{
    6060  this->init();
     
    6969 */
    7070GenericNPC::~GenericNPC ()
    71 {
    72 }
     71{}
    7372
    7473
     
    8786  time = 30.0f;
    8887  // collision reaction registration
    89 //   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
     88  //   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
    9089}
    9190
     
    132131 */
    133132void GenericNPC::playSound(std::string filename)
    134 {
    135 
    136 }
     133{}
    137134
    138135
     
    142139 */
    143140void GenericNPC::stop()
    144 {
    145 
    146 }
    147 
    148 
    149 void GenericNPC::walkTo(const Vector& coordinate)
    150 {
    151   GenericNPC::Anim anim;
    152   anim.v = coordinate;
    153   anim.type = Walk;
    154 
    155   this->behaviourList.push_back(anim);
    156 }
    157 
    158 void GenericNPC::walkTo(float x, float y, float z)
    159 {
    160   this->walkTo(Vector(x,y,z));
    161 
    162 }
    163 
    164 /* running functions */
    165 void GenericNPC::runTo(const Vector& coordinate)
    166 {
    167   GenericNPC::Anim anim;
    168   anim.v = coordinate;
    169   anim.type = Run;
    170 
    171   this->behaviourList.push_back(anim);
    172 }
    173 
    174 void GenericNPC::runTo(float x, float y, float z)
    175 {
    176   this->runTo(Vector(x,y,z));
    177 }
    178 
    179 /* couching functinos */
    180 void GenericNPC::crouchTo(const Vector& coordinate)
    181 {
    182   GenericNPC::Anim anim;
    183   anim.v = coordinate;
    184   anim.type = Crouch;
    185 
    186   this->behaviourList.push_back(anim);
    187 }
    188 void GenericNPC::crouchTo(float x, float y, float z)
    189 {
    190   this->crouchTo(Vector(x,y,z));
    191 }
    192 
    193 
    194 
    195 void GenericNPC::turnTo(float degreeInY)
    196 {
    197   GenericNPC::Anim anim;
    198   anim.q = Quaternion(Vector(0,1,0), degreeInY);
    199   anim.type = TurnTo;
    200 
    201   this->behaviourList.push_back(anim);
    202 }
    203 
    204 
    205 
    206 /**
    207  * lookat a world entity
    208  * @param worldEntity: the worldentity to look at
    209  */
    210 void GenericNPC::lookAt(WorldEntity* worldEntity)
    211 {
    212   GenericNPC::Anim anim;
    213   anim.entity = worldEntity;
    214   anim.type = LookAt;
    215 
    216   this->behaviourList.push_back(anim);
    217 }
    218 
    219 
    220 
    221 
    222 /**
    223  * talk to a world entity and play a sound/music/voice
    224  * @param worldEntity: entity
    225  * @param dialogNr: sound nr to be played (from the xml load tags)
    226  */
    227 void GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)
    228 {}
    229 
    230 
    231 /**
    232  * world entity to shoot at if there is any weapon on the npc
    233  * @param entity: entity to shoot entity
    234  */
    235 void GenericNPC::shootAt(WorldEntity* entity)
    236 {}
    237 
    238 
    239 
    240 
    241 
    242 
    243 
    244 
    245 
    246 
    247 /**
    248  * tick this world entity
    249  * @param time: time in seconds expirded since the last tick
    250  */
    251 void GenericNPC::tick (float time)
    252 {
    253   if( likely(this->getModel(0) != NULL))
    254     ((InteractiveModel*)this->getModel(0))->tick(time);
    255 
     141{}
     142
     143void GenericNPC::nextStep()
     144{
     145  if (!this->behaviourList.empty())
     146    this->behaviourList.pop_front();
     147  else
     148    return;
    256149
    257150  if (!this->behaviourList.empty())
     
    260153    {
    261154      case Walk:
     155        this->setAnimation(RUN, MD2_ANIM_LOOP);
    262156        break;
    263157      case Run:
     158        this->setAnimation(RUN, MD2_ANIM_LOOP);
    264159        break;
    265160      case Crouch:
     161        this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP);
    266162        break;
    267163      case LookAt:
     164        this->setAnimation(STAND, MD2_ANIM_LOOP);
     165
    268166        break;
    269167      case Shoot:
     168        this->setAnimation(STAND, MD2_ANIM_LOOP);
     169        break;
     170
     171      default:
     172        this->setAnimation(STAND, MD2_ANIM_LOOP);
     173        break;
     174
     175    }
     176  }
     177  else
     178  {
     179    this->setAnimation(STAND, MD2_ANIM_LOOP);
     180  }
     181}
     182
     183
     184void GenericNPC::walkTo(const Vector& coordinate)
     185{
     186  GenericNPC::Anim anim;
     187  anim.v = coordinate;
     188  anim.type = Walk;
     189
     190  this->behaviourList.push_back(anim);
     191}
     192
     193void GenericNPC::walkTo(float x, float y, float z)
     194{
     195  this->walkTo(Vector(x,y,z));
     196
     197}
     198
     199/* running functions */
     200void GenericNPC::runTo(const Vector& coordinate)
     201{
     202  GenericNPC::Anim anim;
     203  anim.v = coordinate;
     204  anim.type = Run;
     205
     206  this->behaviourList.push_back(anim);
     207}
     208
     209void GenericNPC::runTo(float x, float y, float z)
     210{
     211  this->runTo(Vector(x,y,z));
     212}
     213
     214/* couching functinos */
     215void GenericNPC::crouchTo(const Vector& coordinate)
     216{
     217  GenericNPC::Anim anim;
     218  anim.v = coordinate;
     219  anim.type = Crouch;
     220
     221  this->behaviourList.push_back(anim);
     222}
     223void GenericNPC::crouchTo(float x, float y, float z)
     224{
     225  this->crouchTo(Vector(x,y,z));
     226}
     227
     228
     229
     230void GenericNPC::turnTo(float degreeInY)
     231{
     232  GenericNPC::Anim anim;
     233  anim.q = Quaternion(Vector(0,1,0), degreeInY);
     234  anim.type = TurnTo;
     235
     236  this->behaviourList.push_back(anim);
     237}
     238
     239
     240
     241/**
     242 * lookat a world entity
     243 * @param worldEntity: the worldentity to look at
     244 */
     245void GenericNPC::lookAt(WorldEntity* worldEntity)
     246{
     247  GenericNPC::Anim anim;
     248  anim.entity = worldEntity;
     249  anim.type = LookAt;
     250
     251  this->behaviourList.push_back(anim);
     252}
     253
     254
     255
     256
     257/**
     258 * talk to a world entity and play a sound/music/voice
     259 * @param worldEntity: entity
     260 * @param dialogNr: sound nr to be played (from the xml load tags)
     261 */
     262void GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr)
     263{}
     264
     265
     266/**
     267 * world entity to shoot at if there is any weapon on the npc
     268 * @param entity: entity to shoot entity
     269 */
     270void GenericNPC::shootAt(WorldEntity* entity)
     271{}
     272
     273
     274
     275
     276
     277
     278
     279
     280
     281
     282/**
     283 * tick this world entity
     284 * @param time: time in seconds expirded since the last tick
     285 */
     286void GenericNPC::tick (float time)
     287{
     288  if( likely(this->getModel(0) != NULL))
     289    ((InteractiveModel*)this->getModel(0))->tick(time);
     290
     291
     292  if (!this->behaviourList.empty())
     293  {
     294    switch(this->behaviourList.front().type)
     295    {
     296      case Walk:
     297        Vector dir = this->getAbsCoor() - this->behaviourList.front().v;
     298        if (dir.len() < .5)
     299          this->nextStep();
     300        else
     301        {
     302          this->shiftCoor(dir.normalize() * dt);
     303        }
     304        break;
     305      case Run:
     306        break;
     307      case Crouch:
     308        break;
     309      case LookAt:
     310        break;
     311      case Shoot:
     312        break;
     313
     314      default:
    270315        break;
    271316
Note: See TracChangeset for help on using the changeset viewer.