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