comparison warfare.pl @ 128:2ff3704cca0e

fixed for ignore same tradegood.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 31 Oct 2008 01:50:05 +0800
parents a5517f0abb85
children 4194f261798b
comparison
equal deleted inserted replaced
127:a5517f0abb85 128:2ff3704cca0e
16 SELECT cities.cityId 16 SELECT cities.cityId
17 FROM user, cities 17 FROM user, cities
18 WHERE user.id = cities.user 18 WHERE user.id = cities.user
19 AND user.army_score_main = 0 19 AND user.army_score_main = 0
20 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? ) 20 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? )
21 AND cities.tradegood != ? 21 ORDER BY cities.citylevel * (cities.citylevel - 1) * user.trader_score_secondary / 10000 DESC
22 ORDER BY cities.citylevel * (cities.citylevel - 1) * user.trader_score_secondary / 10000 DESC LIMIT 30
23 } 22 }
24 ); 23 );
25 # $island->tradegood, 24 # $island->tradegood,
26 # qw/NULL 葡萄酒 大理石 水晶 硫磺/; 25 # qw/NULL 葡萄酒 大理石 水晶 硫磺/;
27 # 不打與自己相同的資源 26 # 不打與自己相同的資源
56 return ($city->{army}->{Swordsman} >= 2 ) ? 1 : 0; 55 return ($city->{army}->{Swordsman} >= 2 ) ? 1 : 0;
57 } 56 }
58 57
59 sub locateVictim { 58 sub locateVictim {
60 my ($self, $city, $x, $y, $tradegood) = @_; 59 my ($self, $city, $x, $y, $tradegood) = @_;
61 my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6), $tradegood); 60 my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6));
62 61
63 foreach my $city (@cities) { 62 foreach my $city (@cities) {
64 my $sheep = $city->user; 63 my $sheep = $city->user;
65 my $island = $city->island; 64 my $island = $city->island;
66 65
66 # we fight for island which ownes differnet trade goods.
67 next if($island->tradegood == $tradegood);
67 # Ignore the user in vacation which we can not attack. 68 # Ignore the user in vacation which we can not attack.
68 next if($city->status eq 'v'); 69 next if($city->status eq 'v');
69 unless ($city->status eq 'i') { 70 unless ($city->status eq 'i') {
70 unless (!defined($sheep->allyId) || $sheep->allyId == 0) { 71 unless (!defined($sheep->allyId) || $sheep->allyId == 0) {
71 my $ally = Ikariam::Ally->retrieve($sheep->allyId); 72 my $ally = Ikariam::Ally->retrieve($sheep->allyId);
125 # build and upgrade for cities 126 # build and upgrade for cities
126 my $tree = LoadFile('warfare.yaml'); 127 my $tree = LoadFile('warfare.yaml');
127 $cities->{$cityId}->{parse_path} = []; 128 $cities->{$cityId}->{parse_path} = [];
128 $cities->{$cityId}->{parse_answer} = undef; 129 $cities->{$cityId}->{parse_answer} = undef;
129 if(ParseTree($tree, $rules, $cities->{$cityId}) eq 'engagement') { 130 if(ParseTree($tree, $rules, $cities->{$cityId}) eq 'engagement') {
130 my $island = Ikariam::Island->retrive($cities->{$cityId}->{island}->{id}); 131 my $island = Ikariam::Island->retrieve($cities->{$cityId}->{island}->{id});
131 $rules->engagement($cityId, $island->{x}, $island->{y}, $island->tradegood); 132 $rules->engagement($cityId, $island->{x}, $island->{y}, $island->tradegood);
132 sleep(30); 133 sleep(30);
133 $i->checkMilitaryAdvisorMilitaryMovements(); 134 $i->checkMilitaryAdvisorMilitaryMovements();
134 } 135 }
135 print Dump($cities->{$cityId}->{parse_path}); 136 print Dump($cities->{$cityId}->{parse_path});