changeset 32:b18369979b58

looking for available land.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sat, 11 Oct 2008 01:22:16 +0800
parents e992576ac97c
children d183277b4d93
files freeland.pl
diffstat 1 files changed, 56 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/freeland.pl	Sat Oct 11 01:22:16 2008 +0800
@@ -0,0 +1,56 @@
+#!/usr/bin/perl
+use strict;
+use Ikariam;
+use Data::Dumper;
+
+package main;
+
+if($#ARGV != 1) {
+    die("Usage: $0 x y\n");
+}
+my ($x, $y) = @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 == 2
+    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://s2.ikariam.tw/index.php?view=island&id=%d&selectCity=%d\n",
+                $user->name, $user->score,
+                $city->cityname, $city->citylevel, 
+                $island->x, $island->y,
+                $island->id,
+                $city->cityId
+            );
+        }
+} else {
+    foreach my $island (@islands)
+    {
+        printf("[%d:%d] http://s2.ikariam.tw/index.php?view=island&id=%d%s\n",
+            $island->x, $island->y,
+            $island->id,
+        );
+    }
+}