Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Sim.h
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: Sim.h
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Simulation Universe and Region classes
13
*/
14
15
#ifndef Sim_h
16
#define Sim_h
17
18
#include "
Types.h
"
19
#include "
Universe.h
"
20
#include "
Scene.h
"
21
#include "
Physical.h
"
22
#include "
Geometry.h
"
23
#include "
List.h
"
24
#include "
Text.h
"
25
26
// +--------------------------------------------------------------------+
27
28
class
Sim
;
29
class
SimRegion
;
30
class
SimObject
;
31
class
SimObserver
;
32
class
SimHyper
;
33
class
SimSplash
;
34
35
class
StarSystem
;
36
class
Orbital
;
37
class
OrbitalRegion
;
38
class
Asteroid
;
39
40
class
NetGame
;
41
42
class
CameraDirector
;
43
class
Contact
;
44
class
Ship
;
45
class
ShipDesign
;
46
class
System
;
47
class
Element
;
48
class
Shot
;
49
class
Drone
;
50
class
Explosion
;
51
class
Debris
;
52
class
WeaponDesign
;
53
class
MotionController
;
54
class
Dust
;
55
class
Grid
;
56
class
Mission
;
57
class
MissionElement
;
58
class
MissionEvent
;
59
class
Hangar
;
60
class
FlightDeck
;
61
62
class
Terrain
;
63
class
TerrainPatch
;
64
65
class
Model
;
66
67
// +--------------------------------------------------------------------+
68
69
class
Sim
:
public
Universe
70
{
71
friend
class
SimRegion
;
72
73
public
:
74
enum
{
REAL_SPACE
,
AIR_SPACE
};
75
76
Sim
(
MotionController
*
ctrl
);
77
virtual
~Sim
();
78
79
static
Sim
*
GetSim
() {
return
sim
; }
80
81
virtual
void
ExecFrame
(
double
seconds);
82
83
void
LoadMission
(
Mission
* msn,
bool
preload_textures=
false
);
84
void
ExecMission
();
85
void
CommitMission
();
86
void
UnloadMission
();
87
88
void
NextView
();
89
void
ShowGrid
(
int
show =
true
);
90
bool
GridShown
()
const
;
91
92
const
char
*
FindAvailCallsign
(
int
IFF);
93
Element
*
CreateElement
(
const
char
* callsign,
int
IFF,
int
type
=0
/*PATROL*/
);
94
void
DestroyElement
(
Element
* elem);
95
Ship
*
CreateShip
(
const
char
*
name
,
96
const
char
* reg_num,
97
ShipDesign
* design,
98
const
char
* rgn_name,
99
const
Point
& loc,
100
int
IFF=0,
101
int
cmd_ai=0,
102
const
int
* loadout=0);
103
Ship
*
FindShip
(
const
char
*
name
,
const
char
* rgn_name=0);
104
Shot
*
CreateShot
(
const
Point
& pos,
const
Camera
& shot_cam,
WeaponDesign
* d,
const
Ship
* ship=0,
SimRegion
* rgn=0);
105
Explosion
*
CreateExplosion
(
const
Point
& pos,
const
Point
& vel,
int
type
,
float
exp_scale,
float
part_scale,
SimRegion
* rgn=0,
SimObject
* source=0,
System
* sys=0);
106
Debris
*
CreateDebris
(
const
Point
& pos,
const
Point
& vel,
Model
* model,
double
mass,
SimRegion
* rgn=0);
107
Asteroid
*
CreateAsteroid
(
const
Point
& pos,
int
type
,
double
mass,
SimRegion
* rgn=0);
108
void
CreateSplashDamage
(
Ship
* ship);
109
void
CreateSplashDamage
(
Shot
* shot);
110
void
DestroyShip
(
Ship
* ship);
111
void
NetDockShip
(
Ship
* ship,
Ship
* carrier,
FlightDeck
* deck);
112
113
virtual
Ship
*
FindShipByObjID
(DWORD objid);
114
virtual
Shot
*
FindShotByObjID
(DWORD objid);
115
116
Mission
*
GetMission
() {
return
mission
; }
117
List<MissionEvent>
&
GetEvents
() {
return
events
; }
118
List<SimRegion>
&
GetRegions
() {
return
regions
; }
119
SimRegion
*
FindRegion
(
const
char
*
name
);
120
SimRegion
*
FindRegion
(
OrbitalRegion
* rgn);
121
SimRegion
*
FindNearestSpaceRegion
(
SimObject
*
object
);
122
SimRegion
*
FindNearestSpaceRegion
(
Orbital
* body);
123
SimRegion
*
FindNearestTerrainRegion
(
SimObject
*
object
);
124
SimRegion
*
FindNearestRegion
(
SimObject
*
object
,
int
type
);
125
bool
ActivateRegion
(
SimRegion
* rgn);
126
127
void
RequestHyperJump
(
Ship
* obj,
128
SimRegion
* rgn,
129
const
Point
& loc,
130
int
type
=0,
131
Ship
* fc_src=0,
132
Ship
* fc_dst=0);
133
134
SimRegion
*
GetActiveRegion
() {
return
active_region
; }
135
StarSystem
*
GetStarSystem
() {
return
star_system
; }
136
List<StarSystem>
&
GetSystemList
();
137
Scene
*
GetScene
() {
return
&
scene
; }
138
Ship
*
GetPlayerShip
();
139
Element
*
GetPlayerElement
();
140
Orbital
*
FindOrbitalBody
(
const
char
*
name
);
141
142
void
SetSelection
(
Ship
* s);
143
bool
IsSelected
(
Ship
* s);
144
ListIter<Ship>
GetSelection
();
145
void
ClearSelection
();
146
void
AddSelection
(
Ship
* s);
147
148
void
SetTestMode
(
bool
t=
true
);
149
150
bool
IsTestMode
()
const
{
return
test_mode
; }
151
bool
IsNetGame
()
const
{
return
netgame
!= 0; }
152
bool
IsActive
()
const
;
153
bool
IsComplete
()
const
;
154
155
MotionController
*
GetControls
()
const
{
return
ctrl
; }
156
157
Element
*
FindElement
(
const
char
*
name
);
158
List<Element>
&
GetElements
() {
return
elements
; }
159
160
int
GetAssignedElements
(
Element
* elem,
List<Element>
& assigned);
161
162
void
SkipCutscene
();
163
void
ResolveTimeSkip
(
double
seconds);
164
void
ResolveHyperList
();
165
void
ResolveSplashList
();
166
167
void
ExecEvents
(
double
seconds);
168
void
ProcessEventTrigger
(
int
type
,
int
event_id=0,
const
char
* ship=0,
int
param=0);
169
double
MissionClock
()
const
;
170
DWORD
StartTime
()
const
{
return
start_time
; }
171
172
// Create a list of mission elements based on the current
173
// state of the simulation. Used for multiplayer join in progress.
174
ListIter<MissionElement>
GetMissionElements
();
175
176
protected
:
177
void
CreateRegions
();
178
void
CreateElements
();
179
void
CopyEvents
();
180
void
BuildLinks
();
181
182
// Convert a single live element into a mission element
183
// that can be serialized over the net.
184
MissionElement
*
CreateMissionElement
(
Element
* elem);
185
Hangar
*
FindSquadron
(
const
char
*
name
,
int
& index);
186
187
static
Sim
*
sim
;
188
SimRegion
*
active_region
;
189
StarSystem
*
star_system
;
190
Scene
scene
;
191
Dust
*
dust
;
192
CameraDirector
*
cam_dir
;
193
194
List<SimRegion>
regions
;
195
List<SimRegion>
rgn_queue
;
196
List<SimHyper>
jumplist
;
197
List<SimSplash>
splashlist
;
198
List<Element>
elements
;
199
List<Element>
finished
;
200
List<MissionEvent>
events
;
201
List<MissionElement>
mission_elements
;
202
203
MotionController
*
ctrl
;
204
205
bool
test_mode
;
206
bool
grid_shown
;
207
Mission
*
mission
;
208
209
NetGame
*
netgame
;
210
DWORD
start_time
;
211
};
212
213
// +--------------------------------------------------------------------+
214
215
class
SimRegion
216
{
217
friend
class
Sim
;
218
219
public
:
220
static
const
char
*
TYPENAME
() {
return
"SimRegion"
; }
221
222
enum
{
REAL_SPACE
,
AIR_SPACE
};
223
224
SimRegion
(
Sim
*
sim
,
const
char
*
name
,
int
type
);
225
SimRegion
(
Sim
*
sim
,
OrbitalRegion
* rgn);
226
virtual
~SimRegion
();
227
228
int
operator ==
(
const
SimRegion
& r)
const
{
return
(
sim
==r.
sim
) && (
name
==r.
name
); }
229
int
operator <
(
const
SimRegion
& r)
const
;
230
int
operator <=
(
const
SimRegion
& r)
const
;
231
232
virtual
void
Activate
();
233
virtual
void
Deactivate
();
234
virtual
void
ExecFrame
(
double
seconds);
235
void
ShowGrid
(
int
show =
true
);
236
void
NextView
();
237
Ship
*
FindShip
(
const
char
*
name
);
238
Ship
*
GetPlayerShip
() {
return
player_ship
; }
239
void
SetPlayerShip
(
Ship
* ship);
240
OrbitalRegion
*
GetOrbitalRegion
() {
return
orbital_region
; }
241
Terrain
*
GetTerrain
() {
return
terrain
; }
242
bool
IsActive
()
const
{
return
active
; }
243
bool
IsAirSpace
()
const
{
return
type
==
AIR_SPACE
; }
244
bool
IsOrbital
()
const
{
return
type
==
REAL_SPACE
; }
245
bool
CanTimeSkip
()
const
;
246
247
virtual
Ship
*
FindShipByObjID
(DWORD objid);
248
virtual
Shot
*
FindShotByObjID
(DWORD objid);
249
250
virtual
void
InsertObject
(
Ship
* ship);
251
virtual
void
InsertObject
(
Shot
* shot);
252
virtual
void
InsertObject
(
Explosion
* explosion);
253
virtual
void
InsertObject
(
Debris
*
debris
);
254
virtual
void
InsertObject
(
Asteroid
* asteroid);
255
256
const
char
*
Name
()
const
{
return
name
; }
257
int
Type
()
const
{
return
type
; }
258
int
NumShips
() {
return
ships
.
size
(); }
259
List<Ship>
&
Ships
() {
return
ships
; }
260
List<Ship>
&
Carriers
() {
return
carriers
; }
261
List<Shot>
&
Shots
() {
return
shots
; }
262
List<Drone>
&
Drones
() {
return
drones
; }
263
List<Debris>
&
Rocks
() {
return
debris
; }
264
List<Asteroid>
&
Roids
() {
return
asteroids
; }
265
List<Explosion>
&
Explosions
() {
return
explosions
; }
266
List<SimRegion>
&
Links
() {
return
links
; }
267
StarSystem
*
System
() {
return
star_system
; }
268
269
Point
Location
()
const
{
return
location
; }
270
271
void
SetSelection
(
Ship
* s);
272
bool
IsSelected
(
Ship
* s);
273
ListIter<Ship>
GetSelection
();
274
void
ClearSelection
();
275
void
AddSelection
(
Ship
* s);
276
277
List<Contact>
&
TrackList
(
int
iff);
278
279
void
ResolveTimeSkip
(
double
seconds);
280
281
protected
:
282
void
CommitMission
();
283
void
TranslateObject
(
SimObject
*
object
);
284
285
void
AttachPlayerShip
(
int
index);
286
void
DestroyShips
();
287
void
DestroyShip
(
Ship
* ship);
288
void
NetDockShip
(
Ship
* ship,
Ship
* carrier,
FlightDeck
* deck);
289
290
void
UpdateSky
(
double
seconds,
const
Point
& ref);
291
void
UpdateShips
(
double
seconds);
292
void
UpdateShots
(
double
seconds);
293
void
UpdateExplosions
(
double
seconds);
294
void
UpdateTracks
(
double
seconds);
295
296
void
DamageShips
();
297
void
CollideShips
();
298
void
CrashShips
();
299
void
DockShips
();
300
301
Sim
*
sim
;
302
Text
name
;
303
int
type
;
304
StarSystem
*
star_system
;
305
OrbitalRegion
*
orbital_region
;
306
Point
location
;
307
Grid
*
grid
;
308
Terrain
*
terrain
;
309
bool
active
;
310
311
Ship
*
player_ship
;
312
int
current_view
;
313
List<Ship>
ships
;
314
List<Ship>
carriers
;
315
List<Ship>
selection
;
316
List<Ship>
dead_ships
;
317
List<Shot>
shots
;
318
List<Drone>
drones
;
319
List<Explosion>
explosions
;
320
List<Debris>
debris
;
321
List<Asteroid>
asteroids
;
322
List<Contact>
track_database
[5];
323
List<SimRegion>
links
;
324
325
DWORD
sim_time
;
326
int
ai_index
;
327
};
328
329
#endif Sim_h
330
Stars45
Sim.h
Generated on Tue Jun 5 2012 20:47:11 for Starshatter_Open by
1.8.1