Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
WeaponGroup.cpp
Go to the documentation of this file.
1
/* Project Starshatter 4.5
2
Destroyer Studios LLC
3
Copyright © 1997-2005. All Rights Reserved.
4
5
SUBSYSTEM: Stars.exe
6
FILE: WeaponGroup.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Weapon Control Category (Group) class
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
WeaponGroup.h
"
17
#include "
Ship.h
"
18
19
// +----------------------------------------------------------------------+
20
21
WeaponGroup::WeaponGroup
(
const
char
* n)
22
: selected(0), trigger(false), orders(
Weapon
::MANUAL),
23
control(
Weapon
::SINGLE_FIRE), sweep(
Weapon
::SWEEP_TIGHT),
24
mass(0.0f), resist(0.0f), name(n), ammo(0)
25
{ }
26
27
// +--------------------------------------------------------------------+
28
29
WeaponGroup::~WeaponGroup
()
30
{
31
weapons
.
destroy
();
32
}
33
34
// +--------------------------------------------------------------------+
35
36
void
37
WeaponGroup::SetName
(
const
char
* n)
38
{
39
name
= n;
40
}
41
42
void
43
WeaponGroup::SetAbbreviation
(
const
char
* a)
44
{
45
abrv
= a;
46
}
47
48
// +--------------------------------------------------------------------+
49
50
bool
51
WeaponGroup::IsPrimary
()
const
52
{
53
if
(
weapons
.
size
() > 0)
54
return
weapons
[0]->
IsPrimary
();
55
56
return
false
;
57
}
58
59
bool
60
WeaponGroup::IsDrone
()
const
61
{
62
if
(
weapons
.
size
() > 0)
63
return
weapons
[0]->
IsDrone
();
64
65
return
false
;
66
}
67
68
bool
69
WeaponGroup::IsDecoy
()
const
70
{
71
if
(
weapons
.
size
() > 0)
72
return
weapons
[0]->
IsDecoy
();
73
74
return
false
;
75
}
76
77
bool
78
WeaponGroup::IsProbe
()
const
79
{
80
if
(
weapons
.
size
() > 0)
81
return
weapons
[0]->
IsProbe
();
82
83
return
false
;
84
}
85
86
bool
87
WeaponGroup::IsMissile
()
const
88
{
89
if
(
weapons
.
size
() > 0)
90
return
weapons
[0]->
IsMissile
();
91
92
return
false
;
93
}
94
95
bool
96
WeaponGroup::IsBeam
()
const
97
{
98
if
(
weapons
.
size
() > 0)
99
return
weapons
[0]->
IsBeam
();
100
101
return
false
;
102
}
103
104
// +--------------------------------------------------------------------+
105
106
void
107
WeaponGroup::AddWeapon
(
Weapon
* w)
108
{
109
weapons
.
append
(w);
110
}
111
112
int
113
WeaponGroup::NumWeapons
()
const
114
{
115
return
weapons
.
size
();
116
}
117
118
List<Weapon>
&
119
WeaponGroup::GetWeapons
()
120
{
121
return
weapons
;
122
}
123
124
bool
125
WeaponGroup::Contains
(
const
Weapon
* w)
const
126
{
127
return
weapons
.
contains
(w)?
true
:
false
;
128
}
129
130
// +--------------------------------------------------------------------+
131
132
void
133
WeaponGroup::SelectWeapon
(
int
n)
134
{
135
if
(n >= 0 && n <
weapons
.
size
())
136
selected
= n;
137
}
138
139
void
140
WeaponGroup::CycleWeapon
()
141
{
142
selected
++;
143
144
if
(
selected
>=
weapons
.
size
())
145
selected
= 0;
146
}
147
148
Weapon
*
149
WeaponGroup::GetWeapon
(
int
n)
const
150
{
151
if
(n >= 0 && n <
weapons
.
size
())
152
return
weapons
[n];
153
154
return
0;
155
}
156
157
Weapon
*
158
WeaponGroup::GetSelected
()
const
159
{
160
return
weapons
[
selected
];
161
}
162
163
bool
164
WeaponGroup::CanTarget
(DWORD tgt_class)
const
165
{
166
if
(
selected
>= 0 &&
selected
<
weapons
.
size
())
167
return
weapons
[
selected
]->
CanTarget
(tgt_class);
168
169
return
false
;
170
}
171
172
// +--------------------------------------------------------------------+
173
174
void
175
WeaponGroup::ExecFrame
(
double
seconds)
176
{
177
ammo
= 0;
178
mass
= 0.0f;
179
resist
= 0.0f;
180
181
ListIter<Weapon>
iter =
weapons
;
182
while
(++iter) {
183
Weapon
* w = iter.
value
();
184
w->
ExecFrame
(seconds);
185
186
ammo
+= w->
Ammo
();
187
mass
+= w->
Mass
();
188
resist
+= w->
Resistance
();
189
}
190
}
191
192
void
193
WeaponGroup::CheckAmmo
()
194
{
195
ammo
= 0;
196
mass
= 0.0f;
197
resist
= 0.0f;
198
199
ListIter<Weapon>
iter =
weapons
;
200
while
(++iter) {
201
Weapon
* w = iter.
value
();
202
203
ammo
+= w->
Ammo
();
204
mass
+= w->
Mass
();
205
resist
+= w->
Resistance
();
206
}
207
}
208
209
// +--------------------------------------------------------------------+
210
211
void
212
WeaponGroup::SetTarget
(
SimObject
* target,
System
* subtarget)
213
{
214
ListIter<Weapon>
w =
weapons
;
215
while
(++w)
216
w->
SetTarget
(target, subtarget);
217
}
218
219
SimObject
*
220
WeaponGroup::GetTarget
()
const
221
{
222
SimObject
* target = 0;
223
224
if
(
weapons
.
size
())
225
target =
weapons
[0]->
GetTarget
();
226
227
return
target;
228
}
229
230
System
*
231
WeaponGroup::GetSubTarget
()
const
232
{
233
System
* subtarget = 0;
234
235
if
(
weapons
.
size
())
236
subtarget =
weapons
[0]->
GetSubTarget
();
237
238
return
subtarget;
239
}
240
241
void
242
WeaponGroup::DropTarget
()
243
{
244
ListIter<Weapon>
w =
weapons
;
245
while
(++w)
246
w->
SetTarget
(0, 0);
247
}
248
249
// +--------------------------------------------------------------------+
250
251
WeaponDesign
*
252
WeaponGroup::GetDesign
()
const
253
{
254
if
(
selected
>= 0 &&
selected
<
weapons
.
size
())
255
return
(
WeaponDesign
*)
weapons
[
selected
]->Design();
256
257
return
0;
258
}
259
260
// +--------------------------------------------------------------------+
261
262
int
263
WeaponGroup::Status
()
const
264
{
265
int
status =
System::NOMINAL
;
266
int
critical =
true
;
267
268
ListIter<Weapon>
iter = (
List<Weapon>
&)
weapons
;
// cast-away const
269
while
(++iter) {
270
Weapon
* w = iter.
value
();
271
272
if
(w->
Status
() <
System::NOMINAL
)
273
status =
System::DEGRADED
;
274
275
if
(w->
Status
() >
System::CRITICAL
)
276
critical =
false
;
277
}
278
279
if
(critical)
280
return
System::CRITICAL
;
281
282
return
status;
283
}
284
285
// +--------------------------------------------------------------------+
286
287
void
288
WeaponGroup::SetFiringOrders
(
int
o)
289
{
290
orders
= o;
291
292
ListIter<Weapon>
w =
weapons
;
293
while
(++w)
294
w->
SetFiringOrders
(
orders
);
295
}
296
297
void
298
WeaponGroup::SetControlMode
(
int
m)
299
{
300
control
= m;
301
302
ListIter<Weapon>
w =
weapons
;
303
while
(++w)
304
w->
SetControlMode
(
control
);
305
}
306
307
void
308
WeaponGroup::SetSweep
(
int
s)
309
{
310
sweep
= s;
311
312
ListIter<Weapon>
w =
weapons
;
313
while
(++w)
314
w->
SetSweep
(
sweep
);
315
}
316
317
// +--------------------------------------------------------------------+
318
319
void
320
WeaponGroup::PowerOff
()
321
{
322
ListIter<Weapon>
w =
weapons
;
323
while
(++w)
324
w->
PowerOff
();
325
}
326
327
void
328
WeaponGroup::PowerOn
()
329
{
330
ListIter<Weapon>
w =
weapons
;
331
while
(++w)
332
w->
PowerOn
();
333
}
334
335
// +--------------------------------------------------------------------+
336
337
int
338
WeaponGroup::Value
()
const
339
{
340
int
result = 0;
341
342
for
(
int
i = 0; i <
weapons
.
size
(); i++) {
343
const
Weapon
* w =
weapons
[i];
344
result += w->
Value
();
345
}
346
347
return
result;
348
}
Stars45
WeaponGroup.cpp
Generated on Tue Jun 5 2012 20:47:17 for Starshatter_Open by
1.8.1