Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
MsnPkgDlg.cpp
Go to the documentation of this file.
1
/* Project Starshatter 5.0
2
Destroyer Studios LLC
3
Copyright (C) 1997-2007. All Rights Reserved.
4
5
SUBSYSTEM: Stars.exe
6
FILE: MsnPkgDlg.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 "
MsnPkgDlg.h
"
17
#include "
PlanScreen.h
"
18
#include "
Campaign.h
"
19
#include "
Mission.h
"
20
#include "
Instruction.h
"
21
#include "
Ship.h
"
22
#include "
ShipDesign.h
"
23
#include "
StarSystem.h
"
24
25
#include "
Game.h
"
26
#include "
Mouse.h
"
27
#include "
Button.h
"
28
#include "
ListBox.h
"
29
#include "
Slider.h
"
30
#include "
ParseUtil.h
"
31
#include "
FormatUtil.h
"
32
#include "
Keyboard.h
"
33
34
// +--------------------------------------------------------------------+
35
// DECLARE MAPPING FUNCTIONS:
36
DEF_MAP_CLIENT
(
MsnPkgDlg
, OnPackage);
37
DEF_MAP_CLIENT
(
MsnPkgDlg
, OnCommit);
38
DEF_MAP_CLIENT
(
MsnPkgDlg
, OnCancel);
39
DEF_MAP_CLIENT
(
MsnPkgDlg
, OnTabButton);
40
41
// +--------------------------------------------------------------------+
42
43
MsnPkgDlg::MsnPkgDlg
(
Screen
* s,
FormDef
& def,
PlanScreen
* mgr)
44
:
FormWindow
(s, 0, 0, s->Width(), s->Height()),
MsnDlg
(mgr)
45
{
46
campaign
=
Campaign::GetCampaign
();
47
48
if
(
campaign
)
49
mission
=
campaign
->
GetMission
();
50
51
Init
(def);
52
}
53
54
MsnPkgDlg::~MsnPkgDlg
()
55
{
56
}
57
58
// +--------------------------------------------------------------------+
59
60
void
61
MsnPkgDlg::RegisterControls
()
62
{
63
pkg_list
= (
ListBox
*)
FindControl
(320);
64
nav_list
= (
ListBox
*)
FindControl
(330);
65
66
for
(
int
i = 0; i < 5; i++)
67
threat
[i] =
FindControl
(251 + i);
68
69
RegisterMsnControls
(
this
);
70
71
if
(
pkg_list
)
72
REGISTER_CLIENT
(
EID_SELECT
,
pkg_list
,
MsnPkgDlg
,
OnPackage
);
73
74
if
(
commit
)
75
REGISTER_CLIENT
(
EID_CLICK
,
commit
,
MsnPkgDlg
,
OnCommit
);
76
77
if
(
cancel
)
78
REGISTER_CLIENT
(
EID_CLICK
,
cancel
,
MsnPkgDlg
,
OnCancel
);
79
80
if
(
sit_button
)
81
REGISTER_CLIENT
(
EID_CLICK
,
sit_button
,
MsnPkgDlg
,
OnTabButton
);
82
83
if
(
pkg_button
)
84
REGISTER_CLIENT
(
EID_CLICK
,
pkg_button
,
MsnPkgDlg
,
OnTabButton
);
85
86
if
(
nav_button
)
87
REGISTER_CLIENT
(
EID_CLICK
,
nav_button
,
MsnPkgDlg
,
OnTabButton
);
88
89
if
(
wep_button
)
90
REGISTER_CLIENT
(
EID_CLICK
,
wep_button
,
MsnPkgDlg
,
OnTabButton
);
91
}
92
93
// +--------------------------------------------------------------------+
94
95
void
96
MsnPkgDlg::Show
()
97
{
98
FormWindow::Show
();
99
ShowMsnDlg
();
100
101
DrawPackages
();
102
DrawNavPlan
();
103
DrawThreats
();
104
}
105
106
// +--------------------------------------------------------------------+
107
108
void
109
MsnPkgDlg::DrawPackages
()
110
{
111
if
(
mission
) {
112
if
(
pkg_list
) {
113
pkg_list
->
ClearItems
();
114
115
int
i = 0;
116
int
elem_index = 0;
117
ListIter<MissionElement>
elem =
mission
->
GetElements
();
118
while
(++elem) {
119
// display this element?
120
if
(elem->
GetIFF
() ==
mission
->
Team
() &&
121
!elem->
IsSquadron
() &&
122
elem->
Region
() ==
mission
->
GetRegion
() &&
123
elem->
GetDesign
()->
type
<
Ship::STATION
) {
124
125
char
txt[256];
126
127
if
(elem->
Player
() > 0) {
128
sprintf_s(txt,
"==>"
);
129
if
(
pkg_index
< 0)
130
pkg_index
= elem_index;
131
}
132
else
{
133
strcpy_s(txt,
" "
);
134
}
135
136
pkg_list
->
AddItemWithData
(txt, elem->
ElementID
());
137
pkg_list
->
SetItemText
(i, 1, elem->
Name
());
138
pkg_list
->
SetItemText
(i, 2, elem->
RoleName
());
139
140
const
ShipDesign
* design = elem->
GetDesign
();
141
142
if
(elem->
Count
() > 1)
143
sprintf_s(txt,
"%d %s"
, elem->
Count
(), design->
abrv
);
144
else
145
sprintf_s(txt,
"%s %s"
, design->
abrv
, design->
name
);
146
pkg_list
->
SetItemText
(i, 3, txt);
147
148
i++;
149
}
150
151
elem_index++;
152
}
153
}
154
}
155
}
156
157
// +--------------------------------------------------------------------+
158
159
void
160
MsnPkgDlg::DrawNavPlan
()
161
{
162
if
(
mission
) {
163
if
(pkg_index < 0 || pkg_index >=
mission
->
GetElements
().
size
())
164
pkg_index
= 0;
165
166
MissionElement
* element =
mission
->
GetElements
()[
pkg_index
];
167
if
(
nav_list
&& element) {
168
nav_list
->
ClearItems
();
169
170
Point
loc = element->
Location
();
171
int
i = 0;
172
173
ListIter<Instruction>
navpt = element->
NavList
();
174
while
(++navpt) {
175
char
txt[256];
176
sprintf_s(txt,
"%d"
, i + 1);
177
178
nav_list
->
AddItem
(txt);
179
nav_list
->
SetItemText
(i, 1,
Instruction::ActionName
(navpt->
Action
()));
180
nav_list
->
SetItemText
(i, 2, navpt->
RegionName
());
181
182
double
dist =
Point
(loc - navpt->
Location
()).length();
183
FormatNumber
(txt, dist);
184
nav_list
->
SetItemText
(i, 3, txt);
185
186
sprintf_s(txt,
"%d"
, navpt->
Speed
());
187
nav_list
->
SetItemText
(i, 4, txt);
188
189
loc = navpt->
Location
();
190
i++;
191
}
192
}
193
}
194
}
195
196
// +--------------------------------------------------------------------+
197
198
void
199
MsnPkgDlg::DrawThreats
()
200
{
201
for
(
int
i = 0; i < 5; i++)
202
if
(
threat
[i])
203
threat
[i]->
SetText
(
""
);
204
205
if
(!
mission
)
return
;
206
207
MissionElement
* player =
mission
->
GetPlayer
();
208
209
if
(!player)
return
;
210
211
Text
rgn0 = player->
Region
();
212
Text
rgn1;
213
int
iff = player->
GetIFF
();
214
215
ListIter<Instruction>
nav = player->
NavList
();
216
while
(++nav) {
217
if
(rgn0 != nav->
RegionName
())
218
rgn1 = nav->
RegionName
();
219
}
220
221
if
(
threat
[0]) {
222
Point
base_loc =
mission
->
GetElements
()[0]->Location();
223
224
int
i = 0;
225
ListIter<MissionElement>
iter =
mission
->
GetElements
();
226
while
(++iter) {
227
MissionElement
* elem = iter.
value
();
228
229
if
(elem->
GetIFF
() == 0 || elem->
GetIFF
() == iff || elem->
IntelLevel
() <=
Intel::SECRET
)
230
continue
;
231
232
if
(elem->
IsSquadron
())
233
continue
;
234
235
if
(elem->
IsGroundUnit
()) {
236
if
(!elem->
GetDesign
() ||
237
elem->
GetDesign
()->
type
!=
Ship::SAM
)
238
continue
;
239
240
if
(elem->
Region
() != rgn0 &&
241
elem->
Region
() != rgn1)
242
continue
;
243
}
244
245
int
mission_role = elem->
MissionRole
();
246
247
if
(mission_role ==
Mission::STRIKE
||
248
mission_role ==
Mission::INTEL
||
249
mission_role >=
Mission::TRANSPORT
)
250
continue
;
251
252
char
rng[32];
253
char
role[32];
254
char
txt[256];
255
256
if
(mission_role ==
Mission::SWEEP
||
257
mission_role ==
Mission::INTERCEPT
||
258
mission_role ==
Mission::FLEET
||
259
mission_role ==
Mission::BOMBARDMENT
)
260
strcpy_s(role,
Game::GetText
(
"MsnDlg.ATTACK"
).data());
261
else
262
strcpy_s(role,
Game::GetText
(
"MsnDlg.PATROL"
).data());
263
264
double
dist =
Point
(base_loc - elem->
Location
()).length();
265
FormatNumber
(rng, dist);
266
267
sprintf_s(txt,
"%s - %d %s - %s"
, role,
268
elem->
Count
(),
269
elem->
GetDesign
()->
abrv
,
270
rng);
271
if
(
threat
[i])
272
threat
[i]->
SetText
(txt);
273
274
i++;
275
276
if
(i >= 5)
277
break
;
278
}
279
}
280
}
281
282
// +--------------------------------------------------------------------+
283
284
void
285
MsnPkgDlg::ExecFrame
()
286
{
287
if
(
Keyboard::KeyDown
(VK_RETURN)) {
288
OnCommit
(0);
289
}
290
}
291
292
// +--------------------------------------------------------------------+
293
294
void
295
MsnPkgDlg::OnPackage
(
AWEvent
* event)
296
{
297
if
(!
pkg_list
|| !
mission
)
298
return
;
299
300
int
seln =
pkg_list
->
GetListIndex
();
301
int
pkg =
pkg_list
->
GetItemData
(seln);
302
303
int
i = 0;
304
ListIter<MissionElement>
elem =
mission
->
GetElements
();
305
while
(++elem) {
306
if
(elem->
ElementID
() == pkg) {
307
pkg_index
= i;
308
//mission->SetPlayer(elem.value());
309
}
310
311
i++;
312
}
313
314
//DrawPackages();
315
DrawNavPlan
();
316
}
317
318
// +--------------------------------------------------------------------+
319
320
void
321
MsnPkgDlg::OnCommit
(
AWEvent
* event)
322
{
323
MsnDlg::OnCommit
(event);
324
}
325
326
void
327
MsnPkgDlg::OnCancel
(
AWEvent
* event)
328
{
329
MsnDlg::OnCancel
(event);
330
}
331
332
void
333
MsnPkgDlg::OnTabButton
(
AWEvent
* event)
334
{
335
MsnDlg::OnTabButton
(event);
336
}
Stars45
MsnPkgDlg.cpp
Generated on Tue Jun 5 2012 20:47:00 for Starshatter_Open by
1.8.1