comparison agent.pl @ 207:48ea8222782a

automatic build spys
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Mon, 03 Nov 2008 18:40:15 +0800
parents b7af307a222d
children a2bb38589172
comparison
equal deleted inserted replaced
206:b7af307a222d 207:48ea8222782a
207 if ($self->is_greekfire_researched() eq 1) { 207 if ($self->is_greekfire_researched() eq 1) {
208 return ($city->{buildings}->{shipyard} >= 5 ? 1 : 0); 208 return ($city->{buildings}->{shipyard} >= 5 ? 1 : 0);
209 } else { 209 } else {
210 return ($city->{buildings}->{shipyard} >= 3 ? 1 : 0); 210 return ($city->{buildings}->{shipyard} >= 3 ? 1 : 0);
211 } 211 }
212 }
213
214 sub rule_engagement
215 {
216 my ($self, $city) = @_;
217 # TODO
218 # 計算距離, 可搶劫比例, 是否有聯盟, 軍事分數 (win rate)
219 }
220
221 sub rule_resource
222 {
223 # TODO
224 } 212 }
225 213
226 sub is_shipyard_upgrading { 214 sub is_shipyard_upgrading {
227 my ($self, $city) = @_; 215 my ($self, $city) = @_;
228 return $self->{'ikariam'}->is_shipyard_upgrading($city->{id}); 216 return $self->{'ikariam'}->is_shipyard_upgrading($city->{id});
257 245
258 sub is_army_trainning { 246 sub is_army_trainning {
259 my ($self, $city) = @_; 247 my ($self, $city) = @_;
260 return $self->{ikariam}->is_army_trainning($city->{id}); 248 return $self->{ikariam}->is_army_trainning($city->{id});
261 } 249 }
262
263 sub train_army { 250 sub train_army {
264 my ($self, $city) = @_; 251 my ($self, $city) = @_;
265 my $cityId = $city->{id}; 252 my $cityId = $city->{id};
266 253
267 # TODO, 依照升級比例算 CP 值最高 254 # TODO, 依照升級比例算 CP 值最高
330 Carp::carp("Current army expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure); 317 Carp::carp("Current army expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure);
331 return 1; 318 return 1;
332 } 319 }
333 return 0; 320 return 0;
334 } 321 }
322
335 1; 323 1;
336 324
337 325
338 package main; 326 package main;
339 my $verbose = 1; 327 my $verbose = 1;
366 } 354 }
367 print("\n"); 355 print("\n");
368 356
369 # maybe this should be moved to Rules. 357 # maybe this should be moved to Rules.
370 $i->blanceHurmanResource($cityId); 358 $i->blanceHurmanResource($cityId);
371 359
360 # build spy
361 $i->buildSpy('spy', $cityId);
362
363 # build military!
372 $tree = LoadFile('military.yaml'); 364 $tree = LoadFile('military.yaml');
373 $cities->{$cityId}->{parse_path} = []; 365 $cities->{$cityId}->{parse_path} = [];
374 $cities->{$cityId}->{parse_answer} = undef; 366 $cities->{$cityId}->{parse_answer} = undef;
375 if (my $action = ParseTree($tree, $rules, $cities->{$cityId})) { 367 if (my $action = ParseTree($tree, $rules, $cities->{$cityId})) {
376 triggerAction($action, $cityId); 368 triggerAction($action, $cityId);