| 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: Patrick Boenzli | 
|---|
| 13 |    co-programmer: | 
|---|
| 14 |  | 
|---|
| 15 |  | 
|---|
| 16 |    @todo: direction in which the projectile flights | 
|---|
| 17 |    @todo: a target to set/hit | 
|---|
| 18 | */ | 
|---|
| 19 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON | 
|---|
| 20 |  | 
|---|
| 21 | #include "laser_cannon.h" | 
|---|
| 22 | #include "world_entities/projectiles/projectile.h" | 
|---|
| 23 |  | 
|---|
| 24 | #include "world_entity.h" | 
|---|
| 25 | #include "static_model.h" | 
|---|
| 26 | #include "weapon_manager.h" | 
|---|
| 27 | #include "util/loading/factory.h" | 
|---|
| 28 |  | 
|---|
| 29 | #include "animation3d.h" | 
|---|
| 30 |  | 
|---|
| 31 | #include "loading/fast_factory.h" | 
|---|
| 32 |  | 
|---|
| 33 | #include "class_id_DEPRECATED.h" | 
|---|
| 34 | ObjectListDefinitionID(LaserCannon, CL_LASER_CANNON); | 
|---|
| 35 | CREATE_FACTORY(LaserCannon); | 
|---|
| 36 |  | 
|---|
| 37 | LaserCannon::LaserCannon(const TiXmlElement* root) | 
|---|
| 38 | { | 
|---|
| 39 |   this->init(); | 
|---|
| 40 |   if (root != NULL) | 
|---|
| 41 |     this->loadParams(root); | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | /** | 
|---|
| 45 |  *  standard deconstructor | 
|---|
| 46 | */ | 
|---|
| 47 | LaserCannon::~LaserCannon () | 
|---|
| 48 | { | 
|---|
| 49 |   // model will be deleted from WorldEntity-destructor | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 | void LaserCannon::init() | 
|---|
| 54 | { | 
|---|
| 55 |   this->registerObject(this, LaserCannon::_objectList); | 
|---|
| 56 |  | 
|---|
| 57 | //  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/laser_cannon.obj", OBJ, RP_CAMPAIGN); | 
|---|
| 58 |  | 
|---|
| 59 |   this->loadModel("models/guns/lasercannon.obj", 5.0f); | 
|---|
| 60 |  | 
|---|
| 61 |   this->setStateDuration(WS_SHOOTING, .1); | 
|---|
| 62 |   this->setStateDuration(WS_RELOADING, .1); | 
|---|
| 63 |   this->setStateDuration(WS_ACTIVATING, .4); | 
|---|
| 64 |   this->setStateDuration(WS_DEACTIVATING, .4); | 
|---|
| 65 |  | 
|---|
| 66 |   this->setEnergyMax(10000); | 
|---|
| 67 |   this->increaseEnergy(10000); | 
|---|
| 68 |   //this->minCharge = 2; | 
|---|
| 69 |  | 
|---|
| 70 |   this->setActionSound(WA_SHOOT, "sound/laser.wav"); | 
|---|
| 71 |   this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav"); | 
|---|
| 72 |  | 
|---|
| 73 |  | 
|---|
| 74 |   this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); | 
|---|
| 75 |   this->setProjectileTypeC("RailProjectile"); | 
|---|
| 76 |   this->prepareProjectiles(100); | 
|---|
| 77 |   this->setEmissionPoint(Vector(2.8,0,0) * 5.0); | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 |  | 
|---|
| 81 | void LaserCannon::loadParams(const TiXmlElement* root) | 
|---|
| 82 | { | 
|---|
| 83 |   Weapon::loadParams(root); | 
|---|
| 84 |  | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 |  | 
|---|
| 88 | /** | 
|---|
| 89 |  *  this activates the weapon | 
|---|
| 90 |  | 
|---|
| 91 |    This is needed, since there can be more than one weapon on a ship. the | 
|---|
| 92 |    activation can be connected with an animation. for example the weapon is | 
|---|
| 93 |    been armed out. | 
|---|
| 94 | */ | 
|---|
| 95 | void LaserCannon::activate() | 
|---|
| 96 | { | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 |  | 
|---|
| 100 | /** | 
|---|
| 101 |  *  this deactivates the weapon | 
|---|
| 102 |  | 
|---|
| 103 |    This is needed, since there can be more than one weapon on a ship. the | 
|---|
| 104 |    activation can be connected with an animation. for example the weapon is | 
|---|
| 105 |    been armed out. | 
|---|
| 106 | */ | 
|---|
| 107 | void LaserCannon::deactivate() | 
|---|
| 108 | { | 
|---|
| 109 | } | 
|---|
| 110 |  | 
|---|
| 111 |  | 
|---|
| 112 | /** | 
|---|
| 113 |  *  fires the weapon | 
|---|
| 114 |  | 
|---|
| 115 |    this is called from the player.cc, when fire-button is been pushed | 
|---|
| 116 |    @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent | 
|---|
| 117 | */ | 
|---|
| 118 | void LaserCannon::fire() | 
|---|
| 119 | { | 
|---|
| 120 |   Projectile* pj =  this->getProjectile(); | 
|---|
| 121 |   if (pj == NULL) | 
|---|
| 122 |     return; | 
|---|
| 123 |  | 
|---|
| 124 |   // make this to let the onKill(...) fuction get the stuff | 
|---|
| 125 |   pj->setOwner(this->getOwner()); | 
|---|
| 126 |  | 
|---|
| 127 |   pj->setParent(PNode::getNullParent()); | 
|---|
| 128 |  | 
|---|
| 129 |   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5)); | 
|---|
| 130 |  | 
|---|
| 131 |   pj->setAbsCoor(this->getEmissionPoint()); | 
|---|
| 132 |   pj->setAbsDir(this->getAbsDir()); | 
|---|
| 133 |   pj->activate(); | 
|---|
| 134 | } | 
|---|