changeset 324:7077be1a14d5

count travel time
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 11 Feb 2009 21:04:27 +0800
parents 3c6e78faa0d4
children 1f5cd5c4f6b6 0db3e2bcbd0f
files sheep.pl
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/sheep.pl	Sun Feb 08 15:18:51 2009 +0800
+++ b/sheep.pl	Wed Feb 11 21:04:27 2009 +0800
@@ -40,6 +40,12 @@
     }
 );
 
+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 listSheeps
 {
     my @sheeps = @_;
@@ -77,7 +83,8 @@
             # $capture = $capture - ($sheep->army_score_main*100);
                         
             $line = sprintf("%d %s score %d army %d risk %d %s/%s,", 
-                $capture,
+                travelTime($::x, $::y, $island->x, $island->y),
+                # $capture,
                 $c->status, $sheep->score, $sheep->army_score_main, $c->risk, $sheep->name, $sheep->ally);
 
             $line .= sprintf("\"%s\" %d [%d,%d] %s http://%s/index.php?view=island&id=%d&selectCity=%d\n",
@@ -97,7 +104,7 @@
 __MAIN__:
 
 if($#ARGV != 1) { die("Usage: $0 x y\n"); }
-my ($x, $y) = @ARGV;
+our ($x, $y) = @ARGV;
 
 listSheeps(Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6)));
 # listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6)));