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