aboutsummaryrefslogtreecommitdiff
path: root/devtools/create_drascula/create_drascula.cpp
blob: 9ea2da380a15a05db43df0a94bdbbd6c60d6ab65 (plain)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 * This is a utility for storing all the hardcoded data of Drascula in a separate
 * data file, used by the game engine
 */

 // HACK to allow building with the SDL backend on MinGW
// see bug #1800764 "TOOLS: MinGW tools building broken"
#ifdef main
#undef main
#endif // main

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "create_drascula.h"
#include "staticdata.h"

#define DRASCULA_DAT_VER 4	// 1 byte

static void writeByte(FILE *fp, uint8 b) {
	fwrite(&b, 1, 1, fp);
}

static void writeUint16BE(FILE *fp, uint16 value) {
	writeByte(fp, (uint8)(value >> 8));
	writeByte(fp, (uint8)(value & 0xFF));
}

void writeSint16BE(FILE *fp, int16 value) {
	writeUint16BE(fp, (uint16)value);
}

int main(int argc, char *argv[]) {
	FILE* outFile;
	int i, lang;
	int len, len1, pad;
	uint8 padBuf[DATAALIGNMENT];

	for (i = 0; i < DATAALIGNMENT; i++)
		padBuf[i] = 0;

	outFile = fopen("drascula.dat", "wb");

	// Write header
	fwrite("DRASCULA", 8, 1, outFile);

	writeByte(outFile, DRASCULA_DAT_VER);

	// Write charmap
	writeUint16BE(outFile, ARRAYSIZE(charMap));
	for (i = 0; i < ARRAYSIZE(charMap); i++) {
		writeByte(outFile, charMap[i].inChar);
		writeSint16BE(outFile, charMap[i].mappedChar);
		writeByte(outFile, charMap[i].charType);
	}

	// Write item locations
	writeUint16BE(outFile, ARRAYSIZE(itemLocations));
	for (i = 0; i < ARRAYSIZE(itemLocations); i++) {
		writeSint16BE(outFile, itemLocations[i].x);
		writeSint16BE(outFile, itemLocations[i].y);
	}

	// Write x_pol and y_pol
	writeUint16BE(outFile, ARRAYSIZE(x_pol));
	for (i = 0; i < ARRAYSIZE(x_pol); i++) {
		writeSint16BE(outFile, x_pol[i]);
		writeSint16BE(outFile, y_pol[i]);
	}

	// Write verbBarX
	writeUint16BE(outFile, ARRAYSIZE(verbBarX));
	for (i = 0; i < ARRAYSIZE(verbBarX); i++) {
		writeSint16BE(outFile, verbBarX[i]);
	}

	// Write x1d_menu and y1d_menu
	writeUint16BE(outFile, ARRAYSIZE(x1d_menu));
	for (i = 0; i < ARRAYSIZE(x1d_menu); i++) {
		writeSint16BE(outFile, x1d_menu[i]);
		writeSint16BE(outFile, y1d_menu[i]);
	}

	// Write frameX
	writeUint16BE(outFile, ARRAYSIZE(frameX));
	for (i = 0; i < ARRAYSIZE(frameX); i++) {
		writeSint16BE(outFile, frameX[i]);
	}

	// Write candleX and candleY
	writeUint16BE(outFile, ARRAYSIZE(candleX));
	for (i = 0; i < ARRAYSIZE(candleX); i++) {
		writeSint16BE(outFile, candleX[i]);
		writeSint16BE(outFile, candleY[i]);
	}

	// Write pianistX
	writeUint16BE(outFile, ARRAYSIZE(pianistX));
	for (i = 0; i < ARRAYSIZE(pianistX); i++) {
		writeSint16BE(outFile, pianistX[i]);
	}

	// Write drunkX
	writeUint16BE(outFile, ARRAYSIZE(drunkX));
	for (i = 0; i < ARRAYSIZE(drunkX); i++) {
		writeSint16BE(outFile, drunkX[i]);
	}

	// Write preupdates
	writeUint16BE(outFile, ARRAYSIZE(roomPreUpdates));

	for (i = 0; i < ARRAYSIZE(roomPreUpdates); i++) {
		writeSint16BE(outFile, roomPreUpdates[i].roomNum);
		writeSint16BE(outFile, roomPreUpdates[i].flag);
		writeSint16BE(outFile, roomPreUpdates[i].flagValue);
		writeSint16BE(outFile, roomPreUpdates[i].sourceX);
		writeSint16BE(outFile, roomPreUpdates[i].sourceY);
		writeSint16BE(outFile, roomPreUpdates[i].destX);
		writeSint16BE(outFile, roomPreUpdates[i].destY);
		writeSint16BE(outFile, roomPreUpdates[i].width);
		writeSint16BE(outFile, roomPreUpdates[i].height);
		writeSint16BE(outFile, roomPreUpdates[i].type);
	}

	// Write updates
	writeUint16BE(outFile, ARRAYSIZE(roomUpdates));

	for (i = 0; i < ARRAYSIZE(roomUpdates); i++) {
		writeSint16BE(outFile, roomUpdates[i].roomNum);
		writeSint16BE(outFile, roomUpdates[i].flag);
		writeSint16BE(outFile, roomUpdates[i].flagValue);
		writeSint16BE(outFile, roomUpdates[i].sourceX);
		writeSint16BE(outFile, roomUpdates[i].sourceY);
		writeSint16BE(outFile, roomUpdates[i].destX);
		writeSint16BE(outFile, roomUpdates[i].destY);
		writeSint16BE(outFile, roomUpdates[i].width);
		writeSint16BE(outFile, roomUpdates[i].height);
		writeSint16BE(outFile, roomUpdates[i].type);
	}

	// Write room actions
	writeUint16BE(outFile, ARRAYSIZE(roomActions));

	for (i = 0; i < ARRAYSIZE(roomActions); i++) {
		writeSint16BE(outFile, roomActions[i].room);
		writeSint16BE(outFile, roomActions[i].chapter);
		writeSint16BE(outFile, roomActions[i].action);
		writeSint16BE(outFile, roomActions[i].objectID);
		writeSint16BE(outFile, roomActions[i].speechID);
	}

	// Write talk sequences
	writeUint16BE(outFile, ARRAYSIZE(talkSequences));

	for (i = 0; i < ARRAYSIZE(talkSequences); i++) {
		writeSint16BE(outFile, talkSequences[i].chapter);
		writeSint16BE(outFile, talkSequences[i].sequence);
		writeSint16BE(outFile, talkSequences[i].commandType);
		writeSint16BE(outFile, talkSequences[i].action);
	}

	// langs
	writeUint16BE(outFile, NUM_LANGS);

	// Write _text
	writeUint16BE(outFile, NUM_TEXT);

	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXT; i++) {
			len1 = strlen(_text[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;

			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXT; i++) {
			len = strlen(_text[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_text[lang][i], len, 1, outFile);
			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _textd
	writeUint16BE(outFile, NUM_TEXTD);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTD; i++) {
			len1 = strlen(_textd[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTD; i++) {
			len = strlen(_textd[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_textd[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _textb
	writeUint16BE(outFile, NUM_TEXTB);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTB; i++) {
			len1 = strlen(_textb[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTB; i++) {
			len = strlen(_textb[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_textb[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _textbj
	writeUint16BE(outFile, NUM_TEXTBJ);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTBJ; i++) {
			len1 = strlen(_textbj[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTBJ; i++) {
			len = strlen(_textbj[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_textbj[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _texte
	writeUint16BE(outFile, NUM_TEXTE);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTE; i++) {
			len1 = strlen(_texte[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTE; i++) {
			len = strlen(_texte[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_texte[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _texti
	writeUint16BE(outFile, NUM_TEXTI);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTI; i++) {
			len1 = strlen(_texti[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTI; i++) {
			len = strlen(_texti[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_texti[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _textl
	writeUint16BE(outFile, NUM_TEXTL);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTL; i++) {
			len1 = strlen(_textl[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTL; i++) {
			len = strlen(_textl[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_textl[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _textp
	writeUint16BE(outFile, NUM_TEXTP);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTP; i++) {
			len1 = strlen(_textp[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTP; i++) {
			len = strlen(_textp[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_textp[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _textt
	writeUint16BE(outFile, NUM_TEXTT);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTT; i++) {
			len1 = strlen(_textt[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTT; i++) {
			len = strlen(_textt[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_textt[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _textvb
	writeUint16BE(outFile, NUM_TEXTVB);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTVB; i++) {
			len1 = strlen(_textvb[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTVB; i++) {
			len = strlen(_textvb[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_textvb[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _textsys
	writeUint16BE(outFile, NUM_TEXTSYS);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTSYS; i++) {
			len1 = strlen(_textsys[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTSYS; i++) {
			len = strlen(_textsys[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_textsys[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _texthis
	writeUint16BE(outFile, NUM_TEXTHIS);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTHIS; i++) {
			len1 = strlen(_texthis[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTHIS; i++) {
			len = strlen(_texthis[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_texthis[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _textverbs
	writeUint16BE(outFile, NUM_TEXTVERBS);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTVERBS; i++) {
			len1 = strlen(_textverbs[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTVERBS; i++) {
			len = strlen(_textverbs[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_textverbs[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _textmisc
	writeUint16BE(outFile, NUM_TEXTMISC);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTMISC; i++) {
			len1 = strlen(_textmisc[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTMISC; i++) {
			len = strlen(_textmisc[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_textmisc[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	// Write _textd1
	writeUint16BE(outFile, NUM_TEXTD1);
	for (lang = 0; lang < NUM_LANGS; lang++) {
		len = DATAALIGNMENT - 2;
		for (i = 0; i < NUM_TEXTD1; i++) {
			len1 = strlen(_textd1[lang][i]) + 1;
			pad = DATAALIGNMENT - (len1 + 2) % DATAALIGNMENT;
			len += 2 + len1 + pad;
		}
		writeUint16BE(outFile, len);

		fwrite(padBuf, DATAALIGNMENT - 2, 1, outFile); // padding
		for (i = 0; i < NUM_TEXTD1; i++) {
			len = strlen(_textd1[lang][i]) + 1;
			pad = DATAALIGNMENT - (len + 2) % DATAALIGNMENT;

			writeUint16BE(outFile, len + pad + 2);
			fwrite(_textd1[lang][i], len, 1, outFile);

			fwrite(padBuf, pad, 1, outFile);
		}
	}

	fclose(outFile);

	return 0;
}