FS2_Open
Open source remastering of the Freespace 2 engine
shieldsysdlg.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 "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 
26 
28 // shield_sys_dlg dialog
29 
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 
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 
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 
56 // shield_sys_dlg message handlers
57 
58 BOOL shield_sys_dlg::OnInitDialog()
59 {
60  int i, z;
61  int teams[MAX_IFFS];
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])
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 (auto it = Ship_info.cbegin(); it != Ship_info.cend(); ++it)
91  box->AddString(it->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 
105 {
106  int i, z;
107 
108  OnSelchangeTeam();
109  OnSelchangeType();
110  for (i=0; i<MAX_SHIPS; i++)
111  if (Ships[i].objnum >= 0) {
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 
128 {
129  Assert(m_team >= 0);
130  if (((CButton *) GetDlgItem(IDC_TEAM_YES))->GetCheck())
132  else if (((CButton *) GetDlgItem(IDC_TEAM_NO))->GetCheck())
134 
135  UpdateData(TRUE);
136  set_team();
137 }
138 
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 
153 {
154  Assert(m_type >= 0);
155  if (((CButton *) GetDlgItem(IDC_TYPE_YES))->GetCheck())
157  else if (((CButton *) GetDlgItem(IDC_TYPE_NO))->GetCheck())
159 
160  UpdateData(TRUE);
161  set_type();
162 }
163 
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 }
int i
Definition: multi_pxo.cpp:466
#define IDC_TYPE_NO
Definition: resource.h:897
int team
Definition: ship.h:606
int objnum
Definition: ship.h:537
#define IDC_TYPE
Definition: resource.h:579
#define MAX_SHIPS
Definition: globals.h:37
virtual void DoDataExchange(CDataExchange *pDX)
Assert(pm!=NULL)
CButton * team
#define IDC_TEAM_NO
Definition: resource.h:899
#define TRUE
Definition: pstypes.h:399
#define OF_NO_SHIELDS
Definition: object.h:110
#define IDC_TEAM
Definition: resource.h:588
iff_info Iff_info[MAX_IFFS]
Definition: iff_defs.cpp:20
#define MAX_SHIP_CLASSES
Definition: globals.h:48
GLdouble GLdouble z
Definition: Glext.h:5451
int Shield_sys_types[MAX_SHIP_CLASSES]
GLsizei GLenum GLenum * types
Definition: Glext.h:7310
virtual void OnOK()
object Objects[MAX_OBJECTS]
Definition: object.cpp:62
afx_msg void OnSelchangeTeam()
afx_msg void OnSelchangeType()
shield_sys_dlg(CWnd *pParent=NULL)
#define IDC_TYPE_YES
Definition: resource.h:896
int BOOL
Definition: config.h:80
ship Ships[MAX_SHIPS]
Definition: ship.cpp:122
int Shield_sys_teams[MAX_IFFS]
SCP_vector< ship_info > Ship_info
Definition: ship.cpp:164
#define MAX_IFFS
Definition: globals.h:34
int Num_iffs
Definition: iff_defs.cpp:19
uint flags
Definition: object.h:151
#define FALSE
Definition: pstypes.h:400
char iff_name[NAME_LENGTH]
Definition: iff_defs.h:36
#define IDC_TEAM_YES
Definition: resource.h:898