|
|
|
|
|
October 18th, 2006, 02:08 AM
|
|
Major General
|
|
Join Date: Feb 2005
Location: Lake of Hali, Aldebaran, OH
Posts: 2,474
Thanks: 51
Thanked 67 Times in 27 Posts
|
|
Dom3 Perl Scripts
This thread is hoped-for as a clearing house for useful dominions 3 perl-scripts.
Short-term plans call for a script to convert .csv files (a format accessible from all major spreadsheet programs) into modscript.
Here's a short one I just wrote that automatically selects semi-reasonable start locations on dom3 random maps. Usage:
StartFinder.pl [neighbors] [distance] < foo.map
StartFinder.pl [neighbors] [distance] < foo.map >> copy of foo.map
neighbors = (exactly) how many neighbors each start site will have. ATM the only terrain it cares about is that sea hexes don't count as neighbors for starts in land hexes, but this is easy to change (if people are worried about being stuck next to heavy cavalry hexes, and so forth.)
distance = minimum distance between start sites. The type of the route (through water, etc.) is ignored.
Disclaimer: This is NOT the most efficient way to manipulate a matrix like this! If you are tempted to adapt this code to do multivariate calculus or something, seek help immediately!
[spooiler] Code:
#!/usr/bin/perl
#Arguments are -
# minimum # of neighbors
# desired distance between start sites
$d_neigh = $ARGV[0];
$d_dist = $ARGV[1];
$max_sea = $ARGV[2];
while (<STDIN>)
{
chomp $_;
@line = split (/ /);
if (/terrain/){
if ($line[2] % 8 >= 4){
$type[$line[1]] = -1;
}
else {
$type[$line[1]] = 0;
}
$dist{$line[1]}{$line[1]} = 0;
if ($line[1] > $numprov){$numprov = $line[1];}
}
if (/neighbour/){
$adj{$line[1]}{$line[2]} = 1;
$adj{$line[2]}{$line[1]} = 1;
$dist{$line[1]}{$line[2]} = 1;
$dist{$line[2]}{$line[1]} = 1;
}
}
# Okay, now we need to know which provinces are eligible start-sites.
for ($i = 1; $i <= $numprov; $i++){
$elig = 0; $same = 0;
for $j (keys %{$adj{$i}}){
if ($type[$i] <= $type[$j]) {$elig++;}
if ($type[$i] == $type[$j]) {$same++;}
}
# print "$i,$elig\n";
if ($elig == $d_neigh){
$elig_list{$i} = 1;
}
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";}
}
# Now we need to extend the adjacency list for each province out to $d_dist.
for ($i = 1; $i <= $numprov; $i++){
for $j (keys %{$adj{$i}}){
for $k (keys %{$adj{$j}}){
if (!exists $dist{$i}{$k}){
$dist{$i}{$k} = 2;
$zone{2}{$i}{$k} = 1;
}
}}}
for ($l = 3; $l <= $d_dist; $l++)
{
for ($i = 1; $i <= $numprov; $i++){
for $j (keys %{$zone{$l-1}{$i}}){
for $k (keys %{$adj{$j}}){
if (!exists $dist{$i}{$k}){
$dist{$i}{$k} = $l;
$zone{$l}{$i}{$k} = 1;
}
}}}
}
for ($i = 1; $i <= $numprov; $i++){
if (exists $elig_list{$i}){
for $j (keys %{$dist{$i}})
{
if (exists $elig_list{$j}){
$clashes{$i}++;
$clashlist{$i}{$j} = 1;
}
}
}
}
@startpriority = sort {$clashes{$a} <=> $clashes{$b}} keys %elig_list;
for $i (@startpriority){
if (!exists $excluded{$i}){
print "#start $i\n";
if ($type[$i] == -1){print "-- sea start\n";}
for $j (keys %{$clashlist{$i}}){
$excluded{$j} = 1;
}
}
}
[/spoiler]
__________________
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
|
October 18th, 2006, 12:47 PM
|
|
Shrapnel Fanatic
|
|
Join Date: Oct 2003
Location: Vacaville, CA, USA
Posts: 13,736
Thanks: 341
Thanked 479 Times in 326 Posts
|
|
Re: Dom3 Perl Scripts
Since you are arraying neighbors Id like one that can find islands and ponds on a map. That would use arrays of neighbor and terrain (water with all neighbors land equals pond, land with all neighbors water equals island).
__________________
-- 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!)
|
October 18th, 2006, 06:06 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: Dom3 Perl Scripts
I believe I've added the desired functionality - let me know if that is what you meant. Is there a way in the version of BB-code these forums use to collapse something so that it doesn't eat the entire page? I suppose I should probably make the script an attachment instead of just pasteing it inline.
__________________
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
|
October 18th, 2006, 06:48 PM
|
|
Shrapnel Fanatic
|
|
Join Date: Oct 2003
Location: Vacaville, CA, USA
Posts: 13,736
Thanks: 341
Thanked 479 Times in 326 Posts
|
|
Re: Dom3 Perl Scripts
I was hoping for a seperate program. Something I could run against a .map and it would tell me islands and lakes
__________________
-- 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!)
|
October 18th, 2006, 09:21 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: Dom3 Perl Scripts
Oh
Attached.
__________________
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
|
October 19th, 2006, 02:14 PM
|
|
Lieutenant General
|
|
Join Date: Sep 2003
Location: Hyvinkää, Finland
Posts: 2,703
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Re: Dom3 Perl Scripts
Perl hmmm, is it hard to learn?
__________________
"Boobs are OK. Just not for Nerfix [img]/threads/images/Graemlins/Smile.gif[/img] ."
- Kristoffer O.
|
October 19th, 2006, 02:31 PM
|
Sergeant
|
|
Join Date: Sep 2003
Location: Norway
Posts: 346
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: Dom3 Perl Scripts
Quote:
Nerfix said:
Perl hmmm, is it hard to learn?
|
Not really. Soul-endangering to learn, maybe, but not hard.
__________________
"Freefall, my old nemesis! All I have to do is activate my compressed gas rocket boots and I will cheat you once again! Belt control ON!…On?" [i]Othar Trygvasson[i]
|
October 19th, 2006, 02:48 PM
|
|
Lieutenant General
|
|
Join Date: Sep 2003
Location: Hyvinkää, Finland
Posts: 2,703
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Re: Dom3 Perl Scripts
Perfect. Ftgahn!
__________________
"Boobs are OK. Just not for Nerfix [img]/threads/images/Graemlins/Smile.gif[/img] ."
- Kristoffer O.
|
October 19th, 2006, 03:33 PM
|
|
Shrapnel Fanatic
|
|
Join Date: Oct 2003
Location: Vacaville, CA, USA
Posts: 13,736
Thanks: 341
Thanked 479 Times in 326 Posts
|
|
Re: Dom3 Perl Scripts
Perl is kindof a cross between basic and C+. With the best of both (altho "best" is an opinion)
__________________
-- 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!)
|
October 19th, 2006, 04:17 PM
|
Sergeant
|
|
Join Date: Sep 2003
Location: Norway
Posts: 346
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Re: Dom3 Perl Scripts
Quote:
Gandalf Parker said:
Perl is kindof a cross between basic and C+. With the best of both (altho "best" is an opinion)
|
And the structure of neither.
__________________
"Freefall, my old nemesis! All I have to do is activate my compressed gas rocket boots and I will cheat you once again! Belt control ON!…On?" [i]Othar Trygvasson[i]
|
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
|
|
|
|
|