Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/npcs/gate.cc @ 9869

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 4.9 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: Silvan Nellen
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
25
26#include "gate.h"
27#include "effects/explosion.h"
28
29
30
31
32
33#include "class_id_DEPRECATED.h"
34ObjectListDefinitionID(Gate, CL_GATE);
35CREATE_FACTORY(Gate);
36
37
38#include "script_class.h"
39CREATE_SCRIPTABLE_CLASS(Gate,
40                        addMethod("hide", Executor0<WorldEntity, lua_State*>(&WorldEntity::hide))
41                            ->addMethod("unhide", Executor0<WorldEntity, lua_State*>(&WorldEntity::unhide))
42                            ->addMethod("destroy", Executor0<Gate, lua_State*>(&Gate::destroy))
43                            ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor))
44                            ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX))
45                            ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY))
46                            ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ))
47                       );
48
49
50
51//! list of all different animations a std md2model supports
52sAnim Gate::animationList[3] =
53{
54 // begin, end, fps, interruptable
55  {   0,  7,  30,  0 },    //!< OPEN
56  {   8, 15,  30,  0 },    //!< CLOSE
57  {  16, 18,  30,  0 }     //!< DIE
58};
59
60
61
62Gate::Gate(const TiXmlElement* root)
63{
64  this->registerObject(this, Gate::_objectList);
65  this->scale = 1.0f;
66  this->actionRadius = 1.0;
67  this->destroyed = false;
68
69  if( root != NULL)
70    this->loadParams(root);
71
72  this->toList(OM_COMMON);
73  this->bLocked = false;
74  this->bOpen = false;
75
76  this->loadMD2Texture("maps/wheel.jpg");
77  this->loadModel("models/creatures/hypergate.md2", this->scale);
78
79  this->setAnimation(GATE_CLOSE, MD2_ANIM_ONCE);
80}
81
82
83Gate::~Gate ()
84{}
85
86
87
88/**
89 * loads the Settings of a MD2Creature from an XML-element.
90 * @param root the XML-element to load the MD2Creature's properties from
91 */
92void Gate::loadParams(const TiXmlElement* root)
93{
94  WorldEntity::loadParams(root);
95
96  LoadParam(root, "action-radius", this, Gate, setActionRadius)
97      .describe("sets the action radius of the door")
98      .defaultValues(3.0);
99  LoadParam(root, "scale", this, Gate, setScale)
100      .describe("sets the scale of the door")
101      .defaultValues(1.0);
102}
103
104
105/**
106 * sets the animatin of this entity
107 */
108void  Gate::setAnimation(int animNum, int playbackMode)
109{
110  if( likely(this->getModel(0) != NULL))
111    ((InteractiveModel*)this->getModel(0))->setAnimation(animationList[animNum].firstFrame,
112                                                         animationList[animNum].lastFrame,
113                                                         animationList[animNum].fps,
114                                                         animationList[animNum].bStoppable,
115                                                         playbackMode);
116}
117
118
119/**
120 * ticks the door
121 * @param time: time since last tick
122 */
123void Gate::tick (float time)
124{
125  if( likely(this->getModel(0) != NULL))
126    ((InteractiveModel*)this->getModel(0))->tick(time);
127
128
129  if( !this->bOpen)
130  {
131    if( this->checkOpen())
132    {
133      this->open();
134    }
135  }
136  else
137  {
138    if( !this->checkOpen())
139    {
140      this->close();
141    }
142  }
143
144
145}
146
147
148/**
149 * open the door
150 */
151void Gate::open()
152{
153  if( this->bLocked || this->destroyed)
154    return;
155
156  this->setAnimation(GATE_OPEN, MD2_ANIM_ONCE);
157  this->bOpen = true;
158}
159
160
161/**
162 * close the door
163 */
164void Gate::close()
165{
166
167  if( this->destroyed)
168    return;
169
170  this->setAnimation(GATE_CLOSE, MD2_ANIM_ONCE);
171  this->bOpen = false;
172}
173
174
175void Gate::destroy()
176{
177  if( this->destroyed)
178    return;
179
180  this->setAnimation(GATE_DIE, MD2_ANIM_ONCE);
181
182  Explosion::explode(this, Vector(this->getScaling()/160,this->getScaling()/160,this->getScaling()/160));
183
184
185  this->destroyed = true;
186}
187
188#include "playable.h"
189#include "generic_npc.h"
190
191/**
192 * checks if the door is open
193 */
194bool Gate::checkOpen()
195{
196
197  std::list<BaseObject*>::const_iterator it;
198  WorldEntity* entity;
199  float distance;
200
201  // for all players
202  for (ObjectList<Playable>::const_iterator it = Playable::objectList().begin();
203       it != Playable::objectList().end();
204       ++it)
205  {
206    entity = (*it);
207
208    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
209    if( distance < this->actionRadius)
210      return true;
211  }
212
213
214  for (ObjectList<GenericNPC>::const_iterator it = GenericNPC::objectList().begin();
215       it != GenericNPC::objectList().end();
216       ++it)
217  {
218    entity = (*it);
219
220    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
221    if( distance < this->actionRadius)
222      return true;
223  }
224
225  return false;
226}
227
228
229
Note: See TracBrowser for help on using the repository browser.