2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/FRED2/WaypointPathDlg.cpp $
18 * Revision 1.3 2002/06/09 04:41:17 relnev
19 * added copyright header
21 * Revision 1.2 2002/05/07 03:16:44 theoddone33
22 * The Great Newline Fix
24 * Revision 1.1.1.1 2002/05/03 03:28:09 root
28 * 2 10/07/98 6:28p Dave
29 * Initial checkin. Renamed all relevant stuff to be Fred2 instead of
30 * Fred. Globalized mission and campaign file extensions. Removed Silent
31 * Threat specific code.
33 * 1 10/07/98 3:02p Dave
35 * 1 10/07/98 3:00p Dave
37 * 12 3/21/98 7:36p Lawrance
38 * Move jump nodes to own lib.
40 * 11 3/10/98 6:11p Hoffoss
41 * Added jump node renaming abilities to Fred.
43 * 10 8/12/97 1:55a Hoffoss
44 * Made extensive changes to object reference checking and handling for
45 * object deletion call.
47 * 9 5/23/97 1:53p Hoffoss
48 * Fixed problems with modeless dialog updating. It won't get caught in
49 * an infinate loop anymore, but still gives an error warning 3 times when
50 * using cancel and trying to switch window focus to main window. Don't
51 * know if I can fix that, but it's not too critical right now.
53 * 8 5/14/97 4:08p Lawrance
54 * removing my_index from game arrays
56 * 7 4/28/97 4:14p Hoffoss
57 * Fixed several bugs involving waypoints.
59 * 6 3/13/97 12:09p Hoffoss
60 * Waypoint path editor finished (apparently I didn't get around to
61 * completing it before).
63 * 5 2/28/97 11:31a Hoffoss
64 * Implemented modeless dialog saving and restoring, and changed some
67 * 4 2/21/97 5:34p Hoffoss
68 * Added extensive modification detection and fixed a bug in initial
71 * 3 2/12/97 5:50p Hoffoss
72 * Expanded on error checking.
74 * 2 2/12/97 12:26p Hoffoss
75 * Expanded on global error checker, added initial orders conflict
76 * checking and warning, added waypoint editor dialog and code.
83 #include "waypointpathdlg.h"
84 #include "management.h"
90 #include "starfield.h"
93 #define ID_JUMP_NODE_MENU 8000
94 #define ID_WAYPOINT_MENU 9000
99 static char THIS_FILE[] = __FILE__;
102 /////////////////////////////////////////////////////////////////////////////
103 // waypoint_path_dlg dialog
105 waypoint_path_dlg::waypoint_path_dlg(CWnd* pParent /*=NULL*/)
106 : CDialog(waypoint_path_dlg::IDD, pParent)
108 //{{AFX_DATA_INIT(waypoint_path_dlg)
114 void waypoint_path_dlg::DoDataExchange(CDataExchange* pDX)
116 CDialog::DoDataExchange(pDX);
117 //{{AFX_DATA_MAP(waypoint_path_dlg)
118 DDX_Text(pDX, IDC_NAME, m_name);
122 BEGIN_MESSAGE_MAP(waypoint_path_dlg, CDialog)
123 //{{AFX_MSG_MAP(waypoint_path_dlg)
129 /////////////////////////////////////////////////////////////////////////////
130 // waypoint_path_dlg message handlers
132 BOOL waypoint_path_dlg::Create()
135 r = CDialog::Create(IDD, Fred_main_wnd);
140 void waypoint_path_dlg::OnInitMenu(CMenu* pMenu)
145 m = pMenu->GetSubMenu(0);
147 for (i=0; i<Num_waypoint_lists; i++)
148 if (Waypoint_lists[i].count)
149 m->AppendMenu(MF_ENABLED | MF_STRING, ID_WAYPOINT_MENU + i, Waypoint_lists[i].name);
151 for (i=0; i<Num_jump_nodes; i++)
152 m->AppendMenu(MF_ENABLED | MF_STRING, ID_JUMP_NODE_MENU + i, Jump_nodes[i].name);
154 m->DeleteMenu(ID_PLACEHOLDER, MF_BYCOMMAND);
155 if (cur_waypoint_list != -1)
156 m->CheckMenuItem(ID_WAYPOINT_MENU + cur_waypoint_list, MF_BYCOMMAND | MF_CHECKED);
158 if (cur_object_index >= 0)
159 if (Objects[cur_object_index].type == OBJ_JUMP_NODE)
160 m->CheckMenuItem(ID_JUMP_NODE_MENU + Objects[cur_object_index].instance, MF_BYCOMMAND | MF_CHECKED);
162 CDialog::OnInitMenu(pMenu);
165 void waypoint_path_dlg::OnOK()
169 void waypoint_path_dlg::OnClose()
172 SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
177 SetWindowPos(Fred_main_wnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
178 Fred_main_wnd->SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
181 void waypoint_path_dlg::initialize_data(int full_update)
188 if (query_valid_object() && Objects[cur_object_index].type == OBJ_WAYPOINT)
189 Assert(cur_waypoint_list == (Objects[cur_object_index].instance / 65536));
191 if (cur_waypoint_list >= 0) {
192 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
194 } else if (Objects[cur_object_index].type == OBJ_JUMP_NODE) {
195 m_name = _T(Jump_nodes[Objects[cur_object_index].instance].name);
205 GetDlgItem(IDC_NAME)->EnableWindow(enable);
208 int waypoint_path_dlg::update_data(int redraw)
210 char *str, old_name[255];
220 if (query_valid_object() && Objects[cur_object_index].type == OBJ_WAYPOINT)
221 Assert(cur_waypoint_list == (Objects[cur_object_index].instance / 65536));
223 if (cur_waypoint_list >= 0) {
224 if (!strnicmp(m_name, "player ", 7)) {
229 z = MessageBox("Waypoint path names can't start with the word 'player'\n"
230 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
235 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
239 for (i=0; i<MAX_WINGS; i++)
240 if (!stricmp(Wings[i].name, m_name)) {
245 z = MessageBox("This waypoint path name is already being used by a wing\n"
246 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
251 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
255 ptr = GET_FIRST(&obj_used_list);
256 while (ptr != END_OF_LIST(&obj_used_list)) {
257 if (ptr->type == OBJ_SHIP) {
258 if (!stricmp(m_name, Ships[ptr->instance].ship_name)) {
263 z = MessageBox("This waypoint path name is already being used by a ship\n"
264 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
269 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
277 for (i=0; i<MAX_WAYPOINT_LISTS; i++)
278 if (Waypoint_lists[i].count && !stricmp(Waypoint_lists[i].name, m_name) && (i != cur_waypoint_list)) {
283 z = MessageBox("This waypoint path name is already being used by another waypoint path\n"
284 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
289 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
293 for (i=0; i<Num_jump_nodes; i++)
294 if (!stricmp(Jump_nodes[i].name, m_name)) {
299 z = MessageBox("This waypoint path name is already being used by a jump node\n"
300 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
305 m_name = _T(Waypoint_lists[cur_waypoint_list].name);
309 strcpy(old_name, Waypoint_lists[cur_waypoint_list].name);
310 string_copy(Waypoint_lists[cur_waypoint_list].name, m_name, NAME_LENGTH, 1);
312 str = (char *) (LPCTSTR) m_name;
313 if (stricmp(old_name, str)) {
314 update_sexp_references(old_name, str);
315 ai_update_goal_references(REF_TYPE_WAYPOINT, old_name, str);
318 } else if (Objects[cur_object_index].type == OBJ_JUMP_NODE) {
319 inst = Objects[cur_object_index].instance;
320 if (!strnicmp(m_name, "player ", 7)) {
325 z = MessageBox("Jump node names can't start with the word 'player'\n"
326 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
331 m_name = _T(Jump_nodes[inst].name);
335 for (i=0; i<MAX_WINGS; i++)
336 if (!stricmp(Wings[i].name, m_name)) {
341 z = MessageBox("This jump node name is already being used by a wing\n"
342 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
347 m_name = _T(Jump_nodes[inst].name);
351 ptr = GET_FIRST(&obj_used_list);
352 while (ptr != END_OF_LIST(&obj_used_list)) {
353 if (ptr->type == OBJ_SHIP) {
354 if (!stricmp(m_name, Ships[ptr->instance].ship_name)) {
359 z = MessageBox("This jump node name is already being used by a ship\n"
360 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
365 m_name = _T(Jump_nodes[inst].name);
373 for (i=0; i<MAX_WAYPOINT_LISTS; i++)
374 if (Waypoint_lists[i].count && !stricmp(Waypoint_lists[i].name, m_name)) {
379 z = MessageBox("This jump node name is already being used by a waypoint path\n"
380 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
385 m_name = _T(Jump_nodes[inst].name);
389 for (i=0; i<Num_jump_nodes; i++)
390 if ((i != inst) && !stricmp(Jump_nodes[i].name, m_name)) {
395 z = MessageBox("This jump node name is already being used by another jump node\n"
396 "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
401 m_name = _T(Jump_nodes[inst].name);
405 strcpy(old_name, Jump_nodes[inst].name);
406 string_copy(Jump_nodes[inst].name, m_name, NAME_LENGTH, 1);
408 str = (char *) (LPCTSTR) m_name;
409 if (stricmp(old_name, str)) {
410 update_sexp_references(old_name, str);
420 BOOL waypoint_path_dlg::OnCommand(WPARAM wParam, LPARAM lParam)
426 if ((id >= ID_WAYPOINT_MENU) && (id < ID_WAYPOINT_MENU + MAX_WAYPOINT_LISTS)) {
427 if (!update_data()) {
428 point = id - ID_WAYPOINT_MENU;
430 ptr = GET_FIRST(&obj_used_list);
431 while (ptr != END_OF_LIST(&obj_used_list)) {
432 if (ptr->type == OBJ_WAYPOINT)
433 if ((ptr->instance / 65536) == point)
434 mark_object(OBJ_INDEX(ptr));
443 if ((id >= ID_JUMP_NODE_MENU) && (id < ID_JUMP_NODE_MENU + Num_jump_nodes)) {
444 if (!update_data()) {
445 point = id - ID_JUMP_NODE_MENU;
447 ptr = GET_FIRST(&obj_used_list);
448 while (ptr != END_OF_LIST(&obj_used_list)) {
449 if (ptr->type == OBJ_JUMP_NODE)
450 if (ptr->instance == point)
451 mark_object(OBJ_INDEX(ptr));
460 return CDialog::OnCommand(wParam, lParam);