Mercurial > eagle-eye
annotate planner.pl @ 369:fb3cfa5533ac
merged
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Thu, 05 Mar 2009 17:36:03 +0800 |
parents | 95148fdc1021 |
children | 0ec57ac68a4c |
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; |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
7 use POSIX qw(strftime); |
271 | 8 |
9 Ikariam::Cities->has_a(island => 'Ikariam::Island'); | |
10 | |
11 my $army = { | |
12 "Slinger" => 301, | |
13 "Swordsman" => 302, | |
14 "Phalanx" => 303, | |
15 "Ram" => 307, | |
16 "Archer" => 313, | |
17 "Catapult" => 306, | |
18 "Gunsman" => 304, | |
19 "Mortar" => 305, | |
20 "SteamGiant" => 308, | |
21 "Gyrocopter" => 312, | |
22 "Bombardier" => 309, | |
23 "Doctor" => 311, | |
24 "Cook" => 310, | |
25 }; | |
26 | |
27 my $fleet = { | |
28 "CargoShip" => 201, | |
29 "Ram-Ship" => 210, | |
30 "BallistaShip" => 213, | |
31 "Flamethrower" => 211, | |
32 "CatapultShip" => 214, | |
33 "MortarShip" => 215, | |
303 | 34 "PaddleWheelRam" => 216, |
271 | 35 "DivingBoat" => 212, |
36 }; | |
37 | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
38 |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
39 sub calcTime { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
40 my ($gooff, $travelTime) = @_; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
41 return (sprintf("%s-%s", strftime("%H:%M", localtime(time+$gooff*60)), strftime("%H:%M", localtime(time+($gooff+$travelTime)*60)))); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
42 } |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
43 |
271 | 44 # return minutes. |
45 sub travelTime { | |
46 my ($x1, $y1, $x2, $y2, $speed) = @_; | |
334 | 47 $speed = 60 unless(defined($speed)); |
48 if($x1 == $x2 && $y1 == $y2) { | |
49 return 600/$speed; | |
50 } else { | |
51 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed)); | |
52 } | |
271 | 53 } |
54 | |
343
85d60a0569bf
fixed travel time for 0.3.0
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
334
diff
changeset
|
55 |
271 | 56 package main; |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
57 |
271 | 58 if($#ARGV < 2) { |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
59 die("Usage: %s -n 1 -a 1 -v 21 targetCity navyCity armyCity wingman1.. wingman2..\n"); |
271 | 60 } |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
61 getopts('wa:n:v:'); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
62 $opt_n = defined($opt_n) ? $opt_n : 1; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
63 $opt_a = defined($opt_a) ? $opt_a : 1; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
64 my $vanguard = defined($opt_v) ? $opt_v : 21; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
65 |
271 | 66 my $targetCityId = shift(@ARGV); |
67 my $targetCity = Ikariam::Cities->retrieve($targetCityId); | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
68 my @cities; |
271 | 69 # NAVY |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
70 foreach my $i (1..$opt_n) { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
71 my $navyCity = shift(@ARGV); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
72 my $city = LoadFile(sprintf("city-%s-dump.yaml", $navyCity)); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
73 $city->{travelTime} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 33); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
74 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 33) + $vanguard; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
75 if($i == 1) { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
76 $city->{distance} += 8; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
77 } else { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
78 $city->{distance} += 5; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
79 } |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
80 $city->{type} = "navy"; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
81 $city->{queue} = "navy" . $i; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
82 push (@cities, $city); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
83 } |
271 | 84 |
85 # ARMY | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
86 foreach my $i (1..$opt_a) { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
87 my $armyCity = shift(@ARGV); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
88 my $city = LoadFile(sprintf("city-%s-dump.yaml", $armyCity)); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
89 $city->{travelTime} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
90 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) + $vanguard; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
91 if($i == 1) { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
92 $city->{distance} += 5; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
93 } else { |
368
95148fdc1021
added time counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
365
diff
changeset
|
94 $city->{distance} += 1; |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
95 } |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
96 $city->{type} = "army"; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
97 $city->{queue} = "army" . $i; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
98 push (@cities, $city); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
99 } |
271 | 100 |
101 # wingman, army | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
102 while(defined($cityId = shift(@ARGV))) { |
271 | 103 my $city = LoadFile(sprintf("city-%s-dump.yaml", $cityId)); |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
104 $city->{type} = "wingman"; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
105 $city->{queue} = "wingman"; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
106 $city->{travelTime} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
107 $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
|
108 if(defined($opt_w)) { |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
109 $city->{distance} -= ($i * 20 + 20); |
301
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
110 } |
271 | 111 push (@cities, $city); |
112 } | |
113 | |
114 # print the code. | |
115 print <<EOF; | |
116 #!/usr/bin/perl | |
117 use strict; | |
118 use Ikariam; | |
119 use Data::Dumper; | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
120 use POSIX qw(strftime); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
121 |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
122 sub calcTime { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
123 my (\$gooff, \$travelTime) = \@_; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
124 return (sprintf("%s-%s", strftime("%H:%M", localtime(time+\$gooff*60)), strftime("%H:%M", localtime(time+(\$gooff+\$travelTime)*60)))); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
125 } |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
126 |
271 | 127 package main; |
128 my \$ikariam = new Ikariam(\$::server, \$::user, \$::pass); | |
129 EOF | |
130 | |
276
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
131 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
|
132 printf ("# http://%s/index.php?view=island&id=%d&selectCity=%d\n", $::server, $targetCity->island->id, $targetCity->id); |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
133 printf("#\n"); |
368
95148fdc1021
added time counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
365
diff
changeset
|
134 printf("my \$delay = 0; # minutes\n"); |
271 | 135 |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
136 @cities = sort { $b->{distance} <=> $a->{distance}; } (@cities); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
137 foreach my $i (0..$#cities) { |
368
95148fdc1021
added time counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
365
diff
changeset
|
138 printf('printf("%%s %s %s %s %sm\n", calcTime(%s - %s + $delay, %s));', |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
139 $cities[$i]->{queue}, $cities[$i]->{name}, $cities[$i]->{id}, $cities[$i]->{travelTime}, |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
140 $cities[0]->{distance}, $cities[$i]->{distance}, $cities[$i]->{travelTime}); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
141 printf(" # %s\n", calcTime($cities[0]->{distance} - $cities[$i]->{distance}, $cities[$i]->{travelTime})); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
142 } |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
143 printf("printf('Press Enter to start...');\n"); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
144 printf("<STDIN>;\n"); |
271 | 145 |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
146 foreach my $i (0..$#cities) { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
147 if($i ne 0) { |
276
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
148 # TODO, 計算港口速度 |
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
149 # 減掉 cities[$i+1]->buliding->port 的速度 |
271 | 150 printf("sleep(%d*60);\n", |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
151 ($cities[$i-1]->{distance} - $cities[$i]->{distance})); |
271 | 152 } |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
153 |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
154 printf("\n# %s %s %dm\n", $cities[$i]->{name}, $cities[$i]->{queue}, $cities[$i]->{travelTime}); |
285
c864134ebe3e
refined output format
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
276
diff
changeset
|
155 printf("# ActionPoint %d/%d\n", $cities[$i]->{actionPoints}, $cities[$i]->{maxActionPoints}); |
271 | 156 |
157 printf('$ikariam->login;' . "\n"); | |
158 if($cities[$i]->{type} eq "navy") { | |
159 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); | |
160 printf('$ikariam->blockadeCity(%d, {' . "\n", $targetCity->id); | |
358
58351fccf619
default unit number is now 0, for avoid stupid thing
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
354
diff
changeset
|
161 printf("\tblockadeDuration => 8*60*60," . "\n"); |
271 | 162 while (my ($k, $v) = each(%{$cities[$i]->{fleet}})) { |
163 if($v > 0) { | |
358
58351fccf619
default unit number is now 0, for avoid stupid thing
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
354
diff
changeset
|
164 printf("\tcargo_fleet_%s => %s, # %s (%d)\n", $fleet->{$k}, 0, $k, $v); |
271 | 165 } |
166 } | |
167 printf('});' . "\n", $cities[$i]->{id}); | |
168 } else { | |
169 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); | |
170 printf('$ikariam->plunderCity(%d, {' . "\n", $targetCity->id); | |
171 while (my ($k, $v) = each(%{$cities[$i]->{army}})) { | |
172 if($v > 0) { | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
173 printf("\tcargo_army_%s => %s, # %s (%d)\n", $army->{$k}, $v, $k, $v); |
271 | 174 } |
175 } | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
176 printf("\ttransporter => 0, # transporter (%s)\n", $cities[$i]->{transporters}->{avail}); |
271 | 177 printf('});' . "\n", $cities[$i]->{id}); |
178 } | |
179 printf('$ikariam->logout;' . "\n"); | |
180 } |