diff warfare.pl @ 122:11541129a389

fixed for counting ally members.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 30 Oct 2008 16:19:24 +0800
parents d3bece9b06b2
children f8c97e5d77ab
line wrap: on
line diff
--- a/warfare.pl	Thu Oct 30 16:05:11 2008 +0800
+++ b/warfare.pl	Thu Oct 30 16:19:24 2008 +0800
@@ -10,7 +10,6 @@
 use Data::Dumper;
 
 Ikariam::User->has_many(cities => 'Ikariam::Cities');
-Ikariam::User->has_a(ally => 'Ikariam::Ally');
 Ikariam::Cities->has_a(user => 'Ikariam::User');
 Ikariam::Cities->has_a(island => 'Ikariam::Island');
 Ikariam::Cities->set_sql(sheeps => qq {
@@ -50,7 +49,7 @@
 
 sub is_army_available {
     my ($self, $city) = @_;
-    return ($city->{army}->{Swordsman} > 2 ) ? 1 : 0;
+    return ($city->{army}->{Swordsman} >= 2 ) ? 1 : 0;
 }
 
 sub locateVictim {
@@ -64,9 +63,10 @@
         # Ignore 假期模式
         next if($city->status eq 'v');
         unless ($city->status eq 'i') {
-            unless ($sheep->allyId == '0') {
-                my $ally = $sheep->ally;
-                # Ignore 聯盟人數大於10
+            unless (!defined($sheep->allyId) || $sheep->allyId == 0) {
+                my $ally = Ikariam::Ally->retrieve($sheep->allyId);
+                # Ignore the ally which have more then 10 members. 
+                # We don't want to piss off the big team.
                 next if(defined($ally) && $ally->members > 10);
             }
         }
@@ -75,19 +75,20 @@
         my $c = Ikariam::Report->search_victim($city->cityId, time - 24*60*60 - 7*60*60)->count();
         # check the current plunders
         foreach (@{$self->{ikariam}->{'military'}->{'homeland'}}) {
-            # 出發跟回家都要計算唷
+            # counting for both leaving and coming back.
             $c++ if($_->{to} == $city->cityId || $_->{from} == $city->cityId);
         }
+        # we attack one city maximum 4 times a day.
         next if($c >= 4);
 
         # {
-        # if(1) {
             my $capture = $city->citylevel * ($city->citylevel - 1) * $sheep->trader_score_secondary / 10000;
-            my $line = sprintf("%d %s [%d,%d] %s (%d) %s/%s. Attacked %d", 
+            my $line = sprintf("%d %s [%d,%d] %s (%d) %s Attacked %d", 
                 $capture, $city->status, 
                 $island->x, $island->y,
                 $city->cityname, $city->cityId,
-                $sheep->name, $sheep->ally, $c);
+                $sheep->name, $c);
+            
             printf("%s\n", $line);
         # }
         return $city->cityId;