Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/door.cc @ 9002

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

merged the branche single_player_map with the trunk

File size: 3.7 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,  9,  0 },   //!< OPEN
42  {   15, 30,  9,  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  this->setAnimation(DOOR_CLOSE, MD2_ANIM_ONCE);
68}
69
70
71Door::~Door ()
72{}
73
74
75
76/**
77 * loads the Settings of a MD2Creature from an XML-element.
78 * @param root the XML-element to load the MD2Creature's properties from
79 */
80void Door::loadParams(const TiXmlElement* root)
81{
82  WorldEntity::loadParams(root);
83
84  LoadParam(root, "action-radius", this, Door, setActionRadius)
85      .describe("sets the action radius of the door")
86      .defaultValues(3.0);
87  LoadParam(root, "scale", this, Door, setScale)
88      .describe("sets the scale of the door")
89      .defaultValues(1.0);
90}
91
92
93/**
94 * sets the animatin of this entity
95 */
96void  Door::setAnimation(int animNum, int playbackMode)
97{
98  if( likely(this->getModel(0) != NULL))
99    ((InteractiveModel*)this->getModel(0))->setAnimation(animationList[animNum].firstFrame,
100                                                         animationList[animNum].lastFrame,
101                                                         animationList[animNum].fps,
102                                                         animationList[animNum].bStoppable,
103                                                         playbackMode);
104}
105
106
107/**
108 * ticks the door
109 * @param time: time since last tick
110 */
111void Door::tick (float time)
112{
113  if( likely(this->getModel(0) != NULL))
114    ((InteractiveModel*)this->getModel(0))->tick(time);
115
116  if( this->checkOpen() && !this->bOpen)
117    this->open();
118  else if( bOpen)
119    this->close();
120
121}
122
123
124/**
125 * open the door
126 */
127void Door::open()
128{
129  if( this->bLocked)
130    return;
131
132  this->setAnimation(DOOR_OPEN, MD2_ANIM_ONCE);
133  this->bOpen = true;
134}
135
136
137/**
138 * close the door
139 */
140void Door::close()
141{
142  this->setAnimation(DOOR_CLOSE, MD2_ANIM_ONCE);
143  this->bOpen = false;
144}
145
146
147
148/**
149 * checks if the door is open
150 */
151bool Door::checkOpen()
152{
153
154  std::list<BaseObject*>::const_iterator it;
155  const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE);
156  WorldEntity* entity;
157  float distance;
158
159  if( list == NULL)
160    return false;
161
162  // for all players
163  for( it = list->begin(); it != list->end(); it++)
164  {
165    entity = dynamic_cast<WorldEntity*>(*it);
166
167    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
168    if( distance < this->actionRadius)
169      return true;
170  }
171
172
173  list = ClassList::getList(CL_GENERIC_NPC);
174  if( list == NULL)
175    return false;
176  for( it = list->begin(); it != list->end(); it++)
177  {
178    entity = dynamic_cast<WorldEntity*>(*it);
179
180    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
181    if( distance < this->actionRadius)
182      return true;
183  }
184
185  return false;
186}
187
188
189
Note: See TracBrowser for help on using the repository browser.