Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/npcs/repair_station.cc @ 10753

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

merged branche data-fix back to trunk. this breaks compatibility with the old data/trunk data repository! be sure to update your data trunk

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