From e2694bf148c4d1c1d90218c49b60c24a397f2fc7 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 9 Jan 2011 15:40:26 +0100 Subject: [PATCH] tile_randomizer.px: Add script for randomizing tiles. Most levels look much nicer if interchangeable tiles are used at random. --- tile_randomizer.px | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 tile_randomizer.px diff --git a/tile_randomizer.px b/tile_randomizer.px new file mode 100755 index 0000000..aa1fc73 --- /dev/null +++ b/tile_randomizer.px @@ -0,0 +1,76 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +our $TileGroups = +[ + [1001, 1002], # forest gras + [1005, 1006], # forest stones top + [1008, 1012], # forest stones left + [1009, 1013, 1014], # forest stones fill + [1011, 1015], # forest stones right + [1017, 1018], # forest stones bottom + [2058, 2060, 2061, 2065, 2066, 2070], # ice tiles + [2179, 2180, 2181, 2187, 2188, 2189, 2195, 2196, 2197], # snow bg + [2171, 2172, 2175, 2176] # those other snow thingies +]; +our $TileMap = {}; + +sub init +{ + for (@$TileGroups) + { + my $group = $_; + + for (@$group) + { + my $id = $_; + + $TileMap->{$id} = $group; + } + } +} # init + +sub get_random +{ + my $id = shift; + my $group; + my $group_size; + + if (!$TileMap->{$id}) + { + return ($id); + } + + $group = $TileMap->{$id}; + $group_size = 0 + @$group; + + return ($group->[int (rand ($group_size))]); +} + +if (-t STDIN) +{ + print STDERR "Usage: ./tile_randomizer.px out_file\n"; + exit (1); +} + +init (); + +while (<>) +{ + my $line = $_; + chomp ($line); + + if ($line =~ m/[^\s\d]/) + { + print "$line\n"; + next; + } + + $line =~ s/\b([1-9][0-9]{0,3})\b/get_random ($1)/ge; + + print "$line\n"; +} + +exit (0); -- 2.11.0