[8514] | 1 | |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | orxonox - the future of 3D-vertical-scrollers |
---|
| 5 | |
---|
| 6 | Copyright (C) 2004 orx |
---|
| 7 | |
---|
| 8 | This program is free software; you can redistribute it and/or modify |
---|
| 9 | it under the terms of the GNU General Public License as published by |
---|
| 10 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 11 | any later version. |
---|
| 12 | |
---|
| 13 | ### File Specific |
---|
| 14 | main-programmer: Patrick Boenzli |
---|
| 15 | co-programmer: |
---|
| 16 | */ |
---|
| 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
| 18 | |
---|
[9003] | 19 | #include "generic_npc.h" |
---|
[8514] | 20 | |
---|
[9003] | 21 | |
---|
[8514] | 22 | #include "util/loading/factory.h" |
---|
| 23 | #include "util/loading/load_param.h" |
---|
| 24 | |
---|
| 25 | #include "interactive_model.h" |
---|
| 26 | #include "md2/md2Model.h" |
---|
| 27 | |
---|
[8516] | 28 | #include "sound_buffer.h" |
---|
| 29 | |
---|
| 30 | #include "loading/resource_manager.h" |
---|
| 31 | |
---|
[8514] | 32 | |
---|
| 33 | CREATE_FACTORY(GenericNPC, CL_GENERIC_NPC); |
---|
| 34 | |
---|
[8894] | 35 | #include "script_class.h" |
---|
| 36 | CREATE_SCRIPTABLE_CLASS(GenericNPC, CL_GENERIC_NPC, |
---|
[9003] | 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 |
---|
[8894] | 43 | ->addMethod("hide", ExecutorLua0<WorldEntity>(&WorldEntity::hide)) |
---|
| 44 | ->addMethod("unhide", ExecutorLua0<WorldEntity>(&WorldEntity::unhide)) |
---|
[9003] | 45 | // Coordinates |
---|
[8894] | 46 | ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX)) |
---|
| 47 | ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY)) |
---|
| 48 | ->addMethod("getAbsCoorZ", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorZ)) |
---|
| 49 | ->addMethod("setAbsCoor", ExecutorLua3<PNode,float,float,float>(&PNode::setAbsCoor)) |
---|
| 50 | ->addMethod("setAbsDir", ExecutorLua4<PNode,float,float,float,float>(&PNode::setAbsDir)) |
---|
| 51 | ); |
---|
[8514] | 52 | |
---|
| 53 | |
---|
[8894] | 54 | |
---|
[8514] | 55 | /** |
---|
| 56 | * constructor |
---|
| 57 | */ |
---|
| 58 | GenericNPC::GenericNPC(const TiXmlElement* root) |
---|
[9003] | 59 | : NPC(root) |
---|
[8514] | 60 | { |
---|
| 61 | this->init(); |
---|
| 62 | |
---|
| 63 | if (root != NULL) |
---|
| 64 | this->loadParams(root); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | /** |
---|
| 69 | * deconstructor |
---|
| 70 | */ |
---|
| 71 | GenericNPC::~GenericNPC () |
---|
[9003] | 72 | {} |
---|
[8514] | 73 | |
---|
| 74 | |
---|
| 75 | /** |
---|
| 76 | * initializing the npc enity |
---|
| 77 | */ |
---|
| 78 | void GenericNPC::init() |
---|
| 79 | { |
---|
| 80 | this->setClassID(CL_GENERIC_NPC, "GenericNPC"); |
---|
| 81 | this->toList(OM_GROUP_00); |
---|
[8516] | 82 | |
---|
| 83 | if (this->soundBuffer != NULL) |
---|
| 84 | ResourceManager::getInstance()->unload(this->soundBuffer); |
---|
| 85 | this->soundBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/rain.wav", WAV); |
---|
[8705] | 86 | |
---|
[8894] | 87 | time = 30.0f; |
---|
[9003] | 88 | |
---|
[8705] | 89 | // collision reaction registration |
---|
[9037] | 90 | this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY); |
---|
[8514] | 91 | } |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | * loads the Settings of a MD2Creature from an XML-element. |
---|
| 96 | * @param root the XML-element to load the MD2Creature's properties from |
---|
| 97 | */ |
---|
| 98 | void GenericNPC::loadParams(const TiXmlElement* root) |
---|
| 99 | { |
---|
[8705] | 100 | NPC::loadParams(root); |
---|
[8514] | 101 | |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | * sets the animation of this npc |
---|
| 107 | * @param anumationIndex: the animation index |
---|
| 108 | * @param anumPlaybackMode: the playback mode |
---|
| 109 | */ |
---|
| 110 | void GenericNPC::setAnimation(int animationIndex, int animPlaybackMode) |
---|
| 111 | { |
---|
| 112 | if( likely(this->getModel(0) != NULL)) |
---|
| 113 | ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
[9003] | 117 | |
---|
[8514] | 118 | /** |
---|
[9003] | 119 | * @returns the current animation number |
---|
| 120 | */ |
---|
| 121 | int GenericNPC::getAnimation() |
---|
| 122 | { |
---|
| 123 | if( likely(this->getModel(0) != NULL)) |
---|
| 124 | return ((InteractiveModel*)this->getModel(0))->getAnimation(); |
---|
| 125 | else |
---|
| 126 | return -1; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | /** |
---|
| 132 | * @returns true if animation is finished |
---|
| 133 | */ |
---|
| 134 | bool GenericNPC::isAnimationFinished() |
---|
| 135 | { |
---|
| 136 | if( likely(this->getModel(0) != NULL)) |
---|
| 137 | return ((InteractiveModel*)this->getModel(0))->isAnimationFinished(); |
---|
| 138 | else |
---|
| 139 | return false; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | /** |
---|
| 144 | * sets the animation speed of this entity |
---|
| 145 | */ |
---|
| 146 | void GenericNPC::setAnimationSpeed(float speed) |
---|
| 147 | { |
---|
| 148 | if( likely(this->getModel(0) != NULL)) |
---|
| 149 | ((InteractiveModel*)this->getModel(0))->setAnimationSpeed(speed); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | /** |
---|
[8514] | 155 | * sets the animation of this npc |
---|
| 156 | * @param anumationIndex: the animation index |
---|
| 157 | * @param anumPlaybackMode: the playback mode |
---|
| 158 | */ |
---|
[8705] | 159 | void GenericNPC::playAnimation(int animationIndex, int animPlaybackMode) |
---|
[8514] | 160 | { |
---|
| 161 | if( likely(this->getModel(0) != NULL)) |
---|
| 162 | ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode); |
---|
| 163 | |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | /** |
---|
| 168 | * play a sound |
---|
| 169 | * @param filename: name of the file |
---|
| 170 | */ |
---|
[9036] | 171 | void GenericNPC::playSound(const std::string& filename) |
---|
[9003] | 172 | {} |
---|
[8705] | 173 | |
---|
[8514] | 174 | |
---|
| 175 | |
---|
| 176 | /** |
---|
[9003] | 177 | * stops the generic animation |
---|
[8514] | 178 | */ |
---|
[9003] | 179 | void GenericNPC::stop() |
---|
[9037] | 180 | { |
---|
[8590] | 181 | |
---|
[9037] | 182 | } |
---|
[8802] | 183 | |
---|
| 184 | |
---|
[9037] | 185 | |
---|
[9003] | 186 | void GenericNPC::initNPC() |
---|
| 187 | { |
---|
| 188 | if (!this->behaviourList.empty()) |
---|
| 189 | { |
---|
| 190 | GenericNPC::Anim currentAnimation = this->behaviourList.front(); |
---|
[8802] | 191 | |
---|
[9003] | 192 | switch(this->behaviourList.front().type) |
---|
| 193 | { |
---|
| 194 | case Walk: |
---|
| 195 | { |
---|
| 196 | if( this->getAnimation() != RUN) |
---|
| 197 | this->setAnimation(RUN, MD2_ANIM_LOOP); |
---|
[8894] | 198 | |
---|
[9003] | 199 | Vector dir = (currentAnimation.v - this->getAbsCoor()); |
---|
[9040] | 200 | dir.y = 0.0f; |
---|
[9003] | 201 | dir.getNormalized(); |
---|
[9040] | 202 | this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0))); |
---|
[8894] | 203 | |
---|
[9003] | 204 | this->setAnimationSpeed(0.5f); |
---|
| 205 | } |
---|
| 206 | break; |
---|
| 207 | case Run: |
---|
| 208 | { |
---|
| 209 | if( this->getAnimation() != RUN) |
---|
| 210 | this->setAnimation(RUN, MD2_ANIM_LOOP); |
---|
[8802] | 211 | |
---|
[9003] | 212 | Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized(); |
---|
| 213 | this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0))); |
---|
[8590] | 214 | |
---|
[9003] | 215 | this->setAnimationSpeed(1.0f); |
---|
| 216 | } |
---|
| 217 | break; |
---|
| 218 | case Crouch: |
---|
| 219 | { |
---|
| 220 | if( this->getAnimation() != CROUCH_WALK) |
---|
| 221 | this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP); |
---|
[8590] | 222 | |
---|
[9003] | 223 | Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized(); |
---|
| 224 | this->setAbsDir(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0))); |
---|
[8802] | 225 | |
---|
[9003] | 226 | this->setAnimationSpeed(1.0f); |
---|
| 227 | } |
---|
| 228 | break; |
---|
| 229 | case LookAt: |
---|
| 230 | if( this->getAnimation() != STAND) |
---|
| 231 | this->setAnimation(STAND, MD2_ANIM_LOOP); |
---|
| 232 | break; |
---|
| 233 | case Shoot: |
---|
| 234 | if( this->getAnimation() != STAND) |
---|
| 235 | this->setAnimation(STAND, MD2_ANIM_LOOP); |
---|
| 236 | break; |
---|
[8894] | 237 | |
---|
[9003] | 238 | default: |
---|
| 239 | if( this->getAnimation() != STAND) |
---|
| 240 | this->setAnimation(STAND, MD2_ANIM_LOOP); |
---|
| 241 | break; |
---|
[8894] | 242 | |
---|
[9003] | 243 | } |
---|
| 244 | } |
---|
[8802] | 245 | } |
---|
| 246 | |
---|
| 247 | |
---|
[9003] | 248 | void GenericNPC::nextStep() |
---|
[8805] | 249 | { |
---|
[9003] | 250 | if (!this->behaviourList.empty()) |
---|
| 251 | this->behaviourList.pop_front(); |
---|
| 252 | else |
---|
| 253 | return; |
---|
[8805] | 254 | |
---|
| 255 | |
---|
[9003] | 256 | if (!this->behaviourList.empty()) |
---|
| 257 | { |
---|
| 258 | GenericNPC::Anim currentAnimation = this->behaviourList.front(); |
---|
[8894] | 259 | |
---|
[9003] | 260 | switch( currentAnimation.type) |
---|
| 261 | { |
---|
| 262 | case Walk: |
---|
| 263 | { |
---|
| 264 | if( this->getAnimation() != RUN) |
---|
| 265 | this->setAnimation(RUN, MD2_ANIM_LOOP); |
---|
[8894] | 266 | |
---|
[9040] | 267 | |
---|
[9003] | 268 | Vector dir = (currentAnimation.v - this->getAbsCoor()); |
---|
[9040] | 269 | dir.y = 0.0f; |
---|
[9003] | 270 | dir.getNormalized(); |
---|
| 271 | this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0); |
---|
[8894] | 272 | |
---|
[9003] | 273 | this->setAnimationSpeed(0.5f); |
---|
| 274 | } |
---|
| 275 | break; |
---|
| 276 | case Run: |
---|
| 277 | { |
---|
| 278 | if( this->getAnimation() != RUN) |
---|
| 279 | this->setAnimation(RUN, MD2_ANIM_LOOP); |
---|
[8894] | 280 | |
---|
[9003] | 281 | Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized(); |
---|
| 282 | this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0); |
---|
[8894] | 283 | |
---|
[9003] | 284 | this->setAnimationSpeed(1.0f); |
---|
| 285 | } |
---|
| 286 | break; |
---|
| 287 | case Crouch: |
---|
| 288 | { |
---|
| 289 | if( this->getAnimation() != CROUCH_WALK) |
---|
| 290 | this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP); |
---|
[8894] | 291 | |
---|
[9003] | 292 | Vector dir = (currentAnimation.v - this->getAbsCoor()).getNormalized(); |
---|
| 293 | this->setAbsDirSoft(Quaternion(dir, Vector(0.0, 1.0, 0.0)) * Quaternion(-M_PI_2, Vector(0.0, 1.0, 0.0)), 4.0); |
---|
[8894] | 294 | |
---|
[9003] | 295 | this->setAnimationSpeed(1.0f); |
---|
| 296 | } |
---|
| 297 | break; |
---|
| 298 | case LookAt: |
---|
| 299 | { |
---|
| 300 | if( this->getAnimation() != STAND) |
---|
| 301 | this->setAnimation(STAND, MD2_ANIM_LOOP); |
---|
| 302 | } |
---|
| 303 | break; |
---|
| 304 | case Shoot: |
---|
| 305 | if( this->getAnimation() != STAND) |
---|
| 306 | this->setAnimation(STAND, MD2_ANIM_LOOP); |
---|
| 307 | break; |
---|
[8894] | 308 | |
---|
[9003] | 309 | default: |
---|
| 310 | if( this->getAnimation() != STAND) |
---|
| 311 | this->setAnimation(STAND, MD2_ANIM_LOOP); |
---|
| 312 | break; |
---|
| 313 | |
---|
| 314 | } |
---|
[8894] | 315 | } |
---|
[9003] | 316 | else |
---|
| 317 | { |
---|
| 318 | this->setAnimation(STAND, MD2_ANIM_LOOP); |
---|
| 319 | } |
---|
[8894] | 320 | } |
---|
| 321 | |
---|
| 322 | |
---|
| 323 | |
---|
| 324 | |
---|
[9003] | 325 | void GenericNPC::walkTo(const Vector& coordinate) |
---|
[8894] | 326 | { |
---|
| 327 | |
---|
[9003] | 328 | GenericNPC::Anim anim; |
---|
| 329 | anim.v = coordinate; |
---|
| 330 | anim.type = Walk; |
---|
| 331 | anim.speed = 30.0f; |
---|
[8894] | 332 | |
---|
[9003] | 333 | if( this->behaviourList.empty()) |
---|
[8894] | 334 | { |
---|
[9003] | 335 | this->behaviourList.push_back(anim); |
---|
| 336 | this->initNPC(); |
---|
| 337 | } |
---|
| 338 | else |
---|
| 339 | this->behaviourList.push_back(anim); |
---|
| 340 | } |
---|
[8894] | 341 | |
---|
[9003] | 342 | void GenericNPC::walkTo(float x, float y, float z) |
---|
| 343 | { |
---|
| 344 | //printf("Walking to %f, %f, %f \n",x,y,z); |
---|
| 345 | this->walkTo(Vector(x,y,z)); |
---|
[8894] | 346 | |
---|
[9003] | 347 | } |
---|
[8894] | 348 | |
---|
[9003] | 349 | /* running functions */ |
---|
| 350 | void GenericNPC::runTo(const Vector& coordinate) |
---|
| 351 | { |
---|
| 352 | GenericNPC::Anim anim; |
---|
| 353 | anim.v = coordinate; |
---|
| 354 | anim.type = Run; |
---|
| 355 | anim.speed = 60.0f; |
---|
[8894] | 356 | |
---|
[9003] | 357 | if( this->behaviourList.empty()) |
---|
| 358 | { |
---|
| 359 | this->behaviourList.push_back(anim); |
---|
| 360 | this->initNPC(); |
---|
[8894] | 361 | } |
---|
[9003] | 362 | else |
---|
| 363 | this->behaviourList.push_back(anim); |
---|
| 364 | } |
---|
[8894] | 365 | |
---|
[9003] | 366 | void GenericNPC::runTo(float x, float y, float z) |
---|
| 367 | { |
---|
| 368 | this->runTo(Vector(x,y,z)); |
---|
[8894] | 369 | } |
---|
| 370 | |
---|
[9003] | 371 | /* couching functinos */ |
---|
| 372 | void GenericNPC::crouchTo(const Vector& coordinate) |
---|
| 373 | { |
---|
| 374 | GenericNPC::Anim anim; |
---|
| 375 | anim.v = coordinate; |
---|
| 376 | anim.type = Crouch; |
---|
[8894] | 377 | |
---|
[9003] | 378 | if( this->behaviourList.empty()) |
---|
| 379 | { |
---|
| 380 | this->behaviourList.push_back(anim); |
---|
| 381 | this->initNPC(); |
---|
| 382 | } |
---|
| 383 | else |
---|
| 384 | this->behaviourList.push_back(anim); |
---|
| 385 | } |
---|
| 386 | void GenericNPC::crouchTo(float x, float y, float z) |
---|
[8894] | 387 | { |
---|
[9003] | 388 | this->crouchTo(Vector(x,y,z)); |
---|
[8894] | 389 | } |
---|
| 390 | |
---|
| 391 | |
---|
| 392 | |
---|
[9003] | 393 | void GenericNPC::turnTo(float degreeInY) |
---|
[8894] | 394 | { |
---|
[9003] | 395 | GenericNPC::Anim anim; |
---|
| 396 | anim.q = Quaternion(Vector(0,1,0), degreeInY); |
---|
| 397 | anim.type = TurnTo; |
---|
[8894] | 398 | |
---|
[9003] | 399 | if( this->behaviourList.empty()) |
---|
[8894] | 400 | { |
---|
[9003] | 401 | this->behaviourList.push_back(anim); |
---|
| 402 | this->initNPC(); |
---|
[8894] | 403 | } |
---|
[9003] | 404 | else |
---|
| 405 | this->behaviourList.push_back(anim); |
---|
[8894] | 406 | } |
---|
| 407 | |
---|
| 408 | |
---|
[9003] | 409 | |
---|
[8894] | 410 | /** |
---|
| 411 | * lookat a world entity |
---|
| 412 | * @param worldEntity: the worldentity to look at |
---|
| 413 | */ |
---|
[9003] | 414 | void GenericNPC::lookAt(WorldEntity* worldEntity) |
---|
[8894] | 415 | { |
---|
[9003] | 416 | GenericNPC::Anim anim; |
---|
| 417 | anim.entity = worldEntity; |
---|
| 418 | anim.type = LookAt; |
---|
[8894] | 419 | |
---|
[9003] | 420 | if( this->behaviourList.empty()) |
---|
[8894] | 421 | { |
---|
[9003] | 422 | this->behaviourList.push_back(anim); |
---|
| 423 | this->initNPC(); |
---|
[8894] | 424 | } |
---|
[9003] | 425 | else |
---|
| 426 | this->behaviourList.push_back(anim); |
---|
[8894] | 427 | } |
---|
| 428 | |
---|
| 429 | |
---|
| 430 | |
---|
[9003] | 431 | |
---|
[8894] | 432 | /** |
---|
| 433 | * talk to a world entity and play a sound/music/voice |
---|
| 434 | * @param worldEntity: entity |
---|
| 435 | * @param dialogNr: sound nr to be played (from the xml load tags) |
---|
| 436 | */ |
---|
[9003] | 437 | void GenericNPC::talkTo(WorldEntity* worldEntity, int dialogNr) |
---|
[8894] | 438 | {} |
---|
| 439 | |
---|
| 440 | |
---|
| 441 | /** |
---|
| 442 | * world entity to shoot at if there is any weapon on the npc |
---|
| 443 | * @param entity: entity to shoot entity |
---|
| 444 | */ |
---|
| 445 | void GenericNPC::shootAt(WorldEntity* entity) |
---|
| 446 | {} |
---|
| 447 | |
---|
| 448 | |
---|
| 449 | |
---|
| 450 | |
---|
| 451 | |
---|
| 452 | |
---|
| 453 | |
---|
| 454 | |
---|
| 455 | |
---|
| 456 | |
---|
| 457 | /** |
---|
[8514] | 458 | * tick this world entity |
---|
| 459 | * @param time: time in seconds expirded since the last tick |
---|
| 460 | */ |
---|
[9003] | 461 | void GenericNPC::tick (float dt) |
---|
[8514] | 462 | { |
---|
| 463 | if( likely(this->getModel(0) != NULL)) |
---|
[9003] | 464 | ((InteractiveModel*)this->getModel(0))->tick(dt); |
---|
[8894] | 465 | |
---|
[9003] | 466 | |
---|
| 467 | if (!this->behaviourList.empty()) |
---|
| 468 | { |
---|
| 469 | GenericNPC::Anim currentAnimation = this->behaviourList.front(); |
---|
| 470 | |
---|
| 471 | switch( currentAnimation.type) |
---|
| 472 | { |
---|
| 473 | case Walk: |
---|
| 474 | { |
---|
| 475 | Vector dest = currentAnimation.v - this->getAbsCoor(); |
---|
[9037] | 476 | dest.y = 0.0f; |
---|
[9003] | 477 | if (dest.len() < .5) |
---|
| 478 | this->nextStep(); |
---|
| 479 | else |
---|
| 480 | { |
---|
[9035] | 481 | Vector move = dest.getNormalized() * currentAnimation.speed * dt; |
---|
| 482 | this->shiftCoor(move); |
---|
[9003] | 483 | } |
---|
| 484 | } |
---|
| 485 | break; |
---|
| 486 | |
---|
| 487 | case Run: |
---|
| 488 | { |
---|
| 489 | Vector dest = currentAnimation.v - this->getAbsCoor(); |
---|
| 490 | if (dest.len() < .5) |
---|
| 491 | this->nextStep(); |
---|
| 492 | else |
---|
| 493 | { |
---|
| 494 | this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt); |
---|
| 495 | } |
---|
| 496 | } |
---|
| 497 | break; |
---|
| 498 | |
---|
| 499 | case Crouch: |
---|
| 500 | { |
---|
| 501 | Vector dest = currentAnimation.v - this->getAbsCoor(); |
---|
| 502 | if (dest.len() < .5) |
---|
| 503 | this->nextStep(); |
---|
| 504 | else |
---|
| 505 | { |
---|
| 506 | this->shiftCoor(dest.getNormalized() * currentAnimation.speed * dt); |
---|
| 507 | } |
---|
| 508 | } |
---|
| 509 | break; |
---|
| 510 | |
---|
| 511 | case TurnTo: |
---|
| 512 | //Quaternion direction = this-> |
---|
| 513 | break; |
---|
| 514 | |
---|
| 515 | case LookAt: |
---|
| 516 | break; |
---|
| 517 | |
---|
| 518 | case Shoot: |
---|
| 519 | break; |
---|
| 520 | |
---|
| 521 | default: |
---|
| 522 | break; |
---|
| 523 | |
---|
| 524 | } |
---|
| 525 | } |
---|
| 526 | |
---|
[9037] | 527 | // physical falling of the player |
---|
| 528 | if( !this->isOnGround()) |
---|
| 529 | { |
---|
| 530 | this->fallVelocity += 300.0f * dt; |
---|
| 531 | //velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity; |
---|
| 532 | // PRINTF(0)("%s is not on ground\n", this->getName()); |
---|
[9003] | 533 | |
---|
[9037] | 534 | this->shiftCoor(Vector(0, -this->fallVelocity * dt,0)); |
---|
| 535 | |
---|
| 536 | } |
---|
| 537 | else |
---|
| 538 | { |
---|
| 539 | this->fallVelocity = 0.0f; |
---|
| 540 | } |
---|
| 541 | |
---|
[8514] | 542 | } |
---|
| 543 | |
---|
| 544 | |
---|
| 545 | |
---|
| 546 | void GenericNPC::destroy() |
---|
| 547 | { |
---|
| 548 | int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX); |
---|
| 549 | |
---|
[9003] | 550 | this->setAnimationSpeed(1.0f); |
---|
| 551 | |
---|
[8514] | 552 | if( randi == 1) |
---|
| 553 | this->setAnimation(DEATH_FALLBACK, MD2_ANIM_ONCE); |
---|
| 554 | else if( randi == 2) |
---|
| 555 | this->setAnimation(DEATH_FALLFORWARD, MD2_ANIM_ONCE); |
---|
| 556 | else if( randi == 3) |
---|
| 557 | this->setAnimation(DEATH_FALLBACKSLOW, MD2_ANIM_ONCE); |
---|
| 558 | else if( randi == 4) |
---|
| 559 | this->setAnimation(CROUCH_DEATH, MD2_ANIM_ONCE); |
---|
| 560 | else |
---|
| 561 | this->setAnimation(DEATH_FALLBACK, MD2_ANIM_ONCE); |
---|
| 562 | } |
---|
| 563 | |
---|