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