|
|
|
|
 |

May 1st, 2007, 10:35 PM
|
 |
Shrapnel Fanatic
|
|
Join Date: Oct 2003
Location: Vacaville, CA, USA
Posts: 13,736
Thanks: 341
Thanked 479 Times in 326 Posts
|
|
Re: tool request (terrain math)
DrP, I get an error trying to grab that file.
__________________
-- DISCLAIMER:
This game is NOT suitable for students, interns, apprentices, or anyone else who is expected to pass tests on a regular basis. Do not think about strategies while operating heavy machinery. Before beginning this game make arrangements for someone to check on you daily. If you find that your game has continued for more than 36 hours straight then you should consult a physician immediately (Do NOT show him the game!)
|

May 1st, 2007, 11:20 PM
|
 |
Major General
|
|
Join Date: Feb 2005
Location: Lake of Hali, Aldebaran, OH
Posts: 2,474
Thanks: 51
Thanked 67 Times in 27 Posts
|
|
Re: tool request (terrain math)
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";
}
__________________
If you read his speech at Rice, all his arguments for going to the moon work equally well as arguments for blowing up the moon, sending cloned dinosaurs into space, or constructing a towering *****-shaped obelisk on Mars. --Randall Munroe
|

May 2nd, 2007, 12:22 AM
|
 |
Shrapnel Fanatic
|
|
Join Date: Oct 2003
Location: Vacaville, CA, USA
Posts: 13,736
Thanks: 341
Thanked 479 Times in 326 Posts
|
|
Re: tool request (terrain math)
That works great. Thanks. 
__________________
-- DISCLAIMER:
This game is NOT suitable for students, interns, apprentices, or anyone else who is expected to pass tests on a regular basis. Do not think about strategies while operating heavy machinery. Before beginning this game make arrangements for someone to check on you daily. If you find that your game has continued for more than 36 hours straight then you should consult a physician immediately (Do NOT show him the game!)
|
| Thread Tools |
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
|
|