]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/playerstarteditor.cpp
The Great Newline Fix
[taylor/freespace2.git] / src / fred2 / playerstarteditor.cpp
1 /*
2  * $Logfile: /Freespace2/code/fred2/PlayerStartEditor.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Player starting point editor dialog box handling code
8  *
9  * $Log$
10  * Revision 1.2  2002/05/07 03:16:44  theoddone33
11  * The Great Newline Fix
12  *
13  * Revision 1.1.1.1  2002/05/03 03:28:08  root
14  * Initial import.
15  *
16  * 
17  * 4     2/23/99 7:03p Dave
18  * Rewrote a horribly mangled and evil team loadout dialog. Bugs gone.
19  * 
20  *
21  * $NoKeywords: $
22  */
23
24 #include "stdafx.h"
25 #include "fred.h"
26 #include "freddoc.h"
27 #include "playerstarteditor.h"
28 #include "missionparse.h"
29 #include "object.h"
30 #include "management.h"
31 #include "weapon.h"
32
33 #ifdef _DEBUG
34 #define new DEBUG_NEW
35 #undef THIS_FILE
36 static char THIS_FILE[] = __FILE__;
37 #endif
38
39 /////////////////////////////////////////////////////////////////////////////
40 // player_start_editor dialog
41
42 player_start_editor::player_start_editor(CWnd* pParent) : CDialog(player_start_editor::IDD, pParent)
43 {
44         //{{AFX_DATA_INIT(player_start_editor)
45         m_delay = 0;    
46         m_weapon_pool = 0;
47         m_ship_pool = 0;
48         //}}AFX_DATA_INIT
49
50         selected_team = 0;
51         dlg_inited = 0;
52 }
53
54 void player_start_editor::DoDataExchange(CDataExchange* pDX)
55 {
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);
66         //}}AFX_DATA_MAP
67 }
68
69 BEGIN_MESSAGE_MAP(player_start_editor, CDialog)
70         //{{AFX_MSG_MAP(player_start_editor)
71         ON_WM_INITMENU()
72         ON_LBN_SELCHANGE(IDC_SHIP_LIST, OnSelchangeShipList)    
73         ON_WM_CLOSE()
74         ON_LBN_SELCHANGE(IDC_WEAPON_LIST, OnSelchangeWeaponList)        
75         ON_EN_UPDATE(IDC_SHIP_POOL, OnUpdateShipPool)
76         ON_EN_UPDATE(IDC_WEAPON_POOL, OnUpdateWeaponPool)
77         //}}AFX_MSG_MAP
78 END_MESSAGE_MAP()
79
80 /////////////////////////////////////////////////////////////////////////////
81 // player_start_editor message handlers
82
83 BOOL player_start_editor::OnInitDialog() 
84 {
85         int i;
86         int idx;        
87
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];
93                 }
94         }
95
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];
101                 }
102         }
103
104         // entry delay time
105         m_delay = f2i(Entry_delay_time);
106
107         // misc window crap
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);   
113
114         // regenerate all the controls
115         reset_controls();
116
117         dlg_inited = 1;
118
119         return TRUE;
120 }
121
122 // regenerate all controls
123 void player_start_editor::reset_controls()
124 {       
125         int i;
126         int ct;
127
128         // create a checklistbox for each "player" ship type    
129         m_ship_list.ResetContent();
130         ct = 0;
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);
134                         
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);
138                         } else {
139                                 m_ship_list.SetCheck(ct, FALSE);
140                         }
141
142                         // next
143                         ct++;
144                 }
145         }
146
147         // create a checklistbox for each weapon ship type      
148         m_weapon_list.ResetContent();
149         ct = 0;
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);
153                         
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);
157                         } else {
158                                 m_weapon_list.SetCheck(ct, FALSE);
159                         }
160
161                         ct++;
162                 }
163         }       
164
165         // be sure that nothing is selected     
166         m_ship_list.SetCurSel(-1);
167         m_weapon_list.SetCurSel(-1);
168         UpdateData(FALSE);      
169 }
170
171 void player_start_editor::OnInitMenu(CMenu* pMenu)
172 {
173         int i;
174         CMenu *m;
175
176         // disable any items we should disable
177         m = pMenu->GetSubMenu(0);
178
179         // uncheck all menu items
180         for (i = 0; i < Num_teams; i++ ){
181                 m->CheckMenuItem(i, MF_BYPOSITION | MF_UNCHECKED);
182         }
183
184         for ( i = Num_teams; i < MAX_TEAMS; i++ ){
185                 m->EnableMenuItem(i, MF_BYPOSITION | MF_GRAYED);
186         }
187
188         // put a check next to the currently selected item
189         m->CheckMenuItem(selected_team, MF_BYPOSITION | MF_CHECKED);
190
191         CDialog::OnInitMenu(pMenu);
192 }
193
194 // switch between active teams
195 BOOL player_start_editor::OnCommand(WPARAM wParam, LPARAM lParam) 
196 {
197         int id;
198
199         // select a team
200         id = LOWORD(wParam);
201         switch(id){
202         case ID_TEAM_1:
203                 selected_team = 0;
204                 reset_controls();
205                 break;
206
207         case ID_TEAM_2:
208                 selected_team = 1;
209                 reset_controls();
210                 break;  
211         }       
212         
213         // low level stuff
214         return CDialog::OnCommand(wParam, lParam);
215 }
216
217 // ship list changed
218 void player_start_editor::OnSelchangeShipList() 
219 {                       
220         int selected;
221         int si_index;
222         char ship_name[255] = "";
223
224         // determine if we've selected something
225         selected = m_ship_list.GetCurSel();     
226         if (selected != -1) {
227                 // lookup the ship
228                 m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name);
229                 si_index = ship_info_lookup(ship_name);
230
231                 // if we have a valid ship type
232                 if(si_index >= 0){
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;
237                                         m_ship_pool = 5;
238                                 } else {
239                                         m_ship_pool = ship_pool[selected_team][si_index];
240                                 }
241                         } 
242                         // otherwise zero the count
243                         else {
244                                 ship_pool[selected_team][si_index] = 0;
245                                 m_ship_pool = 0;
246                         }               
247                 } else {
248                         Int3();
249                 }
250         }
251                 
252         // update shtuff
253         UpdateData(FALSE);
254 }
255
256 // weapon list changed
257 void player_start_editor::OnSelchangeWeaponList() 
258 {
259         int selected;
260         int wi_index;
261         char weapon_name[255] = "";
262
263         // determine if we've selected something
264         selected = m_weapon_list.GetCurSel();   
265         if (selected != -1) {
266                 // lookup the weapon
267                 m_weapon_list.GetText(m_weapon_list.GetCurSel(), weapon_name);
268                 wi_index = weapon_name_lookup(weapon_name);
269
270                 // if we have a valid weapon type
271                 if(wi_index >= 0){
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;
276                                         m_weapon_pool = 100;
277                                 } else {
278                                         m_weapon_pool = weapon_pool[selected_team][wi_index];
279                                 }
280                         } 
281                         // otherwise zero the count
282                         else {
283                                 weapon_pool[selected_team][wi_index] = 0;
284                                 m_weapon_pool = 0;
285                         }               
286                 } else {
287                         Int3();
288                 }
289         }
290                 
291         // update shtuff
292         UpdateData(FALSE);
293 }
294
295 // cancel
296 void player_start_editor::OnCancel()
297 {
298         theApp.record_window_data(&Player_wnd_data, this);
299         CDialog::OnCancel();
300 }
301
302 // ok
303 void player_start_editor::OnOK()
304 {
305         int i, idx;
306
307         // store player entry time delay
308         Entry_delay_time = i2f(m_delay);        
309
310         // store ship pools     
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;
318                         }
319                 }
320         }
321
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];
327                 }
328         }
329
330         theApp.record_window_data(&Player_wnd_data, this);
331         CDialog::OnOK();
332 }
333
334 // ship pool count change
335 void player_start_editor::OnUpdateShipPool() 
336 {
337         int selected, si_index;
338         char ship_name[255] = "";
339
340         if (!dlg_inited){
341                 return;
342         }
343
344         UpdateData(TRUE);       
345         
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)){
349                 // lookup the ship
350                 m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name);
351                 si_index = ship_info_lookup(ship_name);
352
353                 // if we have a valid ship type
354                 if(si_index >= 0){
355                         ship_pool[selected_team][si_index] = m_ship_pool;
356                 }
357         };
358 }
359
360 // weapon pool count change
361 void player_start_editor::OnUpdateWeaponPool() 
362 {
363         int selected, wi_index;
364         char weapon_name[255] = "";
365
366         if (!dlg_inited){
367                 return;
368         }
369
370         UpdateData(TRUE);       
371         
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)){
375                 // lookup the ship
376                 m_weapon_list.GetText(m_weapon_list.GetCurSel(), weapon_name);
377                 wi_index = weapon_info_lookup(weapon_name);
378
379                 // if we have a valid ship type
380                 if(wi_index >= 0){
381                         weapon_pool[selected_team][wi_index] = m_weapon_pool;
382                 }
383         };
384 }