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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
1 #!/usr/bin/perl
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
2 use Ikariam;
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
3 use Data::Dumper;
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
4 use Decision::ParseTree q{ParseTree};
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
8
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
9 Ikariam::Cities->has_a(island => 'Ikariam::Island');
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
10
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11 my $army = {
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
12 "Slinger" => 301,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
13 "Swordsman" => 302,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
14 "Phalanx" => 303,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
15 "Ram" => 307,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
16 "Archer" => 313,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
17 "Catapult" => 306,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
18 "Gunsman" => 304,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
19 "Mortar" => 305,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
20 "SteamGiant" => 308,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
21 "Gyrocopter" => 312,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
22 "Bombardier" => 309,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
23 "Doctor" => 311,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
24 "Cook" => 310,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
25 };
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
26
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
27 my $fleet = {
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28 "CargoShip" => 201,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29 "Ram-Ship" => 210,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30 "BallistaShip" => 213,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 "Flamethrower" => 211,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 "CatapultShip" => 214,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
33 "MortarShip" => 215,
303
50cff2eee239 fixed a typo
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 301
diff changeset
34 "PaddleWheelRam" => 216,
271
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
35 "DivingBoat" => 212,
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36 };
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 # return minutes.
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45 sub travelTime {
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46 my ($x1, $y1, $x2, $y2, $speed) = @_;
334
65f45552060e fixed travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 327
diff changeset
47 $speed = 60 unless(defined($speed));
65f45552060e fixed travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 327
diff changeset
48 if($x1 == $x2 && $y1 == $y2) {
65f45552060e fixed travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 327
diff changeset
49 return 600/$speed;
65f45552060e fixed travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 327
diff changeset
50 } else {
65f45552060e fixed travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 327
diff changeset
51 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed));
65f45552060e fixed travel time
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 327
diff changeset
52 }
271
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
53 }
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
54
343
85d60a0569bf fixed travel time for 0.3.0
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 334
diff changeset
55
271
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
56 package main;
365
2444685c68c9 merged multi-attacks script
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 358
diff changeset
57
271
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
66 my $targetCityId = shift(@ARGV);
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
84
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
100
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
111 push (@cities, $city);
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
112 }
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
113
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
114 # print the code.
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
115 print <<EOF;
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
116 #!/usr/bin/perl
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
117 use strict;
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
118 use Ikariam;
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
127 package main;
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
128 my \$ikariam = new Ikariam(\$::server, \$::user, \$::pass);
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
129 EOF
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
156
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
157 printf('$ikariam->login;' . "\n");
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
158 if($cities[$i]->{type} eq "navy") {
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
159 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id});
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
162 while (my ($k, $v) = each(%{$cities[$i]->{fleet}})) {
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
165 }
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
166 }
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
167 printf('});' . "\n", $cities[$i]->{id});
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
168 } else {
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
169 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id});
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
170 printf('$ikariam->plunderCity(%d, {' . "\n", $targetCity->id);
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
171 while (my ($k, $v) = each(%{$cities[$i]->{army}})) {
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
174 }
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
177 printf('});' . "\n", $cities[$i]->{id});
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
178 }
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
179 printf('$ikariam->logout;' . "\n");
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
180 }