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