Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/npcs/generic_npc.cc @ 8750

Last change on this file since 8750 was 8724, checked in by bensch, 18 years ago

merged the bsp-model-stuff back here

File size: 3.4 KB
Line 
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
19
20#include "util/loading/factory.h"
21#include "util/loading/load_param.h"
22
23#include "interactive_model.h"
24#include "md2/md2Model.h"
25
26#include "sound_buffer.h"
27
28#include "loading/resource_manager.h"
29
30#include "generic_npc.h"
31
32using namespace std;
33
34
35
36CREATE_FACTORY(GenericNPC, CL_GENERIC_NPC);
37
38
39
40/**
41 * constructor
42 */
43GenericNPC::GenericNPC(const TiXmlElement* root)
44  : NPC(root)
45{
46  this->init();
47
48  if (root != NULL)
49    this->loadParams(root);
50}
51
52
53/**
54 * deconstructor
55 */
56GenericNPC::~GenericNPC ()
57{}
58
59
60/**
61 * initializing the npc enity
62 */
63void GenericNPC::init()
64{
65  this->setClassID(CL_GENERIC_NPC, "GenericNPC");
66  this->toList(OM_GROUP_00);
67
68  if (this->soundBuffer != NULL)
69    ResourceManager::getInstance()->unload(this->soundBuffer);
70  this->soundBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/rain.wav", WAV);
71
72  // collision reaction registration
73//   this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
74}
75
76
77/**
78 * loads the Settings of a MD2Creature from an XML-element.
79 * @param root the XML-element to load the MD2Creature's properties from
80 */
81void GenericNPC::loadParams(const TiXmlElement* root)
82{
83  NPC::loadParams(root);
84
85}
86
87
88/**
89 * sets the animation of this npc
90 * @param anumationIndex: the animation index
91 * @param anumPlaybackMode: the playback mode
92 */
93void GenericNPC::setAnimation(int animationIndex, int animPlaybackMode)
94{
95  if( likely(this->getModel(0) != NULL))
96    ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode);
97}
98
99
100/**
101 * sets the animation of this npc
102 * @param anumationIndex: the animation index
103 * @param anumPlaybackMode: the playback mode
104 */
105void GenericNPC::playAnimation(int animationIndex, int animPlaybackMode)
106{
107  if( likely(this->getModel(0) != NULL))
108    ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode);
109
110}
111
112
113/**
114 * play a sound
115 * @param filename: name of the file
116 */
117void GenericNPC::playSound(std::string filename)
118{
119
120}
121
122
123/**
124 * walt to
125 * @param coordinate: coordinate to go to
126 */
127bool GenericNPC::walkTo(const Vector& coordinate, float time)
128{
129
130  return true;
131}
132
133
134/**
135 * walt to
136 * @param coordinate: coordinate to go to
137 */
138bool GenericNPC::walkTo(float x, float y, float z, float time)
139{
140
141  return true;
142}
143
144
145/**
146 * tick this world entity
147 * @param time: time in seconds expirded since the last tick
148 */
149void GenericNPC::tick (float time)
150{
151  if( likely(this->getModel(0) != NULL))
152    ((InteractiveModel*)this->getModel(0))->tick(time);
153}
154
155
156
157void GenericNPC::destroy()
158{
159  int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX);
160
161  if( randi == 1)
162    this->setAnimation(DEATH_FALLBACK, MD2_ANIM_ONCE);
163  else if( randi == 2)
164    this->setAnimation(DEATH_FALLFORWARD, MD2_ANIM_ONCE);
165  else if( randi == 3)
166    this->setAnimation(DEATH_FALLBACKSLOW, MD2_ANIM_ONCE);
167  else if( randi == 4)
168    this->setAnimation(CROUCH_DEATH, MD2_ANIM_ONCE);
169  else
170    this->setAnimation(DEATH_FALLBACK, MD2_ANIM_ONCE);
171}
172
Note: See TracBrowser for help on using the repository browser.