comparison warfare.pl @ 153:25dcc1fffeef

friend or foe identification
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sat, 01 Nov 2008 04:29:08 +0800
parents 4194f261798b
children 1499b0d496b6
comparison
equal deleted inserted replaced
152:60a09758a885 153:25dcc1fffeef
58 return ($city->{army}->{Swordsman} >= 2 ) ? 1 : 0; 58 return ($city->{army}->{Swordsman} >= 2 ) ? 1 : 0;
59 } 59 }
60 60
61 sub locateVictim { 61 sub locateVictim {
62 my ($self, $city, $x, $y, $tradegood) = @_; 62 my ($self, $city, $x, $y, $tradegood) = @_;
63
64 my $user = Ikariam::User->search('name' => $::user);
65
63 my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6)); 66 my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6));
64
65 foreach my $city (@cities) { 67 foreach my $city (@cities) {
66 my $sheep = $city->user; 68 my $sheep = $city->user;
67 my $island = $city->island; 69 my $island = $city->island;
68 70
71 # we don't fight with members in same ally.
72 next if($sheep->allyId == $user->allyId);
69 # we fight for island which ownes differnet trade goods. 73 # we fight for island which ownes differnet trade goods.
70 next if($island->tradegood == $tradegood); 74 next if($island->tradegood == $tradegood);
71 # Ignore the user in vacation which we can not attack. 75 # Ignore the user in vacation which we can not attack.
72 next if($city->status eq 'v'); 76 next if($city->status eq 'v');
73 unless ($city->status eq 'i') { 77 unless ($city->status eq 'i') {
104 return undef; 108 return undef;
105 } 109 }
106 110
107 sub engagement { 111 sub engagement {
108 my ($self, $cityId, $x, $y, $tradegood) = @_; 112 my ($self, $cityId, $x, $y, $tradegood) = @_;
113 print($::i);
114 exit;
109 my $victim = $self->locateVictim($cityId, $x, $y, $tradegood); 115 my $victim = $self->locateVictim($cityId, $x, $y, $tradegood);
110 if(defined($victim)) { 116 if(defined($victim)) {
111 $self->{ikariam}->changeCity($cityId); 117 $self->{ikariam}->changeCity($cityId);
112 $self->{ikariam}->plunderCity($victim); 118 $self->{ikariam}->plunderCity($victim);
113 } 119 }