[10180] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004-2006 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: Marc Schaerrer |
---|
| 13 | co-programmer: |
---|
| 14 | */ |
---|
| 15 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
| 16 | |
---|
| 17 | #include "spike_thrower.h" |
---|
| 18 | |
---|
| 19 | #include "weapon_manager.h" |
---|
| 20 | #include "world_entities/projectiles/projectile.h" |
---|
| 21 | #include "world_entities/projectiles/spike_ball.h" |
---|
[10252] | 22 | #include "world_entities/projectiles/spike.h" |
---|
[10180] | 23 | |
---|
| 24 | #include "model.h" |
---|
| 25 | |
---|
| 26 | #include "state.h" |
---|
| 27 | #include "animation3d.h" |
---|
| 28 | |
---|
| 29 | #include <list> |
---|
| 30 | #include <iterator> |
---|
| 31 | #include "util/state.h" |
---|
| 32 | |
---|
| 33 | #include "math/quaternion.h" |
---|
| 34 | |
---|
| 35 | #include "util/loading/factory.h" |
---|
| 36 | |
---|
| 37 | #include "class_id_DEPRECATED.h" |
---|
| 38 | |
---|
| 39 | using namespace std; |
---|
| 40 | |
---|
| 41 | ObjectListDefinition(SpikeThrower); |
---|
| 42 | CREATE_FACTORY(SpikeThrower); |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | * standard constructor |
---|
| 46 | * |
---|
| 47 | * creates a new SpikeThrower |
---|
| 48 | */ |
---|
| 49 | SpikeThrower::SpikeThrower() |
---|
| 50 | : Weapon() |
---|
| 51 | { |
---|
| 52 | this->init(); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | * creates a new SpikeThrower from a TiXmlElement |
---|
| 57 | */ |
---|
| 58 | SpikeThrower::SpikeThrower(const TiXmlElement* root) |
---|
| 59 | { |
---|
| 60 | this->init(); |
---|
| 61 | if (root != NULL) |
---|
| 62 | this->loadParams(root); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | /** |
---|
| 66 | * standard deconstructor |
---|
| 67 | */ |
---|
| 68 | SpikeThrower::~SpikeThrower () |
---|
| 69 | { |
---|
| 70 | |
---|
| 71 | // model will be deleted from WorldEntity-destructor |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | void SpikeThrower::init() |
---|
| 75 | { |
---|
| 76 | this->registerObject(this, SpikeThrower::_objectList); |
---|
[10256] | 77 | /* |
---|
[10180] | 78 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 79 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
| 80 | |
---|
| 81 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 82 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 83 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
[10256] | 84 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);*/ |
---|
| 85 | /* |
---|
[10180] | 86 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
[10256] | 87 | animation2->setInfinity(ANIM_INF_CONSTANT);*/ |
---|
[10180] | 88 | |
---|
| 89 | this->setStateDuration(WS_SHOOTING, .6); |
---|
| 90 | this->setStateDuration(WS_RELOADING, 1.0f); |
---|
| 91 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 92 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
| 93 | |
---|
| 94 | this->setEnergyMax(10); |
---|
| 95 | this->increaseEnergy(10); |
---|
| 96 | //this->minCharge = 2; |
---|
| 97 | |
---|
| 98 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
[10256] | 99 | this->setProjectileTypeC("SpikeBall"); |
---|
[10180] | 100 | |
---|
| 101 | // this->loadModel("models/guns/turret1.obj", 1.0); |
---|
| 102 | |
---|
[10256] | 103 | this->setEmissionPoint(2, 0, 0); |
---|
[10180] | 104 | this->getProjectileFactory()->prepare(50); |
---|
| 105 | |
---|
[10256] | 106 | // this->setActionSound(WA_SHOOT, "sound/explosions/explosion_1.wav"); |
---|
| 107 | // this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav"); |
---|
| 108 | // this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav"); |
---|
[10180] | 109 | |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | void SpikeThrower::loadParams(const TiXmlElement* root) |
---|
| 113 | { |
---|
| 114 | Weapon::loadParams(root); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | void SpikeThrower::activate() |
---|
| 118 | { |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | void SpikeThrower::deactivate() |
---|
| 122 | { |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | void SpikeThrower::tick(float dt) |
---|
| 126 | { |
---|
| 127 | if (!Weapon::tickW(dt)) |
---|
| 128 | return; |
---|
| 129 | |
---|
| 130 | Quaternion quat; |
---|
| 131 | Vector direction; |
---|
| 132 | if (this->getDefaultTarget() == NULL) |
---|
| 133 | direction = this->getAbsCoor(); |
---|
| 134 | else |
---|
| 135 | direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor(); |
---|
| 136 | |
---|
| 137 | direction.normalize(); |
---|
| 138 | |
---|
| 139 | if (likely (this->getParent() != NULL)) |
---|
| 140 | quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
| 141 | else |
---|
| 142 | quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
| 143 | |
---|
| 144 | this->setAbsDirSoft(quat, 5); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | void SpikeThrower::fire() |
---|
| 148 | { |
---|
[10196] | 149 | Projectile* pj = this->getProjectile(); |
---|
| 150 | if (pj == NULL) |
---|
| 151 | return; |
---|
[10180] | 152 | |
---|
[10196] | 153 | // set the owner |
---|
| 154 | pj->setOwner(this->getOwner()); |
---|
[10180] | 155 | |
---|
[10196] | 156 | pj->setParent(PNode::getNullParent()); |
---|
| 157 | |
---|
[10260] | 158 | // pj->setVelocity(this->getParent()->getAbsDir().apply(Vector(1,0,0))*200 + this->getParent()->getParent()->getVelocity()); |
---|
| 159 | pj->setVelocity(this->getParent()->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*160); |
---|
| 160 | |
---|
[10196] | 161 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
| 162 | pj->setAbsDir(this->getAbsDir()); |
---|
| 163 | pj->activate(); |
---|
[10180] | 164 | } |
---|