Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

the texture door patch from fabian

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
28
29ObjectListDefinition(Door);
30CREATE_FACTORY(Door);
31
32
33
34//! list of all different animations a std md2model supports
35sAnim Door::animationList[2] =
36{
37 // begin, end, fps, interruptable
38  {   0,  15,  30,  0 },   //!< OPEN
39  {   15, 29,  30,  0 }    //!< CLOSE
40};
41
42
43
44Door::Door(const TiXmlElement* root)
45{
46  this->registerObject(this, Door::_objectList);
47  this->scale = 1.0f;
48  this->actionRadius = 1.0;
49
50  if( root != NULL)
51    this->loadParams(root);
52
53  this->toList(OM_COMMON);
54  this->bLocked = false;
55  this->bOpen = false;
56
57//  this->loadMD2Texture("textures/doors.jpg");
58//  this->loadModel("models/creatures/doors.md2", this->scale);
59
60  this->setAnimation(DOOR_CLOSE, MD2_ANIM_ONCE);
61}
62
63
64Door::~Door ()
65{}
66
67
68
69/**
70 * loads the Settings of a MD2Creature from an XML-element.
71 * @param root the XML-element to load the MD2Creature's properties from
72 */
73void Door::loadParams(const TiXmlElement* root)
74{
75  WorldEntity::loadParams(root);
76
77  LoadParam(root, "action-radius", this, Door, setActionRadius)
78      .describe("sets the action radius of the door")
79      .defaultValues(3.0);
80  LoadParam(root, "scale", this, Door, setScale)
81      .describe("sets the scale of the door")
82      .defaultValues(1.0);
83}
84
85
86/**
87 * sets the animatin of this entity
88 */
89void  Door::setAnimation(int animNum, int playbackMode)
90{
91  if( likely(this->getModel(0) != NULL))
92    ((InteractiveModel*)this->getModel(0))->setAnimation(animationList[animNum].firstFrame,
93                                                         animationList[animNum].lastFrame,
94                                                         animationList[animNum].fps,
95                                                         animationList[animNum].bStoppable,
96                                                         playbackMode);
97}
98
99
100/**
101 * ticks the door
102 * @param time: time since last tick
103 */
104void Door::tick (float time)
105{
106  if( likely(this->getModel(0) != NULL))
107    ((InteractiveModel*)this->getModel(0))->tick(time);
108
109  if( !this->bOpen)
110  {
111    if( this->checkOpen())
112    {
113      this->open();
114    }
115  }
116  else
117  {
118    if( !this->checkOpen())
119    {
120      this->close();
121    }
122  }
123
124}
125
126
127/**
128 * open the door
129 */
130void Door::open()
131{
132  if( this->bLocked)
133    return;
134
135  this->setAnimation(DOOR_OPEN, MD2_ANIM_ONCE);
136  this->bOpen = true;
137}
138
139
140/**
141 * close the door
142 */
143void Door::close()
144{
145  this->setAnimation(DOOR_CLOSE, MD2_ANIM_ONCE);
146  this->bOpen = false;
147}
148
149
150#include "playable.h"
151#include "generic_npc.h"
152/**
153 * checks if the door is open
154 */
155bool Door::checkOpen()
156{
157
158  WorldEntity* entity;
159  float distance;
160
161  for (ObjectList<Playable>::const_iterator it = Playable::objectList().begin();
162       it != Playable::objectList().end();
163       ++it)
164  // for all players
165  {
166    entity = (*it);
167
168    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
169    if( distance < this->actionRadius)
170      return true;
171  }
172
173
174
175  for (ObjectList<GenericNPC>::const_iterator it = GenericNPC::objectList().begin();
176       it != GenericNPC::objectList().end();
177       ++it)
178  {
179    entity = (*it);
180
181    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
182    if( distance < this->actionRadius)
183      return true;
184  }
185
186  return false;
187}
188
189
190
Note: See TracBrowser for help on using the repository browser.