comparison planner.pl @ 301:07f51bb67e56

option for wave attack
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 07 Dec 2008 22:25:30 +0800
parents 523ea51126bc
children 50cff2eee239
comparison
equal deleted inserted replaced
300:5fc26f2af95b 301:07f51bb67e56
1 #!/usr/bin/perl 1 #!/usr/bin/perl
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 7
7 Ikariam::Cities->has_a(island => 'Ikariam::Island'); 8 Ikariam::Cities->has_a(island => 'Ikariam::Island');
8 9
9 my $army = { 10 my $army = {
10 "Slinger" => 301, 11 "Slinger" => 301,
39 $speed = 20 unless(defined($speed)); 40 $speed = 20 unless(defined($speed));
40 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed)); 41 return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))+1) * (400/$speed));
41 } 42 }
42 43
43 package main; 44 package main;
45 getopts('w');
44 if($#ARGV < 2) { 46 if($#ARGV < 2) {
45 die("Usage: %s targetCity navyCity armyCity wingman1.. wingman2..\n"); 47 die("Usage: %s targetCity navyCity armyCity wingman1.. wingman2..\n");
46 } 48 }
47 my $targetCityId = shift(@ARGV); 49 my $targetCityId = shift(@ARGV);
48 my $navyCity = shift(@ARGV); 50 my $navyCity = shift(@ARGV);
64 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 20) + 5; 66 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 20) + 5;
65 $city->{type} = "army"; 67 $city->{type} = "army";
66 push (@cities, $city); 68 push (@cities, $city);
67 69
68 # wingman, army 70 # wingman, army
69 foreach my $cityId (@wingman) { 71 foreach my $i (0..$#wingman) {
72 my $cityId = $wingman[$i];
70 my $city = LoadFile(sprintf("city-%s-dump.yaml", $cityId)); 73 my $city = LoadFile(sprintf("city-%s-dump.yaml", $cityId));
71 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 20); 74 if(defined($opt_w)) {
75 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 20) - ($i * 20 + 20);
76 } else {
77 $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 20);
78 }
72 push (@cities, $city); 79 push (@cities, $city);
73 } 80 }
74 81
75 @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities); 82 @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities);
76 83