Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
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
25
NavSystem::NavSystem
()
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
32
power_flags
=
POWER_WATTS
|
POWER_CRITICAL
;
33
}
34
35
// +----------------------------------------------------------------------+
36
37
NavSystem::NavSystem
(
const
NavSystem
& s)
38
:
System
(s), autonav(0)
39
{
40
Mount
(s);
41
42
power_flags
=
POWER_WATTS
|
POWER_CRITICAL
;
43
}
44
45
// +--------------------------------------------------------------------+
46
47
NavSystem::~NavSystem
()
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
65
NavSystem::AutoNavEngaged
()
66
{
67
return
ship
&&
autonav
&&
IsPowerOn
();
68
}
69
70
void
71
NavSystem::EngageAutoNav
()
72
{
73
if
(
IsPowerOn
() && !
autonav
) {
74
if
(!
ship
->
GetNextNavPoint
()) {
75
Button::PlaySound
(
Button::SND_REJECT
);
76
}
77
else
{
78
HUDSounds::PlaySound
(
HUDSounds::SND_NAV_MODE
);
79
autonav
=
true
;
80
}
81
}
82
}
83
84
void
85
NavSystem::DisengageAutoNav
()
86
{
87
if
(
autonav
)
88
HUDSounds::PlaySound
(
HUDSounds::SND_NAV_MODE
);
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
Stars45
NavSystem.cpp
Generated on Thu May 31 2012 16:31:12 for Starshatter_Open by
1.8.1