Mercurial > eagle-eye
view planner.pl @ 360:26f52b25aa06
disable building warehouse
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Mon, 23 Feb 2009 16:25:02 +0800 |
parents | 58351fccf619 |
children | 2444685c68c9 |
line wrap: on
line source
#!/usr/bin/perl use Ikariam; use Data::Dumper; use Decision::ParseTree q{ParseTree}; use YAML qw/LoadFile Dump DumpFile/; use Getopt::Std; Ikariam::Cities->has_a(island => 'Ikariam::Island'); my $army = { "Slinger" => 301, "Swordsman" => 302, "Phalanx" => 303, "Ram" => 307, "Archer" => 313, "Catapult" => 306, "Gunsman" => 304, "Mortar" => 305, "SteamGiant" => 308, "Gyrocopter" => 312, "Bombardier" => 309, "Doctor" => 311, "Cook" => 310, }; my $fleet = { "CargoShip" => 201, "Ram-Ship" => 210, "BallistaShip" => 213, "Flamethrower" => 211, "CatapultShip" => 214, "MortarShip" => 215, "PaddleWheelRam" => 216, "DivingBoat" => 212, }; # return minutes. sub travelTime { my ($x1, $y1, $x2, $y2, $speed) = @_; $speed = 60 unless(defined($speed)); if($x1 == $x2 && $y1 == $y2) { return 600/$speed; } else { return int( (sqrt((abs($x1 - $x2) * abs($x1 - $x2)) + (abs($y1 - $y2) * abs($y1 - $y2)))) * (1200/$speed)); } } package main; getopts('w'); if($#ARGV < 2) { die("Usage: %s targetCity navyCity armyCity wingman1.. wingman2..\n"); } my $targetCityId = shift(@ARGV); my $navyCity = shift(@ARGV); my $armyCity = shift(@ARGV); my @wingman = @ARGV; my $vanguard = 21; my $targetCity = Ikariam::Cities->retrieve($targetCityId); # NAVY my $city = LoadFile(sprintf("city-%s-dump.yaml", $navyCity)); $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 33) + $vanguard + 8; $city->{type} = "navy"; push (@cities, $city); # ARMY my $city = LoadFile(sprintf("city-%s-dump.yaml", $armyCity)); $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) + $vanguard + 5; $city->{type} = "army"; push (@cities, $city); # wingman, army foreach my $i (0..$#wingman) { my $cityId = $wingman[$i]; my $city = LoadFile(sprintf("city-%s-dump.yaml", $cityId)); $city->{type} = "wingman" . ($i+1); if(defined($opt_w)) { $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60) - ($i * 20 + 20); } else { $city->{distance} = travelTime($targetCity->island->x, $targetCity->island->y, $city->{island}->{x}, $city->{island}->{y}, 60); } push (@cities, $city); } # print the code. print <<EOF; #!/usr/bin/perl use strict; use Ikariam; use Data::Dumper; package main; my \$ikariam = new Ikariam(\$::server, \$::user, \$::pass); EOF foreach(@cities) { printf("# %s %s (%s)\n", $_->{type}, $_->{id}, $_->{distance}); } @cities = sort { $a->{distance} <=> $b->{distance}; } (@cities); printf ("# %s %s [%s:%s]\n", $targetCity->owner, $targetCity->cityname, $targetCity->island->x, $targetCity->island->y); printf ("# http://%s/index.php?view=island&id=%d&selectCity=%d\n", $::server, $targetCity->island->id, $targetCity->id); for(my $i = ($#cities + 1) ; $i-- ; $i < 0 ) { if($i ne $#cities) { # TODO, 計算港口速度 # 減掉 cities[$i+1]->buliding->port 的速度 printf("sleep(%d*60);\n", ($cities[$i+1]->{distance} - $cities[$i]->{distance})); } printf("\n# %s %s %dm\n", $cities[$i]->{name}, $cities[$i]->{type}, $cities[$i]->{distance}); printf("# ActionPoint %d/%d\n", $cities[$i]->{actionPoints}, $cities[$i]->{maxActionPoints}); printf('$ikariam->login;' . "\n"); if($cities[$i]->{type} eq "navy") { printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); printf('$ikariam->blockadeCity(%d, {' . "\n", $targetCity->id); printf("\tblockadeDuration => 8*60*60," . "\n"); while (my ($k, $v) = each(%{$cities[$i]->{fleet}})) { if($v > 0) { printf("\tcargo_fleet_%s => %s, # %s (%d)\n", $fleet->{$k}, 0, $k, $v); } } printf('});' . "\n", $cities[$i]->{id}); } else { printf('$ikariam->changeCity(%d);' . "\n", $cities[$i]->{id}); printf('$ikariam->plunderCity(%d, {' . "\n", $targetCity->id); while (my ($k, $v) = each(%{$cities[$i]->{army}})) { if($v > 0) { printf("\tcargo_army_%s => %s, # %s (%d)\n", $army->{$k}, 0, $k, $v); } } printf("\ttransporter => %s, # transporter\n", $cities[$i]->{transporters}->{avail}); printf('});' . "\n", $cities[$i]->{id}); } printf('$ikariam->logout;' . "\n"); }