comparison 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
comparison
equal deleted inserted replaced
26:d8117792c6f5 27:dd85b55eec2a
7 use_base => 'Class::DBI::SQLite', 7 use_base => 'Class::DBI::SQLite',
8 namespace => 'Ikariam', 8 namespace => 'Ikariam',
9 ); 9 );
10 10
11 package Ikariam; 11 package Ikariam;
12 12 use strict;
13 use Data::Dumper; 13 use Data::Dumper;
14 use LWP; 14 use LWP;
15 # use LWP::Debug qw(+ -conns -trace -debug); 15 # use LWP::Debug qw(+ -conns -trace -debug);
16 use LWP::Debug qw(+trace); 16 use LWP::Debug qw(+trace);
17 use HTTP::Cookies; 17 use HTTP::Cookies;
191 191
192 # find inactivity and vacation 192 # find inactivity and vacation
193 my %status; 193 my %status;
194 foreach my $class (qw/inactivity vacation/) 194 foreach my $class (qw/inactivity vacation/)
195 { 195 {
196 @elems = $html->getElementsByAttribute("class", $class); 196 my @elems = $html->getElementsByAttribute("class", $class);
197 foreach my $elem (@elems) { 197 foreach my $elem (@elems) {
198 if($elem->innerText() =~ /^(.*?) \((\w)\)/) { 198 if($elem->innerText() =~ /^(.*?) \((\w)\)/) {
199 $status{$1} = $2; 199 $status{$1} = $2;
200 # printf("%s\n", $elem->innerText()); 200 # printf("%s\n", $elem->innerText());
201 } 201 }
324 $self->{'cities'}->{$cityId}->{corruption} = $elem->innerText(); 324 $self->{'cities'}->{$cityId}->{corruption} = $elem->innerText();
325 $self->{'cities'}->{$cityId}->{corruption} =~ s/%//g; 325 $self->{'cities'}->{$cityId}->{corruption} =~ s/%//g;
326 } 326 }
327 327
328 # count 328 # count
329 my $cities_type = { 329 my @citizens_type = qw/citizens woodworkers specialworkers scientists/;
330 citizens => 8,
331 woodworkers => 10,
332 specialworkers => 12,
333 scientists => 14,
334 };
335
336 @elems = $html->getElementsByAttribute('class', 'count'); 330 @elems = $html->getElementsByAttribute('class', 'count');
337 $self->{'cities'}->{$cityId}->{'cities'} = {}; 331 $self->{'cities'}->{$cityId}->{'citizens'} = {};
338 foreach my $type (keys(%$cities_type)) 332 $self->{'cities'}->{$cityId}->{'citizens'}->{total} = 0;
333
334 foreach my $i (0..$#citizens_type)
339 { 335 {
340 $self->{'cities'}->{$cityId}->{'cities'}->{$type} = $elems[$cities_type{$type}]->innerText(); 336 $self->{'cities'}->{$cityId}->{'citizens'}->{$citizens_type[$i]} = $elems[$i]->innerText();
337 $self->{'cities'}->{$cityId}->{'citizens'}->{total} += $elems[$i]->innerText();;
341 } 338 }
342 339
343 # production 340 # production
344 # skin/resources/icon_gold.gif 341 # skin/resources/icon_gold.gif
345 # skin/resources/icon_wood.gif 342 # skin/resources/icon_wood.gif
346 # skin/resources/icon_sulfur.gif (?) 343 # skin/resources/icon_sulfur.gif (?)
347 # skin/resources/icon_research.gif 344 # skin/resources/icon_research.gif
348 345
349 # foreach my $i (0..$#cities_type) {
350 # next if($cities_type[$i] eq 'undef');
351 # if(defined($elems[$i])) {
352 # $self->{'cities'}->{$cityId}->{'cities_'.$type}->{$cities_type[$i]} = $elems[$i]->innerText();
353 # }
354 # }
355 346
356 # check armies 347 # check armies
357 my %force_types; 348 my %force_types;
358 $force_types{'army'} = [ qw/undef undef Slinger Swordsman Phalanx Ram Archer Catapult Gunsman Mortar SteamGiant Gyrocopter Bombardier Doctor Cook/ ]; 349 $force_types{'army'} = [ qw/undef undef Slinger Swordsman Phalanx Ram Archer Catapult Gunsman Mortar SteamGiant Gyrocopter Bombardier Doctor Cook/ ];
359 $force_types{'fleet'} = [ qw/undef undef Ram-Ship BallistaShip Flamethrower CatapultShip MortarShip PaddleWheelRam DivingBoat/ ]; 350 $force_types{'fleet'} = [ qw/undef undef Ram-Ship BallistaShip Flamethrower CatapultShip MortarShip PaddleWheelRam DivingBoat/ ];