]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/createwingdlg.cpp
Initial revision
[taylor/freespace2.git] / src / fred2 / createwingdlg.cpp
1 // CreateWingDlg.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "fred.h"
6 #include "createwingdlg.h"
7 #include "object.h"
8 #include "linklist.h"
9 #include "parselo.h"
10
11 #ifdef _DEBUG
12 #define new DEBUG_NEW
13 #undef THIS_FILE
14 static char THIS_FILE[] = __FILE__;
15 #endif
16
17 /////////////////////////////////////////////////////////////////////////////
18 // create_wing_dlg dialog
19
20 create_wing_dlg::create_wing_dlg(CWnd* pParent /*=NULL*/)
21         : CDialog(create_wing_dlg::IDD, pParent)
22 {
23         //{{AFX_DATA_INIT(create_wing_dlg)
24         m_name = _T("");
25         //}}AFX_DATA_INIT
26 }
27
28 void create_wing_dlg::DoDataExchange(CDataExchange* pDX)
29 {
30         CDialog::DoDataExchange(pDX);
31         //{{AFX_DATA_MAP(create_wing_dlg)
32         DDX_Text(pDX, IDC_NAME, m_name);
33         //}}AFX_DATA_MAP
34
35         DDV_MaxChars(pDX, m_name, NAME_LENGTH - 4);
36 }
37
38 BEGIN_MESSAGE_MAP(create_wing_dlg, CDialog)
39         //{{AFX_MSG_MAP(create_wing_dlg)
40                 // NOTE: the ClassWizard will add message map macros here
41         //}}AFX_MSG_MAP
42 END_MESSAGE_MAP()
43
44 /////////////////////////////////////////////////////////////////////////////
45 // create_wing_dlg message handlers
46
47 void create_wing_dlg::OnOK()
48 {
49         char msg[512];
50         int i;
51         object *ptr;
52
53         UpdateData(TRUE);
54         UpdateData(TRUE);
55         m_name = drop_white_space((char *)(LPCSTR) m_name);
56         if (m_name.IsEmpty()) {
57                 MessageBox("You must give a name before you can continue.");
58                 return;
59         }
60
61         if (!strnicmp(m_name, "player ", 7)) {
62                 MessageBox("Wing names can't start with the word 'player'");
63                 return;
64         }
65
66         for (i=0; i<MAX_WINGS; i++)
67                 if (!stricmp(Wings[i].name, m_name) && Wings[i].wave_count) {
68                         sprintf(msg, "The name \"%s\" is already being used by another wing", m_name);
69                         MessageBox(msg);
70                         return;
71                 }
72
73         ptr = GET_FIRST(&obj_used_list);
74         while (ptr != END_OF_LIST(&obj_used_list)) {
75                 if (ptr->type == OBJ_SHIP) {
76                         i = ptr->instance;
77                         if (!strnicmp(m_name, Ships[i].ship_name, strlen(m_name))) {
78                                 char *namep;
79
80                                 namep = Ships[i].ship_name + strlen(m_name);
81                                 if (*namep == ' ') {
82                                         namep++;
83                                         while (*namep) {
84                                                 if (!isdigit(*namep))
85                                                         break;
86
87                                                 namep++;
88                                         }
89                                 }
90
91                                 if (!*namep) {
92                                         MessageBox("This wing name is already being used by a ship");
93                                         return;
94                                 }
95                         }
96                 }
97
98                 ptr = GET_NEXT(ptr);
99         }
100
101         for (i=0; i<MAX_WAYPOINT_LISTS; i++)
102                 if (Waypoint_lists[i].count && !stricmp(Waypoint_lists[i].name, m_name)) {
103                         MessageBox("This wing name is already being used by a waypoint path");
104                         return;
105                 }
106
107         CDialog::OnOK();
108 }