comparison enemy.pl @ 272:3730817e3079

show travel time from my cities to enemy's cities
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Mon, 01 Dec 2008 14:15:01 +0800
parents 5f9bb3042d0c
children f81c4f9d267f
comparison
equal deleted inserted replaced
271:0ed1b3e72e65 272:3730817e3079
1 #!/usr/bin/perl 1 #!/usr/bin/perl
2 use strict; 2 use strict;
3 use Ikariam; 3 use Ikariam;
4 use Data::Dumper; 4 use Data::Dumper;
5 use YAML qw/LoadFile/;
5 6
6 package main; 7 package main;
7 my @tradegoodText = qw/NULL 葡萄酒 大理石 水晶 硫磺/; 8 my @tradegoodText = qw/NULL 葡萄酒 大理石 水晶 硫磺/;
8 my @wonderText = qw/NULL 赫菲斯拓斯的熔爐 蓋亞的神殿 狄奧尼索斯的花園 雅典娜的神殿 赫秘士的神殿 阿瑞斯的要塞 波賽頓的神殿 克羅瑟斯的神殿/; 9 my @wonderText = qw/NULL 赫菲斯拓斯的熔爐 蓋亞的神殿 狄奧尼索斯的花園 雅典娜的神殿 赫秘士的神殿 阿瑞斯的要塞 波賽頓的神殿 克羅瑟斯的神殿/;
9 10
11 Ikariam::User->has_many(cities => 'Ikariam::Cities');
12
13 sub travelTime {
14 my ($x1, $y1, $x2, $y2, $speed) = @_;
15 $speed = 20 unless(defined($speed));
16 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed));
17 }
18
19 sub myTownToVicim {
20 my $islandId = shift;
21
22 my @cities = ();
23 foreach (glob("city-*-dump.yaml")) {
24 my $city = LoadFile($_);
25 push (@cities, $city);
26 }
27 my $n = $#cities;
28
29 if(my $island = Ikariam::Island->retrieve($islandId)) {
30 for my $x (0..$n) {
31 printf("%s\t- ", $cities[$x]->{name});
32 printf("Land %3d Ship %3d Catapult %3d Ram %3d\n",
33 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y),
34 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 8),
35 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 6),
36 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 10),
37 );
38 }
39 }
40 }
41
42 package main;
43
10 if($#ARGV != 0) { 44 if($#ARGV != 0) {
11 die("Usage: $0 nickname\n"); 45 die("Usage: $0 nickname\n");
12 } 46 }
13 47
14 # system('perl scores.pl ' . $ARGV[0]);
15
16 Ikariam::User->has_many(cities => 'Ikariam::Cities');
17 my ($u) = Ikariam::User->search('name' => $ARGV[0]); 48 my ($u) = Ikariam::User->search('name' => $ARGV[0]);
18 if(defined($u)) { 49 if(defined($u)) {
19 foreach my $i (qw/name score trader_score_secondary army_score_main ally/) { 50 foreach my $i (qw/name score trader_score_secondary army_score_main ally/) {
20 printf("%s: %s\n", $i, $u->get($i)); 51 printf("%s: %s\n", $i, $u->get($i));
21 } 52 }
22 printf("\nCities\n"); 53 printf("\nCities\n");
23 # print Dumper($u->_data_hash);
24 foreach my $city ($u->cities) { 54 foreach my $city ($u->cities) {
25 my $island = Ikariam::Island->retrieve($city->island); 55 my $island = Ikariam::Island->retrieve($city->island);
26 my $capture = $city->citylevel * ($city->citylevel - 1) * $u->trader_score_secondary / 10000; 56 my $capture = $city->citylevel * ($city->citylevel - 1) * $u->trader_score_secondary / 10000;
27 57
28 printf("Name: %s\n", $city->cityname); 58 printf("Name: %s\n", $city->cityname);
29 if(defined($city->status)) 59 if(defined($city->status)) {
30 {
31 printf("Status: <<<%s>>>\n", $city->status); 60 printf("Status: <<<%s>>>\n", $city->status);
32 } 61 }
33 printf("Level: %s\n", $city->citylevel); 62 printf("Level: %s\n", $city->citylevel);
34 printf("Island: %s\n", $island->name); 63 printf("Island: %s\n", $island->name);
35 printf("Location: [%s:%s] http://%s/index.php?view=island&id=%s&selectCity=%d\n", 64 printf("Location: [%s:%s] http://%s/index.php?view=island&id=%s&selectCity=%d\n",
36 $island->x, $island->y, $::server, $island->id, $city->cityId); 65 $island->x, $island->y, $::server, $island->id, $city->cityId);
37 printf("Tradegood: %s\n", $tradegoodText[$island->tradegood]); 66 printf("Tradegood: %s\n", $tradegoodText[$island->tradegood]);
38 printf("Wonder: %s\n", $wonderText[$island->wonder]); 67 printf("Wonder: %s\n", $wonderText[$island->wonder]);
39 printf("capture score: %d\n\n", $capture); 68 printf("Capture: %d\n", $capture);
40 # print Dumper($island->_data_hash); 69 myTownToVicim($island->id);
41 # print Dumper($city->_data_hash); 70 printf("\n");
42 } 71 }
43 print "-"x80 . "\n"; 72 print "-"x80 . "\n";
44 } 73 }