File: OGFILE.h

package info (click to toggle)
7kaa 2.15.7%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 134,980 kB
  • sloc: cpp: 137,722; ansic: 3,599; asm: 3,523; perl: 1,665; makefile: 1,185; sh: 185; pascal: 27
file content (147 lines) | stat: -rw-r--r-- 3,698 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
/*
 * Seven Kingdoms: Ancient Adversaries
 *
 * Copyright 1997,1998 Enlight Software Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

//Filename    : OGFILE.H
//Description : Object Game file, save and restore game

#ifndef __OGFILE_H
#define __OGFILE_H

#include <cstdint>
#include <FilePath.h>

#ifndef __ONATION_H
#include <ONATION.h>
#endif

class File;

//-------- Define class GameFile -----------//

// Struct is binary compatible to FILETIME on Windows
#pragma pack(1)
struct GameFileDate {
	uint32_t dwLowDateTime;
	uint32_t dwHighDateTime;
};
#pragma pack()

//-------- Define class GameFile -----------//

struct GameFileHeader;

class GameFile
{
public:
	uint32_t     class_size;    // for version compare
	char         file_name[FilePath::MAX_FILE_PATH+1];

	char         player_name[HUMAN_NAME_LEN+1];

	char         race_id;
	char         nation_color;

	int          game_date;     // the game date of the saved game
	GameFileDate file_date;     // saving game date
	short        terrain_set;

public:
	int   save_game(const char* fileName=NULL);
	int   load_game(const char* base_path, const char* filePath=NULL);

	void  set_file_name();
	int   read_game_header(const char* filePath);

	const char *status_str();

private:
	int   validate_header();

	void  save_process();
	void  load_process();
	int   write_game_header(File* filePtr);

	int   write_file(File*);
	int   write_file_1(File*);
	int   write_file_2(File*);
	int   write_file_3(File*);

	int   read_file(File*);
	int   read_file_1(File*);
	int   read_file_2(File*);
	int   read_file_3(File*);

	void  write_book_mark(File* filePtr, short bookMark);
	int   read_book_mark(File* filePtr, short bookMark);

	void  write_record(GameFileHeader* r);
	void  read_record(GameFileHeader* r);
};

//------- Define class GameFileArray --------//

class GameFileArray : public DynArray
{
public:
	char     demo_format;       // whether write the game in shareware format or not (only selectable in design mode)

	//### begin alex 5/3 ###//
	short	load_file_game_version;	// game version of load file
	char	same_version;		// true if major version of the load game is same as that of the program
	//#### end alex 5/3 ####//

private:
	char     has_read_hall_of_fame;
	char     last_file_name[FilePath::MAX_FILE_PATH+1]; // (persisted via HallOfFame)

public:
	GameFileArray();

	void init(const char *extStr);
	void deinit();

	int  menu(int, int *recno=NULL);

	int  save_game()    { return menu(1); }
	int  load_game()    { return menu(2); }

	int save_new_game(const char* =NULL); // save a new game immediately without prompting menu

	GameFile* operator[](int recNo);

private:
	void set_file_name(char* /*out*/ fileName, int size);

	void disp_browse();
	static void disp_entry_info(const GameFile* entry, int x, int y);
	void load_all_game_header(const char *extStr);
	int  process_action(int=0);
	void del_game();

};

extern GameFileArray game_file_array;
extern GameFile game_file;
extern const char *glob_save_file;
extern const char *glob_save_multi_file;

//-------------------------------------//

#endif