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: Patrick Boenzli |
---|
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 "test_gun.h" |
---|
24 | |
---|
25 | #include "world_entity.h" |
---|
26 | #include "model.h" |
---|
27 | #include "test_bullet.h" |
---|
28 | #include "weapon_manager.h" |
---|
29 | #include "factory.h" |
---|
30 | |
---|
31 | #include "vector.h" |
---|
32 | #include "list.h" |
---|
33 | #include "animation3d.h" |
---|
34 | #include "sound_engine.h" |
---|
35 | |
---|
36 | #include "null_parent.h" |
---|
37 | |
---|
38 | #include "fast_factory.h" |
---|
39 | |
---|
40 | |
---|
41 | using namespace std; |
---|
42 | |
---|
43 | CREATE_FACTORY(TestGun, CL_TEST_GUN); |
---|
44 | |
---|
45 | /** |
---|
46 | * standard constructor |
---|
47 | |
---|
48 | creates a new weapon |
---|
49 | */ |
---|
50 | TestGun::TestGun ( int leftRight) |
---|
51 | : Weapon() |
---|
52 | { |
---|
53 | this->init(); |
---|
54 | |
---|
55 | |
---|
56 | this->leftRight = leftRight; |
---|
57 | |
---|
58 | this->objectComponent1 = new PNode(); |
---|
59 | Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1); |
---|
60 | Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this); |
---|
61 | Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this); |
---|
62 | //parent->addChild(this->objectComponent1, PNODE_ALL); |
---|
63 | this->addChild(this->objectComponent1); |
---|
64 | |
---|
65 | animation1->setInfinity(ANIM_INF_CONSTANT); |
---|
66 | animation2->setInfinity(ANIM_INF_CONSTANT); |
---|
67 | animation3->setInfinity(ANIM_INF_CONSTANT); |
---|
68 | |
---|
69 | if( this->leftRight == W_LEFT) |
---|
70 | { |
---|
71 | this->setEmissionPoint(1.0, -0.6, -0.2); |
---|
72 | |
---|
73 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
74 | animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
75 | animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
76 | |
---|
77 | animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
78 | animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
79 | |
---|
80 | animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
81 | animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
82 | } |
---|
83 | else if( this->leftRight == W_RIGHT) |
---|
84 | { |
---|
85 | this->setEmissionPoint(1.0, -0.6, 0.3); |
---|
86 | |
---|
87 | this->objectComponent1->setRelCoor(Vector(0,0,0.35)); |
---|
88 | animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
89 | animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL); |
---|
90 | animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL); |
---|
91 | |
---|
92 | animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
93 | animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
94 | |
---|
95 | animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
96 | animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL); |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | TestGun::TestGun(const TiXmlElement* root) |
---|
102 | { |
---|
103 | this->init(); |
---|
104 | this->loadParams(root); |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * standard deconstructor |
---|
109 | */ |
---|
110 | TestGun::~TestGun () |
---|
111 | { |
---|
112 | // model will be deleted from WorldEntity-destructor |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | void TestGun::init() |
---|
117 | { |
---|
118 | this->setClassID(CL_TEST_GUN, "TestGun"); |
---|
119 | |
---|
120 | // this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN); |
---|
121 | |
---|
122 | this->loadModel("models/guns/test_gun.obj"); |
---|
123 | |
---|
124 | this->setStateDuration(WS_SHOOTING, .1); |
---|
125 | this->setStateDuration(WS_RELOADING, .1); |
---|
126 | this->setStateDuration(WS_ACTIVATING, .4); |
---|
127 | this->setStateDuration(WS_DEACTIVATING, .4); |
---|
128 | |
---|
129 | this->setMaximumEnergy(1000, 100); |
---|
130 | this->increaseEnergy(1000); |
---|
131 | //this->minCharge = 2; |
---|
132 | |
---|
133 | this->setActionSound(WA_SHOOT, "sound/laser.wav"); |
---|
134 | this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav"); |
---|
135 | |
---|
136 | |
---|
137 | this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
138 | this->setProjectileType(CL_LASER); |
---|
139 | this->prepareProjectiles(20); |
---|
140 | |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | void TestGun::loadParams(const TiXmlElement* root) |
---|
145 | { |
---|
146 | |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | /** |
---|
152 | * this activates the weapon |
---|
153 | |
---|
154 | This is needed, since there can be more than one weapon on a ship. the |
---|
155 | activation can be connected with an animation. for example the weapon is |
---|
156 | been armed out. |
---|
157 | */ |
---|
158 | void TestGun::activate() |
---|
159 | { |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | /** |
---|
164 | * this deactivates the weapon |
---|
165 | |
---|
166 | This is needed, since there can be more than one weapon on a ship. the |
---|
167 | activation can be connected with an animation. for example the weapon is |
---|
168 | been armed out. |
---|
169 | */ |
---|
170 | void TestGun::deactivate() |
---|
171 | { |
---|
172 | } |
---|
173 | |
---|
174 | |
---|
175 | /** |
---|
176 | * fires the weapon |
---|
177 | |
---|
178 | this is called from the player.cc, when fire-button is been pushed |
---|
179 | @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent |
---|
180 | */ |
---|
181 | void TestGun::fire() |
---|
182 | { |
---|
183 | Projectile* pj = this->getProjectile(); |
---|
184 | if (pj == NULL) |
---|
185 | return; |
---|
186 | |
---|
187 | pj->setParent(NullParent::getInstance()); |
---|
188 | |
---|
189 | pj->setVelocity(this->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*50+VECTOR_RAND(5)); |
---|
190 | |
---|
191 | pj->setAbsCoor(this->getEmissionPoint()); |
---|
192 | pj->setAbsDir(this->getAbsDir()); |
---|
193 | pj->activate(); |
---|
194 | } |
---|
195 | |
---|
196 | /** |
---|
197 | * is called, when the weapon is destroyed |
---|
198 | * |
---|
199 | * this is in conjunction with the hit function, so when a weapon is able to get |
---|
200 | * hit, it can also be destoryed. |
---|
201 | */ |
---|
202 | void TestGun::destroy () |
---|
203 | {} |
---|
204 | |
---|
205 | /** |
---|
206 | * this will draw the weapon |
---|
207 | */ |
---|
208 | void TestGun::draw () const |
---|
209 | { |
---|
210 | /* draw gun body */ |
---|
211 | glMatrixMode(GL_MODELVIEW); |
---|
212 | glPushMatrix(); |
---|
213 | glTranslatef (this->getAbsCoor ().x, |
---|
214 | this->getAbsCoor ().y, |
---|
215 | this->getAbsCoor ().z); |
---|
216 | |
---|
217 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
218 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
219 | |
---|
220 | if( this->leftRight == W_RIGHT) |
---|
221 | glScalef(1.0, 1.0, -1.0); |
---|
222 | this->model->draw(1); |
---|
223 | glPopMatrix(); |
---|
224 | |
---|
225 | /* draw objectComponent1: gun coil - animated stuff */ |
---|
226 | glMatrixMode(GL_MODELVIEW); |
---|
227 | glPushMatrix(); |
---|
228 | glTranslatef (this->objectComponent1->getAbsCoor ().x, |
---|
229 | this->objectComponent1->getAbsCoor ().y, |
---|
230 | this->objectComponent1->getAbsCoor ().z); |
---|
231 | tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis(); |
---|
232 | glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
233 | this->model->draw(0); |
---|
234 | glPopMatrix(); |
---|
235 | } |
---|
236 | |
---|