annotate planner.pl @ 376:6ca0677a361e

refiend output format and fixed timing issue.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Tue, 14 Apr 2009 17:02:17 +0800
parents 0ec57ac68a4c
children
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 }
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
67 my $targetCityId = shift(@ARGV);
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
85
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
101
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
112 push (@cities, $city);
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
115 # print the code.
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
116 print <<EOF;
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
117 #!/usr/bin/perl
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
118 use strict;
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
119 use Ikariam;
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
128 package main;
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
129 my \$ikariam = new Ikariam(\$::server, \$::user, \$::pass);
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
130 EOF
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
157
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
158 printf('$ikariam->login;' . "\n");
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
159 if($cities[$i]->{type} eq "navy") {
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
160 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id});
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
163 while (my ($k, $v) = each(%{$cities[$i]->{fleet}})) {
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
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 }
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
168 printf('});' . "\n", $cities[$i]->{id});
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
169 } else {
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
170 printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id});
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
171 printf('$ikariam->plunderCity(%d, {' . "\n", $targetCity->id);
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
172 while (my ($k, $v) = each(%{$cities[$i]->{army}})) {
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
175 }
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
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
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
178 printf('});' . "\n", $cities[$i]->{id});
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
179 }
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
180 printf('$ikariam->logout;' . "\n");
0ed1b3e72e65 new campaign planner
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
181 }