# HG changeset patch # User "Rex Tsai " # Date 1225974867 -28800 # Node ID b7ea7c43dbad367f6d56cbbc6b537adf4753b1ec # Parent afd3f5cb85975710995d2ce889af714be1b1d0f3# Parent 978a949602e54fa4f9c94124c9651294f9249afe merged. diff -r afd3f5cb8597 -r b7ea7c43dbad Ikariam.pm --- a/Ikariam.pm Thu Nov 06 20:32:17 2008 +0800 +++ b/Ikariam.pm Thu Nov 06 20:34:27 2008 +0800 @@ -360,15 +360,28 @@ $position = $_ if($locations[$_] eq $type); } - if($position != -1) { - $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); - $self->{mech}->submit_form( - form_number => 1, - fields => { - amount => $self->{'cities'}->{$cityId}->{$type}->{maxValue}, - } - ); - +# Academy - inputScientists + if($position != -1 && $type eq 'academy') { + $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); + $self->{mech}->submit_form( + form_number => 1, + fields => { + s => $self->{'cities'}->{$cityId}->{$type}->{maxValue}, + } + ); + + } + +# Tavern + if($position != -1 && $type eq 'tavern') { + $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); + $self->{mech}->submit_form( + form_number => 1, + fields => { + amount => $self->{'cities'}->{$cityId}->{$type}->{maxValue}, + } + ); + } } @@ -711,6 +724,28 @@ $self->{'cities'}->{$cityId}->{maxActionPoints} = $extractor->find('//span[@id="value_maxActionPoints"]');; } +sub checkAcademy { + my $self = shift; + my $cityId = shift; + my $building = "academy"; + + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + # init + $self->{'cities'}->{$cityId}->{$building}->{'maxValue'} = 0; + $self->{'cities'}->{$cityId}->{$building}->{'iniValue'} = 0; + foreach (0..$#locations) { + if($locations[$_] eq $building) { + my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=%s&id=%d&position=%d', $self->{server}, $building, $cityId, $_ )); + my $extractor = Ikariam::Extractor->new(content => $res->content); + if($extractor->{doc}->toString(0) =~ /maxValue : (\d+),\s+overcharge : \d+,\s+iniValue : (\d+),/) { + $self->{'cities'}->{$cityId}->{$building}->{'maxValue'} = $1; + $self->{'cities'}->{$cityId}->{$building}->{'iniValue'} = $2; + } + last; + } + } +} + sub checkTavern { my $self = shift; my $cityId = shift; @@ -995,6 +1030,7 @@ $self->checkTownHall($cityId); $self->checkArmies($cityId); $self->checkTavern($cityId); + $self->checkAcademy($cityId); } # $self->checkFriends(); return $self->{'cities'}; diff -r afd3f5cb8597 -r b7ea7c43dbad agent.pl --- a/agent.pl Thu Nov 06 20:32:17 2008 +0800 +++ b/agent.pl Thu Nov 06 20:34:27 2008 +0800 @@ -63,7 +63,16 @@ sub is_safehouse_enough { my ($self, $city) = @_; return 0 if(!defined($city->{buildings}->{safehouse})); - return (($city->{buildings}->{townHall} <= ($city->{buildings}->{safehouse} + 4)) ? 0 : 1); + + # build the higgest safehouse. + # maybe we should have more then 4 towns, then we consider that we should upgrade safehouse at level 20. + # return (($city->{buildings}->{townHall} > $city->{buildings}->{safehouse}) ? 0 : 1) + # if($$city->{buildings}->{townHall} >= 20); + # return (($city->{buildings}->{townHall} <= ($city->{buildings}->{safehouse} + 4)) ? 0 : 1); + + # Safehouse must be same level as townHall, + # Maybe one level higher is better. + return (($city->{buildings}->{townHall} > $city->{buildings}->{safehouse}) ? 0 : 1); } sub is_warehouse_enough { @@ -108,7 +117,7 @@ my ($self, $city) = @_; return ($city->{growth} >= 5 ? 1 : 0) - if($city->{buildings}->{townHall} <= 10); + if($city->{buildings}->{townHall} <= 16); return 1 if($city->{buildings}->{townHall} >= 20); @@ -380,6 +389,9 @@ # build spy $i->buildSpy('spy', $cityId); + # enlarge the scientist number. + $i->set("academy", $cityId); + $i->set("tavern", $cityId); # build military! $tree = LoadFile('military.yaml'); diff -r afd3f5cb8597 -r b7ea7c43dbad city.yaml --- a/city.yaml Thu Nov 06 20:32:17 2008 +0800 +++ b/city.yaml Thu Nov 06 20:34:27 2008 +0800 @@ -25,7 +25,11 @@ 1: build_townHall - is_happiness: 0: - - is_winepress_researched: + - is_museum_enough: + 0: + - is_culturalexchange_resaerched: + 1: build_museum + - is_winepress_researched: 1: - is_tavern_available: 0: build_tavern diff -r afd3f5cb8597 -r b7ea7c43dbad overall.yaml --- a/overall.yaml Thu Nov 06 20:32:17 2008 +0800 +++ b/overall.yaml Thu Nov 06 20:34:27 2008 +0800 @@ -28,5 +28,5 @@ # 希臘火, 建造噴火船 - is_greekfire_researched: 0: research_seafaring - + 1: run_defence diff -r afd3f5cb8597 -r b7ea7c43dbad scan.pl --- a/scan.pl Thu Nov 06 20:32:17 2008 +0800 +++ b/scan.pl Thu Nov 06 20:34:27 2008 +0800 @@ -76,32 +76,6 @@ } } -our $i = new Ikariam($::server, $::user, $::pass); - -if($#ARGV == 1) { - $i->login; - my @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]); - saveIslands(@islands); - $i->logout; -} elsif($#ARGV == 0) { - $i->login; - my $island = $ARGV[0]; - my @cities = $i->viewIsland($island); - saveCities($island, @cities); - $i->logout; -} elsif($#ARGV == -1) { - $i->login; - my $cities = $i->check; - foreach my $cityId (keys(%$cities)) { - printf("%s %s\n", $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y}); - my @islands = $i->viewWorldMap( $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y}); - saveIslands(@islands); - } - $i->logout; -} else { - die("Usage: $0\nUsage: $0 x y\n"); -} - sub saveIslands { my @islands = @_; @@ -121,7 +95,7 @@ # scanning the island if($island->time le (time - 30*60*6)) { - my @cities = $i->viewIsland($h_island->{id}); + my @cities = $::i->viewIsland($h_island->{id}); saveCities($h_island->{id}, @cities); $island->set('time', time); @@ -130,4 +104,33 @@ } } -# $i->getCityInfo(); + + +local $SIG{ALRM} = sub { die "timeout\n" }; +alarm 3; +our $i = new Ikariam($::server, $::user, $::pass); + +if($#ARGV == 1) { + $i->login; + my @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]); + saveIslands(@islands); + $i->logout; +} elsif($#ARGV == 0) { + $i->login; + my $island = $ARGV[0]; + my @cities = $i->viewIsland($island); + saveCities($island, @cities); + $i->logout; +} elsif($#ARGV == -1) { + $i->login; + my $cities = $i->check; + # random + foreach my $cityId (keys(%$cities)) { + printf("%s %s\n", $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y}); + my @islands = $i->viewWorldMap( $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y}); + saveIslands(@islands); + } + $i->logout; +} else { + die("Usage: $0\nUsage: $0 x y\n"); +} diff -r afd3f5cb8597 -r b7ea7c43dbad warfare.pl --- a/warfare.pl Thu Nov 06 20:32:17 2008 +0800 +++ b/warfare.pl Thu Nov 06 20:34:27 2008 +0800 @@ -77,6 +77,7 @@ my $sheep = $city->user; my $island = $city->island; + # TODO update sheep and island information. # we don't fight friends. # FIXME: This is very dirty for accessing to $::i directly.