view inactive-map.pl @ 122:11541129a389

fixed for counting ally members.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 30 Oct 2008 16:19:24 +0800
parents da0dd597401c
children
line wrap: on
line source

#!/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 < 1000);

            $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 "<html><head><style type=\"text/css\">
        body {color: #FFFFFF; } 
        a {color: #000000; } 
        table {
        border-width: 0px 0px 0px 0px;
        border-spacing: 0px;
        border-style: inset inset inset inset;
        border-color: gray gray gray gray;
        border-collapse: collapse;
        background-color: white;
        }
        </style></head><body><table border=1>");

    foreach my $y($y1..$y2)
    {
        print(OUT "<tr>");
        foreach my $x ($x1..$x2)
        {
            # printf("<div stlye='float:left; background-color: black; padding: 0; Display:inline;'>o</div>");
            if(defined($maps{$x}{$y}{'density'})) {
                my $c = 255 - (15 * $maps{$x}{$y}{'density'});
                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>",
                    $c, $c, $::server, $maps{$x}{$y}{'id'}, $x, $y, $maps{$x}{$y}{'density'}, $x, $y);
            } else {
                printf(OUT "<td style=\"background-color: rgb(255,255,255);\">[%d,%d]</td>", $x, $y);
            }
        }
        print(OUT "</tr>");
    }
    printf(OUT "</table></body></html>");
    close(OUT);
}

# find_or_create