Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
NavSystem.cpp
Go to the documentation of this file.
1 /* Project Starshatter 5.0
2  Destroyer Studios LLC
3  Copyright © 1997-2007. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: NavSystem.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Navigation System class implementation
13 */
14 
15 #include "MemDebug.h"
16 #include "NavSystem.h"
17 #include "Ship.h"
18 #include "Sim.h"
19 #include "HUDSounds.h"
20 #include "Button.h"
21 #include "Game.h"
22 
23 // +----------------------------------------------------------------------+
24 
26 : System(COMPUTER, 2, "Auto Nav System", 1, 1,1,1),
27 autonav(0)
28 {
29  name = Game::GetText("sys.nav-system");
30  abrv = Game::GetText("sys.nav-system.abrv");
31 
33 }
34 
35 // +----------------------------------------------------------------------+
36 
38 : System(s), autonav(0)
39 {
40  Mount(s);
41 
43 }
44 
45 // +--------------------------------------------------------------------+
46 
48 { }
49 
50 // +--------------------------------------------------------------------+
51 
52 void
53 NavSystem::ExecFrame(double seconds)
54 {
55  if (autonav && ship && !ship->GetNextNavPoint())
56  autonav = false;
57 
58  energy = 0.0f;
59  System::ExecFrame(seconds);
60 }
61 
62 // +----------------------------------------------------------------------+
63 
64 bool
66 {
67  return ship && autonav && IsPowerOn();
68 }
69 
70 void
72 {
73  if (IsPowerOn() && !autonav) {
74  if (!ship->GetNextNavPoint()) {
76  }
77  else {
79  autonav = true;
80  }
81  }
82 }
83 
84 void
86 {
87  if (autonav)
89 
90  autonav = false;
91 }
92 
93 // +--------------------------------------------------------------------+
94 
95 void
96 NavSystem::Distribute(double delivered_energy, double seconds)
97 {
98  if (IsPowerOn()) {
99  // convert Joules to Watts:
100  energy = (float) (delivered_energy/seconds);
101 
102  // brown out:
103  if (energy < capacity*0.75f)
104  power_on = false;
105 
106  // spike:
107  else if (energy > capacity*1.5f) {
108  power_on = false;
109  ApplyDamage(50);
110  }
111  }
112 }
113