comparison enemy.pl @ 333:2ca2c4c49901

fixed travel time
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 12 Feb 2009 02:47:58 +0800
parents efffa408eec5
children ff816ffffbd8
comparison
equal deleted inserted replaced
331:6eac624efc80 333:2ca2c4c49901
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 = 60 unless(defined($speed));
17 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed)); 17 if($x1 == $x2 && $y1 == $y2) {
18 return 600/$speed;
19 } else {
20 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed));
21 }
18 } 22 }
19 23
20 sub travelMatrix { 24 sub travelMatrix {
21 my $userName = shift; 25 my $userName = shift;
22 my @cities = (); 26 my @cities = ();
66 70
67 if(my $island = Ikariam::Island->retrieve($islandId)) { 71 if(my $island = Ikariam::Island->retrieve($islandId)) {
68 my @cities = (); 72 my @cities = ();
69 foreach (glob("city-*-dump.yaml")) { 73 foreach (glob("city-*-dump.yaml")) {
70 my $city = LoadFile($_); 74 my $city = LoadFile($_);
71 $city->{distance} = travelTime($island->x, $island->y, $city->{island}->{x}, $city->{island}->{y}, 20); 75 $city->{distance} = travelTime($island->x, $island->y, $city->{island}->{x}, $city->{island}->{y}, 60);
72 push (@cities, $city); 76 push (@cities, $city);
73 } 77 }
74 @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities); 78 @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities);
75 79
76 my $n = $#cities; 80 my $n = $#cities;
77 for my $x (0..$n) { 81 for my $x (0..$n) {
78 printf("%s (%d)\t- ", $cities[$x]->{name}, $cities[$x]->{id}); 82 printf("%s (%d)\t- ", $cities[$x]->{name}, $cities[$x]->{id});
79 printf("Land %3d Ship %3d Catapult %3d Ram %3d\n", 83 printf("Land %3d Ship %3d Catapult %3d Ram %3d\n",
80 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y), 84 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 60),
81 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 8), 85 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), 86 # 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), 87 # travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 10),
84 ); 88 );
85 } 89 }
86 } 90 }
87 } 91 }
88 92