File: GenericDeathDialog.cpp

package info (click to toggle)
descent3 1.5.0%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 35,256 kB
  • sloc: cpp: 416,147; ansic: 3,233; sh: 10; makefile: 8
file content (127 lines) | stat: -rw-r--r-- 3,576 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Descent 3
 * Copyright (C) 2024 Parallax Software
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// GenericDeathDialog.cpp : implementation file
//

#include "stdafx.h"
#include "editor.h"
#include "GenericDeathDialog.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGenericDeathDialog dialog

CGenericDeathDialog::CGenericDeathDialog(object_info *objinfo, CWnd *pParent /*=NULL*/)
    : CDialog(CGenericDeathDialog::IDD, pParent) {
  //{{AFX_DATA_INIT(CGenericDeathDialog)
  m_prob1 = 0;
  m_prob2 = 0;
  m_prob3 = 0;
  m_prob4 = 0;
  //}}AFX_DATA_INIT

  // Store ptr to source data
  m_objinfo = objinfo;

  ASSERT(MAX_DEATH_TYPES == 4);

  // Copy data
  for (int i = 0; i < MAX_DEATH_TYPES; i++)
    m_death_types[i] = objinfo->death_types[i];

  m_prob1 = objinfo->death_probabilities[0];
  m_prob2 = objinfo->death_probabilities[1];
  m_prob3 = objinfo->death_probabilities[2];
  m_prob4 = objinfo->death_probabilities[3];
}

void CGenericDeathDialog::DoDataExchange(CDataExchange *pDX) {
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CGenericDeathDialog)
  DDX_Text(pDX, IDC_GENEREIC_DEATH_PROB1, m_prob1);
  DDX_Text(pDX, IDC_GENEREIC_DEATH_PROB2, m_prob2);
  DDX_Text(pDX, IDC_GENEREIC_DEATH_PROB3, m_prob3);
  DDX_Text(pDX, IDC_GENEREIC_DEATH_PROB4, m_prob4);
  //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGenericDeathDialog, CDialog)
//{{AFX_MSG_MAP(CGenericDeathDialog)
ON_BN_CLICKED(IDC_GENERIC_DEATH_EDIT1, OnGenericDeathEdit1)
ON_BN_CLICKED(IDC_GENERIC_DEATH_EDIT2, OnGenericDeathEdit2)
ON_BN_CLICKED(IDC_GENERIC_DEATH_EDIT3, OnGenericDeathEdit3)
ON_BN_CLICKED(IDC_GENERIC_DEATH_EDIT4, OnGenericDeathEdit4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGenericDeathDialog message handlers

#include "DeathDialog.h"

void CGenericDeathDialog::OnGenericDeathEdit1() {
  CDeathDialog dlg(&m_death_types[0]);

  dlg.DoModal();
}

void CGenericDeathDialog::OnGenericDeathEdit2() {
  CDeathDialog dlg(&m_death_types[1]);

  dlg.DoModal();
}

void CGenericDeathDialog::OnGenericDeathEdit3() {
  CDeathDialog dlg(&m_death_types[2]);

  dlg.DoModal();
}

void CGenericDeathDialog::OnGenericDeathEdit4() {
  CDeathDialog dlg(&m_death_types[3]);

  dlg.DoModal();
}

void CGenericDeathDialog::OnOK() {
  // Get the data
  UpdateData(true);

  int total_prob = m_prob1 + m_prob2 + m_prob3 + m_prob4;

  if ((total_prob != 100) && (total_prob != 0)) {
    OutrageMessageBox("The total of all death probabilities must be 100 or 0.");
    return;
  }

  for (int i = 0; i < MAX_DEATH_TYPES; i++)
    m_objinfo->death_types[i] = m_death_types[i];

  m_objinfo->death_probabilities[0] = m_prob1;
  m_objinfo->death_probabilities[1] = m_prob2;
  m_objinfo->death_probabilities[2] = m_prob3;
  m_objinfo->death_probabilities[3] = m_prob4;

  CDialog::OnOK();
}