Weird.
Well, it's not long.
Code:
#!/usr/bin/perl
#Arguments are -
# minimum # of neighbors, not counting non-matching.
# minimum # of neighbours, not counting non-matching, wasteland, deep sea or swamp
# bitmask you want to apply.
$d_neigh = $ARGV[0];
$d_neigh2 = $ARGV[1];
$apply = $ARGV[2];
$forced = 0;
while (<STDIN>)
{
chomp $_;
@line = split (/ /);
$pmode = 1;
if (/^#terrain/){
$terrain[$line[1]] = $line[2];
if ($line[2] % 8 >= 4){
$type[$line[1]] = -1;
}
else {
$type[$line[1]] = 1;
}
$cool[$line[1]] = $type[$line[1]];
if ($line[2] % 128 >= 64 || $line[2] % 64 >= 32 || $line[2] % 4096 >= 2048){
$elig[$line[1]] = 2;
}
# Upshot
# - implies sea.
# + implies land.
# 2 implies a wasteland, swamp or deep sea.
$mask[$line[1]] = $line[2];
if ($line[1] > $numprov){$numprov = $line[1];}
$pmode = 0;
}
if (/^#neighbour/){
$adj{$line[1]}{$line[2]} = 1;
$adj{$line[2]}{$line[1]} = 1;
}
if ($pmode == 1){
print "$_\n";
}
}
# Okay, now we need to know which provinces are eligible start-sites.
for ($i = 1; $i <= $numprov; $i++){
$total = 0; $same = 0; $bad = 0;
for $j (keys %{$adj{$i}}){
if ($cool[$i] * $cool[$i] == 1) {$same++;}
if ($cool[$i] * $cool[$j] * $elig[$j] == 2) {$bad++;}
$total++;
}
# print "$i,$elig\n";
if ($same == 0 && $type[$i] == -1){print "-- $i is a single province lake!\n";}
if ($same == 0 && $type[$i] == 0){print "-- $i is a single province island!\n";}
if ($total == 0){print "-- $i is an isolated province!\n";}
if ($same < $d_neigh){$mask[$i] = $mask[$i] | $apply;}
if ($same - $bad < $d_neigh2){$mask[$i] = $mask[$i] | $apply;}
print "#terrain $i $mask[$i]\n";
}