1 // InitialShips.cpp : implementation file
6 #include "initialships.h"
7 #include "campaigntreeview.h"
8 #include "campaigneditordlg.h"
13 static char THIS_FILE[] = __FILE__;
16 #define IDCAT(x,y) x ## y
18 /////////////////////////////////////////////////////////////////////////////
19 // InitialShips dialog
22 InitialShips::InitialShips(CWnd* pParent /*=NULL*/)
23 : CDialog(InitialShips::IDD, pParent)
25 //{{AFX_DATA_INIT(InitialShips)
30 void InitialShips::DoDataExchange(CDataExchange* pDX)
32 CDialog::DoDataExchange(pDX);
33 //{{AFX_DATA_MAP(InitialShips)
34 DDX_Control(pDX, IDC_INITIAL_LIST, m_initial_list);
39 BEGIN_MESSAGE_MAP(InitialShips, CDialog)
40 //{{AFX_MSG_MAP(InitialShips)
44 /////////////////////////////////////////////////////////////////////////////
45 // InitialShips message handlers
47 BOOL InitialShips::OnInitDialog()
51 CDialog::OnInitDialog();
54 // change the window text, get the index into the array, and check the box for either the ships
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);
65 m_initial_list.SetCheck(m_list_count, 0);
67 m_initial_list.SetItemData(m_list_count, i);
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];
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;
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 );
94 if ( Campaign.weapons_allowed[i] ) {
96 } else if ( strlen(Campaign.filename) == 0 ) {
97 if ( strstr(Weapon_info[i].name, "Subach")) {
99 } else if ( strstr(Weapon_info[i].name, "Akheton")) {
101 } else if ( strstr(Weapon_info[i].name, "Rockeye")) {
103 } else if ( strstr(Weapon_info[i].name, "Tempest")) {
109 m_initial_list.SetCheck( m_list_count, 1 );
111 m_initial_list.SetCheck( m_list_count, 0 );
114 m_initial_list.SetItemData(m_list_count, i );
118 SetWindowText("Initial Weapons Allowed");
124 return TRUE; // return TRUE unless you set the focus to a control
125 // EXCEPTION: OCX Property Pages should return FALSE
128 void InitialShips::OnOK()
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;
137 } else if ( m_initial_items == INITIAL_WEAPONS ) {
138 for (i = 0; i < MAX_WEAPON_TYPES; i++ )
139 Campaign.weapons_allowed[i] = 0;
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
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;