[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 | |
---|
[6420] | 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 | |
---|
| 105 | this->getWeaponManager()->addWeapon(wpLeft, 1, 0); |
---|
| 106 | this->getWeaponManager()->addWeapon(wpRight,1 ,1); |
---|
| 107 | this->getWeaponManager()->addWeapon(cannon, 0, 6); |
---|
| 108 | |
---|
| 109 | //this->getWeaponManager()->addWeapon(turret, 3, 0); |
---|
| 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 | |
---|
[6417] | 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 | |
---|
[5982] | 134 | |
---|
[5907] | 135 | travelSpeed = 15.0; |
---|
| 136 | this->velocity = Vector(0.0,0.0,0.0); |
---|
[6162] | 137 | this->mouseDir = this->getAbsDir(); |
---|
[5907] | 138 | |
---|
[6306] | 139 | // GLGuiButton* button = new GLGuiPushButton(); |
---|
| 140 | // button->show(); |
---|
| 141 | // button->setLabel("orxonox"); |
---|
| 142 | // button->setBindNode(this); |
---|
| 143 | // GLGuiBar* bar = new GLGuiBar(); |
---|
| 144 | // bar->show(); |
---|
| 145 | // bar->setValue(7.0); |
---|
| 146 | // bar->setMaximum(10); |
---|
| 147 | // bar->setSize2D( 20, 100); |
---|
| 148 | // bar->setAbsCoor2D( 10, 200); |
---|
[6300] | 149 | |
---|
[5907] | 150 | //add events to the eventlist |
---|
[5978] | 151 | registerEvent(SDLK_w); |
---|
| 152 | registerEvent(SDLK_s); |
---|
| 153 | registerEvent(SDLK_a); |
---|
| 154 | registerEvent(SDLK_d); |
---|
| 155 | registerEvent(SDLK_q); |
---|
| 156 | registerEvent(SDLK_e); |
---|
[5907] | 157 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
| 158 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
| 159 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
| 160 | registerEvent(SDLK_PAGEUP); |
---|
| 161 | registerEvent(SDLK_PAGEDOWN); |
---|
[5978] | 162 | registerEvent(EV_MOUSE_MOTION); |
---|
[5907] | 163 | |
---|
| 164 | this->getWeaponManager()->setSlotCount(7); |
---|
| 165 | |
---|
| 166 | this->getWeaponManager()->setSlotPosition(0, Vector(-2.6, .1, -3.0)); |
---|
| 167 | this->getWeaponManager()->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 168 | |
---|
| 169 | this->getWeaponManager()->setSlotPosition(1, Vector(-2.6, .1, 3.0)); |
---|
| 170 | this->getWeaponManager()->setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 171 | |
---|
| 172 | this->getWeaponManager()->setSlotPosition(2, Vector(-1.5, .5, -.5)); |
---|
| 173 | this->getWeaponManager()->setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
| 174 | |
---|
| 175 | this->getWeaponManager()->setSlotPosition(3, Vector(-1.5, .5, .5)); |
---|
| 176 | this->getWeaponManager()->setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
| 177 | |
---|
| 178 | this->getWeaponManager()->setSlotPosition(4, Vector(-1.5, -.5, .5)); |
---|
| 179 | this->getWeaponManager()->setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
| 180 | |
---|
| 181 | this->getWeaponManager()->setSlotPosition(5, Vector(-1.5, -.5, -.5)); |
---|
| 182 | this->getWeaponManager()->setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
| 183 | // |
---|
| 184 | this->getWeaponManager()->setSlotPosition(6, Vector(-1, 0.0, 0)); |
---|
| 185 | this->getWeaponManager()->setSlotCapability(6, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
| 186 | // |
---|
| 187 | // this->getWeaponManager()->setSlotPosition(8, Vector(-2.5, -0.3, -2.0)); |
---|
| 188 | // this->getWeaponManager()->setSlotDirection(8, Quaternion(-M_PI, Vector(1,0,0))); |
---|
| 189 | // |
---|
| 190 | // this->getWeaponManager()->setSlotPosition(9, Vector(-2.5, -0.3, 2.0)); |
---|
| 191 | // this->getWeaponManager()->setSlotDirection(9, Quaternion(+M_PI, Vector(1,0,0)));: |
---|
| 192 | |
---|
[6162] | 193 | this->getWeaponManager()->getFixedTarget()->setParent(this); |
---|
| 194 | this->getWeaponManager()->getFixedTarget()->setRelCoor(100000,0,0); |
---|
| 195 | |
---|
[6222] | 196 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
---|
[5907] | 197 | } |
---|
| 198 | |
---|
| 199 | /** |
---|
| 200 | * loads the Settings of a SpaceShip from an XML-element. |
---|
| 201 | * @param root the XML-element to load the Spaceship's properties from |
---|
| 202 | */ |
---|
| 203 | void SpaceShip::loadParams(const TiXmlElement* root) |
---|
| 204 | { |
---|
| 205 | static_cast<WorldEntity*>(this)->loadParams(root); |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | |
---|
[6222] | 209 | void SpaceShip::enter() |
---|
| 210 | { |
---|
| 211 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( true); |
---|
[6241] | 212 | this->attachCamera(); |
---|
[6222] | 213 | |
---|
| 214 | |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | void SpaceShip::leave() |
---|
| 218 | { |
---|
| 219 | dynamic_cast<Element2D*>(this->getWeaponManager()->getFixedTarget())->setVisibility( false); |
---|
[6241] | 220 | this->detachCamera(); |
---|
[6222] | 221 | |
---|
| 222 | |
---|
| 223 | } |
---|
| 224 | |
---|
[5907] | 225 | /** |
---|
| 226 | * adds a weapon to the weapon list of the spaceship |
---|
| 227 | * @param weapon to add |
---|
| 228 | */ |
---|
| 229 | void SpaceShip::addWeapon(Weapon* weapon) |
---|
| 230 | { |
---|
| 231 | this->getWeaponManager()->addWeapon(weapon); |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | |
---|
| 235 | /** |
---|
| 236 | * removes a weapon from the spaceship |
---|
| 237 | * @param weapon to remove |
---|
| 238 | */ |
---|
| 239 | void SpaceShip::removeWeapon(Weapon* weapon) |
---|
| 240 | { |
---|
| 241 | this->getWeaponManager()->removeWeapon(weapon); |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | /** |
---|
| 245 | * effect that occurs after the SpaceShip is spawned |
---|
| 246 | */ |
---|
| 247 | void SpaceShip::postSpawn () |
---|
| 248 | { |
---|
| 249 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | /** |
---|
| 253 | * the action occuring if the spaceship left the game |
---|
| 254 | */ |
---|
| 255 | void SpaceShip::leftWorld () |
---|
| 256 | {} |
---|
| 257 | |
---|
| 258 | WorldEntity* ref = NULL; |
---|
| 259 | /** |
---|
| 260 | * this function is called, when two entities collide |
---|
| 261 | * @param entity: the world entity with whom it collides |
---|
| 262 | * |
---|
| 263 | * Implement behaviour like damage application or other miscellaneous collision stuff in this function |
---|
| 264 | */ |
---|
| 265 | void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location) |
---|
| 266 | { |
---|
| 267 | if (entity->isA(CL_TURRET_POWER_UP) && entity != ref) |
---|
| 268 | { |
---|
| 269 | this->ADDWEAPON(); |
---|
| 270 | ref = entity; |
---|
| 271 | } |
---|
| 272 | // PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z); |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | /** |
---|
| 276 | * draws the spaceship after transforming it. |
---|
| 277 | */ |
---|
| 278 | void SpaceShip::draw () const |
---|
| 279 | { |
---|
[6281] | 280 | WorldEntity::draw(); |
---|
[5907] | 281 | this->getWeaponManager()->draw(); |
---|
| 282 | |
---|
| 283 | //this->debug(0); |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | /** |
---|
| 287 | * the function called for each passing timeSnap |
---|
| 288 | * @param time The timespan passed since last update |
---|
| 289 | */ |
---|
| 290 | void SpaceShip::tick (float time) |
---|
| 291 | { |
---|
[6034] | 292 | |
---|
[5907] | 293 | // spaceship controlled movement |
---|
| 294 | this->calculateVelocity(time); |
---|
| 295 | |
---|
| 296 | Vector move = (velocity)*time; |
---|
| 297 | |
---|
[6034] | 298 | //orient the velocity in the direction of the spaceship. |
---|
| 299 | travelSpeed = velocity.len(); |
---|
| 300 | velocity += ((this->getAbsDirX())*travelSpeed-velocity)*airViscosity; |
---|
| 301 | velocity = (velocity.getNormalized())*travelSpeed; |
---|
[6222] | 302 | |
---|
[6162] | 303 | //orient the spaceship in direction of the mouse |
---|
[6241] | 304 | rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, fabsf(time)*3.0); |
---|
| 305 | if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) |
---|
[6162] | 306 | this->setAbsDir( rotQuat); |
---|
| 307 | //this->setAbsDirSoft(mouseDir,5); |
---|
[6222] | 308 | |
---|
[5978] | 309 | // this is the air friction (necessary for a smooth control) |
---|
| 310 | if(velocity.len() != 0) velocity -= velocity*0.01; |
---|
[5982] | 311 | |
---|
[6034] | 312 | //hoover effect |
---|
| 313 | cycle += time; |
---|
[5978] | 314 | this->shiftCoor(Vector(0,1,0)*cos(this->cycle*2.0)*0.02); |
---|
[5982] | 315 | |
---|
[6034] | 316 | //readjust |
---|
| 317 | // if (this->getAbsDirZ().y > 0.1) this->shiftDir(Quaternion(time*0.3, Vector(1,0,0))); |
---|
| 318 | //else if (this->getAbsDirZ().y < -0.1) this->shiftDir(Quaternion(-time*0.3, Vector(1,0,0))); |
---|
| 319 | |
---|
[5978] | 320 | //SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2); |
---|
[5907] | 321 | |
---|
| 322 | this->shiftCoor (move); |
---|
| 323 | |
---|
| 324 | this->getWeaponManager()->tick(time); |
---|
| 325 | // weapon system manipulation |
---|
| 326 | this->weaponAction(); |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | /** |
---|
| 330 | * calculate the velocity |
---|
| 331 | * @param time the timeslice since the last frame |
---|
| 332 | */ |
---|
| 333 | void SpaceShip::calculateVelocity (float time) |
---|
| 334 | { |
---|
| 335 | Vector accel(0.0, 0.0, 0.0); |
---|
[6162] | 336 | /* |
---|
| 337 | Vector rot(0.0, 0.0, 0.0); // wird benötigt für Helicopter |
---|
| 338 | */ |
---|
[5907] | 339 | //float rotVal = 0.0; |
---|
[5912] | 340 | /* FIXME: calculating the direction and orthDirection every timeSlice is redundant! save it somewhere */ |
---|
[5907] | 341 | /* calculate the direction in which the craft is heading */ |
---|
| 342 | |
---|
[6222] | 343 | Plane plane(Vector(0,1,0), Vector(0,0,0)); |
---|
| 344 | |
---|
[5907] | 345 | if( this->bUp ) |
---|
| 346 | { |
---|
[5978] | 347 | //this->shiftCoor(this->getAbsDirX()); |
---|
| 348 | accel += (this->getAbsDirX())*2; |
---|
[6222] | 349 | |
---|
[6162] | 350 | /* Heli-Steuerung |
---|
| 351 | accel += (this->getAbsDirX()*2; |
---|
| 352 | if( |
---|
| 353 | */ |
---|
[5907] | 354 | } |
---|
| 355 | |
---|
| 356 | if( this->bDown ) |
---|
[5908] | 357 | { |
---|
[5978] | 358 | //this->shiftCoor((this->getAbsDirX())*-1); |
---|
| 359 | accel -= (this->getAbsDirX())*2; |
---|
[5907] | 360 | } |
---|
| 361 | |
---|
[6034] | 362 | if( this->bLeft/* > -this->getRelCoor().z*2*/) |
---|
[5907] | 363 | { |
---|
[5912] | 364 | this->shiftDir(Quaternion(time, Vector(0,1,0))); |
---|
| 365 | // accel -= rightDirection; |
---|
[5908] | 366 | //velocityDir.normalize(); |
---|
[5907] | 367 | //rot +=Vector(1,0,0); |
---|
| 368 | //rotVal -= .4; |
---|
| 369 | } |
---|
| 370 | if( this->bRight /* > this->getRelCoor().z*2*/) |
---|
| 371 | { |
---|
[5912] | 372 | this->shiftDir(Quaternion(-time, Vector(0,1,0))); |
---|
| 373 | |
---|
| 374 | // accel += rightDirection; |
---|
[5908] | 375 | //velocityDir.normalize(); |
---|
[5907] | 376 | //rot += Vector(1,0,0); |
---|
| 377 | //rotVal += .4; |
---|
| 378 | } |
---|
[5982] | 379 | |
---|
[6034] | 380 | |
---|
[5978] | 381 | if( this->bRollL /* > -this->getRelCoor().z*2*/) |
---|
| 382 | { |
---|
[6162] | 383 | mouseDir *= Quaternion(-time, Vector(1,0,0)); |
---|
[5978] | 384 | // accel -= rightDirection; |
---|
| 385 | //velocityDir.normalize(); |
---|
| 386 | //rot +=Vector(1,0,0); |
---|
| 387 | //rotVal -= .4; |
---|
| 388 | } |
---|
| 389 | if( this->bRollR /* > this->getRelCoor().z*2*/) |
---|
| 390 | { |
---|
[6162] | 391 | mouseDir *= Quaternion(time, Vector(1,0,0)); |
---|
[5978] | 392 | |
---|
| 393 | // accel += rightDirection; |
---|
| 394 | //velocityDir.normalize(); |
---|
| 395 | //rot += Vector(1,0,0); |
---|
| 396 | //rotVal += .4; |
---|
| 397 | } |
---|
[5907] | 398 | if (this->bAscend ) |
---|
| 399 | { |
---|
[5912] | 400 | this->shiftDir(Quaternion(time, Vector(0,0,1))); |
---|
| 401 | |
---|
| 402 | // accel += upDirection; |
---|
[5908] | 403 | //velocityDir.normalize(); |
---|
[5907] | 404 | //rot += Vector(0,0,1); |
---|
| 405 | //rotVal += .4; |
---|
| 406 | } |
---|
| 407 | if (this->bDescend ) |
---|
| 408 | { |
---|
[5912] | 409 | this->shiftDir(Quaternion(-time, Vector(0,0,1))); |
---|
| 410 | |
---|
| 411 | // accel -= upDirection; |
---|
[5908] | 412 | //velocityDir.normalize(); |
---|
[5907] | 413 | //rot += Vector(0,0,1); |
---|
| 414 | //rotVal -= .4; |
---|
| 415 | } |
---|
| 416 | |
---|
[5978] | 417 | velocity += accel; |
---|
[5907] | 418 | //rot.normalize(); |
---|
| 419 | //this->setRelDirSoft(Quaternion(rotVal, rot), 5); |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | /** |
---|
| 423 | * weapon manipulation by the player |
---|
| 424 | */ |
---|
| 425 | void SpaceShip::weaponAction() |
---|
| 426 | { |
---|
| 427 | if( this->bFire) |
---|
| 428 | { |
---|
| 429 | this->getWeaponManager()->fire(); |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | /** |
---|
| 434 | * @todo switch statement ?? |
---|
| 435 | */ |
---|
| 436 | void SpaceShip::process(const Event &event) |
---|
| 437 | { |
---|
[5982] | 438 | |
---|
| 439 | |
---|
[5978] | 440 | if( event.type == SDLK_a) |
---|
| 441 | this->bRollL = event.bPressed; |
---|
| 442 | else if( event.type == SDLK_d) |
---|
| 443 | this->bRollR = event.bPressed; |
---|
[5907] | 444 | else if( event.type == KeyMapper::PEV_FIRE1) |
---|
| 445 | this->bFire = event.bPressed; |
---|
| 446 | else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed) |
---|
| 447 | this->getWeaponManager()->nextWeaponConfig();//if( !event.bPressed) this->bWeaponChange = !this->bWeaponChange; |
---|
| 448 | else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed) |
---|
| 449 | this->getWeaponManager()->previousWeaponConfig(); |
---|
[5978] | 450 | else if( event.type == SDLK_w) |
---|
| 451 | this->bUp = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
| 452 | else if( event.type == SDLK_s) |
---|
| 453 | this->bDown = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
| 454 | else if( event.type == EV_MOUSE_MOTION) |
---|
| 455 | { |
---|
| 456 | this->xMouse = event.xRel; |
---|
| 457 | this->yMouse = event.yRel; |
---|
[6162] | 458 | mouseDir *= (Quaternion(-M_PI/4*xMouse*mouseSensitivity, Vector(0,1,0))*Quaternion(-M_PI/4*yMouse*mouseSensitivity, Vector(0,0,1))); |
---|
[6241] | 459 | // if( xMouse*xMouse + yMouse*yMouse < 0.9) |
---|
| 460 | //this->setAbsDir(mouseDir); |
---|
[5978] | 461 | } |
---|
[5907] | 462 | } |
---|
| 463 | |
---|
[6243] | 464 | /** |
---|
| 465 | * |
---|
| 466 | */ |
---|
| 467 | bool SpaceShip::pickup(PowerUp* powerUp) |
---|
| 468 | { |
---|
| 469 | if(powerUp->isA(CL_WEAPON_POWER_UP)) { |
---|
| 470 | Weapon* weapon = dynamic_cast<WeaponPowerUp*>(powerUp)->getWeapon(); |
---|
| 471 | WeaponManager* manager = this->getWeaponManager(); |
---|
| 472 | int slot = manager->getNextFreeSlot(0, weapon->getCapability()); |
---|
| 473 | if(slot >= 0) { |
---|
| 474 | manager->addWeapon(weapon, 0, slot); |
---|
| 475 | return true; |
---|
| 476 | } |
---|
| 477 | } |
---|
| 478 | else if(powerUp->isA(CL_PARAM_POWER_UP)) { |
---|
| 479 | ParamPowerUp* ppu = dynamic_cast<ParamPowerUp*>(powerUp); |
---|
| 480 | switch(ppu->getType()) { |
---|
| 481 | case PARAM_SHIELD: |
---|
| 482 | break; |
---|
| 483 | } |
---|
| 484 | } |
---|
| 485 | return false; |
---|
| 486 | } |
---|
| 487 | |
---|
[5907] | 488 | #include "weapons/aiming_turret.h" |
---|
| 489 | // FIXME THIS MIGHT BE CONSIDERED EITHER A FEATURE, OR A BUG |
---|
| 490 | void SpaceShip::ADDWEAPON() |
---|
| 491 | { |
---|
| 492 | Weapon* turret = NULL; |
---|
| 493 | |
---|
[6306] | 494 | if ((float)rand()/RAND_MAX < .9) |
---|
[5907] | 495 | { |
---|
| 496 | //if (this->getWeaponManager()->hasFreeSlot(2, WTYPE_TURRET)) |
---|
| 497 | { |
---|
| 498 | turret = new Turret(); |
---|
| 499 | this->getWeaponManager()->addWeapon(turret, 2); |
---|
| 500 | this->getWeaponManager()->changeWeaponConfig(2); |
---|
| 501 | } |
---|
| 502 | } |
---|
| 503 | else |
---|
| 504 | { |
---|
| 505 | //if (this->getWeaponManager()->hasFreeSlot(3)) |
---|
| 506 | { |
---|
| 507 | turret = new AimingTurret(); |
---|
| 508 | this->getWeaponManager()->addWeapon(turret, 3); |
---|
| 509 | |
---|
| 510 | this->getWeaponManager()->changeWeaponConfig(3); |
---|
| 511 | } |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | if(turret != NULL) |
---|
| 515 | { |
---|
| 516 | turret->setName("Turret"); |
---|
| 517 | turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1); |
---|
| 518 | } |
---|
| 519 | } |
---|
[6420] | 520 | |
---|
| 521 | |
---|
| 522 | int SpaceShip::writeBytes( const byte * data, int length, int sender ) |
---|
| 523 | { |
---|
| 524 | setRequestedSync( false ); |
---|
| 525 | setIsOutOfSync( false ); |
---|
| 526 | |
---|
| 527 | SYNCHELP_READ_BEGIN(); |
---|
| 528 | |
---|
| 529 | SYNCHELP_READ_FKT( WorldEntity::writeState ); |
---|
| 530 | |
---|
| 531 | return SYNCHELP_READ_N; |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | int SpaceShip::readBytes( byte * data, int maxLength, int * reciever ) |
---|
| 535 | { |
---|
| 536 | if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() ) |
---|
| 537 | { |
---|
| 538 | (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() ); |
---|
| 539 | setRequestedSync( true ); |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | int rec = this->getRequestSync(); |
---|
| 543 | if ( rec > 0 ) |
---|
| 544 | { |
---|
| 545 | *reciever = rec; |
---|
| 546 | |
---|
| 547 | SYNCHELP_WRITE_BEGIN(); |
---|
| 548 | |
---|
| 549 | SYNCHELP_WRITE_FKT( WorldEntity::readState ); |
---|
| 550 | |
---|
| 551 | return SYNCHELP_WRITE_N; |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | *reciever = 0; |
---|
| 555 | return 0; |
---|
| 556 | } |
---|