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