1 /*
2 BStone: A Source port of
3 Blake Stone: Aliens of Gold and Blake Stone: Planet Strike
4 
5 Copyright (c) 1992-2013 Apogee Entertainment, LLC
6 Copyright (c) 2013-2015 Boris I. Bendovsky (bibendovsky@hotmail.com)
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the
20 Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23 
24 
25 #ifndef BSTONE_ID_CA_INCLUDED
26 #define BSTONE_ID_CA_INCLUDED
27 
28 
29 #include <cstdint>
30 #include "3d_def.h"
31 
32 
33 extern int NUM_EPISODES;
34 extern int MAPS_PER_EPISODE;
35 extern int MAPS_WITH_STATS;
36 
37 extern int NUMMAPS;
38 
39 const int MAPPLANES = 2;
40 
41 
42 void UNCACHEGRCHUNK(
43     int chunk);
44 
45 #define THREEBYTEGRSTARTS
46 
47 #ifdef THREEBYTEGRSTARTS
48 #define FILEPOSSIZE 3
49 #else
50 #define FILEPOSSIZE 4
51 #endif
52 
53 // ===========================================================================
54 
55 struct maptype {
56     int32_t planestart[3];
57     uint16_t planelength[3];
58     uint16_t width, height;
59     char name[16];
60 }; // maptype
61 
62 struct huffnode {
63     uint16_t bit0, bit1; // 0-255 is a character, > is a pointer to a node
64 }; // huffnode
65 
66 struct mapfiletype {
67     uint16_t RLEWtag;
68     int32_t headeroffsets[100];
69 //      uint8_t           tileinfo[];
70 }; // mapfiletype
71 
72 // ===========================================================================
73 
74 using AudioSegments = std::vector<uint8_t*>;
75 using GrSegments = std::vector<void*>;
76 using GrNeeded = std::vector<uint8_t>;
77 using MapHeaderSegments = std::vector<maptype*>;
78 
79 
80 extern std::string audioname;
81 
82 extern uint16_t rlew_tag;
83 
84 extern int16_t mapon;
85 
86 extern uint16_t* mapsegs[MAPPLANES];
87 extern MapHeaderSegments mapheaderseg;
88 extern AudioSegments audiosegs;
89 extern GrSegments grsegs;
90 
91 extern GrNeeded grneeded;
92 extern uint8_t ca_levelbit, ca_levelnum;
93 
94 extern char* titleptr[8];
95 
96 extern int16_t profilehandle, debughandle;
97 
98 extern std::string extension;
99 extern std::string gheadname;
100 extern std::string gfilename;
101 extern std::string gdictname;
102 extern std::string mheadname;
103 extern std::string mfilename;
104 extern std::string aheadname;
105 extern std::string afilename;
106 
107 extern int32_t* grstarts; // array of offsets in egagraph, -1 for sparse
108 extern int32_t* audiostarts; // array of offsets in audio / audiot
109 //
110 // hooks for custom cache dialogs
111 //
112 extern void (* drawcachebox)(
113     char* title,
114     uint16_t numcache);
115 extern void (* updatecachebox)();
116 extern void (* finishcachebox)();
117 
118 extern bstone::FileStream grhandle;
119 extern bstone::FileStream maphandle;
120 extern bstone::FileStream audiohandle;
121 
122 extern int32_t chunkcomplen;
123 extern int32_t chunkexplen;
124 
125 #ifdef GRHEADERLINKED
126 extern huffnode* grhuffman;
127 #else
128 extern huffnode grhuffman[255];
129 #endif
130 
131 extern int map_compressed_size;
132 extern std::string map_sha1_string;
133 
134 // ===========================================================================
135 
136 // just for the score box reshifting
137 
138 void CAL_ShiftSprite(
139     uint16_t segment,
140     uint16_t source,
141     uint16_t dest,
142     uint16_t width,
143     uint16_t height,
144     uint16_t pixshift);
145 
146 // ===========================================================================
147 
148 void CA_OpenDebug();
149 void CA_CloseDebug();
150 
151 bool CA_ReadFile(
152     char* filename,
153     void** ptr);
154 bool CA_LoadFile(
155     char* filename,
156     void** ptr);
157 bool CA_WriteFile(
158     char* filename,
159     void* ptr,
160     int32_t length);
161 
162 int32_t CA_RLEWCompress(
163     uint16_t* source,
164     int32_t length,
165     uint16_t* dest,
166     uint16_t rlewtag);
167 
168 void CA_RLEWexpand(
169     uint16_t* source,
170     uint16_t* dest,
171     int32_t length,
172     uint16_t rlewtag);
173 
174 void CA_Startup();
175 void CA_Shutdown();
176 
177 void CA_SetGrPurge();
178 void CA_CacheAudioChunk(
179     int16_t chunk);
180 void CA_LoadAllSounds();
181 
182 void CA_UpLevel();
183 void CA_DownLevel();
184 
185 void CA_SetAllPurge();
186 
187 void CA_ClearMarks();
188 void CA_ClearAllMarks();
189 
190 #define CA_MarkGrChunk(chunk) grneeded[chunk] |= ca_levelbit
191 
192 void CA_CacheGrChunk(
193     int16_t chunk);
194 void CA_CacheMap(
195     int16_t mapnum);
196 
197 void CA_CacheMarks();
198 
199 void CAL_SetupAudioFile();
200 void CAL_SetupGrFile();
201 void CAL_SetupMapFile();
202 
203 void CAL_HuffExpand(
204     uint8_t* source,
205     uint8_t* dest,
206     int32_t length,
207     huffnode* hufftable);
208 
209 void ca_huff_expand_on_screen(
210     uint8_t* source,
211     huffnode* hufftable);
212 
213 void CloseGrFile();
214 void OpenGrFile();
215 
216 // BBi
217 extern int ca_gr_last_expanded_size;
218 
219 std::string ca_load_script(
220     int chunk_id,
221     bool strip_xx = false);
222 
223 
224 #endif // BSTONE_ID_CA_INCLUDED
225