FS2_Open
Open source remastering of the Freespace 2 engine
createwingdlg.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 // CreateWingDlg.cpp : implementation file
11 //
12 
13 #include "stdafx.h"
14 #include "FRED.h"
15 #include "CreateWingDlg.h"
16 #include "object/object.h"
17 #include "object/waypoint.h"
18 #include "globalincs/linklist.h"
19 #include "parse/parselo.h"
20 #include "iff_defs/iff_defs.h"
21 
22 #ifdef _DEBUG
23 #undef THIS_FILE
24 static char THIS_FILE[] = __FILE__;
25 #endif
26 
28 // create_wing_dlg dialog
29 
30 create_wing_dlg::create_wing_dlg(CWnd* pParent /*=NULL*/)
31  : CDialog(create_wing_dlg::IDD, pParent)
32 {
33  //{{AFX_DATA_INIT(create_wing_dlg)
34  m_name = _T("");
35  //}}AFX_DATA_INIT
36 }
37 
38 void create_wing_dlg::DoDataExchange(CDataExchange* pDX)
39 {
40  CDialog::DoDataExchange(pDX);
41  //{{AFX_DATA_MAP(create_wing_dlg)
42  DDX_Text(pDX, IDC_NAME, m_name);
43  //}}AFX_DATA_MAP
44 
45  DDV_MaxChars(pDX, m_name, NAME_LENGTH - 4);
46 }
47 
48 BEGIN_MESSAGE_MAP(create_wing_dlg, CDialog)
49  //{{AFX_MSG_MAP(create_wing_dlg)
50  // NOTE: the ClassWizard will add message map macros here
51  //}}AFX_MSG_MAP
52 END_MESSAGE_MAP()
53 
55 // create_wing_dlg message handlers
56 
57 void create_wing_dlg::OnOK()
58 {
59  CString msg;
60  int i;
61  object *ptr;
62 
63  UpdateData(TRUE);
64  UpdateData(TRUE);
65  m_name = drop_white_space((char *)(LPCSTR) m_name);
66  if (m_name.IsEmpty()) {
67  MessageBox("You must give a name before you can continue.");
68  return;
69  }
70 
71  for (i=0; i<MAX_WINGS; i++)
72  if (!stricmp(Wings[i].name, m_name) && Wings[i].wave_count) {
73  msg.Format("The name \"%s\" is already being used by another wing", m_name);
74  MessageBox(msg);
75  return;
76  }
77 
78  ptr = GET_FIRST(&obj_used_list);
79  while (ptr != END_OF_LIST(&obj_used_list)) {
80  if ((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)){
81  i = ptr->instance;
82  if (!strnicmp(m_name, Ships[i].ship_name, strlen(m_name))) {
83  char *namep;
84 
85  namep = Ships[i].ship_name + strlen(m_name);
86  if (*namep == ' ') {
87  namep++;
88  while (*namep) {
89  if (!isdigit(*namep))
90  break;
91 
92  namep++;
93  }
94  }
95 
96  if (!*namep) {
97  MessageBox("This wing name is already being used by a ship");
98  return;
99  }
100  }
101  }
102 
103  ptr = GET_NEXT(ptr);
104  }
105 
106  for (i=0; i<Num_iffs; i++) {
107  if (!stricmp(m_name, Iff_info[i].iff_name)) {
108  msg.Format("The name \"%s\" is already being used by a team", m_name);
109  MessageBox(msg);
110  return;
111  }
112  }
113 
114  for ( i=0; i < (int)Ai_tp_list.size(); i++) {
115  if (!stricmp(m_name, Ai_tp_list[i].name)) {
116  msg.Format("The name \"%s\" is already being used by a target priority group", m_name);
117  MessageBox(msg);
118  return;
119  }
120  }
121 
122  if (find_matching_waypoint_list((LPCSTR) m_name) != NULL)
123  {
124  MessageBox("This wing name is already being used by a waypoint path");
125  return;
126  }
127 
128  if (!stricmp(m_name.Left(1), "<")) {
129  MessageBox("Wing names not allowed to begin with <");
130  return;
131  }
132 
133  CDialog::OnOK();
134 }
wing Wings[MAX_WINGS]
Definition: ship.cpp:128
int i
Definition: multi_pxo.cpp:466
#define IDC_NAME
Definition: resource.h:735
#define MAX_WINGS
Definition: globals.h:50
char * drop_white_space(char *str)
Definition: parselo.cpp:159
#define TRUE
Definition: pstypes.h:399
object obj_used_list
Definition: object.cpp:53
iff_info Iff_info[MAX_IFFS]
Definition: iff_defs.cpp:20
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
int instance
Definition: object.h:150
#define OBJ_START
Definition: object.h:35
#define strnicmp(s1, s2, n)
Definition: config.h:272
#define OBJ_SHIP
Definition: object.h:32
GLuint const GLchar * name
Definition: Glext.h:5608
ship Ships[MAX_SHIPS]
Definition: ship.cpp:122
waypoint_list * find_matching_waypoint_list(const char *name)
Definition: waypoint.cpp:164
#define NAME_LENGTH
Definition: globals.h:15
virtual void DoDataExchange(CDataExchange *pDX)
int MessageBox(HWND h, const char *s1, const char *s2, int i)
create_wing_dlg(CWnd *pParent=NULL)
int Num_iffs
Definition: iff_defs.cpp:19
char type
Definition: object.h:146
SCP_vector< ai_target_priority > Ai_tp_list
Definition: ship.cpp:396
#define stricmp(s1, s2)
Definition: config.h:271
char ship_name[NAME_LENGTH]
Definition: ship.h:604