diff agent.pl @ 86:a8acf50bf7bb

implemented a simple MilityExpenditure counting
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 26 Oct 2008 14:30:58 +0800
parents 2c6c219dc3ff
children 4c82cf844aa8
line wrap: on
line diff
--- a/agent.pl	Sun Oct 26 12:26:43 2008 +0800
+++ b/agent.pl	Sun Oct 26 14:30:58 2008 +0800
@@ -38,6 +38,7 @@
 sub is_space_enough {
     my ($self, $city) = @_;
     # TODO 應該以消耗率/時間計算
+    # $self->{ikariam}->{growth}
     return ($city->{space}->{total} <= ($city->{space}->{occupied}+6) ?  0 : 1)
 }
 
@@ -168,6 +169,29 @@
 {
     # TODO 
 }
+
+sub rule_milityExpenditure
+{
+    my ($self, $cityId) = @_;
+    my $workersRatio = {
+        'citizens' => 0.4,
+        'specialworkers' => 0.3,
+        'woodworkers' => 0.7,
+    };
+
+    my $currentCost = $self->{'ikariam'}->getMilityExpenditure($cityId);
+    my $netincome = $self->{'ikariam'}->getNetIncome($cityId);
+    
+    # 軍費為 兩成 淨收入
+    my $militaryExpenditure = int($netincome * 0.2);
+
+    if($currentCost < $militaryExpenditure) {
+        printf("Current mility expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure);
+    }
+
+    # TODO, 海軍
+
+}
 1; 
 
 
@@ -189,7 +213,6 @@
 triggerAction($action, (keys(%$cities))[0]) if(defined($action));
 print STDERR Dump($decision) if(defined($verbose));
 
-
 # show cities.
 foreach my $cityId (keys(%$cities)) {
     printf("%s http://%s/index.php?view=city&id=%d\n", 
@@ -205,20 +228,19 @@
         print("\n");
     }
     print("\n");
+
+    # maybe this should be moved to Rules.
     $i->blanceHurmanResource($cityId);
+    # 
+    $rules->rule_milityExpenditure($cityId);
 
     # build and upgrade for cities
     $tree  = LoadFile('city.yaml');
     $cities->{$cityId}->{parse_path} = [];
     $cities->{$cityId}->{parse_answer} = undef;
-    while (my $action = ParseTree($tree, $rules, $cities->{$cityId}))
-    {
+    while (my $action = ParseTree($tree, $rules, $cities->{$cityId})) {
         triggerAction($action, $cityId);
-        if($cities->{$cityId}->{parse_answer} ne "fallback") {
-            last ;
-        } else {
-            # TODO: remove the last rule, if the result is fallback
-        }
+        last;
     }
     # Debug
     # print(Dump($cities->{$cityId}->{parse_path})) if(defined($verbose));