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