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