Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9869 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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