Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
SimEvent.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: SimEvent.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Simulation Events for mission summary
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
SimEvent.h
"
17
#include "
Sim.h
"
18
#include "
Game.h
"
19
20
// +====================================================================+
21
22
List<ShipStats>
records
;
23
24
// +====================================================================+
25
26
SimEvent::SimEvent
(
int
e,
const
char
* t,
const
char
* i)
27
: event(e), count(0)
28
{
29
Sim
*
sim
=
Sim::GetSim
();
30
if
(sim) {
31
time = (int) sim->
MissionClock
();
32
}
33
else
{
34
time = (int) (
Game::GameTime
()/1000);
35
}
36
37
SetTarget
(t);
38
SetInfo
(i);
39
}
40
41
SimEvent::~SimEvent
()
42
{
43
}
44
45
// +--------------------------------------------------------------------+
46
47
void
48
SimEvent::SetTime
(
int
t)
49
{
50
time = t;
51
}
52
53
void
54
SimEvent::SetTarget
(
const
char
* t)
55
{
56
if
(t && t[0])
57
target = t;
58
}
59
60
void
61
SimEvent::SetInfo
(
const
char
* i)
62
{
63
if
(i && i[0])
64
info = i;
65
}
66
67
void
68
SimEvent::SetCount
(
int
c)
69
{
70
count = c;
71
}
72
73
Text
74
SimEvent::GetEventDesc
()
const
75
{
76
switch
(event) {
77
case
LAUNCH
:
return
Game::GetText
(
"sim.event.Launch"
);
78
case
DOCK
:
return
Game::GetText
(
"sim.event.Dock"
);
79
case
LAND
:
return
Game::GetText
(
"sim.event.Land"
);
80
case
EJECT
:
return
Game::GetText
(
"sim.event.Eject"
);
81
case
CRASH
:
return
Game::GetText
(
"sim.event.Crash"
);
82
case
COLLIDE
:
return
Game::GetText
(
"sim.event.Collision With"
);
83
case
DESTROYED
:
return
Game::GetText
(
"sim.event.Destroyed By"
);
84
case
MAKE_ORBIT
:
return
Game::GetText
(
"sim.event.Make Orbit"
);
85
case
BREAK_ORBIT
:
return
Game::GetText
(
"sim.event.Break Orbit"
);
86
case
QUANTUM_JUMP
:
return
Game::GetText
(
"sim.event.Quantum Jump"
);
87
case
LAUNCH_SHIP
:
return
Game::GetText
(
"sim.event.Launch Ship"
);
88
case
RECOVER_SHIP
:
return
Game::GetText
(
"sim.event.Recover Ship"
);
89
case
FIRE_GUNS
:
return
Game::GetText
(
"sim.event.Fire Guns"
);
90
case
FIRE_MISSILE
:
return
Game::GetText
(
"sim.event.Fire Missile"
);
91
case
DROP_DECOY
:
return
Game::GetText
(
"sim.event.Drop Decoy"
);
92
case
GUNS_KILL
:
return
Game::GetText
(
"sim.event.Guns Kill"
);
93
case
MISSILE_KILL
:
return
Game::GetText
(
"sim.event.Missile Kill"
);
94
case
LAUNCH_PROBE
:
return
Game::GetText
(
"sim.event.Launch Probe"
);
95
case
SCAN_TARGET
:
return
Game::GetText
(
"sim.event.Scan Target"
);
96
default
:
return
Game::GetText
(
"sim.event.no event"
);
97
}
98
}
99
100
// +====================================================================+
101
102
ShipStats::ShipStats
(
const
char
* n,
int
i)
103
: name(n), iff(i), kill1(0), kill2(0), lost(0), coll(0), points(0),
104
cmd_points(0), gun_shots(0), gun_hits(0), missile_shots(0), missile_hits(0),
105
combat_group(0), combat_unit(0), player(false), ship_class(0), elem_index(-1)
106
{
107
if
(!n || !n[0])
108
name =
Game::GetText
(
"[unknown]"
);
109
}
110
111
ShipStats::~ShipStats
()
112
{
113
events
.
destroy
();
114
}
115
116
// +--------------------------------------------------------------------+
117
118
void
119
ShipStats::SetType
(
const
char
* t)
120
{
121
if
(t && t[0])
122
type = t;
123
}
124
125
void
126
ShipStats::SetRole
(
const
char
* r)
127
{
128
if
(r && r[0])
129
role = r;
130
}
131
132
void
133
ShipStats::SetRegion
(
const
char
* r)
134
{
135
if
(r && r[0])
136
region = r;
137
}
138
139
void
140
ShipStats::SetCombatGroup
(
CombatGroup
* g)
141
{
142
combat_group = g;
143
}
144
145
void
146
ShipStats::SetCombatUnit
(
CombatUnit
* u)
147
{
148
combat_unit = u;
149
}
150
151
void
152
ShipStats::SetElementIndex
(
int
n)
153
{
154
elem_index = n;
155
}
156
157
void
158
ShipStats::SetPlayer
(
bool
p)
159
{
160
player = p;
161
}
162
163
// +--------------------------------------------------------------------+
164
165
void
166
ShipStats::Summarize
()
167
{
168
kill1 = 0;
169
kill2 = 0;
170
lost = 0;
171
coll = 0;
172
173
ListIter<SimEvent>
iter =
events
;
174
while
(++iter) {
175
SimEvent
*
event
= iter.
value
();
176
int
code =
event
->
GetEvent
();
177
178
if
(code ==
SimEvent::GUNS_KILL
)
179
kill1++;
180
181
else
if
(code ==
SimEvent::MISSILE_KILL
)
182
kill2++;
183
184
else
if
(code ==
SimEvent::DESTROYED
)
185
lost++;
186
187
else
if
(code ==
SimEvent::CRASH
)
188
coll++;
189
190
else
if
(code ==
SimEvent::COLLIDE
)
191
coll++;
192
}
193
}
194
195
// +--------------------------------------------------------------------+
196
197
SimEvent
*
198
ShipStats::AddEvent
(
SimEvent
* e)
199
{
200
events
.
append
(e);
201
return
e;
202
}
203
204
SimEvent
*
205
ShipStats::AddEvent
(
int
event,
const
char
* tgt,
const
char
* info)
206
{
207
SimEvent
* e =
new
(__FILE__,__LINE__)
SimEvent
(event, tgt, info);
208
events
.
append
(e);
209
return
e;
210
}
211
212
bool
213
ShipStats::HasEvent
(
int
event)
214
{
215
for
(
int
i = 0; i <
events
.
size
(); i++)
216
if
(
events
[i]->GetEvent() == event)
217
return
true
;
218
219
return
false
;
220
}
221
222
// +--------------------------------------------------------------------+
223
224
void
ShipStats::Initialize
() { records.
destroy
(); }
225
void
ShipStats::Close
() { records.
destroy
(); }
226
227
// +--------------------------------------------------------------------+
228
229
int
230
ShipStats::NumStats
()
231
{
232
return
records.
size
();
233
}
234
235
ShipStats
*
236
ShipStats::GetStats
(
int
i)
237
{
238
if
(i >= 0 && i < records.
size
())
239
return
records.
at
(i);
240
241
return
0;
242
}
243
244
ShipStats
*
245
ShipStats::Find
(
const
char
* name)
246
{
247
if
(name && name[0]) {
248
ListIter<ShipStats>
iter =
records
;
249
while
(++iter) {
250
ShipStats
* stats = iter.
value
();
251
if
(!strcmp(stats->
GetName
(), name))
252
return
stats;
253
}
254
255
ShipStats
* stats =
new
(__FILE__,__LINE__)
ShipStats
(name);
256
records.
append
(stats);
257
return
stats;
258
}
259
260
return
0;
261
}
262
Stars45
SimEvent.cpp
Generated on Tue Jun 5 2012 20:47:11 for Starshatter_Open by
1.8.1