#!/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 [1861, 1862], # forest underground gras [1865, 1866], # forest underground stones top [1868, 1872], # forest underground stones left [1869, 1873, 1874], # forest underground stones fill [1871, 1875], # forest underground stones right [1877, 1879], # forest underground stones bottom [2058, 2060, 2061, 2065, 2066, 2070], # ice tiles [2179, 2180, 2181, 2187, 2188, 2189, 2195, 2196, 2197] # snow bg ]; 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);