annotate ally.pl @ 119:755e5f5434e4

merged for fixed inactive-map.pl and hacks for highscore search.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 30 Oct 2008 15:08:56 +0800
parents 54ab0becd730
children a60cf4d1a6dd
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
23
54ab0becd730 implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 21
diff changeset
9 # my $users = Ikariam::User->search(ally => 'WMeMe');
54ab0becd730 implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 21
diff changeset
10
21
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11 Ikariam::Cities->set_sql(ally => qq {
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
12 SELECT cities.id
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
13 FROM island, cities
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
14 WHERE cities.island == island.id
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
15 AND cities.ally == ?
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
16 });
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
17
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
18 Ikariam::Island->has_many(cities => 'Ikariam::Cities');
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
19 Ikariam::Island->set_sql(ally => qq {
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
20 SELECT island.id
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
21 FROM island, cities
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
22 WHERE cities.island == island.id
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
23 AND cities.ally == ?
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
24 });
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 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
27
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28 my @islands = Ikariam::Island->search_ally($ARGV[0]);
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29 my %maps;
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 my $x1 = 99;
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 my $x2 = 0;
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
33 my $y1 = 99;
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
34 my $y2 = 0;
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 foreach my $island (@islands)
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
37 {
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
38 $x1 = min ($x1, $island->x);
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
39 $x2 = max ($x2, $island->x);
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
40 $y1 = min ($y1, $island->y);
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
41 $y2 = max ($y2, $island->y);
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
42
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
43 $maps{$island->x}{$island->y}{'id'} = $island->id;
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 $maps{$island->x}{$island->y}{'density'} += 1;
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45 # printf("[%s,%s]", $island->x, $island->y);
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46 }
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
48 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
49 printf(OUT "<html><head><style type=\"text/css\">
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
50 body {color: #FFFFFF; }
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
51 a {color: #000000; }
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
52 table {
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
53 border-width: 0px 0px 0px 0px;
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
54 border-spacing: 0px;
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
55 border-style: inset inset inset inset;
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
56 border-color: gray gray gray gray;
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
57 border-collapse: collapse;
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
58 background-color: white;
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 </style></head><body><table border=1>");
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 foreach my $x ($x1..$x2)
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
63 {
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
64 print(OUT "<tr>");
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
65 foreach my $y($y1..$y2)
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
66 {
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
67 # 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
68 if(defined($maps{$x}{$y}{'density'})) {
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
69 my $c = 255 - (15 * $maps{$x}{$y}{'density'});
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
70 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
71 $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
72 } else {
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
73 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
74 }
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 print(OUT "</tr>");
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
77 }
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
78 printf(OUT "</table></body></html>");
d5e02a25b000 map generator for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
79 close(OUT);