annotate inactive-map.pl @ 214:f6836ef11203

fixed a typo.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Tue, 04 Nov 2008 15:13:00 +0800
parents da0dd597401c
children
rev   line source
31
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
1 #!/usr/bin/perl
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
2 use strict;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
3 use Ikariam;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
4 use Data::Dumper;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
5 use List::Util qw[min max];
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
6
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
7 package main;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
8
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
9 Ikariam::User->has_many(cities => 'Ikariam::Cities');
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
10 Ikariam::User->set_sql(inactivity => qq {
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11 SELECT user.id
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
12 FROM user, cities, island
116
da0dd597401c fixed the x/y position
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 31
diff changeset
13 WHERE user.id = cities.user
da0dd597401c fixed the x/y position
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 31
diff changeset
14 AND cities.island = island.id
31
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
15 AND island.x <= ?
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
16 AND island.x >= ?
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
17 AND island.y <= ?
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
18 AND island.y >= ?
116
da0dd597401c fixed the x/y position
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 31
diff changeset
19 AND cities.status = 'i'
31
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
20 }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
21 );
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
22 #Ikariam::User->set_sql(sheeps => qq {
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
23 # SELECT user.id
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
24 # FROM user, cities, island
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
25 # WHERE user.id == cities.user
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
26 # AND cities.island == island.id
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
27 # AND island.x <= ?
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28 # AND island.x >= ?
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29 # AND island.y <= ?
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30 # AND island.y >= ?
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 # AND user.trader_score_secondary >= 50000
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 # AND user.army_score_main <= 100
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
33 # }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
34 #);
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
35
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36 Ikariam::User->set_sql(sheeps => qq {
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
37 SELECT user.id
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
38 FROM user, cities
116
da0dd597401c fixed the x/y position
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 31
diff changeset
39 WHERE user.id = cities.user
da0dd597401c fixed the x/y position
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 31
diff changeset
40 AND cities.status = 'i'
da0dd597401c fixed the x/y position
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 31
diff changeset
41 AND user.trader_score_secondary >= 50000
31
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
42 AND user.army_score_main <= 40
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
43 }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 );
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46 listSheeps(Ikariam::User->search_sheeps());
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
48 sub listSheeps
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
49 {
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
50 my @sheeps = @_;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
51 my %results;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
52
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
53 my $s;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
54 my %maps;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
55
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
56 my $x1 = 99;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
57 my $x2 = 0;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
58 my $y1 = 99;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
59 my $y2 = 0;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
60 foreach my $sheep (sort (@sheeps)) {
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
61 # avoid duplicate
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
62 next if($sheep->id == $s); $s = $sheep->id;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
63
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
64 foreach my $c ($sheep->cities) {
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
65 my $line = "";
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
66
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
67 my $island = Ikariam::Island->retrieve($c->island);
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
68
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
69 # 所得金錢 = 對方城鎮等級x(對方城鎮等級-1)x對方金錢/10000
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
70 my $robbery = $c->citylevel * ($c->citylevel - 1) * $sheep->trader_score_secondary / 10000;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
71
116
da0dd597401c fixed the x/y position
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 31
diff changeset
72 next if($robbery < 1000);
31
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
73
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
74 $maps{$island->x}{$island->y}{'id'} = $island->id;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
75 $maps{$island->x}{$island->y}{'density'} += 1;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
76
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
77 $x1 = min ($x1, $island->x);
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
78 $x2 = max ($x2, $island->x);
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
79 $y1 = min ($y1, $island->y);
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
80 $y2 = max ($y2, $island->y);
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
81 }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
82 }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
83
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
84 open(OUT, ">map.html") or die $!;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
85 printf(OUT "<html><head><style type=\"text/css\">
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
86 body {color: #FFFFFF; }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
87 a {color: #000000; }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
88 table {
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
89 border-width: 0px 0px 0px 0px;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
90 border-spacing: 0px;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
91 border-style: inset inset inset inset;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
92 border-color: gray gray gray gray;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
93 border-collapse: collapse;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
94 background-color: white;
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
95 }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
96 </style></head><body><table border=1>");
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
97
116
da0dd597401c fixed the x/y position
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 31
diff changeset
98 foreach my $y($y1..$y2)
31
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
99 {
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
100 print(OUT "<tr>");
116
da0dd597401c fixed the x/y position
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 31
diff changeset
101 foreach my $x ($x1..$x2)
31
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
102 {
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
103 # printf("<div stlye='float:left; background-color: black; padding: 0; Display:inline;'>o</div>");
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
104 if(defined($maps{$x}{$y}{'density'})) {
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
105 my $c = 255 - (15 * $maps{$x}{$y}{'density'});
116
da0dd597401c fixed the x/y position
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 31
diff changeset
106 printf(OUT "<td style=\"background-color: rgb(255,%d,%d);\"><a href=\"http://%s/index.php?view=island&id=%d\" title=\"[%d,%d] (%d)\">[%d,%d]</a></td>",
da0dd597401c fixed the x/y position
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 31
diff changeset
107 $c, $c, $::server, $maps{$x}{$y}{'id'}, $x, $y, $maps{$x}{$y}{'density'}, $x, $y);
31
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
108 } else {
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
109 printf(OUT "<td style=\"background-color: rgb(255,255,255);\">[%d,%d]</td>", $x, $y);
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
110 }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
111 }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
112 print(OUT "</tr>");
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
113 }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
114 printf(OUT "</table></body></html>");
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
115 close(OUT);
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
116 }
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
117
e992576ac97c inactive user locator
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
118 # find_or_create