Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

door proximity algorithm

File size: 2.4 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, set)
70//       .describe("sets the animation of the md2 model")
71//       .defaultValues(1);
72
73}
74
75
76void  Door::setAnim(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/**
94 * checks if the door is open
95 */
96bool Door::checkOpen()
97{
98
99  std::list<BaseObject*>::const_iterator it;
100  const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE);
101  WorldEntity* entity;
102  float distance;
103
104  if( list == NULL)
105    return false;
106
107  // for all players
108  for( it = list->begin(); it != list->end(); it++)
109  {
110    entity = dynamic_cast<WorldEntity*>(*it);
111
112    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
113    if( distance < this->actionRadius)
114      return true;
115  }
116
117
118  list = ClassList::getList(CL_GENERIC_NPC);
119  if( list == NULL)
120    return false;
121  for( it = list->begin(); it != list->end(); it++)
122  {
123    entity = dynamic_cast<WorldEntity*>(*it);
124
125    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
126    if( distance < this->actionRadius)
127      return true;
128  }
129
130  return false;
131}
132
133
134
Note: See TracBrowser for help on using the repository browser.