File indexing completed on 2024-12-01 03:48:46

0001 #!/usr/bin/perl -W
0002 
0003 use strict;
0004 
0005 my @countries;
0006 my @continents;
0007 my %files;
0008 
0009 my $inFiles = 0;
0010 my $inContinents = 0;
0011 my $inCountries = 0;
0012 my $inBorders = 0;
0013 
0014 while (<>)
0015 {
0016   chomp;
0017   if (/^\s*$/) 
0018   {
0019     next;
0020   }
0021   if (/\[files\]/)
0022   {
0023     $inFiles = 1;
0024     $inContinents = 0;
0025     $inCountries = 0;
0026     $inBorders = 0;
0027   }
0028   elsif (/\[continents\]/)
0029   {
0030     $inFiles = 0;
0031     $inContinents = 1;
0032     $inCountries = 0;
0033     $inBorders = 0;
0034   }
0035   elsif (/\[countries\]/)
0036   {
0037     $inFiles = 0;
0038     $inContinents = 0;
0039     $inCountries = 1;
0040     $inBorders = 0;
0041   }
0042   elsif (/\[borders\]/)
0043   {
0044     $inFiles = 0;
0045     $inContinents = 0;
0046     $inCountries = 0;
0047     $inBorders = 1;
0048   }
0049   elsif ($inFiles)
0050   {
0051     if (/([^\s]+)\s+([^\s]+)/)
0052     {
0053       $files{$1} = $2;
0054     }
0055   }
0056   elsif ($inContinents)
0057   {
0058     if (/([^\s]+)\s+([^\s]+)\s+([^\s]+)/)
0059     {
0060       my %continent;
0061       $continent{"name"} = $1;
0062       $continent{"bonus"} = $2;
0063       $continent{"color"} = $1;
0064       push @continents, \%continent;
0065     }
0066   }
0067   elsif ($inCountries)
0068   {
0069     if (/([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)/)
0070     {
0071       my %country;
0072       $country{"name"} = $2;
0073       push @{${$continents[$3-1]}{"countries"}}, $1;
0074       $country{"continent"} = $3;
0075       $country{"x"} = int($4 * 1.5);
0076       $country{"y"} = int($5 * 1.5);
0077       my @bords;
0078       $country{"borders"} = \@bords;
0079       $countries[$1] = \%country;
0080     }
0081   }
0082   elsif ($inBorders)
0083   {
0084     if ($_ !~ /^$/)
0085     {
0086       my @tab = split(/ /, $_);
0087       my $country = shift @tab;
0088       ${$countries[$country]}{"borders"} = \@tab;
0089     }
0090   }
0091 }
0092 
0093 for (my $i=1; $i <= $#countries; $i++)
0094 {
0095   my %country = %{$countries[$i]};
0096 #   print "$country{'name'}\n";
0097   my ($canx, $cany, $infx, $infy, $cavx, $cavy);
0098   $canx = $country{'x'}-30;
0099   $cany = $country{'y'}-25;
0100   $infx = $country{'x'}-25;
0101   $infy = $country{'y'}+5;
0102   $cavx = $country{'x'}+15;
0103   $cavy = $country{'y'}-15;
0104   print <<EOF;
0105   <country id="$i" name="$country{'name'}" >
0106     <flag-point x="$country{'x'}" y="$country{'y'}" />
0107     <central-point x="$country{'x'}" y="$country{'y'}" />
0108     <cannons-point x="$canx" y="$cany" />
0109     <cavalry-point x="$cavx" y="$cavy" />
0110     <infantry-point x="$infx" y="$infy" />
0111     <neighbours>
0112 EOF
0113 
0114   my $neighbour;
0115   foreach $neighbour ( @{ $country{"borders"} } )
0116   {
0117     print "      <neighbour id=\"$neighbour\" />\n";
0118   }
0119   
0120   print <<EOF;
0121     </neighbours>
0122   </country>
0123 EOF
0124 }
0125 
0126 
0127 for (my $i=0; $i <= $#continents; $i++)
0128 {
0129   my $id = $i+1;
0130   my %continent = %{$continents[$i]};
0131   print "  <continent id=\"$id\" name=\"$continent{name}\" bonus=\"$continent{bonus}\" >\n";
0132   foreach my $country (@{$continent{"countries"}})
0133   {
0134     print "    <continent-country id=\"$country\" />\n";
0135   }
0136 
0137   print "  </continent>\n";
0138 }