Mercurial > eagle-eye
annotate sheep.pl @ 352:bf59bef30dfc
scripts for counting travel time
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sun, 15 Feb 2009 14:19:47 +0800 |
parents | b245f259776f |
children | 85c17a9245e3 |
rev | line source |
---|---|
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1 #!/usr/bin/perl |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
2 use strict; |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
3 use Ikariam; |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
4 use Data::Dumper; |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
5 |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
6 package main; |
95
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
7 my $mime = Ikariam::User->retrieve ('name' => $::user); |
240
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
8 my $myAlly = undef; |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
9 $myAlly = Ikariam::Ally->retrieve($mime->allyId) |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
10 if(defined($mime->allyId) && $mime->allyId ne '0'); |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
11 |
95
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
12 # only challenge the small victims |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
13 my $army_score_main = ($mime->army_score_main / 3); |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
14 |
18 | 15 my @tradegoodText = qw/NULL 葡萄酒 大理石 水晶 硫磺/; |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
16 |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
17 Ikariam::User->has_many(cities => 'Ikariam::Cities'); |
102
94c9cde99e19
check the ally by right phe ally page, not counting the members we scanned.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
95
diff
changeset
|
18 Ikariam::User->has_a(ally => 'Ikariam::Ally'); |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
19 Ikariam::User->set_sql(inactivity => qq { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
20 SELECT user.id |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
21 FROM user, cities, island |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
22 WHERE user.id == cities.user |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
23 AND cities.island == island.id |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
24 AND island.x <= ? |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
25 AND island.x >= ? |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
26 AND island.y <= ? |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
27 AND island.y >= ? |
15 | 28 AND cities.status = 'i' |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
29 } |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
30 ); |
22
552528bb4917
refined the cache timeout is 12 hours.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
31 |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
32 Ikariam::User->set_sql(sheeps => qq { |
24 | 33 SELECT user.id |
34 FROM user, cities | |
35 WHERE user.id == cities.user | |
95
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
36 AND user.trader_score_secondary >= user.army_score_main*3 |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
37 AND user.army_score_main <= $army_score_main |
24 | 38 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? ) |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
39 } |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
40 ); |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
41 |
324 | 42 sub travelTime { |
43 my ($x1, $y1, $x2, $y2, $speed) = @_; | |
343
85d60a0569bf
fixed travel time for 0.3.0
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
341
diff
changeset
|
44 $speed = 60 unless(defined($speed)); |
85d60a0569bf
fixed travel time for 0.3.0
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
341
diff
changeset
|
45 if($x1 == $x2 && $y1 == $y2) { |
85d60a0569bf
fixed travel time for 0.3.0
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
341
diff
changeset
|
46 return 600/$speed; |
85d60a0569bf
fixed travel time for 0.3.0
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
341
diff
changeset
|
47 } else { |
85d60a0569bf
fixed travel time for 0.3.0
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
341
diff
changeset
|
48 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed)); |
85d60a0569bf
fixed travel time for 0.3.0
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
341
diff
changeset
|
49 } |
324 | 50 } |
51 | |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
52 sub listSheeps |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
53 { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
54 my @sheeps = @_; |
24 | 55 my %results; |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
56 |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
57 my $s; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
58 foreach my $sheep (sort (@sheeps)) { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
59 # avoid duplicate |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
60 next if($sheep->id == $s); $s = $sheep->id; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
61 |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
62 foreach my $c ($sheep->cities) { |
24 | 63 my $line = ""; |
64 # Ignore 假期模式 | |
15 | 65 next if($c->status eq 'v'); |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
66 |
15 | 67 unless($c->status eq 'i') { |
240
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
68 # 依照影響力區分 |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
69 unless ($sheep->allyId == '0') { |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
70 unless (!defined($sheep->allyId) || $sheep->allyId == 0) { |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
71 my $ally = Ikariam::Ally->retrieve($sheep->allyId); |
249
c30080146c05
fixed the sheep.pl for ignore user without ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
241
diff
changeset
|
72 next if(!defined($ally)); |
240
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
73 next if($ally->score > $myAlly->score); |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
74 } |
937fc672df56
count by Ally's score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
142
diff
changeset
|
75 } |
15 | 76 } |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
77 |
348
b245f259776f
ignore low level and high risk cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
343
diff
changeset
|
78 next if($c->citylevel le 10); |
b245f259776f
ignore low level and high risk cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
343
diff
changeset
|
79 next if($c->risk ge 30); |
24 | 80 my $island = Ikariam::Island->retrieve($c->island); |
81 | |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
82 |
295
15c288dd7dc5
checking spy risks
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
249
diff
changeset
|
83 $line = sprintf("%d %s score %d army %d risk %d %s/%s,", |
324 | 84 travelTime($::x, $::y, $island->x, $island->y), |
85 # $capture, | |
295
15c288dd7dc5
checking spy risks
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
249
diff
changeset
|
86 $c->status, $sheep->score, $sheep->army_score_main, $c->risk, $sheep->name, $sheep->ally); |
24 | 87 |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
65
diff
changeset
|
88 $line .= sprintf("\"%s\" %d [%d,%d] %s http://%s/index.php?view=island&id=%d&selectCity=%d\n", |
24 | 89 $c->cityname, $c->citylevel, |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
90 $island->x, $island->y, |
18 | 91 $tradegoodText[$island->tradegood], |
74
27b16506231f
improved the tech trees
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
65
diff
changeset
|
92 $::server, |
33
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
93 $island->id, |
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
94 $c->cityId |
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
95 ); |
24 | 96 |
97 printf("%s", $line); | |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
98 } |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
99 } |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
100 } |
95
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
101 |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
102 __MAIN__: |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
103 |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
104 if($#ARGV != 1) { die("Usage: $0 x y\n"); } |
324 | 105 our ($x, $y) = @ARGV; |
95
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
106 |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
107 listSheeps(Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6))); |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
108 # listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6))); |
6527b4b20d60
refiend the army score filtering
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
74
diff
changeset
|
109 |