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 "ShieldSysDlg.h"
15 #include "ship/ship.h"
16 #include "mission/missionparse.h"
17 #include "iff_defs/iff_defs.h"
18
19 #ifdef _DEBUG
20 #undef THIS_FILE
21 static char THIS_FILE[] = __FILE__;
22 #endif
23
24 int Shield_sys_teams[MAX_IFFS] = {0};
25 int Shield_sys_types[MAX_SHIP_CLASSES] = {0};
26
27 /////////////////////////////////////////////////////////////////////////////
28 // shield_sys_dlg dialog
29
shield_sys_dlg(CWnd * pParent)30 shield_sys_dlg::shield_sys_dlg(CWnd* pParent /*=NULL*/)
31 : CDialog(shield_sys_dlg::IDD, pParent)
32 {
33 //{{AFX_DATA_INIT(shield_sys_dlg)
34 m_team = 0;
35 m_type = 0;
36 //}}AFX_DATA_INIT
37 }
38
DoDataExchange(CDataExchange * pDX)39 void shield_sys_dlg::DoDataExchange(CDataExchange* pDX)
40 {
41 CDialog::DoDataExchange(pDX);
42 //{{AFX_DATA_MAP(shield_sys_dlg)
43 DDX_CBIndex(pDX, IDC_TEAM, m_team);
44 DDX_CBIndex(pDX, IDC_TYPE, m_type);
45 //}}AFX_DATA_MAP
46 }
47
BEGIN_MESSAGE_MAP(shield_sys_dlg,CDialog)48 BEGIN_MESSAGE_MAP(shield_sys_dlg, CDialog)
49 //{{AFX_MSG_MAP(shield_sys_dlg)
50 ON_CBN_SELCHANGE(IDC_TEAM, OnSelchangeTeam)
51 ON_CBN_SELCHANGE(IDC_TYPE, OnSelchangeType)
52 //}}AFX_MSG_MAP
53 END_MESSAGE_MAP()
54
55 /////////////////////////////////////////////////////////////////////////////
56 // shield_sys_dlg message handlers
57
58 BOOL shield_sys_dlg::OnInitDialog()
59 {
60 int i, z;
61 int teams[MAX_IFFS];
62 int types[MAX_SHIP_CLASSES];
63 CComboBox *box;
64
65 for (i=0; i<MAX_IFFS; i++)
66 teams[i] = 0;
67
68 for (i=0; i<MAX_SHIP_CLASSES; i++)
69 types[i] = 0;
70
71 for (i=0; i<MAX_SHIPS; i++)
72 if (Ships[i].objnum >= 0) {
73 z = (Objects[Ships[i].objnum].flags & OF_NO_SHIELDS) ? 1 : 0;
74 if (!teams[Ships[i].team])
75 Shield_sys_teams[Ships[i].team] = z;
76 else if (Shield_sys_teams[Ships[i].team] != z)
77 Shield_sys_teams[Ships[i].team] = 2;
78
79 if (!types[Ships[i].ship_info_index])
80 Shield_sys_types[Ships[i].ship_info_index] = z;
81 else if (Shield_sys_types[Ships[i].ship_info_index] != z)
82 Shield_sys_types[Ships[i].ship_info_index] = 2;
83
84 teams[Ships[i].team]++;
85 types[Ships[i].ship_info_index]++;
86 }
87
88 box = (CComboBox *) GetDlgItem(IDC_TYPE);
89 box->ResetContent();
90 for (i=0; i<Num_ship_classes; i++)
91 box->AddString(Ship_info[i].name);
92
93 box = (CComboBox *) GetDlgItem(IDC_TEAM);
94 box->ResetContent();
95 for (i=0; i<Num_iffs; i++)
96 box->AddString(Iff_info[i].iff_name);
97
98 CDialog::OnInitDialog();
99 set_team();
100 set_type();
101 return TRUE;
102 }
103
OnOK()104 void shield_sys_dlg::OnOK()
105 {
106 int i, z;
107
108 OnSelchangeTeam();
109 OnSelchangeType();
110 for (i=0; i<MAX_SHIPS; i++)
111 if (Ships[i].objnum >= 0) {
112 z = Shield_sys_teams[Ships[i].team];
113 if (!Shield_sys_types[Ships[i].ship_info_index])
114 z = 0;
115 else if (Shield_sys_types[Ships[i].ship_info_index] == 1)
116 z = 1;
117
118 if (!z)
119 Objects[Ships[i].objnum].flags &= ~OF_NO_SHIELDS;
120 else if (z == 1)
121 Objects[Ships[i].objnum].flags |= OF_NO_SHIELDS;
122 }
123
124 CDialog::OnOK();
125 }
126
OnSelchangeTeam()127 void shield_sys_dlg::OnSelchangeTeam()
128 {
129 Assert(m_team >= 0);
130 if (((CButton *) GetDlgItem(IDC_TEAM_YES))->GetCheck())
131 Shield_sys_teams[m_team] = 0;
132 else if (((CButton *) GetDlgItem(IDC_TEAM_NO))->GetCheck())
133 Shield_sys_teams[m_team] = 1;
134
135 UpdateData(TRUE);
136 set_team();
137 }
138
set_team()139 void shield_sys_dlg::set_team()
140 {
141 if (!Shield_sys_teams[m_team])
142 ((CButton *) GetDlgItem(IDC_TEAM_YES))->SetCheck(TRUE);
143 else
144 ((CButton *) GetDlgItem(IDC_TEAM_YES))->SetCheck(FALSE);
145
146 if (Shield_sys_teams[m_team] == 1)
147 ((CButton *) GetDlgItem(IDC_TEAM_NO))->SetCheck(TRUE);
148 else
149 ((CButton *) GetDlgItem(IDC_TEAM_NO))->SetCheck(FALSE);
150 }
151
OnSelchangeType()152 void shield_sys_dlg::OnSelchangeType()
153 {
154 Assert(m_type >= 0);
155 if (((CButton *) GetDlgItem(IDC_TYPE_YES))->GetCheck())
156 Shield_sys_types[m_type] = 0;
157 else if (((CButton *) GetDlgItem(IDC_TYPE_NO))->GetCheck())
158 Shield_sys_types[m_type] = 1;
159
160 UpdateData(TRUE);
161 set_type();
162 }
163
set_type()164 void shield_sys_dlg::set_type()
165 {
166 if (!Shield_sys_types[m_type])
167 ((CButton *) GetDlgItem(IDC_TYPE_YES))->SetCheck(TRUE);
168 else
169 ((CButton *) GetDlgItem(IDC_TYPE_YES))->SetCheck(FALSE);
170
171 if (Shield_sys_types[m_type] == 1)
172 ((CButton *) GetDlgItem(IDC_TYPE_NO))->SetCheck(TRUE);
173 else
174 ((CButton *) GetDlgItem(IDC_TYPE_NO))->SetCheck(FALSE);
175 }
176