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