]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/playerstarteditor.cpp
fix issue with looping audio streams
[taylor/freespace2.git] / src / fred2 / playerstarteditor.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
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
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/fred2/PlayerStartEditor.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Player starting point editor dialog box handling code
16  *
17  * $Log$
18  * Revision 1.3  2002/06/09 04:41:16  relnev
19  * added copyright header
20  *
21  * Revision 1.2  2002/05/07 03:16:44  theoddone33
22  * The Great Newline Fix
23  *
24  * Revision 1.1.1.1  2002/05/03 03:28:08  root
25  * Initial import.
26  *
27  * 
28  * 4     2/23/99 7:03p Dave
29  * Rewrote a horribly mangled and evil team loadout dialog. Bugs gone.
30  * 
31  *
32  * $NoKeywords: $
33  */
34
35 #include "stdafx.h"
36 #include "fred.h"
37 #include "freddoc.h"
38 #include "playerstarteditor.h"
39 #include "missionparse.h"
40 #include "object.h"
41 #include "management.h"
42 #include "weapon.h"
43
44 #ifdef _DEBUG
45 #define new DEBUG_NEW
46 #undef THIS_FILE
47 static char THIS_FILE[] = __FILE__;
48 #endif
49
50 /////////////////////////////////////////////////////////////////////////////
51 // player_start_editor dialog
52
53 player_start_editor::player_start_editor(CWnd* pParent) : CDialog(player_start_editor::IDD, pParent)
54 {
55         //{{AFX_DATA_INIT(player_start_editor)
56         m_delay = 0;    
57         m_weapon_pool = 0;
58         m_ship_pool = 0;
59         //}}AFX_DATA_INIT
60
61         selected_team = 0;
62         dlg_inited = 0;
63 }
64
65 void player_start_editor::DoDataExchange(CDataExchange* pDX)
66 {
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);
77         //}}AFX_DATA_MAP
78 }
79
80 BEGIN_MESSAGE_MAP(player_start_editor, CDialog)
81         //{{AFX_MSG_MAP(player_start_editor)
82         ON_WM_INITMENU()
83         ON_LBN_SELCHANGE(IDC_SHIP_LIST, OnSelchangeShipList)    
84         ON_WM_CLOSE()
85         ON_LBN_SELCHANGE(IDC_WEAPON_LIST, OnSelchangeWeaponList)        
86         ON_EN_UPDATE(IDC_SHIP_POOL, OnUpdateShipPool)
87         ON_EN_UPDATE(IDC_WEAPON_POOL, OnUpdateWeaponPool)
88         //}}AFX_MSG_MAP
89 END_MESSAGE_MAP()
90
91 /////////////////////////////////////////////////////////////////////////////
92 // player_start_editor message handlers
93
94 BOOL player_start_editor::OnInitDialog() 
95 {
96         int i;
97         int idx;        
98
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];
104                 }
105         }
106
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];
112                 }
113         }
114
115         // entry delay time
116         m_delay = f2i(Entry_delay_time);
117
118         // misc window crap
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);   
124
125         // regenerate all the controls
126         reset_controls();
127
128         dlg_inited = 1;
129
130         return TRUE;
131 }
132
133 // regenerate all controls
134 void player_start_editor::reset_controls()
135 {       
136         int i;
137         int ct;
138
139         // create a checklistbox for each "player" ship type    
140         m_ship_list.ResetContent();
141         ct = 0;
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);
145                         
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);
149                         } else {
150                                 m_ship_list.SetCheck(ct, FALSE);
151                         }
152
153                         // next
154                         ct++;
155                 }
156         }
157
158         // create a checklistbox for each weapon ship type      
159         m_weapon_list.ResetContent();
160         ct = 0;
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);
164                         
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);
168                         } else {
169                                 m_weapon_list.SetCheck(ct, FALSE);
170                         }
171
172                         ct++;
173                 }
174         }       
175
176         // be sure that nothing is selected     
177         m_ship_list.SetCurSel(-1);
178         m_weapon_list.SetCurSel(-1);
179         UpdateData(FALSE);      
180 }
181
182 void player_start_editor::OnInitMenu(CMenu* pMenu)
183 {
184         int i;
185         CMenu *m;
186
187         // disable any items we should disable
188         m = pMenu->GetSubMenu(0);
189
190         // uncheck all menu items
191         for (i = 0; i < Num_teams; i++ ){
192                 m->CheckMenuItem(i, MF_BYPOSITION | MF_UNCHECKED);
193         }
194
195         for ( i = Num_teams; i < MAX_TEAMS; i++ ){
196                 m->EnableMenuItem(i, MF_BYPOSITION | MF_GRAYED);
197         }
198
199         // put a check next to the currently selected item
200         m->CheckMenuItem(selected_team, MF_BYPOSITION | MF_CHECKED);
201
202         CDialog::OnInitMenu(pMenu);
203 }
204
205 // switch between active teams
206 BOOL player_start_editor::OnCommand(WPARAM wParam, LPARAM lParam) 
207 {
208         int id;
209
210         // select a team
211         id = LOWORD(wParam);
212         switch(id){
213         case ID_TEAM_1:
214                 selected_team = 0;
215                 reset_controls();
216                 break;
217
218         case ID_TEAM_2:
219                 selected_team = 1;
220                 reset_controls();
221                 break;  
222         }       
223         
224         // low level stuff
225         return CDialog::OnCommand(wParam, lParam);
226 }
227
228 // ship list changed
229 void player_start_editor::OnSelchangeShipList() 
230 {                       
231         int selected;
232         int si_index;
233         char ship_name[255] = "";
234
235         // determine if we've selected something
236         selected = m_ship_list.GetCurSel();     
237         if (selected != -1) {
238                 // lookup the ship
239                 m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name);
240                 si_index = ship_info_lookup(ship_name);
241
242                 // if we have a valid ship type
243                 if(si_index >= 0){
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;
248                                         m_ship_pool = 5;
249                                 } else {
250                                         m_ship_pool = ship_pool[selected_team][si_index];
251                                 }
252                         } 
253                         // otherwise zero the count
254                         else {
255                                 ship_pool[selected_team][si_index] = 0;
256                                 m_ship_pool = 0;
257                         }               
258                 } else {
259                         Int3();
260                 }
261         }
262                 
263         // update shtuff
264         UpdateData(FALSE);
265 }
266
267 // weapon list changed
268 void player_start_editor::OnSelchangeWeaponList() 
269 {
270         int selected;
271         int wi_index;
272         char weapon_name[255] = "";
273
274         // determine if we've selected something
275         selected = m_weapon_list.GetCurSel();   
276         if (selected != -1) {
277                 // lookup the weapon
278                 m_weapon_list.GetText(m_weapon_list.GetCurSel(), weapon_name);
279                 wi_index = weapon_name_lookup(weapon_name);
280
281                 // if we have a valid weapon type
282                 if(wi_index >= 0){
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;
287                                         m_weapon_pool = 100;
288                                 } else {
289                                         m_weapon_pool = weapon_pool[selected_team][wi_index];
290                                 }
291                         } 
292                         // otherwise zero the count
293                         else {
294                                 weapon_pool[selected_team][wi_index] = 0;
295                                 m_weapon_pool = 0;
296                         }               
297                 } else {
298                         Int3();
299                 }
300         }
301                 
302         // update shtuff
303         UpdateData(FALSE);
304 }
305
306 // cancel
307 void player_start_editor::OnCancel()
308 {
309         theApp.record_window_data(&Player_wnd_data, this);
310         CDialog::OnCancel();
311 }
312
313 // ok
314 void player_start_editor::OnOK()
315 {
316         int i, idx;
317
318         // store player entry time delay
319         Entry_delay_time = i2f(m_delay);        
320
321         // store ship pools     
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;
329                         }
330                 }
331         }
332
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];
338                 }
339         }
340
341         theApp.record_window_data(&Player_wnd_data, this);
342         CDialog::OnOK();
343 }
344
345 // ship pool count change
346 void player_start_editor::OnUpdateShipPool() 
347 {
348         int selected, si_index;
349         char ship_name[255] = "";
350
351         if (!dlg_inited){
352                 return;
353         }
354
355         UpdateData(TRUE);       
356         
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)){
360                 // lookup the ship
361                 m_ship_list.GetText(m_ship_list.GetCurSel(), ship_name);
362                 si_index = ship_info_lookup(ship_name);
363
364                 // if we have a valid ship type
365                 if(si_index >= 0){
366                         ship_pool[selected_team][si_index] = m_ship_pool;
367                 }
368         };
369 }
370
371 // weapon pool count change
372 void player_start_editor::OnUpdateWeaponPool() 
373 {
374         int selected, wi_index;
375         char weapon_name[255] = "";
376
377         if (!dlg_inited){
378                 return;
379         }
380
381         UpdateData(TRUE);       
382         
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)){
386                 // lookup the ship
387                 m_weapon_list.GetText(m_weapon_list.GetCurSel(), weapon_name);
388                 wi_index = weapon_info_lookup(weapon_name);
389
390                 // if we have a valid ship type
391                 if(wi_index >= 0){
392                         weapon_pool[selected_team][wi_index] = m_weapon_pool;
393                 }
394         };
395 }