FS2_Open
Open source remastering of the Freespace 2 engine
shipspecialhitpoints.cpp
Go to the documentation of this file.
1 // ShipSpecialHitpoints.cpp : implementation file
2 //
3 
4 #include "stdafx.h"
5 #include "fred.h"
6 #include "ShipSpecialHitpoints.h"
7 #include "globalincs/linklist.h"
8 #include "parse/sexp.h"
9 #include "FREDDoc.h"
10 
11 #ifdef _DEBUG
12 #undef THIS_FILE
13 static char THIS_FILE[] = __FILE__;
14 #endif
15 
17 // ShipSpecialHitpoints dialog
18 
19 
21  : CDialog(ShipSpecialHitpoints::IDD, pParent)
22 {
23  //{{AFX_DATA_INIT(ShipSpecialHitpoints)
24  //}}AFX_DATA_INIT
25 }
26 
27 
28 void ShipSpecialHitpoints::DoDataExchange(CDataExchange* pDX)
29 {
30  CDialog::DoDataExchange(pDX);
31  //{{AFX_DATA_MAP(ShipSpecialHitpoints)
34  DDX_Text(pDX, IDC_SPECIAL_SHIELDS, m_shields);
35  DDV_MinMaxInt(pDX, m_shields, -1, INT_MAX);
36  DDX_Text(pDX, IDC_SPECIAL_HULL, m_hull);
37  DDV_MinMaxInt(pDX, m_hull, 1, INT_MAX);
38  //}}AFX_DATA_MAP
39 }
40 
41 
42 BEGIN_MESSAGE_MAP(ShipSpecialHitpoints, CDialog)
43  //{{AFX_MSG_MAP(ShipSpecialHitpoints)
44  ON_BN_CLICKED(IDC_ENABLE_SPECIAL_HITPOINTS, OnEnableSpecialHitpoints)
45  ON_BN_CLICKED(IDC_ENABLE_SPECIAL_SHIELD, OnEnableSpecialShieldpoints)
46  ON_BN_CLICKED(ID_OK, OnOk)
47  ON_BN_CLICKED(ID_CANCEL, OnCancel)
48  //}}AFX_MSG_MAP
49 END_MESSAGE_MAP()
50 
52 // ShipSpecialHitpoints message handlers
53 
54 void ShipSpecialHitpoints::OnEnableSpecialHitpoints()
55 {
56  // TODO: Add your control notification handler code here
57  UpdateData(TRUE);
58 
59  DoGray();
60 }
61 
63 {
64  // TODO: Add your control notification handler code here
65  UpdateData(TRUE);
66 
67  DoGray();
68 }
69 
71 {
72  // get ship num
73  object *objp;
74 
75  num_selected_ships = 0;
76 
77  objp = GET_FIRST(&obj_used_list);
78  while (objp != END_OF_LIST(&obj_used_list)) {
79  if ((objp->type == OBJ_START) || (objp->type == OBJ_SHIP)) {
80  if (objp->flags & OF_MARKED) {
81  m_selected_ships[num_selected_ships] = objp->instance;
82  num_selected_ships++;
83  }
84  }
85  objp = GET_NEXT(objp);
86  }
87 
88  Assert(num_selected_ships);
90  m_ship_num = Objects[cur_object_index].instance;
91 
92  // get the details from the first ship
93  //hull
94  if (Ships[m_ship_num].special_hitpoints) {
95  m_hull = Ships[m_ship_num].special_hitpoints;
97  }
98  else {
99  // get default_table_values
100  ship_info *sip;
101  sip = &Ship_info[Ships[m_ship_num].ship_info_index];
102 
103  m_hull = (int)sip->max_hull_strength;
105 
106  if (m_hull < 1) m_hull = 10;
107  }
108 
109  //shields
110  if (Ships[m_ship_num].special_shield > 0){
111  m_shields = Ships[m_ship_num].special_shield;
113  }
114  else {
115  // get default_table_values
116  ship_info *sip;
117  sip = &Ship_info[Ships[m_ship_num].ship_info_index];
118 
121 
122  if (m_shields < 0) {
123  m_shields = 0;
124  }
125  }
126 
127  CDialog::OnInitDialog();
128 
129  // maybe gray out lots of stuff
130  DoGray();
131 
132  return TRUE; // return TRUE unless you set the focus to a control
133  // EXCEPTION: OCX Property Pages should return FALSE
134 }
135 
137 {
138  GetDlgItem(IDC_SPECIAL_SHIELDS)->EnableWindow(m_special_shield_enabled);
139  GetDlgItem(IDC_SPECIAL_HULL)->EnableWindow(m_special_hitpoints_enabled);
140 }
141 
143 {
144  // TODO: Add extra cleanup here
145 
146  CDialog::OnCancel();
147 }
148 
150 {
151  float temp_max_hull_strength;
152  int new_shield_strength, new_hull_strength;
153  int i;
154 
155  UpdateData(TRUE);
156 
157  // TODO: Add extra validation here
159 
160  // Don't update anything if the hull strength is invalid
161  if (m_hull < 1) {
162  return;
163  }
164 
165  // set to update
166  set_modified();
167 
168  new_hull_strength = m_hull;
169  //Ships[m_ship_num].special_hitpoints = m_hull;
170 
171  }
172  else {
173  // set to update
174  set_modified();
175 
176  new_hull_strength = 0;
177  }
178 
180 
181  // Don't update anything if the hull strength is invalid
182  if (m_shields < 0) {
183  return;
184  }
185 
186  // set to update
187  set_modified();
188 
189  new_shield_strength = m_shields;
190  //Ships[m_ship_num].special_shield = m_shields;
191 
192  }
193  else {
194  // set to update
195  set_modified();
196 
197  new_shield_strength = -1;
198  }
199 
200  for ( i=0; i<num_selected_ships; i++) {
201  // set the special hitpoints/shield
202  Ships[m_selected_ships[i]].special_hitpoints = new_hull_strength;
203  Ships[m_selected_ships[i]].special_shield = new_shield_strength;
204 
205  // calc kamikaze stuff
206  if (Ships[m_selected_ships[i]].special_hitpoints)
207  {
208  temp_max_hull_strength = (float)Ships[m_selected_ships[i]].special_hitpoints;
209  }
210  else
211  {
212  temp_max_hull_strength = Ship_info[Ships[m_selected_ships[i]].ship_info_index].max_hull_strength;
213  }
214 
215  Ai_info[Ships[m_selected_ships[i]].ai_index].kamikaze_damage = min(1000, 200 + (int)(temp_max_hull_strength / 4.0f));
216  }
217 
218 
219  CDialog::OnOK();
220 }
int i
Definition: multi_pxo.cpp:466
#define IDC_ENABLE_SPECIAL_HITPOINTS
Definition: resource.h:1069
#define IDC_SPECIAL_SHIELDS
Definition: resource.h:1071
Assert(pm!=NULL)
int ai_index
Definition: ship.h:538
#define ID_CANCEL
Definition: resource.h:975
GLclampf f
Definition: Glext.h:7097
#define TRUE
Definition: pstypes.h:399
ai_info Ai_info[MAX_AI_INFO]
Definition: ai.cpp:23
object obj_used_list
Definition: object.cpp:53
object * objp
Definition: lua.cpp:3105
virtual void DoDataExchange(CDataExchange *pDX)
#define IDC_ENABLE_SPECIAL_SHIELD
Definition: resource.h:1074
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
int instance
Definition: object.h:150
#define OBJ_START
Definition: object.h:35
ShipSpecialHitpoints(CWnd *pParent=NULL)
#define ID_OK
Definition: resource.h:833
afx_msg void OnEnableSpecialShieldpoints()
float max_shield_strength
Definition: ship.h:1310
object Objects[MAX_OBJECTS]
Definition: object.cpp:62
#define OF_MARKED
Definition: object.h:125
#define OBJ_SHIP
Definition: object.h:32
GLbitfield flags
Definition: Glext.h:6722
void set_modified(BOOL arg)
Definition: freddoc.cpp:676
int BOOL
Definition: config.h:80
ship Ships[MAX_SHIPS]
Definition: ship.cpp:122
if(aifft_max_checks<=0)
Definition: aiturret.cpp:1581
int special_shield
Definition: ship.h:594
typedef float(SCP_EXT_CALLCONV *SCPTRACKIR_PFFLOATVOID)()
#define IDC_SPECIAL_HULL
Definition: resource.h:1072
int ship_info_index
Definition: ship.h:539
SCP_vector< ship_info > Ship_info
Definition: ship.cpp:164
int cur_object_index
Definition: management.cpp:79
int kamikaze_damage
Definition: ai.h:523
int special_hitpoints
Definition: ship.h:593
float max_hull_strength
Definition: ship.h:1309
uint flags
Definition: object.h:151
char type
Definition: object.h:146
#define FALSE
Definition: pstypes.h:400