view freeland.pl @ 278:b2510d9339d8

fixed warehouse level
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Tue, 02 Dec 2008 17:11:39 +0800
parents dba0543daf36
children a9847bf80058
line wrap: on
line source

#!/usr/bin/perl
use strict;
use Ikariam;
use Data::Dumper;

package main;
my @tradegoodText = qw/NULL 葡萄酒 大理石 水晶 硫磺/;
my @wonderText = qw/NULL 赫菲斯拓斯的熔爐 蓋亞的神殿 狄奧尼索斯的花園 雅典娜的神殿 赫秘士的神殿 阿瑞斯的要塞 波賽頓的神殿 克羅瑟斯的神殿/;

if($#ARGV != 2) {
    die("Usage: $0 x y tradegood (1 葡萄酒, 2 大理石, 3 水晶, 4 硫磺/)\n");
}
my ($x, $y, $tradegood) = @ARGV;

my @location = (($x + 6), ($x - 6), ($y + 6), ($y - 6));

# 找空位
Ikariam::Cities->set_sql(lamers => qq {
        SELECT cities.cityId
          FROM user, cities 
         WHERE user.id == cities.user 
           AND user.score <= 1000
           AND cities.status != 'v'
           AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? AND tradegood == 2)
    }
);

# 
my @islands = Ikariam::Island->retrieve_from_sql(qq{
        tradegood == $tradegood
    AND people < 16
    AND x <= $location[0]
    AND x >= $location[1]
    AND y <= $location[2]
    AND y >= $location[3]
    });

if($#islands == -1) {
        my @cities = Ikariam::Cities->search_lamers(@location);
        foreach my $city (@cities) {
            my $island = Ikariam::Island->retrieve($city->island);
            my $user = Ikariam::User->retrieve($city->user);
            printf("%s (%d) \"%s\" %d [%d,%d] http://%s/index.php?view=island&id=%d&selectCity=%d\n",
                $user->name, $user->score,
                $city->cityname, $city->citylevel, 
                $island->x, $island->y,
                $::server,
                $island->id,
                $city->cityId
            );
        }
} else {
    # 依照距離列表
    foreach my $island (@islands)
    {
        printf("%d [%d:%d] %s %s http://%s/index.php?view=island&id=%d%s\n",
            (abs($x-$island->x) + abs($y-$island->y)), # minutes ?
            $island->x, $island->y,
            $tradegoodText[$island->tradegood],
            $wonderText[$island->wonder],
            $::server,
            $island->id,
        );
    }
}