Mercurial > eagle-eye
comparison planner.pl @ 365:2444685c68c9
merged multi-attacks script
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sun, 01 Mar 2009 11:10:32 +0800 |
parents | 58351fccf619 |
children | 95148fdc1021 |
comparison
equal
deleted
inserted
replaced
364:7274d8f41d5f | 365:2444685c68c9 |
---|---|
2 use Ikariam; | 2 use Ikariam; |
3 use Data::Dumper; | 3 use Data::Dumper; |
4 use Decision::ParseTree q{ParseTree}; | 4 use Decision::ParseTree q{ParseTree}; |
5 use YAML qw/LoadFile Dump DumpFile/; | 5 use YAML qw/LoadFile Dump DumpFile/; |
6 use Getopt::Std; | 6 use Getopt::Std; |
7 use POSIX qw(strftime); | |
7 | 8 |
8 Ikariam::Cities->has_a(island => 'Ikariam::Island'); | 9 Ikariam::Cities->has_a(island => 'Ikariam::Island'); |
9 | 10 |
10 my $army = { | 11 my $army = { |
11 "Slinger" => 301, | 12 "Slinger" => 301, |
32 "MortarShip" => 215, | 33 "MortarShip" => 215, |
33 "PaddleWheelRam" => 216, | 34 "PaddleWheelRam" => 216, |
34 "DivingBoat" => 212, | 35 "DivingBoat" => 212, |
35 }; | 36 }; |
36 | 37 |
38 | |
39 sub calcTime { | |
40 my ($gooff, $travelTime) = @_; | |
41 return (sprintf("%s-%s", strftime("%H:%M", localtime(time+$gooff*60)), strftime("%H:%M", localtime(time+($gooff+$travelTime)*60)))); | |
42 } | |
43 | |
37 # return minutes. | 44 # return minutes. |
38 sub travelTime { | 45 sub travelTime { |
39 my ($x1, $y1, $x2, $y2, $speed) = @_; | 46 my ($x1, $y1, $x2, $y2, $speed) = @_; |
40 $speed = 60 unless(defined($speed)); | 47 $speed = 60 unless(defined($speed)); |
41 if($x1 == $x2 && $y1 == $y2) { | 48 if($x1 == $x2 && $y1 == $y2) { |
45 } | 52 } |
46 } | 53 } |
47 | 54 |
48 | 55 |
49 package main; | 56 package main; |
50 getopts('w'); | 57 |
51 if($#ARGV < 2) { | 58 if($#ARGV < 2) { |
52 die("Usage: %s targetCity navyCity armyCity wingman1.. wingman2..\n"); | 59 die("Usage: %s -n 1 -a 1 -v 21 targetCity navyCity armyCity wingman1.. wingman2..\n"); |
53 } | 60 } |
61 getopts('wa:n:v:'); | |
62 $opt_n = defined($opt_n) ? $opt_n : 1; | |
63 $opt_a = defined($opt_a) ? $opt_a : 1; | |
64 my $vanguard = defined($opt_v) ? $opt_v : 21; | |
65 | |
54 my $targetCityId = shift(@ARGV); | 66 my $targetCityId = shift(@ARGV); |
55 my $navyCity = shift(@ARGV); | |
56 my $armyCity = shift(@ARGV); | |
57 my @wingman = @ARGV; | |
58 my $vanguard = 21; | |
59 | |
60 my $targetCity = Ikariam::Cities->retrieve($targetCityId); | 67 my $targetCity = Ikariam::Cities->retrieve($targetCityId); |
61 | 68 my @cities; |
62 # NAVY | 69 # NAVY |
63 my $city = LoadFile(sprintf("city-%s-dump.yaml", $navyCity)); | 70 foreach my $i (1..$opt_n) { |
64 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 33) + $vanguard + 8; | 71 my $navyCity = shift(@ARGV); |
65 $city->{type} = "navy"; | 72 my $city = LoadFile(sprintf("city-%s-dump.yaml", $navyCity)); |
66 push (@cities, $city); | 73 $city->{travelTime} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 33); |
74 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 33) + $vanguard; | |
75 if($i == 1) { | |
76 $city->{distance} += 8; | |
77 } else { | |
78 $city->{distance} += 5; | |
79 } | |
80 $city->{type} = "navy"; | |
81 $city->{queue} = "navy" . $i; | |
82 push (@cities, $city); | |
83 } | |
67 | 84 |
68 # ARMY | 85 # ARMY |
69 my $city = LoadFile(sprintf("city-%s-dump.yaml", $armyCity)); | 86 foreach my $i (1..$opt_a) { |
70 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) + $vanguard + 5; | 87 my $armyCity = shift(@ARGV); |
71 $city->{type} = "army"; | 88 my $city = LoadFile(sprintf("city-%s-dump.yaml", $armyCity)); |
72 push (@cities, $city); | 89 $city->{travelTime} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); |
90 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) + $vanguard; | |
91 if($i == 1) { | |
92 $city->{distance} += 5; | |
93 } else { | |
94 $city->{distance} += 2; | |
95 } | |
96 $city->{type} = "army"; | |
97 $city->{queue} = "army" . $i; | |
98 push (@cities, $city); | |
99 } | |
73 | 100 |
74 # wingman, army | 101 # wingman, army |
75 foreach my $i (0..$#wingman) { | 102 while(defined($cityId = shift(@ARGV))) { |
76 my $cityId = $wingman[$i]; | |
77 my $city = LoadFile(sprintf("city-%s-dump.yaml", $cityId)); | 103 my $city = LoadFile(sprintf("city-%s-dump.yaml", $cityId)); |
78 $city->{type} = "wingman" . ($i+1); | 104 $city->{type} = "wingman"; |
105 $city->{queue} = "wingman"; | |
106 $city->{travelTime} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); | |
107 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); | |
79 if(defined($opt_w)) { | 108 if(defined($opt_w)) { |
80 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) - ($i * 20 + 20); | 109 $city->{distance} -= ($i * 20 + 20); |
81 } else { | |
82 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); | |
83 } | 110 } |
84 push (@cities, $city); | 111 push (@cities, $city); |
85 } | 112 } |
86 | 113 |
87 # print the code. | 114 # print the code. |
88 print <<EOF; | 115 print <<EOF; |
89 #!/usr/bin/perl | 116 #!/usr/bin/perl |
90 use strict; | 117 use strict; |
91 use Ikariam; | 118 use Ikariam; |
92 use Data::Dumper; | 119 use Data::Dumper; |
120 use POSIX qw(strftime); | |
121 | |
122 sub calcTime { | |
123 my (\$gooff, \$travelTime) = \@_; | |
124 return (sprintf("%s-%s", strftime("%H:%M", localtime(time+\$gooff*60)), strftime("%H:%M", localtime(time+(\$gooff+\$travelTime)*60)))); | |
125 } | |
126 | |
93 package main; | 127 package main; |
94 my \$ikariam = new Ikariam(\$::server, \$::user, \$::pass); | 128 my \$ikariam = new Ikariam(\$::server, \$::user, \$::pass); |
95 EOF | 129 EOF |
96 | 130 |
97 foreach(@cities) { | |
98 printf("# %s %s (%s)\n", $_->{type}, $_->{id}, $_->{distance}); | |
99 } | |
100 @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities); | |
101 | |
102 printf ("# %s %s [%s:%s]\n", $targetCity->owner, $targetCity->cityname, $targetCity->island->x, $targetCity->island->y); | 131 printf ("# %s %s [%s:%s]\n", $targetCity->owner, $targetCity->cityname, $targetCity->island->x, $targetCity->island->y); |
103 printf ("# http://%s/index.php?view=island&id=%d&selectCity=%d\n", $::server, $targetCity->island->id, $targetCity->id); | 132 printf ("# http://%s/index.php?view=island&id=%d&selectCity=%d\n", $::server, $targetCity->island->id, $targetCity->id); |
133 printf("#\n"); | |
104 | 134 |
105 for(my $i = ($#cities + 1) ; $i-- ; $i < 0 ) { | 135 @cities = sort { $b->{distance} <=> $a->{distance}; } (@cities); |
136 foreach my $i (0..$#cities) { | |
137 printf('printf("%%s %s %s %s %sm\n", calcTime(%s - %s, %s));', | |
138 $cities[$i]->{queue}, $cities[$i]->{name}, $cities[$i]->{id}, $cities[$i]->{travelTime}, | |
139 $cities[0]->{distance}, $cities[$i]->{distance}, $cities[$i]->{travelTime}); | |
140 printf(" # %s\n", calcTime($cities[0]->{distance} - $cities[$i]->{distance}, $cities[$i]->{travelTime})); | |
141 } | |
142 printf("printf('Press Enter to start...');\n"); | |
143 printf("<STDIN>;\n"); | |
106 | 144 |
107 if($i ne $#cities) { | 145 foreach my $i (0..$#cities) { |
146 if($i ne 0) { | |
108 # TODO, 計算港口速度 | 147 # TODO, 計算港口速度 |
109 # 減掉 cities[$i+1]->buliding->port 的速度 | 148 # 減掉 cities[$i+1]->buliding->port 的速度 |
110 printf("sleep(%d*60);\n", | 149 printf("sleep(%d*60);\n", |
111 ($cities[$i+1]->{distance} - $cities[$i]->{distance})); | 150 ($cities[$i-1]->{distance} - $cities[$i]->{distance})); |
112 } | 151 } |
113 printf("\n# %s %s %dm\n", $cities[$i]->{name}, $cities[$i]->{type}, $cities[$i]->{distance}); | 152 |
153 printf("\n# %s %s %dm\n", $cities[$i]->{name}, $cities[$i]->{queue}, $cities[$i]->{travelTime}); | |
114 printf("# ActionPoint %d/%d\n", $cities[$i]->{actionPoints}, $cities[$i]->{maxActionPoints}); | 154 printf("# ActionPoint %d/%d\n", $cities[$i]->{actionPoints}, $cities[$i]->{maxActionPoints}); |
115 | 155 |
116 printf('$ikariam->login;' . "\n"); | 156 printf('$ikariam->login;' . "\n"); |
117 if($cities[$i]->{type} eq "navy") { | 157 if($cities[$i]->{type} eq "navy") { |
118 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); | 158 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); |
127 } else { | 167 } else { |
128 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); | 168 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); |
129 printf('$ikariam->plunderCity(%d, {' . "\n", $targetCity->id); | 169 printf('$ikariam->plunderCity(%d, {' . "\n", $targetCity->id); |
130 while (my ($k, $v) = each(%{$cities[$i]->{army}})) { | 170 while (my ($k, $v) = each(%{$cities[$i]->{army}})) { |
131 if($v > 0) { | 171 if($v > 0) { |
132 printf("\tcargo_army_%s => %s, # %s (%d)\n", $army->{$k}, 0, $k, $v); | 172 printf("\tcargo_army_%s => %s, # %s (%d)\n", $army->{$k}, $v, $k, $v); |
133 } | 173 } |
134 } | 174 } |
135 printf("\ttransporter => %s, # transporter\n", $cities[$i]->{transporters}->{avail}); | 175 printf("\ttransporter => 0, # transporter (%s)\n", $cities[$i]->{transporters}->{avail}); |
136 printf('});' . "\n", $cities[$i]->{id}); | 176 printf('});' . "\n", $cities[$i]->{id}); |
137 } | 177 } |
138 printf('$ikariam->logout;' . "\n"); | 178 printf('$ikariam->logout;' . "\n"); |
139 } | 179 } |