Mercurial > eagle-eye
annotate planner.pl @ 377:5d6f429e5f19 tip
fixed a typo.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Tue, 14 Apr 2009 17:16:43 +0800 |
parents | 0ec57ac68a4c |
children |
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 } |
375
0ec57ac68a4c
one more parameter for ship speed.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
368
diff
changeset
|
61 getopts('wa:n:v:s:'); |
365
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; |
375
0ec57ac68a4c
one more parameter for ship speed.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
368
diff
changeset
|
64 $opt_s = defined($opt_s) ? $opt_s : 33; |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
65 my $vanguard = defined($opt_v) ? $opt_v : 21; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
66 |
271 | 67 my $targetCityId = shift(@ARGV); |
68 my $targetCity = Ikariam::Cities->retrieve($targetCityId); | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
69 my @cities; |
271 | 70 # NAVY |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
71 foreach my $i (1..$opt_n) { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
72 my $navyCity = shift(@ARGV); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
73 my $city = LoadFile(sprintf("city-%s-dump.yaml", $navyCity)); |
375
0ec57ac68a4c
one more parameter for ship speed.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
368
diff
changeset
|
74 $city->{travelTime} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, $opt_s); |
0ec57ac68a4c
one more parameter for ship speed.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
368
diff
changeset
|
75 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, $opt_s) + $vanguard; |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
76 if($i == 1) { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
77 $city->{distance} += 8; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
78 } else { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
79 $city->{distance} += 5; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
80 } |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
81 $city->{type} = "navy"; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
82 $city->{queue} = "navy" . $i; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
83 push (@cities, $city); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
84 } |
271 | 85 |
86 # ARMY | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
87 foreach my $i (1..$opt_a) { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
88 my $armyCity = shift(@ARGV); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
89 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
|
90 $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
|
91 $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
|
92 if($i == 1) { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
93 $city->{distance} += 5; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
94 } else { |
368
95148fdc1021
added time counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
365
diff
changeset
|
95 $city->{distance} += 1; |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
96 } |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
97 $city->{type} = "army"; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
98 $city->{queue} = "army" . $i; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
99 push (@cities, $city); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
100 } |
271 | 101 |
102 # wingman, army | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
103 while(defined($cityId = shift(@ARGV))) { |
271 | 104 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
|
105 $city->{type} = "wingman"; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
106 $city->{queue} = "wingman"; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
107 $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
|
108 $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
|
109 if(defined($opt_w)) { |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
110 $city->{distance} -= ($i * 20 + 20); |
301
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
111 } |
271 | 112 push (@cities, $city); |
113 } | |
114 | |
115 # print the code. | |
116 print <<EOF; | |
117 #!/usr/bin/perl | |
118 use strict; | |
119 use Ikariam; | |
120 use Data::Dumper; | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
121 use POSIX qw(strftime); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
122 |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
123 sub calcTime { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
124 my (\$gooff, \$travelTime) = \@_; |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
125 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
|
126 } |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
127 |
271 | 128 package main; |
129 my \$ikariam = new Ikariam(\$::server, \$::user, \$::pass); | |
130 EOF | |
131 | |
276
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
132 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
|
133 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
|
134 printf("#\n"); |
368
95148fdc1021
added time counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
365
diff
changeset
|
135 printf("my \$delay = 0; # minutes\n"); |
271 | 136 |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
137 @cities = sort { $b->{distance} <=> $a->{distance}; } (@cities); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
138 foreach my $i (0..$#cities) { |
368
95148fdc1021
added time counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
365
diff
changeset
|
139 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
|
140 $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
|
141 $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 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
|
143 } |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
144 printf("printf('Press Enter to start...');\n"); |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
145 printf("<STDIN>;\n"); |
271 | 146 |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
147 foreach my $i (0..$#cities) { |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
148 if($i ne 0) { |
276
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
149 # TODO, 計算港口速度 |
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
150 # 減掉 cities[$i+1]->buliding->port 的速度 |
271 | 151 printf("sleep(%d*60);\n", |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
152 ($cities[$i-1]->{distance} - $cities[$i]->{distance})); |
271 | 153 } |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
154 |
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
155 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
|
156 printf("# ActionPoint %d/%d\n", $cities[$i]->{actionPoints}, $cities[$i]->{maxActionPoints}); |
271 | 157 |
158 printf('$ikariam->login;' . "\n"); | |
159 if($cities[$i]->{type} eq "navy") { | |
160 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); | |
161 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
|
162 printf("\tblockadeDuration => 8*60*60," . "\n"); |
271 | 163 while (my ($k, $v) = each(%{$cities[$i]->{fleet}})) { |
164 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
|
165 printf("\tcargo_fleet_%s => %s, # %s (%d)\n", $fleet->{$k}, 0, $k, $v); |
271 | 166 } |
167 } | |
168 printf('});' . "\n", $cities[$i]->{id}); | |
169 } else { | |
170 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); | |
171 printf('$ikariam->plunderCity(%d, {' . "\n", $targetCity->id); | |
172 while (my ($k, $v) = each(%{$cities[$i]->{army}})) { | |
173 if($v > 0) { | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
174 printf("\tcargo_army_%s => %s, # %s (%d)\n", $army->{$k}, $v, $k, $v); |
271 | 175 } |
176 } | |
365
2444685c68c9
merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
358
diff
changeset
|
177 printf("\ttransporter => 0, # transporter (%s)\n", $cities[$i]->{transporters}->{avail}); |
271 | 178 printf('});' . "\n", $cities[$i]->{id}); |
179 } | |
180 printf('$ikariam->logout;' . "\n"); | |
181 } |