I searched the net for a map randomizer and didn't
come across one... so I put one together. This script
basically reads the contents of the maps folder to
create a master file..call it what you want. This
master file is then randomized and the output is
written to mapcycle.txt.
#!/usr/bin/perl
#i#############################################
# Dave K 1/17/02 #
# #
# Use this script to randomize a HL map cycle #
###############################################
#
# This should be the path to your halflife maps directory
$mapsdir = "/Path/to/HL/maps/directory/";
#
# let's assign our master map list
#
$master = "/Path/to/place/master/file/";
#
# Cycle should be the map list configured for HL, default is
mapcycle.txt
#
$cycle = "/Path/to/mapcycle.txt";
#
# we'll need to remove the previously randomized mapcycle and master
file
#
unlink $cycle;
unlink $master;
#
# we need a routine to randomize the values in an array
#
sub shuffle {
my $array = lines;
my $i = scalar (@$array);
my $j;
foreach $item (@$array)
{
--$i;
$j = int rand ($i+1);
next if $i == $j;
@$array [$i,$j] = @$array[$j,$i];
}
return @$array;
}
#
# read the maps dir using the readdir function and create an array
#
opendir(MAPSDIR, $mapsdir) || die "Can not open file: $1\n";
@maps = readdir(MAPSDIR);
closedir(MAPSDIR);
foreach $bsp (@maps)
{
unless ( ($bsp eq ".") || ($bsp eq "..") )
{
open (MASTERLIST, ">>$master");
print MASTERLIST "$bsp\n";
close (MASTERLIST);
}
}
#
# we've created our master list, next we'll prepare it for randomizing
#
open MASTERLIST, $master || die "Could not open file: $1\n";
while (<MASTERLIST>) {
#
# go ahead and push the values in our master file into an array
#
push (@lines, $_);
}
#
# declare our shuffle array
#
@reordered = shuffle(@lines);
foreach (@reordered) {
#
# Let's print these reordered values to our map cycle file
#
open (MAPCYCLE, ">>$cycle");
print MAPCYCLE $_;
close (MAPCYCLE);
}