Mercurial > eagle-eye
annotate planner.pl @ 334:65f45552060e
fixed travel time
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Thu, 12 Feb 2009 02:48:45 +0800 |
parents | 0db3e2bcbd0f |
children | 85d60a0569bf |
rev | line source |
---|---|
271 | 1 #!/usr/bin/perl |
2 use Ikariam; | |
3 use Data::Dumper; | |
4 use Decision::ParseTree q{ParseTree}; | |
5 use YAML qw/LoadFile Dump DumpFile/; | |
301
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
6 use Getopt::Std; |
271 | 7 |
8 Ikariam::Cities->has_a(island => 'Ikariam::Island'); | |
9 | |
10 my $army = { | |
11 "Slinger" => 301, | |
12 "Swordsman" => 302, | |
13 "Phalanx" => 303, | |
14 "Ram" => 307, | |
15 "Archer" => 313, | |
16 "Catapult" => 306, | |
17 "Gunsman" => 304, | |
18 "Mortar" => 305, | |
19 "SteamGiant" => 308, | |
20 "Gyrocopter" => 312, | |
21 "Bombardier" => 309, | |
22 "Doctor" => 311, | |
23 "Cook" => 310, | |
24 }; | |
25 | |
26 my $fleet = { | |
27 "CargoShip" => 201, | |
28 "Ram-Ship" => 210, | |
29 "BallistaShip" => 213, | |
30 "Flamethrower" => 211, | |
31 "CatapultShip" => 214, | |
32 "MortarShip" => 215, | |
303 | 33 "PaddleWheelRam" => 216, |
271 | 34 "DivingBoat" => 212, |
35 }; | |
36 | |
37 # return minutes. | |
38 sub travelTime { | |
39 my ($x1, $y1, $x2, $y2, $speed) = @_; | |
334 | 40 $speed = 60 unless(defined($speed)); |
41 if($x1 == $x2 && $y1 == $y2) { | |
42 return 600/$speed; | |
43 } else { | |
44 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed)); | |
45 } | |
271 | 46 } |
47 | |
334 | 48 # |
271 | 49 package main; |
301
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
50 getopts('w'); |
271 | 51 if($#ARGV < 2) { |
52 die("Usage: %s targetCity navyCity armyCity wingman1.. wingman2..\n"); | |
53 } | |
54 my $targetCityId = shift(@ARGV); | |
55 my $navyCity = shift(@ARGV); | |
56 my $armyCity = shift(@ARGV); | |
57 my @wingman = @ARGV; | |
58 | |
59 my $targetCity = Ikariam::Cities->retrieve($targetCityId); | |
60 | |
61 | |
62 # NAVY | |
63 my $city = LoadFile(sprintf("city-%s-dump.yaml", $navyCity)); | |
327 | 64 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 33) + 25; |
271 | 65 $city->{type} = "navy"; |
66 push (@cities, $city); | |
67 | |
68 # ARMY | |
69 my $city = LoadFile(sprintf("city-%s-dump.yaml", $armyCity)); | |
334 | 70 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) + 5; |
271 | 71 $city->{type} = "army"; |
72 push (@cities, $city); | |
73 | |
74 # wingman, army | |
301
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
75 foreach my $i (0..$#wingman) { |
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
76 my $cityId = $wingman[$i]; |
271 | 77 my $city = LoadFile(sprintf("city-%s-dump.yaml", $cityId)); |
307
2972852a4ee5
added comment onn wingman
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
303
diff
changeset
|
78 $city->{type} = "wingman" . ($i+1); |
301
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
79 if(defined($opt_w)) { |
334 | 80 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) - ($i * 20 + 20); |
301
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
81 } else { |
334 | 82 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); |
301
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
83 } |
271 | 84 push (@cities, $city); |
85 } | |
86 | |
87 @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities); | |
88 | |
89 | |
90 # print the code. | |
91 print <<EOF; | |
92 #!/usr/bin/perl | |
93 use strict; | |
94 use Ikariam; | |
95 use Data::Dumper; | |
96 package main; | |
97 my \$ikariam = new Ikariam(\$::server, \$::user, \$::pass); | |
98 EOF | |
99 | |
276
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
100 printf ("# %s %s [%s:%s]\n", $targetCity->owner, $targetCity->cityname, $targetCity->island->x, $targetCity->island->y); |
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
101 printf ("# http://%s/index.php?view=island&id=%d&selectCity=%d\n", $::server, $targetCity->island->id, $targetCity->id); |
271 | 102 |
103 for(my $i = ($#cities + 1) ; $i-- ; $i < 0 ) { | |
104 | |
276
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
105 if($i ne $#cities) { |
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
106 # TODO, 計算港口速度 |
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
107 # 減掉 cities[$i+1]->buliding->port 的速度 |
271 | 108 printf("sleep(%d*60);\n", |
109 ($cities[$i+1]->{distance} - $cities[$i]->{distance})); | |
110 } | |
276
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
111 printf("\n# %s %s %dm\n", $cities[$i]->{name}, $cities[$i]->{type}, $cities[$i]->{distance}); |
285
c864134ebe3e
refined output format
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
276
diff
changeset
|
112 printf("# ActionPoint %d/%d\n", $cities[$i]->{actionPoints}, $cities[$i]->{maxActionPoints}); |
271 | 113 |
114 printf('$ikariam->login;' . "\n"); | |
115 if($cities[$i]->{type} eq "navy") { | |
116 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); | |
117 printf('$ikariam->blockadeCity(%d, {' . "\n", $targetCity->id); | |
285
c864134ebe3e
refined output format
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
276
diff
changeset
|
118 printf("\tblockadeDuration => 2*60*60," . "\n"); |
271 | 119 while (my ($k, $v) = each(%{$cities[$i]->{fleet}})) { |
120 if($v > 0) { | |
285
c864134ebe3e
refined output format
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
276
diff
changeset
|
121 printf("\tcargo_fleet_%s => %s, # %s \n", $fleet->{$k}, $v, $k); |
271 | 122 } |
123 } | |
124 printf('});' . "\n", $cities[$i]->{id}); | |
125 } else { | |
126 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); | |
127 printf('$ikariam->plunderCity(%d, {' . "\n", $targetCity->id); | |
128 while (my ($k, $v) = each(%{$cities[$i]->{army}})) { | |
129 if($v > 0) { | |
285
c864134ebe3e
refined output format
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
276
diff
changeset
|
130 printf("\tcargo_army_%s => %s, # %s \n", $army->{$k}, $v, $k); |
271 | 131 } |
132 } | |
327 | 133 printf("\ttransporter => %s, # transporter\n", $cities[$i]->{transporters}->{avail}); |
271 | 134 printf('});' . "\n", $cities[$i]->{id}); |
135 } | |
136 printf('$ikariam->logout;' . "\n"); | |
137 } |