Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/npcs/gate.cc @ 9229

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

only some renicement

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