comparison agent.pl @ 199:b33c8dbe9b04

fixed is_any_corruption
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Mon, 03 Nov 2008 12:00:54 +0800
parents 2dfeb4371db7
children eec013e81fb0
comparison
equal deleted inserted replaced
198:2dfeb4371db7 199:b33c8dbe9b04
49 my ($self, $city) = @_; 49 my ($self, $city) = @_;
50 my @warehouse = (qw/undef undef 0 4 9 16 18 19 20 21 22 23 24 25/); 50 my @warehouse = (qw/undef undef 0 4 9 16 18 19 20 21 22 23 24 25/);
51 my @cities = keys(%{$self->{ikariam}->{cities}}); 51 my @cities = keys(%{$self->{ikariam}->{cities}});
52 52
53 Carp::carp(sprintf("Required warehouse level %s, current is %s only\n", $warehouse[$#cities], $city->{buildings}->{warehouse})); 53 Carp::carp(sprintf("Required warehouse level %s, current is %s only\n", $warehouse[$#cities], $city->{buildings}->{warehouse}));
54 return 0 if(!defined($city->{buildings}->{warehouse}));
54 return ($city->{buildings}->{warehouse} > $warehouse[$#cities]) ? 0 : 1; 55 return ($city->{buildings}->{warehouse} > $warehouse[$#cities]) ? 0 : 1;
55 } 56 }
56 57
57 sub is_corruption { 58 sub is_corruption {
58 my ($self, $city) = @_; 59 my ($self, $city) = @_;
61 62
62 sub is_any_corruption { 63 sub is_any_corruption {
63 my ($self, $city) = @_; 64 my ($self, $city) = @_;
64 65
65 foreach (keys(%{$self->{ikariam}->{cities}})) { 66 foreach (keys(%{$self->{ikariam}->{cities}})) {
66 return ($self->{ikariam}->{cities}->{$_}->{corruption} > 0) ? 1 : 0; 67 return 1 if ($self->{ikariam}->{cities}->{$_}->{corruption} > 0);
67 } 68 }
68 return 0; 69 return 0;
69 } 70 }
70 71
71 sub is_happiness { 72 sub is_happiness {