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 "swarm_launcher.h" |
---|
18 | |
---|
19 | #include "weapon_manager.h" |
---|
20 | #include "world_entities/projectiles/projectile.h" |
---|
21 | #include "world_entities/projectiles/swarm_projectile.h" |
---|
22 | |
---|
23 | #include "model.h" |
---|
24 | #include "world_entities/npcs/npc.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 "util/loading/factory.h" |
---|
34 | |
---|
35 | #include "elements/glgui_energywidgetvertical.h" |
---|
36 | |
---|
37 | |
---|
38 | |
---|
39 | using namespace std; |
---|
40 | |
---|
41 | ObjectListDefinition(SwarmLauncher); |
---|
42 | CREATE_FACTORY(SwarmLauncher); |
---|
43 | |
---|
44 | /** |
---|
45 | * standard constructor |
---|
46 | * |
---|
47 | * creates a new SwarmLauncher |
---|
48 | */ |
---|
49 | SwarmLauncher::SwarmLauncher() |
---|
50 | : Weapon() |
---|
51 | { |
---|
52 | this->init(); |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * creates a new SwarmLauncher from a TiXmlElement |
---|
57 | */ |
---|
58 | SwarmLauncher::SwarmLauncher(const TiXmlElement* root) |
---|
59 | { |
---|
60 | this->init(); |
---|
61 | if (root != NULL) |
---|
62 | this->loadParams(root); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * standard deconstructor |
---|
67 | */ |
---|
68 | SwarmLauncher::~SwarmLauncher () |
---|
69 | { |
---|
70 | // model will be deleted from WorldEntity-destructor |
---|
71 | } |
---|
72 | |
---|
73 | void SwarmLauncher::init() |
---|
74 | { |
---|
75 | this->registerObject(this, SwarmLauncher::_objectList); |
---|
76 | |
---|
77 | Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this); |
---|
78 | Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this); |
---|
79 | |
---|
80 | animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
81 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
82 | animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
83 | animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT); |
---|
84 | |
---|
85 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
86 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
87 | |
---|
88 | this->setStateDuration(WS_SHOOTING, .6); |
---|
89 | this->setStateDuration(WS_RELOADING, 1.0f); |
---|
90 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
91 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
92 | |
---|
93 | this->setEnergyMax(10); |
---|
94 | this->increaseEnergy(10); |
---|
95 | //this->minCharge = 2; |
---|
96 | |
---|
97 | this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
98 | this->setProjectileTypeC("SwarmProjectile"); |
---|
99 | |
---|
100 | // this->loadModel("models/guns/turret1.obj", 1.0); |
---|
101 | |
---|
102 | this->setEmissionPoint(1.684, 0.472, 0); |
---|
103 | this->getProjectileFactory()->prepare(10); |
---|
104 | |
---|
105 | this->setActionSound(WA_SHOOT, "sounds/explosions/explosion_1.wav"); |
---|
106 | // this->setActionSound(WA_ACTIVATE, "sounds/voices/rockets.wav"); |
---|
107 | // this->setActionSound(WA_RELOAD, "sounds/voices/reload.wav"); |
---|
108 | |
---|
109 | } |
---|
110 | |
---|
111 | void SwarmLauncher::loadParams(const TiXmlElement* root) |
---|
112 | { |
---|
113 | Weapon::loadParams(root); |
---|
114 | } |
---|
115 | |
---|
116 | void SwarmLauncher::activate() |
---|
117 | { |
---|
118 | } |
---|
119 | |
---|
120 | void SwarmLauncher::deactivate() |
---|
121 | { |
---|
122 | } |
---|
123 | |
---|
124 | void SwarmLauncher::tick(float dt) |
---|
125 | { |
---|
126 | if (!Weapon::tickW(dt)) |
---|
127 | return; |
---|
128 | |
---|
129 | Quaternion quat; |
---|
130 | Vector direction; |
---|
131 | if (this->getDefaultTarget() == NULL) |
---|
132 | direction = this->getAbsCoor(); |
---|
133 | else |
---|
134 | direction = this->getDefaultTarget()->getAbsCoor() - this->getAbsCoor(); |
---|
135 | |
---|
136 | direction.normalize(); |
---|
137 | |
---|
138 | if (likely (this->getParent() != NULL)) |
---|
139 | quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
140 | else |
---|
141 | quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ; |
---|
142 | |
---|
143 | this->setAbsDirSoft(quat, 5); |
---|
144 | |
---|
145 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
---|
146 | { |
---|
147 | this->energyWidget->setDisplayedImage("textures/gui/gui_swarm_missiles.png"); |
---|
148 | this->setEnergyWidgetInitialized(true); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | void SwarmLauncher::fire() |
---|
153 | { |
---|
154 | bool fired = false; |
---|
155 | |
---|
156 | Projectile* pj = NULL; |
---|
157 | for( ObjectList<NPC>::const_iterator eIterator = NPC::objectList().begin(); eIterator !=NPC::objectList().end(); eIterator++) |
---|
158 | { |
---|
159 | if( ((*eIterator)->getOMListNumber() != (this->getOMListNumber())) && ((*eIterator)->getClassCName() != "Weapon") && ((*eIterator)->getClassCName() != "Projectile") && ((*eIterator)->getAbsCoor() - this->getAbsCoor()).len() <= 300) |
---|
160 | { |
---|
161 | pj = this->getProjectile(); |
---|
162 | if (pj == NULL) |
---|
163 | return; |
---|
164 | |
---|
165 | fired = true; |
---|
166 | pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*115.0 + VECTOR_RAND(10))); |
---|
167 | |
---|
168 | pj->setParent(PNode::getNullParent()); |
---|
169 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
170 | pj->setAbsDir(this->getAbsDir()); |
---|
171 | dynamic_cast<SwarmProjectile*>(pj)->setTarget( (PNode*)(*eIterator) ); |
---|
172 | pj->activate(); |
---|
173 | } |
---|
174 | } |
---|
175 | if( !fired) |
---|
176 | this->increaseEnergy( this->getProjectile()->getMinEnergy()); |
---|
177 | } |
---|