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