FS2_Open
Open source remastering of the Freespace 2 engine
pilotfile.h
Go to the documentation of this file.
1 
2 #ifndef _PILOTFILE_H
3 #define _PILOTFILE_H
4 
5 #include "cfile/cfile.h"
6 #include "globalincs/pstypes.h"
7 #include "stats/scoring.h"
8 
9 
10 class player;
11 
12 
13 // current pilot constants
14 static const unsigned int PLR_FILE_ID = 0x5f524c50; // "PLR_" in file
15 static const unsigned int CSG_FILE_ID = 0x5f475343; // "CSG_" in file
16 // NOTE: Version should be bumped only for adding/removing sections or section
17 // content. It should *NOT* be bumped for limit bumps or anything of
18 // that sort!
19 // 0 - initial version
20 // 1 - Adding support for the player is multi flag
21 // 2 - Add language in use when pilot was created
22 // (due to intel entries using translated text as the primary key)
23 static const ubyte PLR_VERSION = 2;
24 // 0 - initial version
25 // 1 - re-add recent missions
26 // 2 - separate single/multi squad name & pic
27 // 3 - remove separate detail settings for campaigns
28 // 4 - add CPV rollback for Red Alert missions
29 // 5 - save rank to flags for quick access
30 static const ubyte CSG_VERSION = 5;
31 
32 
33 class pilotfile {
34  public:
35  pilotfile();
36  ~pilotfile();
37 
38  bool load_player(const char *callsign, player *_p = NULL);
39  bool load_savefile(const char *campaign);
40 
41  bool save_player(player *_p = NULL);
42  bool save_savefile();
43 
44  // updating stats, multi and/or all-time
45  void update_stats(scoring_struct *stats, bool training = false);
46  void update_stats_backout(scoring_struct *stats, bool training = false);
47  void reset_stats();
48 
49  // for checking to see if a PLR file is basically valid
50  bool verify(const char *fname, int *rank = NULL, char *valid_language = NULL);
51 
52  // whether current campaign savefile has valid data to work with
53  bool is_invalid()
54  {
55  return m_data_invalid;
56  }
57 
58  private:
59  // --------------------------------------------------------------------
60  // info shared between PLR and CSG ...
61  // --------------------------------------------------------------------
62  CFILE *cfp;
63  SCP_string filename;
64  player *p;
65 
66  int version;
67  ubyte csg_ver;
68 
69  // some sections are required before others...
70  bool m_have_flags;
71  bool m_have_info;
72 
73  // set in case data appears wrong, so we can avoid loading/saving campaign savefile
74  bool m_data_invalid;
75 
76  typedef struct index_list_t {
78  int index;
79  int val;
80 
81  index_list_t() :
82  index(-1), val(0)
83  {
84  }
85  } index_list_t;
86 
87  // overall content list, can include reference to more than current
88  // mod/campaign provides
89  // NOTE: order of each list **must be preserved**
90  SCP_vector<index_list_t> ship_list;
91  SCP_vector<index_list_t> weapon_list;
92  SCP_vector<index_list_t> intel_list;
93  SCP_vector<index_list_t> medals_list;
94 
95  // special stats struct, since our use here is not content specific
96  typedef struct scoring_special_t {
97  int score;
98  int rank;
99  int assists;
100  int kill_count;
101  int kill_count_ok;
102  int bonehead_kills;
103 
104  unsigned int p_shots_fired;
105  unsigned int p_shots_hit;
106  unsigned int p_bonehead_hits;
107 
108  unsigned int s_shots_fired;
109  unsigned int s_shots_hit;
110  unsigned int s_bonehead_hits;
111 
112  unsigned int missions_flown;
113  unsigned int flight_time;
114  _fs_time_t last_flown;
115  _fs_time_t last_backup;
116 
117  SCP_vector<index_list_t> ship_kills;
118  SCP_vector<index_list_t> medals_earned;
119 
121  score(0), rank(RANK_ENSIGN), assists(0), kill_count(0), kill_count_ok(0),
122  bonehead_kills(0), p_shots_fired(0), p_shots_hit(0), p_bonehead_hits(0),
123  s_shots_fired(0), s_shots_hit(0), s_bonehead_hits(0), missions_flown(0),
124  flight_time(0), last_flown(0), last_backup(0)
125  {
126  }
128 
129  scoring_special_t all_time_stats;
130  scoring_special_t multi_stats;
131 
132  // sections of a pilot file. includes both plr and csg sections
133  struct Section {
134  enum id {
135  Flags = 0x0001,
136  Info = 0x0002,
137  Loadout = 0x0003,
138  Controls = 0x0004,
139  Multiplayer = 0x0005,
140  Scoring = 0x0006,
141  ScoringMulti = 0x0007,
142  Techroom = 0x0008,
143  HUD = 0x0009,
144  Settings = 0x0010,
145  RedAlert = 0x0011,
146  Variables = 0x0012,
147  Missions = 0x0013,
148  Cutscenes = 0x0014,
149  LastMissions = 0x0015
150  };
151  };
152 
153  // for writing files, sets/updates section info
154  void startSection(Section::id section_id);
155  void endSection();
156  // file offset of the size value for the current section (set with startSection())
157  size_t m_size_offset;
158 
159 
160  // --------------------------------------------------------------------
161  // PLR specific
162  // --------------------------------------------------------------------
163  void plr_reset_data();
164  void plr_close();
165 
166  void plr_read_flags();
167  void plr_read_info();
168  void plr_read_settings();
169  void plr_read_stats();
170  void plr_read_stats_multi();
171  void plr_read_multiplayer();
172  void plr_read_variables();
173  void plr_read_hud();
174  void plr_read_controls();
175 
176  void plr_write_flags();
177  void plr_write_info();
178  void plr_write_settings();
179  void plr_write_stats();
180  void plr_write_stats_multi();
181  void plr_write_multiplayer();
182  void plr_write_variables();
183  void plr_write_hud();
184  void plr_write_controls();
185 
186  // --------------------------------------------------------------------
187  // CSG specific
188  // --------------------------------------------------------------------
189  void csg_reset_data();
190  void csg_close();
191 
192  void csg_read_flags();
193  void csg_read_info();
194  void csg_read_missions();
195  void csg_read_techroom();
196  void csg_read_loadout();
197  void csg_read_stats();
198  void csg_read_redalert();
199  void csg_read_hud();
200  void csg_read_variables();
201  void csg_read_settings();
202  void csg_read_controls();
203  void csg_read_cutscenes();
204  void csg_read_lastmissions();
205 
206  void csg_write_flags();
207  void csg_write_info();
208  void csg_write_missions();
209  void csg_write_techroom();
210  void csg_write_loadout();
211  void csg_write_stats();
212  void csg_write_redalert();
213  void csg_write_hud();
214  void csg_write_variables();
215  void csg_write_settings();
216  void csg_write_controls();
217  void csg_write_cutscenes();
218  void csg_write_lastmissions();
219 
220  // similar to PLR verify, except we only want the rank
221  bool get_csg_rank(int *rank);
222 
223 };
224 
225 extern pilotfile Pilot;
226 
227 extern void convert_pilot_files();
228 
229 #endif // _PILOTFILE_H
SCP_vector< cutscene_info > Cutscenes
Definition: cutscenes.cpp:39
GLuint index
Definition: Glext.h:5608
bool save_savefile()
Definition: csg.cpp:1524
bool is_invalid()
Definition: pilotfile.h:53
long _fs_time_t
Definition: pstypes.h:55
Definition: cfile.h:28
#define RANK_ENSIGN
Definition: scoring.h:30
void reset_stats()
Definition: pilotfile.cpp:302
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
bool verify(const char *fname, int *rank=NULL, char *valid_language=NULL)
Definition: plr.cpp:1006
Definition: player.h:85
GLenum GLuint id
Definition: Glext.h:5156
bool save_player(player *_p=NULL)
Definition: plr.cpp:935
unsigned char ubyte
Definition: pstypes.h:62
GLuint const GLchar * name
Definition: Glext.h:5608
GLuint GLfloat * val
Definition: Glext.h:6741
bool load_savefile(const char *campaign)
Definition: csg.cpp:1347
void update_stats_backout(scoring_struct *stats, bool training=false)
Definition: pilotfile.cpp:185
void update_stats(scoring_struct *stats, bool training=false)
Definition: pilotfile.cpp:66
bool load_player(const char *callsign, player *_p=NULL)
Definition: plr.cpp:779
GLfloat GLfloat p
Definition: Glext.h:8373
void convert_pilot_files()
pilotfile Pilot
Definition: pilotfile.cpp:7