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