# run-time configuration
my $room = { };
my $prop = { };
my $input = shift;
$input .= '.log' unless -f $input;
(my $base = $input) =~ s/(\.\w+)?$//;
my $output = $base . '.inf';
die "Input file $input is the same as output file $output\n"
if $input eq $output;
my $plotter = $base . '.png';
die "Input file $input is the same as plotter file $plotter\n"
if $input eq $plotter;
open(INPUT, $input)
or die "Unable to open input file $input\n";
warn "input=$input, output=$output, plotter=$plotter\n" if $verbose;
my (%opposite, %sort_by, %xoff, %yoff);
{
my @d1 = qw/n ne e se u in/;
my @d2 = qw/s sw w nw d out/;
@opposite{@d1, @d2} = (@d2, @d1);
@sort_by{@d1, @d2} = qw/a e c f i k b g d h j l/;
splice @d1, 4, 2;
splice @d2, 4, 2;
my $s2 = sqrt(.5);
@xoff{@d1, @d2} = ( .0, $s2, 1.0, $s2, .0, -$s2, -1.0, -$s2, );
@yoff{@d1, @d2} = (1.0, $s2, .0, -$s2, -1.0, -$s2, .0, $s2, );
}
my $expecting = $room_class;
sub trace {
warn sprintf "%d) %s x=%8.5f y=%8.5f fx=%8.5f fy=%8.5f\n", @_,
if $_[1] =~ /^V/;
}
sub gd {
my $hash = shift;
return grep { defined $hash->{$_} } @_;
}
sub cart2rad {
my ($dx, $dy) = @_;
my $d = sqrt($dx*$dx + $dy*$dy);
if (wantarray) {
return ($d, atan2($dy, $dx));
} else {
return $d;
}
}
sub Usage {
die <<"__USAGE__";
Usage: $0 <logfile>
__USAGE__
}
sub move {
my ($prop, $room) = @_;
return if $prop->{parent} == $room;
$prop->{parent} = $room;
$prop->{sibling} = $room->{child};
$room->{child} = $prop;
}
my $next_line;
sub get_description {
my @descr;
while (<INPUT>) {
s/[\n\r]+//;
last if /^>/ or eof(INPUT);
push @descr, $_;
}
$next_line = $_;
return join(' ', @descr);
}
sub fix_description {
my ($property, $descr) = @_;
$descr =~ s/"/~/g; # clean up embedded double-quotes
$descr =~ s/^/\n $property "/; # add header... "\n" is required
$descr =~ s/ *$/"/; # clean up trailing spaces
$descr =~ s/(.*\n[^\n]{1,72}) ([^\n]+)$/$1\n $2/s
while $descr =~ /[^\n]{73,}/; # word-wrap the text
$descr =~ s/\n /\n\t/g; # clean up indentations
return $descr;
}
use Graphics::Plotter;
open(PLOTTER, ">$plotter")
or die "Unable to open plotter file $plotter\n";
my $p = Graphics::Plotter::PNG->new(*PLOTTER);
$p->openpl();
log2inf - Reverse-engineer an IF transcript into an Inform source file.
=head1 SYNOPSIS
sample [options] [file]
Options:
-room <string> name of Class to use for rooms (default 'Room')
-prop <string> name of Class to use for props (default 'Prop')
-dt <float> see below
-animate produce an image after each pass
-verbose increment verbosity level
-srand <int> initialize random number generator
-help brief help message
-man full documentation
=head1 OPTIONS
=over 8
=item B<-room> -I<name>
Name of Class to use for rooms (default 'Room').
=item B<-prop> -I<name>
Name of Class to use for props (default 'Prop').
=item B<-dt> -I<float>
Sets increment amount for map generation.
=item B<-animate>
Graphs are produced by seeding the rooms to random locations, then moving
them around to minimize the forces produced by elastic links between them.
This option causes a graph to be produced after each iteration.
=item B<-verbose>
Increment verbosity level. Use it once to produce a little output,
use it multiple times to produce a lot.
=item B<-srand> -I<int>
Initialize random number generator.
=item B<-help>
Print a brief help message and exits.
=item B<-man>
Prints the manual page and exits.
=back
=head1 DESCRIPTION
In "The Inform Designer's Manual, 4th edition, Graham Nelson says,
"Gareth Rees persuasively advocates writing this sort of
transcript, of an ideal sequence of play, first, and worrying about
how to code up the design afterwards. Other designers prefer to build
from the bottom up, crafting the objects one at a time and finally
bringing them together into the narrative."
I've gone with Rees' idea. First, I wrote a transcript, then I wrote
a Perl script that turns transcripts into Inform source code. So,
something like this:
>n
West Wing
You are in the West Wing of the White House. You see a desk and, on
it, a red telephone.
>x large wooden desk
It has a heavy paperweight on it.
>x paperweight
It says "The buck stops here."
>x red telephone
It's red, without a dial.
>w
Rose Garden
generates something like this:
Room West_Wing "West Wing"
with
description "You are in the West Wing of the White House. You
see a desk and, on it, a red telephone.",
w_to Rose_Garden;
Prop -> large_wooden_desk_00 "large wooden desk"
with
name 'large' 'wooden' 'desk'
description "It has a paperweight on it."
Prop -> paperweight_00 "paperweight"
with
name 'paperweight'
description "It says ~The buck stops here.~"
Prop -> red_telephone_00 "red telephone"
with
name 'red' 'telephone'
description "It's red, without a dial."
Props are numbered, so multiple rooms could contain, for example,
large wooden desks. Note that anything described is assumed to be a
child of the room, so you still have a bit of fixing up to do (both
the paperweight and the telephone, in this instance). Also, note that
I assume the existance of classes named Room and Prop. Right now, I
use the script to generate a file that I then include in my main
Inform source, as both the transcript and the Perl script are still in
a bit of flux.
My next goal is to add a mapping component, which will likely spit out
gnuplot instructions to draw a crude map of just the rooms. You just
pretend that the eight "primary" links between rooms are elastic, and
figure out a layout that keeps the links at their minimal lengths.
Simple iterative physics-based modeling.
I think I can also divide a map into layers by using some coloring
algorithms. It's easy if the only connections between layers are 'up'
and 'down', but I think that by using weighted averaging, I can decide
which connections are important and which just lead to sunken living
rooms and the like.
=head1 AUTHOR
Sam Denton, samwyse (at) email (dot) com
=head1 BUGS
=head1 SEE ALSO
"The Inform Designer's Manual", 4th edition, Graham Nelson.
=head1 COPYRIGHT
Copyright 2004, Sam Denton. All rights reserved.
This program is free software. You may copy or
redistribute it under the same license as Perl itself.
=cut
Files without descriptions:
0Makefile.inform /if-archive/infocom/compilers/inform6/utilities/Makefile.inform
0unixcasefix.sh /if-archive/infocom/compilers/inform6/utilities/unixcasefix.sh