comparison freeland.pl @ 32:b18369979b58

looking for available land.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sat, 11 Oct 2008 01:22:16 +0800
parents
children f25d13153501
comparison
equal deleted inserted replaced
31:e992576ac97c 32:b18369979b58
1 #!/usr/bin/perl
2 use strict;
3 use Ikariam;
4 use Data::Dumper;
5
6 package main;
7
8 if($#ARGV != 1) {
9 die("Usage: $0 x y\n");
10 }
11 my ($x, $y) = @ARGV;
12
13 my @location = (($x + 6), ($x - 6), ($y + 6), ($y - 6));
14
15 # 找空位
16 Ikariam::Cities->set_sql(lamers => qq {
17 SELECT cities.cityId
18 FROM user, cities
19 WHERE user.id == cities.user
20 AND user.score <= 1000
21 AND cities.status != 'v'
22 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? AND tradegood == 2)
23 }
24 );
25
26 my @islands = Ikariam::Island->retrieve_from_sql(qq{
27 tradegood == 2
28 AND people < 16
29 AND x <= $location[0]
30 AND x >= $location[1]
31 AND y <= $location[2]
32 AND y >= $location[3]
33 });
34
35 if($#islands == -1) {
36 my @cities = Ikariam::Cities->search_lamers(@location);
37 foreach my $city (@cities) {
38 my $island = Ikariam::Island->retrieve($city->island);
39 my $user = Ikariam::User->retrieve($city->user);
40 printf("%s (%d) \"%s\" %d [%d,%d] http://s2.ikariam.tw/index.php?view=island&id=%d&selectCity=%d\n",
41 $user->name, $user->score,
42 $city->cityname, $city->citylevel,
43 $island->x, $island->y,
44 $island->id,
45 $city->cityId
46 );
47 }
48 } else {
49 foreach my $island (@islands)
50 {
51 printf("[%d:%d] http://s2.ikariam.tw/index.php?view=island&id=%d%s\n",
52 $island->x, $island->y,
53 $island->id,
54 );
55 }
56 }