1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#!/usr/local/bin/perl
#eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
# if $running_under_some_shell;
require "getopts.pl";
&Getopts('o:');
#die "Usage: scn2g [-o outfile] [infile]\n" if @ARGV > 1;
#
# Get stdout set up and the default module name
#
if ( $opt_o ) {
#
# If they give us an output file name, open it
# and use it as the module name (minus path and extension).
#
open(STDOUT, ">$opt_o") || die "Couldn't open $opt_o for output: $!\n";
($m = $opt_o) =~ s#(.*/)?(.*)\.g$#$2#;
} elsif (@ARGV) {
#
# If they give us an input file,
# use it as the output file name (minus path and extension plus .g)
# and use it as the module name (minus path and extension).
#
($m = $ARGV[0]) =~ s#(.*/)?(.*)\.scn$#$2#;
unless ( -e "$m.g" ) {
open(STDOUT, ">$m.g") || die "Couldn't open $m.g for output: $!\n";
}
} else {
#
# OK, we got nothin', output is stdout and module name is junk.
#
$m = 'xxx';
}
$\ = "\n"; # terminate every print with a newline.
@types = ( 'pt_value', 'units', 'resources', 'unit_at' );
LINE:
while (<>) {
# strip trailing whitespace (and the newline).
s/\s*$//;
if (/^Xconq (\d+) [\+-]* ([^;]*)(;?)$/) {
local($n) = $1;
print qq/(game-module "$m"\n (blurb "$2")/;
if ( $3 ) {
print " (game-module (notes (";
COMMENT:
while (<>) {
last COMMENT if /^\.$/;
chop;
print;
}
print " ))";
}
while ( $n-- ) {
chop($f = <>);
print(qq/ (base-module "$1")/), next if $f =~ /^(\S*)\.per$/;
push(@incfiles, $f);
}
print ")\n";
foreach $f ( @incfiles ) {
print qq/(include "$f")/;
}
next LINE;
} elsif (/^Globals/) {
split;
&read_globs(@_[1..5]);
next LINE;
} elsif (/^Sides/) {
split;
&read_sides(@_[1], @_[2]);
next LINE;
} elsif (/^Units/) {
split;
($num, $detail) = @_[1,2];
&read_unit($detail) while ($num--);
next LINE;
}
s/^/;/;
print;
}
sub read_globs {
local($first_turn, $last_turn, $set_prod, $leave, $conds) = @_;
local($n);
print "; fixed production" if $set_prod;
print "; leave from edges" if $leave;
print "(set turn $first_turn)" if $first_turn;
print "(set last-turn $last_turn)";
print "";
for ($n = 1; $n <= $conds; ++$n) {
chop($_ = <>);
local($w, $t, $st, $end, $s) = split;
$w = ($w = 0)? 'lose' : 'win';
$s++;
print qq/(scorekeeper |cond$n| (title "$types[$t]")/;
print " (applies-to $s)" unless ($s == -1);
print "; (trigger if turn > $st and turn < $end)";
chop($_ = <>);
print "; (do if ($types[$t] $_) $w)";
print ")";
}
}
sub read_sides {
local($num, $detail) = @_;
local($n);
print "";
for ($n = 1; $n <= $num; ++$n) {
$_ = <>;
chop($_);
push(@sides, $_);
print qq/(side $n (name "$_")/;
if ( $detail > 1 ) {
local(@t);
$_ = <>;
split;
for ($i = 1; $i < $num + 1; ++$i) {
push(@t, (@_[$i] == 100)? 'true' : 'false');
}
print " (trusts @t)";
}
if ( $detail > 2 ) {
print STDERR "Oh, shit, I don't know what to do with all this";
}
print ")";
}
print "(set sides-min $num) (set sides-max $num)\n";
}
sub read_unit {
local($detail) = @_;
chop($_ = <>);
local($char, $name, $loc, $owner) = split;
$loc =~ s/,/ /;
++$owner;
$name =~ s/\*/ /g;
print "($char $loc $owner";
print qq/ (n "$name")/ unless $name eq ' ';
if ( $detail > 1 ) {
chop($_ = <>);
split;
local($no, $hp, $qual, $prod, $tl, $before, $trans) = @_[1,3,4,7..10];
local(@res) = splice(@_, 11);
print " (nb $no) (hp $hp) (m @res)";
print " (in $trans)" if $trans != -1;
print " (cxp $qual)" if $qual != 0;
# no handling of production type, turns left in build or made before.
}
if ( $detail > 2 ) {
print STDERR "Oh no, I don't know what to do with all this";
}
print ")";
}
|