Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

collision reaction stuff

File size: 2.6 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
76void  Door::setAnimation(int animationIndex, int animPlaybackMode)
77{
78  if( likely(this->getModel(0) != NULL))
79    ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode);
80}
81
82
83void Door::tick (float time)
84{
85  if( likely(this->getModel(0) != NULL))
86    ((InteractiveModel*)this->getModel(0))->tick(time);
87
88
89}
90
91
92/**
93 * open the door
94 */
95void Door::open()
96{
97  if( this->bLocked)
98    return;
99
100//   this->setAnimation();
101
102}
103
104
105/**
106 * close the door
107 */
108void Door::close()
109{
110
111}
112
113
114
115/**
116 * checks if the door is open
117 */
118bool Door::checkOpen()
119{
120
121  std::list<BaseObject*>::const_iterator it;
122  const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE);
123  WorldEntity* entity;
124  float distance;
125
126  if( list == NULL)
127    return false;
128
129  // for all players
130  for( it = list->begin(); it != list->end(); it++)
131  {
132    entity = dynamic_cast<WorldEntity*>(*it);
133
134    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
135    if( distance < this->actionRadius)
136      return true;
137  }
138
139
140  list = ClassList::getList(CL_GENERIC_NPC);
141  if( list == NULL)
142    return false;
143  for( it = list->begin(); it != list->end(); it++)
144  {
145    entity = dynamic_cast<WorldEntity*>(*it);
146
147    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
148    if( distance < this->actionRadius)
149      return true;
150  }
151
152  return false;
153}
154
155
156
Note: See TracBrowser for help on using the repository browser.