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