2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/fred2/PlayerStartEditor.cpp $
15 * Player starting point editor dialog box handling code
18 * Revision 1.3 2002/06/09 04:41:16 relnev
19 * added copyright header
21 * Revision 1.2 2002/05/07 03:16:44 theoddone33
22 * The Great Newline Fix
24 * Revision 1.1.1.1 2002/05/03 03:28:08 root
28 * 4 2/23/99 7:03p Dave
29 * Rewrote a horribly mangled and evil team loadout dialog. Bugs gone.
38 #include "playerstarteditor.h"
39 #include "missionparse.h"
41 #include "management.h"
47 static char THIS_FILE[] = __FILE__;
50 /////////////////////////////////////////////////////////////////////////////
51 // player_start_editor dialog
53 player_start_editor::player_start_editor(CWnd* pParent) : CDialog(player_start_editor::IDD, pParent)
55 //{{AFX_DATA_INIT(player_start_editor)
65 void player_start_editor::DoDataExchange(CDataExchange* pDX)
67 CDialog::DoDataExchange(pDX);
68 //{{AFX_DATA_MAP(player_start_editor)
69 DDX_Control(pDX, IDC_POOL_SPIN, m_pool_spin);
70 DDX_Control(pDX, IDC_DELAY_SPIN, m_delay_spin);
71 DDX_Control(pDX, IDC_SPIN1, m_spin1);
72 DDX_Control(pDX, IDC_SHIP_LIST, m_ship_list);
73 DDX_Control(pDX, IDC_WEAPON_LIST, m_weapon_list);
74 DDX_Text(pDX, IDC_DELAY, m_delay);
75 DDX_Text(pDX, IDC_SHIP_POOL, m_ship_pool);
76 DDX_Text(pDX, IDC_WEAPON_POOL, m_weapon_pool);
80 BEGIN_MESSAGE_MAP(player_start_editor, CDialog)
81 //{{AFX_MSG_MAP(player_start_editor)
83 ON_LBN_SELCHANGE(IDC_SHIP_LIST, OnSelchangeShipList)
85 ON_LBN_SELCHANGE(IDC_WEAPON_LIST, OnSelchangeWeaponList)
86 ON_EN_UPDATE(IDC_SHIP_POOL, OnUpdateShipPool)
87 ON_EN_UPDATE(IDC_WEAPON_POOL, OnUpdateWeaponPool)
91 /////////////////////////////////////////////////////////////////////////////
92 // player_start_editor message handlers
94 BOOL player_start_editor::OnInitDialog()
99 // initialize ship pool data
100 memset(ship_pool, 0, sizeof(int) * MAX_TEAMS * MAX_SHIP_TYPES);
101 for(i=0; i<MAX_TEAMS; i++){
102 for(idx=0; idx<Team_data[i].number_choices; idx++){
103 ship_pool[i][Team_data[i].ship_list[idx]] = Team_data[i].ship_count[idx];
107 // initialize weapon pool data
108 memset(weapon_pool, 0, sizeof(int) * MAX_TEAMS * MAX_WEAPON_TYPES);
109 for(i=0; i<MAX_TEAMS; i++){
110 for(idx=0; idx<MAX_WEAPON_TYPES; idx++){
111 weapon_pool[i][idx] = Team_data[i].weaponry_pool[idx];
116 m_delay = f2i(Entry_delay_time);
119 CDialog::OnInitDialog();
120 theApp.init_window(&Player_wnd_data, this);
121 m_spin1.SetRange(0, 99);
122 m_pool_spin.SetRange(0, 9999);
123 m_delay_spin.SetRange(0, 30);
125 // regenerate all the controls
133 // regenerate all controls
134 void player_start_editor::reset_controls()
139 // create a checklistbox for each "player" ship type
140 m_ship_list.ResetContent();
142 for (i=0; i<Num_ship_types; i++) {
143 if (Ship_info[i].flags & SIF_PLAYER_SHIP) {
144 m_ship_list.AddString(Ship_info[i].name);
146 // if the ship currently has pool entries, check it
147 if(ship_pool[selected_team][i] > 0){
148 m_ship_list.SetCheck(ct, TRUE);
150 m_ship_list.SetCheck(ct, FALSE);
158 // create a checklistbox for each weapon ship type
159 m_weapon_list.ResetContent();
161 for (i=0; i<Num_weapon_types; i++) {
162 if (Weapon_info[i].wi_flags & WIF_PLAYER_ALLOWED) {
163 m_weapon_list.AddString(Weapon_info[i].name);
165 // if the ship currently has pool entries, check it
166 if(weapon_pool[selected_team][i] > 0){
167 m_weapon_list.SetCheck(ct, TRUE);
169 m_weapon_list.SetCheck(ct, FALSE);
176 // be sure that nothing is selected
177 m_ship_list.SetCurSel(-1);
178 m_weapon_list.SetCurSel(-1);
182 void player_start_editor::OnInitMenu(CMenu* pMenu)
187 // disable any items we should disable
188 m = pMenu->GetSubMenu(0);
190 // uncheck all menu items
191 for (i = 0; i < Num_teams; i++ ){
192 m->CheckMenuItem(i, MF_BYPOSITION | MF_UNCHECKED);
195 for ( i = Num_teams; i < MAX_TEAMS; i++ ){
196 m->EnableMenuItem(i, MF_BYPOSITION | MF_GRAYED);
199 // put a check next to the currently selected item
200 m->CheckMenuItem(selected_team, MF_BYPOSITION | MF_CHECKED);
202 CDialog::OnInitMenu(pMenu);
205 // switch between active teams
206 BOOL player_start_editor::OnCommand(WPARAM wParam, LPARAM lParam)
225 return CDialog::OnCommand(wParam, lParam);
229 void player_start_editor::OnSelchangeShipList()
233 char ship_name[255] = "";
235 // determine if we've selected something
236 selected = m_ship_list.GetCurSel();
237 if (selected != -1) {
239 m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name);
240 si_index = ship_info_lookup(ship_name);
242 // if we have a valid ship type
244 // if this item is checked
245 if(m_ship_list.GetCheck(selected)) {
246 if(ship_pool[selected_team][si_index] <= 0){
247 ship_pool[selected_team][si_index] = 5;
250 m_ship_pool = ship_pool[selected_team][si_index];
253 // otherwise zero the count
255 ship_pool[selected_team][si_index] = 0;
267 // weapon list changed
268 void player_start_editor::OnSelchangeWeaponList()
272 char weapon_name[255] = "";
274 // determine if we've selected something
275 selected = m_weapon_list.GetCurSel();
276 if (selected != -1) {
278 m_weapon_list.GetText(m_weapon_list.GetCurSel(), weapon_name);
279 wi_index = weapon_name_lookup(weapon_name);
281 // if we have a valid weapon type
283 // if this item is checked
284 if(m_weapon_list.GetCheck(selected)) {
285 if(weapon_pool[selected_team][wi_index] <= 0){
286 weapon_pool[selected_team][wi_index] = 100;
289 m_weapon_pool = weapon_pool[selected_team][wi_index];
292 // otherwise zero the count
294 weapon_pool[selected_team][wi_index] = 0;
307 void player_start_editor::OnCancel()
309 theApp.record_window_data(&Player_wnd_data, this);
314 void player_start_editor::OnOK()
318 // store player entry time delay
319 Entry_delay_time = i2f(m_delay);
322 for(i=0; i<MAX_TEAMS; i++){
323 Team_data[i].number_choices = 0;
324 for(idx=0; idx<Num_ship_types; idx++){
325 // if we have ships here
326 if(ship_pool[i][idx] > 0){
327 Team_data[i].ship_count[Team_data[i].number_choices] = ship_pool[i][idx];
328 Team_data[i].ship_list[Team_data[i].number_choices++] = idx;
333 // store weapon pools
334 for(i=0; i<MAX_TEAMS; i++){
335 for(idx=0; idx<Num_weapon_types; idx++){
336 // if we have weapons here
337 Team_data[i].weaponry_pool[idx] = weapon_pool[i][idx];
341 theApp.record_window_data(&Player_wnd_data, this);
345 // ship pool count change
346 void player_start_editor::OnUpdateShipPool()
348 int selected, si_index;
349 char ship_name[255] = "";
357 // if we have a ship selected and checked, update the pool
358 selected = m_ship_list.GetCurSel();
359 if((selected != -1) && m_ship_list.GetCheck(selected)){
361 m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name);
362 si_index = ship_info_lookup(ship_name);
364 // if we have a valid ship type
366 ship_pool[selected_team][si_index] = m_ship_pool;
371 // weapon pool count change
372 void player_start_editor::OnUpdateWeaponPool()
374 int selected, wi_index;
375 char weapon_name[255] = "";
383 // if we have a ship selected and checked, update the pool
384 selected = m_weapon_list.GetCurSel();
385 if((selected != -1) && m_weapon_list.GetCheck(selected)){
387 m_weapon_list.GetText(m_weapon_list.GetCurSel(), weapon_name);
388 wi_index = weapon_info_lookup(weapon_name);
390 // if we have a valid ship type
392 weapon_pool[selected_team][wi_index] = m_weapon_pool;