[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 | |
---|
[10114] | 31 | |
---|
| 32 | ObjectListDefinition(SpaceTurret); |
---|
[9869] | 33 | CREATE_FACTORY(SpaceTurret); |
---|
[5739] | 34 | |
---|
[5596] | 35 | /** |
---|
[9180] | 36 | * constructs and loads a SpaceTurret from a XML-element |
---|
[5596] | 37 | * @param root the XML-element to load from |
---|
| 38 | */ |
---|
[9180] | 39 | SpaceTurret::SpaceTurret(const TiXmlElement* root) |
---|
[9869] | 40 | : NPC(root) |
---|
[5596] | 41 | { |
---|
| 42 | this->init(); |
---|
| 43 | if (root != NULL) |
---|
| 44 | this->loadParams(root); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * standard deconstructor |
---|
| 50 | */ |
---|
[9180] | 51 | SpaceTurret::~SpaceTurret () |
---|
[9869] | 52 | {} |
---|
[5596] | 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 | { |
---|
[9869] | 61 | this->registerObject(this, SpaceTurret::_objectList); |
---|
[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); |
---|
[9656] | 76 | |
---|
| 77 | this->wLeftHandle = registerVarId( new SynchronizeableString( &this->wLeft, &this->wLeft, "weapon-left", PERMISSION_MASTER_SERVER ) ); |
---|
| 78 | this->wRightHandle = registerVarId( new SynchronizeableString( &this->wRight, &this->wRight, "weapon-right", PERMISSION_MASTER_SERVER ) ); |
---|
| 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"); |
---|
[9869] | 100 | if (element != NULL) |
---|
| 101 | element = element->FirstChildElement(); |
---|
| 102 | if (element != NULL) |
---|
| 103 | this->left = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 104 | if (this->left) |
---|
| 105 | { |
---|
[9656] | 106 | this->wLeft = element->Value(); |
---|
| 107 | |
---|
[5819] | 108 | this->left->setParent(this); |
---|
[6142] | 109 | this->left->toList(this->getOMListNumber()); |
---|
[9181] | 110 | this->left->setRelCoor(0,15,-7.5); |
---|
[6433] | 111 | this->left->requestAction( WA_ACTIVATE); |
---|
[7102] | 112 | this->left->setParent(&this->weaponHolder[0]); |
---|
[5819] | 113 | } |
---|
| 114 | |
---|
| 115 | element = root->FirstChildElement("weapon-right"); |
---|
[9869] | 116 | if (element != NULL) |
---|
| 117 | element = element->FirstChildElement(); |
---|
| 118 | if (element != NULL) |
---|
| 119 | this->right = dynamic_cast<Weapon*>( Factory::fabricate( element) ); |
---|
[5819] | 120 | if (this->right) |
---|
| 121 | { |
---|
[9656] | 122 | this->wRight = element->Value(); |
---|
| 123 | |
---|
[5819] | 124 | this->right->setParent(this); |
---|
[6142] | 125 | this->right->toList(this->getOMListNumber()); |
---|
[9181] | 126 | this->right->setRelCoor(0,15,7.5); |
---|
[6433] | 127 | this->left->requestAction( WA_ACTIVATE); |
---|
[7102] | 128 | this->right->setParent(&this->weaponHolder[0]); |
---|
[5819] | 129 | } |
---|
[5596] | 130 | } |
---|
| 131 | |
---|
[9656] | 132 | |
---|
[5596] | 133 | /** |
---|
[9656] | 134 | * sets the left weapon called from net sync |
---|
| 135 | * @param wLeft the left weapon string |
---|
| 136 | */ |
---|
| 137 | void SpaceTurret::setWeaponLeft(const std::string& wLeft) |
---|
[9869] | 138 | {} |
---|
[9656] | 139 | |
---|
| 140 | /** |
---|
| 141 | * sets the left weapon called from net sync |
---|
| 142 | * @param wRught the right weapon string |
---|
| 143 | */ |
---|
| 144 | void SpaceTurret::setWeaponRight(const std::string& wRight) |
---|
| 145 | {} |
---|
| 146 | |
---|
| 147 | /** |
---|
[9180] | 148 | * advances the SpaceTurret about time seconds |
---|
[5596] | 149 | * @param time the Time to step |
---|
| 150 | */ |
---|
[9180] | 151 | void SpaceTurret::tick(float dt) |
---|
[5739] | 152 | { |
---|
[7076] | 153 | if(this->getHealth() > 0.0f && State::getPlayer() && |
---|
[9869] | 154 | State::getPlayer()->getPlayable() && |
---|
| 155 | State::getPlayer()->getPlayable()->distance(this) < 300) // HACK |
---|
[7076] | 156 | { |
---|
[9869] | 157 | if (likely(this->left != NULL)) |
---|
| 158 | { |
---|
| 159 | // this->left->tickW(dt); |
---|
| 160 | this->left->requestAction(WA_SHOOT); |
---|
| 161 | } |
---|
| 162 | if (likely(this->right != NULL)) |
---|
| 163 | { |
---|
| 164 | // this->right->tickW(dt); |
---|
| 165 | this->right->requestAction(WA_SHOOT); |
---|
| 166 | } |
---|
[6433] | 167 | } |
---|
[5739] | 168 | } |
---|
| 169 | |
---|
[5596] | 170 | /** |
---|
| 171 | * draws this worldEntity |
---|
| 172 | */ |
---|
[9180] | 173 | void SpaceTurret::draw () const |
---|
[5596] | 174 | { |
---|
[9180] | 175 | glPushMatrix(); |
---|
| 176 | glTranslatef (this->getAbsCoor ().x, |
---|
| 177 | this->getAbsCoor ().y, |
---|
| 178 | this->getAbsCoor ().z); |
---|
[5596] | 179 | |
---|
[9180] | 180 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
| 181 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
| 182 | |
---|
| 183 | this->getModel()->draw(); |
---|
| 184 | if (this->getModel() != NULL) |
---|
| 185 | this->getModel(3)->draw(); |
---|
| 186 | glPopMatrix(); |
---|
[9869] | 187 | /* |
---|
| 188 | if (this->left != NULL) |
---|
| 189 | this->left->draw(); |
---|
| 190 | if (this->right != NULL) |
---|
| 191 | this->right->draw();*/ |
---|
[5596] | 192 | } |
---|
| 193 | |
---|
| 194 | |
---|
[5680] | 195 | |
---|
| 196 | /** |
---|
| 197 | * |
---|
| 198 | * |
---|
| 199 | */ |
---|
[9180] | 200 | void SpaceTurret::postSpawn () |
---|
[9869] | 201 | {} |
---|
[5795] | 202 | |
---|
[5680] | 203 | /** |
---|
| 204 | * |
---|
| 205 | * |
---|
| 206 | */ |
---|
[9180] | 207 | void SpaceTurret::leftWorld () |
---|
[9869] | 208 | {} |
---|
[5795] | 209 | |
---|
[9180] | 210 | void SpaceTurret::destroy(WorldEntity* killer) |
---|
[7076] | 211 | { |
---|
| 212 | this->setAbsDirSoft(Quaternion(-90, Vector(0,0,1)), 90); |
---|
[7105] | 213 | Explosion::explode(this, Vector(10,10,10)); |
---|
[8777] | 214 | |
---|
| 215 | this->toList(OM_DEAD); |
---|
[9181] | 216 | |
---|
| 217 | if (this->left) |
---|
| 218 | this->left->toList(OM_DEAD); |
---|
| 219 | if (this->right) |
---|
| 220 | this->right->toList(OM_DEAD); |
---|
| 221 | |
---|
[7076] | 222 | } |
---|
[9656] | 223 | |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | /** |
---|
| 227 | * handler for changes on registred vars |
---|
| 228 | * @param id id's which changed |
---|
| 229 | */ |
---|
| 230 | void SpaceTurret::varChangeHandler( std::list< int > & id ) |
---|
| 231 | { |
---|
| 232 | if ( std::find( id.begin(), id.end(), this->wLeftHandle ) != id.end()) |
---|
| 233 | { |
---|
| 234 | this->setWeaponLeft(this->wLeft); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | if ( std::find( id.begin(), id.end(), this->wRightHandle ) != id.end() ) |
---|
| 238 | { |
---|
| 239 | this->setWeaponRight(this->wRight); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | |
---|
| 243 | WorldEntity::varChangeHandler( id ); |
---|
| 244 | } |
---|
| 245 | |
---|