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
RevLine 
[8870]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
[8874]24#include "interactive_model.h"
[8870]25
[8874]26#include "door.h"
27#include "class_list.h"
[8870]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");
[8872]58  this->toList(OM_COMMON);
[8870]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
[8876]69  LoadParam(root, "", this, Door, setActionRadius)
70      .describe("sets the action radius of the door")
71      .defaultValues(1);
[8870]72
73}
74
75
[8878]76/**
77 * sets the animatin of this entity
78 */
[8876]79void  Door::setAnimation(int animationIndex, int animPlaybackMode)
[8870]80{
81  if( likely(this->getModel(0) != NULL))
82    ((InteractiveModel*)this->getModel(0))->setAnimation(animationIndex, animPlaybackMode);
83}
84
85
[8878]86/**
87 * ticks the door
88 * @param time: time since last tick
89 */
[8870]90void Door::tick (float time)
91{
92  if( likely(this->getModel(0) != NULL))
93    ((InteractiveModel*)this->getModel(0))->tick(time);
94
[8878]95  this->checkOpen();
[8870]96}
97
98
[8876]99/**
100 * open the door
101 */
102void Door::open()
103{
104  if( this->bLocked)
105    return;
[8870]106
[8876]107//   this->setAnimation();
108
109}
110
111
[8872]112/**
[8876]113 * close the door
114 */
115void Door::close()
116{
117
118}
119
120
121
122/**
[8872]123 * checks if the door is open
124 */
[8874]125bool Door::checkOpen()
[8870]126{
127
[8874]128  std::list<BaseObject*>::const_iterator it;
129  const std::list<BaseObject*>* list = ClassList::getList(CL_PLAYABLE);
130  WorldEntity* entity;
[8875]131  float distance;
[8870]132
[8874]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
[8875]141    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
142    if( distance < this->actionRadius)
143      return true;
[8874]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  {
[8875]152    entity = dynamic_cast<WorldEntity*>(*it);
[8874]153
[8875]154    distance = fabs((this->getAbsCoor() - entity->getAbsCoor()).len());
155    if( distance < this->actionRadius)
156      return true;
[8874]157  }
158
159  return false;
[8870]160}
161
[8872]162
163
Note: See TracBrowser for help on using the repository browser.