Debian Codegraph @

editor/GenericDeathDialog.cpp

raw symbols SCIP
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 // GenericDeathDialog.cpp : implementation file
20 //
21
22 #include "stdafx.h"
23 #include "editor.h"
24 #include "GenericDeathDialog.h"
25
26 #ifdef _DEBUG
27 #define new DEBUG_NEW
28 #undef THIS_FILE
29 static char THIS_FILE[] = __FILE__;
30 #endif
31
32 /////////////////////////////////////////////////////////////////////////////
33 // CGenericDeathDialog dialog
34
35 CGenericDeathDialog::CGenericDeathDialog(object_info *objinfo, CWnd *pParent /*=NULL*/)
36 : CDialog(CGenericDeathDialog::IDD, pParent) {
37 //{{AFX_DATA_INIT(CGenericDeathDialog)
38 m_prob1 = 0;
39 m_prob2 = 0;
40 m_prob3 = 0;
41 m_prob4 = 0;
42 //}}AFX_DATA_INIT
43
44 // Store ptr to source data
45 m_objinfo = objinfo;
46
47 ASSERT(MAX_DEATH_TYPES == 4);
48
49 // Copy data
50 for (int i = 0; i < MAX_DEATH_TYPES; i++)
51 m_death_types[i] = objinfo->death_types[i];
52
53 m_prob1 = objinfo->death_probabilities[0];
54 m_prob2 = objinfo->death_probabilities[1];
55 m_prob3 = objinfo->death_probabilities[2];
56 m_prob4 = objinfo->death_probabilities[3];
57 }
58
59 void CGenericDeathDialog::DoDataExchange(CDataExchange *pDX) {
60 CDialog::DoDataExchange(pDX);
61 //{{AFX_DATA_MAP(CGenericDeathDialog)
62 DDX_Text(pDX, IDC_GENEREIC_DEATH_PROB1, m_prob1);
63 DDX_Text(pDX, IDC_GENEREIC_DEATH_PROB2, m_prob2);
64 DDX_Text(pDX, IDC_GENEREIC_DEATH_PROB3, m_prob3);
65 DDX_Text(pDX, IDC_GENEREIC_DEATH_PROB4, m_prob4);
66 //}}AFX_DATA_MAP
67 }
68
69 BEGIN_MESSAGE_MAP(CGenericDeathDialog, CDialog)
70 //{{AFX_MSG_MAP(CGenericDeathDialog)
71 ON_BN_CLICKED(IDC_GENERIC_DEATH_EDIT1, OnGenericDeathEdit1)
72 ON_BN_CLICKED(IDC_GENERIC_DEATH_EDIT2, OnGenericDeathEdit2)
73 ON_BN_CLICKED(IDC_GENERIC_DEATH_EDIT3, OnGenericDeathEdit3)
74 ON_BN_CLICKED(IDC_GENERIC_DEATH_EDIT4, OnGenericDeathEdit4)
75 //}}AFX_MSG_MAP
76 END_MESSAGE_MAP()
77
78 /////////////////////////////////////////////////////////////////////////////
79 // CGenericDeathDialog message handlers
80
81 #include "DeathDialog.h"
82
83 void CGenericDeathDialog::OnGenericDeathEdit1() {
84 CDeathDialog dlg(&m_death_types[0]);
85
86 dlg.DoModal();
87 }
88
89 void CGenericDeathDialog::OnGenericDeathEdit2() {
90 CDeathDialog dlg(&m_death_types[1]);
91
92 dlg.DoModal();
93 }
94
95 void CGenericDeathDialog::OnGenericDeathEdit3() {
96 CDeathDialog dlg(&m_death_types[2]);
97
98 dlg.DoModal();
99 }
100
101 void CGenericDeathDialog::OnGenericDeathEdit4() {
102 CDeathDialog dlg(&m_death_types[3]);
103
104 dlg.DoModal();
105 }
106
107 void CGenericDeathDialog::OnOK() {
108 // Get the data
109 UpdateData(true);
110
111 int total_prob = m_prob1 + m_prob2 + m_prob3 + m_prob4;
112
113 if ((total_prob != 100) && (total_prob != 0)) {
114 OutrageMessageBox("The total of all death probabilities must be 100 or 0.");
115 return;
116 }
117
118 for (int i = 0; i < MAX_DEATH_TYPES; i++)
119 m_objinfo->death_types[i] = m_death_types[i];
120
121 m_objinfo->death_probabilities[0] = m_prob1;
122 m_objinfo->death_probabilities[1] = m_prob2;
123 m_objinfo->death_probabilities[2] = m_prob3;
124 m_objinfo->death_probabilities[3] = m_prob4;
125
126 CDialog::OnOK();
127 }