]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/initialships.cpp
fix issue with looping audio streams
[taylor/freespace2.git] / src / fred2 / initialships.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 // InitialShips.cpp : implementation file
10 //
11
12 #include "stdafx.h"
13 #include "fred.h"
14 #include "initialships.h"
15 #include "campaigntreeview.h"
16 #include "campaigneditordlg.h"
17
18 #ifdef _DEBUG
19 #define new DEBUG_NEW
20 #undef THIS_FILE
21 static char THIS_FILE[] = __FILE__;
22 #endif
23
24 #define IDCAT(x,y)              x ## y
25
26 /////////////////////////////////////////////////////////////////////////////
27 // InitialShips dialog
28
29
30 InitialShips::InitialShips(CWnd* pParent /*=NULL*/)
31         : CDialog(InitialShips::IDD, pParent)
32 {
33         //{{AFX_DATA_INIT(InitialShips)
34         //}}AFX_DATA_INIT
35 }
36
37
38 void InitialShips::DoDataExchange(CDataExchange* pDX)
39 {
40         CDialog::DoDataExchange(pDX);
41         //{{AFX_DATA_MAP(InitialShips)
42         DDX_Control(pDX, IDC_INITIAL_LIST, m_initial_list);
43         //}}AFX_DATA_MAP
44 }
45
46
47 BEGIN_MESSAGE_MAP(InitialShips, CDialog)
48         //{{AFX_MSG_MAP(InitialShips)
49         //}}AFX_MSG_MAP
50 END_MESSAGE_MAP()
51
52 /////////////////////////////////////////////////////////////////////////////
53 // InitialShips message handlers
54
55 BOOL InitialShips::OnInitDialog() 
56 {
57         int i, j;
58
59         CDialog::OnInitDialog();
60
61         m_list_count = 0;
62         // change the window text, get the index into the array, and check the box for either the ships
63         // or weapons
64         if ( m_initial_items == INITIAL_SHIPS ) {
65                 for ( i = 0; i < Num_ship_types; i++ ) {
66                         if ( Ship_info[i].flags & SIF_PLAYER_SHIP ) {
67                                 m_initial_list.AddString( Ship_info[i].name );
68                                 if ( Campaign.ships_allowed[i] ) {
69                                         m_initial_list.SetCheck(m_list_count, 1);
70                                 } else if ( (strlen(Campaign.filename) == 0) && strstr(Ship_info[i].name, "Myrmidon") ) {
71                                         m_initial_list.SetCheck(m_list_count, 1);
72                                 } else {
73                                         m_initial_list.SetCheck(m_list_count, 0);
74                                 }
75                                 m_initial_list.SetItemData(m_list_count, i);
76                                 m_list_count++;
77                         }
78                 }
79
80                 // set the titale of the window
81                 SetWindowText("Initial Ships Allowed");
82         } else if ( m_initial_items == INITIAL_WEAPONS ) {
83                 // get the list of initial weapons available by looking at all possible player ships, getting
84                 // the weapon information for those ships, then putting those weapons onto the list
85                 int allowed_weapons[MAX_WEAPON_TYPES];
86
87                 memset( allowed_weapons, 0, sizeof(allowed_weapons) );
88                 for (i = 0; i < Num_ship_types; i++ ) {
89                         if ( Ship_info[i].flags & SIF_PLAYER_SHIP ) {
90                                 for ( j = 0; j < MAX_WEAPON_TYPES; j++ ) {
91                                         if ( Ship_info[i].allowed_weapons[j] )
92                                                 allowed_weapons[j] = 1;
93                                 }
94                         }
95                 }
96
97                 // now add the weapons to the list
98                 for (i = 0; i < MAX_WEAPON_TYPES; i++ ) {
99                         if ( allowed_weapons[i] ) {
100                                 m_initial_list.AddString( Weapon_info[i].name );
101                                 int add_weapon = 0;
102                                 if ( Campaign.weapons_allowed[i] ) {
103                                         add_weapon = 1;
104                                 } else if ( strlen(Campaign.filename) == 0 ) {
105                                         if ( strstr(Weapon_info[i].name, "Subach")) {
106                                                 add_weapon = 1;
107                                         } else if ( strstr(Weapon_info[i].name, "Akheton")) {
108                                                 add_weapon = 1;
109                                         } else if ( strstr(Weapon_info[i].name, "Rockeye")) {
110                                                 add_weapon = 1;
111                                         } else if ( strstr(Weapon_info[i].name, "Tempest")) {
112                                                 add_weapon = 1;
113                                         }
114                                 }
115
116                                 if (add_weapon) {
117                                         m_initial_list.SetCheck( m_list_count, 1 );
118                                 } else {
119                                         m_initial_list.SetCheck( m_list_count, 0 );
120                                 }
121
122                                 m_initial_list.SetItemData(m_list_count, i );
123                                 m_list_count++;
124                         }
125                 }
126                 SetWindowText("Initial Weapons Allowed");
127         } else
128                 Int3();
129
130
131         
132         return TRUE;  // return TRUE unless you set the focus to a control
133                       // EXCEPTION: OCX Property Pages should return FALSE
134 }
135
136 void InitialShips::OnOK() 
137 {
138         int i, index;
139
140         // zero out whichever array we are setting
141         if ( m_initial_items == INITIAL_SHIPS ) {
142                 for ( i = 0; i < MAX_SHIP_TYPES; i++ ){
143                         Campaign.ships_allowed[i] = 0;
144                 }
145         } else if ( m_initial_items == INITIAL_WEAPONS ) {
146                 for (i = 0; i < MAX_WEAPON_TYPES; i++ )
147                         Campaign.weapons_allowed[i] = 0;
148         }
149
150         for ( i = 0; i < m_list_count; i++ ) {
151                 if ( m_initial_list.GetCheck(i) ) {
152                         // this item is checked.  Get the index into either the ship info array or the weapons
153                         // array
154                         index = m_initial_list.GetItemData(i);
155                         if ( m_initial_items == INITIAL_SHIPS ) {
156                                 Campaign.ships_allowed[index] = 1;
157                         } else if ( m_initial_items == INITIAL_WEAPONS ) {
158                                 Campaign.weapons_allowed[index] = 1;
159                         } else
160                                 Int3();
161                         
162                 }
163         }
164
165         CDialog::OnOK();
166 }
167