]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/weaponeditordlg.cpp
fix issue with looping audio streams
[taylor/freespace2.git] / src / fred2 / weaponeditordlg.cpp
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Fred2/WeaponEditorDlg.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Weapon editor dialog box handling code
16  *
17  * $Log$
18  * Revision 1.3  2002/06/09 04:41:17  relnev
19  * added copyright header
20  *
21  * Revision 1.2  2002/05/07 03:16:44  theoddone33
22  * The Great Newline Fix
23  *
24  * Revision 1.1.1.1  2002/05/03 03:28:09  root
25  * Initial import.
26  *
27  * 
28  * 4     4/28/99 11:13p Dave
29  * Temporary checkin of artillery code.
30  * 
31  * 3     4/23/99 12:01p Johnson
32  * Added SIF_HUGE_SHIP
33  * 
34  * 2     10/07/98 6:28p Dave
35  * Initial checkin. Renamed all relevant stuff to be Fred2 instead of
36  * Fred. Globalized mission and campaign file extensions. Removed Silent
37  * Threat specific code.
38  * 
39  * 1     10/07/98 3:02p Dave
40  * 
41  * 1     10/07/98 3:00p Dave
42  * 
43  * 17    5/14/98 5:31p Hoffoss
44  * Fixed some stupid behaviour in this editor related to ammo counts being
45  * -99.
46  * 
47  * 16    4/22/98 11:27a Hoffoss
48  * Make big weapons available for capital ships as well as big ships (why
49  * the hell a capital ship isn't a big ship is beyond me, though).
50  * 
51  * 15    4/14/98 11:46a Johnson
52  * Added window enables for spinners, but it seems to be ignored.
53  * 
54  * 14    2/26/98 10:44a Johnson
55  * Fixed bug with SetRange() not being called on editor first open.
56  * 
57  * 13    2/22/98 1:32a Hoffoss
58  * Changed editor to use raw ammo counts isntead of percentages, and make
59  * it select first item in list by default.
60  * 
61  * 12    2/13/98 3:38p Johnson
62  * Fixed bug where multi ship editing won't update player ships.
63  * 
64  * 11    12/11/97 5:46p Hoffoss
65  * Changed Fred to not display weapons that are not available to various
66  * ships.
67  * 
68  * 10    9/16/97 9:41p Hoffoss
69  * Changed Fred code around to stop using Parse_player structure for
70  * player information, and use actual ships instead.
71  * 
72  * 9     5/30/97 4:50p Hoffoss
73  * Added code to allow marked ship editing of data in child dialogs of
74  * ship editor dialog.
75  * 
76  * 8     4/21/97 5:02p Hoffoss
77  * Player/player status editing supported, and both saved and loaded from
78  * Mission files.
79  * 
80  * 7     4/16/97 2:02p Hoffoss
81  * Fixed bug Mike created by changing code while I had file checked out
82  * still.
83  * 
84  * 6     4/16/97 1:59p Hoffoss
85  * Weapon editor now fully functional.
86  * 
87  * 5     4/10/97 3:20p Mike
88  * Change hull damage to be like shields.
89  * 
90  * 4     4/09/97 11:48a Hoffoss
91  * Initial work to weapon editor.
92  * 
93  * 3     3/31/97 6:07p Hoffoss
94  * Fixed several errors, including BG editor not graying fields, BG editor
95  * not updating image when changed, Removed obsolete data from Weapon
96  * editor, priority not being saved when missions saved, priority not
97  * editable in initial orders editor.
98  * 
99  * 2     2/17/97 5:28p Hoffoss
100  * Checked RCS headers, added them were missing, changing description to
101  * something better, etc where needed.
102  *
103  * $NoKeywords: $
104  */
105
106 #include "stdafx.h"
107 #include "fred.h"
108 #include "weaponeditordlg.h"
109 #include "linklist.h"
110 #include "management.h"
111 #include "weapon.h"
112 #include "ship.h"
113
114 #define BLANK_FIELD -99
115
116 #ifdef _DEBUG
117 #define new DEBUG_NEW
118 #undef THIS_FILE
119 static char THIS_FILE[] = __FILE__;
120 #endif
121
122 /////////////////////////////////////////////////////////////////////////////
123 // WeaponEditorDlg dialog
124
125 WeaponEditorDlg::WeaponEditorDlg(CWnd* pParent /*=NULL*/)
126         : CDialog(WeaponEditorDlg::IDD, pParent)
127 {
128         //{{AFX_DATA_INIT(WeaponEditorDlg)
129         m_ai_class = -1;
130         m_ammo1 = 0;
131         m_ammo2 = 0;
132         m_ammo3 = 0;
133         m_ammo4 = 0;
134         m_gun1 = -1;
135         m_gun2 = -1;
136         m_gun3 = -1;
137         m_missile1 = -1;
138         m_missile2 = -1;
139         m_missile3 = -1;
140         m_missile4 = -1;
141         m_cur_item = -1;
142         //}}AFX_DATA_INIT
143         m_last_item = -1;
144         m_multi_edit = 0;
145 }
146
147 int save_number(char *str, int *val)
148 {
149         char buf[40];
150         int num;
151
152         num = atoi(str);
153         sprintf(buf, "%d", num);
154         if (strncmp(str, buf, strlen(buf)))
155                 return 0;
156
157         *val = num;
158         return 1;
159 }
160
161 void WeaponEditorDlg::DoDataExchange(CDataExchange* pDX)
162 {
163         CString str;
164
165         CDialog::DoDataExchange(pDX);
166         //{{AFX_DATA_MAP(WeaponEditorDlg)
167         DDX_Control(pDX, IDC_SPIN4, m_spin4);
168         DDX_Control(pDX, IDC_SPIN3, m_spin3);
169         DDX_Control(pDX, IDC_SPIN2, m_spin2);
170         DDX_Control(pDX, IDC_SPIN1, m_spin1);
171         DDX_CBIndex(pDX, IDC_AI_CLASS, m_ai_class);
172         DDX_CBIndex(pDX, IDC_GUN1, m_gun1);
173         DDX_CBIndex(pDX, IDC_GUN2, m_gun2);
174         DDX_CBIndex(pDX, IDC_GUN3, m_gun3);
175         DDX_CBIndex(pDX, IDC_MISSILE1, m_missile1);
176         DDX_CBIndex(pDX, IDC_MISSILE2, m_missile2);
177         DDX_CBIndex(pDX, IDC_MISSILE3, m_missile3);
178         DDX_CBIndex(pDX, IDC_MISSILE4, m_missile4);
179         DDX_LBIndex(pDX, IDC_LIST, m_cur_item);
180         //}}AFX_DATA_MAP
181
182         if (pDX->m_bSaveAndValidate) {
183                 GetDlgItem(IDC_AMMO1)->GetWindowText(str);
184                 if (save_number((char *) (LPCSTR) str, &m_ammo1)) {
185                         m_ammo_max1 = (m_missile1 <= 0) ? 0 : get_max_ammo_count_for_bank(m_ship_class, 0, m_missile1 + First_secondary_index - 1);
186                         if (m_ammo1 < 0)
187                                 m_ammo1 = 0;
188                         if (m_ammo1 > m_ammo_max1)
189                                 m_ammo1 = m_ammo_max1;
190                 }
191
192                 GetDlgItem(IDC_AMMO2)->GetWindowText(str);
193                 if (save_number((char *) (LPCSTR) str, &m_ammo2)) {
194                         m_ammo_max2 = (m_missile2 <= 0) ? 0 : get_max_ammo_count_for_bank(m_ship_class, 1, m_missile2 + First_secondary_index - 1);
195                         if (m_ammo2 < 0)
196                                 m_ammo2 = 0;
197                         if (m_ammo2 > m_ammo_max2)
198                                 m_ammo2 = m_ammo_max2;
199                 }
200
201                 GetDlgItem(IDC_AMMO3)->GetWindowText(str);
202                 if (save_number((char *) (LPCSTR) str, &m_ammo3)) {
203                         m_ammo_max3 = (m_missile3 <= 0) ? 0 : get_max_ammo_count_for_bank(m_ship_class, 2, m_missile3 + First_secondary_index - 1);
204                         if (m_ammo3 < 0)
205                                 m_ammo3 = 0;
206                         if (m_ammo3 > m_ammo_max3)
207                                 m_ammo3 = m_ammo_max3;
208                 }
209
210                 GetDlgItem(IDC_AMMO4)->GetWindowText(str);
211                 if (save_number((char *) (LPCSTR) str, &m_ammo4)) {
212                         m_ammo_max4 = (m_missile4 <= 0) ? 0 : get_max_ammo_count_for_bank(m_ship_class, 3, m_missile4 + First_secondary_index - 1);
213                         if (m_ammo4 < 0)
214                                 m_ammo4 = 0;
215                         if (m_ammo4 > m_ammo_max4)
216                                 m_ammo4 = m_ammo_max4;
217                 }
218
219                 m_spin1.SetRange(0, m_ammo_max1);
220                 m_spin2.SetRange(0, m_ammo_max2);
221                 m_spin3.SetRange(0, m_ammo_max3);
222                 m_spin4.SetRange(0, m_ammo_max4);
223
224         } else {
225                 if (m_ammo1 != BLANK_FIELD)
226                         DDX_Text(pDX, IDC_AMMO1, m_ammo1);
227                 else
228                         GetDlgItem(IDC_AMMO1)->SetWindowText("");
229
230                 if (m_ammo2 != BLANK_FIELD)
231                         DDX_Text(pDX, IDC_AMMO2, m_ammo2);
232                 else
233                         GetDlgItem(IDC_AMMO2)->SetWindowText("");
234
235                 if (m_ammo3 != BLANK_FIELD)
236                         DDX_Text(pDX, IDC_AMMO3, m_ammo3);
237                 else
238                         GetDlgItem(IDC_AMMO3)->SetWindowText("");
239
240                 if (m_ammo4 != BLANK_FIELD)
241                         DDX_Text(pDX, IDC_AMMO4, m_ammo4);
242                 else
243                         GetDlgItem(IDC_AMMO4)->SetWindowText("");
244         }
245 }
246
247 BEGIN_MESSAGE_MAP(WeaponEditorDlg, CDialog)
248         //{{AFX_MSG_MAP(WeaponEditorDlg)
249         ON_LBN_SELCHANGE(IDC_LIST, OnSelchangeList)
250         ON_WM_CLOSE()
251         ON_CBN_SELCHANGE(IDC_MISSILE1, OnSelchangeMissile1)
252         ON_CBN_SELCHANGE(IDC_MISSILE2, OnSelchangeMissile2)
253         ON_CBN_SELCHANGE(IDC_MISSILE3, OnSelchangeMissile3)
254         ON_CBN_SELCHANGE(IDC_MISSILE4, OnSelchangeMissile4)
255         //}}AFX_MSG_MAP
256 END_MESSAGE_MAP()
257
258 /////////////////////////////////////////////////////////////////////////////
259 // WeaponEditorDlg message handlers
260
261 BOOL WeaponEditorDlg::OnInitDialog() 
262 {
263         int i, z, big = 1, end1, end2, inst, flag = 0;
264         object *ptr;
265         model_subsystem *psub;
266         ship_subsys *ssl, *pss;
267         CComboBox *box;
268         CListBox *list;
269
270         CDialog::OnInitDialog();
271         m_ship = cur_ship;
272         if (m_ship == -1)
273                 m_ship = Objects[cur_object_index].instance;
274
275         end1 = First_secondary_index;
276         end2 = Num_weapon_types;
277
278         list = (CListBox *) GetDlgItem(IDC_LIST);
279
280         z = list->AddString("Pilot");
281         if (m_multi_edit) {
282                 list->SetItemDataPtr(z, &pilot);
283                 ptr = GET_FIRST(&obj_used_list);
284                 while (ptr != END_OF_LIST(&obj_used_list)) {
285                         if (((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) && (ptr->flags & OF_MARKED)) {
286                                 inst = ptr->instance;
287                                 if (!(ship_get_SIF(inst) & (SIF_BIG_SHIP | SIF_HUGE_SHIP)))
288                                         big = 0;
289
290                                 if (!flag) {
291                                         pilot = Ships[inst].weapons;
292                                         m_ship_class = Ships[inst].ship_info_index;
293                                         flag = 1;
294
295                                 } else {
296                                         SDL_assert(Ships[inst].ship_info_index == m_ship_class);
297                                         if (pilot.ai_class != Ships[inst].weapons.ai_class)
298                                                 pilot.ai_class = BLANK_FIELD;
299
300                                         for (i=0; i<MAX_PRIMARY_BANKS; i++)
301                                                 if (pilot.primary_bank_weapons[i] != Ships[inst].weapons.primary_bank_weapons[i])
302                                                         pilot.primary_bank_weapons[i] = BLANK_FIELD;
303
304                                         for (i=0; i<MAX_SECONDARY_BANKS; i++) {
305                                                 if (pilot.secondary_bank_weapons[i] != Ships[inst].weapons.secondary_bank_weapons[i])
306                                                         pilot.secondary_bank_weapons[i] = BLANK_FIELD;
307                                                 if (pilot.secondary_bank_ammo[i] != Ships[inst].weapons.secondary_bank_ammo[i])
308                                                         pilot.secondary_bank_ammo[i] = BLANK_FIELD;
309                                         }
310                                 }
311                         }
312
313                         ptr = GET_NEXT(ptr);
314                 }
315
316         } else {
317                 if (!(ship_get_SIF(m_ship) & (SIF_BIG_SHIP | SIF_HUGE_SHIP)))
318                         big = 0;
319
320                 m_ship_class = Ships[m_ship].ship_info_index;
321                 list->SetItemDataPtr(z, &Ships[m_ship].weapons);
322                 ssl = &Ships[m_ship].subsys_list;
323                 for (pss = GET_FIRST(ssl); pss != END_OF_LIST(ssl); pss = GET_NEXT(pss)) {
324                         psub = pss->system_info;
325                         if (psub->type == SUBSYSTEM_TURRET) {
326                                 z = list->AddString(psub->subobj_name);
327                                 list->SetItemDataPtr(z, &pss->weapons);
328                         }
329                 }
330         }
331
332         box = (CComboBox *) GetDlgItem(IDC_AI_CLASS);
333         for (i=0; i<Num_ai_classes; i++){
334                 box->AddString(Ai_class_names[i]);
335         }
336
337         for (i=0; i<end1; i++){
338                 if ((Weapon_info[i].wi_flags & WIF_CHILD) || (!big && (Weapon_info[i].wi_flags & WIF_BIG_ONLY))){
339                         end1 = i;
340                 }
341         }
342
343         box = (CComboBox *) GetDlgItem(IDC_GUN1);
344         box->AddString("None");
345         for (i=0; i<end1; i++){
346                 box->AddString(Weapon_info[i].name);
347         }
348
349         box = (CComboBox *) GetDlgItem(IDC_GUN2);
350         box->AddString("None");
351         for (i=0; i<end1; i++){
352                 box->AddString(Weapon_info[i].name);
353         }
354
355         box = (CComboBox *) GetDlgItem(IDC_GUN3);
356         box->AddString("None");
357         for (i=0; i<end1; i++){
358                 box->AddString(Weapon_info[i].name);
359         }
360
361         for (i=First_secondary_index; i<end2; i++){
362                 if ((Weapon_info[i].wi_flags & WIF_CHILD) || (!big && (Weapon_info[i].wi_flags & WIF_BIG_ONLY))){
363                         end2 = i;
364                 }
365         }
366
367         box = (CComboBox *) GetDlgItem(IDC_MISSILE1);
368         box->AddString("None");
369         for (i=First_secondary_index; i<end2; i++){
370                 box->AddString(Weapon_info[i].name);
371         }
372
373         box = (CComboBox *) GetDlgItem(IDC_MISSILE2);
374         box->AddString("None");
375         for (i=First_secondary_index; i<end2; i++){
376                 box->AddString(Weapon_info[i].name);
377         }
378
379         box = (CComboBox *) GetDlgItem(IDC_MISSILE3);
380         box->AddString("None");
381         for (i=First_secondary_index; i<end2; i++){
382                 box->AddString(Weapon_info[i].name);
383         }
384
385         box = (CComboBox *) GetDlgItem(IDC_MISSILE4);
386         box->AddString("None");
387         for (i=First_secondary_index; i<end2; i++){
388                 box->AddString(Weapon_info[i].name);
389         }
390
391         m_cur_item = 0;
392         UpdateData(FALSE);
393         change_selection();
394         UpdateData(TRUE);
395         return TRUE;
396 }
397
398 void WeaponEditorDlg::OnSelchangeList() 
399 {
400         UpdateData(TRUE);
401         UpdateData(TRUE);
402         change_selection();
403 }
404
405 void WeaponEditorDlg::change_selection()
406 {
407         CString a1, a2, a3, a4;
408
409         GetDlgItem(IDC_AMMO1)->GetWindowText(a1);
410         GetDlgItem(IDC_AMMO2)->GetWindowText(a2);
411         GetDlgItem(IDC_AMMO3)->GetWindowText(a3);
412         GetDlgItem(IDC_AMMO4)->GetWindowText(a4);
413
414         if (m_last_item >= 0) {
415                 cur_weapon->ai_class = m_ai_class;
416                 cur_weapon->primary_bank_weapons[0] = m_gun1 - 1;
417                 cur_weapon->primary_bank_weapons[1] = m_gun2 - 1;
418                 cur_weapon->primary_bank_weapons[2] = m_gun3 - 1;
419                 if (m_missile1 > 0)
420                         m_missile1 += First_secondary_index;
421
422                 cur_weapon->secondary_bank_weapons[0] = m_missile1 - 1;
423                 if (m_missile2 > 0)
424                         m_missile2 += First_secondary_index;
425
426                 cur_weapon->secondary_bank_weapons[1] = m_missile2 - 1;
427                 if (m_missile3 > 0)
428                         m_missile3 += First_secondary_index;
429
430                 cur_weapon->secondary_bank_weapons[2] = m_missile3 - 1;
431                 if (m_missile4 > 0)
432                         m_missile4 += First_secondary_index;
433
434                 cur_weapon->secondary_bank_weapons[3] = m_missile4 - 1;
435                 cur_weapon->secondary_bank_ammo[0] = m_ammo_max1 ? (m_ammo1 * 100 / m_ammo_max1) : 0;
436                 cur_weapon->secondary_bank_ammo[1] = m_ammo_max2 ? (m_ammo2 * 100 / m_ammo_max2) : 0;
437                 cur_weapon->secondary_bank_ammo[2] = m_ammo_max3 ? (m_ammo3 * 100 / m_ammo_max3) : 0;
438                 cur_weapon->secondary_bank_ammo[3] = m_ammo_max4 ? (m_ammo4 * 100 / m_ammo_max4) : 0;
439                 if (m_multi_edit) {
440                         if (!strlen(a1))
441                                 cur_weapon->secondary_bank_ammo[0] = BLANK_FIELD;
442                         if (!strlen(a2))
443                                 cur_weapon->secondary_bank_ammo[1] = BLANK_FIELD;
444                         if (!strlen(a3))
445                                 cur_weapon->secondary_bank_ammo[2] = BLANK_FIELD;
446                         if (!strlen(a4))
447                                 cur_weapon->secondary_bank_ammo[3] = BLANK_FIELD;
448                 }
449         }
450
451         m_gun1 = m_gun2 = m_gun3 = m_missile1 = m_missile2 = m_missile3 = m_missile4 = -1;
452         m_ammo1 = m_ammo2 = m_ammo3 = m_ammo4 = BLANK_FIELD;
453         m_ammo_max1 = m_ammo_max2 = m_ammo_max3 = m_ammo_max4 = 0;
454         if (m_cur_item < 0) {
455                 m_last_item = m_cur_item;
456                 GetDlgItem(IDC_GUN1)->EnableWindow(FALSE);
457                 GetDlgItem(IDC_GUN2)->EnableWindow(FALSE);
458                 GetDlgItem(IDC_GUN3)->EnableWindow(FALSE);
459                 GetDlgItem(IDC_MISSILE1)->EnableWindow(FALSE);
460                 GetDlgItem(IDC_MISSILE2)->EnableWindow(FALSE);
461                 GetDlgItem(IDC_MISSILE3)->EnableWindow(FALSE);
462                 GetDlgItem(IDC_MISSILE4)->EnableWindow(FALSE);
463                 GetDlgItem(IDC_AMMO1)->EnableWindow(FALSE);
464                 GetDlgItem(IDC_AMMO2)->EnableWindow(FALSE);
465                 GetDlgItem(IDC_AMMO3)->EnableWindow(FALSE);
466                 GetDlgItem(IDC_AMMO4)->EnableWindow(FALSE);
467                 GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
468                 GetDlgItem(IDC_SPIN2)->EnableWindow(FALSE);
469                 GetDlgItem(IDC_SPIN3)->EnableWindow(FALSE);
470                 GetDlgItem(IDC_SPIN4)->EnableWindow(FALSE);
471                 GetDlgItem(IDC_AI_CLASS)->EnableWindow(FALSE);
472                 UpdateData(FALSE);
473                 return;
474         }
475
476         cur_weapon = (ship_weapon *) ((CListBox *) GetDlgItem(IDC_LIST))->GetItemDataPtr(m_cur_item);
477         GetDlgItem(IDC_AI_CLASS)->EnableWindow(TRUE);
478         m_ai_class = cur_weapon->ai_class;
479
480         if (cur_weapon->num_primary_banks > 0) {
481                 m_gun1 = cur_weapon->primary_bank_weapons[0] + 1;
482                 GetDlgItem(IDC_GUN1)->EnableWindow(TRUE);
483         } else
484                 GetDlgItem(IDC_GUN1)->EnableWindow(FALSE);
485
486         if (cur_weapon->num_primary_banks > 1) {
487                 m_gun2 = cur_weapon->primary_bank_weapons[1] + 1;
488                 GetDlgItem(IDC_GUN2)->EnableWindow(TRUE);
489         } else
490                 GetDlgItem(IDC_GUN2)->EnableWindow(FALSE);
491
492         if (cur_weapon->num_primary_banks > 2) {
493                 m_gun3 = cur_weapon->primary_bank_weapons[2] + 1;
494                 GetDlgItem(IDC_GUN3)->EnableWindow(TRUE);
495         } else
496                 GetDlgItem(IDC_GUN3)->EnableWindow(FALSE);
497
498         if (cur_weapon->num_secondary_banks > 0) {
499                 m_missile1 = cur_weapon->secondary_bank_weapons[0] + 1;
500                 if (m_missile1 > 0) {
501                         m_ammo_max1 = get_max_ammo_count_for_bank(m_ship_class, 0, m_missile1 - 1);
502                         if (cur_weapon->secondary_bank_ammo[0] != BLANK_FIELD)
503                                 m_ammo1 = cur_weapon->secondary_bank_ammo[0] * m_ammo_max1 / 100;
504                         m_missile1 -= First_secondary_index;
505                 }
506
507                 GetDlgItem(IDC_MISSILE1)->EnableWindow(TRUE);
508                 GetDlgItem(IDC_AMMO1)->EnableWindow(TRUE);
509                 GetDlgItem(IDC_SPIN1)->EnableWindow(TRUE);
510
511         } else {
512                 GetDlgItem(IDC_MISSILE1)->EnableWindow(FALSE);
513                 GetDlgItem(IDC_AMMO1)->EnableWindow(FALSE);
514                 GetDlgItem(IDC_SPIN1)->EnableWindow(FALSE);
515         }
516
517         if (cur_weapon->num_secondary_banks > 1) {
518                 m_missile2 = cur_weapon->secondary_bank_weapons[1] + 1;
519                 if (m_missile2 > 0) {
520                         m_ammo_max2 = get_max_ammo_count_for_bank(m_ship_class, 1, m_missile2 - 1);
521                         if (cur_weapon->secondary_bank_ammo[1] != BLANK_FIELD)
522                                 m_ammo2 = cur_weapon->secondary_bank_ammo[1] * m_ammo_max2 / 100;
523                         m_missile2 -= First_secondary_index;
524                 }
525
526                 GetDlgItem(IDC_MISSILE2)->EnableWindow(TRUE);
527                 GetDlgItem(IDC_AMMO2)->EnableWindow(TRUE);
528                 GetDlgItem(IDC_SPIN2)->EnableWindow(TRUE);
529
530         } else {
531                 GetDlgItem(IDC_MISSILE2)->EnableWindow(FALSE);
532                 GetDlgItem(IDC_AMMO2)->EnableWindow(FALSE);
533                 GetDlgItem(IDC_SPIN2)->EnableWindow(FALSE);
534         }
535
536         if (cur_weapon->num_secondary_banks > 2) {
537                 m_missile3 = cur_weapon->secondary_bank_weapons[2] + 1;
538                 if (m_missile3 > 0) {
539                         m_ammo_max3 = get_max_ammo_count_for_bank(m_ship_class, 2, m_missile3 - 1);
540                         if (cur_weapon->secondary_bank_ammo[2] != BLANK_FIELD)
541                                 m_ammo3 = cur_weapon->secondary_bank_ammo[2] * m_ammo_max3 / 100;
542                         m_missile3 -= First_secondary_index;
543                 }
544
545                 GetDlgItem(IDC_MISSILE3)->EnableWindow(TRUE);
546                 GetDlgItem(IDC_AMMO3)->EnableWindow(TRUE);
547                 GetDlgItem(IDC_SPIN3)->EnableWindow(TRUE);
548
549         } else {
550                 GetDlgItem(IDC_MISSILE3)->EnableWindow(FALSE);
551                 GetDlgItem(IDC_AMMO3)->EnableWindow(FALSE);
552                 GetDlgItem(IDC_SPIN3)->EnableWindow(FALSE);
553         }
554
555         if (cur_weapon->num_secondary_banks > 3) {
556                 m_missile4 = cur_weapon->secondary_bank_weapons[3] + 1;
557                 if (m_missile4 > 0) {
558                         m_ammo_max4 = get_max_ammo_count_for_bank(m_ship_class, 3, m_missile4 - 1);
559                         if (cur_weapon->secondary_bank_ammo[3] != BLANK_FIELD)
560                                 m_ammo4 = cur_weapon->secondary_bank_ammo[3] * m_ammo_max4 / 100;
561                         m_missile4 -= First_secondary_index;
562                 }
563
564                 GetDlgItem(IDC_MISSILE4)->EnableWindow(TRUE);
565                 GetDlgItem(IDC_AMMO4)->EnableWindow(TRUE);
566                 GetDlgItem(IDC_SPIN4)->EnableWindow(TRUE);
567
568         } else {
569                 GetDlgItem(IDC_MISSILE4)->EnableWindow(FALSE);
570                 GetDlgItem(IDC_AMMO4)->EnableWindow(FALSE);
571                 GetDlgItem(IDC_SPIN4)->EnableWindow(FALSE);
572         }
573
574         m_last_item = m_cur_item;
575         UpdateData(FALSE);
576         if (m_multi_edit) {
577                 if (m_ammo1 == BLANK_FIELD)
578                         GetDlgItem(IDC_AMMO1)->SetWindowText("");
579                 if (m_ammo2 == BLANK_FIELD)
580                         GetDlgItem(IDC_AMMO2)->SetWindowText("");
581                 if (m_ammo3 == BLANK_FIELD)
582                         GetDlgItem(IDC_AMMO3)->SetWindowText("");
583                 if (m_ammo4 == BLANK_FIELD)
584                         GetDlgItem(IDC_AMMO4)->SetWindowText("");
585         }
586 }
587
588 void WeaponEditorDlg::OnOK()
589 {
590         UpdateData(TRUE);
591         UpdateData(TRUE);
592         change_selection();
593         update_pilot();
594         CDialog::OnOK();
595 }
596
597 void WeaponEditorDlg::OnCancel()
598 {
599         UpdateData(TRUE);
600         UpdateData(TRUE);
601         change_selection();
602         update_pilot();
603         CDialog::OnCancel();
604 }
605
606 void WeaponEditorDlg::OnClose() 
607 {
608         UpdateData(TRUE);
609         UpdateData(TRUE);
610         change_selection();
611         update_pilot();
612         CDialog::OnClose();
613 }
614
615 void WeaponEditorDlg::update_pilot()
616 {
617         int i;
618         object *ptr;
619         ship_weapon *weapon;
620
621         if (m_multi_edit) {
622                 ptr = GET_FIRST(&obj_used_list);
623                 while (ptr != END_OF_LIST(&obj_used_list)) {
624                         if (((ptr->type == OBJ_SHIP) || (ptr->type == OBJ_START)) && (ptr->flags & OF_MARKED)) {
625                                 weapon = &Ships[ptr->instance].weapons;
626
627                                 if (pilot.ai_class >= 0)
628                                         weapon->ai_class = pilot.ai_class;
629                                 
630                                 for (i=0; i<MAX_PRIMARY_BANKS; i++)
631                                         if (pilot.primary_bank_weapons[i] != -2)
632                                                 weapon->primary_bank_weapons[i] = pilot.primary_bank_weapons[i];
633
634                                 for (i=0; i<MAX_SECONDARY_BANKS; i++) {
635                                         if (pilot.secondary_bank_weapons[i] != -2)
636                                                 weapon->secondary_bank_weapons[i] = pilot.secondary_bank_weapons[i];
637                                         if (pilot.secondary_bank_ammo[i] >= 0)
638                                                 weapon->secondary_bank_ammo[i] = pilot.secondary_bank_ammo[i];
639                                 }
640                         }
641
642                         ptr = GET_NEXT(ptr);
643                 }
644         }
645 }
646
647 void WeaponEditorDlg::OnSelchangeMissile1() 
648 {
649         UpdateData(TRUE);
650         UpdateData(TRUE);
651         m_ammo_max1 = get_max_ammo_count_for_bank(m_ship_class, 0, m_missile1 + First_secondary_index - 1);
652         m_ammo1 = m_ammo_max1 ? (m_ammo_max1) : 0;
653         change_selection();
654 }
655
656 void WeaponEditorDlg::OnSelchangeMissile2() 
657 {
658         UpdateData(TRUE);
659         UpdateData(TRUE);
660         m_ammo_max2 = get_max_ammo_count_for_bank(m_ship_class, 0, m_missile2 + First_secondary_index - 1);
661         m_ammo2 = m_ammo_max2 ? (m_ammo_max2) : 0;
662         change_selection();
663 }
664
665 void WeaponEditorDlg::OnSelchangeMissile3() 
666 {
667         UpdateData(TRUE);
668         UpdateData(TRUE);
669         m_ammo_max3 = get_max_ammo_count_for_bank(m_ship_class, 0, m_missile3 + First_secondary_index - 1);
670         m_ammo3 = m_ammo_max3 ? (m_ammo_max3) : 0;
671         change_selection();
672 }
673
674 void WeaponEditorDlg::OnSelchangeMissile4() 
675 {
676         UpdateData(TRUE);
677         UpdateData(TRUE);
678         m_ammo_max4 = get_max_ammo_count_for_bank(m_ship_class, 0, m_missile4 + First_secondary_index - 1);
679         m_ammo4 = m_ammo_max4 ? (m_ammo_max4) : 0;
680         change_selection();
681 }
682