]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/shipspecialdamage.cpp
Initial revision
[taylor/freespace2.git] / src / fred2 / shipspecialdamage.cpp
1 // ShipSpecialDamage.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "fred.h"
6 #include "shipspecialdamage.h"
7 #include "linklist.h"
8 #include "sexp.h"
9 #include "freddoc.h"
10
11 #ifdef _DEBUG
12 #define new DEBUG_NEW
13 #undef THIS_FILE
14 static char THIS_FILE[] = __FILE__;
15 #endif
16
17 /////////////////////////////////////////////////////////////////////////////
18 // ShipSpecialDamage dialog
19
20
21 ShipSpecialDamage::ShipSpecialDamage(CWnd* pParent /*=NULL*/)
22         : CDialog(ShipSpecialDamage::IDD, pParent)
23 {
24         //{{AFX_DATA_INIT(ShipSpecialDamage)
25         //}}AFX_DATA_INIT
26 }
27
28
29 void ShipSpecialDamage::DoDataExchange(CDataExchange* pDX)
30 {
31         CDialog::DoDataExchange(pDX);
32         //{{AFX_DATA_MAP(ShipSpecialDamage)
33         DDX_Check(pDX, IDC_ENABLE_SHOCKWAVE, m_shock_enabled);
34         DDX_Check(pDX, IDC_ENABLE_SPECIAL_EXP, m_special_exp_enabled);
35         DDX_Text(pDX, IDC_SPECIAL_INNER_RAD, m_inner_rad);
36         DDV_MinMaxInt(pDX, m_inner_rad, 10, 10000);
37         DDX_Text(pDX, IDC_SPECIAL_OUTER_RAD, m_outer_rad);
38         DDV_MinMaxInt(pDX, m_outer_rad, 11, 10000);
39         DDX_Text(pDX, IDC_SPECIAL_DAMAGE, m_damage);
40         DDV_MinMaxInt(pDX, m_damage, 0, 100000);
41         DDX_Text(pDX, IDC_SPECIAL_SHOCK_SPEED, m_shock_speed);
42         DDV_MinMaxInt(pDX, m_shock_speed, 10, 1000);
43         DDX_Text(pDX, IDC_SPECIAL_BLAST, m_blast);
44         DDV_MinMaxInt(pDX, m_blast, 0, 100000);
45         //}}AFX_DATA_MAP
46 }
47
48
49 BEGIN_MESSAGE_MAP(ShipSpecialDamage, CDialog)
50         //{{AFX_MSG_MAP(ShipSpecialDamage)
51         ON_BN_CLICKED(IDC_ENABLE_SHOCKWAVE, OnEnableShockwave)
52         ON_BN_CLICKED(IDC_ENABLE_SPECIAL_EXP, OnEnableSpecialExp)
53         //}}AFX_MSG_MAP
54 END_MESSAGE_MAP()
55
56 /////////////////////////////////////////////////////////////////////////////
57 // ShipSpecialDamage message handlers
58
59 void ShipSpecialDamage::OnEnableShockwave() 
60 {
61         // TODO: Add your control notification handler code here
62         UpdateData(TRUE);
63
64         // enable/disable shock speed
65         DoGray();}
66
67 void ShipSpecialDamage::OnEnableSpecialExp() 
68 {
69         // TODO: Add your control notification handler code here
70         UpdateData(TRUE);
71
72         DoGray();
73 }
74
75 BOOL ShipSpecialDamage::OnInitDialog() 
76 {
77         
78         // TODO: Add extra initialization here
79
80         // get ship num
81         object *objp;
82
83         m_ship_num = -1;
84
85         objp = GET_FIRST(&obj_used_list);
86         while (objp != END_OF_LIST(&obj_used_list)) {
87                 if ((objp->type == OBJ_START) || (objp->type == OBJ_SHIP)) {
88                         if (objp->flags & OF_MARKED) {
89
90                                 m_ship_num = objp->instance;
91                                 break;
92                         }
93                 }
94                 objp = GET_NEXT(objp);
95         }
96
97         if (Ships[m_ship_num].special_exp_index == -1) {
98                 // get default_table_values
99                 ship_info *sip;
100                 sip = &Ship_info[Ships[m_ship_num].ship_info_index];
101
102                 m_inner_rad = (int)sip->inner_rad;
103                 m_outer_rad = (int)sip->outer_rad;
104                 m_damage = (int) sip->damage;
105                 m_blast = (int) sip->blast;
106                 m_shock_enabled = (int) sip->explosion_propagates;
107                 m_shock_speed = (int) sip->shockwave_speed;
108                 m_special_exp_enabled = FALSE;
109
110                 if (m_inner_rad < 10) m_inner_rad = 10;
111                 if (m_outer_rad < 11) m_outer_rad = 11;
112                 if (m_shock_speed < 10) m_shock_speed = 10;
113         } else {
114                 int index = Ships[m_ship_num].special_exp_index;
115                 Assert( (index > 0) && (index < MAX_SEXP_VARIABLES-5) );
116
117                 m_inner_rad = atoi(Sexp_variables[index++].text);
118                 m_outer_rad = atoi(Sexp_variables[index++].text);
119                 m_damage = atoi(Sexp_variables[index++].text);
120                 m_blast = atoi(Sexp_variables[index++].text);
121                 m_shock_enabled = atoi(Sexp_variables[index++].text);
122                 m_shock_speed = atoi(Sexp_variables[index++].text);
123                 m_special_exp_enabled = TRUE;
124         }
125
126         CDialog::OnInitDialog();
127
128         // maybe gray out lots of stuff
129         DoGray();
130
131         return TRUE;  // return TRUE unless you set the focus to a control
132                       // EXCEPTION: OCX Property Pages should return FALSE
133 }
134
135 void ShipSpecialDamage::DoGray()
136 {
137         GetDlgItem(IDC_SPECIAL_DAMAGE)->EnableWindow(m_special_exp_enabled);
138         GetDlgItem(IDC_SPECIAL_BLAST)->EnableWindow(m_special_exp_enabled);
139         GetDlgItem(IDC_SPECIAL_INNER_RAD)->EnableWindow(m_special_exp_enabled);
140         GetDlgItem(IDC_SPECIAL_OUTER_RAD)->EnableWindow(m_special_exp_enabled);
141         GetDlgItem(IDC_ENABLE_SHOCKWAVE)->EnableWindow(m_special_exp_enabled);
142         GetDlgItem(IDC_SPECIAL_SHOCK_SPEED)->EnableWindow(m_special_exp_enabled && m_shock_enabled);
143 }
144
145
146 void ShipSpecialDamage::OnCancel() 
147 {
148         // TODO: Add extra cleanup here
149         
150         CDialog::OnCancel();
151 }
152
153 void ShipSpecialDamage::OnOK() 
154 {
155         UpdateData(TRUE);
156
157         // TODO: Add extra validation here
158         if (m_special_exp_enabled) {
159
160                 int start;
161
162                 if (m_inner_rad > m_outer_rad) {
163                         MessageBox("Inner radius must be less than outer radius");
164                         return;
165                 }
166
167                 if (Ships[m_ship_num].special_exp_index == -1) {
168                         // get free sexp_variables
169                         start = sexp_variable_allocate_block(Ships[m_ship_num].ship_name, SEXP_VARIABLE_BLOCK | SEXP_VARIABLE_BLOCK_EXP);
170                         if (start == -1) {
171                                 MessageBox("Unable to allocate storage, try deleting Sexp variables");
172                                 return;
173                         } else {
174                                 Ships[m_ship_num].special_exp_index = start;
175                         }
176                 } else {
177                         start = Ships[m_ship_num].special_exp_index;
178                 }
179                 // set to update
180                 set_modified();
181
182                 // set em
183                 sprintf(Sexp_variables[start+INNER_RAD].text, "%d", m_inner_rad);
184                 sprintf(Sexp_variables[start+OUTER_RAD].text, "%d", m_outer_rad);
185                 sprintf(Sexp_variables[start+DAMAGE].text, "%d", m_damage);
186                 sprintf(Sexp_variables[start+BLAST].text, "%d", m_blast);
187                 sprintf(Sexp_variables[start+PROPAGATE].text, "%d", m_shock_enabled);
188                 sprintf(Sexp_variables[start+SHOCK_SPEED].text, "%d", m_shock_speed);
189
190         } else {
191                 if (Ships[m_ship_num].special_exp_index != -1) {
192                         // set to update
193                         set_modified();
194
195                         // free block
196                         sexp_variable_block_free(Ships[m_ship_num].ship_name, Ships[m_ship_num].special_exp_index, SEXP_VARIABLE_BLOCK |SEXP_VARIABLE_BLOCK_EXP);
197
198                         // set index to no exp block
199                         Ships[m_ship_num].special_exp_index = -1;
200                 }
201         }
202
203         CDialog::OnOK();
204 }