Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DebriefDlg.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: DebriefDlg.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Mission Debriefing Dialog Active Window class
13 */
14 
15 #include "MemDebug.h"
16 #include "DebriefDlg.h"
17 #include "PlanScreen.h"
18 #include "Starshatter.h"
19 #include "Campaign.h"
20 #include "Element.h"
21 #include "Instruction.h"
22 #include "Mission.h"
23 #include "Sim.h"
24 #include "SimEvent.h"
25 #include "Ship.h"
26 #include "ShipDesign.h"
27 #include "StarSystem.h"
28 #include "FormatUtil.h"
29 #include "Player.h"
30 #include "Campaign.h"
31 
32 #include "NetLobby.h"
33 #include "HttpServer.h"
34 
35 #include "Game.h"
36 #include "Keyboard.h"
37 #include "Mouse.h"
38 #include "Button.h"
39 #include "ListBox.h"
40 #include "Slider.h"
41 #include "ParseUtil.h"
42 
43 // +--------------------------------------------------------------------+
44 // DECLARE MAPPING FUNCTIONS:
45 
46 DEF_MAP_CLIENT(DebriefDlg, OnClose);
47 DEF_MAP_CLIENT(DebriefDlg, OnUnit);
48 
49 // +--------------------------------------------------------------------+
50 
52 : FormWindow(s, 0, 0, s->Width(), s->Height()), manager(mgr),
53 close_btn(0), campaign(0), mission(0),
54 unit_index(0), info(0), sim(0), ship(0)
55 {
57 
58  if (campaign)
60 
61  Init(def);
62 }
63 
65 {
66 }
67 
68 // +--------------------------------------------------------------------+
69 
70 void
72 {
77 
78  objectives = FindControl(210);
79  situation = FindControl(240);
81  unit_list = (ListBox*) FindControl(320);
83  event_list = (ListBox*) FindControl(340);
84 
85  if (unit_list)
87 
89 
90  if (close_btn)
92 }
93 
94 // +--------------------------------------------------------------------+
95 
96 void
98 {
101 
102  mission = 0;
104  sim = Sim::GetSim();
105 
106  if (sim)
107  ship = sim->GetPlayerShip();
108 
109  if (campaign)
111 
112  if (mission_name) {
113  if (mission)
115  else
116  mission_name->SetText(Game::GetText("DebriefDlg.mission-name"));
117  }
118 
119  if (mission_system) {
120  mission_system->SetText("");
121 
122  if (mission) {
123  StarSystem* sys = mission->GetStarSystem();
124 
125  if (sys)
126  mission_system->SetText(sys->Name());
127  }
128  }
129 
130  if (mission_sector) {
131  mission_sector->SetText("");
132 
133  if (mission) {
134  MissionElement* elem = mission->GetElements()[0];
135 
136  if (elem)
137  mission_sector->SetText(elem->Region());
138  }
139  }
140 
141  if (mission_time_start) {
142  if (mission) {
143  char txt[32];
144  FormatDayTime(txt, mission->Start());
146  }
147  }
148 
149  if (objectives) {
150  bool found_objectives = false;
151 
152  if (sim && sim->GetPlayerElement()) {
153  Text text;
154  Element* elem = sim->GetPlayerElement();
155 
156  for (int i = 0; i < elem->NumObjectives(); i++) {
157  Instruction* obj = elem->GetObjective(i);
158  text += Text("* ") + obj->GetDescription() + Text("\n");
159 
160  found_objectives = true;
161  }
162 
163  objectives->SetText(text);
164  }
165 
166  if (!found_objectives) {
167  if (mission)
169  else
170  objectives->SetText(Game::GetText("DebriefDlg.unspecified"));
171  }
172  }
173 
174  if (situation) {
175  if (mission)
177  else
178  situation->SetText(Game::GetText("DebriefDlg.unknown"));
179  }
180 
181  if (mission_score) {
182  mission_score->SetText(Game::GetText("DebriefDlg.no-stats"));
183 
184  if (ship) {
185  for (int i = 0; i < ShipStats::NumStats(); i++) {
186  ShipStats* stats = ShipStats::GetStats(i);
187  if (stats && !strcmp(ship->Name(), stats->GetName())) {
188  stats->Summarize();
189 
190  Player* player = Player::GetCurrentPlayer();
191  int points = stats->GetPoints() + stats->GetCommandPoints();
192 
193  if (player && sim)
194  points = player->GetMissionPoints(stats, sim->StartTime()) + stats->GetCommandPoints();
195 
196  char score[32];
197  sprintf_s(score, "%d %s", points, Game::GetText("DebriefDlg.points").data());
198  mission_score->SetText(score);
199  break;
200  }
201  }
202  }
203  }
204 
205  DrawUnits();
206 }
207 
208 // +--------------------------------------------------------------------+
209 
210 void
212 {
213  if (mission) {
214  if (unit_list) {
216 
217  int seln = -1;
218  bool netgame = false;
219 
220  if (sim && sim->IsNetGame())
221  netgame = true;
222 
223  for (int i = 0; i < ShipStats::NumStats(); i++) {
224  ShipStats* stats = ShipStats::GetStats(i);
225  stats->Summarize();
226 
227  if (netgame || (stats->GetIFF() == mission->Team() &&
228  !strcmp(stats->GetRegion(), mission->GetRegion()))) {
229  int n = unit_list->AddItemWithData(" ", i) - 1;
230  unit_list->SetItemText(n, 1, stats->GetName());
231  unit_list->SetItemText(n, 2, stats->GetRole());
232  unit_list->SetItemText(n, 3, stats->GetType());
233 
234  if (ship && !strcmp(ship->Name(), stats->GetName()))
235  seln = n;
236  }
237  }
238 
239  if (seln >= 0) {
240  unit_list->SetSelected(seln);
241  OnUnit(0);
242  }
243  }
244  }
245 }
246 
247 // +--------------------------------------------------------------------+
248 
249 void
251 {
252  if (unit_list && unit_list->NumItems() && unit_list->GetSelCount() < 1) {
254  OnUnit(0);
255  }
256 
257  if (Keyboard::KeyDown(VK_RETURN)) {
258  OnClose(0);
259  }
260 }
261 
262 // +--------------------------------------------------------------------+
263 
264 void
266 {
267  if (!unit_list || !event_list || !summary_list)
268  return;
269 
272 
273  int seln = unit_list->GetSelection();
274  int unit = unit_list->GetItemData(seln);
275 
276  ShipStats* stats = ShipStats::GetStats(unit);
277  if (stats) {
278  stats->Summarize();
279 
280  char txt[64];
281  int i = 0;
282 
283  sprintf_s(txt, "%d", stats->GetGunShots());
284  summary_list->AddItem("Guns Fired: ");
285  summary_list->SetItemText(i++, 1, txt);
286 
287  sprintf_s(txt, "%d", stats->GetGunHits());
288  summary_list->AddItem("Gun Hits: ");
289  summary_list->SetItemText(i++, 1, txt);
290 
291  sprintf_s(txt, "%d", stats->GetGunKills());
292  summary_list->AddItem("Gun Kills: ");
293  summary_list->SetItemText(i++, 1, txt);
294 
295  // one line spacer:
296  summary_list->AddItem(" ");
297  i++;
298 
299  sprintf_s(txt, "%d", stats->GetMissileShots());
300  summary_list->AddItem("Missiles Fired: ");
301  summary_list->SetItemText(i++, 1, txt);
302 
303  sprintf_s(txt, "%d", stats->GetMissileHits());
304  summary_list->AddItem("Missile Hits: ");
305  summary_list->SetItemText(i++, 1, txt);
306 
307  sprintf_s(txt, "%d", stats->GetMissileKills());
308  summary_list->AddItem("Missile Kills: ");
309  summary_list->SetItemText(i++, 1, txt);
310 
311  i = 0;
312  ListIter<SimEvent> iter = stats->GetEvents();
313  while (++iter) {
314  SimEvent* event = iter.value();
315 
316  char txt[64];
317  int time = event->GetTime();
318 
319  if (time > 24 * 60 * 60)
320  FormatDayTime(txt, time);
321  else
322  FormatTime(txt, time);
323 
324  event_list->AddItem(txt);
325  event_list->SetItemText(i, 1, event->GetEventDesc());
326 
327  if (event->GetTarget())
328  event_list->SetItemText(i, 2, event->GetTarget());
329 
330  i++;
331  }
332  }
333 }
334 
335 // +--------------------------------------------------------------------+
336 
337 void
339 {
340  Sim* sim = Sim::GetSim();
341 
342  sim->CommitMission();
343  sim->UnloadMission();
344 
345  NetLobby* lobby = NetLobby::GetInstance();
346  if (lobby && lobby->IsHost()) {
347  lobby->SelectMission(0);
348  lobby->ExecFrame();
349  }
350 
351  Player* player = Player::GetCurrentPlayer();
352  if (player && player->ShowAward()) {
354  }
355 
356  else {
358 
359  if (stars) {
360  Mouse::Show(false);
361 
363  if (campaign && campaign->GetCampaignId() < Campaign::SINGLE_MISSIONS)
365  else
367  }
368 
369  else {
370  Game::Panic("DebriefDlg::OnClose() - Game instance not found");
371  }
372  }
373 }