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 # dirty hack for making "ABC[DEF]" work as a "special" suffix
504 $sound =~ s/([^_])\[/$1_/;
508 $sound = "SND_$sound";
510 my $define_text = "#define $sound";
511 my $tabs = get_tabs($define_text, $max_num_tabs);
513 print "$define_text$tabs$i\n";
518 my $summary = '#define NUM_SOUND_FILES';
519 my $tabs = get_tabs($summary, $max_num_tabs);
521 print "\n$summary$tabs$i\n";
525 print_file_footer($filename_conf_snd_h);
530 my %known_prefix = get_known_music_prefix_definitions();
532 my $filename = "$src_path/conf_mus.c";
534 print_file_header($filename_conf_mus_h, $text_mus_h);
536 open(FILE, "$filename") ||
537 fail("cannot open file '$filename' for reading");
539 my $max_num_tabs = 7;
544 chomp; # cut trailing newline
546 if (!contains_music_file($_)) # skip all lines without music file
551 if (/\[not used\]/ ||
553 /wav[^\}]*$/) # skip all lines without music file
558 s/(.*)/uc($1)/eg; # convert all characters to upper case
559 s/\./_/g; # replace all '.' with '_'
566 # dirty hack for making "ABC[DEF]" work as a "special" suffix
567 $music =~ s/([^_])\[/$1_/;
571 $music = "MUS_$music";
573 my $define_text = "#define $music";
574 my $tabs = get_tabs($define_text, $max_num_tabs);
576 print "$define_text$tabs$i\n";
581 my $summary = '#define NUM_MUSIC_FILES';
582 my $tabs = get_tabs($summary, $max_num_tabs);
584 print "\n$summary$tabs$i\n";
588 print_file_footer($filename_conf_mus_h);
591 sub print_chars_elements_list
593 print_file_header($filename_conf_chr_h, $text_chr_h);
597 foreach my $char (@chars)
599 my $left = "#define EL_CHAR_$char";
601 my $tabs_left = get_tabs($left, 5);
603 my $right = sprintf("(EL_CHAR_ASCII0 + %d)", $i + 32);
605 if ($char ne $char_skip)
607 print "$left$tabs_left$right\n";
615 foreach my $char (@chars)
617 my $left = "#define EL_STEEL_CHAR_$char";
619 my $tabs_left = get_tabs($left, 5);
621 my $right = sprintf("(EL_STEEL_CHAR_ASCII0 + %d)", $i + 32);
623 if ($char ne $char_skip)
625 print "$left$tabs_left$right\n";
631 print_file_footer($filename_conf_chr_c);
634 sub print_chars_graphics_list_line
636 my ($token, $x, $y) = @_;
646 my $basename = ($token =~ /^steel_char/ ? 'RocksFontDC' : 'RocksFontEM' );
648 foreach my $ext (@extensions)
650 my $left = " \{ \"$token$ext\",";
652 my $tabs_left = get_tabs($left, 6);
654 my $right = ($ext eq '' ? $basename . '.png' :
655 $ext eq '.frames' ? '1' : '0');
661 elsif ($ext eq '.ypos')
666 $right = "\"$right\"";
668 my $tabs_right = get_tabs($right, 3);
670 print "$left$tabs_left$right$tabs_right},\n";
674 sub print_chars_graphics_list
676 print_file_header($filename_conf_chr_c, $text_chr_c);
680 foreach my $char (@chars)
682 if ($char ne $char_skip)
685 my $y = int($i / 16);
687 print_chars_graphics_list_line(lc("char_$char"), $x, $y);
690 if (lc($char) eq 'space')
692 print_chars_graphics_list_line("char_space.EDITOR", 7, 4);
695 if ($char ne $char_skip)
705 foreach my $char (@chars)
707 if ($char ne $char_skip)
710 my $y = int($i / 16);
712 print_chars_graphics_list_line(lc("steel_char_$char"), $x, $y);
715 if (lc($char) eq 'space')
717 print_chars_graphics_list_line("steel_char_space.EDITOR", 7, 4);
720 if ($char ne $char_skip)
728 print_file_footer($filename_conf_chr_c);
731 sub print_custom_elements_list
733 print_file_header($filename_conf_cus_h, $text_cus_h);
735 for (my $i = 0; $i < $num_custom_elements; $i++)
737 my $left = sprintf("#define EL_CUSTOM_%d", $i + 1);
739 my $tabs_left = get_tabs($left, 5);
741 my $right = "(EL_CUSTOM_START + $i)";
743 print "$left$tabs_left$right\n";
746 print_file_footer($filename_conf_cus_c);
749 sub print_group_elements_list
751 print_file_header($filename_conf_grp_h, $text_grp_h);
753 for (my $i = 0; $i < $num_group_elements; $i++)
755 my $left = sprintf("#define EL_GROUP_%d", $i + 1);
757 my $tabs_left = get_tabs($left, 5);
759 my $right = "(EL_GROUP_START + $i)";
761 print "$left$tabs_left$right\n";
764 print_file_footer($filename_conf_grp_c);
767 sub print_empty_elements_list
769 print_file_header($filename_conf_emp_h, $text_emp_h);
771 for (my $i = 0; $i < $num_empty_elements; $i++)
773 my $left = sprintf("#define EL_EMPTY_SPACE_%d", $i + 1);
775 my $tabs_left = get_tabs($left, 5);
777 my $right = "(EL_EMPTY_SPACE_START + $i)";
779 print "$left$tabs_left$right\n";
782 print_file_footer($filename_conf_emp_c);
785 sub print_custom_graphics_list
801 print_file_header($filename_conf_cus_c, $text_cus_c);
803 for (my $i = 0; $i < $num_custom_elements; $i++)
805 foreach my $ext (@extensions1)
807 my $left = sprintf(" \{ \"custom_%d$ext\",", $i + 1);
809 my $tabs_left = get_tabs($left, 6);
811 # my $right = ($ext eq '' ? 'RocksElements.png' :
812 my $right = ($ext eq '' ? 'RocksCE.png' :
813 $ext eq '.frames' ? '1' : '0');
818 $right = int($i % 16);
820 elsif ($ext eq '.ypos')
823 $right = int($i / 16);
826 $right = "\"$right\"";
828 my $tabs_right = get_tabs($right, 3);
830 print "$left$tabs_left$right$tabs_right},\n";
833 foreach my $ext (@extensions2)
835 my $left = sprintf(" \{ \"custom_%d.EDITOR$ext\",", $i + 1);
837 my $tabs_left = get_tabs($left, 6);
839 # my $right = ($ext eq '' ? 'RocksElements.png' : '0');
840 my $right = ($ext eq '' ? 'RocksCE.png' : '0');
845 $right = int($i % 16) + 16;
847 elsif ($ext eq '.ypos')
850 $right = int($i / 16);
853 $right = "\"$right\"";
855 my $tabs_right = get_tabs($right, 3);
857 print "$left$tabs_left$right$tabs_right},\n";
863 print_file_footer($filename_conf_cus_c);
866 sub print_group_graphics_list
882 print_file_header($filename_conf_grp_c, $text_grp_c);
884 for (my $i = 0; $i < $num_group_elements; $i++)
886 foreach my $ext (@extensions1)
888 my $left = sprintf(" \{ \"group_%d$ext\",", $i + 1);
890 my $tabs_left = get_tabs($left, 6);
892 # my $right = ($ext eq '' ? 'RocksDC.png' :
893 my $right = ($ext eq '' ? 'RocksCE.png' :
894 $ext eq '.frames' ? '1' : '0');
899 $right = int($i % 16);
901 elsif ($ext eq '.ypos')
904 $right = int($i / 16) + int($num_custom_elements / 16);
907 $right = "\"$right\"";
909 my $tabs_right = get_tabs($right, 3);
911 print "$left$tabs_left$right$tabs_right},\n";
914 foreach my $ext (@extensions2)
916 my $left = sprintf(" \{ \"group_%d.EDITOR$ext\",", $i + 1);
918 my $tabs_left = get_tabs($left, 6);
920 # my $right = ($ext eq '' ? 'RocksDC.png' : '0');
921 my $right = ($ext eq '' ? 'RocksCE.png' : '0');
926 $right = int($i % 16) + 16;
928 elsif ($ext eq '.ypos')
931 $right = int($i / 16) + int($num_custom_elements / 16);
934 $right = "\"$right\"";
936 my $tabs_right = get_tabs($right, 3);
938 print "$left$tabs_left$right$tabs_right},\n";
944 print_file_footer($filename_conf_grp_c);
947 sub print_empty_graphics_list
963 my $num_non_empty_elements = $num_custom_elements + $num_group_elements;
965 print_file_header($filename_conf_emp_c, $text_emp_c);
967 for (my $i = 0; $i < $num_empty_elements; $i++)
969 foreach my $ext (@extensions1)
971 my $left = sprintf(" \{ \"empty_space_%d$ext\",", $i + 1);
973 my $tabs_left = get_tabs($left, 6);
975 # my $right = ($ext eq '' ? 'RocksDC.png' :
976 my $right = ($ext eq '' ? 'RocksCE.png' :
977 $ext eq '.frames' ? '1' : '0');
982 $right = int($i % 16);
984 elsif ($ext eq '.ypos')
987 $right = int($i / 16) + int($num_non_empty_elements / 16);
990 $right = "\"$right\"";
992 my $tabs_right = get_tabs($right, 3);
994 print "$left$tabs_left$right$tabs_right},\n";
997 foreach my $ext (@extensions2)
999 my $left = sprintf(" \{ \"empty_space_%d.EDITOR$ext\",", $i + 1);
1001 my $tabs_left = get_tabs($left, 6);
1003 # my $right = ($ext eq '' ? 'RocksDC.png' : '0');
1004 my $right = ($ext eq '' ? 'RocksCE.png' : '0');
1006 if ($ext eq '.xpos')
1009 $right = int($i % 16) + 16;
1011 elsif ($ext eq '.ypos')
1014 $right = int($i / 16) + int($num_non_empty_elements / 16);
1017 $right = "\"$right\"";
1019 my $tabs_right = get_tabs($right, 3);
1021 print "$left$tabs_left$right$tabs_right},\n";
1027 print_file_footer($filename_conf_emp_c);
1030 sub get_known_element_definitions_ALTERNATIVE
1032 my %known_element = ();
1034 my $filename = "$src_path/main.h";
1036 open(FILE, "$filename") ||
1037 fail("cannot open file '$filename' for reading");
1041 chomp; # cut trailing newline
1043 # process line with element definition
1044 if (/^\#define (EL_[A-Z0-9_]+)\s/)
1046 $known_element{$1} = 1;
1048 # print STDERR "known_element: '$1'\n";
1054 return %known_element;
1057 sub get_known_element_definitions
1059 my %known_element = ();
1061 my $filename = "$src_path/main.c";
1063 open(FILE, "$filename") ||
1064 fail("cannot open file '$filename' for reading");
1066 my $element_name = '';
1067 my $line_is_element_name = 0;
1072 chomp; # cut trailing newline
1074 if (/ELEMENT_INFO_START/) # keyword to start parsing file
1079 elsif (/ELEMENT_INFO_END/) # keyword to stop parsing file
1090 $line_is_element_name = 1;
1092 elsif ($line_is_element_name)
1094 # process line with element name definition
1095 if (/^\s+\"(.+)\",?\s*$/)
1097 $element_name = 'EL_' . uc($1);
1099 # dirty hack for making "[default]" work as an element name
1100 $element_name =~ s/\[//;
1101 $element_name =~ s/\]//;
1103 # change '.' to '_' for elements like "dynamite.active"
1104 $element_name =~ s/\./_/g;
1106 $known_element{$element_name} = 1;
1108 # printf STDERR "::: known element '$element_name'\n";
1111 $line_is_element_name = 0;
1117 return %known_element;
1120 sub get_known_element_class_definitions
1122 my %known_element_class = ();
1124 my $filename = "$src_path/main.c";
1126 open(FILE, "$filename") ||
1127 fail("cannot open file '$filename' for reading");
1129 my $element_name = '';
1130 my $element_class = '';
1131 my $line_is_element_name = 0;
1132 my $line_is_element_class = 0;
1137 chomp; # cut trailing newline
1139 if (/ELEMENT_INFO_START/) # keyword to start parsing file
1144 elsif (/ELEMENT_INFO_END/) # keyword to stop parsing file
1155 $line_is_element_name = 1;
1157 elsif ($line_is_element_name)
1159 # process line with element name definition
1160 if (/^\s+\"(.+)\",?\s*$/)
1162 $element_name = 'EL_' . uc($1);
1164 # dirty hack for making "[default]" work as an element name
1165 $element_name =~ s/\[//;
1166 $element_name =~ s/\]//;
1168 # change '.' to '_' for elements like "dynamite.active"
1169 $element_name =~ s/\./_/g;
1172 $line_is_element_name = 0;
1173 $line_is_element_class = 1;
1175 elsif ($line_is_element_class)
1177 # process line with element class definition
1178 if (/^\s+\"(.+)\",?\s*$/)
1180 $element_class = 'EL_CLASS_' . uc($1);
1182 if (!defined($known_element_class{$element_class}))
1184 $known_element_class{$element_class} = $element_name;
1187 $known_element_class{$element_name} = $element_class;
1189 # print STDERR "known_element_class: '$element_name' => '$element_class'\n";
1192 $line_is_element_class = 0;
1198 return %known_element_class;
1201 sub get_known_action_definitions
1203 my %known_action = ();
1205 my $filename = "$src_path/main.h";
1207 open(FILE, "$filename") ||
1208 fail("cannot open file '$filename' for reading");
1212 chomp; # cut trailing newline
1214 # process line with action definition
1215 if (/^ ACTION_([A-Z0-9_]+)[, ]/)
1217 $known_action{$1} = 1;
1219 # print STDERR "known_action: '$1'\n";
1225 return %known_action;
1228 sub get_known_special_arg_definitions
1230 my %known_special_arg = ();
1232 my $filename = "$src_path/main.h";
1234 open(FILE, "$filename") ||
1235 fail("cannot open file '$filename' for reading");
1239 chomp; # cut trailing newline
1241 # process line with special arg definition
1242 if (/^ GFX_SPECIAL_ARG_([A-Z0-9_]+)[, ]/)
1244 if ($1 eq 'CRUMBLED')
1249 $known_special_arg{$1} = 1;
1251 # print STDERR "known_special_arg: '$1'\n";
1257 return %known_special_arg;
1260 sub get_known_button_definitions
1262 my %known_button = ();
1264 my $filename = "$src_path/conf_gfx.h";
1266 open(FILE, "$filename") ||
1267 fail("cannot open file '$filename' for reading");
1271 chomp; # cut trailing newline
1273 # process line with button definition
1274 if (/^\#define (IMG_MENU_BUTTON[A-Z0-9_]*)\s/)
1276 $known_button{$1} = 1;
1278 # print STDERR "known_button: '$1'\n";
1284 return %known_button;
1287 sub get_known_font_definitions
1289 my %known_font = ();
1291 my $filename = "$src_path/main.h";
1293 open(FILE, "$filename") ||
1294 fail("cannot open file '$filename' for reading");
1298 chomp; # cut trailing newline
1300 # process line with font definition
1301 if (/^ (FONT_[A-Z0-9_]+)[, ]/)
1303 $known_font{$1} = 1;
1305 # print STDERR "known_font: '$1'\n";
1314 sub get_known_sound_prefix_definitions
1316 my %known_sound_prefix = ( 'background' => 1 );
1318 return %known_sound_prefix;
1321 sub get_known_music_prefix_definitions
1323 my %known_music_prefix = ();
1325 my $filename = "$src_path/main.c";
1327 open(FILE, "$filename") ||
1328 fail("cannot open file '$filename' for reading");
1330 my $prefix_name = '';
1335 chomp; # cut trailing newline
1337 if (/MusicPrefixInfo/) # keyword to start parsing file
1342 elsif (/NULL/ && !$skip_line) # keyword to stop parsing file
1351 if (/^\s+{\s+\"(.+)\"/)
1353 my $music_prefix = $1;
1355 $known_music_prefix{$music_prefix} = 1;
1357 # printf STDERR "::: known music prefix '$music_prefix'\n";
1363 return %known_music_prefix;
1366 sub print_element_to_graphic_entry
1368 my ($element, $action, $direction, $crumbled, $graphic) = @_;
1370 my $num_tabs = 5 - int((length($element) + 4 + 1) / 8);
1371 my $tabs = "\t" x $num_tabs;
1377 $crumbled = ($crumbled == 1 ? 'TRUE' : 'FALSE');
1380 print " $element,$tabs$action, $direction, $crumbled,\n";
1381 print " $graphic\n";
1385 sub print_element_to_special_graphic_entry
1387 my ($element, $special, $graphic) = @_;
1389 my $num_tabs = 6 - int((length($element) + 4 + 1) / 8);
1390 my $tabs = "\t" x $num_tabs;
1397 print " $element,$tabs$special,\n";
1398 print " $graphic\n";
1402 sub print_font_to_graphic_entry
1404 my ($font, $special, $graphic) = @_;
1406 my $num_tabs = 6 - int((length($font) + 4 + 1) / 8);
1407 my $tabs = "\t" x $num_tabs;
1414 print " $font,$tabs$special,\n";
1415 print " $graphic\n";
1419 sub print_element_to_sound_entry
1421 my ($element, $is_class, $action, $sound) = @_;
1423 my $element_plus_is_class = "$element, $is_class";
1425 my $num_tabs = 6 - int((length($element_plus_is_class) + 4 + 1) / 8);
1426 my $tabs = "\t" x $num_tabs;
1433 print " $element_plus_is_class,$tabs$action,\n";
1438 sub print_gamemode_to_sound_entry
1440 my ($gamemode, $sound) = @_;
1443 print " $gamemode,\n";
1448 sub print_gamemode_to_music_entry
1450 my ($gamemode, $music) = @_;
1453 print " $gamemode,\n";
1458 sub print_image_config_var_entry
1460 my ($token, $var) = @_;
1468 sub print_active_state_entry
1470 my ($token, $token_active) = @_;
1474 print " $token_active\n";
1478 sub print_element_to_graphic_list
1480 my %graphic_without_element =
1482 'IMG_FLAMES_1_LEFT' => 1,
1483 'IMG_FLAMES_2_LEFT' => 1,
1484 'IMG_FLAMES_3_LEFT' => 1,
1485 'IMG_FLAMES_1_RIGHT' => 1,
1486 'IMG_FLAMES_2_RIGHT' => 1,
1487 'IMG_FLAMES_3_RIGHT' => 1,
1488 'IMG_FLAMES_1_UP' => 1,
1489 'IMG_FLAMES_2_UP' => 1,
1490 'IMG_FLAMES_3_UP' => 1,
1491 'IMG_FLAMES_1_DOWN' => 1,
1492 'IMG_FLAMES_2_DOWN' => 1,
1493 'IMG_FLAMES_3_DOWN' => 1,
1494 'IMG_TWINKLE_BLUE' => 1,
1495 'IMG_TWINKLE_WHITE' => 1,
1498 my %additional_mappings =
1500 # file elements which are mapped to runtime elements when playing
1502 # 'EL_EM_KEY_1_FILE' => 'IMG_EM_KEY_1',
1503 # 'EL_EM_KEY_2_FILE' => 'IMG_EM_KEY_2',
1504 # 'EL_EM_KEY_3_FILE' => 'IMG_EM_KEY_3',
1505 # 'EL_EM_KEY_4_FILE' => 'IMG_EM_KEY_4',
1507 # new elements which still have no graphic
1508 # 'EL_DOOR_WHITE', => 'IMG_CHAR_QUESTION',
1509 # 'EL_DOOR_WHITE_GRAY', => 'IMG_CHAR_QUESTION',
1510 # 'EL_KEY_WHITE', => 'IMG_CHAR_QUESTION',
1511 # 'EL_SIGN_RADIOACTIVITY', => 'IMG_CHAR_QUESTION',
1512 # 'EL_SIGN_WHEELCHAIR', => 'IMG_CHAR_QUESTION',
1513 # 'EL_SIGN_PARKING', => 'IMG_CHAR_QUESTION',
1514 # 'EL_SIGN_ONEWAY', => 'IMG_CHAR_QUESTION',
1515 # 'EL_SIGN_HEART', => 'IMG_CHAR_QUESTION',
1516 # 'EL_SIGN_TRIANGLE', => 'IMG_CHAR_QUESTION',
1517 # 'EL_SIGN_ROUND', => 'IMG_CHAR_QUESTION',
1518 # 'EL_SIGN_EXIT', => 'IMG_CHAR_QUESTION',
1519 # 'EL_SIGN_YINYANG', => 'IMG_CHAR_QUESTION',
1520 # 'EL_SIGN_OTHER', => 'IMG_CHAR_QUESTION',
1521 'EL_SIGN_UNUSED_1', => 'IMG_CHAR_QUESTION',
1522 'EL_SIGN_UNUSED_2', => 'IMG_CHAR_QUESTION',
1523 'EL_DX_UNKNOWN_15', => 'IMG_CHAR_QUESTION',
1524 'EL_DX_UNKNOWN_42', => 'IMG_CHAR_QUESTION',
1526 # file elements with direction which is not defined
1527 'EL_BD_BUTTERFLY_LEFT' => 'IMG_BD_BUTTERFLY',
1528 'EL_BD_BUTTERFLY_RIGHT' => 'IMG_BD_BUTTERFLY',
1529 'EL_BD_BUTTERFLY_UP' => 'IMG_BD_BUTTERFLY',
1530 'EL_BD_BUTTERFLY_DOWN' => 'IMG_BD_BUTTERFLY',
1531 'EL_BD_FIREFLY_LEFT' => 'IMG_BD_FIREFLY',
1532 'EL_BD_FIREFLY_RIGHT' => 'IMG_BD_FIREFLY',
1533 'EL_BD_FIREFLY_UP' => 'IMG_BD_FIREFLY',
1534 'EL_BD_FIREFLY_DOWN' => 'IMG_BD_FIREFLY',
1537 my @unknown_graphics = ();
1538 my %known_element = get_known_element_definitions();
1539 my %known_action = get_known_action_definitions();
1540 my %known_special_arg = get_known_special_arg_definitions();
1541 my %known_direction =
1553 # ---------- read graphic file definitions ----------
1555 my $filename = "$src_path/conf_gfx.c";
1557 print_file_header($filename_conf_e2g_c, $text_e2g_c);
1559 open(FILE, "$filename") ||
1560 fail("cannot open file '$filename' for reading");
1562 print "static struct\n";
1564 print " int element;\n";
1565 print " int action;\n";
1566 print " int direction;\n";
1567 print " boolean crumbled;\n";
1569 print " int graphic;\n";
1571 print "element_to_graphic[] =\n";
1576 chomp; # cut trailing newline
1578 if (/NO_MORE_ELEMENT_IMAGES/) # keyword to stop parsing file
1583 if (!contains_image_file($_)) # skip all lines without image file
1588 s/^ \{ \"//; # cut all leading ...
1589 s/\",.*$//; # ... and trailing garbage
1591 s/\[(\d+)\]/_$1/; # convert "[1]" to "_1" etc.
1593 s/\[//; # dirty hack for making "[default]" ...
1594 s/\]//; # ... work as an element name
1598 if ($token =~ /\.([^\.]+)$/ && defined($known_special_arg{$1}))
1600 next; # skip all special definitions
1603 $token = uc($token); # convert all characters to upper case
1605 my $gfx_action_default = '-1';
1606 my $gfx_action = $gfx_action_default;
1608 my $gfx_direction_default = '-1';
1609 my $gfx_direction = $gfx_direction_default;
1611 my $gfx_crumbled = '0';
1613 my $object = $token;
1618 if ($object =~ /^(.*)\.([A-Z0-9]+)$/ && $2 eq 'CRUMBLED')
1623 $gfx_crumbled = '1';
1626 if ($object =~ /^(.*)\.([A-Z0-9]+)$/ && defined($known_direction{$2}))
1631 $gfx_direction = "MV_BIT_$direction";
1632 $gfx_direction_default = $gfx_direction;
1635 if ($object =~ /^(.*)\.([A-Z0-9_]+)$/ && defined($known_action{$2}))
1640 $gfx_action = "ACTION_$action";
1641 $gfx_action_default = $gfx_action;
1645 $object =~ s/\./_/g; # needed for "invisible_sand.active.digging"
1647 # print STDERR "'$token' => '$object', '$action', '$direction'\n";
1649 my $full_element = "EL_$token";
1650 my $base_element = "EL_$object";
1652 my $element = $base_element;
1653 my $graphic = "IMG_$token";
1655 my $element_without_crumbled = $full_element;
1656 $element_without_crumbled =~ s/_$crumbled$//;
1658 my $element_without_direction = $element_without_crumbled;
1659 $element_without_direction =~ s/_$direction$//;
1661 my $element_without_action = $element_without_direction;
1662 $element_without_action =~ s/_$action$//;
1664 if (defined($known_element{$full_element}))
1666 $element = $full_element;
1668 $gfx_action_default = '-1';
1669 $gfx_direction_default = '-1';
1672 if ($element_without_action eq $element || $action eq '')
1674 $element_without_action = '';
1677 if ($element_without_direction eq $element || $direction eq '')
1679 $element_without_direction = '';
1682 if ($element_without_crumbled eq $element || $crumbled eq '')
1684 $element_without_crumbled = '';
1687 if (defined($graphic_without_element{$graphic}))
1692 if (!defined($known_element{$element}))
1694 # print STDERR "----- ERROR: unknown element '$element' -----\n";
1696 push @unknown_graphics, $graphic;
1701 if (defined($known_element{$element}))
1703 print_element_to_graphic_entry($element,
1704 $gfx_action_default,
1705 $gfx_direction_default,
1710 if (defined($known_element{$element_without_action}))
1712 print_element_to_graphic_entry($element_without_action,
1719 if (defined($known_element{$element_without_direction}))
1721 print_element_to_graphic_entry($element_without_direction,
1728 if (defined($known_element{$element_without_crumbled}))
1730 print_element_to_graphic_entry($element_without_crumbled,
1738 # dump list of additional elements
1739 foreach my $element (sort keys %additional_mappings)
1741 print_element_to_graphic_entry($element, '-1', '-1', '-1',
1742 $additional_mappings{$element});
1745 # dump list of character elements
1746 foreach my $char (@chars)
1748 my $element = "EL_CHAR_$char";
1749 my $graphic = "IMG_CHAR_$char";
1751 if ($char ne $char_skip)
1753 print_element_to_graphic_entry($element, '-1', '-1', '-1',$graphic);
1756 foreach my $char (@chars)
1758 my $element = "EL_STEEL_CHAR_$char";
1759 my $graphic = "IMG_STEEL_CHAR_$char";
1761 if ($char ne $char_skip)
1763 print_element_to_graphic_entry($element, '-1', '-1', '-1',$graphic);
1767 # dump list of custom elements
1768 for (my $i = 0; $i < $num_custom_elements; $i++)
1770 my $element = sprintf("EL_CUSTOM_%d", $i + 1);
1771 my $graphic = sprintf("IMG_CUSTOM_%d", $i + 1);
1773 print_element_to_graphic_entry($element, '-1', '-1', '-1', $graphic);
1776 # dump list of group elements
1777 for (my $i = 0; $i < $num_group_elements; $i++)
1779 my $element = sprintf("EL_GROUP_%d", $i + 1);
1780 my $graphic = sprintf("IMG_GROUP_%d", $i + 1);
1782 print_element_to_graphic_entry($element, '-1', '-1', '-1', $graphic);
1785 # dump list of empty elements
1786 for (my $i = 0; $i < $num_empty_elements; $i++)
1788 my $element = sprintf("EL_EMPTY_SPACE_%d", $i + 1);
1789 my $graphic = sprintf("IMG_EMPTY_SPACE_%d", $i + 1);
1791 print_element_to_graphic_entry($element, '-1', '-1', '-1', $graphic);
1794 print_element_to_graphic_entry('-1', '-1', '-1', '-1', '-1');
1800 if (scalar(@unknown_graphics) > 0)
1802 print STDERR "-" x 79 . "\n";
1803 print STDERR "The following graphics cannot be associated with any element:\n";
1805 foreach my $graphic (@unknown_graphics)
1807 print STDERR "- $graphic\n";
1810 print STDERR "-" x 79 . "\n";
1813 print_file_footer($filename_conf_e2g_c);
1816 sub print_element_to_special_graphic_list
1818 my %graphic_without_element =
1820 'IMG_GLOBAL_DOOR' => 1,
1823 my %additional_mappings =
1825 # old elements which are mapped to other elements when playing
1826 #'EL_BUG' => 'IMG_BUG_RIGHT',
1827 #'EL_SPACESHIP' => 'IMG_SPACESHIP_RIGHT',
1828 #'EL_PACMAN' => 'IMG_PACMAN_RIGHT',
1831 my @elements_with_editor_graphic =
1837 my @unknown_graphics = ();
1838 my %known_element = get_known_element_definitions();
1839 my %known_special_arg = get_known_special_arg_definitions();
1841 # ---------- read graphic file definitions ----------
1843 my $filename = "$src_path/conf_gfx.c";
1845 print_file_header($filename_conf_esg_c, $text_esg_c);
1847 open(FILE, "$filename") ||
1848 fail("cannot open file '$filename' for reading");
1850 print "static struct\n";
1852 print " int element;\n";
1853 print " int special;\n";
1855 print " int graphic;\n";
1857 print "element_to_special_graphic[] =\n";
1862 chomp; # cut trailing newline
1864 if (/NO_MORE_ELEMENT_IMAGES/) # keyword to stop parsing file
1869 if (!contains_image_file($_)) # skip all lines without image file
1874 s/^ \{ \"//; # cut all leading ...
1875 s/\",.*$//; # ... and trailing garbage
1881 if ($token =~ /^font\./) # skip all font definitions
1886 if ($token =~ /^background\./) # skip all background image definitions
1891 if ($token =~ /^(.*)\.([^\.]+)$/ &&
1892 defined($known_special_arg{$2}))
1895 $special = "GFX_SPECIAL_ARG_" . $2;
1899 next; # skip all default definitions
1902 $token =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
1903 $object =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
1906 $object =~ s/\./_/g;
1908 # print STDERR "'$token' => '$object'\n";
1910 my $element = "EL_$object";
1911 my $graphic = "IMG_$token";
1913 if (defined($graphic_without_element{$graphic}))
1918 if (!defined($known_element{$element}))
1920 # print STDERR "----- ERROR: unknown element '$element' -----\n";
1922 push @unknown_graphics, $graphic;
1927 print_element_to_special_graphic_entry($element,
1932 # dump list of additional elements
1933 foreach my $element (sort keys %additional_mappings)
1935 print_element_to_special_graphic_entry($element,
1936 'GFX_SPECIAL_ARG_EDITOR',
1937 $additional_mappings{$element});
1938 print_element_to_special_graphic_entry($element,
1939 'GFX_SPECIAL_ARG_PREVIEW',
1940 $additional_mappings{$element});
1943 # dump list of custom element editor graphics
1944 for (my $i = 0; $i < $num_custom_elements; $i++)
1946 my $element = sprintf("EL_CUSTOM_%d", $i + 1);
1947 my $graphic = sprintf("IMG_CUSTOM_%d_EDITOR", $i + 1);
1949 print_element_to_special_graphic_entry($element,
1950 'GFX_SPECIAL_ARG_EDITOR',
1954 # dump list of group element editor graphics
1955 for (my $i = 0; $i < $num_group_elements; $i++)
1957 my $element = sprintf("EL_GROUP_%d", $i + 1);
1958 my $graphic = sprintf("IMG_GROUP_%d_EDITOR", $i + 1);
1960 print_element_to_special_graphic_entry($element,
1961 'GFX_SPECIAL_ARG_EDITOR',
1965 # dump list of empty element editor graphics
1966 for (my $i = 0; $i < $num_empty_elements; $i++)
1968 my $element = sprintf("EL_EMPTY_SPACE_%d", $i + 1);
1969 my $graphic = sprintf("IMG_EMPTY_SPACE_%d_EDITOR", $i + 1);
1971 print_element_to_special_graphic_entry($element,
1972 'GFX_SPECIAL_ARG_EDITOR',
1976 # dump other special editor graphics
1977 foreach my $token (@elements_with_editor_graphic)
1979 my $element = 'EL_' . uc($token);
1980 my $graphic = 'IMG_' . uc($token) . '_EDITOR';
1982 print_element_to_special_graphic_entry($element,
1983 'GFX_SPECIAL_ARG_EDITOR',
1987 print_element_to_special_graphic_entry('-1', '-1', '-1');
1993 if (scalar(@unknown_graphics) > 0)
1995 print STDERR "-" x 79 . "\n";
1996 print STDERR "The following graphics cannot be associated with any element:\n";
1998 foreach my $graphic (@unknown_graphics)
2000 print STDERR "- $graphic\n";
2003 print STDERR "-" x 79 . "\n";
2006 print_file_footer($filename_conf_esg_c);
2009 sub print_element_to_sound_list
2011 my %sound_without_action =
2013 'SND_AMOEBA_TURNING_TO_GEM' => 1,
2014 'SND_AMOEBA_TURNING_TO_ROCK' => 1,
2015 'SND_BD_AMOEBA_TURNING_TO_GEM' => 1,
2016 'SND_BD_AMOEBA_TURNING_TO_ROCK' => 1,
2018 # no special case anymore after adding action ".splashing"
2019 # 'SND_ACID_SPLASHING' => 1,
2022 my @unknown_sounds = ();
2023 my %known_element = get_known_element_definitions();
2024 my %known_element_class = get_known_element_class_definitions();
2025 my %known_action = get_known_action_definitions();
2027 # ---------- read sound file definitions ----------
2029 my $filename = "$src_path/conf_snd.c";
2031 print_file_header($filename_conf_e2s_c, $text_e2s_c);
2033 open(FILE, "$filename") ||
2034 fail("cannot open file '$filename' for reading");
2036 print "static struct\n";
2038 print " int element;\n";
2039 print " boolean is_class;\n";
2040 print " int action;\n";
2042 print " int sound;\n";
2044 print "element_to_sound[] =\n";
2049 chomp; # cut trailing newline
2051 if (/NO_MORE_ELEMENT_SOUNDS/) # keyword to stop parsing file
2056 if (!contains_sound_file($_)) # skip all lines without sound file
2061 s/^ \{ \"//; # cut all leading ...
2062 s/\",.*$//; # ... and trailing garbage
2066 $token = uc($token); # convert all characters to upper case
2068 my $snd_action_default = '-1';
2069 my $snd_action = $snd_action_default;
2071 my $object = $token;
2074 if ($object =~ /^(.*)\.([A-Z0-9_]+)$/ && defined($known_action{$2}))
2079 $snd_action = "ACTION_$action";
2080 $snd_action_default = $snd_action;
2084 $object =~ s/\./_/g; # needed for "invisible_sand.active.digging"
2086 if ($object =~ /^\[(.+)\]$/)
2088 $object = 'CLASS_' . $1;
2091 # print STDERR "'$token' => '$object', '$action'\n";
2093 my $full_element = "EL_$token";
2094 my $base_element = "EL_$object";
2096 my $element = $base_element;
2099 if ($sound =~ /^\[.+\]/)
2101 $sound =~ s/\[//; # element class sound; begin ...
2102 $sound =~ s/\]//; # ... and end of definition token
2103 $sound =~ s/^/CLASS_/; # add class identifier
2106 $sound = "SND_$sound";
2108 my $element_without_action = $full_element;
2109 $element_without_action =~ s/_$action$//;
2111 my $element_class_without_action = $full_element;
2112 $element_without_action =~ s/_$action$//;
2114 if (defined($known_element_class{$full_element}))
2116 $element = $full_element;
2118 $snd_action_default = '-1';
2121 if ($element_without_action eq $element || $action eq '')
2123 $element_without_action = '';
2126 if (defined($sound_without_action{$sound}))
2131 if (!defined($known_element{$element}) &&
2132 !defined($known_element_class{$element}))
2134 # print STDERR "----- ERROR: unknown element '$element' -----\n";
2136 push @unknown_sounds, $sound;
2141 if (!($element =~ /_CLASS_/) &&
2142 defined($known_element{$element}))
2144 print_element_to_sound_entry($element, "FALSE",
2145 $snd_action_default,
2149 if (!($element =~ /_CLASS_/) &&
2150 defined($known_element{$element_without_action}))
2152 print_element_to_sound_entry($element_without_action, "FALSE",
2157 if ($element =~ /_CLASS_/ &&
2158 defined($known_element_class{$element}))
2160 my $class_element = $known_element_class{$element};
2162 print_element_to_sound_entry($class_element, "TRUE",
2163 $snd_action_default,
2167 if ($element =~ /_CLASS_/ &&
2168 defined($known_element_class{$element_without_action}))
2170 my $class_element = $known_element_class{$element_without_action};
2172 print_element_to_sound_entry($class_element, "TRUE",
2178 print_element_to_sound_entry('-1', '-1', '-1', '-1');
2184 if (scalar(@unknown_sounds) > 0)
2186 print STDERR "-" x 79 . "\n";
2187 print STDERR "The following sounds cannot be associated with any element or element class:\n";
2189 foreach my $sound (@unknown_sounds)
2191 print STDERR "- $sound\n";
2194 print STDERR "-" x 79 . "\n";
2197 print_file_footer($filename_conf_e2s_c);
2200 sub print_font_to_graphic_list
2202 my @unknown_graphics = ();
2203 my %known_font = get_known_font_definitions();
2204 my %known_special_arg = get_known_special_arg_definitions();
2206 # ---------- read graphic file definitions ----------
2208 my $filename = "$src_path/conf_gfx.c";
2210 print_file_header($filename_conf_fnt_c, $text_fnt_c);
2212 open(FILE, "$filename") ||
2213 fail("cannot open file '$filename' for reading");
2215 print "static struct\n";
2217 print " int font_nr;\n";
2218 print " int special;\n";
2220 print " int graphic;\n";
2222 print "font_to_graphic[] =\n";
2227 chomp; # cut trailing newline
2229 if (!contains_image_file($_)) # skip all lines without image file
2234 s/^ \{ \"//; # cut all leading ...
2235 s/\",.*$//; # ... and trailing garbage
2242 if ($token =~ /^(font\..*)$/)
2247 if ($token =~ /^(.*)\.([^\.]+)$/ &&
2248 defined($known_special_arg{$2}))
2251 $special = "GFX_SPECIAL_ARG_" . $2;
2256 next; # skip all non-font definitions
2259 $token =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
2260 $font =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
2265 # print STDERR "'$token' => '$font'\n";
2267 $graphic = "IMG_$token";
2269 if (!defined($known_font{$font}))
2271 # print STDERR "----- ERROR: unknown font '$font' -----\n";
2273 push @unknown_graphics, $graphic;
2278 print_font_to_graphic_entry($font,
2283 print_font_to_graphic_entry('-1', '-1', '-1');
2289 if (scalar(@unknown_graphics) > 0)
2291 print STDERR "-" x 79 . "\n";
2292 print STDERR "The following graphics cannot be associated with any font:\n";
2294 foreach my $graphic (@unknown_graphics)
2296 print STDERR "- $graphic\n";
2299 print STDERR "-" x 79 . "\n";
2302 print_file_footer($filename_conf_fnt_c);
2305 sub print_gamemode_to_sound_list
2307 my %known_prefix = get_known_sound_prefix_definitions();
2308 my %known_special_arg = get_known_special_arg_definitions();
2310 # ---------- read music file definitions ----------
2312 my $filename = "$src_path/conf_snd.c";
2314 print_file_header($filename_conf_g2s_c, $text_g2s_c);
2316 open(FILE, "$filename") ||
2317 fail("cannot open file '$filename' for reading");
2319 print "static struct\n";
2321 print " int gamemode;\n";
2323 print " int sound;\n";
2325 print "gamemode_to_sound[] =\n";
2330 chomp; # cut trailing newline
2332 if (!contains_sound_file($_)) # skip all lines without sound file
2342 s/^ \{ \"//; # cut all leading ...
2343 s/\",.*$//; # ... and trailing garbage
2347 # my $level = -1; # ???
2349 if (defined($known_prefix{$token}))
2351 # no special arg defined
2353 elsif ($token =~ /^(.*)\.([^\.]+)$/ &&
2354 defined($known_prefix{$1}) &&
2355 defined($known_special_arg{$2}))
2357 $gamemode = "GFX_SPECIAL_ARG_" . $2;
2364 # if ($token =~ /^(.*)\./ &&
2365 # !defined($known_prefix{$1}))
2370 # if ($token =~ /^(.*)\.([^\.]+)$/ &&
2371 # defined($known_special_arg{$2}))
2373 # $gamemode = "GFX_SPECIAL_ARG_" . $2;
2376 $token =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
2379 my $sound = "SND_$token";
2381 # print STDERR "'$token' => '$sound'\n";
2383 print_gamemode_to_sound_entry($gamemode, $sound);
2386 print_gamemode_to_sound_entry('-1', '-1');
2392 print_file_footer($filename_conf_g2s_c);
2395 sub print_gamemode_to_music_list
2397 my %known_prefix = get_known_music_prefix_definitions();
2398 my %known_special_arg = get_known_special_arg_definitions();
2400 # ---------- read music file definitions ----------
2402 my $filename = "$src_path/conf_mus.c";
2404 print_file_header($filename_conf_g2m_c, $text_g2m_c);
2406 open(FILE, "$filename") ||
2407 fail("cannot open file '$filename' for reading");
2409 print "static struct\n";
2411 print " int gamemode;\n";
2413 print " int music;\n";
2415 print "gamemode_to_music[] =\n";
2420 chomp; # cut trailing newline
2422 if (!contains_music_file($_)) # skip all lines without music file
2427 s/^ \{ \"//; # cut all leading ...
2428 s/\",.*$//; # ... and trailing garbage
2433 if (defined($known_prefix{$token}))
2435 # no special arg defined
2437 elsif ($token =~ /^(.*)\.([^\.]+)$/ &&
2438 defined($known_prefix{$1}) &&
2439 defined($known_special_arg{$2}))
2441 $gamemode = "GFX_SPECIAL_ARG_" . $2;
2448 # my $prefix = $token;
2449 # $prefix =~ s/\..*$//;
2451 ## if ($token =~ /^(.*)\./ &&
2452 ## !defined($known_prefix{$1}))
2453 # if (!defined($known_prefix{$prefix}))
2458 # if ($token =~ /^(.*)\.([^\.]+)$/ &&
2459 # defined($known_special_arg{$2}))
2461 # $gamemode = "GFX_SPECIAL_ARG_" . $2;
2464 $token =~ s/(.*)/uc($1)/eg; # convert all characters to upper case
2467 my $music = "MUS_$token";
2469 # print STDERR "'$token' => '$music'\n";
2471 print_gamemode_to_music_entry($gamemode, $music);
2474 print_gamemode_to_music_entry('-1', '-1');
2480 print_file_footer($filename_conf_g2m_c);
2483 sub print_image_config_vars
2485 # ---------- read graphic file definitions ----------
2487 my $filename = "$src_path/conf_gfx.c";
2489 print_file_header($filename_conf_var_c, $text_var_c);
2491 open(FILE, "$filename") ||
2492 fail("cannot open file '$filename' for reading");
2494 print "struct TokenIntPtrInfo image_config_vars[] =\n";
2497 my $start_parsing = 0;
2501 chomp; # cut trailing newline
2503 if (/CONFIG_VARS_START/) # keyword to start parsing file
2508 if (!$start_parsing)
2513 if (/^\s*\{\s*\"([^\"]+)\"/) # config token found
2518 # --- some prefix replacements ---
2520 $var =~ s/^main\./menu.main./;
2521 $var =~ s/^setup\./menu.setup./;
2522 $var =~ s/^scores\./menu.scores./;
2523 $var =~ s/^\[player\]\./game.player_/;
2524 $var =~ s/^\[title_initial\]/title_initial_default/;
2525 $var =~ s/^\[title\]/title_default/;
2526 $var =~ s/^\[titlescreen_initial\]/titlescreen_initial_default/;
2527 $var =~ s/^\[titlescreen\]/titlescreen_default/;
2528 $var =~ s/^\[titlemessage_initial\]/titlemessage_initial_default/;
2529 $var =~ s/^\[titlemessage\]/titlemessage_default/;
2531 if ($var =~ /^titlescreen.*(\d)/ ||
2532 $var =~ /^titlemessage.*(\d)/ ||
2533 $var =~ /^game.panel.key_(\d)/ ||
2534 $var =~ /^game.panel.inventory_first_(\d)/ ||
2535 $var =~ /^game.panel.inventory_last_(\d)/ ||
2536 $var =~ /^game.panel.conveyor_belt_(\d)\./ ||
2537 $var =~ /^game.panel.element_(\d)\./ ||
2538 $var =~ /^game.panel.graphic_(\d)\./ ||
2539 $var =~ /^game.panel.ce_score_(\d)\./)
2542 my $array_pos = int($number) - 1;
2543 $var =~ s/_$number/\[$array_pos\]/;
2545 elsif ($var =~ /^game.panel.conveyor_belt_(\d)(_switch)/ ||
2546 $var =~ /^game.panel.element_(\d)(_count)/ ||
2547 $var =~ /^game.panel.ce_score_(\d)(_element)/)
2551 my $array_pos = int($number) - 1;
2552 $var =~ s/_$number$suffix/$suffix\[$array_pos\]/;
2555 # --- some suffix replacements ---
2557 $var =~ s/^(menu\.main\..*)\.chars$/$1.size/;
2558 $var =~ s/^(tape\.text\..*)\.chars$/$1.size/;
2559 $var =~ s/^(game\.panel\..*)\.chars$/$1.size/;
2560 $var =~ s/^(game\.panel\..*)\.tile_size$/$1.size/;
2561 $var =~ s/^(request\.button\..*)\.tile_size$/$1.size/;
2562 $var =~ s/\.digits$/.size/;
2563 $var =~ s/\.2nd_offset$/.offset2/;
2564 $var =~ s/\.2nd_xoffset$/.xoffset2/;
2565 $var =~ s/\.2nd_yoffset$/.yoffset2/;
2566 $var =~ s/\.element$/.id/;
2567 $var =~ s/\.draw_order$/.sort_priority/;
2569 $var =~ s/\.font_[a-z]+$/.font_alt/;
2570 $var =~ s/\.INFO\[([A-Z]+)\](.*)$/_info\[GFX_SPECIAL_ARG_INFO_$1\]$2/;
2571 $var =~ s/\.SETUP\[([A-Z0-9_]+)\](.*)$/_setup\[GFX_SPECIAL_ARG_SETUP_$1\]$2/;
2572 $var =~ s/\.([A-Z]+)$/\[GFX_SPECIAL_ARG_$1\]/;
2573 $var =~ s/\.([A-Z]+)\./\[GFX_SPECIAL_ARG_$1\]./;
2575 if ($var =~ /^(menu.(enter|leave|next)_screen)(.[a-z_]+)$/)
2577 $var = $1 . "[GFX_SPECIAL_ARG_DEFAULT]" . $3;
2580 if ($var =~ /^menu.(draw_[xy]offset|list_size)$/)
2582 $var .= "[GFX_SPECIAL_ARG_DEFAULT]";
2585 if ($var =~ /^(viewport.(window|playfield|door_[12]))(.[a-z_]+)$/)
2587 $var = $1 . "[GFX_SPECIAL_ARG_DEFAULT]" . $3;
2590 print_image_config_var_entry("\"$token\"", "&$var");
2592 if ($var =~ /^(title)_default/ ||
2593 $var =~ /^(title_initial)_default/ ||
2594 $var =~ /^(titlescreen.*)\[\d\]/ ||
2595 $var =~ /^(titlemessage.*)\[\d\]/)
2598 $var =~ s/^$prefix/${prefix}_first/;
2600 print_image_config_var_entry("\"$token\"", "&$var");
2605 print_image_config_var_entry('NULL', 'NULL');
2611 print_file_footer($filename_conf_var_c);
2614 sub print_active_states
2616 # ---------- read graphic file definitions ----------
2618 my %known_element = get_known_element_definitions();
2619 my %known_button = get_known_button_definitions();
2620 my %known_font = get_known_font_definitions();
2622 print_file_header($filename_conf_act_c, $text_act_c);
2624 print "static struct\n";
2626 print " int element;\n";
2627 print " int element_active;\n";
2629 print "element_with_active_state[] =\n";
2632 foreach my $element (sort keys %known_element)
2634 my $element_active = $element . '_ACTIVE';
2636 if (defined($known_element{$element_active}))
2638 print_active_state_entry($element, $element_active);
2642 print_active_state_entry('-1', '-1');
2648 print "static struct\n";
2650 print " int button;\n";
2651 print " int button_active;\n";
2653 print "button_with_active_state[] =\n";
2656 foreach my $button (sort keys %known_button)
2658 my $button_active = $button . '_ACTIVE';
2660 if (defined($known_button{$button_active}))
2662 print_active_state_entry($button, $button_active);
2666 print_active_state_entry('-1', '-1');
2672 print "static struct\n";
2674 print " int font_nr;\n";
2675 print " int font_nr_active;\n";
2677 print "font_with_active_state[] =\n";
2680 foreach my $font (sort keys %known_font)
2682 my $font_active = $font . '_ACTIVE';
2684 if (defined($known_font{$font_active}))
2686 print_active_state_entry($font, $font_active);
2690 print_active_state_entry('-1', '-1');
2694 print_file_footer($filename_conf_act_c);
2698 # =============================================================================
2699 # M A I N - P R O G R A M
2700 # =============================================================================
2704 my $argc = scalar(@ARGV);
2706 if ($argc == 0 || $ARGV[0] eq '-h' || $ARGV[0] eq '--help')
2708 print "Usage: $0 <file>\n\n";
2709 print "Choose <file> from the following list:\n";
2710 print "- '$filename_conf_gfx_h'\n";
2711 print "- '$filename_conf_snd_h'\n";
2712 print "- '$filename_conf_mus_h'\n";
2713 print "- '$filename_conf_chr_c'\n";
2714 print "- '$filename_conf_chr_h'\n";
2715 print "- '$filename_conf_cus_c'\n";
2716 print "- '$filename_conf_cus_h'\n";
2717 print "- '$filename_conf_grp_c'\n";
2718 print "- '$filename_conf_grp_h'\n";
2719 print "- '$filename_conf_emp_c'\n";
2720 print "- '$filename_conf_emp_h'\n";
2721 print "- '$filename_conf_e2g_c'\n";
2722 print "- '$filename_conf_esg_c'\n";
2723 print "- '$filename_conf_fnt_c'\n";
2724 print "- '$filename_conf_g2s_c'\n";
2725 print "- '$filename_conf_g2m_c'\n";
2726 print "- '$filename_conf_var_c'\n";
2727 print "- '$filename_conf_act_c'\n";
2732 if ($ARGV[0] eq $filename_conf_gfx_h)
2734 print_graphics_list();
2736 elsif ($ARGV[0] eq $filename_conf_snd_h)
2738 print_sounds_list();
2740 elsif ($ARGV[0] eq $filename_conf_mus_h)
2744 elsif ($ARGV[0] eq $filename_conf_chr_c)
2746 print_chars_graphics_list();
2748 elsif ($ARGV[0] eq $filename_conf_chr_h)
2750 print_chars_elements_list();
2752 elsif ($ARGV[0] eq $filename_conf_cus_c)
2754 print_custom_graphics_list();
2756 elsif ($ARGV[0] eq $filename_conf_cus_h)
2758 print_custom_elements_list();
2760 elsif ($ARGV[0] eq $filename_conf_grp_c)
2762 print_group_graphics_list();
2764 elsif ($ARGV[0] eq $filename_conf_grp_h)
2766 print_group_elements_list();
2768 elsif ($ARGV[0] eq $filename_conf_emp_c)
2770 print_empty_graphics_list();
2772 elsif ($ARGV[0] eq $filename_conf_emp_h)
2774 print_empty_elements_list();
2776 elsif ($ARGV[0] eq $filename_conf_e2g_c)
2778 print_element_to_graphic_list();
2780 elsif ($ARGV[0] eq $filename_conf_esg_c)
2782 print_element_to_special_graphic_list();
2784 elsif ($ARGV[0] eq $filename_conf_e2s_c)
2786 print_element_to_sound_list();
2788 elsif ($ARGV[0] eq $filename_conf_fnt_c)
2790 print_font_to_graphic_list();
2792 elsif ($ARGV[0] eq $filename_conf_g2s_c)
2794 print_gamemode_to_sound_list();
2796 elsif ($ARGV[0] eq $filename_conf_g2m_c)
2798 print_gamemode_to_music_list();
2800 elsif ($ARGV[0] eq $filename_conf_var_c)
2802 print_image_config_vars();
2804 elsif ($ARGV[0] eq $filename_conf_act_c)
2806 print_active_states();
2810 print "Unknown option '$ARGV[0]'.\n";