Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
MsnDlg.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: MsnDlg.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Mission Briefing Dialog Active Window class
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
MsnDlg.h
"
17
#include "
PlanScreen.h
"
18
#include "
Starshatter.h
"
19
#include "
Campaign.h
"
20
#include "
Mission.h
"
21
#include "
Instruction.h
"
22
#include "
Ship.h
"
23
#include "
ShipDesign.h
"
24
#include "
StarSystem.h
"
25
26
#include "
NetLobby.h
"
27
28
#include "
Game.h
"
29
#include "
FormWindow.h
"
30
#include "
FormatUtil.h
"
31
#include "
Keyboard.h
"
32
#include "
Mouse.h
"
33
#include "
Button.h
"
34
#include "
ListBox.h
"
35
#include "
Slider.h
"
36
#include "
ParseUtil.h
"
37
38
// +--------------------------------------------------------------------+
39
40
MsnDlg::MsnDlg
(
PlanScreen
* mgr)
41
: plan_screen(mgr),
42
commit(0), cancel(0), campaign(0), mission(0),
43
pkg_index(-1), info(0)
44
{
45
campaign
=
Campaign::GetCampaign
();
46
47
if
(
campaign
)
48
mission
=
campaign
->
GetMission
();
49
50
mission_name
= 0;
51
mission_system
= 0;
52
mission_sector
= 0;
53
mission_time_start
= 0;
54
mission_time_target
= 0;
55
mission_time_target_label
= 0;
56
57
sit_button
= 0;
58
pkg_button
= 0;
59
nav_button
= 0;
60
wep_button
= 0;
61
commit
= 0;
62
cancel
= 0;
63
}
64
65
MsnDlg::~MsnDlg
()
66
{
67
}
68
69
// +--------------------------------------------------------------------+
70
71
void
72
MsnDlg::RegisterMsnControls
(
FormWindow
* win)
73
{
74
mission_name
= win->
FindControl
(200);
75
mission_system
= win->
FindControl
(202);
76
mission_sector
= win->
FindControl
(204);
77
mission_time_start
= win->
FindControl
(206);
78
mission_time_target
= win->
FindControl
(208);
79
mission_time_target_label
= win->
FindControl
(207);
80
81
sit_button
= (
Button
*) win->
FindControl
(900);
82
pkg_button
= (
Button
*) win->
FindControl
(901);
83
nav_button
= (
Button
*) win->
FindControl
(902);
84
wep_button
= (
Button
*) win->
FindControl
(903);
85
commit
= (
Button
*) win->
FindControl
(1);
86
cancel
= (
Button
*) win->
FindControl
(2);
87
}
88
89
// +--------------------------------------------------------------------+
90
91
void
92
MsnDlg::ShowMsnDlg
()
93
{
94
campaign
=
Campaign::GetCampaign
();
95
96
mission
= 0;
97
pkg_index
= -1;
98
99
if
(
campaign
) {
100
mission
=
campaign
->
GetMission
();
101
102
if
(!
mission
)
103
::Print
(
"ERROR - MsnDlg::Show() no mission.\n"
);
104
else
105
::Print
(
"MsnDlg::Show() mission id = %d name = '%s'\n"
,
106
mission
->
Identity
(),
107
mission
->
Name
());
108
}
109
else
{
110
::Print
(
"ERROR - MsnDlg::Show() no campaign.\n"
);
111
}
112
113
if
(
mission_name
) {
114
if
(
mission
)
115
mission_name
->
SetText
(
mission
->
Name
());
116
else
117
mission_name
->
SetText
(
Game::GetText
(
"MsnDlg.no-mission"
));
118
}
119
120
if
(
mission_system
) {
121
mission_system
->
SetText
(
""
);
122
123
if
(
mission
) {
124
StarSystem
* sys =
mission
->
GetStarSystem
();
125
126
if
(sys)
127
mission_system
->
SetText
(sys->
Name
());
128
}
129
}
130
131
if
(
mission_sector
) {
132
mission_sector
->
SetText
(
""
);
133
134
if
(
mission
) {
135
mission_sector
->
SetText
(
mission
->
GetRegion
());
136
}
137
}
138
139
if
(
mission_time_start
) {
140
if
(
mission
) {
141
char
txt[32];
142
FormatDayTime
(txt,
mission
->
Start
());
143
mission_time_start
->
SetText
(txt);
144
}
145
}
146
147
if
(
mission_time_target
) {
148
int
time_on_target =
CalcTimeOnTarget
();
149
150
if
(time_on_target) {
151
char
txt[32];
152
FormatDayTime
(txt, time_on_target);
153
mission_time_target
->
SetText
(txt);
154
mission_time_target_label
->
SetText
(
Game::GetText
(
"MsnDlg.target"
));
155
}
156
else
{
157
mission_time_target
->
SetText
(
""
);
158
mission_time_target_label
->
SetText
(
""
);
159
}
160
}
161
162
163
if
(
sit_button
) {
164
sit_button
->
SetButtonState
(
plan_screen
->
IsMsnObjShown
());
165
sit_button
->
SetEnabled
(
true
);
166
}
167
168
if
(
pkg_button
) {
169
pkg_button
->
SetButtonState
(
plan_screen
->
IsMsnPkgShown
());
170
pkg_button
->
SetEnabled
(
true
);
171
}
172
173
if
(
nav_button
) {
174
nav_button
->
SetButtonState
(
plan_screen
->
IsNavShown
());
175
nav_button
->
SetEnabled
(
true
);
176
}
177
178
if
(
wep_button
) {
179
wep_button
->
SetButtonState
(
plan_screen
->
IsMsnWepShown
());
180
wep_button
->
SetEnabled
(
true
);
181
}
182
183
bool
mission_ok =
true
;
184
185
if
(!
mission
|| !
mission
->
IsOK
()) {
186
mission_ok =
false
;
187
188
if
(
sit_button
)
sit_button
->
SetEnabled
(
false
);
189
if
(
pkg_button
)
pkg_button
->
SetEnabled
(
false
);
190
if
(
nav_button
)
nav_button
->
SetEnabled
(
false
);
191
if
(
wep_button
)
wep_button
->
SetEnabled
(
false
);
192
}
193
else
{
194
MissionElement
* player_elem =
mission
->
GetPlayer
();
195
196
if
(
wep_button
&& player_elem)
197
wep_button
->
SetEnabled
(player_elem->
Loadouts
().
size
() > 0);
198
}
199
200
if
(
wep_button
&&
NetLobby::GetInstance
())
201
wep_button
->
SetEnabled
(
false
);
202
203
commit
->
SetEnabled
(mission_ok);
204
cancel
->
SetEnabled
(
true
);
205
}
206
207
// +--------------------------------------------------------------------+
208
209
int
210
MsnDlg::CalcTimeOnTarget
()
211
{
212
if
(
mission
) {
213
MissionElement
* element =
mission
->
GetElements
()[0];
214
if
(element) {
215
Point
loc = element->
Location
();
216
loc.
SwapYZ
();
// navpts use Z for altitude, element loc uses Y for altitude.
217
218
int
mission_time =
mission
->
Start
();
219
220
int
i = 0;
221
ListIter<Instruction>
navpt = element->
NavList
();
222
while
(++navpt) {
223
int
action = navpt->
Action
();
224
225
double
dist =
Point
(loc - navpt->
Location
()).length();
226
227
int
etr = 0;
228
229
if
(navpt->
Speed
() > 0)
230
etr = (
int
) (dist / navpt->
Speed
());
231
else
232
etr = (int) (dist / 500);
233
234
mission_time += etr;
235
236
loc = navpt->
Location
();
237
i++;
238
239
if
(action >=
Instruction::ESCORT
) {
// this is the target!
240
return
mission_time;
241
}
242
}
243
}
244
}
245
246
return
0;
247
}
248
249
// +--------------------------------------------------------------------+
250
251
void
252
MsnDlg::OnTabButton
(
AWEvent
* event)
253
{
254
if
(event->
window
==
sit_button
) {
255
plan_screen
->
ShowMsnObjDlg
();
256
}
257
258
if
(event->
window
==
pkg_button
) {
259
plan_screen
->
ShowMsnPkgDlg
();
260
}
261
262
if
(event->
window
==
nav_button
) {
263
plan_screen
->
ShowNavDlg
();
264
}
265
266
if
(event->
window
==
wep_button
) {
267
plan_screen
->
ShowMsnWepDlg
();
268
}
269
}
270
271
// +--------------------------------------------------------------------+
272
273
void
274
MsnDlg::OnCommit
(
AWEvent
* event)
275
{
276
Starshatter
* stars =
Starshatter::GetInstance
();
277
278
if
(stars) {
279
Mouse::Show
(
false
);
280
stars->
SetGameMode
(
Starshatter::LOAD_MODE
);
281
}
282
283
else
284
Game::Panic
(
"MsnDlg::OnCommit() - Game instance not found"
);
285
}
286
287
void
288
MsnDlg::OnCancel
(
AWEvent
* event)
289
{
290
Starshatter
* stars =
Starshatter::GetInstance
();
291
292
if
(stars) {
293
Mouse::Show
(
false
);
294
295
if
(
campaign
&& (
campaign
->
IsDynamic
() ||
campaign
->
IsTraining
()))
296
stars->
SetGameMode
(
Starshatter::CMPN_MODE
);
297
else
298
stars->
SetGameMode
(
Starshatter::MENU_MODE
);
299
}
300
301
else
302
Game::Panic
(
"MsnDlg::OnCancel() - Game instance not found"
);
303
}
Stars45
MsnDlg.cpp
Generated on Tue Jun 5 2012 20:46:58 for Starshatter_Open by
1.8.1