2 * $Logfile: /Freespace2/code/fred2/PlayerStartEditor.cpp $
7 * Player starting point editor dialog box handling code
10 * Revision 1.2 2002/05/07 03:16:44 theoddone33
11 * The Great Newline Fix
13 * Revision 1.1.1.1 2002/05/03 03:28:08 root
17 * 4 2/23/99 7:03p Dave
18 * Rewrote a horribly mangled and evil team loadout dialog. Bugs gone.
27 #include "playerstarteditor.h"
28 #include "missionparse.h"
30 #include "management.h"
36 static char THIS_FILE[] = __FILE__;
39 /////////////////////////////////////////////////////////////////////////////
40 // player_start_editor dialog
42 player_start_editor::player_start_editor(CWnd* pParent) : CDialog(player_start_editor::IDD, pParent)
44 //{{AFX_DATA_INIT(player_start_editor)
54 void player_start_editor::DoDataExchange(CDataExchange* pDX)
56 CDialog::DoDataExchange(pDX);
57 //{{AFX_DATA_MAP(player_start_editor)
58 DDX_Control(pDX, IDC_POOL_SPIN, m_pool_spin);
59 DDX_Control(pDX, IDC_DELAY_SPIN, m_delay_spin);
60 DDX_Control(pDX, IDC_SPIN1, m_spin1);
61 DDX_Control(pDX, IDC_SHIP_LIST, m_ship_list);
62 DDX_Control(pDX, IDC_WEAPON_LIST, m_weapon_list);
63 DDX_Text(pDX, IDC_DELAY, m_delay);
64 DDX_Text(pDX, IDC_SHIP_POOL, m_ship_pool);
65 DDX_Text(pDX, IDC_WEAPON_POOL, m_weapon_pool);
69 BEGIN_MESSAGE_MAP(player_start_editor, CDialog)
70 //{{AFX_MSG_MAP(player_start_editor)
72 ON_LBN_SELCHANGE(IDC_SHIP_LIST, OnSelchangeShipList)
74 ON_LBN_SELCHANGE(IDC_WEAPON_LIST, OnSelchangeWeaponList)
75 ON_EN_UPDATE(IDC_SHIP_POOL, OnUpdateShipPool)
76 ON_EN_UPDATE(IDC_WEAPON_POOL, OnUpdateWeaponPool)
80 /////////////////////////////////////////////////////////////////////////////
81 // player_start_editor message handlers
83 BOOL player_start_editor::OnInitDialog()
88 // initialize ship pool data
89 memset(ship_pool, 0, sizeof(int) * MAX_TEAMS * MAX_SHIP_TYPES);
90 for(i=0; i<MAX_TEAMS; i++){
91 for(idx=0; idx<Team_data[i].number_choices; idx++){
92 ship_pool[i][Team_data[i].ship_list[idx]] = Team_data[i].ship_count[idx];
96 // initialize weapon pool data
97 memset(weapon_pool, 0, sizeof(int) * MAX_TEAMS * MAX_WEAPON_TYPES);
98 for(i=0; i<MAX_TEAMS; i++){
99 for(idx=0; idx<MAX_WEAPON_TYPES; idx++){
100 weapon_pool[i][idx] = Team_data[i].weaponry_pool[idx];
105 m_delay = f2i(Entry_delay_time);
108 CDialog::OnInitDialog();
109 theApp.init_window(&Player_wnd_data, this);
110 m_spin1.SetRange(0, 99);
111 m_pool_spin.SetRange(0, 9999);
112 m_delay_spin.SetRange(0, 30);
114 // regenerate all the controls
122 // regenerate all controls
123 void player_start_editor::reset_controls()
128 // create a checklistbox for each "player" ship type
129 m_ship_list.ResetContent();
131 for (i=0; i<Num_ship_types; i++) {
132 if (Ship_info[i].flags & SIF_PLAYER_SHIP) {
133 m_ship_list.AddString(Ship_info[i].name);
135 // if the ship currently has pool entries, check it
136 if(ship_pool[selected_team][i] > 0){
137 m_ship_list.SetCheck(ct, TRUE);
139 m_ship_list.SetCheck(ct, FALSE);
147 // create a checklistbox for each weapon ship type
148 m_weapon_list.ResetContent();
150 for (i=0; i<Num_weapon_types; i++) {
151 if (Weapon_info[i].wi_flags & WIF_PLAYER_ALLOWED) {
152 m_weapon_list.AddString(Weapon_info[i].name);
154 // if the ship currently has pool entries, check it
155 if(weapon_pool[selected_team][i] > 0){
156 m_weapon_list.SetCheck(ct, TRUE);
158 m_weapon_list.SetCheck(ct, FALSE);
165 // be sure that nothing is selected
166 m_ship_list.SetCurSel(-1);
167 m_weapon_list.SetCurSel(-1);
171 void player_start_editor::OnInitMenu(CMenu* pMenu)
176 // disable any items we should disable
177 m = pMenu->GetSubMenu(0);
179 // uncheck all menu items
180 for (i = 0; i < Num_teams; i++ ){
181 m->CheckMenuItem(i, MF_BYPOSITION | MF_UNCHECKED);
184 for ( i = Num_teams; i < MAX_TEAMS; i++ ){
185 m->EnableMenuItem(i, MF_BYPOSITION | MF_GRAYED);
188 // put a check next to the currently selected item
189 m->CheckMenuItem(selected_team, MF_BYPOSITION | MF_CHECKED);
191 CDialog::OnInitMenu(pMenu);
194 // switch between active teams
195 BOOL player_start_editor::OnCommand(WPARAM wParam, LPARAM lParam)
214 return CDialog::OnCommand(wParam, lParam);
218 void player_start_editor::OnSelchangeShipList()
222 char ship_name[255] = "";
224 // determine if we've selected something
225 selected = m_ship_list.GetCurSel();
226 if (selected != -1) {
228 m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name);
229 si_index = ship_info_lookup(ship_name);
231 // if we have a valid ship type
233 // if this item is checked
234 if(m_ship_list.GetCheck(selected)) {
235 if(ship_pool[selected_team][si_index] <= 0){
236 ship_pool[selected_team][si_index] = 5;
239 m_ship_pool = ship_pool[selected_team][si_index];
242 // otherwise zero the count
244 ship_pool[selected_team][si_index] = 0;
256 // weapon list changed
257 void player_start_editor::OnSelchangeWeaponList()
261 char weapon_name[255] = "";
263 // determine if we've selected something
264 selected = m_weapon_list.GetCurSel();
265 if (selected != -1) {
267 m_weapon_list.GetText(m_weapon_list.GetCurSel(), weapon_name);
268 wi_index = weapon_name_lookup(weapon_name);
270 // if we have a valid weapon type
272 // if this item is checked
273 if(m_weapon_list.GetCheck(selected)) {
274 if(weapon_pool[selected_team][wi_index] <= 0){
275 weapon_pool[selected_team][wi_index] = 100;
278 m_weapon_pool = weapon_pool[selected_team][wi_index];
281 // otherwise zero the count
283 weapon_pool[selected_team][wi_index] = 0;
296 void player_start_editor::OnCancel()
298 theApp.record_window_data(&Player_wnd_data, this);
303 void player_start_editor::OnOK()
307 // store player entry time delay
308 Entry_delay_time = i2f(m_delay);
311 for(i=0; i<MAX_TEAMS; i++){
312 Team_data[i].number_choices = 0;
313 for(idx=0; idx<Num_ship_types; idx++){
314 // if we have ships here
315 if(ship_pool[i][idx] > 0){
316 Team_data[i].ship_count[Team_data[i].number_choices] = ship_pool[i][idx];
317 Team_data[i].ship_list[Team_data[i].number_choices++] = idx;
322 // store weapon pools
323 for(i=0; i<MAX_TEAMS; i++){
324 for(idx=0; idx<Num_weapon_types; idx++){
325 // if we have weapons here
326 Team_data[i].weaponry_pool[idx] = weapon_pool[i][idx];
330 theApp.record_window_data(&Player_wnd_data, this);
334 // ship pool count change
335 void player_start_editor::OnUpdateShipPool()
337 int selected, si_index;
338 char ship_name[255] = "";
346 // if we have a ship selected and checked, update the pool
347 selected = m_ship_list.GetCurSel();
348 if((selected != -1) && m_ship_list.GetCheck(selected)){
350 m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name);
351 si_index = ship_info_lookup(ship_name);
353 // if we have a valid ship type
355 ship_pool[selected_team][si_index] = m_ship_pool;
360 // weapon pool count change
361 void player_start_editor::OnUpdateWeaponPool()
363 int selected, wi_index;
364 char weapon_name[255] = "";
372 // if we have a ship selected and checked, update the pool
373 selected = m_weapon_list.GetCurSel();
374 if((selected != -1) && m_weapon_list.GetCheck(selected)){
376 m_weapon_list.GetText(m_weapon_list.GetCurSel(), weapon_name);
377 wi_index = weapon_info_lookup(weapon_name);
379 // if we have a valid ship type
381 weapon_pool[selected_team][wi_index] = m_weapon_pool;