annotate victim_travel.pl @ 357:f9a6b226fb79

capture scores names nothing, fixed the risk of spy
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 15 Feb 2009 15:00:09 +0800
parents bf59bef30dfc
children
rev   line source
352
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
1 #!/usr/bin/perl
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
2 use strict;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
3
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
4 use Data::Dumper;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
5 use Ikariam;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
6 use YAML qw/LoadFile/;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
7
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
8 Ikariam::User->has_many(cities => 'Ikariam::Cities');
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
9
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
10 sub travelTime {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11 my ($x1, $y1, $x2, $y2, $speed) = @_;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
12 $speed = 60 unless(defined($speed));
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
13 if($x1 == $x2 && $y1 == $y2) {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
14 return 600/$speed;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
15 } else {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
16 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed));
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
17 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
18 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
19
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
20 sub myTownToVicim {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
21 my $islandId = shift;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
22
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
23 my @cities = ();
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
24 foreach (glob("city-*-dump.yaml")) {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
25 my $city = LoadFile($_);
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
26 push (@cities, $city);
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
27 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28 my $n = $#cities;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30 if(my $island = Ikariam::Island->retrieve($islandId)) {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 for my $x (0..$n) {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 printf("%s\t- ", $cities[$x]->{name});
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
33 printf("Land %3d Ship %3d Catapult %3d Ram %3d\n",
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
34 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 60),
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
35 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 33),
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 26),
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
37 travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $island->x, $island->y, 40),
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
38 );
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
39 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
40 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
41 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
42
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
43 sub cityToIsland {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 my (@city, $island);
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47 package main;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
48
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
49 my $userName = $ARGV[0];
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
50 my @cities = ();
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
51 if(my $user = Ikariam::User->retrieve(name => $userName)) {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
52
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
53 foreach my $target ($user->cities) {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
54 my $island = Ikariam::Island->retrieve($target->island);
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
55 my $city;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
56 $city->{id} = $target->id;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
57 $city->{name} = $target->cityname;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
58 $city->{island}->{id} = $island->id;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
59 $city->{island}->{x} = $island->x;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
60 $city->{island}->{y} = $island->y;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
61
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
62 push (@cities, $city);
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
63 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
64 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
65
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
66 my $n = $#cities;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
67
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
68 # Print them out.
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
69 # header
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
70 printf("Defence\n");
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
71 printf(" %5s ", undef);
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
72 for my $y (0..$n) {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
73 printf ("%5s ", $cities[$y]->{id});
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
74 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
75 print "\n";
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
76
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
77 # body
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
78 for my $x (0..$n) {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
79 printf(" %5s ", $cities[$x]->{id});
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
80 my $total = 0;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
81 for my $y (0..$n) {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
82 my $t = travelTime($cities[$x]->{island}->{x}, $cities[$x]->{island}->{y}, $cities[$y]->{island}->{x}, $cities[$y]->{island}->{y});
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
83 printf("%5s ", $t);
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
84 $total += $t;
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
85 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
86 printf(" %s", $cities[$x]->{name});
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
87 printf("\n");
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
88 }
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
89 printf("\n");
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
90
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
91
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
92 for my $i (0..$n) {
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
93 printf("To: %s [%d:%d] http://%s/index.php?view=island&id=%s&selectCity=%s\n",
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
94 $cities[$i]->{name}, $cities[$i]->{island}->{x}, $cities[$i]->{island}->{y}, $::server, $cities[$i]->{island}->{id}, $cities[$i]->{id});
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
95 myTownToVicim($cities[$i]->{island}->{id});
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
96 printf("\n");
bf59bef30dfc scripts for counting travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
97 }