File: initialships.cpp

package info (click to toggle)
freespace2 3.7.0%2Brepack-2
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 22,848 kB
  • ctags: 41,897
  • sloc: cpp: 369,931; makefile: 1,060; xml: 129; sh: 112
file content (168 lines) | stat: -rw-r--r-- 4,496 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Copyright (C) Volition, Inc. 1999.  All rights reserved.
 *
 * All source code herein is the property of Volition, Inc. You may not sell 
 * or otherwise commercially exploit the source or things you created based on the 
 * source.
 *
*/

// InitialShips.cpp : implementation file
//

#include "stdafx.h"
#include "FRED.h"
#include "InitialShips.h"
#include "CampaignTreeView.h"
#include "CampaignEditorDlg.h"
#include "weapon/weapon.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define IDCAT(x,y)		x ## y

/////////////////////////////////////////////////////////////////////////////
// InitialShips dialog


InitialShips::InitialShips(CWnd* pParent /*=NULL*/)
	: CDialog(InitialShips::IDD, pParent)
{
	//{{AFX_DATA_INIT(InitialShips)
	//}}AFX_DATA_INIT
}


void InitialShips::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(InitialShips)
	DDX_Control(pDX, IDC_INITIAL_LIST, m_initial_list);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(InitialShips, CDialog)
	//{{AFX_MSG_MAP(InitialShips)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// InitialShips message handlers

BOOL InitialShips::OnInitDialog() 
{
	int i, j;

	CDialog::OnInitDialog();

	m_list_count = 0;
	// change the window text, get the index into the array, and check the box for either the ships
	// or weapons
	if ( m_initial_items == INITIAL_SHIPS ) {
		for ( i = 0; i < Num_ship_classes; i++ ) {
			if ( Ship_info[i].flags & SIF_PLAYER_SHIP ) {
				m_initial_list.AddString( Ship_info[i].name );
				if ( Campaign.ships_allowed[i] ) {
					m_initial_list.SetCheck(m_list_count, 1);
				} else if ( (strlen(Campaign.filename) == 0) && strstr(Ship_info[i].name, "Myrmidon") ) { //-V805
					m_initial_list.SetCheck(m_list_count, 1);
				} else {
					m_initial_list.SetCheck(m_list_count, 0);
				}
				m_initial_list.SetItemData(m_list_count, i);
				m_list_count++;
			}
		}

		// set the titale of the window
		SetWindowText("Initial Ships Allowed");
	} else if ( m_initial_items == INITIAL_WEAPONS ) {
		// get the list of initial weapons available by looking at all possible player ships, getting
		// the weapon information for those ships, then putting those weapons onto the list
		int allowed_weapons[MAX_WEAPON_TYPES];

		memset( allowed_weapons, 0, sizeof(allowed_weapons) );
		for (i = 0; i < Num_ship_classes; i++ ) {
			if ( Ship_info[i].flags & SIF_PLAYER_SHIP ) {
				for ( j = 0; j < MAX_WEAPON_TYPES; j++ ) {
					if ( Ship_info[i].allowed_weapons[j] )
						allowed_weapons[j] = 1;
				}
			}
		}

		// now add the weapons to the list
		for (i = 0; i < MAX_WEAPON_TYPES; i++ ) {
			if ( allowed_weapons[i] ) {
				m_initial_list.AddString( Weapon_info[i].name );
				int add_weapon = 0;
				if ( Campaign.weapons_allowed[i] ) {
					add_weapon = 1;
				} else if ( strlen(Campaign.filename) == 0 ) { //-V805
					if ( strstr(Weapon_info[i].name, "Subach")) {
						add_weapon = 1;
					} else if ( strstr(Weapon_info[i].name, "Akheton")) {
						add_weapon = 1;
					} else if ( strstr(Weapon_info[i].name, "Rockeye")) {
						add_weapon = 1;
					} else if ( strstr(Weapon_info[i].name, "Tempest")) {
						add_weapon = 1;
					}
				}

				if (add_weapon) {
					m_initial_list.SetCheck( m_list_count, 1 );
				} else {
					m_initial_list.SetCheck( m_list_count, 0 );
				}

				m_initial_list.SetItemData(m_list_count, i );
				m_list_count++;
			}
		}
		SetWindowText("Initial Weapons Allowed");
	} else
		Int3();


	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void InitialShips::OnOK() 
{
	int i, index;

	// zero out whichever array we are setting
	if ( m_initial_items == INITIAL_SHIPS ) {
		for ( i = 0; i < MAX_SHIP_CLASSES; i++ ){
			Campaign.ships_allowed[i] = 0;
		}
	} else if ( m_initial_items == INITIAL_WEAPONS ) {
		for (i = 0; i < MAX_WEAPON_TYPES; i++ )
			Campaign.weapons_allowed[i] = 0;
	}

	for ( i = 0; i < m_list_count; i++ ) {
		if ( m_initial_list.GetCheck(i) ) {
			// this item is checked.  Get the index into either the ship info array or the weapons
			// array
			index = m_initial_list.GetItemData(i);
			if ( m_initial_items == INITIAL_SHIPS ) {
				Campaign.ships_allowed[index] = 1;
			} else if ( m_initial_items == INITIAL_WEAPONS ) {
				Campaign.weapons_allowed[index] = 1;
			} else
				Int3();
			
		}
	}

	CDialog::OnOK();
}