changeset 55:ff00d108e955

check resources for build_townHall
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Mon, 20 Oct 2008 23:44:45 +0800
parents 2d3c394b7940
children 6e0d5e781949
files agent.pl building.yaml
diffstat 2 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/agent.pl	Mon Oct 20 23:24:15 2008 +0800
+++ b/agent.pl	Mon Oct 20 23:44:45 2008 +0800
@@ -81,6 +81,19 @@
     }
 }
 
+sub is_resource_enoghforHall {
+    my ($self, $city) = @_;
+    my @wood = qw/udnef 0 70 98 65 129 236 402 594 849 1176 1586 2101 3208 4937 7171 10139 14537 18420 22896 28047 33934 40623 48017 56511 226044 452088 904176 1808352 3616704 7233408 14466816 28933632/;
+    my @marble = qw/undef 0 0 17 28 66 95 156 243 406 579 799 1348 2124 2951 4409 6461 8187 10176 12466 15082 18055 21381 25116 100464 200928 401856 803712 1607424 3214848 6429696 12859392/;
+
+    my $level = $city->{buildings}->{townHall};
+    if($city->{resources}->{woold} >= $wood[$level] && $city->{resources}->{marble} >= $marble[$level] ) {
+        return 1;
+    }
+    warn("Resource is short for build city hall.");
+    return 0;
+}
+
 sub is_drydock_researched {
     my ($self, $city) = @_;
     return (defined($city->{research}->{4010}) ?  1 : 0);
@@ -138,7 +151,11 @@
     {
         # TODO: remove the last rule, if the result is fallback
         triggerAction($action, $cityId);
-        last;
+        if($cities->{$cityId}->{parse_answer} ne "fallback") {
+            last ;
+        } else {
+
+        }
     }
     # Debug
     print(Dumper($cities->{$cityId}->{parse_path}));
--- a/building.yaml	Mon Oct 20 23:24:15 2008 +0800
+++ b/building.yaml	Mon Oct 20 23:44:45 2008 +0800
@@ -16,7 +16,9 @@
             - is_wall_enough:
                0: build_wall
             - is_space_enough:
-               0: build_townHall
+               0: 
+                  - is_resource_enoghforHall:
+                     1: build_townHall
             - is_corruption:
                1: build_governorsresidence
             # 倉庫庫存量