Mercurial > eagle-eye
comparison enemy.pl @ 336:ff816ffffbd8
fixed timing issue
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Thu, 12 Feb 2009 03:25:20 +0800 |
parents | c4ef89a74128 2ca2c4c49901 |
children | 6c03c2c80429 |
comparison
equal
deleted
inserted
replaced
335:c4ef89a74128 | 336:ff816ffffbd8 |
---|---|
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 = 50 unless(defined($speed)); | 16 $speed = 20 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}, 50); | 71 $city->{distance} = travelTime($island->x, $island->y, $city->{island}->{x}, $city->{island}->{y}, 20); |
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, 50), | 80 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y), |
81 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 33), | 81 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 8), |
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), | |
82 ); | 84 ); |
83 } | 85 } |
84 } | 86 } |
85 } | 87 } |
86 | 88 |