Mercurial > eagle-eye
comparison enemy.pl @ 335:c4ef89a74128
fixed timing
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Thu, 12 Feb 2009 03:24:41 +0800 |
parents | efffa408eec5 |
children | ff816ffffbd8 |
comparison
equal
deleted
inserted
replaced
332:118605b58d09 | 335:c4ef89a74128 |
---|---|
11 | 11 |
12 Ikariam::User->has_many(cities => 'Ikariam::Cities'); | 12 Ikariam::User->has_many(cities => 'Ikariam::Cities'); |
13 | 13 |
14 sub travelTime { | 14 sub travelTime { |
15 my ($x1, $y1, $x2, $y2, $speed) = @_; | 15 my ($x1, $y1, $x2, $y2, $speed) = @_; |
16 $speed = 20 unless(defined($speed)); | 16 $speed = 50 unless(defined($speed)); |
17 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed)); | 17 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed)); |
18 } | 18 } |
19 | 19 |
20 sub travelMatrix { | 20 sub travelMatrix { |
21 my $userName = shift; | 21 my $userName = shift; |
66 | 66 |
67 if(my $island = Ikariam::Island->retrieve($islandId)) { | 67 if(my $island = Ikariam::Island->retrieve($islandId)) { |
68 my @cities = (); | 68 my @cities = (); |
69 foreach (glob("city-*-dump.yaml")) { | 69 foreach (glob("city-*-dump.yaml")) { |
70 my $city = LoadFile($_); | 70 my $city = LoadFile($_); |
71 $city->{distance} = travelTime($island->x, $island->y, $city->{island}->{x}, $city->{island}->{y}, 20); | 71 $city->{distance} = travelTime($island->x, $island->y, $city->{island}->{x}, $city->{island}->{y}, 50); |
72 push (@cities, $city); | 72 push (@cities, $city); |
73 } | 73 } |
74 @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities); | 74 @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities); |
75 | 75 |
76 my $n = $#cities; | 76 my $n = $#cities; |
77 for my $x (0..$n) { | 77 for my $x (0..$n) { |
78 printf("%s (%d)\t- ", $cities[$x]->{name}, $cities[$x]->{id}); | 78 printf("%s (%d)\t- ", $cities[$x]->{name}, $cities[$x]->{id}); |
79 printf("Land %3d Ship %3d Catapult %3d Ram %3d\n", | 79 printf("Land %3d Ship %3d Catapult %3d Ram %3d\n", |
80 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y), | 80 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 50), |
81 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 8), | 81 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 33), |
82 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 6), | |
83 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 10), | |
84 ); | 82 ); |
85 } | 83 } |
86 } | 84 } |
87 } | 85 } |
88 | 86 |