Mercurial > eagle-eye
annotate planner.pl @ 313:a5d85719155d
fixed the if/else logic
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Tue, 06 Jan 2009 23:51:53 +0800 |
parents | 2972852a4ee5 |
children | 0db3e2bcbd0f |
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) = @_; | |
40 $speed = 20 unless(defined($speed)); | |
41 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed)); | |
42 } | |
43 | |
44 package main; | |
301
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
45 getopts('w'); |
271 | 46 if($#ARGV < 2) { |
47 die("Usage: %s targetCity navyCity armyCity wingman1.. wingman2..\n"); | |
48 } | |
49 my $targetCityId = shift(@ARGV); | |
50 my $navyCity = shift(@ARGV); | |
51 my $armyCity = shift(@ARGV); | |
52 my @wingman = @ARGV; | |
53 | |
54 my $targetCity = Ikariam::Cities->retrieve($targetCityId); | |
55 | |
56 | |
57 # NAVY | |
58 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
|
59 # $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
|
60 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 8) + 25; |
271 | 61 $city->{type} = "navy"; |
62 push (@cities, $city); | |
63 | |
64 # ARMY | |
65 my $city = LoadFile(sprintf("city-%s-dump.yaml", $armyCity)); | |
66 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 20) + 5; | |
67 $city->{type} = "army"; | |
68 push (@cities, $city); | |
69 | |
70 # wingman, army | |
301
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
71 foreach my $i (0..$#wingman) { |
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
72 my $cityId = $wingman[$i]; |
271 | 73 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
|
74 $city->{type} = "wingman" . ($i+1); |
301
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
75 if(defined($opt_w)) { |
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
76 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 20) - ($i * 20 + 20); |
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
77 } else { |
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
78 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 20); |
07f51bb67e56
option for wave attack
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
293
diff
changeset
|
79 } |
271 | 80 push (@cities, $city); |
81 } | |
82 | |
83 @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities); | |
84 | |
85 | |
86 # print the code. | |
87 print <<EOF; | |
88 #!/usr/bin/perl | |
89 use strict; | |
90 use Ikariam; | |
91 use Data::Dumper; | |
92 package main; | |
93 my \$ikariam = new Ikariam(\$::server, \$::user, \$::pass); | |
94 EOF | |
95 | |
276
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
96 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
|
97 printf ("# http://%s/index.php?view=island&id=%d&selectCity=%d\n", $::server, $targetCity->island->id, $targetCity->id); |
271 | 98 |
99 for(my $i = ($#cities + 1) ; $i-- ; $i < 0 ) { | |
100 | |
276
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
101 if($i ne $#cities) { |
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
102 # TODO, 計算港口速度 |
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
103 # 減掉 cities[$i+1]->buliding->port 的速度 |
271 | 104 printf("sleep(%d*60);\n", |
105 ($cities[$i+1]->{distance} - $cities[$i]->{distance})); | |
106 } | |
276
8355ec8514f9
refined output data
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
271
diff
changeset
|
107 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
|
108 printf("# ActionPoint %d/%d\n", $cities[$i]->{actionPoints}, $cities[$i]->{maxActionPoints}); |
271 | 109 |
110 printf('$ikariam->login;' . "\n"); | |
111 if($cities[$i]->{type} eq "navy") { | |
112 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); | |
113 printf('$ikariam->blockadeCity(%d, {' . "\n", $targetCity->id); | |
285
c864134ebe3e
refined output format
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
276
diff
changeset
|
114 printf("\tblockadeDuration => 2*60*60," . "\n"); |
271 | 115 while (my ($k, $v) = each(%{$cities[$i]->{fleet}})) { |
116 if($v > 0) { | |
285
c864134ebe3e
refined output format
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
276
diff
changeset
|
117 printf("\tcargo_fleet_%s => %s, # %s \n", $fleet->{$k}, $v, $k); |
271 | 118 } |
119 } | |
120 printf('});' . "\n", $cities[$i]->{id}); | |
121 } else { | |
122 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); | |
123 printf('$ikariam->plunderCity(%d, {' . "\n", $targetCity->id); | |
124 while (my ($k, $v) = each(%{$cities[$i]->{army}})) { | |
125 if($v > 0) { | |
285
c864134ebe3e
refined output format
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
276
diff
changeset
|
126 printf("\tcargo_army_%s => %s, # %s \n", $army->{$k}, $v, $k); |
271 | 127 } |
128 } | |
129 printf('});' . "\n", $cities[$i]->{id}); | |
130 } | |
131 printf('$ikariam->logout;' . "\n"); | |
132 } |