- Timestamp:
- Jun 29, 2006, 4:30:32 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/single_player_map/src/world_entities/npcs/generic_npc.cc
r8909 r8913 35 35 #include "script_class.h" 36 36 CREATE_SCRIPTABLE_CLASS(GenericNPC, CL_GENERIC_NPC, 37 // Move37 // Move 38 38 addMethod("walkTo", ExecutorLua3<GenericNPC,float,float,float>(&GenericNPC::walkTo)) 39 39 ->addMethod("turnTo", ExecutorLua1<GenericNPC,float>(&GenericNPC::turnTo)) 40 // Display40 // Display 41 41 ->addMethod("hide", ExecutorLua0<WorldEntity>(&WorldEntity::hide)) 42 42 ->addMethod("unhide", ExecutorLua0<WorldEntity>(&WorldEntity::unhide)) 43 // Coordinates43 // Coordinates 44 44 ->addMethod("getAbsCoorX", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorX)) 45 45 ->addMethod("getAbsCoorY", ExecutorLua0ret<PNode, float>(&PNode::getAbsCoorY)) … … 56 56 */ 57 57 GenericNPC::GenericNPC(const TiXmlElement* root) 58 : NPC(root)58 : NPC(root) 59 59 { 60 60 this->init(); … … 69 69 */ 70 70 GenericNPC::~GenericNPC () 71 { 72 } 71 {} 73 72 74 73 … … 87 86 time = 30.0f; 88 87 // 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); 90 89 } 91 90 … … 132 131 */ 133 132 void GenericNPC::playSound(std::string filename) 134 { 135 136 } 133 {} 137 134 138 135 … … 142 139 */ 143 140 void 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 143 void GenericNPC::nextStep() 144 { 145 if (!this->behaviourList.empty()) 146 this->behaviourList.pop_front(); 147 else 148 return; 256 149 257 150 if (!this->behaviourList.empty()) … … 260 153 { 261 154 case Walk: 155 this->setAnimation(RUN, MD2_ANIM_LOOP); 262 156 break; 263 157 case Run: 158 this->setAnimation(RUN, MD2_ANIM_LOOP); 264 159 break; 265 160 case Crouch: 161 this->setAnimation(CROUCH_WALK, MD2_ANIM_LOOP); 266 162 break; 267 163 case LookAt: 164 this->setAnimation(STAND, MD2_ANIM_LOOP); 165 268 166 break; 269 167 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 184 void 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 193 void GenericNPC::walkTo(float x, float y, float z) 194 { 195 this->walkTo(Vector(x,y,z)); 196 197 } 198 199 /* running functions */ 200 void 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 209 void GenericNPC::runTo(float x, float y, float z) 210 { 211 this->runTo(Vector(x,y,z)); 212 } 213 214 /* couching functinos */ 215 void 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 } 223 void GenericNPC::crouchTo(float x, float y, float z) 224 { 225 this->crouchTo(Vector(x,y,z)); 226 } 227 228 229 230 void 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 */ 245 void 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 */ 262 void 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 */ 270 void 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 */ 286 void 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: 270 315 break; 271 316
Note: See TracChangeset
for help on using the changeset viewer.