2 * $Logfile: /Freespace2/code/fred2/PlayerStartEditor.cpp $
7 * Player starting point editor dialog box handling code
10 * Revision 1.1 2002/05/03 03:28:08 root
14 * 4 2/23/99 7:03p Dave
15 * Rewrote a horribly mangled and evil team loadout dialog. Bugs gone.
24 #include "playerstarteditor.h"
25 #include "missionparse.h"
27 #include "management.h"
33 static char THIS_FILE[] = __FILE__;
36 /////////////////////////////////////////////////////////////////////////////
37 // player_start_editor dialog
39 player_start_editor::player_start_editor(CWnd* pParent) : CDialog(player_start_editor::IDD, pParent)
41 //{{AFX_DATA_INIT(player_start_editor)
51 void player_start_editor::DoDataExchange(CDataExchange* pDX)
53 CDialog::DoDataExchange(pDX);
54 //{{AFX_DATA_MAP(player_start_editor)
55 DDX_Control(pDX, IDC_POOL_SPIN, m_pool_spin);
56 DDX_Control(pDX, IDC_DELAY_SPIN, m_delay_spin);
57 DDX_Control(pDX, IDC_SPIN1, m_spin1);
58 DDX_Control(pDX, IDC_SHIP_LIST, m_ship_list);
59 DDX_Control(pDX, IDC_WEAPON_LIST, m_weapon_list);
60 DDX_Text(pDX, IDC_DELAY, m_delay);
61 DDX_Text(pDX, IDC_SHIP_POOL, m_ship_pool);
62 DDX_Text(pDX, IDC_WEAPON_POOL, m_weapon_pool);
66 BEGIN_MESSAGE_MAP(player_start_editor, CDialog)
67 //{{AFX_MSG_MAP(player_start_editor)
69 ON_LBN_SELCHANGE(IDC_SHIP_LIST, OnSelchangeShipList)
71 ON_LBN_SELCHANGE(IDC_WEAPON_LIST, OnSelchangeWeaponList)
72 ON_EN_UPDATE(IDC_SHIP_POOL, OnUpdateShipPool)
73 ON_EN_UPDATE(IDC_WEAPON_POOL, OnUpdateWeaponPool)
77 /////////////////////////////////////////////////////////////////////////////
78 // player_start_editor message handlers
80 BOOL player_start_editor::OnInitDialog()
85 // initialize ship pool data
86 memset(ship_pool, 0, sizeof(int) * MAX_TEAMS * MAX_SHIP_TYPES);
87 for(i=0; i<MAX_TEAMS; i++){
88 for(idx=0; idx<Team_data[i].number_choices; idx++){
89 ship_pool[i][Team_data[i].ship_list[idx]] = Team_data[i].ship_count[idx];
93 // initialize weapon pool data
94 memset(weapon_pool, 0, sizeof(int) * MAX_TEAMS * MAX_WEAPON_TYPES);
95 for(i=0; i<MAX_TEAMS; i++){
96 for(idx=0; idx<MAX_WEAPON_TYPES; idx++){
97 weapon_pool[i][idx] = Team_data[i].weaponry_pool[idx];
102 m_delay = f2i(Entry_delay_time);
105 CDialog::OnInitDialog();
106 theApp.init_window(&Player_wnd_data, this);
107 m_spin1.SetRange(0, 99);
108 m_pool_spin.SetRange(0, 9999);
109 m_delay_spin.SetRange(0, 30);
111 // regenerate all the controls
119 // regenerate all controls
120 void player_start_editor::reset_controls()
125 // create a checklistbox for each "player" ship type
126 m_ship_list.ResetContent();
128 for (i=0; i<Num_ship_types; i++) {
129 if (Ship_info[i].flags & SIF_PLAYER_SHIP) {
130 m_ship_list.AddString(Ship_info[i].name);
132 // if the ship currently has pool entries, check it
133 if(ship_pool[selected_team][i] > 0){
134 m_ship_list.SetCheck(ct, TRUE);
136 m_ship_list.SetCheck(ct, FALSE);
144 // create a checklistbox for each weapon ship type
145 m_weapon_list.ResetContent();
147 for (i=0; i<Num_weapon_types; i++) {
148 if (Weapon_info[i].wi_flags & WIF_PLAYER_ALLOWED) {
149 m_weapon_list.AddString(Weapon_info[i].name);
151 // if the ship currently has pool entries, check it
152 if(weapon_pool[selected_team][i] > 0){
153 m_weapon_list.SetCheck(ct, TRUE);
155 m_weapon_list.SetCheck(ct, FALSE);
162 // be sure that nothing is selected
163 m_ship_list.SetCurSel(-1);
164 m_weapon_list.SetCurSel(-1);
168 void player_start_editor::OnInitMenu(CMenu* pMenu)
173 // disable any items we should disable
174 m = pMenu->GetSubMenu(0);
176 // uncheck all menu items
177 for (i = 0; i < Num_teams; i++ ){
178 m->CheckMenuItem(i, MF_BYPOSITION | MF_UNCHECKED);
181 for ( i = Num_teams; i < MAX_TEAMS; i++ ){
182 m->EnableMenuItem(i, MF_BYPOSITION | MF_GRAYED);
185 // put a check next to the currently selected item
186 m->CheckMenuItem(selected_team, MF_BYPOSITION | MF_CHECKED);
188 CDialog::OnInitMenu(pMenu);
191 // switch between active teams
192 BOOL player_start_editor::OnCommand(WPARAM wParam, LPARAM lParam)
211 return CDialog::OnCommand(wParam, lParam);
215 void player_start_editor::OnSelchangeShipList()
219 char ship_name[255] = "";
221 // determine if we've selected something
222 selected = m_ship_list.GetCurSel();
223 if (selected != -1) {
225 m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name);
226 si_index = ship_info_lookup(ship_name);
228 // if we have a valid ship type
230 // if this item is checked
231 if(m_ship_list.GetCheck(selected)) {
232 if(ship_pool[selected_team][si_index] <= 0){
233 ship_pool[selected_team][si_index] = 5;
236 m_ship_pool = ship_pool[selected_team][si_index];
239 // otherwise zero the count
241 ship_pool[selected_team][si_index] = 0;
253 // weapon list changed
254 void player_start_editor::OnSelchangeWeaponList()
258 char weapon_name[255] = "";
260 // determine if we've selected something
261 selected = m_weapon_list.GetCurSel();
262 if (selected != -1) {
264 m_weapon_list.GetText(m_weapon_list.GetCurSel(), weapon_name);
265 wi_index = weapon_name_lookup(weapon_name);
267 // if we have a valid weapon type
269 // if this item is checked
270 if(m_weapon_list.GetCheck(selected)) {
271 if(weapon_pool[selected_team][wi_index] <= 0){
272 weapon_pool[selected_team][wi_index] = 100;
275 m_weapon_pool = weapon_pool[selected_team][wi_index];
278 // otherwise zero the count
280 weapon_pool[selected_team][wi_index] = 0;
293 void player_start_editor::OnCancel()
295 theApp.record_window_data(&Player_wnd_data, this);
300 void player_start_editor::OnOK()
304 // store player entry time delay
305 Entry_delay_time = i2f(m_delay);
308 for(i=0; i<MAX_TEAMS; i++){
309 Team_data[i].number_choices = 0;
310 for(idx=0; idx<Num_ship_types; idx++){
311 // if we have ships here
312 if(ship_pool[i][idx] > 0){
313 Team_data[i].ship_count[Team_data[i].number_choices] = ship_pool[i][idx];
314 Team_data[i].ship_list[Team_data[i].number_choices++] = idx;
319 // store weapon pools
320 for(i=0; i<MAX_TEAMS; i++){
321 for(idx=0; idx<Num_weapon_types; idx++){
322 // if we have weapons here
323 Team_data[i].weaponry_pool[idx] = weapon_pool[i][idx];
327 theApp.record_window_data(&Player_wnd_data, this);
331 // ship pool count change
332 void player_start_editor::OnUpdateShipPool()
334 int selected, si_index;
335 char ship_name[255] = "";
343 // if we have a ship selected and checked, update the pool
344 selected = m_ship_list.GetCurSel();
345 if((selected != -1) && m_ship_list.GetCheck(selected)){
347 m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name);
348 si_index = ship_info_lookup(ship_name);
350 // if we have a valid ship type
352 ship_pool[selected_team][si_index] = m_ship_pool;
357 // weapon pool count change
358 void player_start_editor::OnUpdateWeaponPool()
360 int selected, wi_index;
361 char weapon_name[255] = "";
369 // if we have a ship selected and checked, update the pool
370 selected = m_weapon_list.GetCurSel();
371 if((selected != -1) && m_weapon_list.GetCheck(selected)){
373 m_weapon_list.GetText(m_weapon_list.GetCurSel(), weapon_name);
374 wi_index = weapon_info_lookup(weapon_name);
376 // if we have a valid ship type
378 weapon_pool[selected_team][wi_index] = m_weapon_pool;