diff Ikariam.pm @ 27:dd85b55eec2a

implemented basic inference engine.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 10 Oct 2008 03:38:49 +0800
parents d8117792c6f5
children 99723b8f348b
line wrap: on
line diff
--- a/Ikariam.pm	Fri Oct 10 03:20:36 2008 +0800
+++ b/Ikariam.pm	Fri Oct 10 03:38:49 2008 +0800
@@ -9,7 +9,7 @@
 );
 
 package Ikariam;
-
+use strict;
 use Data::Dumper;
 use LWP;
 # use LWP::Debug qw(+ -conns -trace -debug);
@@ -193,7 +193,7 @@
     my %status;
     foreach my $class (qw/inactivity vacation/)
     {
-        @elems = $html->getElementsByAttribute("class", $class);
+        my @elems = $html->getElementsByAttribute("class", $class);
         foreach my $elem (@elems) {
             if($elem->innerText() =~ /^(.*?) \((\w)\)/) {
                 $status{$1} = $2;
@@ -326,18 +326,15 @@
         }
 
         # count
-        my $cities_type = {
-            citizens => 8,
-            woodworkers => 10, 
-            specialworkers => 12,
-            scientists => 14,
-        };
+        my @citizens_type = qw/citizens woodworkers specialworkers scientists/;
+        @elems = $html->getElementsByAttribute('class', 'count');
+        $self->{'cities'}->{$cityId}->{'citizens'} = {};
+        $self->{'cities'}->{$cityId}->{'citizens'}->{total} = 0;
 
-        @elems = $html->getElementsByAttribute('class', 'count');
-        $self->{'cities'}->{$cityId}->{'cities'} = {};
-        foreach my $type (keys(%$cities_type))
+        foreach my $i (0..$#citizens_type)
         {
-            $self->{'cities'}->{$cityId}->{'cities'}->{$type} = $elems[$cities_type{$type}]->innerText();
+            $self->{'cities'}->{$cityId}->{'citizens'}->{$citizens_type[$i]} = $elems[$i]->innerText();
+            $self->{'cities'}->{$cityId}->{'citizens'}->{total} += $elems[$i]->innerText();;
         }
 
         # production
@@ -346,12 +343,6 @@
         # skin/resources/icon_sulfur.gif (?)
         # skin/resources/icon_research.gif
 
-#        foreach my $i (0..$#cities_type) {
-#            next if($cities_type[$i] eq 'undef');
-#            if(defined($elems[$i])) {
-#                $self->{'cities'}->{$cityId}->{'cities_'.$type}->{$cities_type[$i]} = $elems[$i]->innerText();
-#            }
-#        }
 
         # check armies
         my %force_types;