From 8898ad9b25fca6afe2374d293a981db02a83d7e9 Mon Sep 17 00:00:00 2001 From: "FWoltermann@gmail.com" Date: Thu, 31 May 2012 14:46:27 +0000 Subject: Committing the documentation to svn to have it accessible online --- Doc/doxygen/html/_msn_elem_dlg_8cpp_source.html | 922 ++++++++++++++++++++++++ 1 file changed, 922 insertions(+) create mode 100644 Doc/doxygen/html/_msn_elem_dlg_8cpp_source.html (limited to 'Doc/doxygen/html/_msn_elem_dlg_8cpp_source.html') diff --git a/Doc/doxygen/html/_msn_elem_dlg_8cpp_source.html b/Doc/doxygen/html/_msn_elem_dlg_8cpp_source.html new file mode 100644 index 0000000..ef03586 --- /dev/null +++ b/Doc/doxygen/html/_msn_elem_dlg_8cpp_source.html @@ -0,0 +1,922 @@ + + + + + +Starshatter_Open: D:/SRC/StarshatterSVN/Stars45/MsnElemDlg.cpp Source File + + + + + + + + + + + + + +
+
+ + + + + + +
+
Starshatter_Open +
+
Open source Starshatter engine
+
+
+ + + + + +
+
+ +
+
+
+ +
+ + + + +
+ +
+ +
+
+
MsnElemDlg.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: MsnElemDlg.cpp
+
7  AUTHOR: John DiCamillo
+
8 
+
9 
+
10  OVERVIEW
+
11  ========
+
12  Mod Config Dialog Active Window class
+
13 */
+
14 
+
15 #include "MemDebug.h"
+
16 #include "MsnElemDlg.h"
+
17 #include "MsnEditDlg.h"
+
18 #include "MenuScreen.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 #include "Galaxy.h"
+
26 
+
27 #include "Game.h"
+
28 #include "DataLoader.h"
+
29 #include "Button.h"
+
30 #include "ListBox.h"
+
31 #include "EditBox.h"
+
32 #include "Video.h"
+
33 #include "Keyboard.h"
+
34 #include "Mouse.h"
+
35 #include "ParseUtil.h"
+
36 #include "Skin.h"
+
37 
+
38 // +--------------------------------------------------------------------+
+
39 // DECLARE MAPPING FUNCTIONS:
+
40 
+ + +
43 DEF_MAP_CLIENT(MsnElemDlg, OnClassSelect);
+
44 DEF_MAP_CLIENT(MsnElemDlg, OnDesignSelect);
+
45 DEF_MAP_CLIENT(MsnElemDlg, OnObjectiveSelect);
+
46 DEF_MAP_CLIENT(MsnElemDlg, OnIFFChange);
+
47 
+
48 // +--------------------------------------------------------------------+
+
49 
+ +
51 : FormWindow(s, 0, 0, s->Width(), s->Height()), manager(mgr),
+
52 btn_accept(0), btn_cancel(0), edt_name(0), cmb_class(0), cmb_design(0),
+
53 edt_size(0), edt_iff(0), cmb_role(0), cmb_region(0), cmb_skin(0),
+
54 edt_loc_x(0), edt_loc_y(0), edt_loc_z(0), cmb_heading(0), edt_hold_time(0),
+
55 btn_player(0), btn_playable(0), btn_alert(0), btn_command_ai(0),
+
56 edt_respawns(0), cmb_commander(0), cmb_carrier(0), cmb_squadron(0),
+
57 cmb_intel(0), cmb_loadout(0), cmb_objective(0), cmb_target(0),
+
58 mission(0), elem(0), exit_latch(true)
+
59 {
+
60  Init(def);
+
61 }
+
62 
+ +
64 {
+
65 }
+
66 
+
67 // +--------------------------------------------------------------------+
+
68 
+
69 void
+ +
71 {
+
72  btn_accept = (Button*) FindControl( 1);
+
73  if (btn_accept)
+ +
75 
+
76  btn_cancel = (Button*) FindControl( 2);
+
77  if (btn_accept)
+ +
79 
+
80  edt_name = (EditBox*) FindControl(201);
+
81  cmb_class = (ComboBox*) FindControl(202);
+ +
83  cmb_skin = (ComboBox*) FindControl(213);
+
84  edt_size = (EditBox*) FindControl(204);
+
85  edt_iff = (EditBox*) FindControl(205);
+
86  cmb_role = (ComboBox*) FindControl(206);
+ +
88  edt_loc_x = (EditBox*) FindControl(208);
+
89  edt_loc_y = (EditBox*) FindControl(209);
+
90  edt_loc_z = (EditBox*) FindControl(210);
+ + +
93 
+
94  btn_player = (Button*) FindControl(221);
+
95  btn_alert = (Button*) FindControl(222);
+ + + + +
100  cmb_carrier = (ComboBox*) FindControl(227);
+ +
102  cmb_intel = (ComboBox*) FindControl(229);
+
103  cmb_loadout = (ComboBox*) FindControl(230);
+ +
105  cmb_target = (ComboBox*) FindControl(232);
+
106 
+
107  if (cmb_class)
+ +
109 
+
110  if (cmb_design)
+ +
112 
+
113  if (cmb_objective)
+ +
115 
+
116  if (edt_iff)
+ +
118 }
+
119 
+
120 // +--------------------------------------------------------------------+
+
121 
+
122 void
+ +
124 {
+ +
126 
+
127  if (!elem) return;
+
128 
+
129  int current_class = 0;
+
130 
+
131  if (cmb_class) {
+ +
133 
+ + + +
137 
+ + + + + + + + + + + + + +
151 
+ + + + +
156 
+ + + + + + +
163 
+
164  const ShipDesign* design = elem->GetDesign();
+
165 
+
166  for (int i = 0; i < cmb_class->NumItems(); i++) {
+
167  const char* cname = cmb_class->GetItem(i);
+
168  int classid = Ship::ClassForName(cname);
+
169 
+
170  if (design && classid == design->type) {
+ +
172  current_class = classid;
+
173  break;
+
174  }
+
175  }
+
176  }
+
177 
+
178  if (cmb_design) {
+
179  OnClassSelect(0);
+
180  OnDesignSelect(0);
+
181  }
+
182 
+
183  if (cmb_role) {
+
184  cmb_role->ClearItems();
+
185 
+
186  for (int i = Mission::PATROL; i <= Mission::OTHER; i++) {
+ +
188 
+
189  if (i == 0)
+ +
191 
+
192  else if (elem->MissionRole() == i)
+ +
194  }
+
195  }
+
196 
+
197  if (cmb_region) {
+ +
199 
+
200  if (mission) {
+
201  StarSystem* sys = mission->GetStarSystem();
+
202  if (sys) {
+
203  List<OrbitalRegion> regions;
+
204  regions.append(sys->AllRegions());
+
205  regions.sort();
+
206 
+
207  ListIter<OrbitalRegion> iter = regions;
+
208  while (++iter) {
+
209  OrbitalRegion* region = iter.value();
+
210  cmb_region->AddItem(region->Name());
+
211 
+
212  if (!strcmp(elem->Region(), region->Name()))
+ +
214  }
+
215  }
+
216  }
+
217  }
+
218 
+
219  char buf[64];
+
220 
+
221  if (edt_name) edt_name->SetText(elem->Name());
+
222 
+
223  sprintf_s(buf, "%d", elem->Count());
+
224  if (edt_size) edt_size->SetText(buf);
+
225 
+
226  sprintf_s(buf, "%d", elem->GetIFF());
+
227  if (edt_iff) edt_iff->SetText(buf);
+
228 
+
229  sprintf_s(buf, "%d", (int) elem->Location().x / 1000);
+
230  if (edt_loc_x) edt_loc_x->SetText(buf);
+
231 
+
232  sprintf_s(buf, "%d", (int) elem->Location().y / 1000);
+
233  if (edt_loc_y) edt_loc_y->SetText(buf);
+
234 
+
235  sprintf_s(buf, "%d", (int) elem->Location().z / 1000);
+
236  if (edt_loc_z) edt_loc_z->SetText(buf);
+
237 
+
238  sprintf_s(buf, "%d", elem->RespawnCount());
+
239  if (edt_respawns) edt_respawns->SetText(buf);
+
240 
+
241  sprintf_s(buf, "%d", elem->HoldTime());
+ +
243 
+
244  if (btn_player) btn_player->SetButtonState(elem->Player() > 0 ? 1 : 0);
+ +
246  if (btn_alert) btn_alert->SetButtonState(elem->IsAlert() ? 1 : 0);
+ +
248 
+
249  UpdateTeamInfo();
+
250 
+
251  if (cmb_intel) {
+ +
253 
+
254  for (int i = Intel::RESERVE; i < Intel::TRACKED; i++) {
+ +
256 
+
257  if (i == 0)
+ +
259 
+
260  else if (elem->IntelLevel() == i)
+ +
262  }
+
263  }
+
264 
+
265  Instruction* instr = 0;
+
266  if (elem->Objectives().size() > 0)
+
267  instr = elem->Objectives().at(0);
+
268 
+
269  if (cmb_objective) {
+ +
271  cmb_objective->AddItem("");
+ +
273 
+
274  for (int i = 0; i < Instruction::NUM_ACTIONS; i++) {
+ +
276 
+
277  if (instr && instr->Action() == i)
+ +
279  }
+
280  }
+
281 
+
282  if (cmb_target) {
+ +
284  }
+
285 
+
286  if (cmb_heading) {
+
287  double heading = elem->Heading();
+
288 
+
289  while (heading > 2*PI)
+
290  heading -= 2*PI;
+
291 
+
292  while (heading < 0)
+
293  heading += 2*PI;
+
294 
+
295  if (heading >= PI/4 && heading < 3*PI/4)
+ +
297 
+
298  else if (heading >= 3*PI/4 && heading < 5*PI/4)
+ +
300 
+
301  else if (heading >= 5*PI/4 && heading < 7*PI/4)
+ +
303 
+
304  else
+ +
306  }
+
307 
+
308  exit_latch = true;
+
309 }
+
310 
+
311 // +--------------------------------------------------------------------+
+
312 
+
313 void
+ +
315 {
+
316  if (Keyboard::KeyDown(VK_RETURN)) {
+ +
318  OnAccept(0);
+
319  }
+
320 
+
321  else if (Keyboard::KeyDown(VK_ESCAPE)) {
+
322  if (!exit_latch)
+
323  OnCancel(0);
+
324  }
+
325 
+
326  else {
+
327  exit_latch = false;
+
328  }
+
329 }
+
330 
+
331 // +--------------------------------------------------------------------+
+
332 
+
333 void
+ +
335 {
+
336  mission = m;
+
337 }
+
338 
+
339 void
+ +
341 {
+
342  elem = e;
+
343 }
+
344 
+
345 // +--------------------------------------------------------------------+
+
346 
+
347 void
+ +
349 {
+
350  if (cmb_commander) {
+ +
352  cmb_commander->AddItem("");
+ +
354 
+
355  if (mission && elem) {
+ +
357  while (++iter) {
+
358  MissionElement* e = iter.value();
+
359 
+
360  if (CanCommand(e, elem)) {
+
361  cmb_commander->AddItem(e->Name());
+
362 
+
363  if (elem->Commander() == e->Name())
+ +
365  }
+
366  }
+
367  }
+
368  }
+
369 
+
370  if (cmb_squadron) {
+ +
372  cmb_squadron->AddItem("");
+ +
374 
+
375  if (mission && elem) {
+ +
377  while (++iter) {
+
378  MissionElement* e = iter.value();
+
379 
+
380  if (e->GetIFF() == elem->GetIFF() && e != elem && e->IsSquadron()) {
+
381  cmb_squadron->AddItem(e->Name());
+
382 
+
383  if (elem->Squadron() == e->Name())
+ +
385  }
+
386  }
+
387  }
+
388  }
+
389 
+
390  if (cmb_carrier) {
+ +
392  cmb_carrier->AddItem("");
+ +
394 
+
395  if (mission && elem) {
+ +
397  while (++iter) {
+
398  MissionElement* e = iter.value();
+
399 
+
400  if (e->GetIFF() == elem->GetIFF() && e != elem && e->GetDesign() && e->GetDesign()->flight_decks.size()) {
+
401  cmb_carrier->AddItem(e->Name());
+
402 
+
403  if (elem->Carrier() == e->Name())
+ +
405  }
+
406  }
+
407  }
+
408  }
+
409 }
+
410 
+
411 // +--------------------------------------------------------------------+
+
412 
+
413 void
+ +
415 {
+
416  if (!cmb_class || !cmb_design) return;
+
417 
+
418  const char* cname = cmb_class->GetSelectedItem();
+
419  int classid = Ship::ClassForName(cname);
+
420 
+ +
422 
+
423  List<Text> designs;
+
424  ShipDesign::GetDesignList(classid, designs);
+
425 
+
426  if (designs.size() > 0) {
+
427  const ShipDesign* design = elem->GetDesign();
+
428  bool found = false;
+
429 
+
430  for (int i = 0; i < designs.size(); i++) {
+
431  const char* dsn = designs[i]->data();
+
432  cmb_design->AddItem(dsn);
+
433 
+
434  if (design && !_stricmp(dsn, design->name)) {
+ +
436  found = true;
+
437  }
+
438  }
+
439 
+
440  if (!found)
+ +
442  }
+
443  else {
+
444  cmb_design->AddItem("");
+ +
446  }
+
447 
+
448  OnDesignSelect(0);
+
449 }
+
450 
+
451 // +--------------------------------------------------------------------+
+
452 
+
453 void
+ +
455 {
+
456  if (!cmb_design) return;
+
457 
+
458  ShipDesign* design = 0;
+
459 
+
460  const char* dname = cmb_design->GetSelectedItem();
+
461  int load_index = 0;
+
462 
+
463  if (dname)
+
464  design = ShipDesign::Get(dname);
+
465 
+
466  if (cmb_loadout) {
+ +
468 
+
469  if (design) {
+
470  MissionLoad* mload = 0;
+
471 
+
472  if (elem && elem->Loadouts().size() > 0)
+
473  mload = elem->Loadouts().at(0);
+
474 
+
475  const List<ShipLoad>& loadouts = design->loadouts;
+
476 
+
477  if (loadouts.size() > 0) {
+
478  for (int i = 0; i < loadouts.size(); i++) {
+
479  const ShipLoad* load = loadouts[i];
+
480  if (load->name[0]) {
+
481  cmb_loadout->AddItem(load->name);
+
482 
+
483  if (mload && mload->GetName() == load->name) {
+
484  load_index = cmb_loadout->NumItems()-1;
+
485  }
+
486  }
+
487  }
+
488  }
+
489  }
+
490 
+
491  if (cmb_loadout->NumItems() < 1)
+
492  cmb_loadout->AddItem("");
+
493 
+
494  cmb_loadout->SetSelection(load_index);
+
495  }
+
496 
+
497  if (cmb_skin) {
+
498  cmb_skin->ClearItems();
+
499 
+
500  if (design) {
+
501  cmb_skin->AddItem(Game::GetText("MsnDlg.default"));
+ +
503 
+
504  ListIter<Skin> iter = design->skins;
+
505 
+
506  while (++iter) {
+
507  Skin* s = iter.value();
+
508  cmb_skin->AddItem(s->Name());
+
509 
+
510  if (elem && elem->GetSkin() && !strcmp(s->Name(), elem->GetSkin()->Name())) {
+ +
512  }
+
513  }
+
514  }
+
515  }
+
516 }
+
517 
+
518 // +--------------------------------------------------------------------+
+
519 
+
520 void
+ +
522 {
+
523  if (!cmb_objective || !cmb_target) return;
+
524 
+
525  Instruction* instr = 0;
+
526  if (elem->Objectives().size() > 0)
+
527  instr = elem->Objectives().at(0);
+
528 
+
529  int objid = cmb_objective->GetSelectedIndex() - 1;
+
530 
+ +
532  cmb_target->AddItem("");
+
533 
+
534  if (mission) {
+ +
536  while (++iter) {
+
537  MissionElement* e = iter.value();
+
538 
+
539  if (e != elem) {
+
540  bool add = false;
+
541 
+
542  if (objid < Instruction::PATROL)
+
543  add = e->GetIFF() == 0 || e->GetIFF() == elem->GetIFF();
+
544  else
+
545  add = e->GetIFF() != elem->GetIFF();
+
546 
+
547  if (add) {
+
548  cmb_target->AddItem(e->Name());
+
549 
+
550  if (instr && !_stricmp(instr->TargetName(), e->Name()))
+ +
552  }
+
553  }
+
554  }
+
555  }
+
556 }
+
557 
+
558 // +--------------------------------------------------------------------+
+
559 
+
560 void
+ +
562 {
+
563  if (edt_iff && elem) {
+
564  int elem_iff = 0;
+
565  sscanf_s(edt_iff->GetText().data(), "%d", &elem_iff);
+
566 
+
567  if (elem->GetIFF() == elem_iff)
+
568  return;
+
569 
+
570  elem->SetIFF(elem_iff);
+
571  }
+
572 
+
573  UpdateTeamInfo();
+
574 
+
575  if (cmb_target)
+ +
577 }
+
578 
+
579 // +--------------------------------------------------------------------+
+
580 
+
581 void
+ +
583 {
+
584  if (mission && elem) {
+
585  char buf[64];
+
586  int val;
+
587 
+
588  if (edt_name) {
+ +
590  }
+
591 
+
592  if (edt_size) {
+
593  strcpy_s(buf, edt_size->GetText());
+
594 
+
595  if (isdigit(*buf))
+
596  sscanf_s(buf, "%d", &val);
+
597  else
+
598  val = 1;
+
599 
+
600  elem->SetCount(val);
+
601  }
+
602 
+
603  if (edt_iff) {
+
604  strcpy_s(buf, edt_iff->GetText());
+
605 
+
606  if (isdigit(*buf))
+
607  sscanf_s(buf, "%d", &val);
+
608  else
+
609  val = 1;
+
610 
+
611  elem->SetIFF(val);
+
612  }
+
613 
+
614  if (edt_loc_x && edt_loc_y && edt_loc_z) {
+
615  Point loc;
+
616 
+
617  strcpy_s(buf, edt_loc_x->GetText());
+
618 
+
619  if (isdigit(*buf) || *buf == '-')
+
620  sscanf_s(buf, "%d", &val);
+
621  else
+
622  val = 0;
+
623 
+
624  loc.x = val * 1000;
+
625 
+
626  strcpy_s(buf, edt_loc_y->GetText());
+
627 
+
628  if (isdigit(*buf) || *buf == '-')
+
629  sscanf_s(buf, "%d", &val);
+
630  else
+
631  val = 0;
+
632 
+
633  loc.y = val * 1000;
+
634 
+
635  strcpy_s(buf, edt_loc_z->GetText());
+
636 
+
637  if (isdigit(*buf) || *buf == '-')
+
638  sscanf_s(buf, "%d", &val);
+
639  else
+
640  val = 0;
+
641 
+
642  loc.z = val * 1000;
+
643 
+
644  elem->SetLocation(loc);
+
645  }
+
646 
+
647  if (edt_respawns) {
+
648  strcpy_s(buf, edt_respawns->GetText());
+
649 
+
650  if (isdigit(*buf))
+
651  sscanf_s(buf, "%d", &val);
+
652  else
+
653  val = 0;
+
654 
+
655  elem->SetRespawnCount(val);
+
656  }
+
657 
+
658  if (edt_hold_time) {
+
659  strcpy_s(buf, edt_hold_time->GetText());
+
660 
+
661  if (isdigit(*buf))
+
662  sscanf_s(buf, "%d", &val);
+
663  else
+
664  val = 0;
+
665 
+
666  elem->SetHoldTime(val);
+
667  }
+
668 
+
669  if (btn_player) {
+
670  if (btn_player->GetButtonState() > 0) {
+ +
672  }
+
673  else {
+
674  elem->SetPlayer(0);
+
675  }
+
676  }
+
677 
+
678  if (btn_playable)
+
679  elem->SetPlayable(btn_playable->GetButtonState() ? true : false);
+
680 
+
681  if (btn_alert)
+
682  elem->SetAlert(btn_alert->GetButtonState() ? true : false);
+
683 
+
684  if (btn_command_ai)
+ +
686 
+
687  if (cmb_design) {
+ +
689 
+
690  if (d) {
+
691  elem->SetDesign(d);
+
692 
+
693  if (cmb_skin) {
+
694  const char* skin_name = cmb_skin->GetSelectedItem();
+
695 
+
696  if (strcmp(skin_name, Game::GetText("MsnDlg.default").data())) {
+
697  elem->SetSkin(d->FindSkin(skin_name));
+
698  }
+
699  else {
+
700  elem->SetSkin(0);
+
701  }
+
702  }
+
703  }
+
704  }
+
705 
+
706  if (cmb_role) {
+ +
708  }
+
709 
+
710  if (cmb_region) {
+ +
712 
+
713  if (elem->Player() > 0) {
+ +
715  }
+
716  }
+
717 
+
718  if (cmb_heading) {
+
719  switch (cmb_heading->GetSelectedIndex()) {
+
720  default:
+
721  case 0: elem->SetHeading(0); break;
+
722  case 1: elem->SetHeading(PI/2); break;
+
723  case 2: elem->SetHeading(PI); break;
+
724  case 3: elem->SetHeading(3*PI/2); break;
+
725  }
+
726  }
+
727 
+
728  if (cmb_commander) {
+ +
730  }
+
731 
+
732  if (cmb_squadron) {
+ +
734  }
+
735 
+
736  if (cmb_carrier) {
+ +
738  }
+
739 
+
740  if (cmb_intel) {
+ +
742  }
+
743 
+
744  if (cmb_loadout && cmb_loadout->NumItems()) {
+
745  elem->Loadouts().destroy();
+
746 
+
747  const char* loadname = cmb_loadout->GetSelectedItem();
+
748  if (loadname && *loadname) {
+
749  MissionLoad* mload = new(__FILE__,__LINE__) MissionLoad(-1, cmb_loadout->GetSelectedItem());
+
750  elem->Loadouts().append(mload);
+
751  }
+
752  }
+
753 
+
754  if (cmb_objective && cmb_target) {
+
755  List<Instruction>& objectives = elem->Objectives();
+
756  objectives.destroy();
+
757 
+
758  int action = cmb_objective->GetSelectedIndex() - 1;
+
759  const char* target = cmb_target->GetSelectedItem();
+
760 
+
761  if (action >= Instruction::VECTOR) {
+
762  Instruction* obj = new(__FILE__,__LINE__) Instruction(action, target);
+
763  objectives.append(obj);
+
764  }
+
765  }
+
766 
+
767  if (elem->Player()) {
+
768  mission->SetTeam(elem->GetIFF());
+
769  }
+
770  }
+
771 
+ +
773 }
+
774 
+
775 void
+ +
777 {
+ +
779 }
+
780 
+
781 bool
+ +
783 const MissionElement* subordinate) const
+
784 {
+
785  if (mission && commander && subordinate && commander != subordinate) {
+
786  if (commander->GetIFF() != subordinate->GetIFF())
+
787  return false;
+
788 
+
789  if (commander->IsSquadron())
+
790  return false;
+
791 
+
792  if (commander->Commander().length() == 0)
+
793  return true;
+
794 
+
795  if (subordinate->Name() == commander->Commander())
+
796  return false;
+
797 
+
798  MissionElement* elem = mission->FindElement(commander->Commander());
+
799 
+
800  if (elem)
+
801  return CanCommand(elem, subordinate);
+
802  }
+
803 
+
804  return false;
+
805 }
+
+
+ + + + -- cgit v1.1