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