-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathwar1tool.cpp
4059 lines (3670 loc) · 110 KB
/
war1tool.cpp
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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Utility for Stratagus - A free fantasy real time strategy game engine
//
/**@name war1tool.c - Extract files from war archives. */
//
// (c) Copyright 2003-2004 by Jimmy Salmon
//
// 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; version 2 dated June, 1991.
//
// 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., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
// $Id$
//@{
/*----------------------------------------------------------------------------
-- Includes
----------------------------------------------------------------------------*/
#define VERSION "3.3.3" // Version of extractor wartool
#define AUTHORS "Lutz Sammer, Nehal Mistry, Jimmy Salmon, Pali Rohar, and Tim Felgentreff."
#define COPYRIGHT "1998-2022 by The Stratagus Project"
#ifndef _MSC_VER
#define __USE_XOPEN_EXTENDED 1 // to get strdup
#endif
#include <assert.h>
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
#include <ctype.h>
#include <png.h>
#include <zlib.h>
#include <iomanip>
#include <string>
#include <regex>
#include <sstream>
#ifdef _MSC_VER
// #define inline __inline
#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
#define strdup _strdup
#define DEBUG _DEBUG
#include <direct.h>
#include <io.h>
#include "dirent_msvc.h"
#else
#include <dirent.h>
#include <unistd.h>
#endif
#include <stratagus-gameutils.h>
#include "endian.h"
#include "xmi2mid.h"
#include "scale2x.h"
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(USE_BEOS)
typedef unsigned long u_int32_t;
#endif
#ifndef __GNUC__
#define __attribute__(args) // Does nothing for non GNU CC
#endif
#ifdef WIN32
#define mkdir(x, y) _mkdir(x)
#define open(x, y, z) _open(x, y, z)
#define read(x, y, z) _read(x, y, z)
#define close(x) _close(x)
#define unlink(x) _unlink(x)
#endif
#ifndef O_BINARY
#define O_BINARY 0
#endif
#define AccessByte(p) (*((unsigned char*)(p)))
//----------------------------------------------------------------------------
// Config
//----------------------------------------------------------------------------
/**
** Destination directory of the graphics
*/
char* Dir;
/**
** Path to the tileset graphics. (default=$DIR/graphics/tilesets)
*/
#define TILESET_PATH "graphics/tilesets"
/**
** Path to the unit graphics. (default=$DIR/graphics)
*/
#define UNIT_PATH "graphics"
/**
** Path to the cm files. (default=$DIR)
*/
#define CM_PATH "."
/**
** Path to the cursor files.
*/
#define CURSOR_PATH "graphics/ui/cursors"
/**
** Path to the graphic files.
*/
#define GRAPHIC_PATH "graphics"
/**
** Path to the sound files.
*/
#define SOUND_PATH "sounds"
/**
** Path to the sound files.
*/
#define MUSIC_PATH "music"
/**
** Path to the text files.
*/
#define TEXT_PATH "campaigns"
/**
** Path to the video files.
*/
#define VIDEO_PATH "videos"
#define DEFAULT_DATA_DIR "data.wc1"
/**
** How much tiles are stored in a row.
*/
#define TILE_PER_ROW 16
//----------------------------------------------------------------------------
/**
** Conversion control sturcture.
*/
typedef struct _control_ {
int Type; /// Entry type
int Version; /// Only in this version
const char* File; /// Save file
int Arg1; /// Extra argument 1
int Arg2; /// Extra argument 2
int Arg3; /// Extra argument 3
int Arg4; /// Extra argument 4
} Control;
/**
** Original archive buffer.
*/
unsigned char* ArchiveBuffer;
/**
** Offsets for each entry into original archive buffer.
*/
unsigned char** ArchiveOffsets;
/**
** Archive length
*/
int ArchiveLength;
/**
** Possible entry types of archive file.
*/
enum _archive_type_ {
F, // File (name)
T, // Tileset (name,idx)
U, // Uncompressed Graphics (name,pal,gfu)
TU, // Tileset unit (for walls and roads)
RP, // Tileset ruin parts (for destroyed buildings)
LM, // Tileset unit "mine entrance" (as a harvesting building for dungeons)
I, // Image (name,pal,img)
W, // Wav (name,wav)
M, // XMI Midi Sound (name,xmi)
X, // Text (name,text,ofs)
X2, // Text2 (name,text)
C, // Cursor (name,cursor)
FLC, // FLC
VOC, // VOC
CM, // Cm
CS, // skirmish maps
};
#define NumUnitDirections 16
typedef struct _unit_directions_ {
const char* name; // just for readability
int directions[NumUnitDirections];
} UnitDirections;
UnitDirections TilesetUnitDirections[] = {
{"forest-wall", {16, 11, 18, 12, 21, 21, 20, 15, 18, 10, 18, 14, 17, 13, 19, 16}},
{"swamp-wall", {16, 11, 18, 12, 21, 21, 20, 15, 18, 10, 18, 14, 17, 13, 19, 16}},
{"dungeon-wall", {66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66}},
{"forest-road", {64, 59, 58, 62, 57, 61, 70, 65, 56, 60, 68, 64, 67, 63, 69, 66}},
{"swamp-road", {65, 60, 59, 63, 58, 62, 71, 66, 57, 61, 69, 65, 68, 64, 70, 67}},
{"dungeon-road", {81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81}}
};
#define MaxRuinDimensions 4
#define _7 ,0,0,0,0,0,0,0
#define _12 ,0,0,0,0,0,0,0,0,0,0,0,0
#define _15 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
typedef struct _ruin_parts_ {
const char* name; // just for readability
int parts[MaxRuinDimensions*MaxRuinDimensions];
} RuinParts;
RuinParts TilesetRuinParts[] = {
{ "forest-ruins4x4",{ 41, 42, 42, 43, 44, 45, 45, 46, 44, 45, 45, 46, 47, 48, 48, 49 } },
{ "swamp-ruins4x4",{ 42, 43, 43, 44, 45, 46, 46, 47, 45, 46, 46, 47, 48, 49, 49, 50 } },
{ "dungeon-ruins4x4",{ 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83, 83 } },
{ "forest-ruins3x3",{ 41, 42, 43, 44, 45, 46, 47, 48, 49 _7 } },
{ "swamp-ruins3x3",{ 42, 43, 44, 45, 46, 47, 48, 49, 50 _7 } },
{ "dungeon-ruins3x3",{ 83, 83, 83, 83, 83, 83, 83, 83, 83 _7 } },
{ "forest-ruins2x2",{ 41, 43, 47, 49 _12 } },
{ "swamp-ruins2x2",{ 42, 44, 48, 50 _12 } },
{ "dungeon-ruins2x2",{ 83, 83, 83, 83 _12 } },
{ "forest-ruins1x1",{ 55 _15 } },
{ "swamp-ruins1x1",{ 54 _15 } },
{ "dungeon-ruins1x1",{ 83 _15 } },
{ "forest-wall-construction",{ 34 _15 } },
{ "swamp-wall-construction",{ 34 _15 } },
{ "dungeon-wall-construction",{ 22 _15 } },
{ "dungeon-entrance-2x3",
{0x49, 0x4a,
0x64, 0x65,
0x75, 0x76} },
{ "pentagram", { 262, 263, 286, 287 _12 }},
{ "north-wall", { 64, 65, 88, 89 _12 }},
{ "north-wall-barrels", { 64, 64, 92, 93 _12 }},
{ "north-wall-wardrobe", { 219, 220, 238, 239 _12 }},
{ "north-wall-cupboard", { 260, 261, 284, 285 _12 }},
};
char* ArchiveDir;
/**
** What, where, how to extract.
*/
Control Todo[] = {
#define __ ,0,0,0
#define _2 ,0,0,
#define _1 ,0
{FLC,0,"cave1.war", 0, 1, 1, 0},
{FLC,0,"cave2.war", 0, 6, 1, 0},
{FLC,0,"cave3.war", 0, 1, 1, 0},
{FLC,0,"hfinale.war", 0, 2, 0, 0},
{FLC,0,"hintro1.war", 0, 1, 1, 0},
{FLC,0,"hintro2.war", 0, 12, 1, 0},
{FLC,0,"hmap01.war", 1 __},
{FLC,0,"hmap02.war", 1 __},
{FLC,0,"hmap03.war", 1 __},
{FLC,0,"hmap04.war", 1 __},
{FLC,0,"hmap05.war", 1 __},
{FLC,0,"hmap06.war", 1 __},
{FLC,0,"hmap07.war", 1 __},
{FLC,0,"hmap08.war", 1 __},
{FLC,0,"hmap09.war", 1 __},
{FLC,0,"hmap10.war", 1 __},
{FLC,0,"hmap11.war", 1 __},
{FLC,0,"hmap12.war", 1 __},
{FLC,0,"lose1.war", 0 __},
{FLC,0,"lose2.war", 0 __},
{FLC,0,"ofinale.war", 0, 2, 0, 0},
{FLC,0,"ointro1.war", 0, 1, 1, 0},
{FLC,0,"ointro2.war", 0, 18, 1, 0},
{FLC,0,"ointro3.war", 0, 1, 1, 0},
{FLC,0,"omap01.war", 1 __},
{FLC,0,"omap02.war", 1 __},
{FLC,0,"omap03.war", 1 __},
{FLC,0,"omap04.war", 1 __},
{FLC,0,"omap05.war", 1 __},
{FLC,0,"omap06.war", 1 __},
{FLC,0,"omap07.war", 1 __},
{FLC,0,"omap08.war", 1 __},
{FLC,0,"omap09.war", 1 __},
{FLC,0,"omap10.war", 1 __},
{FLC,0,"omap11.war", 1 __},
{FLC,0,"omap12.war", 1 __},
{FLC,0,"title.war", 40, 1, 1, 0},
{FLC,0,"win1.war", 0 __},
{FLC,0,"win2.war", 0 __},
///////////////////////////////////////////////////////////////////////////////
// MOST THINGS
///////////////////////////////////////////////////////////////////////////////
#ifdef USE_BEOS
{F,0,"DATA.WAR", 0 __},
#else
{F,0,"data.war", 0 __},
#endif
// Midi music
// TODO: Use better file names
{M,0,"00", 0 __},
{M,0,"01", 1 __},
{M,0,"02", 2 __},
{M,0,"03", 3 __},
{M,0,"04", 4 __},
{M,0,"05", 5 __},
{M,0,"06", 6 __},
{M,0,"07", 7 __},
{M,0,"08", 8 __},
{M,0,"09", 9 __},
{M,0,"10", 10 __},
{M,0,"11", 11 __},
{M,0,"12", 12 __},
{M,0,"13", 13 __},
{M,0,"14", 14 __},
{M,0,"15", 15 __},
{M,0,"16", 16 __},
{M,0,"17", 17 __},
{M,0,"18", 18 __},
{M,0,"19", 19 __},
{M,0,"20", 20 __},
{M,0,"21", 21 __},
{M,0,"22", 22 __},
{M,0,"23", 23 __},
{M,0,"24", 24 __},
{M,0,"25", 25 __},
{M,0,"26", 26 __},
{M,0,"27", 27 __},
{M,0,"28", 28 __},
{M,0,"29", 29 __},
{M,0,"30", 30 __},
{M,0,"31", 31 __},
{M,0,"32", 32 __},
{M,0,"33", 33 __},
{M,0,"34", 34 __},
{M,0,"35", 35 __},
{M,0,"36", 36 __},
{M,0,"37", 37 __},
{M,0,"38", 38 __},
{M,0,"39", 39 __},
{M,0,"40", 40 __},
{M,0,"41", 41 __},
{M,0,"42", 42 __},
{M,0,"43", 43 __},
{M,0,"44", 44 __},
{CM,0,"campaigns/human/01", 117, 63 _2},
{CM,0,"campaigns/human/02", 119, 55 _2},
{CM,0,"campaigns/human/03", 121, 69 _2},
{CM,0,"campaigns/human/04", 123, 97 _2},
{CM,0,"campaigns/human/05", 125, 57 _2},
{CM,0,"campaigns/human/06", 127, 47 _2},
{CM,0,"campaigns/human/07", 129, 67 _2},
{CM,0,"campaigns/human/08", 131, 95 _2},
{CM,0,"campaigns/human/09", 133, 71 _2},
{CM,0,"campaigns/human/10", 135, 73 _2},
{CM,0,"campaigns/human/11", 137, 75 _2},
{CM,0,"campaigns/human/12", 139, 77 _2},
{CM,0,"campaigns/orc/01", 118, 79 _2},
{CM,0,"campaigns/orc/02", 120, 81 _2},
{CM,0,"campaigns/orc/03", 122, 49 _2},
{CM,0,"campaigns/orc/04", 124, 93 _2},
{CM,0,"campaigns/orc/05", 126, 83 _2},
{CM,0,"campaigns/orc/06", 128, 65 _2},
{CM,0,"campaigns/orc/07", 130, 85 _2},
{CM,0,"campaigns/orc/08", 132, 99 _2},
{CM,0,"campaigns/orc/09", 134, 87 _2},
{CM,0,"campaigns/orc/10", 136, 53 _2},
{CM,0,"campaigns/orc/11", 138, 45 _2},
{CM,0,"campaigns/orc/12", 140, 59 _2},
// custom maps
{CS,0,"forest1", 51 __},
{CS,0,"forest2", 61 __},
{CS,0,"swamp1", 89 __},
{CS,0,"swamp2", 91 __},
{CS,0,"dungeons/dungeon1", 101 __},
{CS,0,"dungeons/dungeon2", 103 __},
{CS,0,"dungeons/dungeon3", 105 __},
{CS,0,"dungeons/dungeon4", 107 __},
//{CS,0,"dungeons/dungeon5", 109 __}, this 4x maps are exactly the same as dungeon4, they clutter maplist providing no benefit
//{CS,0,"dungeons/dungeon6", 111 __},
//{CS,0,"dungeons/dungeon7", 113 __},
//{CS,0,"dungeons/dungeon8", 115 __},
// Tilesets
{T,0,"forest/terrain", 190 __},
{T,0,"swamp/terrain", 193 __},
{T,0,"dungeon/terrain", 196 __},
// Some animations
{U,0,"425", 424, 425 _2},
{U,0,"426", 424, 426 _2},
{U,0,"427", 424, 427 _2},
{U,0,"428", 423, 428 _2},
{U,0,"429", 423, 429 _2},
{U,0,"430", 423, 430 _2},
{U,0,"431", 423, 431 _2},
{U,0,"460", 459, 460 _2},
// Text
{X,0,"orc/01_intro", 432 __},
{X,0,"orc/02_intro", 433 __},
{X,0,"orc/03_intro", 434 __},
{X,0,"orc/04_intro", 435 __},
{X,0,"orc/05_intro", 436 __},
{X,0,"orc/06_intro", 437 __},
{X,0,"orc/07_intro", 438 __},
{X,0,"orc/08_intro", 439 __},
{X,0,"orc/09_intro", 440 __},
{X,0,"orc/10_intro", 441 __},
{X,0,"orc/11_intro", 442 __},
{X,0,"orc/12_intro", 443 __},
{X,0,"human/01_intro", 444 __},
{X,0,"human/02_intro", 445 __},
{X,0,"human/03_intro", 446 __},
{X,0,"human/04_intro", 447 __},
{X,0,"human/05_intro", 448 __},
{X,0,"human/06_intro", 449 __},
{X,0,"human/07_intro", 450 __},
{X,0,"human/08_intro", 451 __},
{X,0,"human/09_intro", 452 __},
{X,0,"human/10_intro", 453 __},
{X,0,"human/11_intro", 454 __},
{X,0,"human/12_intro", 455 __},
{X,0,"human/ending_1", 461 __},
{X,0,"orc/ending_1", 462 __},
{X,0,"human/ending_2", 463 __},
{X,0,"orc/ending_2", 464 __},
{X,0,"credits", 465 __},
{X,0,"victory_dialog_1", 466 __},
{X,0,"victory_dialog_2", 467 __},
{X,0,"defeat_dialog_1", 468 __},
{X,0,"defeat_dialog_2", 469 __},
// Cursors
{C,0,"arrow", 262, 263 _2},
{C,0,"invalid_command", 262, 264 _2},
{C,0,"yellow_crosshair", 262, 265 _2},
{C,0,"red_crosshair", 262, 266 _2},
{C,0,"yellow_crosshair_2", 262, 267 _2},
{C,0,"magnifying_glass", 262, 268 _2},
{C,0,"small_green_crosshair", 262, 269 _2},
{C,0,"watch", 262, 270 _2},
{C,0,"up_arrow", 262, 271 _2},
{C,0,"upper_right_arrow", 262, 272 _2},
{C,0,"right_arrow", 262, 273 _2},
{C,0,"lower_right_arrow", 262, 274 _2},
{C,0,"down_arrow", 262, 275 _2},
{C,0,"lower_left_arrow", 262, 276 _2},
{C,0,"left_arrow", 262, 277 _2},
{C,0,"upper_left_arrow", 262, 278 _2},
// Unit graphics
{U,0,"human/units/footman", 191, 279 _2},
{U,0,"orc/units/grunt", 191, 280 _2},
{U,0,"human/units/peasant", 191, 281 _2},
{U,0,"orc/units/peon", 191, 282 _2},
{U,0,"human/units/catapult", 191, 283 _2},
{U,0,"orc/units/catapult", 191, 284 _2},
{U,0,"human/units/knight", 191, 285 _2},
{U,0,"orc/units/raider", 191, 286 _2},
{U,0,"human/units/archer", 191, 287 _2},
{U,0,"orc/units/spearman", 191, 288 _2},
{U,0,"human/units/conjurer", 191, 289 _2},
{U,0,"orc/units/warlock", 191, 290 _2},
{U,0,"human/units/cleric", 191, 291 _2},
{U,0,"orc/units/necrolyte", 191, 292 _2},
{U,0,"human/units/medivh", 191, 293 _2},
{U,0,"human/units/lothar", 191, 294 _2},
{U,0,"neutral/units/wounded", 191, 295 _2},
{U,0,"neutral/units/grizelda,garona", 191, 296 _2},
{U,0,"neutral/units/ogre", 191, 297 _2},
{U,0,"neutral/units/spider", 191, 298 _2},
{U,0,"neutral/units/slime", 191, 299 _2},
{U,0,"neutral/units/fire_elemental", 191, 300 _2},
{U,0,"neutral/units/scorpion", 191, 301 _2},
{U,0,"neutral/units/brigand", 191, 302 _2},
{U,0,"neutral/units/colored-brigand", 191, 302 _2},
{U,0,"neutral/units/the_dead", 191, 303 _2},
{U,0,"neutral/units/skeleton", 191, 304 _2},
{U,0,"neutral/units/daemon", 191, 305 _2},
{U,0,"neutral/units/water_elemental", 191, 306 _2},
// here come buildings
{U,0,"neutral/units/dead_bodies", 191, 326 _2},
{U,0,"human/units/peasant_with_wood", 191, 327 _2},
{U,0,"orc/units/peon_with_wood", 191, 328 _2},
{U,0,"human/units/peasant_with_gold", 191, 329 _2},
{U,0,"orc/units/peon_with_gold", 191, 330 _2},
// Buildings
{U,0,"tilesets/forest/human/buildings/farm", 191, 307 _2},
{U,0,"tilesets/forest/orc/buildings/farm", 191, 308 _2},
{U,0,"tilesets/forest/human/buildings/barracks", 191, 309 _2},
{U,0,"tilesets/forest/orc/buildings/barracks", 191, 310 _2},
{U,0,"tilesets/forest/human/buildings/church", 191, 311 _2},
{U,0,"tilesets/forest/orc/buildings/temple", 191, 312 _2},
{U,0,"tilesets/forest/human/buildings/tower", 191, 313 _2},
{U,0,"tilesets/forest/orc/buildings/tower", 191, 314 _2},
{U,0,"tilesets/forest/human/buildings/town_hall", 191, 315 _2},
{U,0,"tilesets/forest/orc/buildings/town_hall", 191, 316 _2},
{U,0,"tilesets/forest/human/buildings/lumber_mill", 191, 317 _2},
{U,0,"tilesets/forest/orc/buildings/lumber_mill", 191, 318 _2},
{U,0,"tilesets/forest/human/buildings/stable", 191, 319 _2},
{U,0,"tilesets/forest/orc/buildings/kennel", 191, 320 _2},
{U,0,"tilesets/forest/human/buildings/blacksmith", 191, 321 _2},
{U,0,"tilesets/forest/orc/buildings/blacksmith", 191, 322 _2},
{U,0,"tilesets/forest/human/buildings/stormwind_keep", 191, 323 _2},
{U,0,"tilesets/forest/orc/buildings/blackrock_spire", 191, 324 _2},
{U,0,"tilesets/forest/neutral/buildings/gold_mine", 191, 325 _2},
// here come dead bodies, and workers with resources
{U,0,"tilesets/forest/human/buildings/farm_construction", 191, 331 _2},
{U,0,"tilesets/forest/orc/buildings/farm_construction", 191, 332 _2},
{U,0,"tilesets/forest/human/buildings/barracks_construction", 191, 333 _2},
{U,0,"tilesets/forest/orc/buildings/barracks_construction", 191, 334 _2},
{U,0,"tilesets/forest/human/buildings/church_construction", 191, 335 _2},
{U,0,"tilesets/forest/orc/buildings/temple_construction", 191, 336 _2},
{U,0,"tilesets/forest/human/buildings/tower_construction", 191, 337 _2},
{U,0,"tilesets/forest/orc/buildings/tower_construction", 191, 338 _2},
{U,0,"tilesets/forest/human/buildings/town_hall_construction", 191, 339 _2},
{U,0,"tilesets/forest/orc/buildings/town_hall_construction", 191, 340 _2},
{U,0,"tilesets/forest/human/buildings/lumber_mill_construction", 191, 341 _2},
{U,0,"tilesets/forest/orc/buildings/lumber_mill_construction", 191, 342 _2},
{U,0,"tilesets/forest/human/buildings/stable_construction", 191, 343 _2},
{U,0,"tilesets/forest/orc/buildings/kennel_construction", 191, 344 _2},
{U,0,"tilesets/forest/human/buildings/blacksmith_construction", 191, 345 _2},
{U,0,"tilesets/forest/orc/buildings/blacksmith_construction", 191, 346 _2},
{U,0,"tilesets/swamp/human/buildings/farm", 194, 307 _2},
{U,0,"tilesets/swamp/orc/buildings/farm", 194, 308 _2},
{U,0,"tilesets/swamp/human/buildings/barracks", 194, 309 _2},
{U,0,"tilesets/swamp/orc/buildings/barracks", 194, 310 _2},
{U,0,"tilesets/swamp/human/buildings/church", 194, 311 _2},
{U,0,"tilesets/swamp/orc/buildings/temple", 194, 312 _2},
{U,0,"tilesets/swamp/human/buildings/tower", 194, 313 _2},
{U,0,"tilesets/swamp/orc/buildings/tower", 194, 314 _2},
{U,0,"tilesets/swamp/human/buildings/town_hall", 194, 315 _2},
{U,0,"tilesets/swamp/orc/buildings/town_hall", 194, 316 _2},
{U,0,"tilesets/swamp/human/buildings/lumber_mill", 194, 317 _2},
{U,0,"tilesets/swamp/orc/buildings/lumber_mill", 194, 318 _2},
{U,0,"tilesets/swamp/human/buildings/stable", 194, 319 _2},
{U,0,"tilesets/swamp/orc/buildings/kennel", 194, 320 _2},
{U,0,"tilesets/swamp/human/buildings/blacksmith", 194, 321 _2},
{U,0,"tilesets/swamp/orc/buildings/blacksmith", 194, 322 _2},
{U,0,"tilesets/swamp/human/buildings/stormwind_keep", 194, 323 _2},
{U,0,"tilesets/swamp/orc/buildings/blackrock_spire", 194, 324 _2},
{U,0,"tilesets/swamp/neutral/buildings/gold_mine", 194, 325 _2},
{U,0,"tilesets/swamp/human/buildings/farm_construction", 194, 331 _2},
{U,0,"tilesets/swamp/orc/buildings/farm_construction", 194, 332 _2},
{U,0,"tilesets/swamp/human/buildings/barracks_construction", 194, 333 _2},
{U,0,"tilesets/swamp/orc/buildings/barracks_construction", 194, 334 _2},
{U,0,"tilesets/swamp/human/buildings/church_construction", 194, 335 _2},
{U,0,"tilesets/swamp/orc/buildings/temple_construction", 194, 336 _2},
{U,0,"tilesets/swamp/human/buildings/tower_construction", 194, 337 _2},
{U,0,"tilesets/swamp/orc/buildings/tower_construction", 194, 338 _2},
{U,0,"tilesets/swamp/human/buildings/town_hall_construction", 194, 339 _2},
{U,0,"tilesets/swamp/orc/buildings/town_hall_construction", 194, 340 _2},
{U,0,"tilesets/swamp/human/buildings/lumber_mill_construction", 194, 341 _2},
{U,0,"tilesets/swamp/orc/buildings/lumber_mill_construction", 194, 342 _2},
{U,0,"tilesets/swamp/human/buildings/stable_construction", 194, 343 _2},
{U,0,"tilesets/swamp/orc/buildings/kennel_construction", 194, 344 _2},
{U,0,"tilesets/swamp/human/buildings/blacksmith_construction", 194, 345 _2},
{U,0,"tilesets/swamp/orc/buildings/blacksmith_construction", 194, 346 _2},
{TU,0,"forest/neutral/buildings/wall",190,0 _2},
{TU,0,"swamp/neutral/buildings/wall",193,1 _2},
{TU,0,"dungeon/neutral/buildings/wall",196,2 _2},
{TU,0,"forest/neutral/buildings/road",190,3 _2},
{TU,0,"swamp/neutral/buildings/road",193,4 _2},
{TU,0,"dungeon/neutral/buildings/road",196,5 _2},
{RP,0,"forest/neutral/buildings/ruins",190,0,4 _1},
{RP,0,"swamp/neutral/buildings/ruins",193,1,4 _1},
{RP,0,"dungeon/neutral/buildings/ruins",196,2,4 _1},
{RP,0,"forest/neutral/buildings/ruins",190,3,3 _1 },
{RP,0,"swamp/neutral/buildings/ruins",193,4,3 _1 },
{RP,0,"dungeon/neutral/buildings/ruins",196,5,3 _1 },
{RP,0,"forest/neutral/buildings/ruins",190,6,2 _1 },
{RP,0,"swamp/neutral/buildings/ruins",193,7,2 _1 },
{RP,0,"dungeon/neutral/buildings/ruins",196,8,2 _1 },
{RP,0,"forest/neutral/buildings/ruins",190,9,1 _1 },
{RP,0,"swamp/neutral/buildings/ruins",193,10,1 _1 },
{RP,0,"dungeon/neutral/buildings/ruins",196,11,1 _1 },
{RP,0,"forest/neutral/buildings/wall",190,12,1 _1 },
{RP,0,"swamp/neutral/buildings/wall",193,13,1 _1 },
{RP,0,"dungeon/neutral/buildings/wall",196,14,1 _1 },
{LM,0,"dungeon/neutral/buildings/entrance",196,15,4 _1 },
{LM,0,"dungeon/neutral/buildings/pentagram",196,16,2 _1 },
{LM,0,"dungeon/neutral/buildings/north-wall",196,17,2 _1 },
{LM,0,"dungeon/neutral/buildings/north-wall-barrels",196,18,2 _1 },
{LM,0,"dungeon/neutral/buildings/north-wall-wardrobe",196,19,2 _1 },
{LM,0,"dungeon/neutral/buildings/north-wall-cupboard",196,20,2 _1 },
// Missiles
{U,0,"missiles/fireball", 217, 347 _2},
{U,0,"missiles/catapult_projectile", 191, 348 _2},
{U,0,"missiles/arrow", 217, 349 _2},
{U,0,"missiles/poison_cloud", 191, 350 _2},
{U,0,"missiles/rain_of_fire", 191, 351 _2},
{U,0,"missiles/small_fire", 191, 352 _2},
{U,0,"missiles/large_fire", 191, 353 _2},
{U,0,"missiles/explosion", 191, 354 _2},
{U,0,"missiles/healing", 217, 355 _2},
{U,0,"missiles/building_collapse", 191, 356 _2},
{U,0,"missiles/water_elemental_projectile", 217, 357 _2},
{U,0,"missiles/fireball_2", 191, 358 _2},
// Icons
{U,0,"tilesets/forest/portrait_icons", 191, 361 _2},
{U,0,"tilesets/swamp/portrait_icons", 194, 361 _2},
{U,0,"tilesets/dungeon/portrait_icons", 197, 361 _2},
// UI
{U,0,"ui/orc/icon_selection_boxes", 191, 359 _2},
{U,0,"ui/human/icon_selection_boxes", 191, 360 _2},
{I,0,"ui/logo", 217, 216 _2},
{I,0,"ui/human/top_resource_bar", 255, 218 _2},
{I,0,"ui/orc/top_resource_bar", 191, 219 _2},
{I,0,"ui/human/right_panel", 255, 220 _2},
{I,0,"ui/orc/right_panel", 217, 221 _2},
{I,0,"ui/human/bottom_panel", 255, 222 _2},
{I,0,"ui/orc/bottom_panel", 217, 223 _2},
{I,0,"ui/human/minimap_2", 255, 224 _2},
{I,0,"ui/orc/minimap_2", 217, 225 _2},
{I,0,"ui/human/left_panel", 255, 226 _2},
{I,0,"ui/orc/left_panel", 217, 227 _2},
{I,0,"ui/human/minimap", 255, 228 _2},
{I,0,"ui/orc/minimap", 217, 229 _2},
{I,0,"ui/human/panel_1", 255, 233 _2},
{I,0,"ui/orc/panel_1", 217, 234 _2},
{I,0,"ui/human/panel_2", 255, 235 _2},
{I,0,"ui/orc/panel_2", 217, 236 _2},
{I,0,"ui/bottom_of_title_screen", 260, 243 _2},
{I,0,"ui/human/left_arrow", 255, 244 _2},
{I,0,"ui/orc/left_arrow", 255, 245 _2},
{I,0,"ui/human/right_arrow", 255, 246 _2},
{I,0,"ui/orc/right_arrow", 255, 247 _2},
{I,0,"ui/box", 255, 248 _2},
{I,0,"ui/human/save_game", 255, 249 _2},
{I,0,"ui/orc/save_game", 217, 250 _2},
{I,0,"ui/hot_keys", 255, 254 _2},
{I,0,"ui/human/ok_box", 255, 256 _2},
{I,0,"ui/orc/ok_box", 255, 257 _2},
{I,0,"ui/top_of_title_screen", 260, 258 _2},
{I,0,"ui/title_screen", 260, 261 _2},
{I,0,"ui/menu_button_1", 217, 362 _2},
{I,0,"ui/menu_button_2", 217, 363 _2},
{I,0,"ui/human/icon_border", 255, 364 _2},
{I,0,"ui/orc/icon_border", 217, 365 _2},
{I,0,"ui/gold_icon_1", 191, 406 _2},
{I,0,"ui/lumber_icon_1", 217, 407 _2},
{I,0,"ui/gold_icon_2", 191, 408 _2},
{I,0,"ui/lumber_icon_2", 217, 409 _2},
{I,0,"ui/percent_complete", 217, 410 _2},
{I,0,"ui/human/outcome_windows", 413, 411 _2},
{I,0,"ui/orc/outcome_windows", 414, 412 _2},
{I,0,"ui/victory_scene", 416, 415 _2},
{I,0,"ui/defeat_scene", 418, 417 _2},
{I,0,"ui/victory_text", 418, 419 _2},
{I,0,"ui/defeat_text", 418, 420 _2},
{I,0,"ui/human/briefing", 423, 421 _2},
{I,0,"ui/orc/briefing", 424, 422 _2},
{I,0,"ui/human/victory_1", 457, 456 _2},
{I,0,"ui/orc/victory_1", 459, 458 _2},
{I,0,"ui/human/victory_2", 457, 470 _2},
{I,0,"ui/orc/victory_2", 260, 471 _2},
// Sounds
{W,0,"logo", 472 __},
{W,0,"intro_door", 473, 1, 0, 0},
{VOC,0,"misc/building", 474 __},
{VOC,0,"misc/explosion", 475 __},
{VOC,0,"missiles/catapult_rock_fired", 476 __},
{VOC,0,"misc/tree_chopping_1", 477 __},
{VOC,0,"misc/tree_chopping_2", 478 __},
{VOC,0,"misc/tree_chopping_3", 479 __},
{VOC,0,"misc/tree_chopping_4", 480 __},
{VOC,0,"misc/building_collapse_1", 481 __},
{VOC,0,"misc/building_collapse_2", 482 __},
{VOC,0,"misc/building_collapse_3", 483 __},
{VOC,0,"ui/chime", 484 __},
{W,0,"ui/click", 485 __},
{VOC,0,"ui/cancel", 486 __},
{VOC,0,"missiles/sword_attack_1", 487 __},
{VOC,0,"missiles/sword_attack_2", 488 __},
{VOC,0,"missiles/sword_attack_3", 489 __},
{VOC,0,"missiles/fist_attack", 490 __},
{VOC,0,"missiles/catapult_fire_explosion", 491 __},
{VOC,0,"missiles/fireball", 492 __},
{VOC,0,"missiles/arrow,spear", 493 __},
{VOC,0,"missiles/arrow,spear_hit", 494 __},
{VOC,0,"orc/help_1", 495 __},
{VOC,0,"orc/help_2", 496 __},
{W,0,"human/help_2", 497 __},
{W,0,"human/help_1", 498 __},
{VOC,0,"orc/dead", 499 __},
{VOC,0,"human/dead", 500 __},
{VOC,0,"orc/work_complete", 501 __},
{W,0,"human/work_complete", 502 __},
{VOC,0,"orc/help_3", 503 __},
{W,0,"orc/help_4", 504 __},
{W,0,"human/help_3", 505 __},
{W,0,"human/help_4", 506 __},
{VOC,0,"orc/ready", 507 __},
{W,0,"human/ready", 508 __},
{VOC,0,"orc/acknowledgement_1", 509 __},
{VOC,0,"orc/acknowledgement_2", 510 __},
{VOC,0,"orc/acknowledgement_3", 511 __},
{VOC,0,"orc/acknowledgement_4", 512 __},
{W,0,"human/acknowledgement_1", 513 __},
{W,0,"human/acknowledgement_2", 514 __},
{VOC,0,"orc/selected_1", 515 __},
{VOC,0,"orc/selected_2", 516 __},
{VOC,0,"orc/selected_3", 517 __},
{VOC,0,"orc/selected_4", 518 __},
{VOC,0,"orc/selected_5", 519 __},
{W,0,"human/selected_1", 520 __},
{W,0,"human/selected_2", 521 __},
{W,0,"human/selected_3", 522 __},
{W,0,"human/selected_4", 523 __},
{W,0,"human/selected_5", 524 __},
{VOC,0,"orc/annoyed_1", 525 __},
{VOC,0,"orc/annoyed_2", 526 __},
{W,0,"orc/annoyed_3", 527 __},
{W,0,"human/annoyed_1", 528 __},
{W,0,"human/annoyed_2", 529 __},
{W,0,"human/annoyed_3", 530 __},
{W,0,"dead_spider,scorpion", 531 __},
{W,0,"normal_spell", 532 __},
{W,0,"misc/build_road", 533 __},
{W,0,"orc/temple", 534 __},
{W,0,"human/church", 535 __},
{W,0,"orc/kennel", 536 __},
{W,0,"human/stable", 537 __},
{W,0,"blacksmith", 538 __},
{W,0,"misc/fire_crackling", 539 __},
{W,0,"cannon", 540 __},
{W,0,"cannon2", 541 __},
{W,0,"../campaigns/human/ending_1", 542 __},
{W,0,"../campaigns/human/ending_2", 543 __},
{W,0,"../campaigns/orc/ending_1", 544 __},
{W,0,"../campaigns/orc/ending_2", 545 __},
{W,0,"intro_1", 546, 1, 0, 0},
{W,0,"intro_2", 547, 1, 0, 0},
{W,0,"intro_3", 548, 1, 0, 0},
{W,0,"intro_4", 549, 1, 0, 0},
{W,0,"intro_5", 550, 1, 0, 0},
{W,0,"../campaigns/human/01_intro", 551 __},
{W,0,"../campaigns/human/02_intro", 552 __},
{W,0,"../campaigns/human/03_intro", 553 __},
{W,0,"../campaigns/human/04_intro", 554 __},
{W,0,"../campaigns/human/05_intro", 555 __},
{W,0,"../campaigns/human/06_intro", 556 __},
{W,0,"../campaigns/human/07_intro", 557 __},
{W,0,"../campaigns/human/08_intro", 558 __},
{W,0,"../campaigns/human/09_intro", 559 __},
{W,0,"../campaigns/human/10_intro", 560 __},
{W,0,"../campaigns/human/11_intro", 561 __},
{W,0,"../campaigns/human/12_intro", 562 __},
{W,0,"../campaigns/orc/01_intro", 563 __},
{W,0,"../campaigns/orc/02_intro", 564 __},
{W,0,"../campaigns/orc/03_intro", 565 __},
{W,0,"../campaigns/orc/04_intro", 566 __},
{W,0,"../campaigns/orc/05_intro", 567 __},
{W,0,"../campaigns/orc/06_intro", 568 __},
{W,0,"../campaigns/orc/07_intro", 569 __},
{W,0,"../campaigns/orc/08_intro", 570 __},
{W,0,"../campaigns/orc/09_intro", 571 __},
{W,0,"../campaigns/orc/10_intro", 572 __},
{W,0,"../campaigns/orc/11_intro", 573 __},
{W,0,"../campaigns/orc/12_intro", 574 __},
{W,0,"human/defeat", 575 __},
{W,0,"orc/defeat", 576 __},
{W,0,"orc/victory_1", 577 __},
{W,0,"orc/victory_2", 578 __},
{W,0,"orc/victory_3", 579 __},
{W,0,"human/victory_1", 580 __},
{W,0,"human/victory_2", 581 __},
{W,0,"human/victory_3", 582 __},
#undef __
#undef _2
};
// This which can be allowed/disallowed in maps.
// A bitmask of 1 << these things can be found in MapFlags.
struct _allowed_features_ {
const char* thing[2];
};
struct _allowed_features_ AllowedFeatures[] = {
// Units. 0 - 6
{"unit-footman", "unit-grunt"},
{"unit-peasant", "unit-peon"},
{"unit-human-catapult", "unit-orc-catapult"},
{"unit-knight", "unit-raider"},
{"unit-archer", "unit-spearman"},
{"unit-conjurer", "unit-warlock"},
{"unit-cleric", "unit-necrolyte"},
// Constructing buildings. 7 - 14
{"unit-human-farm", "unit-orc-farm"},
{"unit-human-barracks", "unit-orc-barracks"},
{"unit-human-church", "unit-orc-temple"},
{"unit-human-tower", "unit-orc-tower"},
{"unit-human-town-hall", "unit-orc-town-hall"},
{"unit-human-lumber-mill", "unit-orc-lumber-mill"},
{"unit-human-stable", "unit-orc-kennel"},
{"unit-human-blacksmith", "unit-orc-blacksmith"},
// Cleric/Necrolyte spells. 15 - 17
{"upgrade-healing", "upgrade-raise-dead"},
{"upgrade-holy-vision", "upgrade-dark-vision"},
{"upgrade-invisibility", "upgrade-unholy-armor"},
// Conjurer/Warlock spells. 18 - 20
{"upgrade-scorpion", "upgrade-spider"},
{"upgrade-rain-of-fire", "upgrade-poison-cloud"},
{"upgrade-water-elemental", "upgrade-daemon"},
// Roads and walls. 21 - 22
{"unit-road", "unit-road"},
{"unit-wall", "unit-wall"}
};
int MaxAllowedFeature = 22;
#define SkipFeature(f) (f >= 15 && f <= 21)
#define IsAllowedFeature(id, feature) ((id & (1 << (int)feature)) != 0)
//----------------------------------------------------------------------------
// TOOLS
//----------------------------------------------------------------------------
/**
** Check if path exists, if not make all directories.
*/
void CheckPath(const char* path)
{
char* cp;
char* s;
if (*path && path[0] == '.') { // relative don't work
return;
}
cp = strdup(path);
s = strrchr(cp, '/');
if (s) {
*s = '\0'; // remove file
s = cp;
for (;;) { // make each path element
s = strchr(s, '/');
if (s) {
*s = '\0';
}
mkdir(cp, 0777);
if (s) {
*s++ = '/';
} else {
break;
}
}
} else {
mkdir(cp, 0777);
}
free(cp);
}
//----------------------------------------------------------------------------
// PNG
//----------------------------------------------------------------------------
/**
** Resize an image
**
** @param image image data to be converted
** @param ow old image width
** @param oh old image height
** @param nw new image width
** @param nh new image height
*/
void ResizeImage(unsigned char** image, int ow, int oh, int nw, int nh)
{
if (ow == nw && nh == oh) {
return;
}
if (!(ow * 2 == nw && oh * 2 == nh)) {
fprintf(stderr, "Can only scale by factors of two!");
exit(-1);
}
unsigned char* data;
data = (unsigned char*)malloc(nw * nh);
//int i;
//int j;
//int x;
//x = 0;
//for (i = 0; i < nh; ++i) {
// for (j = 0; j < nw; ++j) {
// data[x] = ((unsigned char*)*image)[
// i * oh / nh * ow + j * ow / nw];
// ++x;
// }
//}
scale2x(data, *image, ow, oh);
free(*image);
*image = data;
}
/**
** Save a png file.
**
** @param name File name
** @param image Graphic data
** @param w Graphic width
** @param h Graphic height
** @param pal Palette
** @param transparent Image uses transparency
*/
int SavePNG(const char* name, unsigned char* image, int w, int h,
unsigned char* pal, int transparent)
{
FILE* fp;
png_structp png_ptr;
png_infop info_ptr;
unsigned char** lines;
int i;
const int bit_depth = 8;
const int interlace_type = 0;
const int num_palette = 256;
if (!(fp = fopen(name, "wb"))) {
fprintf(stderr,"%s:", name);
perror("Can't open file");
return 1;
}
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
fclose(fp);
return 1;
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_write_struct(&png_ptr, NULL);
fclose(fp);
return 1;
}
if (setjmp(png_jmpbuf(png_ptr))) {
// FIXME: must free buffers!!
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
return 1;
}
png_init_io(png_ptr, fp);
// zlib parameters
png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
// prepare the file information
#if PNG_LIBPNG_VER >= 10504
png_set_IHDR(png_ptr, info_ptr, w, h, bit_depth, PNG_COLOR_TYPE_PALETTE, interlace_type,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_set_PLTE(png_ptr, info_ptr, (png_colorp)pal, num_palette);
#else
info_ptr->width = w;
info_ptr->height = h;
info_ptr->bit_depth = bit_depth;
info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
info_ptr->interlace_type = interlace_type;
info_ptr->valid |= PNG_INFO_PLTE;