Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Component.cpp
Go to the documentation of this file.
1
/* Project Starshatter 4.5
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: Stars.exe
6
FILE: Component.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Generic ship system sub-component class
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
Component.h
"
17
#include "
System.h
"
18
#include "
Game.h
"
19
20
// +----------------------------------------------------------------------+
21
22
ComponentDesign::ComponentDesign
()
23
: repair_time(0.0f), replace_time(0.0f), spares(0), affects(0)
24
{ }
25
26
// +----------------------------------------------------------------------+
27
28
ComponentDesign::~ComponentDesign
()
29
{ }
30
31
// +----------------------------------------------------------------------+
32
33
Component::Component
(
ComponentDesign
* d,
System
* s)
34
: design(d), system(s),
35
status(NOMINAL), availability(100.0f), time_remaining(0.0f),
36
spares(0), jerried(0)
37
{
38
if
(
design
)
39
spares
=
design
->
spares
;
40
}
41
42
// +----------------------------------------------------------------------+
43
44
Component::Component
(
const
Component
& c)
45
: design(c.design), system(c.system),
46
status(c.status), availability(c.availability), time_remaining(c.time_remaining),
47
spares(c.spares), jerried(c.jerried)
48
{
49
}
50
51
// +--------------------------------------------------------------------+
52
53
Component::~Component
()
54
{ }
55
56
// +--------------------------------------------------------------------+
57
58
void
59
Component::ExecMaintFrame
(
double
seconds)
60
{
61
if
(
status
>
NOMINAL
) {
62
time_remaining
-= (float) seconds;
63
64
// when repairs are complete:
65
if
(
time_remaining
<= 0) {
66
if
(
status
==
REPAIR
) {
67
// did we just jerry-rig a failed component?
68
if
(
availability
< 50)
69
jerried
++;
70
71
if
(
jerried
< 5)
72
availability
+= 50.0f - 10 *
jerried
;
73
if
(
availability
> 100)
availability
= 100.0f;
74
}
75
else
{
76
availability
= 100.0f;
77
}
78
79
if
(
availability
> 99)
80
status
=
NOMINAL
;
81
else
if
(
availability
> 49)
82
status
=
DEGRADED
;
83
else
84
status
=
CRITICAL
;
85
86
time_remaining
= 0.0f;
87
88
if
(
system
)
89
system
->
CalcStatus
();
90
}
91
}
92
}
93
94
// +--------------------------------------------------------------------+
95
96
void
97
Component::ApplyDamage
(
double
damage)
98
{
99
availability
-= (float) damage;
100
if
(
availability
< 1)
availability
= 0.0f;
101
102
if
(
status
<
REPLACE
) {
103
if
(
availability
> 99)
104
status
=
NOMINAL
;
105
else
if
(
availability
> 49)
106
status
=
DEGRADED
;
107
else
108
status
=
CRITICAL
;
109
}
110
111
if
(
system
)
112
system
->
CalcStatus
();
113
}
114
115
// +--------------------------------------------------------------------+
116
117
void
118
Component::Repair
()
119
{
120
if
(
status
<
NOMINAL
) {
121
status
=
REPAIR
;
122
time_remaining
=
design
->
repair_time
;
123
124
if
(
system
)
125
system
->
CalcStatus
();
126
}
127
}
128
129
// +--------------------------------------------------------------------+
130
131
void
132
Component::Replace
()
133
{
134
if
(
status
<=
NOMINAL
) {
135
status
=
REPLACE
;
136
spares
--;
137
time_remaining
=
design
->
replace_time
;
138
139
if
(
system
)
140
system
->
CalcStatus
();
141
}
142
}
143
144
// +--------------------------------------------------------------------+
145
146
float
147
Component::Availability
()
const
148
{
149
if
(
status
>
NOMINAL
&&
availability
> 50)
150
return
50.0f;
151
152
return
availability
;
153
}
154
155
float
156
Component::TimeRemaining
()
const
157
{
158
return
(
float
)
time_remaining
;
159
}
160
161
int
162
Component::SpareCount
()
const
163
{
164
return
spares
;
165
}
166
167
bool
168
Component::IsJerried
()
const
169
{
170
return
jerried
?
true
:
false
;
171
}
172
173
int
174
Component::NumJerried
()
const
175
{
176
return
jerried
;
177
}
Stars45
Component.cpp
Generated on Tue Jun 5 2012 20:46:50 for Starshatter_Open by
1.8.1