Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/npcs/door.cc @ 9076

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

orxonox/trunk: merged the single_player_map branche back
merged with command:
svn merge -r8896:HEAD https://svn.orxonox.net/orxonox/branches/single_player_map .
no conflicts

File size: 3.8 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 "door.h"
27#include "class_list.h"
28
29
30using namespace std;
31
32
33CREATE_FACTORY(Door, CL_DOOR);
34
35
36
37//! list of all different animations a std md2model supports
38sAnim Door::animationList[2] =
39{
40 // begin, end, fps, interruptable
41  {   0,  15,  30,  0 },   //!< OPEN
42  {   15, 29,  30,  0 }    //!< CLOSE
43};
44
45
46
47Door::Door ()
48{
49  this->init();
50}
51
52
53Door::Door(const TiXmlElement* root)
54{
55
56  this->setClassID(CL_DOOR, "Door");
57  this->scale = 1.0f;
58
59  if( root != NULL)
60    this->loadParams(root);
61
62  this->toList(OM_COMMON);
63  this->bLocked = false;
64
65  this->loadMD2Texture("maps/doors.jpg");
66  this->loadModel("models/creatures/doors.md2", this->scale);
67
68  this->setAnimation(DOOR_CLOSE, MD2_ANIM_ONCE);
69}
70
71
72Door::~Door ()
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 Door::loadParams(const TiXmlElement* root)
82{
83  WorldEntity::loadParams(root);
84
85  LoadParam(root, "action-radius", this, Door, setActionRadius)
86      .describe("sets the action radius of the door")
87      .defaultValues(3.0);
88  LoadParam(root, "scale", this, Door, 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  Door::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 Door::tick (float time)
113{
114  if( likely(this->getModel(0) != NULL))
115    ((InteractiveModel*)this->getModel(0))->tick(time);
116
117  if( !this->bOpen)
118  {
119    if( this->checkOpen())
120    {
121      this->open();
122    }
123  }
124  else
125  {
126    if( !this->checkOpen())
127    {
128      this->close();
129    }
130  }
131
132}
133
134
135/**
136 * open the door
137 */
138void Door::open()
139{
140  if( this->bLocked)
141    return;
142
143  this->setAnimation(DOOR_OPEN, MD2_ANIM_ONCE);
144  this->bOpen = true;
145}
146
147
148/**
149 * close the door
150 */
151void Door::close()
152{
153  this->setAnimation(DOOR_CLOSE, MD2_ANIM_ONCE);
154  this->bOpen = false;
155}
156
157
158
159/**
160 * checks if the door is open
161 */
162bool Door::checkOpen()
163{
164
165  std::list<BaseObject*>::const_iterator it;
166  const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE);
167  WorldEntity* entity;
168  float distance;
169
170  if( list == NULL)
171    return false;
172
173  // for all players
174  for( it = list->begin(); it != list->end(); it++)
175  {
176    entity = dynamic_cast<WorldEntity*>(*it);
177
178    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
179    if( distance < this->actionRadius)
180      return true;
181  }
182
183
184  list = ClassList::getList(CL_GENERIC_NPC);
185  if( list == NULL)
186    return false;
187  for( it = list->begin(); it != list->end(); it++)
188  {
189    entity = dynamic_cast<WorldEntity*>(*it);
190
191    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
192    if( distance < this->actionRadius)
193      return true;
194  }
195
196  return false;
197}
198
199
200
Note: See TracBrowser for help on using the repository browser.