Changeset 9869 in orxonox.OLD for trunk/src/world_entities/npcs/generic_npc.cc
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/npcs/generic_npc.cc
r9235 r9869 27 27 28 28 #include "sound_buffer.h" 29 30 #include "loading/resource_manager.h" 31 32 33 CREATE_FACTORY(GenericNPC, CL_GENERIC_NPC); 29 #include "resource_sound_buffer.h" 30 31 #include "sound/resource_sound_buffer.h" 32 33 #include "bsp_entity.h" 34 35 #include "class_id_DEPRECATED.h" 36 ObjectListDefinitionID(GenericNPC, CL_GENERIC_NPC); 37 CREATE_FACTORY(GenericNPC); 34 38 35 39 #include "script_class.h" 36 CREATE_SCRIPTABLE_CLASS(GenericNPC, CL_GENERIC_NPC,40 CREATE_SCRIPTABLE_CLASS(GenericNPC, 37 41 // Move 38 addMethod("walkTo", Executor Lua3<GenericNPC,float,float,float>(&GenericNPC::walkTo))39 ->addMethod("runTo", Executor Lua3<GenericNPC,float,float,float>(&GenericNPC::runTo))40 ->addMethod("turnTo", Executor Lua1<GenericNPC,float>(&GenericNPC::turnTo))41 ->addMethod("finalGoalReached", Executor Lua0ret<GenericNPC,bool>(&GenericNPC::finalGoalReached))42 ->addMethod("stop", Executor Lua0<GenericNPC>(&GenericNPC::stop))43 ->addMethod("resume", Executor Lua0<GenericNPC>(&GenericNPC::resume))44 ->addMethod("playAnimation", Executor Lua2<GenericNPC,int,int>(&GenericNPC::playAnimation))42 addMethod("walkTo", Executor3<GenericNPC, lua_State*,float,float,float>(&GenericNPC::walkTo)) 43 ->addMethod("runTo", Executor3<GenericNPC, lua_State*,float,float,float>(&GenericNPC::runTo)) 44 ->addMethod("turnTo", Executor1<GenericNPC, lua_State*,float>(&GenericNPC::turnTo)) 45 ->addMethod("finalGoalReached", Executor0ret<GenericNPC, lua_State*,bool>(&GenericNPC::finalGoalReached)) 46 ->addMethod("stop", Executor0<GenericNPC, lua_State*>(&GenericNPC::stop)) 47 ->addMethod("resume", Executor0<GenericNPC, lua_State*>(&GenericNPC::resume)) 48 ->addMethod("playAnimation", Executor2<GenericNPC, lua_State*,int,int>(&GenericNPC::playAnimation)) 45 49 // Display 46 ->addMethod("hide", Executor Lua0<WorldEntity>(&WorldEntity::hide))47 ->addMethod("unhide", Executor Lua0<WorldEntity>(&WorldEntity::unhide))50 ->addMethod("hide", Executor0<WorldEntity, lua_State*>(&WorldEntity::hide)) 51 ->addMethod("unhide", Executor0<WorldEntity, lua_State*>(&WorldEntity::unhide)) 48 52 // Coordinates 49 ->addMethod("getAbsCoorX", Executor Lua0ret<PNode, float>(&PNode::getAbsCoorX))50 ->addMethod("getAbsCoorY", Executor Lua0ret<PNode, float>(&PNode::getAbsCoorY))51 ->addMethod("getAbsCoorZ", Executor Lua0ret<PNode, float>(&PNode::getAbsCoorZ))52 ->addMethod("setAbsCoor", Executor Lua3<PNode,float,float,float>(&PNode::setAbsCoor))53 ->addMethod("setAbsDir", Executor Lua4<PNode,float,float,float,float>(&PNode::setAbsDir))53 ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX)) 54 ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) 55 ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) 56 ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor)) 57 ->addMethod("setAbsDir", Executor4<PNode, lua_State*,float,float,float,float>(&PNode::setAbsDir)) 54 58 ); 55 59 … … 81 85 void GenericNPC::init() 82 86 { 83 this-> setClassID(CL_GENERIC_NPC, "GenericNPC");87 this->registerObject(this, GenericNPC::_objectList); 84 88 85 89 this->toList(OM_GROUP_00); 86 90 87 this->soundBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/rain.wav", WAV);91 this->soundBuffer = OrxSound::ResourceSoundBuffer("sound/rain.wav"); 88 92 89 93 time = 30.0f; … … 92 96 93 97 // collision reaction registration 94 this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);98 this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID()); 95 99 } 96 100 … … 231 235 this->setAnimationSpeed(0.5f); 232 236 } 233 237 break; 234 238 case Run: 235 239 { … … 244 248 this->setAnimationSpeed(1.0f); 245 249 } 246 250 break; 247 251 case Crouch: 248 252 { … … 257 261 this->setAnimationSpeed(1.0f); 258 262 } 259 263 break; 260 264 case LookAt: 261 262 263 265 if( this->getAnimation() != STAND) 266 this->setAnimation(STAND, MD2_ANIM_LOOP); 267 break; 264 268 case Shoot: 265 266 267 269 if( this->getAnimation() != STAND) 270 this->setAnimation(STAND, MD2_ANIM_LOOP); 271 break; 268 272 269 273 default: 270 271 272 274 if( this->getAnimation() != STAND) 275 this->setAnimation(STAND, MD2_ANIM_LOOP); 276 break; 273 277 274 278 } … … 304 308 this->setAnimationSpeed(0.5f); 305 309 } 306 310 break; 307 311 case Run: 308 312 { … … 317 321 this->setAnimationSpeed(1.0f); 318 322 } 319 323 break; 320 324 case Crouch: 321 325 { … … 330 334 this->setAnimationSpeed(1.0f); 331 335 } 332 336 break; 333 337 case LookAt: 334 338 { … … 336 340 this->setAnimation(STAND, MD2_ANIM_LOOP); 337 341 } 338 342 break; 339 343 case Shoot: 340 344 if( this->getAnimation() != STAND) 341 345 this->setAnimation(STAND, MD2_ANIM_LOOP); 342 346 break; 343 347 344 348 default: 345 349 if( this->getAnimation() != STAND) 346 350 this->setAnimation(STAND, MD2_ANIM_LOOP); 347 351 break; 348 352 349 353 } … … 507 511 { 508 512 case Walk: 513 { 514 Vector dest = currentAnimation.v - this->getAbsCoor(); 515 dest.y = 0.0f; 516 if (dest.len() < .5) 509 517 { 510 Vector dest = currentAnimation.v - this->getAbsCoor(); 511 dest.y = 0.0f; 512 if (dest.len() < .5) 513 { 514 this->nextStep(); 515 } 516 else 517 { 518 Vector move = dest.getNormalized() * currentAnimation.speed * dt; 519 this->shiftCoor(move); 520 } 518 this->nextStep(); 521 519 } 522 break; 520 else 521 { 522 Vector move = dest.getNormalized() * currentAnimation.speed * dt; 523 this->shiftCoor(move); 524 } 525 } 526 break; 523 527 524 528 case Run: … … 549 553 550 554 case TurnTo: 551 552 555 //Quaternion direction = this-> 556 break; 553 557 554 558 case LookAt: 555 559 break; 556 560 557 561 case Shoot: 558 562 break; 559 563 560 564 default: 561 565 break; 562 566 563 567 } … … 569 573 this->fallVelocity += 300.0f * dt; 570 574 //velocity -= Vector(0.0, 1.0, 0.0) * this->fallVelocity; 571 // PRINTF(0)("%s is not on ground\n", this->getName());575 // PRINTF(0)("%s is not on ground\n", this->getName()); 572 576 this->shiftCoor(Vector(0, -this->fallVelocity * dt,0)); 573 577
Note: See TracChangeset
for help on using the changeset viewer.