changeset 236:cf08e01f5713

merged.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 06 Nov 2008 20:36:24 +0800
parents a89e049d1d31 (current diff) b7ea7c43dbad (diff)
children a254fb798eb9
files agent.pl
diffstat 6 files changed, 100 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/Ikariam.pm	Thu Nov 06 20:32:52 2008 +0800
+++ b/Ikariam.pm	Thu Nov 06 20:36:24 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'};
--- a/agent.pl	Thu Nov 06 20:32:52 2008 +0800
+++ b/agent.pl	Thu Nov 06 20:36:24 2008 +0800
@@ -63,12 +63,22 @@
 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 {
     my ($self, $city) = @_;
-    my @warehouse = (qw/undef undef 0 4 9 16 18 19 20 21 22 23 24 25/);
+    # my @warehouse = (qw/undef undef 0 4 9 16 18 19 20 21 22 23 24 25/);
+    my @warehouse = (qw/undef undef 0 4 9 15 18 19 20 21 22 23 24 25/);
     my @cities = keys(%{$self->{ikariam}->{cities}});
     my $nextCities = ($#cities + 1) + 1;
 
@@ -107,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);
  
@@ -379,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');
--- a/city.yaml	Thu Nov 06 20:32:52 2008 +0800
+++ b/city.yaml	Thu Nov 06 20:36:24 2008 +0800
@@ -13,6 +13,7 @@
                # 1: increaseTransporter
             - is_corruption:
                1:
+                  # FIXME: 應該先升級皇宮
                   - is_warehouse_enougn_for_governorsresidence:
                      0: build_warehouse
                      1: build_palaceColony
@@ -24,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
--- a/overall.yaml	Thu Nov 06 20:32:52 2008 +0800
+++ b/overall.yaml	Thu Nov 06 20:36:24 2008 +0800
@@ -28,5 +28,5 @@
      # 希臘火, 建造噴火船
      - is_greekfire_researched:
         0: research_seafaring
-        
+
    1: run_defence
--- a/scan.pl	Thu Nov 06 20:32:52 2008 +0800
+++ b/scan.pl	Thu Nov 06 20:36:24 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");
+}
--- a/warfare.pl	Thu Nov 06 20:32:52 2008 +0800
+++ b/warfare.pl	Thu Nov 06 20:36:24 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.