[5596] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Manuel Leuenberger |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[9180] | 16 | #include "space_turret.h" |
---|
[5739] | 17 | #include "model.h" |
---|
[6432] | 18 | #include "world_entities/weapons/turret.h" |
---|
[5596] | 19 | |
---|
[7076] | 20 | #include "state.h" |
---|
| 21 | #include "playable.h" |
---|
| 22 | #include "player.h" |
---|
| 23 | |
---|
| 24 | |
---|
[7193] | 25 | #include "util/loading/factory.h" |
---|
[6341] | 26 | #include "network_game_manager.h" |
---|
[7193] | 27 | #include "util/loading/load_param.h" |
---|
[5795] | 28 | |
---|
[7103] | 29 | #include "effects/explosion.h" |
---|
| 30 | |
---|
[9180] | 31 | CREATE_FACTORY(SpaceTurret, CL_SPACE_TURRET); |
---|
[5739] | 32 | |
---|
[5596] | 33 | /** |
---|
[9180] | 34 | * constructs and loads a SpaceTurret from a XML-element |
---|
[5596] | 35 | * @param root the XML-element to load from |
---|
| 36 | */ |
---|
[9180] | 37 | SpaceTurret::SpaceTurret(const TiXmlElement* root) |
---|
[8724] | 38 | : NPC(root) |
---|
[5596] | 39 | { |
---|
| 40 | this->init(); |
---|
| 41 | if (root != NULL) |
---|
| 42 | this->loadParams(root); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | /** |
---|
| 47 | * standard deconstructor |
---|
| 48 | */ |
---|
[9180] | 49 | SpaceTurret::~SpaceTurret () |
---|
[5596] | 50 | { |
---|
| 51 | |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /** |
---|
[9180] | 56 | * initializes the SpaceTurret |
---|
[5596] | 57 | * @todo change this to what you wish |
---|
| 58 | */ |
---|
[9180] | 59 | void SpaceTurret::init() |
---|
[5596] | 60 | { |
---|
[9180] | 61 | this->setClassID(CL_SPACE_TURRET, "SpaceTurret"); |
---|
[9181] | 62 | this->loadModel("models/ground_turret_#.obj", 7.5); |
---|
| 63 | this->loadModel("models/comet.obj", 1.0f, 3); |
---|
[5795] | 64 | this->left = NULL; |
---|
| 65 | this->right = NULL; |
---|
| 66 | |
---|
[9206] | 67 | this->setHealthMax(100); |
---|
| 68 | this->setHealth(30); |
---|
[7076] | 69 | |
---|
[7102] | 70 | this->weaponHolder[0].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 71 | this->weaponHolder[1].addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
| 72 | |
---|
| 73 | this->weaponHolder[0].setRelCoor(0,25,0); |
---|
| 74 | this->weaponHolder[0].setParent(this); |
---|
| 75 | this->weaponHolder[1].setParent(this); |
---|
[9602] | 76 | |
---|
| 77 | this->wLeftHandle = registerVarId( new SynchronizeableString( &this->wLeft, &this->wLeft, "weapon-left" ) ); |
---|
| 78 | this->wRightHandle = registerVarId( new SynchronizeableString( &this->wRight, &this->wRight, "weapon-right" ) ); |
---|
| 79 | |
---|
[5596] | 80 | } |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | /** |
---|
[9180] | 84 | * loads a SpaceTurret from a XML-element |
---|
[5596] | 85 | * @param root the XML-element to load from |
---|
| 86 | * @todo make the class Loadable |
---|
| 87 | */ |
---|
[9180] | 88 | void SpaceTurret::loadParams(const TiXmlElement* root) |
---|
[5596] | 89 | { |
---|
| 90 | // all the clases this Entity is directly derived from must be called in this way, to load all settings. |
---|
[6512] | 91 | NPC::loadParams(root); |
---|
[5596] | 92 | |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | * @todo: make the class Loadable |
---|
| 96 | */ |
---|
[5819] | 97 | const TiXmlElement* element; |
---|
| 98 | |
---|
| 99 | element = root->FirstChildElement("weapon-left"); |
---|
| 100 | if (element != NULL) element = element->FirstChildElement(); |
---|
[5982] | 101 | this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 102 | if (this->left) |
---|
| 103 | { |
---|
[9602] | 104 | this->wLeft = element->Value(); |
---|
| 105 | |
---|
[5819] | 106 | this->left->setParent(this); |
---|
[6142] | 107 | this->left->toList(this->getOMListNumber()); |
---|
[9181] | 108 | this->left->setRelCoor(0,15,-7.5); |
---|
[6433] | 109 | this->left->requestAction( WA_ACTIVATE); |
---|
[7102] | 110 | this->left->setParent(&this->weaponHolder[0]); |
---|
[5819] | 111 | } |
---|
| 112 | |
---|
| 113 | element = root->FirstChildElement("weapon-right"); |
---|
| 114 | if (element != NULL) if (element != NULL) element = element->FirstChildElement(); |
---|
[5982] | 115 | this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 116 | if (this->right) |
---|
| 117 | { |
---|
[9602] | 118 | this->wRight = element->Value(); |
---|
| 119 | |
---|
[5819] | 120 | this->right->setParent(this); |
---|
[6142] | 121 | this->right->toList(this->getOMListNumber()); |
---|
[9181] | 122 | this->right->setRelCoor(0,15,7.5); |
---|
[6433] | 123 | this->left->requestAction( WA_ACTIVATE); |
---|
[7102] | 124 | this->right->setParent(&this->weaponHolder[0]); |
---|
[5819] | 125 | } |
---|
[5596] | 126 | } |
---|
| 127 | |
---|
[9602] | 128 | |
---|
[5596] | 129 | /** |
---|
[9602] | 130 | * sets the left weapon called from net sync |
---|
| 131 | * @param wLeft the left weapon string |
---|
| 132 | */ |
---|
| 133 | void SpaceTurret::setWeaponLeft(const std::string& wLeft) |
---|
| 134 | { |
---|
| 135 | |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | /** |
---|
| 139 | * sets the left weapon called from net sync |
---|
| 140 | * @param wRught the right weapon string |
---|
| 141 | */ |
---|
| 142 | void SpaceTurret::setWeaponRight(const std::string& wRight) |
---|
| 143 | {} |
---|
| 144 | |
---|
| 145 | /** |
---|
[9180] | 146 | * advances the SpaceTurret about time seconds |
---|
[5596] | 147 | * @param time the Time to step |
---|
| 148 | */ |
---|
[9180] | 149 | void SpaceTurret::tick(float dt) |
---|
[5739] | 150 | { |
---|
[7076] | 151 | if(this->getHealth() > 0.0f && State::getPlayer() && |
---|
| 152 | State::getPlayer()->getPlayable() && |
---|
[9181] | 153 | State::getPlayer()->getPlayable()->distance(this) < 300) // HACK |
---|
[7076] | 154 | { |
---|
[6433] | 155 | if (likely(this->left != NULL)) |
---|
| 156 | { |
---|
[6736] | 157 | // this->left->tickW(dt); |
---|
[6433] | 158 | this->left->requestAction(WA_SHOOT); |
---|
| 159 | } |
---|
| 160 | if (likely(this->right != NULL)) |
---|
| 161 | { |
---|
[6736] | 162 | // this->right->tickW(dt); |
---|
[6433] | 163 | this->right->requestAction(WA_SHOOT); |
---|
| 164 | } |
---|
[7076] | 165 | } |
---|
[5739] | 166 | } |
---|
| 167 | |
---|
[5596] | 168 | /** |
---|
| 169 | * draws this worldEntity |
---|
| 170 | */ |
---|
[9180] | 171 | void SpaceTurret::draw () const |
---|
[5596] | 172 | { |
---|
[9180] | 173 | glPushMatrix(); |
---|
| 174 | glTranslatef (this->getAbsCoor ().x, |
---|
| 175 | this->getAbsCoor ().y, |
---|
| 176 | this->getAbsCoor ().z); |
---|
[5596] | 177 | |
---|
[9180] | 178 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 179 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 180 | |
---|
| 181 | this->getModel()->draw(); |
---|
| 182 | if (this->getModel() != NULL) |
---|
| 183 | this->getModel(3)->draw(); |
---|
| 184 | glPopMatrix(); |
---|
[9181] | 185 | /* |
---|
[5819] | 186 | if (this->left != NULL) |
---|
[5795] | 187 | this->left->draw(); |
---|
| 188 | if (this->right != NULL) |
---|
[9181] | 189 | this->right->draw();*/ |
---|
[5596] | 190 | } |
---|
| 191 | |
---|
| 192 | |
---|
[5680] | 193 | |
---|
| 194 | /** |
---|
| 195 | * |
---|
| 196 | * |
---|
| 197 | */ |
---|
[9180] | 198 | void SpaceTurret::postSpawn () |
---|
[5680] | 199 | { |
---|
[5795] | 200 | |
---|
[5680] | 201 | } |
---|
| 202 | |
---|
| 203 | /** |
---|
| 204 | * |
---|
| 205 | * |
---|
| 206 | */ |
---|
[9180] | 207 | void SpaceTurret::leftWorld () |
---|
[5680] | 208 | { |
---|
[5795] | 209 | |
---|
[5680] | 210 | } |
---|
[6341] | 211 | |
---|
[9180] | 212 | void SpaceTurret::destroy(WorldEntity* killer) |
---|
[7076] | 213 | { |
---|
| 214 | this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90); |
---|
[7105] | 215 | Explosion::explode(this, Vector(10,10,10)); |
---|
[8777] | 216 | |
---|
| 217 | this->toList(OM_DEAD); |
---|
[9181] | 218 | |
---|
| 219 | if (this->left) |
---|
| 220 | this->left->toList(OM_DEAD); |
---|
| 221 | if (this->right) |
---|
| 222 | this->right->toList(OM_DEAD); |
---|
| 223 | |
---|
[7076] | 224 | } |
---|
[9602] | 225 | |
---|
| 226 | |
---|
| 227 | |
---|
| 228 | /** |
---|
| 229 | * handler for changes on registred vars |
---|
| 230 | * @param id id's which changed |
---|
| 231 | */ |
---|
| 232 | void SpaceTurret::varChangeHandler( std::list< int > & id ) |
---|
| 233 | { |
---|
| 234 | if ( std::find( id.begin(), id.end(), this->wLeftHandle ) != id.end()) |
---|
| 235 | { |
---|
| 236 | this->setWeaponLeft(this->wLeft); |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | if ( std::find( id.begin(), id.end(), this->wRightHandle ) != id.end() ) |
---|
| 240 | { |
---|
| 241 | this->setWeaponRight(this->wRight); |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | |
---|
| 245 | WorldEntity::varChangeHandler( id ); |
---|
| 246 | } |
---|
| 247 | |
---|