changeset 173:e8a244ce5a1d

update the tavern setting
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 02 Nov 2008 04:12:00 +0800
parents ba03aa8abdb2
children 0cfc7a19a4d2
files Ikariam.pm agent.pl city.yaml
diffstat 3 files changed, 44 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Ikariam.pm	Sun Nov 02 00:30:02 2008 +0800
+++ b/Ikariam.pm	Sun Nov 02 04:12:00 2008 +0800
@@ -1,4 +1,3 @@
-#!/usr/bin/env perl
 BEGIN {
     foreach (((getpwuid($<))[7], $ENV{HOME}, $ENV{LOGDIR}, ".")) {
         require "$_/.eagleeye.pm" if (-f "$_/.eagleeye.pm");
@@ -373,6 +372,32 @@
     }
 }
 
+# for tavern only
+sub set {
+    my $self = shift;
+    my $type = shift;
+    my $cityId = shift;
+
+    die ("we don't know about this city") unless(defined($self->{'cities'}->{$cityId}));
+
+    my $position = -1;
+    my @locations = @{$self->{'cities'}->{$cityId}->{locations}};
+    foreach (0..$#locations) {
+        $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},
+                 }
+                 );
+ 
+    }
+}
+
 sub build {
     my $self = shift;
     my $type = shift;
--- a/agent.pl	Sun Nov 02 00:30:02 2008 +0800
+++ b/agent.pl	Sun Nov 02 04:12:00 2008 +0800
@@ -52,10 +52,7 @@
 
 sub is_happiness {
     my ($self, $city) = @_;
-    # FIXME.
-    # we should update the tavern setting.
 
-    # we should update the travl
     return ($city->{growth} >= 5 ?  1 : 0) 
         if($city->{buildings}->{townHall} <= 10);
 
@@ -64,6 +61,16 @@
     return ($city->{happiness} >= 2 ?  1 : 0);
 }
 
+sub is_tavern_available {
+    my ($self, $city) = @_;
+    return (defined($city->{buildings}->{tavern}) ? 1 : 0);
+}
+
+sub is_bacchanal {
+    my ($self, $city) = @_;
+    return ($city->{tavern}->{maxValue} == $city->{tavern}->{iniValue} ? 1 : 0);
+}
+
 sub is_warehouse_enough {
     my ($self, $city) = @_;
     # TODO 以速率計算容納率
@@ -162,7 +169,6 @@
     return (defined($self->{'ikariam'}->{research}->{4010}) ?  1 : 0);
 }
 
-
 sub is_barracks_level_enough {
     my ($self, $city) = @_;
     return 0 if(!defined($city->{buildings}->{barracks}));
@@ -246,7 +252,6 @@
 
 our $i = new Ikariam($::server, $::user, $::pass);
 $i->login;
-$i->checkMilitaryAdvisorCombatReports();
 my $cities = $i->check;
 
 # Genereic rules for both overall and city level arranagement.
--- a/city.yaml	Sun Nov 02 00:30:02 2008 +0800
+++ b/city.yaml	Sun Nov 02 04:12:00 2008 +0800
@@ -23,10 +23,15 @@
             - is_warehouse_enough:
                0: build_warehouse
             - is_happiness:
-               0: 
+               0:
                   - is_winepress_researched:
-                     # FIXME: we should update the tavern setting.
-                     1: build_tavern
+                     1:
+                        - is_tavern_available:
+                           0: build_tavern
+                           1: 
+                              - is_bacchanal:
+                                 0: set_tavern
+                                 1: build_tavern
             # TODO
             # http://ikariam.wikia.com/wiki/List_of_buildings
             # http://ikariam.wikia.com/wiki/Technology_Tree