1 /*
2  * Seven Kingdoms: Ancient Adversaries
3  *
4  * Copyright 1997,1998 Enlight Software Ltd.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 //Filename    :: ODYNARRB.H
22 //Description :: Dynamic Array Object Version B
23 
24 #ifndef __ODYNARRB_H
25 #define __ODYNARRB_H
26 
27 #ifndef __ODYNARR_H
28 #include <ODYNARR.h>
29 #endif
30 
31 //------------ Define Constant -------------//
32 
33 #define DEFAULT_REUSE_INTERVAL_DAYS		3
34 
35 //----------- Define variable type -----------//
36 
37 typedef char* (*CreateEleFP)();
38 
39 //--------- Define struct EmptyRoom -----------//
40 
41 #pragma pack(1)
42 struct EmptyRoom
43 {
44 	short	recno;
45 	int   deleted_game_date;
46 };
47 #pragma pack()
48 
49 //---------- Define class DynArrayB -----------//
50 
51 #pragma pack(1)
52 class DynArrayB : public DynArray
53 {
54 public:
55 	EmptyRoom*  empty_room_array;
56 	short  		empty_room_num;  	// rooms allocated
57 	short  		empty_room_count;	// rooms used
58 	short			reuse_interval_days;
59 
60 public:
61 	DynArrayB(int,int=DEF_DYNARRAY_BLOCK_SIZE,int reuseIntervalDays=0);
62    ~DynArrayB();
63 
64    // packed_size()  is the size when the array is packed (deleted record are actually removed)
65    // packed_recno() is the recno when the array is packed
66 
packed_size()67    int  packed_size() const  { return size() - empty_room_count; }
68    int  packed_recno(int) const;	// Given the recno unpacked, it returns the recno packed.
69 
70    void linkin(const void*);
71    void linkout(int= -1);
72    void zap();
73 
74 	int  write_file(File*);    	// Write current dynamic array to file
75 	int  read_file(File*);   	  	// Read dynamic array from file
76 
77 	int  write_empty_room(File*);    // Write current dynamic array to file
78 	int  read_empty_room(File*);     // Read dynamic array from file
79 
80 	int  write_ptr_array(File*, int);
81 	int  read_ptr_array(File*, int, CreateEleFP);
82 };
83 #pragma pack()
84 
85 //---------------------------------------------//
86 
87 #endif
88 
89 
90