]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/shipspecialdamage.cpp
fix issue with looping audio streams
[taylor/freespace2.git] / src / fred2 / shipspecialdamage.cpp
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
6  * the source.
7  */
8
9 // ShipSpecialDamage.cpp : implementation file
10 //
11
12 #include "stdafx.h"
13 #include "fred.h"
14 #include "shipspecialdamage.h"
15 #include "linklist.h"
16 #include "sexp.h"
17 #include "freddoc.h"
18
19 #ifdef _DEBUG
20 #define new DEBUG_NEW
21 #undef THIS_FILE
22 static char THIS_FILE[] = __FILE__;
23 #endif
24
25 /////////////////////////////////////////////////////////////////////////////
26 // ShipSpecialDamage dialog
27
28
29 ShipSpecialDamage::ShipSpecialDamage(CWnd* pParent /*=NULL*/)
30         : CDialog(ShipSpecialDamage::IDD, pParent)
31 {
32         //{{AFX_DATA_INIT(ShipSpecialDamage)
33         //}}AFX_DATA_INIT
34 }
35
36
37 void ShipSpecialDamage::DoDataExchange(CDataExchange* pDX)
38 {
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);
53         //}}AFX_DATA_MAP
54 }
55
56
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)
61         //}}AFX_MSG_MAP
62 END_MESSAGE_MAP()
63
64 /////////////////////////////////////////////////////////////////////////////
65 // ShipSpecialDamage message handlers
66
67 void ShipSpecialDamage::OnEnableShockwave() 
68 {
69         // TODO: Add your control notification handler code here
70         UpdateData(TRUE);
71
72         // enable/disable shock speed
73         DoGray();}
74
75 void ShipSpecialDamage::OnEnableSpecialExp() 
76 {
77         // TODO: Add your control notification handler code here
78         UpdateData(TRUE);
79
80         DoGray();
81 }
82
83 BOOL ShipSpecialDamage::OnInitDialog() 
84 {
85         
86         // TODO: Add extra initialization here
87
88         // get ship num
89         object *objp;
90
91         m_ship_num = -1;
92
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) {
97
98                                 m_ship_num = objp->instance;
99                                 break;
100                         }
101                 }
102                 objp = GET_NEXT(objp);
103         }
104
105         if (Ships[m_ship_num].special_exp_index == -1) {
106                 // get default_table_values
107                 ship_info *sip;
108                 sip = &Ship_info[Ships[m_ship_num].ship_info_index];
109
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;
117
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;
121         } else {
122                 int index = Ships[m_ship_num].special_exp_index;
123                 SDL_assert( (index > 0) && (index < MAX_SEXP_VARIABLES-5) );
124
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;
132         }
133
134         CDialog::OnInitDialog();
135
136         // maybe gray out lots of stuff
137         DoGray();
138
139         return TRUE;  // return TRUE unless you set the focus to a control
140                       // EXCEPTION: OCX Property Pages should return FALSE
141 }
142
143 void ShipSpecialDamage::DoGray()
144 {
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);
151 }
152
153
154 void ShipSpecialDamage::OnCancel() 
155 {
156         // TODO: Add extra cleanup here
157         
158         CDialog::OnCancel();
159 }
160
161 void ShipSpecialDamage::OnOK() 
162 {
163         UpdateData(TRUE);
164
165         // TODO: Add extra validation here
166         if (m_special_exp_enabled) {
167
168                 int start;
169
170                 if (m_inner_rad > m_outer_rad) {
171                         MessageBox("Inner radius must be less than outer radius");
172                         return;
173                 }
174
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);
178                         if (start == -1) {
179                                 MessageBox("Unable to allocate storage, try deleting Sexp variables");
180                                 return;
181                         } else {
182                                 Ships[m_ship_num].special_exp_index = start;
183                         }
184                 } else {
185                         start = Ships[m_ship_num].special_exp_index;
186                 }
187                 // set to update
188                 set_modified();
189
190                 // set em
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);
197
198         } else {
199                 if (Ships[m_ship_num].special_exp_index != -1) {
200                         // set to update
201                         set_modified();
202
203                         // free block
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);
205
206                         // set index to no exp block
207                         Ships[m_ship_num].special_exp_index = -1;
208                 }
209         }
210
211         CDialog::OnOK();
212 }
213