| 1 |  | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 5 |  | 
|---|
| 6 |    Copyright (C) 2004 orx | 
|---|
| 7 |  | 
|---|
| 8 |    This program is free software; you can redistribute it and/or modify | 
|---|
| 9 |    it under the terms of the GNU General Public License as published by | 
|---|
| 10 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 11 |    any later version. | 
|---|
| 12 |  | 
|---|
| 13 |    ### File Specific | 
|---|
| 14 |    main-programmer: Benjamin Grauer | 
|---|
| 15 |    co-programmer: | 
|---|
| 16 |  | 
|---|
| 17 |  | 
|---|
| 18 |    @todo: direction in which the projectile flights | 
|---|
| 19 |    @todo: a target to set/hit | 
|---|
| 20 | */ | 
|---|
| 21 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON | 
|---|
| 22 |  | 
|---|
| 23 | #include "hyperblaster.h" | 
|---|
| 24 |  | 
|---|
| 25 | #include "world_entity.h" | 
|---|
| 26 | #include "model.h" | 
|---|
| 27 | #include "world_entities/projectiles/projectile.h" | 
|---|
| 28 | #include "weapon_manager.h" | 
|---|
| 29 | #include "util/loading/factory.h" | 
|---|
| 30 |  | 
|---|
| 31 | #include "animation3d.h" | 
|---|
| 32 |  | 
|---|
| 33 | #include "fast_factory.h" | 
|---|
| 34 |  | 
|---|
| 35 |  | 
|---|
| 36 | using namespace std; | 
|---|
| 37 |  | 
|---|
| 38 | CREATE_FACTORY(Hyperblaster, CL_HYPERBLASTER); | 
|---|
| 39 |  | 
|---|
| 40 | Hyperblaster::Hyperblaster(const TiXmlElement* root) | 
|---|
| 41 | { | 
|---|
| 42 |   this->init(); | 
|---|
| 43 |   if (root != NULL) | 
|---|
| 44 |     this->loadParams(root); | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | /** | 
|---|
| 48 |  *  standard deconstructor | 
|---|
| 49 | */ | 
|---|
| 50 | Hyperblaster::~Hyperblaster () | 
|---|
| 51 | { | 
|---|
| 52 |   // model will be deleted from WorldEntity-destructor | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | void Hyperblaster::init() | 
|---|
| 57 | { | 
|---|
| 58 |   this->setClassID(CL_HYPERBLASTER, "Hyperblaster"); | 
|---|
| 59 |  | 
|---|
| 60 | //  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN); | 
|---|
| 61 |  | 
|---|
| 62 |   this->loadModel("models/guns/plasmadriver_#.obj", 2.0); | 
|---|
| 63 |  | 
|---|
| 64 |   this->setStateDuration(WS_SHOOTING, 2.0); | 
|---|
| 65 |   this->setStateDuration(WS_RELOADING, 5.0); | 
|---|
| 66 |   this->setStateDuration(WS_ACTIVATING, .8); | 
|---|
| 67 |   this->setStateDuration(WS_DEACTIVATING, .8); | 
|---|
| 68 |  | 
|---|
| 69 |   this->setEnergyMax(5000); | 
|---|
| 70 |   this->increaseEnergy(5000); | 
|---|
| 71 |   //this->minCharge = 2; | 
|---|
| 72 |  | 
|---|
| 73 |   this->setActionSound(WA_SHOOT, "sound/explosions/explosion_4.wav"); | 
|---|
| 74 |   this->setActionSound(WA_ACTIVATE, "sound/powerups/whats this2.wav"); | 
|---|
| 75 |   this->setActionSound(WA_RELOAD, "sound/spawn/alien_generator.wav"); | 
|---|
| 76 |  | 
|---|
| 77 |   this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_HEAVY); | 
|---|
| 78 |   this->setProjectileType(CL_HYPERBLAST); | 
|---|
| 79 |   this->prepareProjectiles(2); | 
|---|
| 80 |  | 
|---|
| 81 | //  this->objectComponent1 = new PNode(); | 
|---|
| 82 | //  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1); | 
|---|
| 83 |   Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); | 
|---|
| 84 |   Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); | 
|---|
| 85 |   //parent->addChild(this->objectComponent1, PNODE_ALL); | 
|---|
| 86 | //  this->addChild(this->objectComponent1); | 
|---|
| 87 |  | 
|---|
| 88 | //  animation1->setInfinity(ANIM_INF_CONSTANT); | 
|---|
| 89 |   animation2->setInfinity(ANIM_INF_CONSTANT); | 
|---|
| 90 |   animation3->setInfinity(ANIM_INF_CONSTANT); | 
|---|
| 91 |  | 
|---|
| 92 |   this->setEmissionPoint(3.8, 1.2, 0); | 
|---|
| 93 |  | 
|---|
| 94 | //     animation1->addKeyFrame(Vector(0, -1.5, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); | 
|---|
| 95 | //     animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); | 
|---|
| 96 | //     animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); | 
|---|
| 97 |  | 
|---|
| 98 |   animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); | 
|---|
| 99 |   animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); | 
|---|
| 100 |  | 
|---|
| 101 |   animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); | 
|---|
| 102 |   animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 |  | 
|---|
| 106 | void Hyperblaster::loadParams(const TiXmlElement* root) | 
|---|
| 107 | { | 
|---|
| 108 |   Weapon::loadParams(root); | 
|---|
| 109 | } | 
|---|
| 110 |  | 
|---|
| 111 |  | 
|---|
| 112 | /** | 
|---|
| 113 |  *  this activates the weapon | 
|---|
| 114 |  | 
|---|
| 115 |    This is needed, since there can be more than one weapon on a ship. the | 
|---|
| 116 |    activation can be connected with an animation. for example the weapon is | 
|---|
| 117 |    been armed out. | 
|---|
| 118 | */ | 
|---|
| 119 | void Hyperblaster::activate() | 
|---|
| 120 | { | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 |  | 
|---|
| 124 | /** | 
|---|
| 125 |  *  this deactivates the weapon | 
|---|
| 126 |  | 
|---|
| 127 |    This is needed, since there can be more than one weapon on a ship. the | 
|---|
| 128 |    activation can be connected with an animation. for example the weapon is | 
|---|
| 129 |    been armed out. | 
|---|
| 130 | */ | 
|---|
| 131 | void Hyperblaster::deactivate() | 
|---|
| 132 | { | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 |  | 
|---|
| 136 | /** | 
|---|
| 137 |  *  fires the weapon | 
|---|
| 138 |  | 
|---|
| 139 |    this is called from the player.cc, when fire-button is been pushed | 
|---|
| 140 |    @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent | 
|---|
| 141 | */ | 
|---|
| 142 | void Hyperblaster::fire() | 
|---|
| 143 | { | 
|---|
| 144 |   Projectile* pj =  this->getProjectile(); | 
|---|
| 145 |   if (pj == NULL) | 
|---|
| 146 |     return; | 
|---|
| 147 |  | 
|---|
| 148 |   pj->setParent(PNode::getNullParent()); | 
|---|
| 149 |  | 
|---|
| 150 |   pj->setVelocity(this->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*15+VECTOR_RAND(5)); | 
|---|
| 151 |  | 
|---|
| 152 |   pj->setAbsCoor(this->getEmissionPoint()); | 
|---|
| 153 |   pj->setAbsDir(this->getAbsDir()); | 
|---|
| 154 |   pj->activate(); | 
|---|
| 155 | } | 
|---|
| 156 |  | 
|---|
| 157 | /** | 
|---|
| 158 |  *  is called, when the weapon is destroyed | 
|---|
| 159 |  * | 
|---|
| 160 |  * this is in conjunction with the hit function, so when a weapon is able to get | 
|---|
| 161 |  * hit, it can also be destoryed. | 
|---|
| 162 | */ | 
|---|
| 163 | void Hyperblaster::destroy () | 
|---|
| 164 | {} | 
|---|