Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/bsp_model/src/world_entities/npcs/generic_npc.cc @ 8538

Last change on this file since 8538 was 8516, checked in by patrick, 18 years ago

bsp: added a sound source to the generic npc as a start

File size: 3.3 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
73
74/**
75 * loads the Settings of a MD2Creature from an XML-element.
76 * @param root the XML-element to load the MD2Creature's properties from
77 */
78void GenericNPC::loadParams(const TiXmlElement* root)
79{
80  WorldEntity::loadParams(root);
81
82  LoadParam(root, "md2animation", this, GenericNPC, setAnimation)
83      .describe("sets the animation of the md2 model")
84      .defaultValues(1);
85
86}
87
88
89/**
90 * sets the animation of this npc
91 * @param anumationIndex: the animation index
92 * @param anumPlaybackMode: the playback mode
93 */
94void GenericNPC::setAnimation(int animationIndex, int animPlaybackMode)
95{
96  if( likely(this->getModel(0) != NULL))
97    ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode);
98}
99
100
101/**
102 * sets the animation of this npc
103 * @param anumationIndex: the animation index
104 * @param anumPlaybackMode: the playback mode
105 */
106bool GenericNPC::playAnimation(int animationIndex, int animPlaybackMode)
107{
108  if( likely(this->getModel(0) != NULL))
109    ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode);
110
111  return true;
112}
113
114
115/**
116 * play a sound
117 * @param filename: name of the file
118 */
119bool GenericNPC::playSound(std::string filename)
120{
121  return true;
122}
123
124
125/**
126 * walt to
127 * @param coordinate: coordinate to go to
128 */
129bool GenericNPC::walkTo(const Vector& coordinate)
130{
131
132  return true;
133}
134
135
136/**
137 * tick this world entity
138 * @param time: time in seconds expirded since the last tick
139 */
140void GenericNPC::tick (float time)
141{
142  if( likely(this->getModel(0) != NULL))
143    ((InteractiveModel*)this->getModel(0))->tick(time);
144}
145
146
147
148void GenericNPC::destroy()
149{
150  int randi = (int)(5.0f * (float)rand()/(float)RAND_MAX);
151
152  if( randi == 1)
153    this->setAnimation(DEATH_FALLBACK, MD2_ANIM_ONCE);
154  else if( randi == 2)
155    this->setAnimation(DEATH_FALLFORWARD, MD2_ANIM_ONCE);
156  else if( randi == 3)
157    this->setAnimation(DEATH_FALLBACKSLOW, MD2_ANIM_ONCE);
158  else if( randi == 4)
159    this->setAnimation(CROUCH_DEATH, MD2_ANIM_ONCE);
160  else
161    this->setAnimation(DEATH_FALLBACK, MD2_ANIM_ONCE);
162}
163
Note: See TracBrowser for help on using the repository browser.