[5907] | 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: Benjamin Knecht |
---|
[6034] | 13 | co-programmer: Silvan Nellen |
---|
[5907] | 14 | |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
| 18 | |
---|
| 19 | #include "executor/executor.h" |
---|
| 20 | #include "space_ship.h" |
---|
| 21 | |
---|
[6034] | 22 | #include "objModel.h" |
---|
[5907] | 23 | #include "resource_manager.h" |
---|
| 24 | |
---|
| 25 | #include "weapons/weapon_manager.h" |
---|
| 26 | #include "weapons/test_gun.h" |
---|
| 27 | #include "weapons/turret.h" |
---|
| 28 | #include "weapons/cannon.h" |
---|
| 29 | |
---|
| 30 | #include "factory.h" |
---|
| 31 | #include "key_mapper.h" |
---|
[5978] | 32 | #include "event_handler.h" |
---|
[5907] | 33 | |
---|
[6424] | 34 | #include "network_game_manager.h" |
---|
| 35 | |
---|
[6243] | 36 | #include "power_ups/weapon_power_up.h" |
---|
| 37 | #include "power_ups/param_power_up.h" |
---|
| 38 | |
---|
[5978] | 39 | #include "graphics_engine.h" |
---|
| 40 | |
---|
[6287] | 41 | |
---|
| 42 | |
---|
[6306] | 43 | // #include "lib/gui/gl_gui/glgui_bar.h" |
---|
| 44 | // #include "lib/gui/gl_gui/glgui_pushbutton.h" |
---|
[6287] | 45 | |
---|
| 46 | |
---|
[5907] | 47 | using namespace std; |
---|
| 48 | |
---|
| 49 | CREATE_FACTORY(SpaceShip, CL_SPACE_SHIP); |
---|
| 50 | |
---|
| 51 | /** |
---|
| 52 | * creates the controlable Spaceship |
---|
| 53 | */ |
---|
| 54 | SpaceShip::SpaceShip() |
---|
| 55 | { |
---|
| 56 | this->init(); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * destructs the spaceship, deletes alocated memory |
---|
| 61 | */ |
---|
| 62 | SpaceShip::~SpaceShip () |
---|
| 63 | { |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | /** |
---|
| 67 | * loads a Spaceships information from a specified file. |
---|
| 68 | * @param fileName the name of the File to load the spaceship from (absolute path) |
---|
| 69 | */ |
---|
| 70 | SpaceShip::SpaceShip(const char* fileName) |
---|
| 71 | { |
---|
| 72 | this->init(); |
---|
| 73 | TiXmlDocument doc(fileName); |
---|
| 74 | |
---|
| 75 | if(!doc.LoadFile()) |
---|
| 76 | { |
---|
| 77 | PRINTF(2)("Loading file %s failed for spaceship.\n", fileName); |
---|
| 78 | return; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | this->loadParams(doc.RootElement()); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * creates a new Spaceship from Xml Data |
---|
| 86 | * @param root the xml element containing spaceship data |
---|
| 87 | |
---|
| 88 | @todo add more parameters to load |
---|
| 89 | */ |
---|
| 90 | SpaceShip::SpaceShip(const TiXmlElement* root) |
---|
| 91 | { |
---|
| 92 | this->init(); |
---|
| 93 | if (root != NULL) |
---|
| 94 | this->loadParams(root); |
---|
| 95 | |
---|
| 96 | //weapons: |
---|
| 97 | Weapon* wpRight = new TestGun(0); |
---|
| 98 | wpRight->setName("testGun Right"); |
---|
| 99 | Weapon* wpLeft = new TestGun(1); |
---|
| 100 | wpLeft->setName("testGun Left"); |
---|
[5982] | 101 | Weapon* cannon = dynamic_cast<Weapon*>(Factory::fabricate(CL_CANNON)); |
---|
[5907] | 102 | |
---|
| 103 | cannon->setName("BFG"); |
---|
| 104 | |
---|
[6443] | 105 | this->addWeapon(wpLeft, 1, 0); |
---|
| 106 | this->addWeapon(wpRight,1 ,1); |
---|
| 107 | this->addWeapon(cannon, 0, 6); |
---|
[5907] | 108 | |
---|
[6443] | 109 | //this->addWeapon(turret, 3, 0); |
---|
[5907] | 110 | |
---|
| 111 | this->getWeaponManager()->changeWeaponConfig(1); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * initializes a Spaceship |
---|
| 117 | */ |
---|
| 118 | void SpaceShip::init() |
---|
| 119 | { |
---|
| 120 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
| 121 | this->setClassID(CL_SPACE_SHIP, "SpaceShip"); |
---|
| 122 | |
---|
| 123 | PRINTF(4)("SPACESHIP INIT\n"); |
---|
| 124 | |
---|
[6426] | 125 | EventHandler::getInstance()->grabEvents(true); |
---|
[5907] | 126 | |
---|
[5978] | 127 | bUp = bDown = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = false; |
---|
[5907] | 128 | bFire = false; |
---|
[5978] | 129 | xMouse = yMouse = 0; |
---|
| 130 | mouseSensitivity = 0.001; |
---|
[6034] | 131 | airViscosity = 1.0; |
---|
[5978] | 132 | cycle = 0.0; |
---|
[5907] | 133 | |
---|
[6430] | 134 | this->setMaxEnergy(100); |
---|
| 135 | this->setEnergy(80); |
---|
[5982] | 136 | |
---|
[5907] | 137 | travelSpeed = 15.0; |
---|
| 138 | this->velocity = Vector(0.0,0.0,0.0); |
---|
[6162] | 139 | this->mouseDir = this->getAbsDir(); |
---|
[5907] | 140 | |
---|
[6306] | 141 | // GLGuiButton* button = new GLGuiPushButton(); |
---|
| 142 | // button->show(); |
---|
| 143 | // button->setLabel("orxonox"); |
---|
| 144 | // button->setBindNode(this); |
---|
| 145 | // GLGuiBar* bar = new GLGuiBar(); |
---|
| 146 | // bar->show(); |
---|
| 147 | // bar->setValue(7.0); |
---|
| 148 | // bar->setMaximum(10); |
---|
| 149 | // bar->setSize2D( 20, 100); |
---|
| 150 | // bar->setAbsCoor2D( 10, 200); |
---|
[6300] | 151 | |
---|
[5907] | 152 | //add events to the eventlist |
---|
[5978] | 153 | registerEvent(SDLK_w); |
---|
| 154 | registerEvent(SDLK_s); |
---|
| 155 | registerEvent(SDLK_a); |
---|
| 156 | registerEvent(SDLK_d); |
---|
| 157 | registerEvent(SDLK_q); |
---|
| 158 | registerEvent(SDLK_e); |
---|
[5907] | 159 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
| 160 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 161 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
| 162 | registerEvent(SDLK_PAGEUP); |
---|
| 163 | registerEvent(SDLK_PAGEDOWN); |
---|
[5978] | 164 | registerEvent(EV_MOUSE_MOTION); |
---|
[5907] | 165 | |
---|
| 166 | this->getWeaponManager()->setSlotCount(7); |
---|
| 167 | |
---|
| 168 | this->getWeaponManager()->setSlotPosition(0, Vector(-2.6, .1, -3.0)); |
---|
| 169 | this->getWeaponManager()->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 170 | |
---|
| 171 | this->getWeaponManager()->setSlotPosition(1, Vector(-2.6, .1, 3.0)); |
---|
| 172 | this->getWeaponManager()->setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 173 | |
---|
| 174 | this->getWeaponManager()->setSlotPosition(2, Vector(-1.5, .5, -.5)); |
---|
| 175 | this->getWeaponManager()->setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
| 176 | |
---|
| 177 | this->getWeaponManager()->setSlotPosition(3, Vector(-1.5, .5, .5)); |
---|
| 178 | this->getWeaponManager()->setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
| 179 | |
---|
| 180 | this->getWeaponManager()->setSlotPosition(4, Vector(-1.5, -.5, .5)); |
---|
| 181 | this->getWeaponManager()->setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
| 182 | |
---|
| 183 | this->getWeaponManager()->setSlotPosition(5, Vector(-1.5, -.5, -.5)); |
---|
| 184 | this->getWeaponManager()->setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
| 185 | // |
---|
| 186 | this->getWeaponManager()->setSlotPosition(6, Vector(-1, 0.0, 0)); |
---|
| 187 | this->getWeaponManager()->setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 188 | // |
---|
| 189 | // this->getWeaponManager()->setSlotPosition(8, Vector(-2.5, -0.3, -2.0)); |
---|
| 190 | // this->getWeaponManager()->setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0))); |
---|
| 191 | // |
---|
| 192 | // this->getWeaponManager()->setSlotPosition(9, Vector(-2.5, -0.3, 2.0)); |
---|
| 193 | // this->getWeaponManager()->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: |
---|
| 194 | |
---|
[6162] | 195 | this->getWeaponManager()->getFixedTarget()->setParent(this); |
---|
| 196 | this->getWeaponManager()->getFixedTarget()->setRelCoor(100000,0,0); |
---|
| 197 | |
---|
[6222] | 198 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
---|
[5907] | 199 | } |
---|
| 200 | |
---|
| 201 | /** |
---|
| 202 | * loads the Settings of a SpaceShip from an XML-element. |
---|
| 203 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 204 | */ |
---|
| 205 | void SpaceShip::loadParams(const TiXmlElement* root) |
---|
| 206 | { |
---|
| 207 | static_cast<WorldEntity*>(this)->loadParams(root); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | |
---|
[6222] | 211 | void SpaceShip::enter() |
---|
| 212 | { |
---|
| 213 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true); |
---|
[6241] | 214 | this->attachCamera(); |
---|
[6222] | 215 | } |
---|
| 216 | |
---|
| 217 | void SpaceShip::leave() |
---|
| 218 | { |
---|
| 219 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
---|
[6241] | 220 | this->detachCamera(); |
---|
[6222] | 221 | } |
---|
| 222 | |
---|
[5907] | 223 | |
---|
| 224 | /** |
---|
| 225 | * effect that occurs after the SpaceShip is spawned |
---|
| 226 | */ |
---|
| 227 | void SpaceShip::postSpawn () |
---|
| 228 | { |
---|
| 229 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | /** |
---|
| 233 | * the action occuring if the spaceship left the game |
---|
| 234 | */ |
---|
| 235 | void SpaceShip::leftWorld () |
---|
| 236 | {} |
---|
| 237 | |
---|
| 238 | WorldEntity* ref = NULL; |
---|
| 239 | /** |
---|
| 240 | * this function is called, when two entities collide |
---|
| 241 | * @param entity: the world entity with whom it collides |
---|
| 242 | * |
---|
| 243 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 244 | */ |
---|
| 245 | void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 246 | { |
---|
[6436] | 247 | Playable::collidesWith(entity, location); |
---|
[5907] | 248 | if (entity->isA(CL_TURRET_POWER_UP) && entity != ref) |
---|
| 249 | { |
---|
| 250 | this->ADDWEAPON(); |
---|
| 251 | ref = entity; |
---|
| 252 | } |
---|
| 253 | // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z); |
---|
| 254 | } |
---|
| 255 | |
---|
| 256 | /** |
---|
| 257 | * draws the spaceship after transforming it. |
---|
| 258 | */ |
---|
| 259 | void SpaceShip::draw () const |
---|
| 260 | { |
---|
[6281] | 261 | WorldEntity::draw(); |
---|
[5907] | 262 | this->getWeaponManager()->draw(); |
---|
| 263 | |
---|
| 264 | //this->debug(0); |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | /** |
---|
| 268 | * the function called for each passing timeSnap |
---|
| 269 | * @param time The timespan passed since last update |
---|
| 270 | */ |
---|
| 271 | void SpaceShip::tick (float time) |
---|
| 272 | { |
---|
[6034] | 273 | |
---|
[5907] | 274 | // spaceship controlled movement |
---|
| 275 | this->calculateVelocity(time); |
---|
| 276 | |
---|
| 277 | Vector move = (velocity)*time; |
---|
| 278 | |
---|
[6034] | 279 | //orient the velocity in the direction of the spaceship. |
---|
| 280 | travelSpeed = velocity.len(); |
---|
| 281 | velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity; |
---|
| 282 | velocity = (velocity.getNormalized())*travelSpeed; |
---|
[6222] | 283 | |
---|
[6162] | 284 | //orient the spaceship in direction of the mouse |
---|
[6241] | 285 | rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)*3.0); |
---|
| 286 | if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) |
---|
[6162] | 287 | this->setAbsDir( rotQuat); |
---|
| 288 | //this->setAbsDirSoft(mouseDir,5); |
---|
[6222] | 289 | |
---|
[5978] | 290 | // this is the air friction (necessary for a smooth control) |
---|
| 291 | if(velocity.len() != 0) velocity -= velocity*0.01; |
---|
[5982] | 292 | |
---|
[6034] | 293 | //hoover effect |
---|
| 294 | cycle += time; |
---|
[5978] | 295 | this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); |
---|
[5982] | 296 | |
---|
[6034] | 297 | //readjust |
---|
[6430] | 298 | |
---|
[6426] | 299 | /* |
---|
| 300 | In the game "Yager" the spaceship gets readjusted when the player moves the mouse. |
---|
| 301 | I (bknecht) go and check it out how they do it, we could probably use this also in Orxonox. |
---|
| 302 | */ |
---|
[6430] | 303 | //if (xMouse != 0 && yMouse != 0) |
---|
| 304 | |
---|
[6426] | 305 | //if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); |
---|
[6034] | 306 | //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); |
---|
| 307 | |
---|
[5978] | 308 | //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); |
---|
[5907] | 309 | |
---|
| 310 | this->shiftCoor (move); |
---|
| 311 | |
---|
| 312 | this->getWeaponManager()->tick(time); |
---|
| 313 | // weapon system manipulation |
---|
| 314 | this->weaponAction(); |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | /** |
---|
| 318 | * calculate the velocity |
---|
| 319 | * @param time the timeslice since the last frame |
---|
| 320 | */ |
---|
| 321 | void SpaceShip::calculateVelocity (float time) |
---|
| 322 | { |
---|
| 323 | Vector accel(0.0, 0.0, 0.0); |
---|
[6162] | 324 | /* |
---|
| 325 | Vector rot(0.0, 0.0, 0.0); // wird benötigt für Helicopter |
---|
| 326 | */ |
---|
[5907] | 327 | //float rotVal = 0.0; |
---|
[5912] | 328 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
[5907] | 329 | /* calculate the direction in which the craft is heading */ |
---|
| 330 | |
---|
[6222] | 331 | Plane plane(Vector(0,1,0), Vector(0,0,0)); |
---|
| 332 | |
---|
[5907] | 333 | if( this->bUp ) |
---|
| 334 | { |
---|
[5978] | 335 | //this->shiftCoor(this->getAbsDirX()); |
---|
| 336 | accel += (this->getAbsDirX())*2; |
---|
[6222] | 337 | |
---|
[6162] | 338 | /* Heli-Steuerung |
---|
| 339 | accel += (this->getAbsDirX()*2; |
---|
| 340 | if( |
---|
| 341 | */ |
---|
[5907] | 342 | } |
---|
| 343 | |
---|
| 344 | if( this->bDown ) |
---|
[5908] | 345 | { |
---|
[5978] | 346 | //this->shiftCoor((this->getAbsDirX())*-1); |
---|
| 347 | accel -= (this->getAbsDirX())*2; |
---|
[5907] | 348 | } |
---|
| 349 | |
---|
[6034] | 350 | if( this->bLeft/* > -this->getRelCoor().z*2*/) |
---|
[5907] | 351 | { |
---|
[5912] | 352 | this->shiftDir(Quaternion(time, Vector(0,1,0))); |
---|
| 353 | // accel -= rightDirection; |
---|
[5908] | 354 | //velocityDir.normalize(); |
---|
[5907] | 355 | //rot +=Vector(1,0,0); |
---|
| 356 | //rotVal -= .4; |
---|
| 357 | } |
---|
| 358 | if( this->bRight /* > this->getRelCoor().z*2*/) |
---|
| 359 | { |
---|
[5912] | 360 | this->shiftDir(Quaternion(-time, Vector(0,1,0))); |
---|
| 361 | |
---|
| 362 | // accel += rightDirection; |
---|
[5908] | 363 | //velocityDir.normalize(); |
---|
[5907] | 364 | //rot += Vector(1,0,0); |
---|
| 365 | //rotVal += .4; |
---|
| 366 | } |
---|
[5982] | 367 | |
---|
[6034] | 368 | |
---|
[5978] | 369 | if( this->bRollL /* > -this->getRelCoor().z*2*/) |
---|
| 370 | { |
---|
[6162] | 371 | mouseDir *= Quaternion(-time, Vector(1,0,0)); |
---|
[5978] | 372 | // accel -= rightDirection; |
---|
| 373 | //velocityDir.normalize(); |
---|
| 374 | //rot +=Vector(1,0,0); |
---|
| 375 | //rotVal -= .4; |
---|
| 376 | } |
---|
| 377 | if( this->bRollR /* > this->getRelCoor().z*2*/) |
---|
| 378 | { |
---|
[6162] | 379 | mouseDir *= Quaternion(time, Vector(1,0,0)); |
---|
[5978] | 380 | |
---|
| 381 | // accel += rightDirection; |
---|
| 382 | //velocityDir.normalize(); |
---|
| 383 | //rot += Vector(1,0,0); |
---|
| 384 | //rotVal += .4; |
---|
| 385 | } |
---|
[5907] | 386 | if (this->bAscend ) |
---|
| 387 | { |
---|
[5912] | 388 | this->shiftDir(Quaternion(time, Vector(0,0,1))); |
---|
| 389 | |
---|
| 390 | // accel += upDirection; |
---|
[5908] | 391 | //velocityDir.normalize(); |
---|
[5907] | 392 | //rot += Vector(0,0,1); |
---|
| 393 | //rotVal += .4; |
---|
| 394 | } |
---|
| 395 | if (this->bDescend ) |
---|
| 396 | { |
---|
[5912] | 397 | this->shiftDir(Quaternion(-time, Vector(0,0,1))); |
---|
| 398 | |
---|
| 399 | // accel -= upDirection; |
---|
[5908] | 400 | //velocityDir.normalize(); |
---|
[5907] | 401 | //rot += Vector(0,0,1); |
---|
| 402 | //rotVal -= .4; |
---|
| 403 | } |
---|
| 404 | |
---|
[5978] | 405 | velocity += accel; |
---|
[5907] | 406 | //rot.normalize(); |
---|
| 407 | //this->setRelDirSoft(Quaternion(rotVal, rot), 5); |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | /** |
---|
| 411 | * weapon manipulation by the player |
---|
| 412 | */ |
---|
| 413 | void SpaceShip::weaponAction() |
---|
| 414 | { |
---|
| 415 | if( this->bFire) |
---|
| 416 | { |
---|
| 417 | this->getWeaponManager()->fire(); |
---|
| 418 | } |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | /** |
---|
| 422 | * @todo switch statement ?? |
---|
| 423 | */ |
---|
| 424 | void SpaceShip::process(const Event &event) |
---|
| 425 | { |
---|
[5982] | 426 | |
---|
| 427 | |
---|
[5978] | 428 | if( event.type == SDLK_a) |
---|
| 429 | this->bRollL = event.bPressed; |
---|
| 430 | else if( event.type == SDLK_d) |
---|
| 431 | this->bRollR = event.bPressed; |
---|
[5907] | 432 | else if( event.type == KeyMapper::PEV_FIRE1) |
---|
| 433 | this->bFire = event.bPressed; |
---|
| 434 | else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed) |
---|
[6443] | 435 | { |
---|
[6444] | 436 | this->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange; |
---|
[6443] | 437 | } |
---|
[5907] | 438 | else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed) |
---|
[6444] | 439 | this->previousWeaponConfig(); |
---|
[5978] | 440 | else if( event.type == SDLK_w) |
---|
| 441 | this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
| 442 | else if( event.type == SDLK_s) |
---|
| 443 | this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
| 444 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 445 | { |
---|
| 446 | this->xMouse = event.xRel; |
---|
| 447 | this->yMouse = event.yRel; |
---|
[6162] | 448 | mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))); |
---|
[6241] | 449 | // if( xMouse*xMouse + yMouse*yMouse < 0.9) |
---|
| 450 | //this->setAbsDir(mouseDir); |
---|
[5978] | 451 | } |
---|
[5907] | 452 | } |
---|
| 453 | |
---|
[6243] | 454 | /** |
---|
| 455 | * |
---|
| 456 | */ |
---|
| 457 | bool SpaceShip::pickup(PowerUp* powerUp) |
---|
| 458 | { |
---|
| 459 | if(powerUp->isA(CL_WEAPON_POWER_UP)) { |
---|
| 460 | Weapon* weapon = dynamic_cast<WeaponPowerUp*>(powerUp)->getWeapon(); |
---|
| 461 | WeaponManager* manager = this->getWeaponManager(); |
---|
| 462 | int slot = manager->getNextFreeSlot(0, weapon->getCapability()); |
---|
| 463 | if(slot >= 0) { |
---|
| 464 | manager->addWeapon(weapon, 0, slot); |
---|
| 465 | return true; |
---|
| 466 | } |
---|
| 467 | } |
---|
| 468 | else if(powerUp->isA(CL_PARAM_POWER_UP)) { |
---|
| 469 | ParamPowerUp* ppu = dynamic_cast<ParamPowerUp*>(powerUp); |
---|
| 470 | switch(ppu->getType()) { |
---|
| 471 | case PARAM_SHIELD: |
---|
| 472 | break; |
---|
| 473 | } |
---|
| 474 | } |
---|
| 475 | return false; |
---|
| 476 | } |
---|
| 477 | |
---|
[5907] | 478 | #include "weapons/aiming_turret.h" |
---|
| 479 | // FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG |
---|
| 480 | void SpaceShip::ADDWEAPON() |
---|
| 481 | { |
---|
| 482 | Weapon* turret = NULL; |
---|
| 483 | |
---|
[6306] | 484 | if ((float)rand()/RAND_MAX < .9) |
---|
[5907] | 485 | { |
---|
| 486 | //if (this->getWeaponManager()->hasFreeSlot(2, WTYPE_TURRET)) |
---|
| 487 | { |
---|
| 488 | turret = new Turret(); |
---|
[6443] | 489 | this->addWeapon(turret, 2); |
---|
[5907] | 490 | this->getWeaponManager()->changeWeaponConfig(2); |
---|
| 491 | } |
---|
| 492 | } |
---|
| 493 | else |
---|
| 494 | { |
---|
| 495 | //if (this->getWeaponManager()->hasFreeSlot(3)) |
---|
| 496 | { |
---|
[6426] | 497 | turret = dynamic_cast<Weapon*>(Factory::fabricate(CL_TARGETING_TURRET)); |
---|
| 498 | if (turret != NULL) |
---|
[6443] | 499 | this->addWeapon(turret, 3); |
---|
[5907] | 500 | |
---|
| 501 | this->getWeaponManager()->changeWeaponConfig(3); |
---|
| 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | if(turret != NULL) |
---|
| 506 | { |
---|
| 507 | turret->setName("Turret"); |
---|
| 508 | turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1); |
---|
| 509 | } |
---|
| 510 | } |
---|
[6424] | 511 | |
---|
| 512 | |
---|
| 513 | int SpaceShip::writeBytes( const byte * data, int length, int sender ) |
---|
| 514 | { |
---|
| 515 | setRequestedSync( false ); |
---|
| 516 | setIsOutOfSync( false ); |
---|
| 517 | |
---|
| 518 | SYNCHELP_READ_BEGIN(); |
---|
| 519 | |
---|
| 520 | SYNCHELP_READ_FKT( WorldEntity::writeState ); |
---|
| 521 | |
---|
| 522 | return SYNCHELP_READ_N; |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | int SpaceShip::readBytes( byte * data, int maxLength, int * reciever ) |
---|
| 526 | { |
---|
| 527 | if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) |
---|
| 528 | { |
---|
| 529 | (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); |
---|
| 530 | setRequestedSync( true ); |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | int rec = this->getRequestSync(); |
---|
| 534 | if ( rec > 0 ) |
---|
| 535 | { |
---|
| 536 | *reciever = rec; |
---|
| 537 | |
---|
| 538 | SYNCHELP_WRITE_BEGIN(); |
---|
| 539 | |
---|
| 540 | SYNCHELP_WRITE_FKT( WorldEntity::readState ); |
---|
| 541 | |
---|
| 542 | return SYNCHELP_WRITE_N; |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | *reciever = 0; |
---|
| 546 | return 0; |
---|
| 547 | } |
---|