| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | // PlayerWeaponsDialog.cpp : implementation file |
| 20 | // |
| 21 | |
| 22 | #include "stdafx.h" |
| 23 | #include "editor.h" |
| 24 | #include "PlayerWeaponsDialog.h" |
| 25 | #include "RobotEditWeaponsDialog.h" |
| 26 | #include "ship.h" |
| 27 | #include "weapon.h" |
| 28 | #include "pserror.h" |
| 29 | #include "soundload.h" |
| 30 | |
| 31 | #ifdef _DEBUG |
| 32 | #define new DEBUG_NEW |
| 33 | #undef THIS_FILE |
| 34 | static char THIS_FILE[] = __FILE__; |
| 35 | #endif |
| 36 | |
| 37 | // char *WeaponListText[MAX_PLAYER_WEAPONS] = |
| 38 | //{ |
| 39 | // "Primary 1", |
| 40 | // "Primary 2", |
| 41 | // "Primary 3", |
| 42 | // "Primary 4", |
| 43 | // "Primary 5", |
| 44 | // "Primary 6", |
| 45 | // "Primary 7", |
| 46 | // "Primary 8", |
| 47 | // "Primary 9", |
| 48 | // "Primary 10", |
| 49 | // "Secondary 1", |
| 50 | // "Secondary 2", |
| 51 | // "Secondary 3", |
| 52 | // "Secondary 4", |
| 53 | // "Secondary 5", |
| 54 | // "Secondary 6", |
| 55 | // "Secondary 7", |
| 56 | // "Secondary 8", |
| 57 | // "Secondary 9", |
| 58 | // "Secondary 10", |
| 59 | // "Flare" |
| 60 | // }; |
| 61 | |
| 62 | // Use the real weapon names in this dialog |
| 63 | #define WeaponListText Static_weapon_names |
| 64 | |
| 65 | ///////////////////////////////////////////////////////////////////////////// |
| 66 | // PlayerWeaponsDialog dialog |
| 67 | |
| 68 | PlayerWeaponsDialog::PlayerWeaponsDialog(int current_ship, CWnd *pParent /*=NULL*/) |
| 69 | : CDialog(PlayerWeaponsDialog::IDD, pParent) { |
| 70 | //{{AFX_DATA_INIT(PlayerWeaponsDialog) |
| 71 | m_current_wb_text = _T(""); |
| 72 | //}}AFX_DATA_INIT |
| 73 | |
| 74 | m_current_ship = current_ship; |
| 75 | } |
| 76 | |
| 77 | void PlayerWeaponsDialog::DoDataExchange(CDataExchange *pDX) { |
| 78 | CDialog::DoDataExchange(pDX); |
| 79 | //{{AFX_DATA_MAP(PlayerWeaponsDialog) |
| 80 | DDX_CBString(pDX, IDC_CURRENT_WEAPON_BATTERY_COMBO, m_current_wb_text); |
| 81 | //}}AFX_DATA_MAP |
| 82 | } |
| 83 | |
| 84 | BEGIN_MESSAGE_MAP(PlayerWeaponsDialog, CDialog) |
| 85 | //{{AFX_MSG_MAP(PlayerWeaponsDialog) |
| 86 | ON_BN_CLICKED(IDC_EDIT_WB_BUTTON, OnEditWbButton) |
| 87 | ON_CBN_SELENDOK(IDC_CURRENT_WEAPON_BATTERY_COMBO, OnSelendokCurrentWeaponBatteryCombo) |
| 88 | ON_BN_CLICKED(IDC_FIRES_FUSION, OnFiresFusion) |
| 89 | ON_BN_CLICKED(IDC_CONTINUOUS_FIRING_SOUND, OnContinuousFiringSound) |
| 90 | ON_BN_CLICKED(IDC_FIRING_RELEASE_SOUND, OnFiringReleaseSound) |
| 91 | ON_CBN_SELCHANGE(IDC_FIRING_SOUND_PULLDOWN, OnSelchangeFiringSoundPulldown) |
| 92 | ON_CBN_SELCHANGE(IDC_RELEASE_SOUND_PULLDOWN, OnSelchangeReleaseSoundPulldown) |
| 93 | ON_CBN_SELCHANGE(IDC_SPEW_POWERUP_PULLDOWN, OnSelchangeSpewPowerupPulldown) |
| 94 | ON_BN_CLICKED(IDC_ONOFF, OnOnoff) |
| 95 | ON_BN_CLICKED(IDC_ZOOM, OnZoom) |
| 96 | ON_EN_KILLFOCUS(IDC_MAX_AMMO, OnKillfocusMaxAmmo) |
| 97 | ON_BN_CLICKED(IDC_SHOW_TENTHS, OnShowTenths) |
| 98 | //}}AFX_MSG_MAP |
| 99 | END_MESSAGE_MAP() |
| 100 | |
| 101 | ///////////////////////////////////////////////////////////////////////////// |
| 102 | // PlayerWeaponsDialog message handlers |
| 103 | |
| 104 | int PlayerWeaponsDialog::CurrentWBIndex() { |
| 105 | int i; |
| 106 | |
| 107 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 108 | if (!stricmp(WeaponListText[i], m_current_wb_text)) |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | ASSERT(i < MAX_PLAYER_WEAPONS); |
| 113 | |
| 114 | return i; |
| 115 | } |
| 116 | |
| 117 | void PlayerWeaponsDialog::OnEditWbButton() { |
| 118 | int i = CurrentWBIndex(); |
| 119 | |
| 120 | // All player wb profiles are considered to be wb 0 as far as RobotEditWeaponsDialog is concerned. :) |
| 121 | RobotEditWeaponsDialog dlg(&Ships[m_current_ship].static_wb[i], |
| 122 | GetPolymodelPointer(Ships[m_current_ship].model_handle)); |
| 123 | |
| 124 | if (dlg.DoModal() == IDOK) |
| 125 | dlg.GetData(); |
| 126 | } |
| 127 | |
| 128 | #define NULL_NAME "<none>" |
| 129 | |
| 130 | BOOL PlayerWeaponsDialog::OnInitDialog() { |
| 131 | CDialog::OnInitDialog(); |
| 132 | int i; |
| 133 | |
| 134 | SendDlgItemMessage(IDC_CURRENT_WEAPON_BATTERY_COMBO, CB_RESETCONTENT, 0, 0); |
| 135 | for (i = 0; i < MAX_PLAYER_WEAPONS; i++) { |
| 136 | if (!stricmp("", WeaponListText[i])) |
| 137 | break; |
| 138 | SendDlgItemMessage(IDC_CURRENT_WEAPON_BATTERY_COMBO, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)WeaponListText[i]); |
| 139 | } |
| 140 | SendDlgItemMessage(IDC_CURRENT_WEAPON_BATTERY_COMBO, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)WeaponListText[0]); |
| 141 | |
| 142 | SendDlgItemMessage(IDC_FIRING_SOUND_PULLDOWN, CB_RESETCONTENT, 0, 0); |
| 143 | for (i = 0; i < MAX_SOUNDS; i++) { |
| 144 | if (Sounds[i].used) |
| 145 | SendDlgItemMessage(IDC_FIRING_SOUND_PULLDOWN, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)Sounds[i].name); |
| 146 | } |
| 147 | SendDlgItemMessage(IDC_FIRING_SOUND_PULLDOWN, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)Sounds[0].name); |
| 148 | |
| 149 | SendDlgItemMessage(IDC_RELEASE_SOUND_PULLDOWN, CB_RESETCONTENT, 0, 0); |
| 150 | for (i = 0; i < MAX_SOUNDS; i++) { |
| 151 | if (Sounds[i].used) |
| 152 | SendDlgItemMessage(IDC_RELEASE_SOUND_PULLDOWN, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)Sounds[i].name); |
| 153 | } |
| 154 | SendDlgItemMessage(IDC_RELEASE_SOUND_PULLDOWN, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)Sounds[0].name); |
| 155 | |
| 156 | // Update powerup list |
| 157 | SendDlgItemMessage(IDC_SPEW_POWERUP_PULLDOWN, CB_RESETCONTENT, 0, 0); |
| 158 | SendDlgItemMessage(IDC_SPEW_POWERUP_PULLDOWN, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)NULL_NAME); |
| 159 | for (i = 0; i < MAX_OBJECT_IDS; i++) |
| 160 | if (Object_info[i].type == OBJ_POWERUP) |
| 161 | SendDlgItemMessage(IDC_SPEW_POWERUP_PULLDOWN, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)Object_info[i].name); |
| 162 | SendDlgItemMessage(IDC_SPEW_POWERUP_PULLDOWN, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)NULL_NAME); |
| 163 | |
| 164 | m_current_wb_text = WeaponListText[0]; |
| 165 | |
| 166 | UpdateDialog(); |
| 167 | |
| 168 | return TRUE; // return TRUE unless you set the focus to a control |
| 169 | // EXCEPTION: OCX Property Pages should return FALSE |
| 170 | } |
| 171 | |
| 172 | void PlayerWeaponsDialog::UpdateDialog() { |
| 173 | CButton *bbox; |
| 174 | int index = CurrentWBIndex(); |
| 175 | ship *ship = &Ships[m_current_ship]; |
| 176 | int fire_flags = Ships[m_current_ship].fire_flags[index]; |
| 177 | int result; |
| 178 | |
| 179 | // if(!UpdateData(true)) return; |
| 180 | |
| 181 | bbox = (CButton *)GetDlgItem(IDC_FIRES_FUSION); |
| 182 | bbox->SetCheck(fire_flags & SFF_FUSION); |
| 183 | |
| 184 | bbox = (CButton *)GetDlgItem(IDC_ONOFF); |
| 185 | bbox->SetCheck(ship->static_wb[index].flags & WBF_ON_OFF); |
| 186 | |
| 187 | bbox = (CButton *)GetDlgItem(IDC_ZOOM); |
| 188 | bbox->SetCheck(fire_flags & SFF_ZOOM); |
| 189 | |
| 190 | // Set checkboxes & enable/disable pulldown boxes |
| 191 | int firing_sound = Ships[m_current_ship].firing_sound[index]; |
| 192 | int release_sound = Ships[m_current_ship].firing_release_sound[index]; |
| 193 | bbox = (CButton *)GetDlgItem(IDC_CONTINUOUS_FIRING_SOUND); |
| 194 | bbox->SetCheck(firing_sound != -1); |
| 195 | ((CButton *)GetDlgItem(IDC_FIRING_SOUND_PULLDOWN))->EnableWindow(firing_sound != -1); |
| 196 | |
| 197 | bbox = (CButton *)GetDlgItem(IDC_FIRING_RELEASE_SOUND); |
| 198 | bbox->SetCheck(release_sound != -1); |
| 199 | ((CButton *)GetDlgItem(IDC_RELEASE_SOUND_PULLDOWN))->EnableWindow(release_sound != -1); |
| 200 | |
| 201 | // Update sounds in pulldown box |
| 202 | SendDlgItemMessage(IDC_FIRING_SOUND_PULLDOWN, CB_SELECTSTRING, 0, |
| 203 | (LPARAM)(LPCTSTR)((firing_sound == -1) ? Sounds[0].name : Sounds[firing_sound].name)); |
| 204 | SendDlgItemMessage(IDC_RELEASE_SOUND_PULLDOWN, CB_SELECTSTRING, 0, |
| 205 | (LPARAM)(LPCTSTR)((release_sound == -1) ? Sounds[0].name : Sounds[release_sound].name)); |
| 206 | |
| 207 | // Update powerup pulldown box |
| 208 | try_again:; |
| 209 | result = SendDlgItemMessage(IDC_SPEW_POWERUP_PULLDOWN, CB_SELECTSTRING, 0, |
| 210 | (LPARAM)(LPCTSTR)((Ships[m_current_ship].spew_powerup[index] == -1) |
| 211 | ? NULL_NAME |
| 212 | : Object_info[Ships[m_current_ship].spew_powerup[index]].name)); |
| 213 | if (result == -1) { |
| 214 | Int3(); // Can't find requested powerup in list, so spew powerup to none. |
| 215 | Ships[m_current_ship].spew_powerup[index] = -1; |
| 216 | goto try_again; |
| 217 | } |
| 218 | |
| 219 | // Update max ammo |
| 220 | char str[200]; |
| 221 | bbox = (CButton *)GetDlgItem(IDC_MAX_AMMO); |
| 222 | sprintf(str, "%d", ship->max_ammo[index]); |
| 223 | bbox->SetWindowText(str); |
| 224 | |
| 225 | // Update tenths checkbox |
| 226 | bbox = (CButton *)GetDlgItem(IDC_SHOW_TENTHS); |
| 227 | bbox->SetCheck(fire_flags & SFF_TENTHS); |
| 228 | |
| 229 | // Add new UpdateDialog stuff here. -- note from Chris |
| 230 | } |
| 231 | |
| 232 | void PlayerWeaponsDialog::OnSelendokCurrentWeaponBatteryCombo() { |
| 233 | int cur; |
| 234 | char name[200]; |
| 235 | |
| 236 | // if(!UpdateData(true)) return; |
| 237 | |
| 238 | cur = SendDlgItemMessage(IDC_CURRENT_WEAPON_BATTERY_COMBO, CB_GETCURSEL, 0, 0); |
| 239 | SendDlgItemMessage(IDC_CURRENT_WEAPON_BATTERY_COMBO, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name); |
| 240 | |
| 241 | m_current_wb_text = name; |
| 242 | |
| 243 | // UpdateData(false); |
| 244 | |
| 245 | UpdateDialog(); |
| 246 | } |
| 247 | |
| 248 | void PlayerWeaponsDialog::OnFiresFusion() { |
| 249 | int i = CurrentWBIndex(); |
| 250 | |
| 251 | Ships[m_current_ship].fire_flags[i] &= ~(SFF_ZOOM); |
| 252 | Ships[m_current_ship].static_wb[i].flags &= ~(WBF_ON_OFF); |
| 253 | Ships[m_current_ship].fire_flags[i] |= SFF_FUSION; |
| 254 | UpdateDialog(); |
| 255 | } |
| 256 | |
| 257 | void PlayerWeaponsDialog::OnContinuousFiringSound() { |
| 258 | int i = CurrentWBIndex(); |
| 259 | CButton *btn; |
| 260 | |
| 261 | btn = (CButton *)GetDlgItem(IDC_CONTINUOUS_FIRING_SOUND); |
| 262 | |
| 263 | if (btn->GetCheck()) |
| 264 | Ships[m_current_ship].firing_sound[i] = 0; |
| 265 | else |
| 266 | Ships[m_current_ship].firing_sound[i] = -1; |
| 267 | |
| 268 | UpdateDialog(); |
| 269 | } |
| 270 | |
| 271 | void PlayerWeaponsDialog::OnFiringReleaseSound() { |
| 272 | int i = CurrentWBIndex(); |
| 273 | CButton *btn; |
| 274 | |
| 275 | btn = (CButton *)GetDlgItem(IDC_FIRING_RELEASE_SOUND); |
| 276 | |
| 277 | if (btn->GetCheck()) |
| 278 | Ships[m_current_ship].firing_release_sound[i] = 0; |
| 279 | else |
| 280 | Ships[m_current_ship].firing_release_sound[i] = -1; |
| 281 | |
| 282 | UpdateDialog(); |
| 283 | } |
| 284 | |
| 285 | void PlayerWeaponsDialog::OnSelchangeFiringSoundPulldown() { |
| 286 | int cur; |
| 287 | char name[200]; |
| 288 | |
| 289 | cur = SendDlgItemMessage(IDC_FIRING_SOUND_PULLDOWN, CB_GETCURSEL, 0, 0); |
| 290 | SendDlgItemMessage(IDC_FIRING_SOUND_PULLDOWN, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name); |
| 291 | |
| 292 | int i = CurrentWBIndex(); |
| 293 | |
| 294 | for (int s = 0; s < MAX_SOUNDS; s++) { |
| 295 | if (Sounds[s].used && !strcmp(name, Sounds[s].name)) { |
| 296 | Ships[m_current_ship].firing_sound[i] = s; |
| 297 | break; |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | void PlayerWeaponsDialog::OnSelchangeReleaseSoundPulldown() { |
| 303 | int cur; |
| 304 | char name[200]; |
| 305 | |
| 306 | cur = SendDlgItemMessage(IDC_RELEASE_SOUND_PULLDOWN, CB_GETCURSEL, 0, 0); |
| 307 | SendDlgItemMessage(IDC_RELEASE_SOUND_PULLDOWN, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name); |
| 308 | |
| 309 | int i = CurrentWBIndex(); |
| 310 | |
| 311 | for (int s = 0; s < MAX_SOUNDS; s++) { |
| 312 | if (Sounds[s].used && !strcmp(name, Sounds[s].name)) { |
| 313 | Ships[m_current_ship].firing_release_sound[i] = s; |
| 314 | break; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | void PlayerWeaponsDialog::OnSelchangeSpewPowerupPulldown() { |
| 320 | int cur; |
| 321 | char name[200]; |
| 322 | int i, id; |
| 323 | |
| 324 | cur = SendDlgItemMessage(IDC_SPEW_POWERUP_PULLDOWN, CB_GETCURSEL, 0, 0); |
| 325 | SendDlgItemMessage(IDC_SPEW_POWERUP_PULLDOWN, CB_GETLBTEXT, cur, (LPARAM)(LPCTSTR)name); |
| 326 | |
| 327 | i = CurrentWBIndex(); |
| 328 | id = FindObjectIDName(name); |
| 329 | |
| 330 | Ships[m_current_ship].spew_powerup[i] = id; |
| 331 | } |
| 332 | |
| 333 | void PlayerWeaponsDialog::OnOnoff() { |
| 334 | int i = CurrentWBIndex(); |
| 335 | |
| 336 | Ships[m_current_ship].fire_flags[i] &= ~(SFF_FUSION | SFF_ZOOM); |
| 337 | Ships[m_current_ship].static_wb[i].flags |= WBF_ON_OFF; |
| 338 | UpdateDialog(); |
| 339 | } |
| 340 | |
| 341 | void PlayerWeaponsDialog::OnZoom() { |
| 342 | int i = CurrentWBIndex(); |
| 343 | |
| 344 | Ships[m_current_ship].fire_flags[i] &= ~(SFF_FUSION); |
| 345 | Ships[m_current_ship].static_wb[i].flags &= ~(WBF_ON_OFF); |
| 346 | Ships[m_current_ship].fire_flags[i] |= SFF_ZOOM; |
| 347 | UpdateDialog(); |
| 348 | } |
| 349 | |
| 350 | void PlayerWeaponsDialog::OnKillfocusMaxAmmo() { |
| 351 | int i = CurrentWBIndex(); |
| 352 | |
| 353 | char str[200]; |
| 354 | CButton *bbox = (CButton *)GetDlgItem(IDC_MAX_AMMO); |
| 355 | bbox->GetWindowText(str, sizeof(str)); |
| 356 | |
| 357 | Ships[m_current_ship].max_ammo[i] = atoi(str); |
| 358 | } |
| 359 | |
| 360 | void PlayerWeaponsDialog::OnShowTenths() { |
| 361 | int i = CurrentWBIndex(); |
| 362 | CButton *bbox = (CButton *)GetDlgItem(IDC_SHOW_TENTHS); |
| 363 | |
| 364 | if (bbox->GetCheck()) |
| 365 | Ships[m_current_ship].fire_flags[i] |= SFF_TENTHS; |
| 366 | else |
| 367 | Ships[m_current_ship].fire_flags[i] &= ~SFF_TENTHS; |
| 368 | |
| 369 | UpdateDialog(); |
| 370 | } |