1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 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: Benjamin Knecht |
---|
13 | co-programmer: Silvan Nellen |
---|
14 | |
---|
15 | */ |
---|
16 | |
---|
17 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
18 | |
---|
19 | #include "executor/executor.h" |
---|
20 | #include "space_ship.h" |
---|
21 | |
---|
22 | #include "util/loading/resource_manager.h" |
---|
23 | |
---|
24 | #include "weapons/test_gun.h" |
---|
25 | #include "weapons/light_blaster.h" |
---|
26 | #include "weapons/medium_blaster.h" |
---|
27 | #include "weapons/heavy_blaster.h" |
---|
28 | #include "weapons/swarm_launcher.h" |
---|
29 | #include "weapons/spike_launcher.h" |
---|
30 | #include "weapons/spike_thrower.h" |
---|
31 | #include "weapons/boomerang_gun.h" |
---|
32 | #include "weapons/turret.h" |
---|
33 | #include "weapons/cannon.h" |
---|
34 | |
---|
35 | #include "elements/glgui_energywidgetvertical.h" |
---|
36 | #include "glgui_bar.h" |
---|
37 | |
---|
38 | #include "particles/dot_emitter.h" |
---|
39 | #include "particles/emitter_node.h" |
---|
40 | #include "particles/sprite_particles.h" |
---|
41 | #include "effects/trail.h" |
---|
42 | |
---|
43 | #include "effects/wobblegrid.h" |
---|
44 | |
---|
45 | #include "util/loading/factory.h" |
---|
46 | #include "key_mapper.h" |
---|
47 | |
---|
48 | #include "network_game_manager.h" |
---|
49 | #include "shared_network_data.h" |
---|
50 | |
---|
51 | #include "power_ups/weapon_power_up.h" |
---|
52 | #include "power_ups/param_power_up.h" |
---|
53 | |
---|
54 | #include "graphics_engine.h" |
---|
55 | |
---|
56 | #include "plane.h" |
---|
57 | |
---|
58 | #include "state.h" |
---|
59 | #include "player.h" |
---|
60 | #include "camera.h" |
---|
61 | |
---|
62 | |
---|
63 | #include "util/loading/load_param.h" |
---|
64 | #include "time.h" |
---|
65 | |
---|
66 | #include "track/track.h" |
---|
67 | |
---|
68 | |
---|
69 | // #include "lib/gui/gl_gui/glgui_bar.h" |
---|
70 | // #include "lib/gui/gl_gui/glgui_pushbutton.h" |
---|
71 | |
---|
72 | |
---|
73 | #include "class_id_DEPRECATED.h" |
---|
74 | ObjectListDefinitionID(SpaceShip, CL_SPACE_SHIP); |
---|
75 | CREATE_FACTORY(SpaceShip); |
---|
76 | |
---|
77 | #include "script_class.h" |
---|
78 | CREATE_SCRIPTABLE_CLASS(SpaceShip, |
---|
79 | addMethod("hasPlayer", Executor0ret<Playable, lua_State*,bool>(&Playable::hasPlayer)) |
---|
80 | ->addMethod("fire", Executor1<Playable, lua_State*, bool>(&Playable::fire)) |
---|
81 | ->addMethod("loadModel", Executor2<WorldEntity, lua_State*,const std::string& ,float>(&WorldEntity::loadModel2)) |
---|
82 | ->addMethod("setName", Executor1<BaseObject, lua_State*,const std::string&>(&BaseObject::setName)) |
---|
83 | ->addMethod("hide", Executor0<WorldEntity, lua_State*>(&WorldEntity::hide)) |
---|
84 | ->addMethod("unhide", Executor0<WorldEntity, lua_State*>(&WorldEntity::unhide)) |
---|
85 | //Coordinates |
---|
86 | ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor)) |
---|
87 | ->addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX)) |
---|
88 | ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) |
---|
89 | ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) |
---|
90 | //->addMethod("setCameraSpeed", Executor1<SpaceShip, lua_State*, float>(&SpaceShip::setCameraSpeed)) |
---|
91 | ); |
---|
92 | |
---|
93 | /** |
---|
94 | * destructs the spaceship, deletes alocated memory |
---|
95 | */ |
---|
96 | SpaceShip::~SpaceShip () |
---|
97 | { |
---|
98 | this->setPlayer(NULL); |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * loads a Spaceships information from a specified file. |
---|
103 | * @param fileName the name of the File to load the spaceship from (absolute path) |
---|
104 | */ |
---|
105 | SpaceShip::SpaceShip(const std::string& fileName) |
---|
106 | : secWeaponMan(this) //, |
---|
107 | //supportedPlaymodes(Playable::Vertical) , |
---|
108 | //playmode(Playable::Vertical) |
---|
109 | { |
---|
110 | this->init(); |
---|
111 | TiXmlDocument doc(fileName); |
---|
112 | |
---|
113 | if(!doc.LoadFile()) |
---|
114 | { |
---|
115 | PRINTF(2)("Loading file %s failed for spaceship.\n", fileName.c_str()); |
---|
116 | return; |
---|
117 | } |
---|
118 | |
---|
119 | this->loadParams(doc.RootElement()); |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * creates a new Spaceship from Xml Data |
---|
124 | * @param root the xml element containing spaceship data |
---|
125 | |
---|
126 | @todo add more parameters to load |
---|
127 | */ |
---|
128 | SpaceShip::SpaceShip(const TiXmlElement* root) |
---|
129 | : secWeaponMan(this) //, |
---|
130 | //supportedPlaymodes(Playable::Vertical) , |
---|
131 | //playmode(Playable::Vertical) |
---|
132 | { |
---|
133 | this->init(); |
---|
134 | //this->setParentMode(PNODE_REPARENT_DELETE_CHILDREN); |
---|
135 | if (root != NULL) |
---|
136 | this->loadParams(root); |
---|
137 | |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | /** |
---|
142 | * initializes a Spaceship |
---|
143 | */ |
---|
144 | void SpaceShip::init() |
---|
145 | { |
---|
146 | |
---|
147 | srand(time(0)); //initialize Random Nomber Generator |
---|
148 | |
---|
149 | // this->setRelDir(Quaternion(M_PI, Vector(1,0,0))); |
---|
150 | this->registerObject(this, SpaceShip::_objectList); |
---|
151 | PRINTF(4)("SPACESHIP INIT\n"); |
---|
152 | this->weaponMan.setParentEntity( this); |
---|
153 | //weapons: |
---|
154 | |
---|
155 | Weapon* wpRight1 = new LightBlaster (); |
---|
156 | wpRight1->setName( "LightBlaster"); |
---|
157 | Weapon* wpLeft1 = new LightBlaster (); |
---|
158 | wpLeft1->setName( "LightBlaster"); |
---|
159 | |
---|
160 | Weapon* wpRight2 = new MediumBlaster (); |
---|
161 | wpRight2->setName( "MediumBlaster"); |
---|
162 | Weapon* wpLeft2 = new MediumBlaster (); |
---|
163 | wpLeft2->setName( "MediumBlaster"); |
---|
164 | |
---|
165 | Weapon* wpRight3 = new HeavyBlaster (1); |
---|
166 | wpRight3->setName( "HeavyBlaster"); |
---|
167 | Weapon* wpLeft3 = new HeavyBlaster (0); |
---|
168 | wpLeft3->setName( "HeavyBlaster"); |
---|
169 | |
---|
170 | Weapon* cannon = new SwarmLauncher(); |
---|
171 | cannon->setName( "SwarmLauncher"); |
---|
172 | |
---|
173 | Weapon* spike = new SpikeThrower(); |
---|
174 | spike->setName( "SpikeThrower" ); |
---|
175 | |
---|
176 | // Weapon* spike2 = new SpikeLauncher(); |
---|
177 | // spike2->setName( "SpikeLauncher" ); |
---|
178 | |
---|
179 | this->weaponMan.addWeapon( wpLeft1, 0, 0); |
---|
180 | this->weaponMan.addWeapon( wpRight1, 0, 1); |
---|
181 | |
---|
182 | this->weaponMan.addWeapon( wpLeft2, 1, 2); |
---|
183 | this->weaponMan.addWeapon( wpRight2, 1, 3); |
---|
184 | |
---|
185 | this->weaponMan.addWeapon( wpLeft3, 2, 4); |
---|
186 | this->weaponMan.addWeapon( wpRight3, 2, 5); |
---|
187 | |
---|
188 | this->weaponMan.addWeapon( wpLeft1, 3, 0); |
---|
189 | this->weaponMan.addWeapon( wpRight1, 3, 1); |
---|
190 | |
---|
191 | this->weaponMan.addWeapon( wpLeft2, 3, 2); |
---|
192 | this->weaponMan.addWeapon( wpRight2, 3, 3); |
---|
193 | |
---|
194 | this->weaponMan.addWeapon( wpLeft3, 3, 4); |
---|
195 | this->weaponMan.addWeapon( wpRight3, 3, 5); |
---|
196 | |
---|
197 | this->secWeaponMan.addWeapon( cannon, 0, 0); |
---|
198 | this->secWeaponMan.addWeapon( spike, 1, 1); |
---|
199 | // this->secWeaponMan.addWeapon( spike2, 2, 2); |
---|
200 | |
---|
201 | |
---|
202 | this->weaponMan.changeWeaponConfig(3); |
---|
203 | this->secWeaponMan.changeWeaponConfig(1); |
---|
204 | |
---|
205 | curWeaponPrimary = 3; |
---|
206 | curWeaponSecondary = 1; |
---|
207 | |
---|
208 | Playable::weaponConfigChanged(); |
---|
209 | |
---|
210 | reactorOutput = 10; |
---|
211 | |
---|
212 | weaponEnergyRegen = 10; // 10 einheiten pro Sekunde |
---|
213 | engineSpeedBase = 5; |
---|
214 | shieldRegen = 2; |
---|
215 | |
---|
216 | shieldEnergyShare = 0.3; |
---|
217 | weaponEnergyShare = 0.3; |
---|
218 | engineEnergyShare = 0.4; |
---|
219 | |
---|
220 | shieldCur = 20; |
---|
221 | shieldMax = 100; |
---|
222 | shieldTH = .2 * shieldMax; // shield power must be 20% before shield kicks in again |
---|
223 | |
---|
224 | this->setHealth( 20); |
---|
225 | this->setHealthMax( 100); |
---|
226 | |
---|
227 | electronicCur = 50; |
---|
228 | electronicMax = 50; |
---|
229 | electronicRegen = 3; |
---|
230 | electronicTH = .7 * electronicMax; // 30% of eDamage can be handled by the ship |
---|
231 | |
---|
232 | |
---|
233 | this->loadModel("models/ships/mantawing.obj"); |
---|
234 | //this->setVisibiliy(false); |
---|
235 | |
---|
236 | bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; |
---|
237 | |
---|
238 | |
---|
239 | this->setHealthMax(shieldMax); |
---|
240 | this->setHealth(shieldCur); |
---|
241 | |
---|
242 | this->travelNode = new PNode(); |
---|
243 | |
---|
244 | // camera - issue |
---|
245 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
246 | this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); |
---|
247 | |
---|
248 | // widget handling |
---|
249 | /* |
---|
250 | this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical(); |
---|
251 | this->electronicWidget->setDisplayedName(std::string(this->getClassName()) + " Electronics:"); |
---|
252 | this->electronicWidget->setSize2D(30,400); |
---|
253 | this->electronicWidget->setAbsCoor2D(150,200); |
---|
254 | this->electronicWidget->shiftDir2D(270); |
---|
255 | this->updateElectronicWidget(); |
---|
256 | this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical(); |
---|
257 | this->shieldWidget->setDisplayedName(std::string(this->getClassName()) + " Shield:"); |
---|
258 | this->shieldWidget->setSize2D(30,400); |
---|
259 | this->shieldWidget->setAbsCoor2D(200,200); |
---|
260 | this->shieldWidget->shiftDir2D(270); |
---|
261 | this->updateShieldWidget(); |
---|
262 | if (this->hasPlayer()) |
---|
263 | { |
---|
264 | State::getPlayer()->hud().setShiledWidget(this->shieldWidget); |
---|
265 | State::getPlayer()->hud().setEnergyWidget(this->electronicWidget); |
---|
266 | } |
---|
267 | */ |
---|
268 | this->electronicWidget = NULL; |
---|
269 | this->shieldWidget = NULL; |
---|
270 | |
---|
271 | //add events to the eventlist |
---|
272 | registerEvent(KeyMapper::PEV_FORWARD); |
---|
273 | registerEvent(KeyMapper::PEV_BACKWARD); |
---|
274 | registerEvent(KeyMapper::PEV_LEFT); |
---|
275 | registerEvent(KeyMapper::PEV_RIGHT); |
---|
276 | //registerEvent(SDLK_q); |
---|
277 | //registerEvent(SDLK_e); |
---|
278 | registerEvent(KeyMapper::PEV_FIRE1); |
---|
279 | registerEvent(KeyMapper::PEV_FIRE2); // Added for secondary weapon support |
---|
280 | registerEvent(KeyMapper::PEV_NEXT_WEAPON); |
---|
281 | registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON); |
---|
282 | //registerEvent(SDLK_PAGEUP); |
---|
283 | //registerEvent(SDLK_PAGEDOWN); |
---|
284 | registerEvent(EV_MOUSE_MOTION); |
---|
285 | |
---|
286 | this->weaponMan.setParentEntity( this); |
---|
287 | this->secWeaponMan.setParentEntity( this); |
---|
288 | |
---|
289 | this->weaponMan.setSlotCount(6); |
---|
290 | |
---|
291 | this->weaponMan.setSlotPosition(0, Vector(0.0, 0, -3.0)); |
---|
292 | this->weaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
293 | |
---|
294 | this->weaponMan.setSlotPosition(1, Vector(0.0, 0, 3.0)); |
---|
295 | this->weaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
296 | |
---|
297 | this->weaponMan.setSlotPosition(2, Vector(-1.5, 0, -.5)); |
---|
298 | this->weaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
299 | |
---|
300 | this->weaponMan.setSlotPosition(3, Vector(-1.5, 0, .5)); |
---|
301 | this->weaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
302 | |
---|
303 | this->weaponMan.setSlotPosition(4, Vector(1.5, 0, .5)); |
---|
304 | this->weaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
305 | |
---|
306 | this->weaponMan.setSlotPosition(5, Vector(1.5, 0, -.5)); |
---|
307 | this->weaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
308 | |
---|
309 | this->secWeaponMan.setSlotCount(6); |
---|
310 | |
---|
311 | this->secWeaponMan.setSlotPosition(0, Vector(1.5, 0, 0)); |
---|
312 | this->secWeaponMan.setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
313 | |
---|
314 | this->secWeaponMan.setSlotPosition(1, Vector(2.6, 0, 3.0)); |
---|
315 | this->secWeaponMan.setSlotCapability(1, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL); |
---|
316 | |
---|
317 | this->secWeaponMan.setSlotPosition(2, Vector(1.5, 0, -.5)); |
---|
318 | this->secWeaponMan.setSlotDirection(2, Quaternion(-M_PI_4*.5, Vector(1,0,0))); |
---|
319 | |
---|
320 | this->secWeaponMan.setSlotPosition(3, Vector(1.5, 0, .5)); |
---|
321 | this->secWeaponMan.setSlotDirection(3, Quaternion(M_PI_4*.5, Vector(1,0,0))); |
---|
322 | |
---|
323 | this->secWeaponMan.setSlotPosition(4, Vector(1.5, 0, .5)); |
---|
324 | this->secWeaponMan.setSlotDirection(4, Quaternion(-M_PI_4*.5+M_PI, Vector(1,0,0))); |
---|
325 | |
---|
326 | this->secWeaponMan.setSlotPosition(5, Vector(1.5, 0, -.5)); |
---|
327 | this->secWeaponMan.setSlotDirection(5, Quaternion(+M_PI_4*.5-M_PI, Vector(1,0,0))); |
---|
328 | |
---|
329 | |
---|
330 | this->weaponMan.getFixedTarget()->setParent(this); |
---|
331 | this->weaponMan.getFixedTarget()->setRelCoor(100000,0,0); |
---|
332 | |
---|
333 | |
---|
334 | this->secWeaponMan.getFixedTarget()->setParent(this); |
---|
335 | this->secWeaponMan.getFixedTarget()->setRelCoor(100000,0,0); |
---|
336 | this->secWeaponMan.setRotationSpeed(0); |
---|
337 | |
---|
338 | dynamic_cast<Element2D*>(this->weaponMan.getFixedTarget())->setVisibility( false); |
---|
339 | |
---|
340 | |
---|
341 | registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); |
---|
342 | registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); |
---|
343 | registerVar( new SynchronizeableBool( &bLeft, &bLeft, "bLeft", PERMISSION_OWNER ) ); |
---|
344 | registerVar( new SynchronizeableBool( &bRight, &bRight, "bRight", PERMISSION_OWNER ) ); |
---|
345 | registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) ); |
---|
346 | registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); |
---|
347 | registerVar( new SynchronizeableBool( &bFire, &bFire, "bSecFire", PERMISSION_OWNER)); |
---|
348 | registerVar( new SynchronizeableVector( &velocity, &velocity, "velocity", PERMISSION_MASTER_SERVER ) ); |
---|
349 | |
---|
350 | //this->airFriction = 0.5f; |
---|
351 | this->travelDistancePlus = Vector2D(38.0, 43.0); |
---|
352 | this->travelDistanceMinus = Vector2D(-38.0, -43.0); |
---|
353 | this->cameraSpeed = 40; |
---|
354 | this->cameraLook = 0.0f; |
---|
355 | //this->airFriction = 0.0f; |
---|
356 | |
---|
357 | srand(time(0)); //initaialize RNG |
---|
358 | |
---|
359 | this->travelNode->debugDraw(); |
---|
360 | |
---|
361 | this->setSupportedPlaymodes(Playable::Horizontal | Playable::Vertical); |
---|
362 | |
---|
363 | /// FIXME |
---|
364 | this->trail = new Trail( 5, 10, .2, this); |
---|
365 | this->trail->setTexture( "maps/engine.png"); |
---|
366 | |
---|
367 | this->trailL = new Trail( 5, 10, .2, this); |
---|
368 | this->trailL->setTexture( "maps/engine.png"); |
---|
369 | |
---|
370 | this->trailR = new Trail( 5, 10, .2, this); |
---|
371 | this->trailR->setTexture( "maps/engine.png"); |
---|
372 | |
---|
373 | |
---|
374 | this->toList(OM_GROUP_00); |
---|
375 | |
---|
376 | //FIXME Just testaddition to show the wobblegrid |
---|
377 | /* |
---|
378 | this->test = new Wobblegrid(5); |
---|
379 | test->setTexture("maps/blub.png"); |
---|
380 | |
---|
381 | test->setAbsCoor( this->getAbsCoor() + Vector(0, 2, 0)); |
---|
382 | test->setParent( this); |
---|
383 | */ |
---|
384 | |
---|
385 | } |
---|
386 | |
---|
387 | |
---|
388 | /** |
---|
389 | * loads the Settings of a SpaceShip from an XML-element. |
---|
390 | * @param root the XML-element to load the Spaceship's properties from |
---|
391 | */ |
---|
392 | void SpaceShip::loadParams(const TiXmlElement* root) |
---|
393 | { |
---|
394 | Playable::loadParams(root); |
---|
395 | |
---|
396 | LoadParam(root, "playmode", this, SpaceShip, setPlaymodeXML); |
---|
397 | LoadParam(root, "cameraDistance", this, SpaceShip, setCameraDistance); |
---|
398 | LoadParam(root, "cameraFovy", this, SpaceShip, setCameraFovy); |
---|
399 | |
---|
400 | State::getCamera()->setViewMode(Camera::ViewTop); |
---|
401 | } |
---|
402 | |
---|
403 | |
---|
404 | void SpaceShip::setPlayDirection(const Quaternion& rot, float speed) |
---|
405 | { |
---|
406 | //this->direction = Quaternion (rot.getHeading(), Vector(0,1,0)); |
---|
407 | } |
---|
408 | |
---|
409 | void SpaceShip::reset() |
---|
410 | { |
---|
411 | bForward = bBackward = bLeft = bRight = bAscend = bDescend = bRollL = bRollR = bFire = bSecFire = false; |
---|
412 | |
---|
413 | //xMouse = yMouse = 0; |
---|
414 | |
---|
415 | this->setHealth(80); |
---|
416 | this->velocity = Vector(0.0, 0.0, 0.0); |
---|
417 | } |
---|
418 | |
---|
419 | |
---|
420 | void SpaceShip::enter() |
---|
421 | { |
---|
422 | this->secWeaponMan.showCrosshair(); |
---|
423 | this->toList( OM_GROUP_01 ); |
---|
424 | State::getPlayer()->hud().setRadarCenterNode(this->travelNode); |
---|
425 | State::getPlayer()->hud().setOverlayActive(true); |
---|
426 | //dynamic_cast <OrxGui::GLGuiEnergyWidgetVertical*> (State::getPlayer()->hud().getArmorWidget())->setDisplayedName("Armor"); |
---|
427 | //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( true); |
---|
428 | //this->attachCamera(); |
---|
429 | // this->setPlaymode(Playable::Horizontal); |
---|
430 | } |
---|
431 | |
---|
432 | void SpaceShip::leave() |
---|
433 | { |
---|
434 | this->secWeaponMan.hideCrosshair(); |
---|
435 | this->toList( OM_GROUP_00); |
---|
436 | State::getPlayer()->hud().setOverlayActive(false); |
---|
437 | State::getCamera()->setEventHandling(true); |
---|
438 | State::getPlayer()->hud().setRadarCenterNode(NULL); |
---|
439 | //dynamic_cast<Element2D*>(this->secWeaponMan.getFixedTarget())->setVisibility( false); |
---|
440 | //this->detachCamera(); |
---|
441 | } |
---|
442 | |
---|
443 | |
---|
444 | /** |
---|
445 | * effect that occurs after the SpaceShip is spawned |
---|
446 | */ |
---|
447 | void SpaceShip::postSpawn () |
---|
448 | { |
---|
449 | if(this->hasPlayer()) |
---|
450 | Playable::postSpawn(); |
---|
451 | |
---|
452 | //setCollision(new CollisionCluster(1.0, Vector(0,0,0))); |
---|
453 | } |
---|
454 | |
---|
455 | /** |
---|
456 | * the action occuring if the spaceship left the game |
---|
457 | */ |
---|
458 | void SpaceShip::leftWorld () |
---|
459 | { |
---|
460 | |
---|
461 | } |
---|
462 | |
---|
463 | WorldEntity* ref = NULL; |
---|
464 | |
---|
465 | /** |
---|
466 | * draws the spaceship after transforming it. |
---|
467 | */ |
---|
468 | void SpaceShip::draw () const |
---|
469 | { |
---|
470 | WorldEntity::draw(); |
---|
471 | |
---|
472 | glMatrixMode(GL_MODELVIEW); |
---|
473 | glPushMatrix(); |
---|
474 | |
---|
475 | float matrix[4][4]; |
---|
476 | glTranslatef (this->getAbsCoor ().x-1, this->getAbsCoor ().y-.2, this->getAbsCoor ().z); |
---|
477 | this->getAbsDir().matrix (matrix); |
---|
478 | glMultMatrixf((float*)matrix); |
---|
479 | //glScalef(2.0, 2.0, 2.0); // no double rescale |
---|
480 | // FIXME |
---|
481 | this->trail->draw(); |
---|
482 | |
---|
483 | glTranslatef(0,0,-.5); |
---|
484 | this->trailL->draw(); |
---|
485 | |
---|
486 | glTranslatef(0,0,1); |
---|
487 | this->trailR->draw(); |
---|
488 | |
---|
489 | glPopMatrix(); |
---|
490 | //this->debug(0); |
---|
491 | } |
---|
492 | |
---|
493 | /** |
---|
494 | * the function called for each passing timeSnap |
---|
495 | * @param time The timespan passed since last update |
---|
496 | */ |
---|
497 | void SpaceShip::tick (float time) |
---|
498 | { |
---|
499 | // Playable::tick(time); |
---|
500 | |
---|
501 | // this->test->tick(time); |
---|
502 | |
---|
503 | // Own Tick Setup, as a different fire routine is used on the weapon manager |
---|
504 | this->weaponMan.tick(time); |
---|
505 | this->secWeaponMan.tick(time); |
---|
506 | |
---|
507 | if( this->systemFailure() ) |
---|
508 | bFire = bSecFire = false; |
---|
509 | |
---|
510 | // fire reqeust/release for primary weapons |
---|
511 | if( this->bFire) |
---|
512 | this->weaponMan.fire(); |
---|
513 | else |
---|
514 | this->weaponMan.releaseFire(); |
---|
515 | |
---|
516 | // fire reqeust/release for secondary weapons |
---|
517 | if( this->bSecFire) |
---|
518 | this->secWeaponMan.fire(); |
---|
519 | else |
---|
520 | this->secWeaponMan.releaseFire(); |
---|
521 | |
---|
522 | // Tracktick |
---|
523 | if(this->entityTrack) |
---|
524 | this->entityTrack->tick(time); |
---|
525 | |
---|
526 | |
---|
527 | // Shield Regeneration and other regular calculations on the ship |
---|
528 | this->regen(time); |
---|
529 | |
---|
530 | // Weapon Regeneration and other regular calculations on the ship |
---|
531 | this->weaponRegen(time); |
---|
532 | |
---|
533 | // current engine speed output |
---|
534 | this->engineSpeedCur = this->engineSpeedBase + this->reactorOutput * this->engineEnergyShare; |
---|
535 | |
---|
536 | // calculation of maxSpeed and acceleration: |
---|
537 | this->travelSpeed = this->engineSpeedCur * 5; |
---|
538 | this->acceleration = this->travelSpeed * 2; |
---|
539 | |
---|
540 | this->movement(time); |
---|
541 | |
---|
542 | // TRYING TO FIX PNode. |
---|
543 | this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); |
---|
544 | this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); |
---|
545 | |
---|
546 | |
---|
547 | this->velocity = (this->getAbsCoor() - this->oldPos) / time; |
---|
548 | this->oldPos = this->getAbsCoor(); |
---|
549 | |
---|
550 | //FIXME |
---|
551 | this->trail->tick(time); |
---|
552 | this->trailL->tick(time); |
---|
553 | this->trailR->tick(time); |
---|
554 | |
---|
555 | //orient the spaceship in direction of the mouse |
---|
556 | /* |
---|
557 | rotQuat = Quaternion::quatSlerp( this->getAbsDir(), mouseDir, 0.5);//fabsf(time)*shipInertia); |
---|
558 | if (this->getAbsDir().distance(rotQuat) > 0.00000000000001) |
---|
559 | this->setAbsDir( rotQuat); |
---|
560 | //this->setAbsDirSoft(mouseDir,5); |
---|
561 | */ |
---|
562 | /* |
---|
563 | this->shiftCoor(move); |
---|
564 | */ |
---|
565 | |
---|
566 | // PRINTF(0)("id of %s is: %i\n", this->getName(), this->getOMListNumber()); |
---|
567 | |
---|
568 | } |
---|
569 | |
---|
570 | /** |
---|
571 | * @todo switch statement ?? |
---|
572 | */ |
---|
573 | void SpaceShip::process(const Event &event) |
---|
574 | { |
---|
575 | //Playable::process(event); |
---|
576 | |
---|
577 | if( event.type == KeyMapper::PEV_LEFT) |
---|
578 | this->bLeft = event.bPressed; |
---|
579 | else if( event.type == KeyMapper::PEV_RIGHT) |
---|
580 | this->bRight = event.bPressed; |
---|
581 | else if( event.type == KeyMapper::PEV_FORWARD) |
---|
582 | this->bForward = event.bPressed; //this->shiftCoor(0,.1,0); |
---|
583 | else if( event.type == KeyMapper::PEV_BACKWARD) |
---|
584 | this->bBackward = event.bPressed; //this->shiftCoor(0,-.1,0); |
---|
585 | else if( event.type == KeyMapper::PEV_FIRE2) |
---|
586 | this->bSecFire = event.bPressed; |
---|
587 | else if( event.type == KeyMapper::PEV_FIRE1) |
---|
588 | this->bFire = event.bPressed; |
---|
589 | else if( event.type == KeyMapper::PEV_NEXT_WEAPON && event.bPressed) |
---|
590 | { |
---|
591 | this->nextWeaponConfig(); |
---|
592 | } |
---|
593 | else if ( event.type == KeyMapper::PEV_PREVIOUS_WEAPON && event.bPressed) |
---|
594 | this->previousWeaponConfig(); |
---|
595 | |
---|
596 | if (!(State::getCamera()->getEventHandling())) |
---|
597 | { |
---|
598 | if( event.type == KeyMapper::PEV_VIEW0) |
---|
599 | { |
---|
600 | State::getCamera()->setViewMode(Camera::ViewNormal); |
---|
601 | State::getCameraTargetNode()->setParent(this); |
---|
602 | State::getCamera()->setParent(this); |
---|
603 | } |
---|
604 | else if( event.type == KeyMapper::PEV_VIEW1) |
---|
605 | { |
---|
606 | State::getCamera()->setViewMode(Camera::ViewBehind); |
---|
607 | State::getCameraTargetNode()->setParent(this); |
---|
608 | State::getCamera()->setParent(this); |
---|
609 | } |
---|
610 | else if( event.type == KeyMapper::PEV_VIEW2) |
---|
611 | { |
---|
612 | State::getCamera()->setViewMode(Camera::ViewFront); |
---|
613 | State::getCameraTargetNode()->setParent(this); |
---|
614 | State::getCamera()->setParent(this); |
---|
615 | } |
---|
616 | else if( event.type == KeyMapper::PEV_VIEW3) |
---|
617 | { |
---|
618 | State::getCamera()->setViewMode(Camera::ViewLeft); |
---|
619 | State::getCameraTargetNode()->setParent(this); |
---|
620 | State::getCamera()->setParent(this); |
---|
621 | } |
---|
622 | else if( event.type == KeyMapper::PEV_VIEW4) |
---|
623 | { |
---|
624 | State::getCamera()->setViewMode(Camera::ViewRight); |
---|
625 | State::getCameraTargetNode()->setParent(this); |
---|
626 | State::getCamera()->setParent(this); |
---|
627 | } |
---|
628 | else if( event.type == KeyMapper::PEV_VIEW5) |
---|
629 | { |
---|
630 | State::getCamera()->setViewMode(Camera::ViewTop); |
---|
631 | State::getCameraTargetNode()->setParent(this->travelNode); |
---|
632 | State::getCamera()->setParent(this->travelNode); |
---|
633 | } |
---|
634 | } |
---|
635 | |
---|
636 | |
---|
637 | /* |
---|
638 | else if( event.type == EV_MOUSE_MOTION) |
---|
639 | { |
---|
640 | |
---|
641 | this->xMouse += event.xRel; |
---|
642 | this->yMouse += event.yRel; |
---|
643 | } |
---|
644 | */ |
---|
645 | } |
---|
646 | |
---|
647 | void SpaceShip::destroy( WorldEntity* killer ) |
---|
648 | { |
---|
649 | if(this->hasPlayer()) |
---|
650 | Playable::destroy( killer); |
---|
651 | |
---|
652 | PRINTF(5)("spaceship destroy\n"); |
---|
653 | |
---|
654 | EmitterNode* node = NULL; |
---|
655 | DotEmitter* emitter = NULL; |
---|
656 | SpriteParticles* explosionParticles = NULL; |
---|
657 | |
---|
658 | explosionParticles = new SpriteParticles(200); |
---|
659 | explosionParticles->setName("SpaceShipExplosionParticles"); |
---|
660 | explosionParticles->setLifeSpan(.2, .3); |
---|
661 | explosionParticles->setRadius(0.0, 10.0); |
---|
662 | explosionParticles->setRadius(.5, 6.0); |
---|
663 | explosionParticles->setRadius(1.0, 3.0); |
---|
664 | explosionParticles->setColor(0.0, 1,1,1,.9); |
---|
665 | explosionParticles->setColor(0.1, 1,1,0,.9); |
---|
666 | explosionParticles->setColor(0.5, .8,.4,0,.5); |
---|
667 | explosionParticles->setColor(1.0, .2,.2,.2,.5); |
---|
668 | |
---|
669 | |
---|
670 | emitter = new DotEmitter( 2000, 70, 360); |
---|
671 | //emitter->setSpread( 0, M_2_PI); |
---|
672 | emitter->setEmissionRate( 200.0); |
---|
673 | //emitter->setEmissionVelocity( 200.0); |
---|
674 | //emitter->setSystem( explosionParticles); |
---|
675 | //emitter->setAbsCoor( this->getAbsCoor()); |
---|
676 | |
---|
677 | node = new EmitterNode( .1f); |
---|
678 | node->setupParticle( emitter, explosionParticles); |
---|
679 | node->setAbsDir( this->getAbsDir()); |
---|
680 | node->setVelocity( this->getVelocity() * .9f); |
---|
681 | node->setAbsCoor( this->getAbsCoor()); |
---|
682 | if( !node->start()) |
---|
683 | PRINTF(0)("Explosion node not correctly started!"); |
---|
684 | /* |
---|
685 | PNode* node = new PNode(); |
---|
686 | node->setAbsCoor(this->getAbsCoor()); |
---|
687 | Explosion* explosion = new Explosion(); |
---|
688 | explosion->explode( node, Vector(5,5,5)); |
---|
689 | */ |
---|
690 | /* |
---|
691 | if( this->hasPlayer()) |
---|
692 | { |
---|
693 | this->setAbsCoor(Vector(-10000,10000,10000)); |
---|
694 | this->hide(); |
---|
695 | } |
---|
696 | else |
---|
697 | {*/ |
---|
698 | this->setAbsCoor( this->getAbsCoor() + Vector(100,0,0) + Vector(1,0,0) * VECTOR_RAND(150).dot(Vector(1,0,0))); |
---|
699 | //} |
---|
700 | |
---|
701 | } |
---|
702 | |
---|
703 | void SpaceShip::respawn( ) |
---|
704 | { |
---|
705 | Playable::respawn(); |
---|
706 | } |
---|
707 | |
---|
708 | |
---|
709 | void SpaceShip::damage(float pDamage, float eDamage){ |
---|
710 | PRINTF(5)("ship hit for (%f,%f) \n",pDamage,eDamage); |
---|
711 | |
---|
712 | if( this->shieldActive) { |
---|
713 | if( this->shieldCur > pDamage) { |
---|
714 | this->shieldCur = this->shieldCur - pDamage; |
---|
715 | } |
---|
716 | else { // shield <= pDamage |
---|
717 | this->shieldCur -=pDamage; |
---|
718 | this->shieldActive = false; //shield collapses |
---|
719 | pDamage += this->shieldCur; |
---|
720 | if( !this->shieldActive) { |
---|
721 | this->armorCur -= pDamage / 2; // remaining damages hits armor at half rate |
---|
722 | this->electronicCur -= eDamage; |
---|
723 | } |
---|
724 | } |
---|
725 | } |
---|
726 | else { |
---|
727 | this->armorCur = this->armorCur - pDamage; |
---|
728 | this->electronicCur = this->electronicCur - eDamage; |
---|
729 | } |
---|
730 | if( this->armorCur <= 0) { /* FIXME implement shipcrash*/ } |
---|
731 | this->destroy(this); |
---|
732 | |
---|
733 | updateElectronicWidget(); |
---|
734 | updateShieldWidget(); |
---|
735 | |
---|
736 | this->setHealth( this->armorCur); |
---|
737 | } |
---|
738 | |
---|
739 | |
---|
740 | void SpaceShip::regen(float time){ |
---|
741 | float tmp; |
---|
742 | if (this->armorCur != this->armorMax || this->armorRegen != 0){ |
---|
743 | tmp = this->armorCur + this->armorRegen * time; |
---|
744 | if ( tmp > electronicMax) |
---|
745 | this->armorCur = this->armorMax; |
---|
746 | else |
---|
747 | this->armorCur = tmp; |
---|
748 | } |
---|
749 | if (this->shieldCur != this->shieldMax || this->shieldRegen != 0){ |
---|
750 | tmp = this->shieldCur + (this->shieldRegen + this->reactorOutput * this->shieldEnergyShare) * time; |
---|
751 | if( tmp > shieldMax) |
---|
752 | this->shieldCur = this->shieldMax; |
---|
753 | else |
---|
754 | this->shieldCur = tmp; |
---|
755 | this->shieldActive = ( this->shieldActive || this->shieldCur > shieldTH); |
---|
756 | |
---|
757 | updateShieldWidget(); |
---|
758 | } |
---|
759 | |
---|
760 | this->setHealth( this->shieldCur); // FIXME currently just to test share system |
---|
761 | |
---|
762 | if (this->electronicCur != this->electronicMax || this->electronicRegen != 0){ |
---|
763 | tmp = this->electronicCur + this->electronicRegen * time; |
---|
764 | if ( tmp > electronicMax) |
---|
765 | this->electronicCur = this->electronicMax; |
---|
766 | else |
---|
767 | this->electronicCur = tmp; |
---|
768 | |
---|
769 | updateElectronicWidget(); |
---|
770 | } |
---|
771 | |
---|
772 | } |
---|
773 | |
---|
774 | |
---|
775 | /** |
---|
776 | * Weapon regeneration |
---|
777 | * does not use any reactor capacity, as it wouldn't work in a consistent way. |
---|
778 | */ |
---|
779 | void SpaceShip::weaponRegen(float time) |
---|
780 | { |
---|
781 | float energy = ( this->reactorOutput * this->weaponEnergyShare + this->weaponEnergyRegen) * time; |
---|
782 | Weapon* weapon; |
---|
783 | for( unsigned int i=0; i < this->weaponMan.getSlotCount(); i++) |
---|
784 | { |
---|
785 | weapon = this->weaponMan.getWeapon(i); |
---|
786 | if( weapon != NULL && weapon->isActive()) |
---|
787 | { |
---|
788 | weapon->increaseEnergy( energy); |
---|
789 | } |
---|
790 | |
---|
791 | } |
---|
792 | // weaponMan.increaseAmmunition( weapon, energy); |
---|
793 | } |
---|
794 | |
---|
795 | |
---|
796 | void SpaceShip::enterPlaymode(Playable::Playmode playmode) |
---|
797 | { |
---|
798 | switch(playmode) |
---|
799 | { |
---|
800 | case Playable::Full3D: |
---|
801 | /* |
---|
802 | if (State::getCameraNode != NULL) |
---|
803 | { |
---|
804 | Vector absCoor = this->getAbsCoor(); |
---|
805 | this->setParent(PNode::getNullParent()); |
---|
806 | this->setAbsCoor(absCoor); |
---|
807 | State::getCameraNode()->setParentSoft(&this->cameraNode); |
---|
808 | State::getCameraNode()->setRelCoorSoft(-10, 0,0); |
---|
809 | State::getCameraTargetNode()->setParentSoft(&this->cameraNode); |
---|
810 | State::getCameraTargetNode()->setRelCoorSoft(100, 0,0); |
---|
811 | |
---|
812 | } |
---|
813 | */ |
---|
814 | //break; |
---|
815 | |
---|
816 | break; |
---|
817 | case Playable::Horizontal: |
---|
818 | if (State::getCameraNode != NULL) |
---|
819 | { |
---|
820 | this->debugNode(1); |
---|
821 | this->travelNode->debugNode(1); |
---|
822 | |
---|
823 | this->travelNode->setAbsCoor(this->getAbsCoor()); |
---|
824 | this->travelNode->updateNode(0.01f); |
---|
825 | |
---|
826 | this->setParent(this->travelNode); |
---|
827 | |
---|
828 | // If track exists put travelNode on trackNode of track |
---|
829 | if (this->entityTrack) |
---|
830 | this->travelNode->setParent(this->entityTrack->getTrackNode()); |
---|
831 | |
---|
832 | |
---|
833 | |
---|
834 | this->setRelCoor(0,0,0); |
---|
835 | |
---|
836 | State::getCameraNode()->setParentSoft(this->travelNode); |
---|
837 | //State::getCameraNode()->setParentSoft(this->entityTrack->getTrackNode()); |
---|
838 | //State::getCameraNode()->setRelCoorSoft(-0.01, 40, 0); |
---|
839 | State::getCameraTargetNode()->setParentSoft(this->travelNode); |
---|
840 | //State::getCameraTargetNode()->setParentSoft(this->entityTrack->getTrackNode()); |
---|
841 | //State::getCameraTargetNode()->setRelCoorSoft(0,0,0); |
---|
842 | this->setCameraMode(Camera::ViewTop); |
---|
843 | State::getCamera()->setEventHandling(false); |
---|
844 | registerEvent(KeyMapper::PEV_VIEW0); |
---|
845 | registerEvent(KeyMapper::PEV_VIEW1); |
---|
846 | registerEvent(KeyMapper::PEV_VIEW2); |
---|
847 | registerEvent(KeyMapper::PEV_VIEW3); |
---|
848 | registerEvent(KeyMapper::PEV_VIEW4); |
---|
849 | registerEvent(KeyMapper::PEV_VIEW5); |
---|
850 | |
---|
851 | State::getCamera()->setParentMode(PNODE_MOVEMENT); |
---|
852 | |
---|
853 | this->debugNode(1); |
---|
854 | this->travelNode->debugNode(1); |
---|
855 | } |
---|
856 | break; |
---|
857 | |
---|
858 | default: |
---|
859 | PRINTF(2)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); |
---|
860 | } |
---|
861 | } |
---|
862 | |
---|
863 | /** |
---|
864 | * @brief calculate the velocity |
---|
865 | * @param time the timeslice since the last frame |
---|
866 | */ |
---|
867 | |
---|
868 | void SpaceShip::movement (float dt) |
---|
869 | { |
---|
870 | //by releasing the buttons, the velocity decreases with airCoeff*Acceleration. Should be strong enough so |
---|
871 | //the ship doesn't slide too much. |
---|
872 | float airCoeff = 2.5; |
---|
873 | float pi = 3.14; |
---|
874 | |
---|
875 | |
---|
876 | switch(this->getPlaymode()) |
---|
877 | { |
---|
878 | case Playable::Horizontal: |
---|
879 | { |
---|
880 | // these routines will change the travel movement into zero in a short amout of time, if the player |
---|
881 | // doesn't press any buttons. |
---|
882 | if (this->travelVelocity.x >= 0) |
---|
883 | { |
---|
884 | if (this->travelVelocity.x > airCoeff*this->acceleration * dt) |
---|
885 | this->travelVelocity.x -= airCoeff* this->acceleration * dt; |
---|
886 | else |
---|
887 | this->travelVelocity.x = 0; |
---|
888 | } |
---|
889 | else |
---|
890 | { |
---|
891 | if (this->travelVelocity.x < -airCoeff*this->acceleration * dt) |
---|
892 | this->travelVelocity.x += airCoeff* this->acceleration * dt; |
---|
893 | else |
---|
894 | this->travelVelocity.x = 0; |
---|
895 | } |
---|
896 | if (this->travelVelocity.z >= 0) |
---|
897 | { |
---|
898 | if (this->travelVelocity.z > airCoeff*this->acceleration * dt) |
---|
899 | this->travelVelocity.z -= airCoeff* this->acceleration * dt; |
---|
900 | else |
---|
901 | this->travelVelocity.z = 0; |
---|
902 | } |
---|
903 | else |
---|
904 | { |
---|
905 | if (this->travelVelocity.z < -airCoeff*this->acceleration * dt) |
---|
906 | this->travelVelocity.z += airCoeff* this->acceleration * dt; |
---|
907 | else |
---|
908 | this->travelVelocity.z = 0; |
---|
909 | } |
---|
910 | |
---|
911 | // this will evite, that the ship moves outside the travelDistance- borders,when the player releases all buttons |
---|
912 | // and its continuing to slide a bit. |
---|
913 | Vector oldCoor = this->getRelCoor(); |
---|
914 | if (this->getRelCoor().x > this->travelDistancePlus.x) this->setRelCoor(this->travelDistancePlus.x, oldCoor.y, oldCoor.z); |
---|
915 | if (this->getRelCoor().x < this->travelDistanceMinus.x) this->setRelCoor(this->travelDistanceMinus.x, oldCoor.y, oldCoor.z); |
---|
916 | if (this->getRelCoor().z > this->travelDistancePlus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistancePlus.y); |
---|
917 | if (this->getRelCoor().z < this->travelDistanceMinus.y) this->setRelCoor(oldCoor.x, oldCoor.y, this->travelDistanceMinus.y); |
---|
918 | |
---|
919 | if( this->systemFailure() ) |
---|
920 | bForward = bBackward = bLeft = bRight = false; |
---|
921 | |
---|
922 | if( this->bForward ) |
---|
923 | { |
---|
924 | if(this->getRelCoor().x < this->travelDistancePlus.x) |
---|
925 | { |
---|
926 | if (this->travelVelocity.x < this->travelSpeed) |
---|
927 | { |
---|
928 | this->travelVelocity.x += (airCoeff + 1.0)*this->acceleration*dt; |
---|
929 | } |
---|
930 | else |
---|
931 | { |
---|
932 | this->travelVelocity.x = this->travelSpeed; |
---|
933 | } |
---|
934 | } |
---|
935 | else |
---|
936 | { |
---|
937 | this->travelVelocity.x = 0.0f; |
---|
938 | } |
---|
939 | } |
---|
940 | |
---|
941 | if( this->bBackward ) |
---|
942 | { |
---|
943 | if(this->getRelCoor().x > this->travelDistanceMinus.x) |
---|
944 | { |
---|
945 | if (this->travelVelocity.x > -this->travelSpeed) |
---|
946 | { |
---|
947 | this->travelVelocity.x -= (airCoeff + 1.0)*this->acceleration*dt; |
---|
948 | } |
---|
949 | else |
---|
950 | { |
---|
951 | this->travelVelocity.x = -this->travelSpeed; |
---|
952 | } |
---|
953 | } |
---|
954 | else |
---|
955 | { |
---|
956 | this->travelVelocity.x = 0.0f; |
---|
957 | } |
---|
958 | } |
---|
959 | |
---|
960 | if( this->bLeft) |
---|
961 | { |
---|
962 | if(this->getRelCoor().z > this->travelDistanceMinus.y) |
---|
963 | { |
---|
964 | if (this->travelVelocity.z > -this->travelSpeed) |
---|
965 | { |
---|
966 | this->travelVelocity.z -= (airCoeff + 1.0)*this->acceleration*dt; |
---|
967 | } |
---|
968 | else |
---|
969 | { |
---|
970 | this->travelVelocity.z = -this->travelSpeed; |
---|
971 | } |
---|
972 | } |
---|
973 | else |
---|
974 | { |
---|
975 | this->travelVelocity.z = 0.0f; |
---|
976 | } |
---|
977 | this->setRelDirSoft(Quaternion(-pi/6, Vector(1,0,0)), 6); |
---|
978 | } |
---|
979 | |
---|
980 | if( this->bRight) |
---|
981 | { |
---|
982 | if(this->getRelCoor().z < this->travelDistancePlus.y) |
---|
983 | { |
---|
984 | if (this->travelVelocity.z < this->travelSpeed) |
---|
985 | { |
---|
986 | this->travelVelocity.z += (airCoeff + 1.0)*this->acceleration*dt; |
---|
987 | } |
---|
988 | else |
---|
989 | { |
---|
990 | this->travelVelocity.z = this->travelSpeed; |
---|
991 | } |
---|
992 | } |
---|
993 | else |
---|
994 | { |
---|
995 | this->travelVelocity.z = 0.0f; |
---|
996 | } |
---|
997 | this->setRelDirSoft(Quaternion(pi/6, Vector(1,0,0)), 6); |
---|
998 | } |
---|
999 | if (!this->bRight && !this->bLeft) |
---|
1000 | { |
---|
1001 | this->setRelDirSoft(Quaternion(0, Vector(1,0,0)), 6); |
---|
1002 | } |
---|
1003 | |
---|
1004 | //normalisation of the vectors (vector sum must be <= travelspeed) |
---|
1005 | float xzNorm = sqrt(pow(this->travelVelocity.x, 2) + pow(this->travelVelocity.z, 2)); |
---|
1006 | if (xzNorm > this->travelSpeed) |
---|
1007 | { |
---|
1008 | this->travelVelocity.x = this->travelVelocity.x/xzNorm * this->travelSpeed; |
---|
1009 | this->travelVelocity.z = this->travelVelocity.z/xzNorm * this->travelSpeed; |
---|
1010 | } |
---|
1011 | |
---|
1012 | //this moves camera and ship along the travel path. |
---|
1013 | if (!this->entityTrack) |
---|
1014 | this->travelNode->shiftCoor(Vector(this->cameraSpeed * dt, 0, 0)); |
---|
1015 | |
---|
1016 | break; |
---|
1017 | } |
---|
1018 | case Playable::Vertical: |
---|
1019 | break; |
---|
1020 | default: |
---|
1021 | PRINTF(4)("Playmode %s Not Implemented in %s\n", Playable::playmodeToString(this->getPlaymode()).c_str(), this->getClassCName()); |
---|
1022 | } |
---|
1023 | //set new coordinates calculated through key- events. |
---|
1024 | this->shiftCoor (this->travelVelocity * dt); |
---|
1025 | } |
---|
1026 | |
---|
1027 | void SpaceShip::setPlaymodeXML(const std::string& playmode) |
---|
1028 | { |
---|
1029 | this->setPlaymode(Playable::stringToPlaymode(playmode)); |
---|
1030 | } |
---|
1031 | |
---|
1032 | /** |
---|
1033 | * @brief jumps to the next WeaponConfiguration |
---|
1034 | */ |
---|
1035 | void SpaceShip::nextWeaponConfig() |
---|
1036 | { |
---|
1037 | PRINTF(0)("Requested next weapon config!\n"); |
---|
1038 | this->weaponMan.nextWeaponConfig(); |
---|
1039 | Playable::weaponConfigChanged(); |
---|
1040 | } |
---|
1041 | |
---|
1042 | /** |
---|
1043 | * @brief moves to the last WeaponConfiguration |
---|
1044 | */ |
---|
1045 | void SpaceShip::previousWeaponConfig() |
---|
1046 | { |
---|
1047 | this->curWeaponPrimary = (this->curWeaponPrimary + 1) % 3; |
---|
1048 | this->weaponMan.changeWeaponConfig(this->curWeaponPrimary); |
---|
1049 | Playable::weaponConfigChanged(); |
---|
1050 | } |
---|
1051 | |
---|
1052 | void SpaceShip::hit( float damage, WorldEntity* killer) |
---|
1053 | { |
---|
1054 | this->damage(killer->getDamage(),0); |
---|
1055 | } |
---|
1056 | |
---|
1057 | void SpaceShip::updateElectronicWidget() |
---|
1058 | { |
---|
1059 | if (this->electronicWidget != NULL) |
---|
1060 | { //if it exists already: update it |
---|
1061 | this->electronicWidget->setMaximum(this->electronicMax); |
---|
1062 | this->electronicWidget->setValue(this->electronicCur); |
---|
1063 | } |
---|
1064 | else |
---|
1065 | { //create the widget |
---|
1066 | this->electronicWidget = new OrxGui::GLGuiEnergyWidgetVertical(); |
---|
1067 | this->electronicWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1)); |
---|
1068 | //this->electronicWidget->setDisplayedName("Electronics:"); |
---|
1069 | //this->electronicWidget->setSize2D(100,20); |
---|
1070 | //this->electronicWidget->setAbsCoor2D(150,200); |
---|
1071 | this->updateElectronicWidget(); |
---|
1072 | if (this->hasPlayer()) |
---|
1073 | State::getPlayer()->hud().setEnergyWidget(this->electronicWidget); |
---|
1074 | } |
---|
1075 | } |
---|
1076 | |
---|
1077 | void SpaceShip::updateShieldWidget() |
---|
1078 | { |
---|
1079 | if (this->shieldWidget != NULL) |
---|
1080 | { |
---|
1081 | this->shieldWidget->setMaximum(this->shieldMax); |
---|
1082 | this->shieldWidget->setValue(this->shieldCur);; |
---|
1083 | } |
---|
1084 | else |
---|
1085 | { |
---|
1086 | this->shieldWidget = new OrxGui::GLGuiEnergyWidgetVertical(); |
---|
1087 | this->shieldWidget->getBarWidget()->setChangedValueColor(Color(1,0,0,1)); |
---|
1088 | //this->shieldWidget->setDisplayedName("Shield:"); |
---|
1089 | //his->shieldWidget->setSize2D(100,20); |
---|
1090 | //this->shieldWidget->setAbsCoor2D(200,200); |
---|
1091 | this->updateShieldWidget(); |
---|
1092 | if (this->hasPlayer()) |
---|
1093 | State::getPlayer()->hud().setShiledWidget(this->shieldWidget); |
---|
1094 | } |
---|
1095 | } |
---|
1096 | |
---|
1097 | void SpaceShip::setCameraDistance(float dist) |
---|
1098 | { |
---|
1099 | State::getCamera()->setViewTopDistance(dist); |
---|
1100 | } |
---|
1101 | |
---|
1102 | void SpaceShip::setCameraFovy(float fovy) |
---|
1103 | { |
---|
1104 | State::getCamera()->setViewTopFovy(fovy); |
---|
1105 | } |
---|