# HG changeset patch # User "Rex Tsai " # Date 1223593252 -28800 # Node ID e992576ac97c35240e020dde8407949bfc4d97e0 # Parent de5de6d472f9a203edc09775e17306486961765a inactive user locator diff -r de5de6d472f9 -r e992576ac97c inactive-map.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inactive-map.pl Fri Oct 10 07:00:52 2008 +0800 @@ -0,0 +1,118 @@ +#!/usr/bin/perl +use strict; +use Ikariam; +use Data::Dumper; +use List::Util qw[min max]; + +package main; + +Ikariam::User->has_many(cities => 'Ikariam::Cities'); +Ikariam::User->set_sql(inactivity => qq { + SELECT user.id + FROM user, cities, island + WHERE user.id == cities.user + AND cities.island == island.id + AND island.x <= ? + AND island.x >= ? + AND island.y <= ? + AND island.y >= ? + AND cities.status == 'i' + } +); +#Ikariam::User->set_sql(sheeps => qq { +# SELECT user.id +# FROM user, cities, island +# WHERE user.id == cities.user +# AND cities.island == island.id +# AND island.x <= ? +# AND island.x >= ? +# AND island.y <= ? +# AND island.y >= ? +# AND user.trader_score_secondary >= 50000 +# AND user.army_score_main <= 100 +# } +#); + +Ikariam::User->set_sql(sheeps => qq { + SELECT user.id + FROM user, cities + WHERE user.id == cities.user + AND cities.status == 'i' + AND user.trader_score_secondary >= 50000 + AND user.army_score_main <= 40 + } +); + +listSheeps(Ikariam::User->search_sheeps()); + +sub listSheeps +{ + my @sheeps = @_; + my %results; + + my $s; + my %maps; + + my $x1 = 99; + my $x2 = 0; + my $y1 = 99; + my $y2 = 0; + foreach my $sheep (sort (@sheeps)) { + # avoid duplicate + next if($sheep->id == $s); $s = $sheep->id; + + foreach my $c ($sheep->cities) { + my $line = ""; + + my $island = Ikariam::Island->retrieve($c->island); + + # 所得金錢 = 對方城鎮等級x(對方城鎮等級-1)x對方金錢/10000 + my $robbery = $c->citylevel * ($c->citylevel - 1) * $sheep->trader_score_secondary / 10000; + + next if($robbery < 2000); + + $maps{$island->x}{$island->y}{'id'} = $island->id; + $maps{$island->x}{$island->y}{'density'} += 1; + + $x1 = min ($x1, $island->x); + $x2 = max ($x2, $island->x); + $y1 = min ($y1, $island->y); + $y2 = max ($y2, $island->y); + } + } + + open(OUT, ">map.html") or die $!; + printf(OUT ""); + + foreach my $x ($x1..$x2) + { + print(OUT ""); + foreach my $y($y1..$y2) + { + # printf("
o
"); + if(defined($maps{$x}{$y}{'density'})) { + my $c = 255 - (15 * $maps{$x}{$y}{'density'}); + printf(OUT "", + $c, $c, $maps{$x}{$y}{'id'}, $x, $y, $maps{$x}{$y}{'density'}, $x, $y); + } else { + printf(OUT "", $x, $y); + } + } + print(OUT ""); + } + printf(OUT "
[%d,%d][%d,%d]
"); + close(OUT); +} + +# find_or_create