Mercurial > eagle-eye
annotate inactive-map.pl @ 130:dbefe10550cb
refined sql format
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 31 Oct 2008 01:54:12 +0800 |
parents | da0dd597401c |
children |
rev | line source |
---|---|
31 | 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::User->has_many(cities => 'Ikariam::Cities'); | |
10 Ikariam::User->set_sql(inactivity => qq { | |
11 SELECT user.id | |
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 | 15 AND island.x <= ? |
16 AND island.x >= ? | |
17 AND island.y <= ? | |
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 | 20 } |
21 ); | |
22 #Ikariam::User->set_sql(sheeps => qq { | |
23 # SELECT user.id | |
24 # FROM user, cities, island | |
25 # WHERE user.id == cities.user | |
26 # AND cities.island == island.id | |
27 # AND island.x <= ? | |
28 # AND island.x >= ? | |
29 # AND island.y <= ? | |
30 # AND island.y >= ? | |
31 # AND user.trader_score_secondary >= 50000 | |
32 # AND user.army_score_main <= 100 | |
33 # } | |
34 #); | |
35 | |
36 Ikariam::User->set_sql(sheeps => qq { | |
37 SELECT user.id | |
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 | 42 AND user.army_score_main <= 40 |
43 } | |
44 ); | |
45 | |
46 listSheeps(Ikariam::User->search_sheeps()); | |
47 | |
48 sub listSheeps | |
49 { | |
50 my @sheeps = @_; | |
51 my %results; | |
52 | |
53 my $s; | |
54 my %maps; | |
55 | |
56 my $x1 = 99; | |
57 my $x2 = 0; | |
58 my $y1 = 99; | |
59 my $y2 = 0; | |
60 foreach my $sheep (sort (@sheeps)) { | |
61 # avoid duplicate | |
62 next if($sheep->id == $s); $s = $sheep->id; | |
63 | |
64 foreach my $c ($sheep->cities) { | |
65 my $line = ""; | |
66 | |
67 my $island = Ikariam::Island->retrieve($c->island); | |
68 | |
69 # 所得金錢 = 對方城鎮等級x(對方城鎮等級-1)x對方金錢/10000 | |
70 my $robbery = $c->citylevel * ($c->citylevel - 1) * $sheep->trader_score_secondary / 10000; | |
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 | 73 |
74 $maps{$island->x}{$island->y}{'id'} = $island->id; | |
75 $maps{$island->x}{$island->y}{'density'} += 1; | |
76 | |
77 $x1 = min ($x1, $island->x); | |
78 $x2 = max ($x2, $island->x); | |
79 $y1 = min ($y1, $island->y); | |
80 $y2 = max ($y2, $island->y); | |
81 } | |
82 } | |
83 | |
84 open(OUT, ">map.html") or die $!; | |
85 printf(OUT "<html><head><style type=\"text/css\"> | |
86 body {color: #FFFFFF; } | |
87 a {color: #000000; } | |
88 table { | |
89 border-width: 0px 0px 0px 0px; | |
90 border-spacing: 0px; | |
91 border-style: inset inset inset inset; | |
92 border-color: gray gray gray gray; | |
93 border-collapse: collapse; | |
94 background-color: white; | |
95 } | |
96 </style></head><body><table border=1>"); | |
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 | 99 { |
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 | 102 { |
103 # printf("<div stlye='float:left; background-color: black; padding: 0; Display:inline;'>o</div>"); | |
104 if(defined($maps{$x}{$y}{'density'})) { | |
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 | 108 } else { |
109 printf(OUT "<td style=\"background-color: rgb(255,255,255);\">[%d,%d]</td>", $x, $y); | |
110 } | |
111 } | |
112 print(OUT "</tr>"); | |
113 } | |
114 printf(OUT "</table></body></html>"); | |
115 close(OUT); | |
116 } | |
117 | |
118 # find_or_create |