Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged the branche single_player_map with the trunk

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