Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10276 was 10114, checked in by patrick, 18 years ago

merged network back to trunk

File size: 4.8 KB
RevLine 
[9222]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
[9298]15   co-programmer: Silvan Nellen
[9222]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
[10114]33
34ObjectListDefinition(Gate);
[9869]35CREATE_FACTORY(Gate);
[9406]36
[9222]37
[9233]38#include "script_class.h"
[9869]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))
[9233]47                       );
[9222]48
[9233]49
[9869]50
[9222]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{
[9869]64  this->registerObject(this, Gate::_objectList);
[9222]65  this->scale = 1.0f;
66  this->actionRadius = 1.0;
[9298]67  this->destroyed = false;
[9222]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
[9229]128
[9222]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
[9229]144
[9222]145}
146
147
148/**
149 * open the door
150 */
151void Gate::open()
152{
[9298]153  if( this->bLocked || this->destroyed)
[9222]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{
[9869]166
[9298]167  if( this->destroyed)
168    return;
[9869]169
[9222]170  this->setAnimation(GATE_CLOSE, MD2_ANIM_ONCE);
171  this->bOpen = false;
172}
173
174
175void Gate::destroy()
176{
[9298]177  if( this->destroyed)
178    return;
[9869]179
[9222]180  this->setAnimation(GATE_DIE, MD2_ANIM_ONCE);
181
[9298]182  Explosion::explode(this, Vector(this->getScaling()/160,this->getScaling()/160,this->getScaling()/160));
[9869]183
184
[9298]185  this->destroyed = true;
[9222]186}
187
[9869]188#include "playable.h"
189#include "generic_npc.h"
[9222]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
[9869]202  for (ObjectList<Playable>::const_iterator it = Playable::objectList().begin();
203       it != Playable::objectList().end();
204       ++it)
[9222]205  {
[9869]206    entity = (*it);
[9222]207
208    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
209    if( distance < this->actionRadius)
210      return true;
211  }
212
213
[9869]214  for (ObjectList<GenericNPC>::const_iterator it = GenericNPC::objectList().begin();
215       it != GenericNPC::objectList().end();
216       ++it)
[9222]217  {
[9869]218    entity = (*it);
[9222]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.