[8927] | 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 | |
---|
[10114] | 28 | |
---|
| 29 | ObjectListDefinition(RepairStation); |
---|
[9869] | 30 | CREATE_FACTORY(RepairStation); |
---|
[8927] | 31 | |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | //! list of all different animations a std md2model supports |
---|
[8931] | 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 | |
---|
| 43 | sAnim RepairStation::animationList[8] = |
---|
[8927] | 44 | { |
---|
| 45 | // begin, end, fps, interruptable |
---|
[8945] | 46 | { 0, 12, 20, 0 }, //!< CYCLE01 |
---|
[8931] | 47 | { 12, 24, 30, 0 }, //!< CYCLE02 |
---|
[8945] | 48 | { 24, 40, 10, 0 }, //!< CYCLE03 |
---|
[8931] | 49 | { 40, 55, 30, 0 }, //!< CYCLE04 |
---|
[8945] | 50 | { 55, 68, 20, 0 }, //!< CYCLE05 |
---|
[8931] | 51 | { 68, 81, 30, 0 }, //!< CYCLE06 |
---|
[8945] | 52 | { 81, 89, 40, 0 }, //!< CYCLE07 |
---|
[8931] | 53 | { 89, 99, 30, 0 } //!< CYCLE08 |
---|
[8927] | 54 | }; |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | RepairStation::RepairStation () |
---|
| 59 | { |
---|
| 60 | this->init(); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | RepairStation::RepairStation(const TiXmlElement* root) |
---|
| 65 | { |
---|
[9869] | 66 | this->registerObject(this, RepairStation::_objectList); |
---|
[8927] | 67 | this->scale = 1.0f; |
---|
| 68 | |
---|
| 69 | if( root != NULL) |
---|
| 70 | this->loadParams(root); |
---|
| 71 | |
---|
| 72 | this->toList(OM_COMMON); |
---|
| 73 | |
---|
[8945] | 74 | this->bActivated = true; |
---|
| 75 | this->animationStep = 1; |
---|
| 76 | this->animationCurrent = REPAIR_CYCLE01; |
---|
[8927] | 77 | |
---|
[10317] | 78 | this->loadMD2Texture("textures/repairstation.jpg"); |
---|
[8945] | 79 | this->loadModel("models/creatures/repairstation.md2", this->scale); |
---|
| 80 | |
---|
[8943] | 81 | this->setAnimation(REPAIR_CYCLE01, MD2_ANIM_ONCE); |
---|
[8927] | 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | RepairStation::~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 | */ |
---|
| 94 | void RepairStation::loadParams(const TiXmlElement* root) |
---|
| 95 | { |
---|
| 96 | WorldEntity::loadParams(root); |
---|
| 97 | |
---|
| 98 | LoadParam(root, "scale", this, RepairStation, setScale) |
---|
[8942] | 99 | .describe("sets the scale of the repair station") |
---|
[8927] | 100 | .defaultValues(1.0); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | /** |
---|
| 105 | * sets the animatin of this entity |
---|
| 106 | */ |
---|
| 107 | void 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 | |
---|
[8943] | 118 | /** |
---|
| 119 | * @returns the current animation number |
---|
| 120 | */ |
---|
| 121 | int RepairStation::getAnimation() |
---|
| 122 | { |
---|
| 123 | if( likely(this->getModel(0) != NULL)) |
---|
[8945] | 124 | return ((InteractiveModel*)this->getModel(0))->getAnimation(); |
---|
| 125 | else |
---|
| 126 | return -1; |
---|
[8943] | 127 | } |
---|
[8941] | 128 | |
---|
| 129 | |
---|
[8943] | 130 | |
---|
[8942] | 131 | /** |
---|
[8945] | 132 | * @returns true if animation is finished |
---|
| 133 | */ |
---|
| 134 | bool 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 | /** |
---|
[8942] | 144 | * this activates the repair station and makes it working |
---|
| 145 | */ |
---|
[8941] | 146 | void RepairStation::activate() |
---|
[8942] | 147 | { |
---|
| 148 | this->animationStep = 1; |
---|
[8945] | 149 | this->bActivated = true; |
---|
[8942] | 150 | } |
---|
[8941] | 151 | |
---|
[8942] | 152 | |
---|
| 153 | /** |
---|
| 154 | * this deactivates the repair station |
---|
| 155 | */ |
---|
[8941] | 156 | void RepairStation::deactivate() |
---|
[8942] | 157 | { |
---|
| 158 | this->animationStep = 0; |
---|
[8945] | 159 | this->bActivated = false; |
---|
[8942] | 160 | } |
---|
[8941] | 161 | |
---|
[8942] | 162 | |
---|
| 163 | /** |
---|
| 164 | * this toggles the rotation direction |
---|
| 165 | */ |
---|
[8941] | 166 | void RepairStation::toggleRotation() |
---|
[8942] | 167 | { |
---|
| 168 | this->animationStep *= -1; |
---|
| 169 | } |
---|
[8941] | 170 | |
---|
| 171 | |
---|
[8927] | 172 | /** |
---|
| 173 | * ticks the door |
---|
| 174 | * @param time: time since last tick |
---|
| 175 | */ |
---|
| 176 | void RepairStation::tick (float time) |
---|
| 177 | { |
---|
| 178 | if( likely(this->getModel(0) != NULL)) |
---|
| 179 | ((InteractiveModel*)this->getModel(0))->tick(time); |
---|
| 180 | |
---|
[8945] | 181 | if( !this->bActivated) |
---|
| 182 | return; |
---|
[8927] | 183 | |
---|
[8945] | 184 | if( this->isAnimationFinished()) |
---|
| 185 | { |
---|
| 186 | this->animationCurrent = (this->animationCurrent + this->animationStep) % REPAIR_MAX_ANIMATIONS; |
---|
| 187 | this->setAnimation( this->animationCurrent, MD2_ANIM_ONCE); |
---|
| 188 | } |
---|
[8927] | 189 | } |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | |
---|