2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
9 // InitialShips.cpp : implementation file
14 #include "initialships.h"
15 #include "campaigntreeview.h"
16 #include "campaigneditordlg.h"
21 static char THIS_FILE[] = __FILE__;
24 #define IDCAT(x,y) x ## y
26 /////////////////////////////////////////////////////////////////////////////
27 // InitialShips dialog
30 InitialShips::InitialShips(CWnd* pParent /*=NULL*/)
31 : CDialog(InitialShips::IDD, pParent)
33 //{{AFX_DATA_INIT(InitialShips)
38 void InitialShips::DoDataExchange(CDataExchange* pDX)
40 CDialog::DoDataExchange(pDX);
41 //{{AFX_DATA_MAP(InitialShips)
42 DDX_Control(pDX, IDC_INITIAL_LIST, m_initial_list);
47 BEGIN_MESSAGE_MAP(InitialShips, CDialog)
48 //{{AFX_MSG_MAP(InitialShips)
52 /////////////////////////////////////////////////////////////////////////////
53 // InitialShips message handlers
55 BOOL InitialShips::OnInitDialog()
59 CDialog::OnInitDialog();
62 // change the window text, get the index into the array, and check the box for either the ships
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);
73 m_initial_list.SetCheck(m_list_count, 0);
75 m_initial_list.SetItemData(m_list_count, i);
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];
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;
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 );
102 if ( Campaign.weapons_allowed[i] ) {
104 } else if ( strlen(Campaign.filename) == 0 ) {
105 if ( strstr(Weapon_info[i].name, "Subach")) {
107 } else if ( strstr(Weapon_info[i].name, "Akheton")) {
109 } else if ( strstr(Weapon_info[i].name, "Rockeye")) {
111 } else if ( strstr(Weapon_info[i].name, "Tempest")) {
117 m_initial_list.SetCheck( m_list_count, 1 );
119 m_initial_list.SetCheck( m_list_count, 0 );
122 m_initial_list.SetItemData(m_list_count, i );
126 SetWindowText("Initial Weapons Allowed");
132 return TRUE; // return TRUE unless you set the focus to a control
133 // EXCEPTION: OCX Property Pages should return FALSE
136 void InitialShips::OnOK()
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;
145 } else if ( m_initial_items == INITIAL_WEAPONS ) {
146 for (i = 0; i < MAX_WEAPON_TYPES; i++ )
147 Campaign.weapons_allowed[i] = 0;
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
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;