FS2_Open
Open source remastering of the Freespace 2 engine
waypointpathdlg.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
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 the
6  * source.
7  *
8 */
9 
10 
11 
12 #include "stdafx.h"
13 #include "FRED.h"
14 #include "WaypointPathDlg.h"
15 #include "Management.h"
16 #include "MainFrm.h"
17 #include "object/object.h"
18 #include "object/waypoint.h"
19 #include "globalincs/linklist.h"
20 #include "ship/ship.h"
21 #include "ai/aigoals.h"
22 #include "starfield/starfield.h"
23 #include "jumpnode/jumpnode.h"
24 #include "iff_defs/iff_defs.h"
25 
26 #define ID_JUMP_NODE_MENU 8000
27 #define ID_WAYPOINT_MENU 9000
28 
29 #ifdef _DEBUG
30 #undef THIS_FILE
31 static char THIS_FILE[] = __FILE__;
32 #endif
33 
35 // waypoint_path_dlg dialog
36 
37 waypoint_path_dlg::waypoint_path_dlg(CWnd* pParent /*=NULL*/)
38  : CDialog(waypoint_path_dlg::IDD, pParent)
39 {
40  //{{AFX_DATA_INIT(waypoint_path_dlg)
41  m_name = _T("");
42  //}}AFX_DATA_INIT
43  bypass_errors = 0;
44 }
45 
46 void waypoint_path_dlg::DoDataExchange(CDataExchange* pDX)
47 {
48  CDialog::DoDataExchange(pDX);
49  //{{AFX_DATA_MAP(waypoint_path_dlg)
50  DDX_Text(pDX, IDC_NAME, m_name);
51  //}}AFX_DATA_MAP
52 }
53 
54 BEGIN_MESSAGE_MAP(waypoint_path_dlg, CDialog)
55  //{{AFX_MSG_MAP(waypoint_path_dlg)
56  ON_WM_CLOSE()
57  ON_WM_INITMENU()
58  //}}AFX_MSG_MAP
59 END_MESSAGE_MAP()
60 
62 // waypoint_path_dlg message handlers
63 
65 {
66  BOOL r;
67  r = CDialog::Create(IDD, Fred_main_wnd);
68  initialize_data(1);
69  return r;
70 }
71 
73 {
74  int i;
77  CMenu *m;
78 
79  m = pMenu->GetSubMenu(0);
80  clear_menu(m);
81 
82  for (i = 0, ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++i, ++ii) {
83  m->AppendMenu(MF_ENABLED | MF_STRING, ID_WAYPOINT_MENU + i, ii->get_name());
84  }
85 
86  i = 0;
87  for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
88  m->AppendMenu(MF_ENABLED | MF_STRING, ID_JUMP_NODE_MENU + i, jnp->GetName());
89  if (jnp->GetSCPObjectNumber() == cur_object_index) {
90  m->CheckMenuItem(ID_JUMP_NODE_MENU + i, MF_BYCOMMAND | MF_CHECKED);
91  }
92  i++;
93 
94  }
95 
96  m->DeleteMenu(ID_PLACEHOLDER, MF_BYCOMMAND);
97  if (cur_waypoint_list != NULL)
98  {
100  Assert(index >= 0);
101  m->CheckMenuItem(ID_WAYPOINT_MENU + index, MF_BYCOMMAND | MF_CHECKED);
102  }
103 
104  CDialog::OnInitMenu(pMenu);
105 }
106 
108 {
109 }
110 
112 {
113  if (update_data()) {
114  SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);
115  bypass_errors = 0;
116  return;
117  }
118 
119  SetWindowPos(Fred_main_wnd, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW);
120  Fred_main_wnd->SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
121 }
122 
124 {
125  int enable = TRUE;
127 
128  if (!GetSafeHwnd())
129  return;
130 
132  {
134  }
135 
136  if (cur_waypoint_list != NULL) {
138 
139  } else if (Objects[cur_object_index].type == OBJ_JUMP_NODE) {
140  for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
141  if(jnp->GetSCPObject() == &Objects[cur_object_index])
142  break;
143  }
144 
145  m_name = _T(jnp->GetName());
146 
147  } else {
148  m_name = _T("");
149  enable = FALSE;
150  }
151 
152  if (full_update)
153  UpdateData(FALSE);
154 
155  GetDlgItem(IDC_NAME)->EnableWindow(enable);
156 }
157 
159 {
160  const char *str;
161  char old_name[255];
162  int i, z;
163  object *ptr;
165 
166  if (!GetSafeHwnd())
167  return 0;
168 
169  UpdateData(TRUE);
170  UpdateData(TRUE);
171 
173  {
175  }
176 
177  if (cur_waypoint_list != NULL) {
178  for (i=0; i<MAX_WINGS; i++)
179  {
180  if (!stricmp(Wings[i].name, m_name)) {
181  if (bypass_errors)
182  return 1;
183 
184  bypass_errors = 1;
185  z = MessageBox("This waypoint path name is already being used by a wing\n"
186  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
187 
188  if (z == IDCANCEL)
189  return -1;
190 
192  UpdateData(FALSE);
193  }
194  }
195 
196  ptr = GET_FIRST(&obj_used_list);
197  while (ptr != END_OF_LIST(&obj_used_list)) {
198  if ((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) {
199  if (!stricmp(m_name, Ships[ptr->instance].ship_name)) {
200  if (bypass_errors)
201  return 1;
202 
203  bypass_errors = 1;
204  z = MessageBox("This waypoint path name is already being used by a ship\n"
205  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
206 
207  if (z == IDCANCEL)
208  return -1;
209 
211  UpdateData(FALSE);
212  }
213  }
214 
215  ptr = GET_NEXT(ptr);
216  }
217 
218  for (i=0; i<Num_iffs; i++) {
219  if (!stricmp(m_name, Iff_info[i].iff_name)) {
220  if (bypass_errors)
221  return 1;
222 
223  bypass_errors = 1;
224  z = MessageBox("This waypoint path name is already being used by a team.\n"
225  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
226 
227  if (z == IDCANCEL)
228  return -1;
229 
231  UpdateData(FALSE);
232  }
233  }
234 
235  for ( i=0; i < (int)Ai_tp_list.size(); i++) {
236  if (!stricmp(m_name, Ai_tp_list[i].name)) {
237  if (bypass_errors)
238  return 1;
239 
240  bypass_errors = 1;
241  z = MessageBox("This waypoint path name is already being used by a target priority group.\n"
242  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
243 
244  if (z == IDCANCEL)
245  return -1;
246 
248  UpdateData(FALSE);
249  }
250  }
251 
253  for (ii = Waypoint_lists.begin(); ii != Waypoint_lists.end(); ++ii)
254  {
255  if (!stricmp(ii->get_name(), m_name) && (&(*ii) != cur_waypoint_list)) {
256  if (bypass_errors)
257  return 1;
258 
259  bypass_errors = 1;
260  z = MessageBox("This waypoint path name is already being used by another waypoint path\n"
261  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
262 
263  if (z == IDCANCEL)
264  return -1;
265 
267  UpdateData(FALSE);
268  }
269  }
270 
271  if(jumpnode_get_by_name(m_name) != NULL)
272  {
273  if (bypass_errors)
274  return 1;
275 
276  bypass_errors = 1;
277  z = MessageBox("This waypoint path name is already being used by a jump node\n"
278  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
279 
280  if (z == IDCANCEL)
281  return -1;
282 
284  UpdateData(FALSE);
285  }
286 
287  if (!stricmp(m_name.Left(1), "<")) {
288  if (bypass_errors)
289  return 1;
290 
291  bypass_errors = 1;
292  z = MessageBox("Waypoint names not allowed to begin with <\n"
293  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
294 
295  if (z == IDCANCEL)
296  return -1;
297 
299  UpdateData(FALSE);
300  }
301 
302 
303  strcpy_s(old_name, cur_waypoint_list->get_name());
305 
306  str = (char *) (LPCTSTR) m_name;
307  if (strcmp(old_name, str)) {
308  update_sexp_references(old_name, str);
310  update_texture_replacements(old_name, str);
311  }
312 
313  } else if (Objects[cur_object_index].type == OBJ_JUMP_NODE) {
314  for (jnp = Jump_nodes.begin(); jnp != Jump_nodes.end(); ++jnp) {
315  if(jnp->GetSCPObject() == &Objects[cur_object_index])
316  break;
317  }
318 
319  for (i=0; i<MAX_WINGS; i++)
320  {
321  if (!stricmp(Wings[i].name, m_name)) {
322  if (bypass_errors)
323  return 1;
324 
325  bypass_errors = 1;
326  z = MessageBox("This jump node name is already being used by a wing\n"
327  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
328 
329  if (z == IDCANCEL)
330  return -1;
331 
332  m_name = _T(jnp->GetName());
333  UpdateData(FALSE);
334  }
335  }
336 
337  ptr = GET_FIRST(&obj_used_list);
338  while (ptr != END_OF_LIST(&obj_used_list)) {
339  if ((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) {
340  if (!stricmp(m_name, Ships[ptr->instance].ship_name)) {
341  if (bypass_errors)
342  return 1;
343 
344  bypass_errors = 1;
345  z = MessageBox("This jump node name is already being used by a ship\n"
346  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
347 
348  if (z == IDCANCEL)
349  return -1;
350 
351  m_name = _T(jnp->GetName());
352  UpdateData(FALSE);
353  }
354  }
355 
356  ptr = GET_NEXT(ptr);
357  }
358 
359  for (i=0; i<Num_iffs; i++) {
360  if (!stricmp(m_name, Iff_info[i].iff_name)) {
361  if (bypass_errors)
362  return 1;
363 
364  bypass_errors = 1;
365  z = MessageBox("This jump node name is already being used by a team.\n"
366  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
367 
368  if (z == IDCANCEL)
369  return -1;
370 
371  m_name = _T(jnp->GetName());
372  UpdateData(FALSE);
373  }
374  }
375 
376  for ( i=0; i < (int)Ai_tp_list.size(); i++) {
377  if (!stricmp(m_name, Ai_tp_list[i].name)) {
378  if (bypass_errors)
379  return 1;
380 
381  bypass_errors = 1;
382  z = MessageBox("This jump node name is already being used by a target priority group.\n"
383  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
384 
385  if (z == IDCANCEL)
386  return -1;
387 
388  m_name = _T(jnp->GetName());
389  UpdateData(FALSE);
390  }
391  }
392 
393  if (find_matching_waypoint_list((LPCSTR) m_name) != NULL)
394  {
395  if (bypass_errors)
396  return 1;
397 
398  bypass_errors = 1;
399  z = MessageBox("This jump node name is already being used by a waypoint path\n"
400  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
401 
402  if (z == IDCANCEL)
403  return -1;
404 
405  m_name = _T(jnp->GetName());
406  UpdateData(FALSE);
407  }
408 
409  if (!stricmp(m_name.Left(1), "<")) {
410  if (bypass_errors)
411  return 1;
412 
413  bypass_errors = 1;
414  z = MessageBox("Jump node names not allowed to begin with <\n"
415  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
416 
417  if (z == IDCANCEL)
418  return -1;
419 
420  m_name = _T(jnp->GetName());
421  UpdateData(FALSE);
422  }
423 
424  CJumpNode* found = jumpnode_get_by_name(m_name);
425  if(found != NULL && &(*jnp) != found)
426  {
427  if (bypass_errors)
428  return 1;
429 
430  bypass_errors = 1;
431  z = MessageBox("This jump node name is already being used by another jump node\n"
432  "Press OK to restore old name", "Error", MB_ICONEXCLAMATION | MB_OKCANCEL);
433 
434  if (z == IDCANCEL)
435  return -1;
436 
437  m_name = _T(jnp->GetName());
438  UpdateData(FALSE);
439  }
440 
441  strcpy_s(old_name, jnp->GetName());
442  jnp->SetName((LPCSTR) m_name);
443 
444  str = (LPCTSTR) m_name;
445  if (strcmp(old_name, str)) {
446  update_sexp_references(old_name, str);
447  }
448 
449  }
450 
451  if (redraw)
453 
454  return 0;
455 }
456 
458 {
459  int id, point;
460  object *ptr;
461 
462  id = LOWORD(wParam);
463  if ((id >= ID_WAYPOINT_MENU) && (id < ID_WAYPOINT_MENU + (int) Waypoint_lists.size())) {
464  if (!update_data()) {
465  point = id - ID_WAYPOINT_MENU;
466  unmark_all();
467  ptr = GET_FIRST(&obj_used_list);
468  while (ptr != END_OF_LIST(&obj_used_list)) {
469  if (ptr->type == OBJ_WAYPOINT)
470  if (calc_waypoint_list_index(ptr->instance) == point)
471  mark_object(OBJ_INDEX(ptr));
472 
473  ptr = GET_NEXT(ptr);
474  }
475 
476  return 1;
477  }
478  }
479 
480  if ((id >= ID_JUMP_NODE_MENU) && (id < ID_JUMP_NODE_MENU + (int) Jump_nodes.size())) {
481  if (!update_data()) {
482  point = id - ID_JUMP_NODE_MENU;
483  unmark_all();
484  ptr = GET_FIRST(&obj_used_list);
485  while ((ptr != END_OF_LIST(&obj_used_list)) && (point > -1)) {
486  if (ptr->type == OBJ_JUMP_NODE) {
487  if (point == 0) {
488  mark_object(OBJ_INDEX(ptr));
489  }
490  point--;
491  }
492 
493  ptr = GET_NEXT(ptr);
494  }
495 
496  return 1;
497  }
498  }
499 
500  return CDialog::OnCommand(wParam, lParam);
501 }
virtual void DoDataExchange(CDataExchange *pDX)
#define MB_OKCANCEL
Definition: config.h:180
wing Wings[MAX_WINGS]
Definition: ship.cpp:128
int i
Definition: multi_pxo.cpp:466
char * get_name()
Definition: waypoint.cpp:84
#define IDC_NAME
Definition: resource.h:735
void initialize_data(int full_update)
GLuint index
Definition: Glext.h:5608
void unmark_all()
#define MAX_WINGS
Definition: globals.h:50
afx_msg void OnInitMenu(CMenu *pMenu)
waypoint_list * find_waypoint_list_with_instance(int waypoint_instance, int *waypoint_index)
Definition: waypoint.cpp:254
Assert(pm!=NULL)
void update_sexp_references(const char *old_name, const char *new_name, int format, int node)
Definition: sexp.cpp:28332
#define TRUE
Definition: pstypes.h:399
UINT WPARAM wParam
Definition: msacm.h:1064
object obj_used_list
Definition: object.cpp:53
CMainFrame * Fred_main_wnd
Definition: mainfrm.cpp:89
waypoint_path_dlg(CWnd *pParent=NULL)
UINT WPARAM LPARAM lParam
Definition: msacm.h:1064
waypoint_list * cur_waypoint_list
Definition: management.cpp:83
SCP_list< waypoint_list > Waypoint_lists
Definition: waypoint.cpp:9
long LPARAM
Definition: config.h:101
SCP_list< CJumpNode > Jump_nodes
Definition: jumpnode.cpp:16
GLenum type
Definition: Gl.h:1492
iff_info Iff_info[MAX_IFFS]
Definition: iff_defs.cpp:20
#define ID_WAYPOINT_MENU
int query_valid_object(int index)
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
#define OBJ_WAYPOINT
Definition: object.h:36
int instance
Definition: object.h:150
#define OBJ_START
Definition: object.h:35
GLdouble GLdouble GLdouble r
Definition: Glext.h:5337
#define ID_JUMP_NODE_MENU
int update_data(int redraw=1)
GLdouble GLdouble z
Definition: Glext.h:5451
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam)
GLenum GLuint id
Definition: Glext.h:5156
#define REF_TYPE_WAYPOINT
Definition: sexp.h:839
void ai_update_goal_references(ai_goal *goals, int type, const char *old_name, const char *new_name)
Definition: aigoals.cpp:2295
afx_msg void OnClose()
object Objects[MAX_OBJECTS]
Definition: object.cpp:62
void string_copy(char *dest, const CString &src, int max_len, int modify)
Definition: management.cpp:142
#define OBJ_INDEX(objp)
Definition: object.h:235
#define OBJ_SHIP
Definition: object.h:32
GLuint const GLchar * name
Definition: Glext.h:5608
GLboolean enable
Definition: Glext.h:10591
int BOOL
Definition: config.h:80
ship Ships[MAX_SHIPS]
Definition: ship.cpp:122
CJumpNode * jumpnode_get_by_name(const CString &name)
#define MB_ICONEXCLAMATION
Definition: config.h:184
waypoint_list * find_matching_waypoint_list(const char *name)
Definition: waypoint.cpp:164
#define NAME_LENGTH
Definition: globals.h:15
void mark_object(int obj)
int find_index_of_waypoint_list(waypoint_list *wp_list)
Definition: waypoint.cpp:324
int MessageBox(HWND h, const char *s1, const char *s2, int i)
const GLfloat * m
Definition: Glext.h:10319
#define ID_PLACEHOLDER
Definition: resource.h:1288
int cur_object_index
Definition: management.cpp:79
int Num_iffs
Definition: iff_defs.cpp:19
void clear_menu(CMenu *ptr)
char type
Definition: object.h:146
#define FALSE
Definition: pstypes.h:400
SCP_vector< ai_target_priority > Ai_tp_list
Definition: ship.cpp:396
#define stricmp(s1, s2)
Definition: config.h:271
#define OBJ_JUMP_NODE
Definition: object.h:45
void update_texture_replacements(const char *old_name, const char *new_name)
char ship_name[NAME_LENGTH]
Definition: ship.h:604
int calc_waypoint_list_index(int waypoint_instance)
Definition: waypoint.cpp:125
#define strcpy_s(...)
Definition: safe_strings.h:67
void update_map_window()
Definition: fred.cpp:532