41
41
#include "mygetopt.h"
42
42
43
43
unsigned int option_version ;
44
+ unsigned int game_version ;
45
+
46
+ static const id_format_pair_t formats_v0_th06 [] = {
47
+ { 0 , "fff" },
48
+ { 1 , "Cff" },
49
+ { 2 , "fff" },
50
+ { 3 , "SSS" },
51
+ { 4 , "SSS" },
52
+ { 5 , "SSS" },
53
+ { 0 , NULL }
54
+ };
44
55
45
56
/* Some of the S's here are actually colors. */
46
57
static const id_format_pair_t formats_v0 [] = {
@@ -128,6 +139,24 @@ static const id_format_pair_t formats_v2[] = {
128
139
{ 0 , NULL }
129
140
};
130
141
142
+ static const id_format_pair_t *
143
+ get_format_table (
144
+ unsigned int version
145
+ ) {
146
+ switch (version ) {
147
+ case 0 :
148
+ if (game_version == 6 )
149
+ return formats_v0_th06 ;
150
+ return formats_v0 ;
151
+ case 1 :
152
+ return formats_v1 ;
153
+ case 2 :
154
+ return formats_v2 ;
155
+ default :
156
+ return NULL ;
157
+ }
158
+ }
159
+
131
160
static thstd_t *
132
161
std_read_file (
133
162
FILE * in )
@@ -237,9 +266,7 @@ std_dump(
237
266
std_object_instance_t * instance ;
238
267
std_instr_t * instr ;
239
268
240
- const id_format_pair_t * formats =
241
- option_version == 0 ? formats_v0 :
242
- option_version == 1 ? formats_v1 : formats_v2 ;
269
+ const id_format_pair_t * formats = get_format_table (option_version );
243
270
244
271
uint16_t object_id ;
245
272
uint32_t time ;
@@ -403,9 +430,7 @@ std_create(
403
430
404
431
uint32_t instr_time = 0 ;
405
432
406
- const id_format_pair_t * formats =
407
- option_version == 0 ? formats_v0 :
408
- option_version == 1 ? formats_v1 : formats_v2 ;
433
+ const id_format_pair_t * formats = get_format_table (option_version );
409
434
410
435
f = fopen (spec , "r" );
411
436
if (!f ) {
@@ -840,7 +865,6 @@ main(
840
865
argv0 = util_shortname (argv [0 ]);
841
866
int opt ;
842
867
int ind = 0 ;
843
- unsigned int version = 0 ;
844
868
while (argv [util_optind ]) {
845
869
switch (opt = util_getopt (argc ,argv ,commands )) {
846
870
case 'c' :
@@ -851,7 +875,7 @@ main(
851
875
exit (1 );
852
876
}
853
877
command = opt ;
854
- version = parse_version (util_optarg );
878
+ game_version = parse_version (util_optarg );
855
879
break ;
856
880
default :
857
881
util_getopt_default (& ind ,argv ,opt ,print_usage );
@@ -860,7 +884,7 @@ main(
860
884
argc = ind ;
861
885
argv [argc ] = NULL ;
862
886
863
- switch (version ) {
887
+ switch (game_version ) {
864
888
case 6 :
865
889
case 7 :
866
890
case 8 :
@@ -888,10 +912,10 @@ main(
888
912
break ;
889
913
default :
890
914
if (command == 'c' || command == 'd' ) {
891
- if (version == 0 )
915
+ if (game_version == 0 )
892
916
fprintf (stderr , "%s: version must be specified\n" , argv0 );
893
917
else
894
- fprintf (stderr , "%s: version %u is unsupported\n" , argv0 , version );
918
+ fprintf (stderr , "%s: version %u is unsupported\n" , argv0 , game_version );
895
919
exit (1 );
896
920
}
897
921
}
0 commit comments