[4592] | 1 | /* |
---|
[3618] | 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 |
---|
[4963] | 12 | main-programmer: Benjamin Grauer |
---|
[4592] | 13 | co-programmer: |
---|
[3618] | 14 | */ |
---|
[5357] | 15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
[3618] | 16 | |
---|
[9217] | 17 | #include "boomerang_gun.h" |
---|
[3618] | 18 | |
---|
[4963] | 19 | #include "weapon_manager.h" |
---|
[6434] | 20 | #include "world_entities/projectiles/projectile.h" |
---|
[3618] | 21 | |
---|
[5511] | 22 | #include "model.h" |
---|
| 23 | |
---|
[4829] | 24 | #include "state.h" |
---|
[3851] | 25 | #include "animation3d.h" |
---|
[3618] | 26 | |
---|
[7193] | 27 | #include "util/loading/factory.h" |
---|
[4287] | 28 | |
---|
[10114] | 29 | |
---|
| 30 | ObjectListDefinition(BoomerangGun); |
---|
[9869] | 31 | CREATE_FACTORY(BoomerangGun); |
---|
[4931] | 32 | |
---|
[3618] | 33 | |
---|
| 34 | /** |
---|
[4836] | 35 | * standard constructor |
---|
[5750] | 36 | * |
---|
[9217] | 37 | * creates a new BoomerangGun |
---|
[5750] | 38 | */ |
---|
[9217] | 39 | BoomerangGun::BoomerangGun () |
---|
[5750] | 40 | : Weapon() |
---|
[3683] | 41 | { |
---|
[4973] | 42 | this->init(); |
---|
| 43 | } |
---|
| 44 | |
---|
[5750] | 45 | /** |
---|
[9217] | 46 | * creates a new BoomerangGun from a TiXmlElement |
---|
[5750] | 47 | */ |
---|
[9217] | 48 | BoomerangGun::BoomerangGun(const TiXmlElement* root) |
---|
[4973] | 49 | { |
---|
| 50 | this->init(); |
---|
[6547] | 51 | if (root != NULL) |
---|
| 52 | this->loadParams(root); |
---|
[4973] | 53 | } |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | * standard deconstructor |
---|
| 57 | */ |
---|
[9217] | 58 | BoomerangGun::~BoomerangGun () |
---|
[4973] | 59 | { |
---|
| 60 | // model will be deleted from WorldEntity-destructor |
---|
| 61 | } |
---|
| 62 | |
---|
[9217] | 63 | void BoomerangGun::init() |
---|
[4973] | 64 | { |
---|
[9869] | 65 | this->registerObject(this, BoomerangGun::_objectList); |
---|
[4973] | 66 | |
---|
[5819] | 67 | |
---|
[4964] | 68 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
| 69 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
[3755] | 70 | |
---|
[4964] | 71 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 72 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 73 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 74 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
| 75 | |
---|
[4893] | 76 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
| 77 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
[3888] | 78 | |
---|
[6759] | 79 | this->setStateDuration(WS_SHOOTING, .6); |
---|
[6306] | 80 | this->setStateDuration(WS_RELOADING, 1.0f); |
---|
[4910] | 81 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
| 82 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
[4885] | 83 | |
---|
[6671] | 84 | this->setEnergyMax(100); |
---|
[6306] | 85 | this->increaseEnergy(100); |
---|
[4927] | 86 | //this->minCharge = 2; |
---|
[4885] | 87 | |
---|
[9219] | 88 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET); |
---|
[9869] | 89 | this->setProjectileTypeC("BoomerangProjectile"); |
---|
[4964] | 90 | |
---|
[9217] | 91 | this->loadModel("models/guns/turret1.obj", 5.0); |
---|
[4973] | 92 | |
---|
[4964] | 93 | this->setEmissionPoint(1.684, 0.472, 0); |
---|
[4948] | 94 | //this->getProjectileFactory()->prepare(100); |
---|
[7070] | 95 | |
---|
[10415] | 96 | this->setActionSound(WA_SHOOT, "sounds/explosions/explosion_3.wav"); |
---|
[10419] | 97 | this->setActionSound(WA_ACTIVATE, "sounds/voices/rockets.wav"); |
---|
| 98 | this->setActionSound(WA_RELOAD, "sounds/voices/reload.wav"); |
---|
[7070] | 99 | |
---|
[3683] | 100 | } |
---|
[3618] | 101 | |
---|
[9217] | 102 | void BoomerangGun::loadParams(const TiXmlElement* root) |
---|
[4973] | 103 | { |
---|
[6512] | 104 | Weapon::loadParams(root); |
---|
[3618] | 105 | } |
---|
| 106 | |
---|
[9217] | 107 | void BoomerangGun::activate() |
---|
[3980] | 108 | { |
---|
| 109 | } |
---|
[3618] | 110 | |
---|
[9217] | 111 | void BoomerangGun::deactivate() |
---|
[3980] | 112 | { |
---|
| 113 | } |
---|
[3618] | 114 | |
---|
[9217] | 115 | void BoomerangGun::tick(float dt) |
---|
[4964] | 116 | { |
---|
[6738] | 117 | if (!Weapon::tickW(dt)) |
---|
| 118 | return; |
---|
[6724] | 119 | |
---|
[5001] | 120 | Quaternion quat; |
---|
[6920] | 121 | Vector direction; |
---|
| 122 | if (this->getDefaultTarget() == NULL) |
---|
| 123 | direction = this->getAbsCoor(); |
---|
| 124 | else |
---|
| 125 | direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor(); |
---|
[5001] | 126 | |
---|
[4964] | 127 | direction.normalize(); |
---|
[5001] | 128 | |
---|
[4969] | 129 | if (likely (this->getParent() != NULL)) |
---|
[5001] | 130 | quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
[4969] | 131 | else |
---|
[5001] | 132 | quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
| 133 | |
---|
[6724] | 134 | this->setAbsDirSoft(quat, 5); |
---|
[4964] | 135 | } |
---|
| 136 | |
---|
[9217] | 137 | void BoomerangGun::fire() |
---|
[3620] | 138 | { |
---|
[5356] | 139 | Projectile* pj = this->getProjectile(); |
---|
| 140 | if (pj == NULL) |
---|
| 141 | return; |
---|
[3888] | 142 | |
---|
[5819] | 143 | pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 /*+ VECTOR_RAND(13) */ |
---|
[5440] | 144 | /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity()); |
---|
[4955] | 145 | |
---|
[5819] | 146 | |
---|
[6074] | 147 | pj->setParent(PNode::getNullParent()); |
---|
[4927] | 148 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
[3708] | 149 | pj->setAbsDir(this->getAbsDir()); |
---|
[5443] | 150 | pj->activate(); |
---|
[3620] | 151 | } |
---|