changeset 272:3730817e3079

show travel time from my cities to enemy's cities
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Mon, 01 Dec 2008 14:15:01 +0800
parents 0ed1b3e72e65
children f81c4f9d267f
files enemy.pl
diffstat 1 files changed, 38 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/enemy.pl	Mon Dec 01 01:02:36 2008 +0800
+++ b/enemy.pl	Mon Dec 01 14:15:01 2008 +0800
@@ -2,32 +2,61 @@
 use strict;
 use Ikariam;
 use Data::Dumper;
+use YAML qw/LoadFile/;
 
 package main;
 my @tradegoodText = qw/NULL 葡萄酒 大理石 水晶 硫磺/;
 my @wonderText = qw/NULL 赫菲斯拓斯的熔爐 蓋亞的神殿 狄奧尼索斯的花園 雅典娜的神殿 赫秘士的神殿 阿瑞斯的要塞 波賽頓的神殿 克羅瑟斯的神殿/;
 
+Ikariam::User->has_many(cities => 'Ikariam::Cities');
+
+sub travelTime {
+    my ($x1, $y1, $x2, $y2, $speed) = @_;
+    $speed = 20 unless(defined($speed));
+    return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed));
+}
+
+sub myTownToVicim {
+    my $islandId = shift;
+
+    my @cities = ();
+    foreach (glob("city-*-dump.yaml")) {
+        my $city = LoadFile($_);
+        push (@cities, $city);
+    }
+    my $n = $#cities;
+
+    if(my $island = Ikariam::Island->retrieve($islandId)) {
+        for my $x (0..$n) {
+            printf("%s\t- ", $cities[$x]->{name});
+            printf("Land %3d Ship %3d Catapult %3d Ram %3d\n", 
+                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y),
+                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 8),
+                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 6),
+                    travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 10),
+                  );
+        }
+    }
+}
+
+package main;
+
 if($#ARGV != 0) {
     die("Usage: $0 nickname\n");
 }
 
-# system('perl scores.pl ' . $ARGV[0]);
-
-Ikariam::User->has_many(cities => 'Ikariam::Cities');
 my ($u) = Ikariam::User->search('name' => $ARGV[0]);
 if(defined($u)) {
     foreach my $i (qw/name score trader_score_secondary army_score_main ally/) {
         printf("%s: %s\n", $i, $u->get($i));
     }
     printf("\nCities\n");
-    # print Dumper($u->_data_hash);
     foreach my $city ($u->cities) {
         my $island = Ikariam::Island->retrieve($city->island);
         my $capture = $city->citylevel * ($city->citylevel - 1) * $u->trader_score_secondary / 10000;
 
         printf("Name: %s\n", $city->cityname);
-        if(defined($city->status))
-        {
+        if(defined($city->status)) {
             printf("Status: <<<%s>>>\n", $city->status);
         }
         printf("Level: %s\n", $city->citylevel);
@@ -36,9 +65,9 @@
             $island->x, $island->y, $::server, $island->id, $city->cityId);
         printf("Tradegood: %s\n", $tradegoodText[$island->tradegood]);
         printf("Wonder: %s\n", $wonderText[$island->wonder]);
-        printf("capture score: %d\n\n", $capture);
-        # print Dumper($island->_data_hash);
-        # print Dumper($city->_data_hash);
+        printf("Capture: %d\n", $capture);
+        myTownToVicim($island->id);
+        printf("\n");
     }
     print "-"x80 . "\n";
 }