Mercurial > eagle-eye
comparison inactive-map.pl @ 31:e992576ac97c
inactive user locator
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 10 Oct 2008 07:00:52 +0800 |
parents | |
children | da0dd597401c |
comparison
equal
deleted
inserted
replaced
30:de5de6d472f9 | 31:e992576ac97c |
---|---|
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 | |
13 WHERE user.id == cities.user | |
14 AND cities.island == island.id | |
15 AND island.x <= ? | |
16 AND island.x >= ? | |
17 AND island.y <= ? | |
18 AND island.y >= ? | |
19 AND cities.status == 'i' | |
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 | |
39 WHERE user.id == cities.user | |
40 AND cities.status == 'i' | |
41 AND user.trader_score_secondary >= 50000 | |
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 | |
72 next if($robbery < 2000); | |
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 | |
98 foreach my $x ($x1..$x2) | |
99 { | |
100 print(OUT "<tr>"); | |
101 foreach my $y($y1..$y2) | |
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'}); | |
106 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>", | |
107 $c, $c, $maps{$x}{$y}{'id'}, $x, $y, $maps{$x}{$y}{'density'}, $x, $y); | |
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 |