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