2 * $Logfile: /Freespace2/code/fred2/wing_editor.cpp $
7 * Wing editor dialog box handler code
10 * Revision 1.1 2002/05/03 03:28:09 root
14 * 3 8/16/99 10:52p Andsager
15 * Allow closer ship positioning for NEAR_SHIP ship and wing arrivals.
17 * 2 10/07/98 6:28p Dave
18 * Initial checkin. Renamed all relevant stuff to be Fred2 instead of
19 * Fred. Globalized mission and campaign file extensions. Removed Silent
20 * Threat specific code.
22 * 1 10/07/98 3:02p Dave
24 * 1 10/07/98 3:00p Dave
26 * 83 9/14/98 3:31p Allender
27 * don't allow alpha, beta, and gamma to get > 1 wave when editing a
28 * multiplayer missions
30 * 82 6/17/98 4:50p Hoffoss
31 * Added error checking for arrival delays used on wing player is in.
33 * 81 5/22/98 10:10a Hoffoss
34 * Fixed bug with hide cue button not working correctly.
36 * 80 3/24/98 12:30p Allender
37 * arrival/departure target boxes were getting initialized incorrectly
39 * 79 3/21/98 7:36p Lawrance
40 * Move jump nodes to own lib.
42 * 78 3/16/98 8:27p Allender
43 * Fred support for two new AI flags -- kamikaze and no dynamic goals.
45 * 77 3/10/98 6:11p Hoffoss
46 * Added jump node renaming abilities to Fred.
48 * 76 2/23/98 9:48p Allender
49 * added no arrival/departure warps to wings
51 * 75 12/31/97 3:56p Hoffoss
52 * Forced alpha wing to always have a true arrival cue.
54 * 74 12/29/97 4:55p Johnson
57 * 73 12/18/97 10:40a Hoffoss
58 * Fixed bug with a few of the checkboxes not initializing properly.
60 * 72 11/25/97 10:03a Allender
61 * added no arrival message checkbox to wing editor
63 * 71 11/25/97 9:42a Hoffoss
64 * Removed starting wing checkbox from wing editor.
66 * 70 11/13/97 4:14p Allender
67 * automatic assignment of hotkeys for starting wings. Appripriate
68 * warnings when they are incorrectly used. hotkeys correctly assigned to
69 * ships/wing arriving after mission start
71 * 69 11/11/97 2:13p Allender
72 * docking bay support for Fred and Freespace. Added hook to ai code for
73 * arrival/departure from dock bays. Fred support now sufficient.
75 * 68 11/10/97 10:13p Allender
76 * added departure anchor to Fred and Freespace in preparation for using
77 * docking bays. Functional in Fred, not in FreeSpace.
79 * 67 10/28/97 3:33p Hoffoss
80 * Fixed bug where <1 num_waves was being allowed to be entered into Fred.
82 * 66 10/14/97 5:33p Hoffoss
83 * Added Fred support (and fsm support) for the no_arrival_music flags in
86 * 65 10/01/97 12:37p Hoffoss
87 * Changed Fred (and FreeSpace) to utilize alpha, beta and gamma as player
88 * starting wing names.
90 * 64 9/04/97 5:35p Hoffoss
91 * Fixed arrival distance stuff.
93 * 63 9/04/97 5:04p Johnson
94 * Fixed bug with arrival target distance checking.
96 * 62 9/04/97 4:30p Hoffoss
97 * Removed sexp tree info from grayed trees.
99 * 61 8/30/97 9:52p Hoffoss
100 * Implemented arrival location, distance, and anchor in Fred.
102 * 60 8/22/97 4:16p Hoffoss
103 * added support for arrival and departure info in ship editor using
104 * wing's info if editing marked ships in a wing instead of using ship's.
106 * 59 8/21/97 3:20p Duncan
107 * Fixed bug in wing renaming when a player is in the wing.
109 * 58 8/19/97 1:44p Hoffoss
110 * Fixed bug with updating too quickly (i.e. via prev and next buttons).
112 * 57 8/15/97 5:14p Hoffoss
113 * Completely changed around how initial orders dialog worked. It's
114 * pretty awesome now.
116 * 56 8/15/97 11:24a Hoffoss
117 * Changed order of events.
119 * 55 8/13/97 11:31p Hoffoss
120 * Added bound checking on min/max wave delay.
122 * 54 8/13/97 11:22p Hoffoss
123 * Implemented wave delay min and max in Fred.
125 * 53 8/12/97 7:17p Hoffoss
126 * Added previous button to ship and wing editors.
128 * 52 8/12/97 6:32p Hoffoss
129 * Added code to allow hiding of arrival and departure cues in editors.
131 * 51 8/12/97 3:33p Hoffoss
132 * Fixed the "press cancel to go to reference" code to work properly.
134 * 50 8/12/97 1:55a Hoffoss
135 * Made extensive changes to object reference checking and handling for
136 * object deletion call.
138 * 49 8/10/97 4:22p Hoffoss
139 * Made main display update when ships or wings are renamed.
141 * 48 8/08/97 10:00a Hoffoss
142 * Added protection from threshold being equal or higher than the number
143 * of ships in a wing.
145 * 47 8/01/97 2:45p Hoffoss
146 * Fixed bug with no new item in MFC CTreeCtrl selection changed message.
147 * Throught it shouldn't happen, but Whiteside made it happen.
149 * 46 7/30/97 5:23p Hoffoss
150 * Removed Sexp tree verification code, since it duplicates normal sexp
151 * verification, and is just another set of code to keep maintained.
153 * 45 7/30/97 12:31p Hoffoss
154 * Made improvements to ship goals editor (initial orders) to disallow
157 * 44 7/28/97 2:28p Hoffoss
158 * Added bypasses to MFC integer validation routines.
160 * 43 7/25/97 2:40p Hoffoss
161 * Fixed bug in sexp tree selection updating handling.
163 * 42 7/24/97 4:44p Hoffoss
164 * Added sexp help to more dialogs, and changed made some changes to make
165 * it work correctly for ship and wing editors.
167 * 41 7/18/97 2:05p Hoffoss
168 * Fixed some bugs BoundsChecker turned up.
170 * 40 7/16/97 6:30p Hoffoss
171 * Added icons to sexp trees, mainly because I think they will be required
174 * 39 7/09/97 2:38p Allender
175 * organized ship/wing editor dialogs. Added protect ship and ignore
176 * count checkboxes to those dialogs. Changed flag code for
177 * parse_objects. Added unprotect sexpressions
179 * 38 7/08/97 10:15a Allender
180 * making ships/wings reinforcements now do not set the arrival cue to
181 * false. A reinforcement may only be available after it's arrival cue is
184 * 37 7/02/97 3:30p Hoffoss
185 * Put in code to validate and bash if necessary the wing wave threshold.
187 * 36 6/18/97 3:07p Hoffoss
188 * Wing ship names are 1 indexes instead of 0 indexed now.
190 * 35 6/05/97 6:10p Hoffoss
191 * Added features: Autosaving, object hiding. Also fixed some minor bugs.
193 * 34 5/30/97 11:33a Allender
194 * more hotkey combo box stuff
196 * 33 5/23/97 1:53p Hoffoss
197 * Fixed problems with modeless dialog updating. It won't get caught in
198 * an infinate loop anymore, but still gives an error warning 3 times when
199 * using cancel and trying to switch window focus to main window. Don't
200 * know if I can fix that, but it's not too critical right now.
202 * 32 5/01/97 4:15p Hoffoss
205 * 31 4/28/97 2:37p Hoffoss
206 * Added hotkey editing to Fred for ships and wings.
208 * 30 4/23/97 11:55a Hoffoss
209 * Fixed many bugs uncovered while trying to create Mission 6.
211 * 29 4/07/97 1:53p Hoffoss
212 * Fixed a few bugs, and added sexp chain duplicating for object
215 * 28 4/03/97 11:35a Hoffoss
216 * Fixed bugs: viewpoint didn't reset, initial orders not updated when
217 * referenced ship is renamed or deleted.
219 * 27 4/01/97 5:15p Hoffoss
220 * Fixed errors in max length checks, renaming a wing now renames the
221 * ships in the wing as well, as it should.
223 * 26 3/20/97 3:55p Hoffoss
224 * Major changes to how dialog boxes initialize (load) and update (save)
225 * their internal data. This should simplify things and create less
228 * 25 3/17/97 4:29p Hoffoss
229 * Automated player's wing flaging as a starting player wing.
231 * 24 3/05/97 10:54a Hoffoss
232 * removed special arrival/departure cue token usage in wing editor.
234 * 23 2/28/97 11:31a Hoffoss
235 * Implemented modeless dialog saving and restoring, and changed some
238 * 22 2/27/97 3:16p Allender
239 * major wing structure enhancement. simplified wing code. All around
240 * better wing support
242 * 21 2/24/97 5:38p Hoffoss
243 * Added dialog box to name a wing at creation, code to change ship names
244 * to match wing name, and code to maintain these ship names.
246 * 20 2/21/97 5:34p Hoffoss
247 * Added extensive modification detection and fixed a bug in initial
250 * 19 2/20/97 4:03p Hoffoss
251 * Several ToDo items: new reinforcement clears arrival cue, reinforcement
252 * control from ship and wing dialogs, show grid toggle.
254 * 18 2/17/97 5:28p Hoffoss
255 * Checked RCS headers, added them were missing, changing description to
256 * something better, etc where needed.
265 #include "management.h"
267 #include "linklist.h"
269 #include "fredview.h"
270 #include "starfield.h"
271 #include "jumpnode.h"
273 #define ID_WING_MENU 9000
276 #define new DEBUG_NEW
278 static char THIS_FILE[] = __FILE__;
281 /////////////////////////////////////////////////////////////////////////////
282 // wing_editor dialog
284 wing_editor::wing_editor(CWnd* pParent /*=NULL*/)
285 : CDialog(wing_editor::IDD, pParent)
287 //{{AFX_DATA_INIT(wing_editor)
288 m_wing_name = _T("");
292 m_arrival_location = -1;
293 m_departure_location = -1;
295 m_departure_delay = 0;
296 m_reinforcement = FALSE;
298 m_ignore_count = FALSE;
299 m_arrival_delay_max = 0;
300 m_arrival_delay_min = 0;
302 m_arrival_target = -1;
303 m_no_arrival_music = FALSE;
304 m_departure_target = -1;
305 m_no_arrival_message = FALSE;
306 m_no_arrival_warp = FALSE;
307 m_no_departure_warp = FALSE;
308 m_no_dynamic = FALSE;
311 select_sexp_node = -1;
315 void wing_editor::DoDataExchange(CDataExchange* pDX)
319 CDialog::DoDataExchange(pDX);
320 //{{AFX_DATA_MAP(wing_editor)
321 DDX_Control(pDX, IDC_DEPARTURE_DELAY_SPIN, m_departure_delay_spin);
322 DDX_Control(pDX, IDC_ARRIVAL_DELAY_SPIN, m_arrival_delay_spin);
323 DDX_Control(pDX, IDC_DEPARTURE_TREE, m_departure_tree);
324 DDX_Control(pDX, IDC_ARRIVAL_TREE, m_arrival_tree);
325 DDX_Control(pDX, IDC_SPIN_WAVE_THRESHOLD, m_threshold_spin);
326 DDX_Control(pDX, IDC_SPIN_WAVES, m_waves_spin);
327 DDX_Text(pDX, IDC_WING_NAME, m_wing_name);
328 DDX_CBIndex(pDX, IDC_WING_SPECIAL_SHIP, m_special_ship);
329 DDX_CBIndex(pDX, IDC_ARRIVAL_LOCATION, m_arrival_location);
330 DDX_CBIndex(pDX, IDC_DEPARTURE_LOCATION, m_departure_location);
331 DDX_Check(pDX, IDC_REINFORCEMENT, m_reinforcement);
332 DDX_CBIndex(pDX, IDC_HOTKEY, m_hotkey);
333 DDX_Check(pDX, IDC_IGNORE_COUNT, m_ignore_count);
334 DDX_Text(pDX, IDC_ARRIVAL_DISTANCE, m_arrival_dist);
335 DDX_CBIndex(pDX, IDC_ARRIVAL_TARGET, m_arrival_target);
336 DDX_Check(pDX, IDC_NO_ARRIVAL_MUSIC, m_no_arrival_music);
337 DDX_CBIndex(pDX, IDC_DEPARTURE_TARGET, m_departure_target);
338 DDX_Check(pDX, IDC_NO_ARRIVAL_MESSAGE, m_no_arrival_message);
339 DDX_Check(pDX, IDC_NO_ARRIVAL_WARP, m_no_arrival_warp);
340 DDX_Check(pDX, IDC_NO_DEPARTURE_WARP, m_no_departure_warp);
341 DDX_Check(pDX, IDC_NO_DYNAMIC, m_no_dynamic);
344 if (pDX->m_bSaveAndValidate) { // get dialog control values
345 GetDlgItem(IDC_ARRIVAL_DELAY)->GetWindowText(str);
346 m_arrival_delay = atoi(str);
347 if (m_arrival_delay < 0)
350 GetDlgItem(IDC_DEPARTURE_DELAY)->GetWindowText(str);
351 m_departure_delay = atoi(str);
352 if (m_departure_delay < 0)
353 m_departure_delay = 0;
355 GetDlgItem(IDC_WING_WAVES)->GetWindowText(str);
360 GetDlgItem(IDC_WING_WAVE_THRESHOLD)->GetWindowText(str);
361 m_threshold = atoi(str);
365 GetDlgItem(IDC_ARRIVAL_DELAY_MIN)->GetWindowText(str);
366 m_arrival_delay_min = atoi(str);
367 if (m_arrival_delay_min < 0)
368 m_arrival_delay_min = 0;
370 GetDlgItem(IDC_ARRIVAL_DELAY_MAX)->GetWindowText(str);
371 m_arrival_delay_max = atoi(str);
372 if (m_arrival_delay_max < 0)
373 m_arrival_delay_max = 0;
376 DDX_Text(pDX, IDC_ARRIVAL_DELAY, m_arrival_delay);
377 DDX_Text(pDX, IDC_DEPARTURE_DELAY, m_departure_delay);
378 DDX_Text(pDX, IDC_WING_WAVES, m_waves);
379 DDX_Text(pDX, IDC_WING_WAVE_THRESHOLD, m_threshold);
380 DDX_Text(pDX, IDC_ARRIVAL_DELAY_MIN, m_arrival_delay_min);
381 DDX_Text(pDX, IDC_ARRIVAL_DELAY_MAX, m_arrival_delay_max);
385 BEGIN_MESSAGE_MAP(wing_editor, CDialog)
386 //{{AFX_MSG_MAP(wing_editor)
388 ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_WAVES, OnDeltaposSpinWaves)
389 ON_NOTIFY(NM_RCLICK, IDC_ARRIVAL_TREE, OnRclickArrivalTree)
390 ON_NOTIFY(NM_RCLICK, IDC_DEPARTURE_TREE, OnRclickDepartureTree)
391 ON_NOTIFY(TVN_BEGINLABELEDIT, IDC_ARRIVAL_TREE, OnBeginlabeleditArrivalTree)
392 ON_NOTIFY(TVN_BEGINLABELEDIT, IDC_DEPARTURE_TREE, OnBeginlabeleditDepartureTree)
393 ON_NOTIFY(TVN_ENDLABELEDIT, IDC_ARRIVAL_TREE, OnEndlabeleditArrivalTree)
394 ON_NOTIFY(TVN_ENDLABELEDIT, IDC_DEPARTURE_TREE, OnEndlabeleditDepartureTree)
395 ON_BN_CLICKED(IDC_DELETE_WING, OnDeleteWing)
396 ON_BN_CLICKED(IDC_DISBAND_WING, OnDisbandWing)
398 ON_BN_CLICKED(IDC_GOALS2, OnGoals2)
399 ON_BN_CLICKED(IDC_REINFORCEMENT, OnReinforcement)
400 ON_BN_CLICKED(IDC_NEXT, OnNext)
401 ON_NOTIFY(TVN_SELCHANGED, IDC_ARRIVAL_TREE, OnSelchangedArrivalTree)
402 ON_NOTIFY(TVN_SELCHANGED, IDC_DEPARTURE_TREE, OnSelchangedDepartureTree)
403 ON_BN_CLICKED(IDC_HIDE_CUES, OnHideCues)
404 ON_BN_CLICKED(IDC_PREV, OnPrev)
405 ON_CBN_SELCHANGE(IDC_ARRIVAL_LOCATION, OnSelchangeArrivalLocation)
406 ON_CBN_SELCHANGE(IDC_DEPARTURE_LOCATION, OnSelchangeDepartureLocation)
407 ON_CBN_SELCHANGE(IDC_HOTKEY, OnSelchangeHotkey)
411 /////////////////////////////////////////////////////////////////////////////
412 // wing_editor message handlers
414 BOOL wing_editor::Create()
420 r = CDialog::Create(IDD, Fred_main_wnd);
421 box = (CComboBox *) GetDlgItem(IDC_ARRIVAL_LOCATION);
423 for (i=0; i<MAX_ARRIVAL_NAMES; i++)
424 box->AddString(Arrival_location_names[i]);
426 box = (CComboBox *) GetDlgItem(IDC_DEPARTURE_LOCATION);
428 for (i=0; i<MAX_DEPARTURE_NAMES; i++)
429 box->AddString(Departure_location_names[i]);
432 m_waves_spin.SetRange(1, 99);
433 m_arrival_tree.link_modified(&modified); // provide way to indicate trees are modified in dialog
434 m_arrival_tree.setup((CEdit *) GetDlgItem(IDC_HELP_BOX));
435 m_departure_tree.link_modified(&modified);
436 m_departure_tree.setup();
437 m_arrival_delay_spin.SetRange(0, 999);
438 m_departure_delay_spin.SetRange(0, 999);
444 void wing_editor::OnInitMenu(CMenu* pMenu)
448 m = pMenu->GetSubMenu(0);
450 generate_wing_popup_menu(m, ID_WING_MENU, MF_ENABLED);
452 m->CheckMenuItem(ID_WING_MENU + cur_wing, MF_BYCOMMAND | MF_CHECKED);
454 CDialog::OnInitMenu(pMenu);
457 void wing_editor::OnOK()
465 GetDlgItem(IDC_ARRIVAL_TREE)->SetFocus();
470 void wing_editor::OnClose()
472 if (verify() && (!bypass_errors)) {
473 SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
479 SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
484 SetWindowPos(Fred_main_wnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
485 Fred_main_wnd->SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
488 // initialize everything that update_data_safe() saves.
489 void wing_editor::initialize_data_safe(int full_update)
491 int i, enable = TRUE, player_wing = 0, player_enabled = 1;
492 CComboBox *arrival_box, *departure_box;
494 nprintf(("Fred routing", "Wing dialog load safe\n"));
498 arrival_box = (CComboBox *) GetDlgItem(IDC_ARRIVAL_TARGET);
499 departure_box = (CComboBox *)GetDlgItem(IDC_DEPARTURE_TARGET);
504 m_arrival_location = -1;
505 m_departure_location = -1;
507 m_arrival_delay_min = 0;
508 m_arrival_delay_max = 0;
510 m_arrival_target = -1;
511 m_departure_target = -1;
512 m_departure_delay = 0;
513 m_arrival_tree.clear_tree();
514 m_departure_tree.clear_tree();
515 m_arrival_tree.DeleteAllItems();
516 m_departure_tree.DeleteAllItems();
517 m_reinforcement = FALSE;
520 m_no_arrival_music = 0;
521 m_no_arrival_message = 0;
522 m_no_arrival_warp = 0;
523 m_no_departure_warp = 0;
525 player_enabled = enable = FALSE;
530 if (cur_wing == wing_name_lookup("alpha", 1))
533 if ((The_mission.game_type & MISSION_TYPE_MULTI_TEAMS) && (cur_wing == wing_name_lookup("zeta", 1)))
536 // in multiplayer coop missions, alpha, beta, and gamma are both off limits.
537 if ( The_mission.game_type & MISSION_TYPE_MULTI_COOP ) {
538 if ( (cur_wing == wing_name_lookup("alpha", 1)) || (cur_wing == wing_name_lookup("beta", 1)) || (cur_wing == wing_name_lookup("gamma", 1)) ) {
543 if ((Player_start_shipnum >= 0) && (Player_start_shipnum < MAX_SHIPS) && (Ships[Player_start_shipnum].objnum >= 0))
544 if (Ships[Player_start_shipnum].wingnum == cur_wing)
547 m_special_ship = Wings[cur_wing].special_ship;
548 m_waves = Wings[cur_wing].num_waves;
549 m_threshold = Wings[cur_wing].threshold;
550 m_arrival_location = Wings[cur_wing].arrival_location;
551 m_departure_location = Wings[cur_wing].departure_location;
552 m_arrival_delay = Wings[cur_wing].arrival_delay;
553 m_arrival_delay_min = Wings[cur_wing].wave_delay_min;
554 m_arrival_delay_max = Wings[cur_wing].wave_delay_max;
555 m_arrival_dist = Wings[cur_wing].arrival_distance;
556 m_arrival_target = Wings[cur_wing].arrival_anchor;
557 m_departure_target = Wings[cur_wing].departure_anchor;
558 m_no_dynamic = (Wings[cur_wing].flags & WF_NO_DYNAMIC)?1:0;
560 // Add the ships/special items to the combo box here before data is updated
561 if ( m_arrival_location == ARRIVE_FROM_DOCK_BAY ) {
562 management_add_ships_to_combo( arrival_box, SHIPS_2_COMBO_DOCKING_BAY_ONLY );
564 management_add_ships_to_combo( arrival_box, SHIPS_2_COMBO_SPECIAL | SHIPS_2_COMBO_ALL_SHIPS );
567 if (m_arrival_target >= SPECIAL_ARRIVAL_ANCHORS_OFFSET)
568 m_arrival_target -= SPECIAL_ARRIVAL_ANCHORS_OFFSET;
569 else if (m_arrival_target >= 0)
570 m_arrival_target = arrival_box->FindStringExact(-1, Ships[m_arrival_target].ship_name);
572 if ( m_departure_target >= 0 )
573 m_departure_target = departure_box->FindStringExact(-1, Ships[m_departure_target].ship_name);
575 // add the ships to the departure target combo box
576 if ( m_departure_location == DEPART_AT_DOCK_BAY ) {
577 management_add_ships_to_combo( departure_box, SHIPS_2_COMBO_DOCKING_BAY_ONLY );
579 departure_box->ResetContent();
582 m_departure_delay = Wings[cur_wing].departure_delay;
584 m_arrival_tree.load_tree(Locked_sexp_true);
586 m_arrival_tree.load_tree(Wings[cur_wing].arrival_cue);
588 m_departure_tree.load_tree(Wings[cur_wing].departure_cue, "false");
589 m_hotkey = Wings[cur_wing].hotkey+1;
590 if (Wings[cur_wing].flags & WF_IGNORE_COUNT)
595 if (Wings[cur_wing].flags & WF_NO_ARRIVAL_MUSIC)
596 m_no_arrival_music = 1;
598 m_no_arrival_music = 0;
600 if ( Wings[cur_wing].flags & WF_NO_ARRIVAL_MESSAGE )
601 m_no_arrival_message = 1;
603 m_no_arrival_message = 0;
605 if ( Wings[cur_wing].flags & WF_NO_ARRIVAL_WARP )
606 m_no_arrival_warp = 1;
608 m_no_arrival_warp = 0;
610 if ( Wings[cur_wing].flags & WF_NO_DEPARTURE_WARP )
611 m_no_departure_warp = 1;
613 m_no_departure_warp = 0;
615 ptr = (CComboBox *) GetDlgItem(IDC_WING_SPECIAL_SHIP);
617 for (i=0; i<Wings[cur_wing].wave_count; i++)
618 ptr->AddString(Ships[Wings[cur_wing].ship_index[i]].ship_name);
620 m_threshold_spin.SetRange(0, Wings[cur_wing].wave_count - 1);
621 for (i=0; i<Num_reinforcements; i++)
622 if (!stricmp(Reinforcements[i].name, Wings[cur_wing].name))
625 if (i < Num_reinforcements)
626 m_reinforcement = TRUE;
628 m_reinforcement = FALSE;
634 GetDlgItem(IDC_WING_NAME)->EnableWindow(enable);
635 GetDlgItem(IDC_WING_SPECIAL_SHIP)->EnableWindow(enable);
636 GetDlgItem(IDC_WING_WAVES)->EnableWindow(player_enabled);
637 GetDlgItem(IDC_WING_WAVE_THRESHOLD)->EnableWindow(player_enabled);
638 GetDlgItem(IDC_DISBAND_WING)->EnableWindow(enable);
639 GetDlgItem(IDC_SPIN_WAVES)->EnableWindow(player_enabled);
640 GetDlgItem(IDC_SPIN_WAVE_THRESHOLD)->EnableWindow(player_enabled);
641 GetDlgItem(IDC_ARRIVAL_LOCATION)->EnableWindow(enable);
643 GetDlgItem(IDC_ARRIVAL_DELAY)->EnableWindow(player_enabled);
644 GetDlgItem(IDC_ARRIVAL_DELAY_MIN)->EnableWindow(player_enabled);
645 GetDlgItem(IDC_ARRIVAL_DELAY_MAX)->EnableWindow(player_enabled);
646 GetDlgItem(IDC_ARRIVAL_DELAY_SPIN)->EnableWindow(player_enabled);
647 if (m_arrival_location) {
648 GetDlgItem(IDC_ARRIVAL_DISTANCE)->EnableWindow(enable);
649 GetDlgItem(IDC_ARRIVAL_TARGET)->EnableWindow(enable);
651 GetDlgItem(IDC_ARRIVAL_DISTANCE)->EnableWindow(FALSE);
652 GetDlgItem(IDC_ARRIVAL_TARGET)->EnableWindow(FALSE);
654 GetDlgItem(IDC_NO_DYNAMIC)->EnableWindow(enable);
656 if ( m_departure_location ) {
657 GetDlgItem(IDC_DEPARTURE_TARGET)->EnableWindow(enable);
659 GetDlgItem(IDC_DEPARTURE_TARGET)->EnableWindow(FALSE);
663 GetDlgItem(IDC_ARRIVAL_TREE)->EnableWindow(0);
665 GetDlgItem(IDC_ARRIVAL_TREE)->EnableWindow(enable);
667 GetDlgItem(IDC_DEPARTURE_LOCATION)->EnableWindow(enable);
668 GetDlgItem(IDC_DEPARTURE_DELAY)->EnableWindow(enable);
669 GetDlgItem(IDC_DEPARTURE_DELAY_SPIN)->EnableWindow(enable);
670 GetDlgItem(IDC_DEPARTURE_TREE)->EnableWindow(enable);
671 GetDlgItem(IDC_GOALS2)->EnableWindow(enable);
672 GetDlgItem(IDC_DELETE_WING)->EnableWindow(enable);
673 GetDlgItem(IDC_REINFORCEMENT)->EnableWindow(enable);
674 GetDlgItem(IDC_HOTKEY)->EnableWindow(enable);
675 GetDlgItem(IDC_IGNORE_COUNT)->EnableWindow(enable);
676 GetDlgItem(IDC_NO_ARRIVAL_MUSIC)->EnableWindow(enable);
677 GetDlgItem(IDC_NO_ARRIVAL_MESSAGE)->EnableWindow(enable);
678 GetDlgItem(IDC_NO_ARRIVAL_WARP)->EnableWindow(enable);
679 GetDlgItem(IDC_NO_DEPARTURE_WARP)->EnableWindow(enable);
684 // check to see if the wing has a ship which is not a fighter/bomber type. If so, then disable
685 // the wing_waves and wing_threshold stuff
686 for (i = 0; i < Wings[cur_wing].wave_count; i++ ) {
689 sflag = Ship_info[Ships[Wings[cur_wing].ship_index[i]].ship_info_index].flags;
690 if ( !(sflag & SIF_FIGHTER) && !(sflag & SIF_BOMBER) )
698 void wing_editor::initialize_data(int full_update)
703 nprintf(("Fred routing", "Wing dialog load\n"));
707 m_arrival_tree.select_sexp_node = m_departure_tree.select_sexp_node = select_sexp_node;
708 select_sexp_node = -1;
710 m_wing_name = _T("");
712 m_wing_name = _T(Wings[cur_wing].name);
714 initialize_data_safe(full_update);
719 i = m_arrival_tree.select_sexp_node;
721 w = GetDlgItem(IDC_ARRIVAL_TREE);
722 m_arrival_tree.hilite_item(i);
725 i = m_departure_tree.select_sexp_node;
727 w = GetDlgItem(IDC_DEPARTURE_TREE);
728 m_departure_tree.hilite_item(i);
733 // update wing structure(s) with dialog data. The data is first checked for errors. If
734 // no errors occur, returns 0. If an error occurs, returns -1. If the update is bypassed,
735 // returns 1. Bypass is necessary to avoid an infinite loop, and it doesn't actually
736 // update the data. Bypass only occurs if bypass mode is active and we still get an error.
737 // Once the error no longer occurs, bypass mode is cleared and data is updated.
738 int wing_editor::update_data(int redraw)
740 char *str, old_name[255], buf[512];
744 nprintf(("Fred routing", "Wing dialog save\n"));
752 if (!strnicmp(m_wing_name, "player ", 7)) {
757 z = MessageBox("Wing names can't start with the word 'player'\n"
758 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
763 m_wing_name = _T(Wings[cur_wing].name);
767 for (i=0; i<MAX_WINGS; i++)
768 if (Wings[i].wave_count && !stricmp(Wings[i].name, m_wing_name) && (i != cur_wing)) {
773 z = MessageBox("This wing name is already being used by another wing\n"
774 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
779 m_wing_name = _T(Wings[cur_wing].name);
783 ptr = GET_FIRST(&obj_used_list);
784 while (ptr != END_OF_LIST(&obj_used_list)) {
785 if (ptr->type == OBJ_SHIP) {
786 if (!stricmp(m_wing_name, Ships[ptr->instance].ship_name)) {
791 z = MessageBox("This wing name is already being used by a ship\n"
792 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
797 m_wing_name = _T(Wings[cur_wing].name);
805 for (i=0; i<MAX_WAYPOINT_LISTS; i++)
806 if (Waypoint_lists[i].count && !stricmp(Waypoint_lists[i].name, m_wing_name)) {
811 z = MessageBox("This wing name is already being used by a waypoint path\n"
812 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
817 m_wing_name = _T(Wings[cur_wing].name);
821 for (i=0; i<Num_jump_nodes; i++)
822 if (!stricmp(Jump_nodes[i].name, m_wing_name)) {
827 z = MessageBox("This wing name is already being used by a jump node\n"
828 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
833 m_wing_name = _T(Wings[cur_wing].name);
837 strcpy(old_name, Wings[cur_wing].name);
838 string_copy(Wings[cur_wing].name, m_wing_name, NAME_LENGTH, 1);
843 str = Wings[cur_wing].name;
844 if (stricmp(old_name, str)) {
845 update_sexp_references(old_name, str);
846 ai_update_goal_references(REF_TYPE_WING, old_name, str);
847 for (i=0; i<Num_reinforcements; i++)
848 if (!stricmp(old_name, Reinforcements[i].name)) {
849 Assert(strlen(str) < NAME_LENGTH);
850 strcpy(Reinforcements[i].name, str);
853 for (i=0; i<Wings[cur_wing].wave_count; i++) {
854 if ((Objects[wing_objects[cur_wing][i]].type == OBJ_SHIP) || (Objects[wing_objects[cur_wing][i]].type == OBJ_START)) {
855 sprintf(buf, "%s %d", str, i + 1);
856 rename_ship(Wings[cur_wing].ship_index[i], buf);
863 if (set_reinforcement(str, m_reinforcement) == 1) {
864 free_sexp2(Wings[cur_wing].arrival_cue);
865 Wings[cur_wing].arrival_cue = Locked_sexp_false;
875 // update parts of wing that can't fail. This is useful if for when you need to change
876 // something in a wing that this updates elsewhere in Fred. Normally when auto-update
877 // kicks in, the changes you make will be wiped out by the auto=update, so instead you
878 // would call this function to update the wing, make your changes, and then call the
879 // initialize_data_safe() function to show your changes in the dialog
880 void wing_editor::update_data_safe()
883 int i, d, hotkey = -1;
885 nprintf(("Fred routing", "Wing dialog save safe\n"));
895 if (m_threshold >= Wings[cur_wing].wave_count) {
896 m_threshold = Wings[cur_wing].wave_count - 1;
898 sprintf(buf, "Wave threshold is set too high. Value has been lowered to %d", (int) m_threshold);
903 if (m_threshold + Wings[cur_wing].wave_count > MAX_SHIPS_PER_WING) {
904 m_threshold = MAX_SHIPS_PER_WING - Wings[cur_wing].wave_count;
906 sprintf(buf, "Wave threshold is set too high. Value has been lowered to %d", (int) m_threshold);
914 sprintf(buf, "Number of waves illegal. Has been set to 1.", (int) m_waves);
919 MODIFY(Wings[cur_wing].special_ship, m_special_ship);
920 MODIFY(Wings[cur_wing].num_waves, m_waves);
921 MODIFY(Wings[cur_wing].threshold, m_threshold);
922 MODIFY(Wings[cur_wing].arrival_location, m_arrival_location);
923 MODIFY(Wings[cur_wing].departure_location, m_departure_location);
924 MODIFY(Wings[cur_wing].arrival_delay, m_arrival_delay);
925 if (m_arrival_delay_min > m_arrival_delay_max) {
927 sprintf(buf, "Arrival delay minimum greater than maximum. Value lowered to %d", m_arrival_delay_max);
930 m_arrival_delay_min = m_arrival_delay_max;
933 MODIFY(Wings[cur_wing].wave_delay_min, m_arrival_delay_min);
934 MODIFY(Wings[cur_wing].wave_delay_max, m_arrival_delay_max);
935 MODIFY(Wings[cur_wing].arrival_distance, m_arrival_dist);
936 if (m_arrival_target >= 0) {
937 i = ((CComboBox *) GetDlgItem(IDC_ARRIVAL_TARGET)) -> GetItemData(m_arrival_target);
938 MODIFY(Wings[cur_wing].arrival_anchor, i);
940 // when arriving near or in front of a ship, be sure that we are far enough away from it!!!
941 if (((m_arrival_location != ARRIVE_AT_LOCATION) && (m_arrival_location != ARRIVE_FROM_DOCK_BAY)) && (i >= 0) && (i < SPECIAL_ARRIVAL_ANCHORS_OFFSET)) {
942 d = int(min(500, 2.0f * Objects[Ships[i].objnum].radius));
943 if ((Wings[cur_wing].arrival_distance < d) && (Wings[cur_wing].arrival_distance > -d)) {
945 sprintf(buf, "Ship must arrive at least %d meters away from target.\n"
946 "Value has been reset to this. Use with caution!\r\n"
947 "Reccomended distance is %d meters.\r\n", d, (int)(2.0f * Objects[Ships[i].objnum].radius) );
950 if (Wings[cur_wing].arrival_distance < 0)
951 Wings[cur_wing].arrival_distance = -d;
953 Wings[cur_wing].arrival_distance = d;
955 m_arrival_dist = Wings[cur_wing].arrival_distance;
960 i = ((CComboBox*)GetDlgItem(IDC_DEPARTURE_TARGET))->GetItemData(m_departure_target);
961 MODIFY(Wings[cur_wing].departure_anchor, i);
963 MODIFY(Wings[cur_wing].departure_delay, m_departure_delay);
964 hotkey = m_hotkey - 1;
965 MODIFY(Wings[cur_wing].hotkey, hotkey);
966 if ( m_ignore_count ) {
967 if ( !(Wings[cur_wing].flags & WF_IGNORE_COUNT) )
969 Wings[cur_wing].flags |= WF_IGNORE_COUNT;
972 if ( Wings[cur_wing].flags & WF_IGNORE_COUNT )
974 Wings[cur_wing].flags &= ~WF_IGNORE_COUNT;
977 if ( m_no_arrival_music ) {
978 if ( !(Wings[cur_wing].flags & WF_NO_ARRIVAL_MUSIC) )
980 Wings[cur_wing].flags |= WF_NO_ARRIVAL_MUSIC;
983 if ( Wings[cur_wing].flags & WF_NO_ARRIVAL_MUSIC )
985 Wings[cur_wing].flags &= ~WF_NO_ARRIVAL_MUSIC;
988 // check the no message flag
989 if ( m_no_arrival_message ) {
990 if ( !(Wings[cur_wing].flags & WF_NO_ARRIVAL_MESSAGE) )
992 Wings[cur_wing].flags |= WF_NO_ARRIVAL_MESSAGE;
995 if ( Wings[cur_wing].flags & WF_NO_ARRIVAL_MESSAGE )
997 Wings[cur_wing].flags &= ~WF_NO_ARRIVAL_MESSAGE;
1000 // set the no warp effect for wings flag
1001 if ( m_no_arrival_warp ) {
1002 if ( !(Wings[cur_wing].flags & WF_NO_ARRIVAL_WARP) )
1004 Wings[cur_wing].flags |= WF_NO_ARRIVAL_WARP;
1006 if ( Wings[cur_wing].flags & WF_NO_ARRIVAL_WARP )
1008 Wings[cur_wing].flags &= ~WF_NO_ARRIVAL_WARP;
1010 // set the no warp effect for wings flag
1011 if ( m_no_departure_warp ) {
1012 if ( !(Wings[cur_wing].flags & WF_NO_DEPARTURE_WARP) )
1014 Wings[cur_wing].flags |= WF_NO_DEPARTURE_WARP;
1016 if ( Wings[cur_wing].flags & WF_NO_DEPARTURE_WARP )
1018 Wings[cur_wing].flags &= ~WF_NO_DEPARTURE_WARP;
1021 if ( m_no_dynamic ) {
1022 if ( !(Wings[cur_wing].flags & WF_NO_DYNAMIC) )
1024 Wings[cur_wing].flags |= WF_NO_DYNAMIC;
1026 if ( Wings[cur_wing].flags & WF_NO_DYNAMIC )
1028 Wings[cur_wing].flags &= ~WF_NO_DYNAMIC;
1031 if (Wings[cur_wing].arrival_cue >= 0)
1032 free_sexp2(Wings[cur_wing].arrival_cue);
1033 Wings[cur_wing].arrival_cue = m_arrival_tree.save_tree();
1035 if (Wings[cur_wing].departure_cue >= 0)
1036 free_sexp2(Wings[cur_wing].departure_cue);
1037 Wings[cur_wing].departure_cue = m_departure_tree.save_tree();
1043 BOOL wing_editor::OnCommand(WPARAM wParam, LPARAM lParam)
1047 id = LOWORD(wParam);
1048 if (id >= ID_WING_MENU && id < ID_WING_MENU + MAX_WINGS) {
1049 if (!update_data()) {
1050 wing = id - ID_WING_MENU;
1056 return CDialog::OnCommand(wParam, lParam);
1059 void wing_editor::OnDeltaposSpinWaves(NMHDR* pNMHDR, LRESULT* pResult)
1062 NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
1064 new_pos = pNMUpDown->iPos + pNMUpDown->iDelta;
1065 if (new_pos > 0 && new_pos < 100) {
1073 void wing_editor::OnRclickArrivalTree(NMHDR* pNMHDR, LRESULT* pResult)
1075 m_arrival_tree.right_clicked();
1079 void wing_editor::OnRclickDepartureTree(NMHDR* pNMHDR, LRESULT* pResult)
1081 m_departure_tree.right_clicked();
1085 void wing_editor::OnBeginlabeleditArrivalTree(NMHDR* pNMHDR, LRESULT* pResult)
1087 TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
1089 if (m_arrival_tree.edit_label(pTVDispInfo->item.hItem) == 1) {
1097 void wing_editor::OnBeginlabeleditDepartureTree(NMHDR* pNMHDR, LRESULT* pResult)
1099 TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
1101 if (m_departure_tree.edit_label(pTVDispInfo->item.hItem) == 1) {
1109 void wing_editor::OnEndlabeleditArrivalTree(NMHDR* pNMHDR, LRESULT* pResult)
1111 TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
1113 *pResult = m_arrival_tree.end_label_edit(pTVDispInfo->item.hItem, pTVDispInfo->item.pszText);
1116 void wing_editor::OnEndlabeleditDepartureTree(NMHDR* pNMHDR, LRESULT* pResult)
1118 TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
1120 *pResult = m_departure_tree.end_label_edit(pTVDispInfo->item.hItem, pTVDispInfo->item.pszText);
1123 int wing_editor::verify()
1125 nprintf(("Fred routing", "Wing dialog verify\n"));
1126 if (!GetSafeHwnd() || !modified)
1135 // delete wing and all ships that are part of the wing
1136 void wing_editor::OnDeleteWing()
1138 modified = 0; // no need to run update checks, since wing will be gone shortly anyway.
1139 delete_wing(cur_wing);
1142 // delete wing, but leave ships intact and wingless
1143 void wing_editor::OnDisbandWing()
1145 modified = 0; // no need to run update checks, since wing will be gone shortly anyway.
1146 remove_wing(cur_wing);
1149 void wing_editor::OnGoals2()
1151 ShipGoalsDlg dlg_goals;
1153 Assert(cur_wing != -1);
1154 dlg_goals.self_wing = cur_wing;
1155 dlg_goals.DoModal();
1156 if (query_initial_orders_conflict(cur_wing))
1157 MessageBox("One or more ships of this wing also has initial orders",
1158 "Possible conflict");
1161 void wing_editor::OnReinforcement()
1165 //if (m_reinforcement)
1166 // m_arrival_tree.clear_tree("false");
1169 void wing_editor::OnPrev()
1171 int wing, count = 0;
1173 if (!update_data() && num_wings) {
1174 wing = cur_wing - 1;
1176 wing = MAX_WINGS - 1;
1178 while (!Wings[wing].wave_count) {
1180 if (count++ > MAX_WINGS)
1184 wing = MAX_WINGS - 1;
1188 Wing_editor_dialog.initialize_data(1);
1195 void wing_editor::OnNext()
1197 int wing, count = 0;
1199 if (!update_data() && num_wings) {
1200 wing = cur_wing + 1;
1201 if (wing >= MAX_WINGS)
1204 while (!Wings[wing].wave_count) {
1206 if (count++ > MAX_WINGS)
1209 if (wing >= MAX_WINGS)
1214 Wing_editor_dialog.initialize_data(1);
1221 void wing_editor::OnSelchangedArrivalTree(NMHDR* pNMHDR, LRESULT* pResult)
1225 NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
1226 h = pNMTreeView->itemNew.hItem;
1228 m_arrival_tree.update_help(h);
1233 void wing_editor::OnSelchangedDepartureTree(NMHDR* pNMHDR, LRESULT* pResult)
1237 NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
1238 h = pNMTreeView->itemNew.hItem;
1240 m_departure_tree.update_help(h);
1245 void wing_editor::calc_cue_height()
1249 GetDlgItem(IDC_CUE_FRAME)->GetWindowRect(cue);
1250 cue_height = cue.bottom - cue.top + 10;
1252 cue_height += SEXP_HELP_BOX_SIZE;
1254 if (Hide_wing_cues) {
1255 ((CButton *) GetDlgItem(IDC_HIDE_CUES)) -> SetCheck(1);
1260 void wing_editor::show_hide_sexp_help()
1265 cue_height += SEXP_HELP_BOX_SIZE;
1267 cue_height -= SEXP_HELP_BOX_SIZE;
1269 if (((CButton *) GetDlgItem(IDC_HIDE_CUES)) -> GetCheck())
1272 GetWindowRect(rect);
1274 rect.bottom += SEXP_HELP_BOX_SIZE;
1276 rect.bottom -= SEXP_HELP_BOX_SIZE;
1281 void wing_editor::OnHideCues()
1285 GetWindowRect(rect);
1286 if (((CButton *) GetDlgItem(IDC_HIDE_CUES)) -> GetCheck()) {
1287 rect.bottom -= cue_height;
1291 rect.bottom += cue_height;
1298 void wing_editor::OnSelchangeArrivalLocation()
1302 box = (CComboBox *)GetDlgItem(IDC_ARRIVAL_TARGET);
1304 if (m_arrival_location) {
1305 GetDlgItem(IDC_ARRIVAL_DISTANCE)->EnableWindow(TRUE);
1306 GetDlgItem(IDC_ARRIVAL_TARGET)->EnableWindow(TRUE);
1307 if (m_arrival_target < 0) {
1308 m_arrival_target = 0;
1311 // determine which items we should put into the arrival target combo box
1312 if ( m_arrival_location == ARRIVE_FROM_DOCK_BAY ) {
1313 management_add_ships_to_combo( box, SHIPS_2_COMBO_DOCKING_BAY_ONLY );
1315 management_add_ships_to_combo( box, SHIPS_2_COMBO_SPECIAL | SHIPS_2_COMBO_ALL_SHIPS );
1318 m_arrival_target = -1;
1319 GetDlgItem(IDC_ARRIVAL_DISTANCE)->EnableWindow(FALSE);
1320 GetDlgItem(IDC_ARRIVAL_TARGET)->EnableWindow(FALSE);
1325 void wing_editor::OnSelchangeDepartureLocation()
1329 box = (CComboBox *)GetDlgItem(IDC_DEPARTURE_TARGET);
1331 if (m_departure_location) {
1332 GetDlgItem(IDC_DEPARTURE_TARGET)->EnableWindow(TRUE);
1333 if (m_departure_target < 0) {
1334 m_departure_target = 0;
1336 // we need to build up the list box content based on the departure type. When
1337 // from a docking bay, only show ships in the list which have them. Show all ships otherwise
1338 if ( m_departure_location == DEPART_AT_DOCK_BAY ) {
1339 management_add_ships_to_combo( box, SHIPS_2_COMBO_DOCKING_BAY_ONLY );
1341 // I think that this section is currently illegal
1345 m_departure_target = -1;
1346 GetDlgItem(IDC_DEPARTURE_TARGET)->EnableWindow(FALSE);
1351 // see if hotkey should possibly be reserved for player starting wing
1352 void wing_editor::OnSelchangeHotkey()
1358 set_num = m_hotkey - 1; // hotkey sets are 1 index based
1360 // first, determine if we are currently working with a starting wing
1361 for ( i = 0; i < MAX_STARTING_WINGS; i++ ) {
1362 if ( !stricmp( Wings[cur_wing].name, Starting_wing_names[i]) )
1365 if ( i == MAX_STARTING_WINGS )
1368 // we have a player starting wing. See if we assigned a non-standard hotkey
1369 if ( (set_num >= MAX_STARTING_WINGS) || (set_num != i) ) {
1370 sprintf(buf, "Assigning nonstandard hotkey to wing %s (default is F%d)", Wings[cur_wing].name, 5+i);
1371 MessageBox(buf, NULL, MB_OK | MB_ICONEXCLAMATION );