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