diff Ikariam.pm @ 87:4c82cf844aa8

counting navy expenditure
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 26 Oct 2008 15:02:06 +0800
parents a8acf50bf7bb
children 0fa9cd836e1e
line wrap: on
line diff
--- a/Ikariam.pm	Sun Oct 26 14:30:58 2008 +0800
+++ b/Ikariam.pm	Sun Oct 26 15:02:06 2008 +0800
@@ -91,7 +91,7 @@
 use Data::Dumper;
 use LWP;
 # use LWP::Debug qw(+ -conns -trace -debug);
-use LWP::Debug qw(+trace);
+# use LWP::Debug qw(+trace);
 use HTTP::Cookies;
 use WWW::Mechanize;
 use HTML::TagParser;
@@ -157,6 +157,7 @@
         view => 'highscore'
         ]);
 
+    # TODO rewrite with Xpath
     my $c;
     my $status = gunzip \$res->content => \$c 
         or die "gunzip failed: $GunzipError\n";
@@ -648,6 +649,7 @@
         my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=cityMilitary-%s&id=%d', $self->{server}, $x, $cityId));
         my @numbers = Ikariam::Extractor->new(content => $res->content)->find('//table//tr/td');
         foreach my $j (0..$#{$force_types{$x}}) {
+            next if(!defined($force_types{$x}[$j]));
             if ($numbers[$j] == '-') {
                 $self->{'cities'}->{$cityId}->{$x}->{$force_types{$x}[$j]} = 0;
             } else {
@@ -692,6 +694,28 @@
     return ($self->{cities}->{$cityId}->{citizens}->{total}*4 - $self->{cities}->{$cityId}->{citizens}->{scientists}*8 );
 }
 
+sub getNavyExpenditure {
+    my $self = shift;
+    my $cityId = shift;
+    my $cities = $self->{cities};
+
+    my $ships = {
+        CargoShip => {n => "CargoShip",a => 0,d => 0,s => 4,c => "Steamship",v => 20,A => 0,D => 0},
+        'Ram-Ship' => {n => "Ram-Ship",p => 6,w => 56,S => 21,b => "34m",u => 20,m => 1,o => 3,a => 16,d => 16,A => 4,D => 4,s => 10,c => "Sailer",v => 10},
+        BallistaShip => {n => "BallistaShip",p => 5,w => 72,S => 29,b => "47m",u => 24,m => 3,o => 5,a => 20,d => 28,A => 5,D => 7,s => 11,c => "Sailer",v => 8,x => "Resistance"},
+        Flamethrower => {n => "Flamethrower",p => 5,w => 105,S => 77,b => "1h 55m",u => 45,m => 5,o => 7,a => 40,d => 40,A => 10,D => 10,s => 12,c => "Steamship",v => 8,x => "Assault"},
+        CatapultShip => {n => "CatapultShip",p => 10,w => 173,S => 76,b => "3h 11m",u => 57,m => 7,o => 10,a => 60,d => 60,A => 12,D => 12,s => 16,c => "Sailer",v => 6},
+        MortarShip => {n => "MortarShip",p => 22,w => 456,S => 282,b => "3h 38m",u => 130,m => 12,o => 15,a => 160,d => 160,A => 35,D => 35,s => 14,c => "Steamship",v => 4},
+        PaddleWheelRam => {n => "PaddleWheelRam",i => "steamboat",p => 12,w => 513,S => 167,b => "4h 8m",u => 114,m => 10,o => 13,a => 100,d => 90,A => 20,D => 18,s => 13,c => "Steamship",v => 8,x => "Assault"},
+        DivingBoat => {n => "DivingBoat",i => "submarine",p => 16,w => 493,C => 378,b => "5h 5m",u => 126,m => 15,o => 16,a => 110,d => 155,A => 20,D => 30,s => 10,c => "Steamship",v => 2,x => "Resistance"}
+    };
+    my $cost = 0;
+    foreach(keys(%{$cities->{$cityId}->{fleet}})) {
+        $cost += $cities->{$cityId}->{fleet}->{$_} * $ships->{$_}->{u};
+    }
+    return $cost;
+}
+
 sub getMilityExpenditure {
     my $self = shift;
     my $cityId = shift;
@@ -728,7 +752,6 @@
     };
 
     my $cost = 0;
-
     foreach(keys(%{$cities->{$cityId}->{army}})) {
         # printf("%s %d = %d\n", $_, $cities->{$cityId}->{army}->{$_},  $cities->{$cityId}->{army}->{$_} * $troops->{$_}->{u});
         $cost += $cities->{$cityId}->{army}->{$_} * $troops->{$_}->{u};