Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/world_entities/npcs/repair_station.cc @ 9518

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

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 4.1 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#include "interactive_model.h"
24
25
26#include "repair_station.h"
27#include "class_list.h"
28
29
30
31
32
33CREATE_FACTORY(RepairStation, CL_DOOR);
34
35
36
37//! list of all different animations a std md2model supports
38// sAnim RepairStation::animationList[2] =
39// {
40//  // begin, end, fps, interruptable
41//   {   0,  10,  30,  0 },   //!< OPEN
42//   {   10, 20,  30,  0 }    //!< CLOSE
43// };
44
45
46sAnim RepairStation::animationList[8] =
47{
48 // begin, end, fps, interruptable
49  {   0,  12,  20,  0 },   //!< CYCLE01
50  {   12, 24,  30,  0 },   //!< CYCLE02
51  {   24, 40,  10,  0 },   //!< CYCLE03
52  {   40, 55,  30,  0 },   //!< CYCLE04
53  {   55, 68,  20,  0 },   //!< CYCLE05
54  {   68, 81,  30,  0 },   //!< CYCLE06
55  {   81, 89,  40,  0 },   //!< CYCLE07
56  {   89, 99,  30,  0 }    //!< CYCLE08
57};
58
59
60
61RepairStation::RepairStation ()
62{
63  this->init();
64}
65
66
67RepairStation::RepairStation(const TiXmlElement* root)
68{
69
70  this->setClassID(CL_DOOR, "RepairStation");
71  this->scale = 1.0f;
72
73  if( root != NULL)
74    this->loadParams(root);
75
76  this->toList(OM_COMMON);
77
78  this->bActivated = true;
79  this->animationStep = 1;
80  this->animationCurrent = REPAIR_CYCLE01;
81
82  this->loadMD2Texture("maps/repairstation.jpg");
83  this->loadModel("models/creatures/repairstation.md2", this->scale);
84
85  this->setAnimation(REPAIR_CYCLE01, MD2_ANIM_ONCE);
86}
87
88
89RepairStation::~RepairStation ()
90{}
91
92
93
94/**
95 * loads the Settings of a MD2Creature from an XML-element.
96 * @param root the XML-element to load the MD2Creature's properties from
97 */
98void RepairStation::loadParams(const TiXmlElement* root)
99{
100  WorldEntity::loadParams(root);
101
102  LoadParam(root, "scale", this, RepairStation, setScale)
103      .describe("sets the scale of the repair station")
104      .defaultValues(1.0);
105}
106
107
108/**
109 * sets the animatin of this entity
110 */
111void  RepairStation::setAnimation(int animNum, int playbackMode)
112{
113  if( likely(this->getModel(0) != NULL))
114    ((InteractiveModel*)this->getModel(0))->setAnimation(animationList[animNum].firstFrame,
115                                                         animationList[animNum].lastFrame,
116                                                         animationList[animNum].fps,
117                                                         animationList[animNum].bStoppable,
118                                                         playbackMode);
119}
120
121
122/**
123 * @returns the current animation number
124 */
125int RepairStation::getAnimation()
126{
127  if( likely(this->getModel(0) != NULL))
128    return ((InteractiveModel*)this->getModel(0))->getAnimation();
129  else
130    return -1;
131}
132
133
134
135/**
136 * @returns true if animation is finished
137 */
138bool RepairStation::isAnimationFinished()
139{
140  if( likely(this->getModel(0) != NULL))
141    return ((InteractiveModel*)this->getModel(0))->isAnimationFinished();
142  else
143    return false;
144}
145
146
147/**
148 * this activates the repair station and makes it working
149 */
150void RepairStation::activate()
151{
152  this->animationStep = 1;
153  this->bActivated = true;
154}
155
156
157/**
158 * this deactivates the repair station
159 */
160void RepairStation::deactivate()
161{
162  this->animationStep = 0;
163  this->bActivated = false;
164}
165
166
167/**
168 * this toggles the rotation direction
169 */
170void RepairStation::toggleRotation()
171{
172  this->animationStep *= -1;
173}
174
175
176/**
177 * ticks the door
178 * @param time: time since last tick
179 */
180void RepairStation::tick (float time)
181{
182  if( likely(this->getModel(0) != NULL))
183    ((InteractiveModel*)this->getModel(0))->tick(time);
184
185  if( !this->bActivated)
186    return;
187
188  if( this->isAnimationFinished())
189  {
190    this->animationCurrent = (this->animationCurrent + this->animationStep) % REPAIR_MAX_ANIMATIONS;
191    this->setAnimation( this->animationCurrent, MD2_ANIM_ONCE);
192  }
193}
194
195
196
197
Note: See TracBrowser for help on using the repository browser.