2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
9 // ShipSpecialDamage.cpp : implementation file
14 #include "shipspecialdamage.h"
22 static char THIS_FILE[] = __FILE__;
25 /////////////////////////////////////////////////////////////////////////////
26 // ShipSpecialDamage dialog
29 ShipSpecialDamage::ShipSpecialDamage(CWnd* pParent /*=NULL*/)
30 : CDialog(ShipSpecialDamage::IDD, pParent)
32 //{{AFX_DATA_INIT(ShipSpecialDamage)
37 void ShipSpecialDamage::DoDataExchange(CDataExchange* pDX)
39 CDialog::DoDataExchange(pDX);
40 //{{AFX_DATA_MAP(ShipSpecialDamage)
41 DDX_Check(pDX, IDC_ENABLE_SHOCKWAVE, m_shock_enabled);
42 DDX_Check(pDX, IDC_ENABLE_SPECIAL_EXP, m_special_exp_enabled);
43 DDX_Text(pDX, IDC_SPECIAL_INNER_RAD, m_inner_rad);
44 DDV_MinMaxInt(pDX, m_inner_rad, 10, 10000);
45 DDX_Text(pDX, IDC_SPECIAL_OUTER_RAD, m_outer_rad);
46 DDV_MinMaxInt(pDX, m_outer_rad, 11, 10000);
47 DDX_Text(pDX, IDC_SPECIAL_DAMAGE, m_damage);
48 DDV_MinMaxInt(pDX, m_damage, 0, 100000);
49 DDX_Text(pDX, IDC_SPECIAL_SHOCK_SPEED, m_shock_speed);
50 DDV_MinMaxInt(pDX, m_shock_speed, 10, 1000);
51 DDX_Text(pDX, IDC_SPECIAL_BLAST, m_blast);
52 DDV_MinMaxInt(pDX, m_blast, 0, 100000);
57 BEGIN_MESSAGE_MAP(ShipSpecialDamage, CDialog)
58 //{{AFX_MSG_MAP(ShipSpecialDamage)
59 ON_BN_CLICKED(IDC_ENABLE_SHOCKWAVE, OnEnableShockwave)
60 ON_BN_CLICKED(IDC_ENABLE_SPECIAL_EXP, OnEnableSpecialExp)
64 /////////////////////////////////////////////////////////////////////////////
65 // ShipSpecialDamage message handlers
67 void ShipSpecialDamage::OnEnableShockwave()
69 // TODO: Add your control notification handler code here
72 // enable/disable shock speed
75 void ShipSpecialDamage::OnEnableSpecialExp()
77 // TODO: Add your control notification handler code here
83 BOOL ShipSpecialDamage::OnInitDialog()
86 // TODO: Add extra initialization here
93 objp = GET_FIRST(&obj_used_list);
94 while (objp != END_OF_LIST(&obj_used_list)) {
95 if ((objp->type == OBJ_START) || (objp->type == OBJ_SHIP)) {
96 if (objp->flags & OF_MARKED) {
98 m_ship_num = objp->instance;
102 objp = GET_NEXT(objp);
105 if (Ships[m_ship_num].special_exp_index == -1) {
106 // get default_table_values
108 sip = &Ship_info[Ships[m_ship_num].ship_info_index];
110 m_inner_rad = (int)sip->inner_rad;
111 m_outer_rad = (int)sip->outer_rad;
112 m_damage = (int) sip->damage;
113 m_blast = (int) sip->blast;
114 m_shock_enabled = (int) sip->explosion_propagates;
115 m_shock_speed = (int) sip->shockwave_speed;
116 m_special_exp_enabled = FALSE;
118 if (m_inner_rad < 10) m_inner_rad = 10;
119 if (m_outer_rad < 11) m_outer_rad = 11;
120 if (m_shock_speed < 10) m_shock_speed = 10;
122 int index = Ships[m_ship_num].special_exp_index;
123 SDL_assert( (index > 0) && (index < MAX_SEXP_VARIABLES-5) );
125 m_inner_rad = atoi(Sexp_variables[index++].text);
126 m_outer_rad = atoi(Sexp_variables[index++].text);
127 m_damage = atoi(Sexp_variables[index++].text);
128 m_blast = atoi(Sexp_variables[index++].text);
129 m_shock_enabled = atoi(Sexp_variables[index++].text);
130 m_shock_speed = atoi(Sexp_variables[index++].text);
131 m_special_exp_enabled = TRUE;
134 CDialog::OnInitDialog();
136 // maybe gray out lots of stuff
139 return TRUE; // return TRUE unless you set the focus to a control
140 // EXCEPTION: OCX Property Pages should return FALSE
143 void ShipSpecialDamage::DoGray()
145 GetDlgItem(IDC_SPECIAL_DAMAGE)->EnableWindow(m_special_exp_enabled);
146 GetDlgItem(IDC_SPECIAL_BLAST)->EnableWindow(m_special_exp_enabled);
147 GetDlgItem(IDC_SPECIAL_INNER_RAD)->EnableWindow(m_special_exp_enabled);
148 GetDlgItem(IDC_SPECIAL_OUTER_RAD)->EnableWindow(m_special_exp_enabled);
149 GetDlgItem(IDC_ENABLE_SHOCKWAVE)->EnableWindow(m_special_exp_enabled);
150 GetDlgItem(IDC_SPECIAL_SHOCK_SPEED)->EnableWindow(m_special_exp_enabled && m_shock_enabled);
154 void ShipSpecialDamage::OnCancel()
156 // TODO: Add extra cleanup here
161 void ShipSpecialDamage::OnOK()
165 // TODO: Add extra validation here
166 if (m_special_exp_enabled) {
170 if (m_inner_rad > m_outer_rad) {
171 MessageBox("Inner radius must be less than outer radius");
175 if (Ships[m_ship_num].special_exp_index == -1) {
176 // get free sexp_variables
177 start = sexp_variable_allocate_block(Ships[m_ship_num].ship_name, SEXP_VARIABLE_BLOCK | SEXP_VARIABLE_BLOCK_EXP);
179 MessageBox("Unable to allocate storage, try deleting Sexp variables");
182 Ships[m_ship_num].special_exp_index = start;
185 start = Ships[m_ship_num].special_exp_index;
191 sprintf(Sexp_variables[start+INNER_RAD].text, "%d", m_inner_rad);
192 sprintf(Sexp_variables[start+OUTER_RAD].text, "%d", m_outer_rad);
193 sprintf(Sexp_variables[start+DAMAGE].text, "%d", m_damage);
194 sprintf(Sexp_variables[start+BLAST].text, "%d", m_blast);
195 sprintf(Sexp_variables[start+PROPAGATE].text, "%d", m_shock_enabled);
196 sprintf(Sexp_variables[start+SHOCK_SPEED].text, "%d", m_shock_speed);
199 if (Ships[m_ship_num].special_exp_index != -1) {
204 sexp_variable_block_free(Ships[m_ship_num].ship_name, Ships[m_ship_num].special_exp_index, SEXP_VARIABLE_BLOCK |SEXP_VARIABLE_BLOCK_EXP);
206 // set index to no exp block
207 Ships[m_ship_num].special_exp_index = -1;