Mercurial > eagle-eye
annotate ally.pl @ 21:d5e02a25b000
map generator for ally
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Wed, 08 Oct 2008 19:25:31 +0800 |
parents | |
children | 54ab0becd730 |
rev | line source |
---|---|
21
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1 #!/usr/bin/perl |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
2 use strict; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
3 use Ikariam; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
4 use Data::Dumper; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
5 use List::Util qw[min max]; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
6 |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
7 package main; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
8 |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
9 Ikariam::Cities->set_sql(ally => qq { |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
10 SELECT cities.id |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
11 FROM island, cities |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
12 WHERE cities.island == island.id |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
13 AND cities.ally == ? |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
14 }); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
15 |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
16 Ikariam::Island->has_many(cities => 'Ikariam::Cities'); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
17 Ikariam::Island->set_sql(ally => qq { |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
18 SELECT island.id |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
19 FROM island, cities |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
20 WHERE cities.island == island.id |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
21 AND cities.ally == ? |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
22 }); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
23 |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
24 die("Usage: $0\nUsage: $0 ally\n") unless ($#ARGV == 0); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
25 |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
26 my @islands = Ikariam::Island->search_ally($ARGV[0]); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
27 my %maps; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
28 |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
29 my $x1 = 99; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
30 my $x2 = 0; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
31 my $y1 = 99; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
32 my $y2 = 0; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
33 |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
34 foreach my $island (@islands) |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
35 { |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
36 $x1 = min ($x1, $island->x); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
37 $x2 = max ($x2, $island->x); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
38 $y1 = min ($y1, $island->y); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
39 $y2 = max ($y2, $island->y); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
40 |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
41 $maps{$island->x}{$island->y}{'id'} = $island->id; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
42 $maps{$island->x}{$island->y}{'density'} += 1; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
43 # printf("[%s,%s]", $island->x, $island->y); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
44 } |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
45 |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
46 open(OUT, sprintf(">%s-map.html", $ARGV[0])) or die $!; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
47 printf(OUT "<html><head><style type=\"text/css\"> |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
48 body {color: #FFFFFF; } |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
49 a {color: #000000; } |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
50 table { |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
51 border-width: 0px 0px 0px 0px; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
52 border-spacing: 0px; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
53 border-style: inset inset inset inset; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
54 border-color: gray gray gray gray; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
55 border-collapse: collapse; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
56 background-color: white; |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
57 } |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
58 </style></head><body><table border=1>"); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
59 |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
60 foreach my $x ($x1..$x2) |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
61 { |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
62 print(OUT "<tr>"); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
63 foreach my $y($y1..$y2) |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
64 { |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
65 # printf("<div stlye='float:left; background-color: black; padding: 0; Display:inline;'>o</div>"); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
66 if(defined($maps{$x}{$y}{'density'})) { |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
67 my $c = 255 - (15 * $maps{$x}{$y}{'density'}); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
68 printf(OUT "<td style=\"background-color: rgb(255,%d,%d);\"><a href=\"http://s2.ikariam.tw/index.php?view=island&id=%d\" title=\"[%d,%d] (%d)\">[%d,%d]</a></td>", |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
69 $c, $c, $maps{$x}{$y}{'id'}, $x, $y, $maps{$x}{$y}{'density'}, $x, $y); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
70 } else { |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
71 printf(OUT "<td style=\"background-color: rgb(255,255,255);\">[%d,%d]</td>", $x, $y); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
72 } |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
73 } |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
74 print(OUT "</tr>"); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
75 } |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
76 printf(OUT "</table></body></html>"); |
d5e02a25b000
map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
77 close(OUT); |