File: shieldsysdlg.cpp

package info (click to toggle)
freespace2 3.7.4%2Brepack-1.1
  • links: PTS, VCS
  • area: non-free
  • in suites: bullseye
  • size: 22,268 kB
  • sloc: cpp: 393,535; ansic: 4,106; makefile: 1,091; xml: 181; sh: 137
file content (175 lines) | stat: -rw-r--r-- 4,269 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * Copyright (C) Volition, Inc. 1999.  All rights reserved.
 *
 * All source code herein is the property of Volition, Inc. You may not sell 
 * or otherwise commercially exploit the source or things you created based on the 
 * source.
 *
*/



#include "stdafx.h"
#include "FRED.h"
#include "ShieldSysDlg.h"
#include "ship/ship.h"
#include "mission/missionparse.h"
#include "iff_defs/iff_defs.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

int Shield_sys_teams[MAX_IFFS] = {0};
int Shield_sys_types[MAX_SHIP_CLASSES] = {0};

/////////////////////////////////////////////////////////////////////////////
// shield_sys_dlg dialog

shield_sys_dlg::shield_sys_dlg(CWnd* pParent /*=NULL*/)
	: CDialog(shield_sys_dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(shield_sys_dlg)
	m_team = 0;
	m_type = 0;
	//}}AFX_DATA_INIT
}

void shield_sys_dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(shield_sys_dlg)
	DDX_CBIndex(pDX, IDC_TEAM, m_team);
	DDX_CBIndex(pDX, IDC_TYPE, m_type);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(shield_sys_dlg, CDialog)
	//{{AFX_MSG_MAP(shield_sys_dlg)
	ON_CBN_SELCHANGE(IDC_TEAM, OnSelchangeTeam)
	ON_CBN_SELCHANGE(IDC_TYPE, OnSelchangeType)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// shield_sys_dlg message handlers

BOOL shield_sys_dlg::OnInitDialog() 
{
	int i, z;
	int teams[MAX_IFFS];
	int types[MAX_SHIP_CLASSES];
	CComboBox *box;

	for (i=0; i<MAX_IFFS; i++)
		teams[i] = 0;

	for (i=0; i<MAX_SHIP_CLASSES; i++)
		types[i] = 0;

	for (i=0; i<MAX_SHIPS; i++)
		if (Ships[i].objnum >= 0) {
			z = (Objects[Ships[i].objnum].flags & OF_NO_SHIELDS) ? 1 : 0;
			if (!teams[Ships[i].team])
				Shield_sys_teams[Ships[i].team] = z;
			else if (Shield_sys_teams[Ships[i].team] != z)
				Shield_sys_teams[Ships[i].team] = 2;

			if (!types[Ships[i].ship_info_index])
				Shield_sys_types[Ships[i].ship_info_index] = z;
			else if (Shield_sys_types[Ships[i].ship_info_index] != z)
				Shield_sys_types[Ships[i].ship_info_index] = 2;

			teams[Ships[i].team]++;
			types[Ships[i].ship_info_index]++;
		}

	box = (CComboBox *) GetDlgItem(IDC_TYPE);
	box->ResetContent();
	for (auto it = Ship_info.cbegin(); it != Ship_info.cend(); ++it)
		box->AddString(it->name);

	box = (CComboBox *) GetDlgItem(IDC_TEAM);
	box->ResetContent();
	for (i=0; i<Num_iffs; i++)
		box->AddString(Iff_info[i].iff_name);

	CDialog::OnInitDialog();
	set_team();
	set_type();
	return TRUE;
}

void shield_sys_dlg::OnOK() 
{
	int i, z;

	OnSelchangeTeam();
	OnSelchangeType();
	for (i=0; i<MAX_SHIPS; i++)
		if (Ships[i].objnum >= 0) {
			z = Shield_sys_teams[Ships[i].team];
			if (!Shield_sys_types[Ships[i].ship_info_index])
				z = 0;
			else if (Shield_sys_types[Ships[i].ship_info_index] == 1)
				z = 1;

			if (!z)
				Objects[Ships[i].objnum].flags &= ~OF_NO_SHIELDS;
			else if (z == 1)
				Objects[Ships[i].objnum].flags |= OF_NO_SHIELDS;
		}

	CDialog::OnOK();
}

void shield_sys_dlg::OnSelchangeTeam()
{
	Assert(m_team >= 0);
	if (((CButton *) GetDlgItem(IDC_TEAM_YES))->GetCheck())
		Shield_sys_teams[m_team] = 0;
	else if (((CButton *) GetDlgItem(IDC_TEAM_NO))->GetCheck())
		Shield_sys_teams[m_team] = 1;

	UpdateData(TRUE);
	set_team();
}

void shield_sys_dlg::set_team()
{
	if (!Shield_sys_teams[m_team])
		((CButton *) GetDlgItem(IDC_TEAM_YES))->SetCheck(TRUE);
	else
		((CButton *) GetDlgItem(IDC_TEAM_YES))->SetCheck(FALSE);

	if (Shield_sys_teams[m_team] == 1)
		((CButton *) GetDlgItem(IDC_TEAM_NO))->SetCheck(TRUE);
	else
		((CButton *) GetDlgItem(IDC_TEAM_NO))->SetCheck(FALSE);
}

void shield_sys_dlg::OnSelchangeType()
{
	Assert(m_type >= 0);
	if (((CButton *) GetDlgItem(IDC_TYPE_YES))->GetCheck())
		Shield_sys_types[m_type] = 0;
	else if (((CButton *) GetDlgItem(IDC_TYPE_NO))->GetCheck())
		Shield_sys_types[m_type] = 1;

	UpdateData(TRUE);
	set_type();
}

void shield_sys_dlg::set_type()
{
	if (!Shield_sys_types[m_type])
		((CButton *) GetDlgItem(IDC_TYPE_YES))->SetCheck(TRUE);
	else
		((CButton *) GetDlgItem(IDC_TYPE_YES))->SetCheck(FALSE);

	if (Shield_sys_types[m_type] == 1)
		((CButton *) GetDlgItem(IDC_TYPE_NO))->SetCheck(TRUE);
	else
		((CButton *) GetDlgItem(IDC_TYPE_NO))->SetCheck(FALSE);
}