Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/single_player_map/src/world_entities/door.cc @ 8878

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

altering md2 model for dynamic animations choosement

File size: 2.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
24#include "interactive_model.h"
25
26#include "door.h"
27#include "class_list.h"
28
29
30using namespace std;
31
32
33CREATE_FACTORY(Door, CL_DOOR);
34
35
36Door::Door ()
37{
38  this->init();
39}
40
41
42Door::Door(const TiXmlElement* root)
43{
44  this->init();
45  if (root != NULL)
46    this->loadParams(root);
47}
48
49
50Door::~Door ()
51{}
52
53
54
55void Door::init()
56{
57  this->setClassID(CL_DOOR, "Door");
58  this->toList(OM_COMMON);
59}
60
61/**
62 * loads the Settings of a MD2Creature from an XML-element.
63 * @param root the XML-element to load the MD2Creature's properties from
64 */
65void Door::loadParams(const TiXmlElement* root)
66{
67  WorldEntity::loadParams(root);
68
69  LoadParam(root, "", this, Door, setActionRadius)
70      .describe("sets the action radius of the door")
71      .defaultValues(1);
72
73}
74
75
76/**
77 * sets the animatin of this entity
78 */
79void  Door::setAnimation(int animationIndex, int animPlaybackMode)
80{
81  if( likely(this->getModel(0) != NULL))
82    ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode);
83}
84
85
86/**
87 * ticks the door
88 * @param time: time since last tick
89 */
90void Door::tick (float time)
91{
92  if( likely(this->getModel(0) != NULL))
93    ((InteractiveModel*)this->getModel(0))->tick(time);
94
95  this->checkOpen();
96}
97
98
99/**
100 * open the door
101 */
102void Door::open()
103{
104  if( this->bLocked)
105    return;
106
107//   this->setAnimation();
108
109}
110
111
112/**
113 * close the door
114 */
115void Door::close()
116{
117
118}
119
120
121
122/**
123 * checks if the door is open
124 */
125bool Door::checkOpen()
126{
127
128  std::list<BaseObject*>::const_iterator it;
129  const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE);
130  WorldEntity* entity;
131  float distance;
132
133  if( list == NULL)
134    return false;
135
136  // for all players
137  for( it = list->begin(); it != list->end(); it++)
138  {
139    entity = dynamic_cast<WorldEntity*>(*it);
140
141    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
142    if( distance < this->actionRadius)
143      return true;
144  }
145
146
147  list = ClassList::getList(CL_GENERIC_NPC);
148  if( list == NULL)
149    return false;
150  for( it = list->begin(); it != list->end(); it++)
151  {
152    entity = dynamic_cast<WorldEntity*>(*it);
153
154    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
155    if( distance < this->actionRadius)
156      return true;
157  }
158
159  return false;
160}
161
162
163
Note: See TracBrowser for help on using the repository browser.