Mercurial > eagle-eye
view inference.pl @ 29:dbec53e754e3
added rule_building
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 10 Oct 2008 05:15:40 +0800 |
parents | 99723b8f348b |
children | de5de6d472f9 |
line wrap: on
line source
#!/usr/bin/perl use strict; use Ikariam; use Data::Dumper; package main; our $cities; our $server = 's2.ikariam.tw'; sub Warn { my ($city, $msg) = @_; printf("WARNING: http://%s/index.php?view=city&id=%s (%s) %s \n", $server, $city, $cities->{$city}->{name}, $msg); } our $i = new Ikariam($server, "chihchun", "c795d57d"); $i->login; $cities = $i->check; $i->logout; print(Dumper($cities)); sub rule_happiness { my $id = shift; if($cities->{$id}->{happiness} >= 3) { Warn($id, sprintf("is not happy (%s)!", $cities->{$id}->{happiness_text})); } } sub rule_resource { my $id = shift; # checking goods foreach my $good (qw/wood wine marble crystal/) { if($cities->{$id}->{$good} <= 100) { Warn($id, sprintf("Running out %s (%d)!", $good, $cities->{$id}->{$good})); } } } sub rule_building { my $cityId = shift; # 城鎮跟圍牆 if($cities->{$cityId}->{buildings}->{wall} < $cities->{$cityId}->{buildings}->{townHall}) { Warn($cityId, sprintf("Wall level (%d) is lower then twon hall (%d)!", $cities->{$cityId}->{buildings}->{wall}, $cities->{$cityId}->{buildings}->{townHall} )); } } # 貪腐 sub rule_corruption { my $id = shift; if($cities->{$id}->{corruption} > 0) { Warn($id, sprintf("corruption is %d", $cities->{$id}->{corruption})); } } # space # Checking rules foreach my $procedure (qw/rule_happiness rule_corruption rule_building rule_resource/) { foreach my $id (keys(%$cities)) { eval(sprintf("%s(%s);", $procedure, $id)); } }