FS2_Open
Open source remastering of the Freespace 2 engine
reinforcementeditordlg.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 "ReinforcementEditorDlg.h"
15 #include "mission/missionparse.h"
16 #include "globalincs/linklist.h"
17 #include "ship/ship.h"
18 #include "FREDDoc.h"
19 #include "Management.h"
20 #include "mission/missionmessage.h"
21 
22 #define ID_WING_DATA 9000
23 
24 #ifdef _DEBUG
25 #undef THIS_FILE
26 static char THIS_FILE[] = __FILE__;
27 #endif
28 
30 // reinforcement_editor_dlg dialog
31 
33  : CDialog(reinforcement_editor_dlg::IDD, pParent)
34 {
35  //{{AFX_DATA_INIT(reinforcement_editor_dlg)
36  m_uses = 0;
37  m_delay = 0;
38  //}}AFX_DATA_INIT
39  cur = -1;
40 }
41 
43 {
44  CDialog::DoDataExchange(pDX);
45  //{{AFX_DATA_MAP(reinforcement_editor_dlg)
46  DDX_Control(pDX, IDC_DELAY_SPIN, m_delay_spin);
47  DDX_Control(pDX, IDC_USES_SPIN, m_uses_spin);
48  DDX_Text(pDX, IDC_USES, m_uses);
49  DDX_Text(pDX, IDC_DELAY, m_delay);
50  //}}AFX_DATA_MAP
51 }
52 
53 BEGIN_MESSAGE_MAP(reinforcement_editor_dlg, CDialog)
54  //{{AFX_MSG_MAP(reinforcement_editor_dlg)
55  ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeList)
56  ON_BN_CLICKED(IDC_ADD, OnAdd)
57  ON_BN_CLICKED(IDC_DELETE, OnDelete)
58  ON_WM_CLOSE()
59  //}}AFX_MSG_MAP
60 END_MESSAGE_MAP()
61 
63 // reinforcement_editor_dlg message handlers
64 
66 {
67  int i;
68  CListBox *box;
69 
70  CDialog::OnInitDialog();
72  box = (CListBox *) GetDlgItem(IDC_LIST);
73  for (i=0; i<Num_reinforcements; i++) {
74  m_reinforcements[i] = Reinforcements[i];
75  box->AddString(Reinforcements[i].name);
76  }
77 
78  m_num_reinforcements = Num_reinforcements;
79  m_uses_spin.SetRange(1, 99);
80  m_delay_spin.SetRange(0, 1000);
81  update_data();
82  if (Num_reinforcements == MAX_REINFORCEMENTS)
83  GetDlgItem(IDC_ADD) -> EnableWindow(FALSE);
84 
85  return TRUE;
86 }
87 
89 {
90  object *objp;
91  int enable = TRUE;
92 
93  if (cur < 0) {
94  m_uses = 0;
95  m_delay = 0;
96  enable = FALSE;
97 
98  } else {
99  m_uses = m_reinforcements[cur].uses;
100  m_delay = m_reinforcements[cur].arrival_delay;
101  }
102 
103  UpdateData(FALSE);
104 
105  GetDlgItem(IDC_USES)->EnableWindow(enable);
106  GetDlgItem(IDC_USES_SPIN)->EnableWindow(enable);
107  GetDlgItem(IDC_DELAY)->EnableWindow(enable);
108  GetDlgItem(IDC_DELAY_SPIN)->EnableWindow(enable);
109 
110  if (cur < 0)
111  return;
112 
113  // disable the uses entries if the reinforcement is a ship
114  objp = GET_FIRST(&obj_used_list);
115  while (objp != END_OF_LIST(&obj_used_list)) {
116  if (objp->type == OBJ_SHIP) {
117  if ( !stricmp( Ships[objp->instance].ship_name, m_reinforcements[cur].name) ) {
118  GetDlgItem(IDC_USES)->EnableWindow(FALSE);
119  GetDlgItem(IDC_USES_SPIN)->EnableWindow(FALSE);
120  break;
121  }
122  }
123  objp = GET_NEXT(objp);
124  }
125 }
126 
128 {
129  save_data();
130  cur = ((CListBox *) GetDlgItem(IDC_LIST))->GetCurSel();
131  GetDlgItem(IDC_DELETE) -> EnableWindow(cur != -1);
132  update_data();
133 }
134 
136 {
137  UpdateData(TRUE);
138  UpdateData(TRUE);
139  if (cur >= 0) {
140  Assert(cur < m_num_reinforcements);
141  m_reinforcements[cur].uses = m_uses;
142  m_reinforcements[cur].arrival_delay = m_delay;
143 
144  // save the message information to the reinforcement structure. First clear out the string
145  // entires in the Reinforcement structure
146  memset( m_reinforcements[cur].no_messages, 0, MAX_REINFORCEMENT_MESSAGES * NAME_LENGTH );
147  memset( m_reinforcements[cur].yes_messages, 0, MAX_REINFORCEMENT_MESSAGES * NAME_LENGTH );
148  }
149 }
150 
152 {
153  int i, j;
154 
155  save_data();
156  if (Num_reinforcements != m_num_reinforcements)
157  return 1;
158 
159  for (i=0; i<Num_reinforcements; i++) {
160  if (stricmp(m_reinforcements[i].name, Reinforcements[i].name))
161  return 1;
162  if (m_reinforcements[i].uses != Reinforcements[i].uses)
163  return 1;
164  if ( m_reinforcements[i].arrival_delay != Reinforcements[i].arrival_delay )
165  return 1;
166 
167  // determine if the message content has changed
168  for ( j = 0; j < MAX_REINFORCEMENT_MESSAGES; j++ ) {
169  if ( stricmp(m_reinforcements[i].no_messages[j], Reinforcements[i].no_messages[j]) )
170  return 1;
171  }
172  for ( j = 0; j < MAX_REINFORCEMENT_MESSAGES; j++ ) {
173  if ( stricmp(m_reinforcements[i].yes_messages[j], Reinforcements[i].yes_messages[j]) )
174  return 1;
175  }
176  }
177 
178  return 0;
179 }
180 
182 {
183  int i, j;
184 
185  save_data();
186  // clear arrival cues for any new reinforcements to the list
187  for (i=0; i<m_num_reinforcements; i++) {
188  for (j=0; j<Num_reinforcements; j++)
189  if (!stricmp(m_reinforcements[i].name, Reinforcements[j].name))
190  break;
191 
192  if (j == Num_reinforcements) {
193  for (j=0; j<MAX_SHIPS; j++)
194  if ((Ships[j].objnum != -1) && !stricmp(m_reinforcements[i].name, Ships[j].ship_name)) {
195  //free_sexp2(Ships[j].arrival_cue);
196  //Ships[j].arrival_cue = Locked_sexp_false;
197  break;
198  }
199 
200  if (j == MAX_SHIPS) {
201  for (j=0; j<MAX_WINGS; j++)
202  if (Wings[j].wave_count && !stricmp(m_reinforcements[i].name, Wings[j].name)) {
203  //free_sexp2(Wings[j].arrival_cue);
204  //Wings[j].arrival_cue = Locked_sexp_false;
205  break;
206  }
207 
208  Assert(j < MAX_WINGS);
209  }
210  }
211  }
212 
213  if (Num_reinforcements != m_num_reinforcements)
214  set_modified();
215 
216  Num_reinforcements = m_num_reinforcements;
217  for (i=0; i<m_num_reinforcements; i++) {
218  if (memcmp((void *) &Reinforcements[i], (void *) &m_reinforcements[i], sizeof(reinforcements)))
219  set_modified();
220 
221  Reinforcements[i] = m_reinforcements[i];
222  set_reinforcement( Reinforcements[i].name, 1 ); // this call should
223  }
224 
225  Update_ship = Update_wing = 1;
227  CDialog::OnOK();
228 }
229 
231 {
233  CDialog::OnCancel();
234 }
235 
237 // reinforcement_select dialog
238 
240  : CDialog(reinforcement_select::IDD, pParent)
241 {
242  //{{AFX_DATA_INIT(reinforcement_select)
243  // NOTE: the ClassWizard will add member initialization here
244  //}}AFX_DATA_INIT
245  cur = -1;
246 }
247 
248 void reinforcement_select::DoDataExchange(CDataExchange* pDX)
249 {
250  CDialog::DoDataExchange(pDX);
251  //{{AFX_DATA_MAP(reinforcement_select)
252  // NOTE: the ClassWizard will add DDX and DDV calls here
253  //}}AFX_DATA_MAP
254 }
255 
256 BEGIN_MESSAGE_MAP(reinforcement_select, CDialog)
257  //{{AFX_MSG_MAP(reinforcement_select)
258  ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeList)
259  //}}AFX_MSG_MAP
260 END_MESSAGE_MAP()
261 
263 // reinforcement_select message handlers
264 
265 BOOL reinforcement_select::OnInitDialog()
266 {
267  int i, z;
268  CListBox *box;
269  object *ptr;
270 
271  CDialog::OnInitDialog();
272  box = (CListBox *) GetDlgItem(IDC_LIST);
273  ptr = GET_FIRST(&obj_used_list);
274  while (ptr != END_OF_LIST(&obj_used_list)) {
275  if (ptr->type == OBJ_SHIP && Ships[ptr->instance].wingnum < 0) {
276  z = box->AddString(Ships[ptr->instance].ship_name);
277  box->SetItemData(z, OBJ_INDEX(ptr));
278  }
279 
280  ptr = GET_NEXT(ptr);
281  }
282 
283  for (i=0; i<Num_wings; i++) {
284  z = box->AddString(Wings[i].name);
285  box->SetItemData(z, ID_WING_DATA + i);
286  }
287 
288  return TRUE; // return TRUE unless you set the focus to a control
289  // EXCEPTION: OCX Property Pages should return FALSE
290 }
291 
293 {
294  cur = ((CListBox *) GetDlgItem(IDC_LIST))->GetCurSel();
295  GetDlgItem(IDOK)->EnableWindow(cur != -1);
296 }
297 
299 {
300  cur = ((CListBox *) GetDlgItem(IDC_LIST))->GetCurSel();
301  Assert(cur != -1);
302  ((CListBox *) GetDlgItem(IDC_LIST)) -> GetText(cur, name);
303  CDialog::OnOK();
304 }
305 
307 {
308  cur = -1;
309  CDialog::OnCancel();
310 }
311 
313 {
314  int i, wing_index;
316  CString name_check;
317 
318  dlg.DoModal();
319  if (dlg.cur != -1) {
320  // if we've run out of reinforcement slots
321  if (m_num_reinforcements == MAX_REINFORCEMENTS) {
322  MessageBox("Reached limit on reinforcements. Can't add more!");
323  return;
324  }
325 
326  // if this is a wing, make sure its a valid wing (no mixed ship teams)
327  wing_index = wing_lookup((char*)dlg.name);
328  if(wing_index >= 0){
329  if(wing_has_conflicting_teams(wing_index)){
330  MessageBox("Cannot have a reinforcement wing with mixed teams, sucka!");
331  return;
332  }
333  }
334 
335  i = m_num_reinforcements++;
336  strcpy_s(m_reinforcements[i].name, dlg.name);
337  ((CListBox *) GetDlgItem(IDC_LIST)) -> AddString(dlg.name);
338  m_reinforcements[i].type = 0;
339  m_reinforcements[i].uses = 1;
340  m_reinforcements[i].arrival_delay = 0;
341  memset( m_reinforcements[i].no_messages, 0, MAX_REINFORCEMENT_MESSAGES * NAME_LENGTH );
342  memset( m_reinforcements[i].yes_messages, 0, MAX_REINFORCEMENT_MESSAGES * NAME_LENGTH );
343  if (m_num_reinforcements == MAX_REINFORCEMENTS){
344  GetDlgItem(IDC_ADD) -> EnableWindow(FALSE);
345  }
346  }
347 }
348 
350 {
351  int i;
352 
353  if (cur != -1) {
354  ((CListBox *) GetDlgItem(IDC_LIST)) -> DeleteString(cur);
355  for (i=cur; i<m_num_reinforcements-1; i++)
356  m_reinforcements[i] = m_reinforcements[i + 1];
357  }
358 
359  m_num_reinforcements--;
360  cur = -1;
361  if (!m_reinforcements)
362  GetDlgItem(IDC_DELETE) -> EnableWindow(FALSE);
363 }
364 
366 {
367  int z;
368 
369  if (query_modified()) {
370  z = MessageBox("Do you want to keep your changes?", "Close", MB_ICONQUESTION | MB_YESNOCANCEL);
371  if (z == IDCANCEL)
372  return;
373 
374  if (z == IDYES) {
375  OnOK();
376  return;
377  }
378  }
379 
380  CDialog::OnClose();
381 }
void record_window_data(window_data *wndd, CWnd *wnd)
Definition: fred.cpp:670
wing Wings[MAX_WINGS]
Definition: ship.cpp:128
int i
Definition: multi_pxo.cpp:466
CFREDApp theApp
Definition: fred.cpp:115
window_data Reinforcement_wnd_data
Definition: fred.cpp:71
#define MAX_WINGS
Definition: globals.h:50
#define MAX_SHIPS
Definition: globals.h:37
Assert(pm!=NULL)
int init_window(window_data *wndd, CWnd *wnd, int adjust=0, int pre=0)
Definition: fred.cpp:639
#define IDC_DELETE
Definition: resource.h:560
int wing_has_conflicting_teams(int wing_index)
Definition: ship.cpp:17054
#define MB_ICONQUESTION
Definition: config.h:188
virtual void DoDataExchange(CDataExchange *pDX)
#define TRUE
Definition: pstypes.h:399
object obj_used_list
Definition: object.cpp:53
#define IDC_USES
Definition: resource.h:726
#define MB_YESNOCANCEL
Definition: config.h:183
object * objp
Definition: lua.cpp:3105
int type
Definition: ship.h:84
#define MAX_REINFORCEMENT_MESSAGES
Definition: ship.h:78
#define IDC_LIST
Definition: resource.h:725
reinforcements Reinforcements[MAX_REINFORCEMENTS]
Definition: ship.cpp:165
int instance
Definition: object.h:150
#define ID_WING_DATA
char name[NAME_LENGTH]
Definition: ship.h:83
#define IDC_ADD
Definition: resource.h:728
int Update_wing
Definition: management.cpp:88
int wingnum
Definition: ship.h:623
GLdouble GLdouble z
Definition: Glext.h:5451
int uses
Definition: ship.h:85
int Num_wings
Definition: ship.cpp:120
#define IDC_DELAY
Definition: resource.h:870
#define OBJ_INDEX(objp)
Definition: object.h:235
#define OBJ_SHIP
Definition: object.h:32
void set_modified(BOOL arg)
Definition: freddoc.cpp:676
GLuint const GLchar * name
Definition: Glext.h:5608
GLboolean enable
Definition: Glext.h:10591
int BOOL
Definition: config.h:80
reinforcement_select(CWnd *pParent=NULL)
ship Ships[MAX_SHIPS]
Definition: ship.cpp:122
int arrival_delay
Definition: ship.h:87
#define NAME_LENGTH
Definition: globals.h:15
#define IDC_USES_SPIN
Definition: resource.h:727
int set_reinforcement(char *name, int state)
virtual void DoDataExchange(CDataExchange *pDX)
#define MAX_REINFORCEMENTS
Definition: ship.h:58
reinforcement_editor_dlg(CWnd *pParent=NULL)
int MessageBox(HWND h, const char *s1, const char *s2, int i)
int Update_ship
Definition: management.cpp:87
int Num_reinforcements
Definition: ship.cpp:121
char type
Definition: object.h:146
#define FALSE
Definition: pstypes.h:400
#define IDC_DELAY_SPIN
Definition: resource.h:871
#define stricmp(s1, s2)
Definition: config.h:271
int wing_lookup(const char *name)
Definition: ship.cpp:12736
char ship_name[NAME_LENGTH]
Definition: ship.h:604
#define strcpy_s(...)
Definition: safe_strings.h:67