File: shipspecialhitpoints.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 (220 lines) | stat: -rw-r--r-- 5,129 bytes parent folder | download | duplicates (3)
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// ShipSpecialHitpoints.cpp : implementation file
//

#include "stdafx.h"
#include "fred.h"
#include "ShipSpecialHitpoints.h"
#include "globalincs/linklist.h"
#include "parse/sexp.h"
#include "FREDDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// ShipSpecialHitpoints dialog


ShipSpecialHitpoints::ShipSpecialHitpoints(CWnd* pParent /*=NULL*/)
	: CDialog(ShipSpecialHitpoints::IDD, pParent)
{
	//{{AFX_DATA_INIT(ShipSpecialHitpoints)
	//}}AFX_DATA_INIT
}


void ShipSpecialHitpoints::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(ShipSpecialHitpoints)
	DDX_Check(pDX, IDC_ENABLE_SPECIAL_HITPOINTS, m_special_hitpoints_enabled);
	DDX_Check(pDX, IDC_ENABLE_SPECIAL_SHIELD, m_special_shield_enabled);
	DDX_Text(pDX, IDC_SPECIAL_SHIELDS, m_shields);
	DDV_MinMaxInt(pDX, m_shields, -1, INT_MAX);
	DDX_Text(pDX, IDC_SPECIAL_HULL, m_hull);
	DDV_MinMaxInt(pDX, m_hull, 1, INT_MAX);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(ShipSpecialHitpoints, CDialog)
	//{{AFX_MSG_MAP(ShipSpecialHitpoints)
	ON_BN_CLICKED(IDC_ENABLE_SPECIAL_HITPOINTS, OnEnableSpecialHitpoints)
	ON_BN_CLICKED(IDC_ENABLE_SPECIAL_SHIELD, OnEnableSpecialShieldpoints)
	ON_BN_CLICKED(ID_OK, OnOk)
	ON_BN_CLICKED(ID_CANCEL, OnCancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// ShipSpecialHitpoints message handlers

void ShipSpecialHitpoints::OnEnableSpecialHitpoints() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	DoGray();
}

void ShipSpecialHitpoints::OnEnableSpecialShieldpoints() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	DoGray();
}

BOOL ShipSpecialHitpoints::OnInitDialog() 
{
	// get ship num
	object *objp;

	num_selected_ships = 0;

	objp = GET_FIRST(&obj_used_list);
	while (objp != END_OF_LIST(&obj_used_list)) {
		if ((objp->type == OBJ_START) || (objp->type == OBJ_SHIP)) {
			if (objp->flags & OF_MARKED) {
				m_selected_ships[num_selected_ships] = objp->instance;
				num_selected_ships++;
			}
		}
		objp = GET_NEXT(objp);
	}

	Assert(num_selected_ships);
	Assert (Objects[cur_object_index].flags & OF_MARKED);
	m_ship_num = Objects[cur_object_index].instance; 

	// get the details from the first ship
	//hull
	if (Ships[m_ship_num].special_hitpoints) {
		m_hull = Ships[m_ship_num].special_hitpoints;
		m_special_hitpoints_enabled = TRUE;
	}
	else {
		// get default_table_values
		ship_info *sip;
		sip = &Ship_info[Ships[m_ship_num].ship_info_index];

		m_hull = (int)sip->max_hull_strength;
		m_special_hitpoints_enabled = FALSE;

		if (m_hull < 1) m_hull = 10;
	}

	//shields
	if (Ships[m_ship_num].special_shield > 0){
		m_shields = Ships[m_ship_num].special_shield;
		m_special_shield_enabled = TRUE;
	}
	else {
		// get default_table_values
		ship_info *sip;
		sip = &Ship_info[Ships[m_ship_num].ship_info_index];

		m_shields = (int)sip->max_shield_strength;
		m_special_shield_enabled = FALSE;

		if (m_shields < 0) {
			m_shields = 0;
		}
	} 

	CDialog::OnInitDialog();

	// maybe gray out lots of stuff
	DoGray();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void ShipSpecialHitpoints::DoGray()
{
	GetDlgItem(IDC_SPECIAL_SHIELDS)->EnableWindow(m_special_shield_enabled);
	GetDlgItem(IDC_SPECIAL_HULL)->EnableWindow(m_special_hitpoints_enabled);
}

void ShipSpecialHitpoints::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void ShipSpecialHitpoints::OnOk() 
{
	float temp_max_hull_strength;
	int new_shield_strength, new_hull_strength;
	int i;

	UpdateData(TRUE);

	// TODO: Add extra validation here
	if (m_special_hitpoints_enabled) {

		// Don't update anything if the hull strength is invalid
		if (m_hull < 1) {
			return;
		}

		// set to update
		set_modified();

		new_hull_strength = m_hull;
		//Ships[m_ship_num].special_hitpoints = m_hull;

	} 
	else {
		// set to update
		set_modified();

		new_hull_strength = 0;
	}

	if (m_special_shield_enabled) {

		// Don't update anything if the hull strength is invalid
		if (m_shields < 0) 	{
			return;
		}

		// set to update
		set_modified();

		new_shield_strength = m_shields;
		//Ships[m_ship_num].special_shield = m_shields;

	} 
	else {
		// set to update
		set_modified();

		new_shield_strength = -1;
	}

	for ( i=0; i<num_selected_ships; i++) {
		// set the special hitpoints/shield
		Ships[m_selected_ships[i]].special_hitpoints = new_hull_strength;
		Ships[m_selected_ships[i]].special_shield = new_shield_strength;

		// calc kamikaze stuff
		if (Ships[m_selected_ships[i]].special_hitpoints)
		{
			temp_max_hull_strength = (float)Ships[m_selected_ships[i]].special_hitpoints;
		}
		else
		{
			temp_max_hull_strength = Ship_info[Ships[m_selected_ships[i]].ship_info_index].max_hull_strength;
		}

		Ai_info[Ships[m_selected_ships[i]].ai_index].kamikaze_damage = min(1000, 200 + (int)(temp_max_hull_strength / 4.0f));
	}

	
	CDialog::OnOK();
}