3 # =============================================================================
4 # Rocks'n'Diamonds - McDuffin Strikes Back!
5 # -----------------------------------------------------------------------------
6 # (c) 1995-2014 by Artsoft Entertainment
9 # https://www.artsoft.org/
10 # -----------------------------------------------------------------------------
11 # create_element_defs.pl
12 # =============================================================================
17 # =============================================================================
18 # C O N F I G U R A T I O N S E C T I O N
19 # =============================================================================
22 my $src_path = "$base_path/src";
24 if (-d "../src") # we're already inside "src" directory
30 # -----------------------------------------------------------------------------
32 # -----------------------------------------------------------------------------
34 my $filename_header_tmpl = "$src_path/header.tmpl";
36 my $filename_conf_gfx_h = 'conf_gfx.h';
37 my $filename_conf_snd_h = 'conf_snd.h';
38 my $filename_conf_mus_h = 'conf_mus.h';
39 my $filename_conf_chr_c = 'conf_chr.c';
40 my $filename_conf_chr_h = 'conf_chr.h';
41 my $filename_conf_cus_c = 'conf_cus.c';
42 my $filename_conf_cus_h = 'conf_cus.h';
43 my $filename_conf_grp_c = 'conf_grp.c';
44 my $filename_conf_grp_h = 'conf_grp.h';
45 my $filename_conf_emp_c = 'conf_emp.c';
46 my $filename_conf_emp_h = 'conf_emp.h';
47 my $filename_conf_e2g_c = 'conf_e2g.c';
48 my $filename_conf_esg_c = 'conf_esg.c';
49 my $filename_conf_e2s_c = 'conf_e2s.c';
50 my $filename_conf_fnt_c = 'conf_fnt.c';
51 my $filename_conf_g2s_c = 'conf_g2s.c';
52 my $filename_conf_g2m_c = 'conf_g2m.c';
53 my $filename_conf_var_c = 'conf_var.c';
54 my $filename_conf_act_c = 'conf_act.c';
56 my $text_auto = 'this file was automatically generated -- do not edit by hand';
57 my $text_gfx_h = 'values for graphics configuration (normal elements)';
58 my $text_snd_h = 'values for sounds configuration';
59 my $text_mus_h = 'values for music configuration';
60 my $text_chr_c = 'values for graphics configuration (character elements)';
61 my $text_chr_h = 'values for elements configuration (character elements)';
62 my $text_cus_c = 'values for graphics configuration (custom elements)';
63 my $text_cus_h = 'values for elements configuration (custom elements)';
64 my $text_grp_c = 'values for graphics configuration (group elements)';
65 my $text_grp_h = 'values for elements configuration (group elements)';
66 my $text_emp_c = 'values for graphics configuration (empty elements)';
67 my $text_emp_h = 'values for elements configuration (empty elements)';
68 my $text_e2g_c = 'values for element/graphics mapping configuration (normal)';
69 my $text_esg_c = 'values for element/graphics mapping configuration (special)';
70 my $text_e2s_c = 'values for element/sounds mapping configuration';
71 my $text_fnt_c = 'values for font/graphics mapping configuration';
72 my $text_g2s_c = 'values for gamemode/sound mapping configuration';
73 my $text_g2m_c = 'values for gamemode/music mapping configuration';
74 my $text_var_c = 'values for image and layout parameter configuration';
75 my $text_act_c = 'values for active states of elements and fonts';
77 my $num_custom_elements = 256;
78 my $num_group_elements = 32;
79 my $num_empty_elements = 16;
81 my $char_skip = '---[SKIP]---';
172 # -----------------------------------------------------------------------------
174 # -----------------------------------------------------------------------------
180 # =============================================================================
182 # =============================================================================
186 my ($error_msg) = @_;
188 print STDERR "ERROR: ";
189 print STDERR "$error_msg\n";
194 my ($error_msg) = @_;
196 print STDERR "FATAL ";
202 sub contains_image_file
206 return ($line =~ /\".+\.png\"/ ||
207 $line =~ /UNDEFINED_FILENAME/);
210 sub contains_sound_file
214 return ($line =~ /\".+\.wav\"/ ||
215 $line =~ /UNDEFINED_FILENAME/);
218 sub contains_music_file
222 return ($line =~ /\".+\.wav\"/ ||
223 $line =~ /\".+\.mod\"/ ||
224 $line =~ /\".+\.mp3\"/ ||
225 $line =~ /UNDEFINED_FILENAME/);
228 sub print_file_header
230 my ($filename, $comment) = @_;
231 my $filename_tmpl = 'xxxxxxxx.x';
232 my $filename_text = $filename;
233 my $filename_def = uc($filename);
234 $filename_def =~ s/\./_/;
236 $filename_text .= ' ' x (length($filename_tmpl) - length($filename_text));
238 open(FILE, "$filename_header_tmpl") ||
239 fail("cannot open file '$filename_header_tmpl' for reading");
243 s/$filename_tmpl/$filename_text/;
251 print "// ------- $text_auto -------\n";
253 print "#ifndef $filename_def\n";
254 print "#define $filename_def\n";
256 print "// $comment\n";
260 sub print_file_footer
263 my $filename_def = uc($filename);
264 $filename_def =~ s/\./_/;
267 print "#endif // $filename_def\n";
272 my ($text, $max_num_tabs) = @_;
274 my $num_tabs = $max_num_tabs - int(length($text) / 8);
276 if ($num_tabs < 1) # at least one tab needed as separator
281 return "\t" x $num_tabs;
284 sub print_graphics_list
286 my $filename = "$src_path/conf_gfx.c";
288 print_file_header($filename_conf_gfx_h, $text_gfx_h);
290 open(FILE, "$filename") ||
291 fail("cannot open file '$filename' for reading");
293 my $max_num_tabs = 7;
298 chomp; # cut trailing newline
300 if (/^\#include "conf_chr.c"/) # dump list of character elements
302 foreach my $char (@chars)
306 $prefix =~ s/^/#define IMG_CHAR_/;
308 my $tabs = get_tabs($prefix, $max_num_tabs);
310 if ($char ne $char_skip)
312 print "$prefix$tabs$i\n";
317 if (lc($char) eq 'space')
319 $prefix =~ s/$/_EDITOR/;
321 my $tabs = get_tabs($prefix, $max_num_tabs);
323 print "$prefix$tabs$i\n";
329 foreach my $char (@chars)
333 $prefix =~ s/^/#define IMG_STEEL_CHAR_/;
335 my $tabs = get_tabs($prefix, $max_num_tabs);
337 if ($char ne $char_skip)
339 print "$prefix$tabs$i\n";
344 if (lc($char) eq 'space')
346 $prefix =~ s/$/_EDITOR/;
348 my $tabs = get_tabs($prefix, $max_num_tabs);
350 print "$prefix$tabs$i\n";
357 if (/^\#include "conf_cus.c"/) # dump list of custom elements
359 for (my $nr = 0; $nr < $num_custom_elements; $nr++)
361 my $line = sprintf("#define IMG_CUSTOM_%d", $nr + 1);
363 my $tabs = get_tabs($line, $max_num_tabs);
365 print "$line$tabs$i\n";
369 $line = sprintf("#define IMG_CUSTOM_%d_EDITOR", $nr + 1);
371 $tabs = get_tabs($line, $max_num_tabs);
373 print "$line$tabs$i\n";
379 if (/^\#include "conf_grp.c"/) # dump list of group elements
381 for (my $nr = 0; $nr < $num_group_elements; $nr++)
383 my $line = sprintf("#define IMG_GROUP_%d", $nr + 1);
385 my $tabs = get_tabs($line, $max_num_tabs);
387 print "$line$tabs$i\n";
391 $line = sprintf("#define IMG_GROUP_%d_EDITOR", $nr + 1);
393 $tabs = get_tabs($line, $max_num_tabs);
395 print "$line$tabs$i\n";
401 if (/^\#include "conf_emp.c"/) # dump list of empty elements
403 for (my $nr = 0; $nr < $num_empty_elements; $nr++)
405 my $line = sprintf("#define IMG_EMPTY_SPACE_%d", $nr + 1);
407 my $tabs = get_tabs($line, $max_num_tabs);
409 print "$line$tabs$i\n";
413 $line = sprintf("#define IMG_EMPTY_SPACE_%d_EDITOR", $nr + 1);
415 $tabs = get_tabs($line, $max_num_tabs);
417 print "$line$tabs$i\n";
423 if (!contains_image_file($_)) # skip all lines without image file
428 s/(.*)/uc($1)/eg; # convert all characters to upper case
429 s/\./_/g; # replace all '.' with '_'
431 s/^ \{ \"/#define IMG_/; # convert line
432 s/\",.*$//; # convert line
434 # dirty hack for making "ABC[DEF]" work as a "special" suffix
437 # dirty hack for making "[default]" work as an element name
441 my $tabs = get_tabs($_, $max_num_tabs);
448 my $summary = '#define NUM_IMAGE_FILES';
449 my $tabs = get_tabs($summary, $max_num_tabs);
451 print "\n$summary$tabs$i\n";
455 print_file_footer($filename_conf_gfx_h);
458 sub print_sounds_list
460 my %known_element = get_known_element_definitions();
462 my $filename = "$src_path/conf_snd.c";
464 print_file_header($filename_conf_snd_h, $text_snd_h);
466 open(FILE, "$filename") ||
467 fail("cannot open file '$filename' for reading");
469 my $max_num_tabs = 7;
474 chomp; # cut trailing newline
476 if (!contains_sound_file($_)) # skip all lines without sound file
481 if (/\[not used\]/ ||
483 /wav[^\}]*$/) # skip all lines without sound file
488 s/(.*)/uc($1)/eg; # convert all characters to upper case
489 s/\./_/g; # replace all '.' with '_'
496 if ($sound =~ /^\[.+\]/)
498 $sound =~ s/\[//; # element class sound; begin ...
499 $sound =~ s/\]//; # ... and end of definition token
500 $sound =~ s/^/CLASS_/; # add class identifier
503 $sound = "SND_$sound";
505 my $define_text = "#define $sound";
506 my $tabs = get_tabs($define_text, $max_num_tabs);
508 print "$define_text$tabs$i\n";
513 my $summary = '#define NUM_SOUND_FILES';
514 my $tabs = get_tabs($summary, $max_num_tabs);
516 print "\n$summary$tabs$i\n";
520 print_file_footer($filename_conf_snd_h);
525 my %known_prefix = get_known_music_prefix_definitions();
527 my $filename = "$src_path/conf_mus.c";
529 print_file_header($filename_conf_mus_h, $text_mus_h);
531 open(FILE, "$filename") ||
532 fail("cannot open file '$filename' for reading");
534 my $max_num_tabs = 7;
539 chomp; # cut trailing newline
541 if (!contains_music_file($_)) # skip all lines without music file
546 if (/\[not used\]/ ||
548 /wav[^\}]*$/) # skip all lines without music file
553 s/(.*)/uc($1)/eg; # convert all characters to upper case
554 s/\./_/g; # replace all '.' with '_'
561 $music = "MUS_$music";
563 my $define_text = "#define $music";
564 my $tabs = get_tabs($define_text, $max_num_tabs);
566 print "$define_text$tabs$i\n";
571 my $summary = '#define NUM_MUSIC_FILES';
572 my $tabs = get_tabs($summary, $max_num_tabs);
574 print "\n$summary$tabs$i\n";
578 print_file_footer($filename_conf_mus_h);
581 sub print_chars_elements_list
583 print_file_header($filename_conf_chr_h, $text_chr_h);
587 foreach my $char (@chars)
589 my $left = "#define EL_CHAR_$char";
591 my $tabs_left = get_tabs($left, 5);
593 my $right = sprintf("(EL_CHAR_ASCII0 + %d)", $i + 32);
595 if ($char ne $char_skip)
597 print "$left$tabs_left$right\n";
605 foreach my $char (@chars)
607 my $left = "#define EL_STEEL_CHAR_$char";
609 my $tabs_left = get_tabs($left, 5);
611 my $right = sprintf("(EL_STEEL_CHAR_ASCII0 + %d)", $i + 32);
613 if ($char ne $char_skip)
615 print "$left$tabs_left$right\n";
621 print_file_footer($filename_conf_chr_c);
624 sub print_chars_graphics_list_line
626 my ($token, $x, $y) = @_;
636 my $basename = ($token =~ /^steel_char/ ? 'RocksFontDC' : 'RocksFontEM' );
638 foreach my $ext (@extensions)
640 my $left = " \{ \"$token$ext\",";
642 my $tabs_left = get_tabs($left, 6);
644 my $right = ($ext eq '' ? $basename . '.png' :
645 $ext eq '.frames' ? '1' : '0');
651 elsif ($ext eq '.ypos')
656 $right = "\"$right\"";
658 my $tabs_right = get_tabs($right, 3);
660 print "$left$tabs_left$right$tabs_right},\n";
664 sub print_chars_graphics_list
666 print_file_header($filename_conf_chr_c, $text_chr_c);
670 foreach my $char (@chars)
672 if ($char ne $char_skip)
675 my $y = int($i / 16);
677 print_chars_graphics_list_line(lc("char_$char"), $x, $y);
680 if (lc($char) eq 'space')
682 print_chars_graphics_list_line("char_space.EDITOR", 7, 4);
685 if ($char ne $char_skip)
695 foreach my $char (@chars)
697 if ($char ne $char_skip)
700 my $y = int($i / 16);
702 print_chars_graphics_list_line(lc("steel_char_$char"), $x, $y);
705 if (lc($char) eq 'space')
707 print_chars_graphics_list_line("steel_char_space.EDITOR", 7, 4);
710 if ($char ne $char_skip)
718 print_file_footer($filename_conf_chr_c);
721 sub print_custom_elements_list
723 print_file_header($filename_conf_cus_h, $text_cus_h);
725 for (my $i = 0; $i < $num_custom_elements; $i++)
727 my $left = sprintf("#define EL_CUSTOM_%d", $i + 1);
729 my $tabs_left = get_tabs($left, 5);
731 my $right = "(EL_CUSTOM_START + $i)";
733 print "$left$tabs_left$right\n";
736 print_file_footer($filename_conf_cus_c);
739 sub print_group_elements_list
741 print_file_header($filename_conf_grp_h, $text_grp_h);
743 for (my $i = 0; $i < $num_group_elements; $i++)
745 my $left = sprintf("#define EL_GROUP_%d", $i + 1);
747 my $tabs_left = get_tabs($left, 5);
749 my $right = "(EL_GROUP_START + $i)";
751 print "$left$tabs_left$right\n";
754 print_file_footer($filename_conf_grp_c);
757 sub print_empty_elements_list
759 print_file_header($filename_conf_emp_h, $text_emp_h);
761 for (my $i = 0; $i < $num_empty_elements; $i++)
763 my $left = sprintf("#define EL_EMPTY_SPACE_%d", $i + 1);
765 my $tabs_left = get_tabs($left, 5);
767 my $right = "(EL_EMPTY_SPACE_START + $i)";
769 print "$left$tabs_left$right\n";
772 print_file_footer($filename_conf_emp_c);
775 sub print_custom_graphics_list
791 print_file_header($filename_conf_cus_c, $text_cus_c);
793 for (my $i = 0; $i < $num_custom_elements; $i++)
795 foreach my $ext (@extensions1)
797 my $left = sprintf(" \{ \"custom_%d$ext\",", $i + 1);
799 my $tabs_left = get_tabs($left, 6);
801 # my $right = ($ext eq '' ? 'RocksElements.png' :
802 my $right = ($ext eq '' ? 'RocksCE.png' :
803 $ext eq '.frames' ? '1' : '0');
808 $right = int($i % 16);
810 elsif ($ext eq '.ypos')
813 $right = int($i / 16);
816 $right = "\"$right\"";
818 my $tabs_right = get_tabs($right, 3);
820 print "$left$tabs_left$right$tabs_right},\n";
823 foreach my $ext (@extensions2)
825 my $left = sprintf(" \{ \"custom_%d.EDITOR$ext\",", $i + 1);
827 my $tabs_left = get_tabs($left, 6);
829 # my $right = ($ext eq '' ? 'RocksElements.png' : '0');
830 my $right = ($ext eq '' ? 'RocksCE.png' : '0');
835 $right = int($i % 16) + 16;
837 elsif ($ext eq '.ypos')
840 $right = int($i / 16);
843 $right = "\"$right\"";
845 my $tabs_right = get_tabs($right, 3);
847 print "$left$tabs_left$right$tabs_right},\n";
853 print_file_footer($filename_conf_cus_c);
856 sub print_group_graphics_list
872 print_file_header($filename_conf_grp_c, $text_grp_c);
874 for (my $i = 0; $i < $num_group_elements; $i++)
876 foreach my $ext (@extensions1)
878 my $left = sprintf(" \{ \"group_%d$ext\",", $i + 1);
880 my $tabs_left = get_tabs($left, 6);
882 # my $right = ($ext eq '' ? 'RocksDC.png' :
883 my $right = ($ext eq '' ? 'RocksCE.png' :
884 $ext eq '.frames' ? '1' : '0');
889 $right = int($i % 16);
891 elsif ($ext eq '.ypos')
894 $right = int($i / 16) + int($num_custom_elements / 16);
897 $right = "\"$right\"";
899 my $tabs_right = get_tabs($right, 3);
901 print "$left$tabs_left$right$tabs_right},\n";
904 foreach my $ext (@extensions2)
906 my $left = sprintf(" \{ \"group_%d.EDITOR$ext\",", $i + 1);
908 my $tabs_left = get_tabs($left, 6);
910 # my $right = ($ext eq '' ? 'RocksDC.png' : '0');
911 my $right = ($ext eq '' ? 'RocksCE.png' : '0');
916 $right = int($i % 16) + 16;
918 elsif ($ext eq '.ypos')
921 $right = int($i / 16) + int($num_custom_elements / 16);
924 $right = "\"$right\"";
926 my $tabs_right = get_tabs($right, 3);
928 print "$left$tabs_left$right$tabs_right},\n";
934 print_file_footer($filename_conf_grp_c);
937 sub print_empty_graphics_list
953 my $num_non_empty_elements = $num_custom_elements + $num_group_elements;
955 print_file_header($filename_conf_emp_c, $text_emp_c);
957 for (my $i = 0; $i < $num_empty_elements; $i++)
959 foreach my $ext (@extensions1)
961 my $left = sprintf(" \{ \"empty_space_%d$ext\",", $i + 1);
963 my $tabs_left = get_tabs($left, 6);
965 # my $right = ($ext eq '' ? 'RocksDC.png' :
966 my $right = ($ext eq '' ? 'RocksCE.png' :
967 $ext eq '.frames' ? '1' : '0');
972 $right = int($i % 16);
974 elsif ($ext eq '.ypos')
977 $right = int($i / 16) + int($num_non_empty_elements / 16);
980 $right = "\"$right\"";
982 my $tabs_right = get_tabs($right, 3);
984 print "$left$tabs_left$right$tabs_right},\n";
987 foreach my $ext (@extensions2)
989 my $left = sprintf(" \{ \"empty_space_%d.EDITOR$ext\",", $i + 1);
991 my $tabs_left = get_tabs($left, 6);
993 # my $right = ($ext eq '' ? 'RocksDC.png' : '0');
994 my $right = ($ext eq '' ? 'RocksCE.png' : '0');
999 $right = int($i % 16) + 16;
1001 elsif ($ext eq '.ypos')
1004 $right = int($i / 16) + int($num_non_empty_elements / 16);
1007 $right = "\"$right\"";
1009 my $tabs_right = get_tabs($right, 3);
1011 print "$left$tabs_left$right$tabs_right},\n";
1017 print_file_footer($filename_conf_emp_c);
1020 sub get_known_element_definitions_ALTERNATIVE
1022 my %known_element = ();
1024 my $filename = "$src_path/main.h";
1026 open(FILE, "$filename") ||
1027 fail("cannot open file '$filename' for reading");
1031 chomp; # cut trailing newline
1033 # process line with element definition
1034 if (/^\#define (EL_[A-Z0-9_]+)\s/)
1036 $known_element{$1} = 1;
1038 # print STDERR "known_element: '$1'\n";
1044 return %known_element;
1047 sub get_known_element_definitions
1049 my %known_element = ();
1051 my $filename = "$src_path/main.c";
1053 open(FILE, "$filename") ||
1054 fail("cannot open file '$filename' for reading");
1056 my $element_name = '';
1057 my $line_is_element_name = 0;
1062 chomp; # cut trailing newline
1064 if (/ELEMENT_INFO_START/) # keyword to start parsing file
1069 elsif (/ELEMENT_INFO_END/) # keyword to stop parsing file
1080 $line_is_element_name = 1;
1082 elsif ($line_is_element_name)
1084 # process line with element name definition
1085 if (/^\s+\"(.+)\",?\s*$/)
1087 $element_name = 'EL_' . uc($1);
1089 # dirty hack for making "[default]" work as an element name
1090 $element_name =~ s/\[//;
1091 $element_name =~ s/\]//;
1093 # change '.' to '_' for elements like "dynamite.active"
1094 $element_name =~ s/\./_/g;
1096 $known_element{$element_name} = 1;
1098 # printf STDERR "::: known element '$element_name'\n";
1101 $line_is_element_name = 0;
1107 return %known_element;
1110 sub get_known_element_class_definitions
1112 my %known_element_class = ();
1114 my $filename = "$src_path/main.c";
1116 open(FILE, "$filename") ||
1117 fail("cannot open file '$filename' for reading");
1119 my $element_name = '';
1120 my $element_class = '';
1121 my $line_is_element_name = 0;
1122 my $line_is_element_class = 0;
1127 chomp; # cut trailing newline
1129 if (/ELEMENT_INFO_START/) # keyword to start parsing file
1134 elsif (/ELEMENT_INFO_END/) # keyword to stop parsing file
1145 $line_is_element_name = 1;
1147 elsif ($line_is_element_name)
1149 # process line with element name definition
1150 if (/^\s+\"(.+)\",?\s*$/)
1152 $element_name = 'EL_' . uc($1);
1154 # dirty hack for making "[default]" work as an element name
1155 $element_name =~ s/\[//;
1156 $element_name =~ s/\]//;
1158 # change '.' to '_' for elements like "dynamite.active"
1159 $element_name =~ s/\./_/g;
1162 $line_is_element_name = 0;
1163 $line_is_element_class = 1;
1165 elsif ($line_is_element_class)
1167 # process line with element class definition
1168 if (/^\s+\"(.+)\",?\s*$/)
1170 $element_class = 'EL_CLASS_' . uc($1);
1172 if (!defined($known_element_class{$element_class}))
1174 $known_element_class{$element_class} = $element_name;
1177 $known_element_class{$element_name} = $element_class;
1179 # print STDERR "known_element_class: '$element_name' => '$element_class'\n";
1182 $line_is_element_class = 0;
1188 return %known_element_class;
1191 sub get_known_action_definitions
1193 my %known_action = ();
1195 my $filename = "$src_path/main.h";
1197 open(FILE, "$filename") ||
1198 fail("cannot open file '$filename' for reading");
1202 chomp; # cut trailing newline
1204 # process line with action definition
1205 if (/^ ACTION_([A-Z0-9_]+)[, ]/)
1207 $known_action{$1} = 1;
1209 # print STDERR "known_action: '$1'\n";
1215 return %known_action;
1218 sub get_known_special_arg_definitions
1220 my %known_special_arg = ();
1222 my $filename = "$src_path/main.h";
1224 open(FILE, "$filename") ||
1225 fail("cannot open file '$filename' for reading");
1229 chomp; # cut trailing newline
1231 # process line with special arg definition
1232 if (/^ GFX_SPECIAL_ARG_([A-Z0-9_]+)[, ]/)
1234 if ($1 eq 'CRUMBLED')
1239 $known_special_arg{$1} = 1;
1241 # print STDERR "known_special_arg: '$1'\n";
1247 return %known_special_arg;
1250 sub get_known_button_definitions
1252 my %known_button = ();
1254 my $filename = "$src_path/conf_gfx.h";
1256 open(FILE, "$filename") ||
1257 fail("cannot open file '$filename' for reading");
1261 chomp; # cut trailing newline
1263 # process line with button definition
1264 if (/^\#define (IMG_MENU_BUTTON[A-Z0-9_]*)\s/)
1266 $known_button{$1} = 1;
1268 # print STDERR "known_button: '$1'\n";
1274 return %known_button;
1277 sub get_known_font_definitions
1279 my %known_font = ();
1281 my $filename = "$src_path/main.h";
1283 open(FILE, "$filename") ||
1284 fail("cannot open file '$filename' for reading");
1288 chomp; # cut trailing newline
1290 # process line with font definition
1291 if (/^ (FONT_[A-Z0-9_]+)[, ]/)
1293 $known_font{$1} = 1;
1295 # print STDERR "known_font: '$1'\n";
1304 sub get_known_sound_prefix_definitions
1306 my %known_sound_prefix = ( 'background' => 1 );
1308 return %known_sound_prefix;
1311 sub get_known_music_prefix_definitions
1313 my %known_music_prefix = ();
1315 my $filename = "$src_path/main.c";
1317 open(FILE, "$filename") ||
1318 fail("cannot open file '$filename' for reading");
1320 my $prefix_name = '';
1325 chomp; # cut trailing newline
1327 if (/MusicPrefixInfo/) # keyword to start parsing file
1332 elsif (/NULL/ && !$skip_line) # keyword to stop parsing file
1341 if (/^\s+{\s+\"(.+)\"/)
1343 my $music_prefix = $1;
1345 $known_music_prefix{$music_prefix} = 1;
1347 # printf STDERR "::: known music prefix '$music_prefix'\n";
1353 return %known_music_prefix;
1356 sub print_element_to_graphic_entry
1358 my ($element, $action, $direction, $crumbled, $graphic) = @_;
1360 my $num_tabs = 5 - int((length($element) + 4 + 1) / 8);
1361 my $tabs = "\t" x $num_tabs;
1367 $crumbled = ($crumbled == 1 ? 'TRUE' : 'FALSE');
1370 print " $element,$tabs$action, $direction, $crumbled,\n";
1371 print " $graphic\n";
1375 sub print_element_to_special_graphic_entry
1377 my ($element, $special, $graphic) = @_;
1379 my $num_tabs = 6 - int((length($element) + 4 + 1) / 8);
1380 my $tabs = "\t" x $num_tabs;
1387 print " $element,$tabs$special,\n";
1388 print " $graphic\n";
1392 sub print_font_to_graphic_entry
1394 my ($font, $special, $graphic) = @_;
1396 my $num_tabs = 6 - int((length($font) + 4 + 1) / 8);
1397 my $tabs = "\t" x $num_tabs;
1404 print " $font,$tabs$special,\n";
1405 print " $graphic\n";
1409 sub print_element_to_sound_entry
1411 my ($element, $is_class, $action, $sound) = @_;
1413 my $element_plus_is_class = "$element, $is_class";
1415 my $num_tabs = 6 - int((length($element_plus_is_class) + 4 + 1) / 8);
1416 my $tabs = "\t" x $num_tabs;
1423 print " $element_plus_is_class,$tabs$action,\n";
1428 sub print_gamemode_to_sound_entry
1430 my ($gamemode, $sound) = @_;
1433 print " $gamemode,\n";
1438 sub print_gamemode_to_music_entry
1440 my ($gamemode, $music) = @_;
1443 print " $gamemode,\n";
1448 sub print_image_config_var_entry
1450 my ($token, $var) = @_;
1458 sub print_active_state_entry
1460 my ($token, $token_active) = @_;
1464 print " $token_active\n";
1468 sub print_element_to_graphic_list
1470 my %graphic_without_element =
1472 'IMG_FLAMES_1_LEFT' => 1,
1473 'IMG_FLAMES_2_LEFT' => 1,
1474 'IMG_FLAMES_3_LEFT' => 1,
1475 'IMG_FLAMES_1_RIGHT' => 1,
1476 'IMG_FLAMES_2_RIGHT' => 1,
1477 'IMG_FLAMES_3_RIGHT' => 1,
1478 'IMG_FLAMES_1_UP' => 1,
1479 'IMG_FLAMES_2_UP' => 1,
1480 'IMG_FLAMES_3_UP' => 1,
1481 'IMG_FLAMES_1_DOWN' => 1,
1482 'IMG_FLAMES_2_DOWN' => 1,
1483 'IMG_FLAMES_3_DOWN' => 1,
1484 'IMG_TWINKLE_BLUE' => 1,
1485 'IMG_TWINKLE_WHITE' => 1,
1488 my %additional_mappings =
1490 # file elements which are mapped to runtime elements when playing
1492 # 'EL_EM_KEY_1_FILE' => 'IMG_EM_KEY_1',
1493 # 'EL_EM_KEY_2_FILE' => 'IMG_EM_KEY_2',
1494 # 'EL_EM_KEY_3_FILE' => 'IMG_EM_KEY_3',
1495 # 'EL_EM_KEY_4_FILE' => 'IMG_EM_KEY_4',
1497 # new elements which still have no graphic
1498 # 'EL_DOOR_WHITE', => 'IMG_CHAR_QUESTION',
1499 # 'EL_DOOR_WHITE_GRAY', => 'IMG_CHAR_QUESTION',
1500 # 'EL_KEY_WHITE', => 'IMG_CHAR_QUESTION',
1501 # 'EL_SIGN_RADIOACTIVITY', => 'IMG_CHAR_QUESTION',
1502 # 'EL_SIGN_WHEELCHAIR', => 'IMG_CHAR_QUESTION',
1503 # 'EL_SIGN_PARKING', => 'IMG_CHAR_QUESTION',
1504 # 'EL_SIGN_ONEWAY', => 'IMG_CHAR_QUESTION',
1505 # 'EL_SIGN_HEART', => 'IMG_CHAR_QUESTION',
1506 # 'EL_SIGN_TRIANGLE', => 'IMG_CHAR_QUESTION',
1507 # 'EL_SIGN_ROUND', => 'IMG_CHAR_QUESTION',
1508 # 'EL_SIGN_EXIT', => 'IMG_CHAR_QUESTION',
1509 # 'EL_SIGN_YINYANG', => 'IMG_CHAR_QUESTION',
1510 # 'EL_SIGN_OTHER', => 'IMG_CHAR_QUESTION',
1511 'EL_SIGN_UNUSED_1', => 'IMG_CHAR_QUESTION',
1512 'EL_SIGN_UNUSED_2', => 'IMG_CHAR_QUESTION',
1513 'EL_DX_UNKNOWN_15', => 'IMG_CHAR_QUESTION',
1514 'EL_DX_UNKNOWN_42', => 'IMG_CHAR_QUESTION',
1516 # file elements with direction which is not defined
1517 'EL_BD_BUTTERFLY_LEFT' => 'IMG_BD_BUTTERFLY',
1518 'EL_BD_BUTTERFLY_RIGHT' => 'IMG_BD_BUTTERFLY',
1519 'EL_BD_BUTTERFLY_UP' => 'IMG_BD_BUTTERFLY',
1520 'EL_BD_BUTTERFLY_DOWN' => 'IMG_BD_BUTTERFLY',
1521 'EL_BD_FIREFLY_LEFT' => 'IMG_BD_FIREFLY',
1522 'EL_BD_FIREFLY_RIGHT' => 'IMG_BD_FIREFLY',
1523 'EL_BD_FIREFLY_UP' => 'IMG_BD_FIREFLY',
1524 'EL_BD_FIREFLY_DOWN' => 'IMG_BD_FIREFLY',
1527 my @unknown_graphics = ();
1528 my %known_element = get_known_element_definitions();
1529 my %known_action = get_known_action_definitions();
1530 my %known_special_arg = get_known_special_arg_definitions();
1531 my %known_direction =
1543 # ---------- read graphic file definitions ----------
1545 my $filename = "$src_path/conf_gfx.c";
1547 print_file_header($filename_conf_e2g_c, $text_e2g_c);
1549 open(FILE, "$filename") ||
1550 fail("cannot open file '$filename' for reading");
1552 print "static struct\n";
1554 print " int element;\n";
1555 print " int action;\n";
1556 print " int direction;\n";
1557 print " boolean crumbled;\n";
1559 print " int graphic;\n";
1561 print "element_to_graphic[] =\n";
1566 chomp; # cut trailing newline
1568 if (/NO_MORE_ELEMENT_IMAGES/) # keyword to stop parsing file
1573 if (!contains_image_file($_)) # skip all lines without image file
1578 s/^ \{ \"//; # cut all leading ...
1579 s/\",.*$//; # ... and trailing garbage
1581 s/\[(\d+)\]/_$1/; # convert "[1]" to "_1" etc.
1583 s/\[//; # dirty hack for making "[default]" ...
1584 s/\]//; # ... work as an element name
1588 if ($token =~ /\.([^\.]+)$/ && defined($known_special_arg{$1}))
1590 next; # skip all special definitions
1593 $token = uc($token); # convert all characters to upper case
1595 my $gfx_action_default = '-1';
1596 my $gfx_action = $gfx_action_default;
1598 my $gfx_direction_default = '-1';
1599 my $gfx_direction = $gfx_direction_default;
1601 my $gfx_crumbled = '0';
1603 my $object = $token;
1608 if ($object =~ /^(.*)\.([A-Z0-9]+)$/ && $2 eq 'CRUMBLED')
1613 $gfx_crumbled = '1';
1616 if ($object =~ /^(.*)\.([A-Z0-9]+)$/ && defined($known_direction{$2}))
1621 $gfx_direction = "MV_BIT_$direction";
1622 $gfx_direction_default = $gfx_direction;
1625 if ($object =~ /^(.*)\.([A-Z0-9_]+)$/ && defined($known_action{$2}))
1630 $gfx_action = "ACTION_$action";
1631 $gfx_action_default = $gfx_action;
1635 $object =~ s/\./_/g; # needed for "invisible_sand.active.digging"
1637 # print STDERR "'$token' => '$object', '$action', '$direction'\n";
1639 my $full_element = "EL_$token";
1640 my $base_element = "EL_$object";
1642 my $element = $base_element;
1643 my $graphic = "IMG_$token";
1645 my $element_without_crumbled = $full_element;
1646 $element_without_crumbled =~ s/_$crumbled$//;
1648 my $element_without_direction = $element_without_crumbled;
1649 $element_without_direction =~ s/_$direction$//;
1651 my $element_without_action = $element_without_direction;
1652 $element_without_action =~ s/_$action$//;
1654 if (defined($known_element{$full_element}))
1656 $element = $full_element;
1658 $gfx_action_default = '-1';
1659 $gfx_direction_default = '-1';
1662 if ($element_without_action eq $element || $action eq '')
1664 $element_without_action = '';
1667 if ($element_without_direction eq $element || $direction eq '')
1669 $element_without_direction = '';
1672 if ($element_without_crumbled eq $element || $crumbled eq '')
1674 $element_without_crumbled = '';
1677 if (defined($graphic_without_element{$graphic}))
1682 if (!defined($known_element{$element}))
1684 # print STDERR "----- ERROR: unknown element '$element' -----\n";
1686 push @unknown_graphics, $graphic;
1691 if (defined($known_element{$element}))
1693 print_element_to_graphic_entry($element,
1694 $gfx_action_default,
1695 $gfx_direction_default,
1700 if (defined($known_element{$element_without_action}))
1702 print_element_to_graphic_entry($element_without_action,
1709 if (defined($known_element{$element_without_direction}))
1711 print_element_to_graphic_entry($element_without_direction,
1718 if (defined($known_element{$element_without_crumbled}))
1720 print_element_to_graphic_entry($element_without_crumbled,
1728 # dump list of additional elements
1729 foreach my $element (sort keys %additional_mappings)
1731 print_element_to_graphic_entry($element, '-1', '-1', '-1',
1732 $additional_mappings{$element});
1735 # dump list of character elements
1736 foreach my $char (@chars)
1738 my $element = "EL_CHAR_$char";
1739 my $graphic = "IMG_CHAR_$char";
1741 if ($char ne $char_skip)
1743 print_element_to_graphic_entry($element, '-1', '-1', '-1',$graphic);
1746 foreach my $char (@chars)
1748 my $element = "EL_STEEL_CHAR_$char";
1749 my $graphic = "IMG_STEEL_CHAR_$char";
1751 if ($char ne $char_skip)
1753 print_element_to_graphic_entry($element, '-1', '-1', '-1',$graphic);
1757 # dump list of custom elements
1758 for (my $i = 0; $i < $num_custom_elements; $i++)
1760 my $element = sprintf("EL_CUSTOM_%d", $i + 1);
1761 my $graphic = sprintf("IMG_CUSTOM_%d", $i + 1);
1763 print_element_to_graphic_entry($element, '-1', '-1', '-1', $graphic);
1766 # dump list of group elements
1767 for (my $i = 0; $i < $num_group_elements; $i++)
1769 my $element = sprintf("EL_GROUP_%d", $i + 1);
1770 my $graphic = sprintf("IMG_GROUP_%d", $i + 1);
1772 print_element_to_graphic_entry($element, '-1', '-1', '-1', $graphic);
1775 # dump list of empty elements
1776 for (my $i = 0; $i < $num_empty_elements; $i++)
1778 my $element = sprintf("EL_EMPTY_SPACE_%d", $i + 1);
1779 my $graphic = sprintf("IMG_EMPTY_SPACE_%d", $i + 1);
1781 print_element_to_graphic_entry($element, '-1', '-1', '-1', $graphic);
1784 print_element_to_graphic_entry('-1', '-1', '-1', '-1', '-1');
1790 if (scalar(@unknown_graphics) > 0)
1792 print STDERR "-" x 79 . "\n";
1793 print STDERR "The following graphics cannot be associated with any element:\n";
1795 foreach my $graphic (@unknown_graphics)
1797 print STDERR "- $graphic\n";
1800 print STDERR "-" x 79 . "\n";
1803 print_file_footer($filename_conf_e2g_c);
1806 sub print_element_to_special_graphic_list
1808 my %graphic_without_element =
1810 'IMG_GLOBAL_DOOR' => 1,
1813 my %additional_mappings =
1815 # old elements which are mapped to other elements when playing
1816 #'EL_BUG' => 'IMG_BUG_RIGHT',
1817 #'EL_SPACESHIP' => 'IMG_SPACESHIP_RIGHT',
1818 #'EL_PACMAN' => 'IMG_PACMAN_RIGHT',
1821 my @elements_with_editor_graphic =
1827 my @unknown_graphics = ();
1828 my %known_element = get_known_element_definitions();
1829 my %known_special_arg = get_known_special_arg_definitions();
1831 # ---------- read graphic file definitions ----------
1833 my $filename = "$src_path/conf_gfx.c";
1835 print_file_header($filename_conf_esg_c, $text_esg_c);
1837 open(FILE, "$filename") ||
1838 fail("cannot open file '$filename' for reading");
1840 print "static struct\n";
1842 print " int element;\n";
1843 print " int special;\n";
1845 print " int graphic;\n";
1847 print "element_to_special_graphic[] =\n";
1852 chomp; # cut trailing newline
1854 if (/NO_MORE_ELEMENT_IMAGES/) # keyword to stop parsing file
1859 if (!contains_image_file($_)) # skip all lines without image file
1864 s/^ \{ \"//; # cut all leading ...
1865 s/\",.*$//; # ... and trailing garbage
1871 if ($token =~ /^font\./) # skip all font definitions
1876 if ($token =~ /^background\./) # skip all background image definitions
1881 if ($token =~ /^(.*)\.([^\.]+)$/ &&
1882 defined($known_special_arg{$2}))
1885 $special = "GFX_SPECIAL_ARG_" . $2;
1889 next; # skip all default definitions
1892 $token =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
1893 $object =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
1896 $object =~ s/\./_/g;
1898 # print STDERR "'$token' => '$object'\n";
1900 my $element = "EL_$object";
1901 my $graphic = "IMG_$token";
1903 if (defined($graphic_without_element{$graphic}))
1908 if (!defined($known_element{$element}))
1910 # print STDERR "----- ERROR: unknown element '$element' -----\n";
1912 push @unknown_graphics, $graphic;
1917 print_element_to_special_graphic_entry($element,
1922 # dump list of additional elements
1923 foreach my $element (sort keys %additional_mappings)
1925 print_element_to_special_graphic_entry($element,
1926 'GFX_SPECIAL_ARG_EDITOR',
1927 $additional_mappings{$element});
1928 print_element_to_special_graphic_entry($element,
1929 'GFX_SPECIAL_ARG_PREVIEW',
1930 $additional_mappings{$element});
1933 # dump list of custom element editor graphics
1934 for (my $i = 0; $i < $num_custom_elements; $i++)
1936 my $element = sprintf("EL_CUSTOM_%d", $i + 1);
1937 my $graphic = sprintf("IMG_CUSTOM_%d_EDITOR", $i + 1);
1939 print_element_to_special_graphic_entry($element,
1940 'GFX_SPECIAL_ARG_EDITOR',
1944 # dump list of group element editor graphics
1945 for (my $i = 0; $i < $num_group_elements; $i++)
1947 my $element = sprintf("EL_GROUP_%d", $i + 1);
1948 my $graphic = sprintf("IMG_GROUP_%d_EDITOR", $i + 1);
1950 print_element_to_special_graphic_entry($element,
1951 'GFX_SPECIAL_ARG_EDITOR',
1955 # dump list of empty element editor graphics
1956 for (my $i = 0; $i < $num_empty_elements; $i++)
1958 my $element = sprintf("EL_EMPTY_SPACE_%d", $i + 1);
1959 my $graphic = sprintf("IMG_EMPTY_SPACE_%d_EDITOR", $i + 1);
1961 print_element_to_special_graphic_entry($element,
1962 'GFX_SPECIAL_ARG_EDITOR',
1966 # dump other special editor graphics
1967 foreach my $token (@elements_with_editor_graphic)
1969 my $element = 'EL_' . uc($token);
1970 my $graphic = 'IMG_' . uc($token) . '_EDITOR';
1972 print_element_to_special_graphic_entry($element,
1973 'GFX_SPECIAL_ARG_EDITOR',
1977 print_element_to_special_graphic_entry('-1', '-1', '-1');
1983 if (scalar(@unknown_graphics) > 0)
1985 print STDERR "-" x 79 . "\n";
1986 print STDERR "The following graphics cannot be associated with any element:\n";
1988 foreach my $graphic (@unknown_graphics)
1990 print STDERR "- $graphic\n";
1993 print STDERR "-" x 79 . "\n";
1996 print_file_footer($filename_conf_esg_c);
1999 sub print_element_to_sound_list
2001 my %sound_without_action =
2003 'SND_AMOEBA_TURNING_TO_GEM' => 1,
2004 'SND_AMOEBA_TURNING_TO_ROCK' => 1,
2005 'SND_BD_AMOEBA_TURNING_TO_GEM' => 1,
2006 'SND_BD_AMOEBA_TURNING_TO_ROCK' => 1,
2008 # no special case anymore after adding action ".splashing"
2009 # 'SND_ACID_SPLASHING' => 1,
2012 my @unknown_sounds = ();
2013 my %known_element = get_known_element_definitions();
2014 my %known_element_class = get_known_element_class_definitions();
2015 my %known_action = get_known_action_definitions();
2017 # ---------- read sound file definitions ----------
2019 my $filename = "$src_path/conf_snd.c";
2021 print_file_header($filename_conf_e2s_c, $text_e2s_c);
2023 open(FILE, "$filename") ||
2024 fail("cannot open file '$filename' for reading");
2026 print "static struct\n";
2028 print " int element;\n";
2029 print " boolean is_class;\n";
2030 print " int action;\n";
2032 print " int sound;\n";
2034 print "element_to_sound[] =\n";
2039 chomp; # cut trailing newline
2041 if (/NO_MORE_ELEMENT_SOUNDS/) # keyword to stop parsing file
2046 if (!contains_sound_file($_)) # skip all lines without sound file
2051 s/^ \{ \"//; # cut all leading ...
2052 s/\",.*$//; # ... and trailing garbage
2056 $token = uc($token); # convert all characters to upper case
2058 my $snd_action_default = '-1';
2059 my $snd_action = $snd_action_default;
2061 my $object = $token;
2064 if ($object =~ /^(.*)\.([A-Z0-9_]+)$/ && defined($known_action{$2}))
2069 $snd_action = "ACTION_$action";
2070 $snd_action_default = $snd_action;
2074 $object =~ s/\./_/g; # needed for "invisible_sand.active.digging"
2076 if ($object =~ /^\[(.+)\]$/)
2078 $object = 'CLASS_' . $1;
2081 # print STDERR "'$token' => '$object', '$action'\n";
2083 my $full_element = "EL_$token";
2084 my $base_element = "EL_$object";
2086 my $element = $base_element;
2089 if ($sound =~ /^\[.+\]/)
2091 $sound =~ s/\[//; # element class sound; begin ...
2092 $sound =~ s/\]//; # ... and end of definition token
2093 $sound =~ s/^/CLASS_/; # add class identifier
2096 $sound = "SND_$sound";
2098 my $element_without_action = $full_element;
2099 $element_without_action =~ s/_$action$//;
2101 my $element_class_without_action = $full_element;
2102 $element_without_action =~ s/_$action$//;
2104 if (defined($known_element_class{$full_element}))
2106 $element = $full_element;
2108 $snd_action_default = '-1';
2111 if ($element_without_action eq $element || $action eq '')
2113 $element_without_action = '';
2116 if (defined($sound_without_action{$sound}))
2121 if (!defined($known_element{$element}) &&
2122 !defined($known_element_class{$element}))
2124 # print STDERR "----- ERROR: unknown element '$element' -----\n";
2126 push @unknown_sounds, $sound;
2131 if (!($element =~ /_CLASS_/) &&
2132 defined($known_element{$element}))
2134 print_element_to_sound_entry($element, "FALSE",
2135 $snd_action_default,
2139 if (!($element =~ /_CLASS_/) &&
2140 defined($known_element{$element_without_action}))
2142 print_element_to_sound_entry($element_without_action, "FALSE",
2147 if ($element =~ /_CLASS_/ &&
2148 defined($known_element_class{$element}))
2150 my $class_element = $known_element_class{$element};
2152 print_element_to_sound_entry($class_element, "TRUE",
2153 $snd_action_default,
2157 if ($element =~ /_CLASS_/ &&
2158 defined($known_element_class{$element_without_action}))
2160 my $class_element = $known_element_class{$element_without_action};
2162 print_element_to_sound_entry($class_element, "TRUE",
2168 print_element_to_sound_entry('-1', '-1', '-1', '-1');
2174 if (scalar(@unknown_sounds) > 0)
2176 print STDERR "-" x 79 . "\n";
2177 print STDERR "The following sounds cannot be associated with any element or element class:\n";
2179 foreach my $sound (@unknown_sounds)
2181 print STDERR "- $sound\n";
2184 print STDERR "-" x 79 . "\n";
2187 print_file_footer($filename_conf_e2s_c);
2190 sub print_font_to_graphic_list
2192 my @unknown_graphics = ();
2193 my %known_font = get_known_font_definitions();
2194 my %known_special_arg = get_known_special_arg_definitions();
2196 # ---------- read graphic file definitions ----------
2198 my $filename = "$src_path/conf_gfx.c";
2200 print_file_header($filename_conf_fnt_c, $text_fnt_c);
2202 open(FILE, "$filename") ||
2203 fail("cannot open file '$filename' for reading");
2205 print "static struct\n";
2207 print " int font_nr;\n";
2208 print " int special;\n";
2210 print " int graphic;\n";
2212 print "font_to_graphic[] =\n";
2217 chomp; # cut trailing newline
2219 if (!contains_image_file($_)) # skip all lines without image file
2224 s/^ \{ \"//; # cut all leading ...
2225 s/\",.*$//; # ... and trailing garbage
2232 if ($token =~ /^(font\..*)$/)
2237 if ($token =~ /^(.*)\.([^\.]+)$/ &&
2238 defined($known_special_arg{$2}))
2241 $special = "GFX_SPECIAL_ARG_" . $2;
2246 next; # skip all non-font definitions
2249 $token =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
2250 $font =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
2255 # print STDERR "'$token' => '$font'\n";
2257 $graphic = "IMG_$token";
2259 if (!defined($known_font{$font}))
2261 # print STDERR "----- ERROR: unknown font '$font' -----\n";
2263 push @unknown_graphics, $graphic;
2268 print_font_to_graphic_entry($font,
2273 print_font_to_graphic_entry('-1', '-1', '-1');
2279 if (scalar(@unknown_graphics) > 0)
2281 print STDERR "-" x 79 . "\n";
2282 print STDERR "The following graphics cannot be associated with any font:\n";
2284 foreach my $graphic (@unknown_graphics)
2286 print STDERR "- $graphic\n";
2289 print STDERR "-" x 79 . "\n";
2292 print_file_footer($filename_conf_fnt_c);
2295 sub print_gamemode_to_sound_list
2297 my %known_prefix = get_known_sound_prefix_definitions();
2298 my %known_special_arg = get_known_special_arg_definitions();
2300 # ---------- read music file definitions ----------
2302 my $filename = "$src_path/conf_snd.c";
2304 print_file_header($filename_conf_g2s_c, $text_g2s_c);
2306 open(FILE, "$filename") ||
2307 fail("cannot open file '$filename' for reading");
2309 print "static struct\n";
2311 print " int gamemode;\n";
2313 print " int sound;\n";
2315 print "gamemode_to_sound[] =\n";
2320 chomp; # cut trailing newline
2322 if (!contains_sound_file($_)) # skip all lines without sound file
2332 s/^ \{ \"//; # cut all leading ...
2333 s/\",.*$//; # ... and trailing garbage
2337 # my $level = -1; # ???
2339 if (defined($known_prefix{$token}))
2341 # no special arg defined
2343 elsif ($token =~ /^(.*)\.([^\.]+)$/ &&
2344 defined($known_prefix{$1}) &&
2345 defined($known_special_arg{$2}))
2347 $gamemode = "GFX_SPECIAL_ARG_" . $2;
2354 # if ($token =~ /^(.*)\./ &&
2355 # !defined($known_prefix{$1}))
2360 # if ($token =~ /^(.*)\.([^\.]+)$/ &&
2361 # defined($known_special_arg{$2}))
2363 # $gamemode = "GFX_SPECIAL_ARG_" . $2;
2366 $token =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
2369 my $sound = "SND_$token";
2371 # print STDERR "'$token' => '$sound'\n";
2373 print_gamemode_to_sound_entry($gamemode, $sound);
2376 print_gamemode_to_sound_entry('-1', '-1');
2382 print_file_footer($filename_conf_g2s_c);
2385 sub print_gamemode_to_music_list
2387 my %known_prefix = get_known_music_prefix_definitions();
2388 my %known_special_arg = get_known_special_arg_definitions();
2390 # ---------- read music file definitions ----------
2392 my $filename = "$src_path/conf_mus.c";
2394 print_file_header($filename_conf_g2m_c, $text_g2m_c);
2396 open(FILE, "$filename") ||
2397 fail("cannot open file '$filename' for reading");
2399 print "static struct\n";
2401 print " int gamemode;\n";
2403 print " int music;\n";
2405 print "gamemode_to_music[] =\n";
2410 chomp; # cut trailing newline
2412 if (!contains_music_file($_)) # skip all lines without music file
2417 s/^ \{ \"//; # cut all leading ...
2418 s/\",.*$//; # ... and trailing garbage
2423 if (defined($known_prefix{$token}))
2425 # no special arg defined
2427 elsif ($token =~ /^(.*)\.([^\.]+)$/ &&
2428 defined($known_prefix{$1}) &&
2429 defined($known_special_arg{$2}))
2431 $gamemode = "GFX_SPECIAL_ARG_" . $2;
2438 # my $prefix = $token;
2439 # $prefix =~ s/\..*$//;
2441 ## if ($token =~ /^(.*)\./ &&
2442 ## !defined($known_prefix{$1}))
2443 # if (!defined($known_prefix{$prefix}))
2448 # if ($token =~ /^(.*)\.([^\.]+)$/ &&
2449 # defined($known_special_arg{$2}))
2451 # $gamemode = "GFX_SPECIAL_ARG_" . $2;
2454 $token =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
2457 my $music = "MUS_$token";
2459 # print STDERR "'$token' => '$music'\n";
2461 print_gamemode_to_music_entry($gamemode, $music);
2464 print_gamemode_to_music_entry('-1', '-1');
2470 print_file_footer($filename_conf_g2m_c);
2473 sub print_image_config_vars
2475 # ---------- read graphic file definitions ----------
2477 my $filename = "$src_path/conf_gfx.c";
2479 print_file_header($filename_conf_var_c, $text_var_c);
2481 open(FILE, "$filename") ||
2482 fail("cannot open file '$filename' for reading");
2484 print "struct TokenIntPtrInfo image_config_vars[] =\n";
2487 my $start_parsing = 0;
2491 chomp; # cut trailing newline
2493 if (/CONFIG_VARS_START/) # keyword to start parsing file
2498 if (!$start_parsing)
2503 if (/^\s*\{\s*\"([^\"]+)\"/) # config token found
2508 # --- some prefix replacements ---
2510 $var =~ s/^main\./menu.main./;
2511 $var =~ s/^setup\./menu.setup./;
2512 $var =~ s/^scores\./menu.scores./;
2513 $var =~ s/^\[player\]\./game.player_/;
2514 $var =~ s/^\[title_initial\]/title_initial_default/;
2515 $var =~ s/^\[title\]/title_default/;
2516 $var =~ s/^\[titlescreen_initial\]/titlescreen_initial_default/;
2517 $var =~ s/^\[titlescreen\]/titlescreen_default/;
2518 $var =~ s/^\[titlemessage_initial\]/titlemessage_initial_default/;
2519 $var =~ s/^\[titlemessage\]/titlemessage_default/;
2521 if ($var =~ /^titlescreen.*(\d)/ ||
2522 $var =~ /^titlemessage.*(\d)/ ||
2523 $var =~ /^game.panel.key_(\d)/ ||
2524 $var =~ /^game.panel.inventory_first_(\d)/ ||
2525 $var =~ /^game.panel.inventory_last_(\d)/ ||
2526 $var =~ /^game.panel.conveyor_belt_(\d)\./ ||
2527 $var =~ /^game.panel.element_(\d)\./ ||
2528 $var =~ /^game.panel.graphic_(\d)\./ ||
2529 $var =~ /^game.panel.ce_score_(\d)\./)
2532 my $array_pos = int($number) - 1;
2533 $var =~ s/_$number/\[$array_pos\]/;
2535 elsif ($var =~ /^game.panel.conveyor_belt_(\d)(_switch)/ ||
2536 $var =~ /^game.panel.element_(\d)(_count)/ ||
2537 $var =~ /^game.panel.ce_score_(\d)(_element)/)
2541 my $array_pos = int($number) - 1;
2542 $var =~ s/_$number$suffix/$suffix\[$array_pos\]/;
2545 # --- some suffix replacements ---
2547 $var =~ s/^(menu\.main\..*)\.chars$/$1.size/;
2548 $var =~ s/^(tape\.text\..*)\.chars$/$1.size/;
2549 $var =~ s/^(game\.panel\..*)\.chars$/$1.size/;
2550 $var =~ s/^(game\.panel\..*)\.tile_size$/$1.size/;
2551 $var =~ s/^(request\.button\..*)\.tile_size$/$1.size/;
2552 $var =~ s/\.digits$/.size/;
2553 $var =~ s/\.2nd_offset$/.offset2/;
2554 $var =~ s/\.2nd_xoffset$/.xoffset2/;
2555 $var =~ s/\.2nd_yoffset$/.yoffset2/;
2556 $var =~ s/\.element$/.id/;
2557 $var =~ s/\.draw_order$/.sort_priority/;
2559 $var =~ s/\.font_[a-z]+$/.font_alt/;
2560 $var =~ s/\.INFO\[([A-Z]+)\](.*)$/_info\[GFX_SPECIAL_ARG_INFO_$1\]$2/;
2561 $var =~ s/\.SETUP\[([A-Z0-9_]+)\](.*)$/_setup\[GFX_SPECIAL_ARG_SETUP_$1\]$2/;
2562 $var =~ s/\.([A-Z]+)$/\[GFX_SPECIAL_ARG_$1\]/;
2563 $var =~ s/\.([A-Z]+)\./\[GFX_SPECIAL_ARG_$1\]./;
2565 if ($var =~ /^(menu.(enter|leave|next)_screen)(.[a-z_]+)$/)
2567 $var = $1 . "[GFX_SPECIAL_ARG_DEFAULT]" . $3;
2570 if ($var =~ /^menu.(draw_[xy]offset|list_size)$/)
2572 $var .= "[GFX_SPECIAL_ARG_DEFAULT]";
2575 if ($var =~ /^(viewport.(window|playfield|door_[12]))(.[a-z_]+)$/)
2577 $var = $1 . "[GFX_SPECIAL_ARG_DEFAULT]" . $3;
2580 print_image_config_var_entry("\"$token\"", "&$var");
2582 if ($var =~ /^(title)_default/ ||
2583 $var =~ /^(title_initial)_default/ ||
2584 $var =~ /^(titlescreen.*)\[\d\]/ ||
2585 $var =~ /^(titlemessage.*)\[\d\]/)
2588 $var =~ s/^$prefix/${prefix}_first/;
2590 print_image_config_var_entry("\"$token\"", "&$var");
2595 print_image_config_var_entry('NULL', 'NULL');
2601 print_file_footer($filename_conf_var_c);
2604 sub print_active_states
2606 # ---------- read graphic file definitions ----------
2608 my %known_element = get_known_element_definitions();
2609 my %known_button = get_known_button_definitions();
2610 my %known_font = get_known_font_definitions();
2612 print_file_header($filename_conf_act_c, $text_act_c);
2614 print "static struct\n";
2616 print " int element;\n";
2617 print " int element_active;\n";
2619 print "element_with_active_state[] =\n";
2622 foreach my $element (sort keys %known_element)
2624 my $element_active = $element . '_ACTIVE';
2626 if (defined($known_element{$element_active}))
2628 print_active_state_entry($element, $element_active);
2632 print_active_state_entry('-1', '-1');
2638 print "static struct\n";
2640 print " int button;\n";
2641 print " int button_active;\n";
2643 print "button_with_active_state[] =\n";
2646 foreach my $button (sort keys %known_button)
2648 my $button_active = $button . '_ACTIVE';
2650 if (defined($known_button{$button_active}))
2652 print_active_state_entry($button, $button_active);
2656 print_active_state_entry('-1', '-1');
2662 print "static struct\n";
2664 print " int font_nr;\n";
2665 print " int font_nr_active;\n";
2667 print "font_with_active_state[] =\n";
2670 foreach my $font (sort keys %known_font)
2672 my $font_active = $font . '_ACTIVE';
2674 if (defined($known_font{$font_active}))
2676 print_active_state_entry($font, $font_active);
2680 print_active_state_entry('-1', '-1');
2684 print_file_footer($filename_conf_act_c);
2688 # =============================================================================
2689 # M A I N - P R O G R A M
2690 # =============================================================================
2694 my $argc = scalar(@ARGV);
2696 if ($argc == 0 || $ARGV[0] eq '-h' || $ARGV[0] eq '--help')
2698 print "Usage: $0 <file>\n\n";
2699 print "Choose <file> from the following list:\n";
2700 print "- '$filename_conf_gfx_h'\n";
2701 print "- '$filename_conf_snd_h'\n";
2702 print "- '$filename_conf_mus_h'\n";
2703 print "- '$filename_conf_chr_c'\n";
2704 print "- '$filename_conf_chr_h'\n";
2705 print "- '$filename_conf_cus_c'\n";
2706 print "- '$filename_conf_cus_h'\n";
2707 print "- '$filename_conf_grp_c'\n";
2708 print "- '$filename_conf_grp_h'\n";
2709 print "- '$filename_conf_emp_c'\n";
2710 print "- '$filename_conf_emp_h'\n";
2711 print "- '$filename_conf_e2g_c'\n";
2712 print "- '$filename_conf_esg_c'\n";
2713 print "- '$filename_conf_fnt_c'\n";
2714 print "- '$filename_conf_g2s_c'\n";
2715 print "- '$filename_conf_g2m_c'\n";
2716 print "- '$filename_conf_var_c'\n";
2717 print "- '$filename_conf_act_c'\n";
2722 if ($ARGV[0] eq $filename_conf_gfx_h)
2724 print_graphics_list();
2726 elsif ($ARGV[0] eq $filename_conf_snd_h)
2728 print_sounds_list();
2730 elsif ($ARGV[0] eq $filename_conf_mus_h)
2734 elsif ($ARGV[0] eq $filename_conf_chr_c)
2736 print_chars_graphics_list();
2738 elsif ($ARGV[0] eq $filename_conf_chr_h)
2740 print_chars_elements_list();
2742 elsif ($ARGV[0] eq $filename_conf_cus_c)
2744 print_custom_graphics_list();
2746 elsif ($ARGV[0] eq $filename_conf_cus_h)
2748 print_custom_elements_list();
2750 elsif ($ARGV[0] eq $filename_conf_grp_c)
2752 print_group_graphics_list();
2754 elsif ($ARGV[0] eq $filename_conf_grp_h)
2756 print_group_elements_list();
2758 elsif ($ARGV[0] eq $filename_conf_emp_c)
2760 print_empty_graphics_list();
2762 elsif ($ARGV[0] eq $filename_conf_emp_h)
2764 print_empty_elements_list();
2766 elsif ($ARGV[0] eq $filename_conf_e2g_c)
2768 print_element_to_graphic_list();
2770 elsif ($ARGV[0] eq $filename_conf_esg_c)
2772 print_element_to_special_graphic_list();
2774 elsif ($ARGV[0] eq $filename_conf_e2s_c)
2776 print_element_to_sound_list();
2778 elsif ($ARGV[0] eq $filename_conf_fnt_c)
2780 print_font_to_graphic_list();
2782 elsif ($ARGV[0] eq $filename_conf_g2s_c)
2784 print_gamemode_to_sound_list();
2786 elsif ($ARGV[0] eq $filename_conf_g2m_c)
2788 print_gamemode_to_music_list();
2790 elsif ($ARGV[0] eq $filename_conf_var_c)
2792 print_image_config_vars();
2794 elsif ($ARGV[0] eq $filename_conf_act_c)
2796 print_active_states();
2800 print "Unknown option '$ARGV[0]'.\n";