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, Nicolas Schlumberger |
---|
13 | co-programmer: |
---|
14 | |
---|
15 | */ |
---|
16 | |
---|
17 | #include "disruptor.h" |
---|
18 | #include "world_entities/projectiles/projectile.h" |
---|
19 | |
---|
20 | #include "world_entity.h" |
---|
21 | #include "static_model.h" |
---|
22 | #include "weapon_manager.h" |
---|
23 | #include "util/loading/factory.h" |
---|
24 | |
---|
25 | #include "animation3d.h" |
---|
26 | |
---|
27 | #include "loading/fast_factory.h" |
---|
28 | |
---|
29 | #include "elements/glgui_energywidgetvertical.h" |
---|
30 | |
---|
31 | ObjectListDefinition(Disruptor); |
---|
32 | CREATE_FACTORY(Disruptor); |
---|
33 | |
---|
34 | /** |
---|
35 | * Standard constructor |
---|
36 | */ |
---|
37 | Disruptor::Disruptor () |
---|
38 | : Weapon() |
---|
39 | { |
---|
40 | this->init(); |
---|
41 | } |
---|
42 | |
---|
43 | Disruptor::Disruptor (const TiXmlElement* root = NULL) |
---|
44 | : Weapon() |
---|
45 | { |
---|
46 | // TODO add leftRight to params |
---|
47 | this->init(); |
---|
48 | if (root != NULL) |
---|
49 | this->loadParams(root); |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * Default destructor |
---|
54 | */ |
---|
55 | Disruptor::~Disruptor() |
---|
56 | { |
---|
57 | for (int i = 0; i < this->getBarrels(); i++) |
---|
58 | { |
---|
59 | delete [] this->shootAnim[i]; |
---|
60 | delete [] this->objComp[i]; |
---|
61 | } |
---|
62 | delete [] this->emissionPoint; |
---|
63 | |
---|
64 | delete [] this->shootAnim; |
---|
65 | delete [] this->objComp; |
---|
66 | |
---|
67 | } |
---|
68 | |
---|
69 | void Disruptor::loadParams(const TiXmlElement* root) |
---|
70 | { |
---|
71 | Weapon::loadParams(root); |
---|
72 | } |
---|
73 | |
---|
74 | void Disruptor::init() |
---|
75 | { |
---|
76 | |
---|
77 | this->setScaling(.5); |
---|
78 | |
---|
79 | this->loadModel("models/guns/disruptor.obj", this->getScaling()); |
---|
80 | |
---|
81 | |
---|
82 | this->setStateDuration(WS_SHOOTING, 0.3333); // 3 Shots per Second |
---|
83 | this->setStateDuration(WS_RELOADING, 0); |
---|
84 | this->setStateDuration(WS_ACTIVATING, .5); |
---|
85 | this->setStateDuration(WS_DEACTIVATING, 1); |
---|
86 | |
---|
87 | this->setEnergyMax(500); |
---|
88 | this->increaseEnergy(500); |
---|
89 | //this->minCharge = 2; |
---|
90 | |
---|
91 | this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav"); |
---|
92 | // this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav"); |
---|
93 | this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav"); |
---|
94 | |
---|
95 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT); |
---|
96 | this->setProjectileTypeC("HBolt"); |
---|
97 | this->prepareProjectiles(10); |
---|
98 | |
---|
99 | this->setBarrels(1); |
---|
100 | this->setSegs(1); |
---|
101 | this->activeBarrel = 0; |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | this->objComp = new PNode**[this->getBarrels()]; |
---|
106 | this->emissionPoint = new PNode*[this->getBarrels()]; |
---|
107 | this->shootAnim = new Animation3D**[this->getBarrels()]; |
---|
108 | for (int i = 0; i < this->getBarrels(); i++) |
---|
109 | { |
---|
110 | this->objComp[i] = new PNode* [this->getSegs()]; |
---|
111 | this->emissionPoint[i] = new PNode; |
---|
112 | this->emissionPoint[i]->setParent(this); //Parenting emissionPoint to Weapon |
---|
113 | this->emissionPoint[i]->setName("EmissionPoint"); |
---|
114 | this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
115 | this->shootAnim[i] = new Animation3D* [this->getSegs()]; |
---|
116 | for(int j = 0; j < this->getSegs(); j++) |
---|
117 | { |
---|
118 | this->objComp[i][j] = new PNode; |
---|
119 | this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]); |
---|
120 | this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | this->emissionPoint[0]->setRelCoor(Vector(1.672, 0.0, 0.0) * this->getScaling()); |
---|
125 | |
---|
126 | |
---|
127 | this->shootAnim[0][0]->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
128 | this->shootAnim[0][0]->addKeyFrame(Vector(-0.5, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.2, ANIM_LINEAR, ANIM_NULL); |
---|
129 | // this->shootAnim[0][0]->addKeyFrame(Vector(0.0, 0.0, 0.0) * this->getScaling(), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
130 | |
---|
131 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
132 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
133 | |
---|
134 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
135 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
136 | |
---|
137 | animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
138 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
139 | |
---|
140 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL); |
---|
141 | animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | void Disruptor::fire() |
---|
146 | { |
---|
147 | Projectile* pj = this->getProjectile(); |
---|
148 | if (pj == NULL) |
---|
149 | return; |
---|
150 | |
---|
151 | // set the owner |
---|
152 | pj->setOwner(this->getOwner()); |
---|
153 | pj->setParent(PNode::getNullParent()); |
---|
154 | |
---|
155 | pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1)); |
---|
156 | |
---|
157 | pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor()); |
---|
158 | pj->setAbsDir(this->getAbsDir()); |
---|
159 | pj->activate(); |
---|
160 | |
---|
161 | |
---|
162 | this->shootAnim[0][0]->replay(); |
---|
163 | |
---|
164 | |
---|
165 | } |
---|
166 | |
---|
167 | /** |
---|
168 | * this activates the weapon |
---|
169 | */ |
---|
170 | void Disruptor::activate() |
---|
171 | { |
---|
172 | } |
---|
173 | |
---|
174 | /** |
---|
175 | * this deactivates the weapon |
---|
176 | */ |
---|
177 | void Disruptor::deactivate() |
---|
178 | { |
---|
179 | } |
---|
180 | |
---|
181 | |
---|
182 | void Disruptor::draw() const |
---|
183 | { |
---|
184 | glPushMatrix(); |
---|
185 | glMatrixMode(GL_MODELVIEW); |
---|
186 | glTranslatef (this->getAbsCoor ().x, |
---|
187 | this->getAbsCoor ().y, |
---|
188 | this->getAbsCoor ().z); |
---|
189 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
190 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
191 | |
---|
192 | //Base |
---|
193 | static_cast<StaticModel*>(this->getModel())->draw(1); |
---|
194 | |
---|
195 | // Barrel |
---|
196 | glPushMatrix(); |
---|
197 | glTranslatef(this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z); |
---|
198 | static_cast<StaticModel*>(this->getModel())->draw(0); |
---|
199 | glPopMatrix(); |
---|
200 | glPopMatrix(); |
---|
201 | } |
---|
202 | |
---|
203 | void Disruptor::tick(float dt) |
---|
204 | { |
---|
205 | if (!Weapon::tickW(dt)) |
---|
206 | return; |
---|
207 | if (this->energyWidget != NULL && !this->isEnergyWidgetInitialized) |
---|
208 | { |
---|
209 | this->energyWidget->setDisplayedImage("textures/gui/gui_heavy_bolt.png"); |
---|
210 | this->setEnergyWidgetInitialized(true); |
---|
211 | } |
---|
212 | } |
---|