changeset 337:025a36717f2c

fixed timing
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 12 Feb 2009 03:25:32 +0800
parents ff816ffffbd8
children 824f949bc484
files planner.pl
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/planner.pl	Thu Feb 12 03:25:20 2009 +0800
+++ b/planner.pl	Thu Feb 12 03:25:32 2009 +0800
@@ -37,10 +37,15 @@
 # return minutes.
 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));
+    $speed = 60 unless(defined($speed));
+    if($x1 == $x2 && $y1 == $y2) {
+        return 600/$speed;
+    } else {
+        return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed));
+    }
 }
 
+#
 package main;
 getopts('w');
 if($#ARGV < 2) {
@@ -62,7 +67,7 @@
 
 # ARMY
 my $city = LoadFile(sprintf("city-%s-dump.yaml", $armyCity));
-$city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 50) + 5;
+$city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) + 5;
 $city->{type} = "army";
 push (@cities, $city);
 
@@ -72,9 +77,9 @@
     my $city = LoadFile(sprintf("city-%s-dump.yaml", $cityId));
     $city->{type} = "wingman" . ($i+1);
     if(defined($opt_w)) {
-        $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 50) - ($i * 20 + 20);
+        $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) - ($i * 20 + 20);
     } else {
-        $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 50);
+        $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60);
     }
     push (@cities, $city);
 }