annotate warfare.pl @ 322:4cf62bfa4cbd

changed the level of shipyard
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 28 Jan 2009 21:51:47 +0800
parents d194ff3edb2f
children 118605b58d09
rev   line source
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
1 #!/usr/bin/perl
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
2 use strict;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
3 use Ikariam;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
4 use Data::Dumper;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
5 use Decision::ParseTree q{ParseTree};
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
6 use YAML qw/LoadFile Dump DumpFile/;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
7
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
8 package Ikariam::Warfare::Rules;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
9 use strict;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
10 use Data::Dumper;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
12 Ikariam::User->has_many(cities => 'Ikariam::Cities');
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
13 Ikariam::Cities->has_a(user => 'Ikariam::User');
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
14 Ikariam::Cities->has_a(island => 'Ikariam::Island');
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
15 Ikariam::Cities->set_sql(sheeps => qq {
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
16 SELECT cities.cityId
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
17 FROM user, cities
125
4374173bab47 collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 124
diff changeset
18 WHERE user.id = cities.user
4374173bab47 collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 124
diff changeset
19 AND user.army_score_main = 0
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
20 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? )
128
2ff3704cca0e fixed for ignore same tradegood.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 127
diff changeset
21 ORDER BY cities.citylevel * (cities.citylevel - 1) * user.trader_score_secondary / 10000 DESC
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
22 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
23 );
135
4194f261798b check for transporters is available
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 128
diff changeset
24
108
d3bece9b06b2 fixed the couting *again*
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 107
diff changeset
25 Ikariam::Report->set_sql(victim => qq {
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
26 SELECT report.id
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
27 FROM report
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28 WHERE report.city = ?
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29 AND report.date >= ?
108
d3bece9b06b2 fixed the couting *again*
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 107
diff changeset
30 }
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 );
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
33 sub new {
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
34 my ( $class, $i ) = @_;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
35 my $self = {
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36 ikariam => $i,
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
37 };
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
38 return bless $self, $class;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
39 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
40
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
41 sub is_attacked {
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
42 my ($self, $city) = @_;
259
a4e52feec5a5 fixed a typo in is_attacked. fixed actionPoint number.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 258
diff changeset
43 return ($self->{'ikariam'}->{'military'}->{attack} > 0 ) ? 1 : 0;
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46 sub is_actionPoint_enough {
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47 my ($self, $city) = @_;
259
a4e52feec5a5 fixed a typo in is_attacked. fixed actionPoint number.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 258
diff changeset
48 return ($city->{actionPoints} > ($city->{maxActionPoints}/3) ) ? 1 : 0;
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
49 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
50
135
4194f261798b check for transporters is available
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 128
diff changeset
51 sub is_transporters_available {
4194f261798b check for transporters is available
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 128
diff changeset
52 my ($self, $city) = @_;
205
d9f17bcbf1f1 we keep 10 transporters for prize
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 197
diff changeset
53 # we keep 10 transporters for prize
d9f17bcbf1f1 we keep 10 transporters for prize
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 197
diff changeset
54 return ($city->{transporters}->{avail} > 10) ? 1 : 0;
135
4194f261798b check for transporters is available
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 128
diff changeset
55 }
4194f261798b check for transporters is available
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 128
diff changeset
56
179
8afd380c20ac do not fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 157
diff changeset
57 sub is_port_available {
8afd380c20ac do not fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 157
diff changeset
58 my ($self, $city) = @_;
8afd380c20ac do not fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 157
diff changeset
59 foreach(1..2) {
8afd380c20ac do not fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 157
diff changeset
60 return 1 if($city->{locations}[$_] eq 'port');
8afd380c20ac do not fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 157
diff changeset
61 }
8afd380c20ac do not fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 157
diff changeset
62 return 0;
8afd380c20ac do not fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 157
diff changeset
63 }
8afd380c20ac do not fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 157
diff changeset
64
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
65 sub is_army_available {
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
66 my ($self, $city) = @_;
263
83e3ce37779d refined army scheme
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 261
diff changeset
67 # 方陣撞不死
268
285d5b39ef2c we hused 3 Phalanx for plunder
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 266
diff changeset
68 # return ($city->{army}->{Swordsman} >= 2 && $city->{army}->{Phalanx} >= 1) ? 1 : 0;
285d5b39ef2c we hused 3 Phalanx for plunder
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 266
diff changeset
69 return ($city->{army}->{Phalanx} >= 3) ? 1 : 0;
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
70 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
71
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
72 sub locateVictim {
127
a5517f0abb85 fixed a small missed param.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 125
diff changeset
73 my ($self, $city, $x, $y, $tradegood) = @_;
153
25dcc1fffeef friend or foe identification
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 135
diff changeset
74
157
4b5e1d3a5198 fixed a typo.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 156
diff changeset
75 my $user = Ikariam::User->retrieve('name' => $::user);
153
25dcc1fffeef friend or foe identification
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 135
diff changeset
76
128
2ff3704cca0e fixed for ignore same tradegood.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 127
diff changeset
77 my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6));
156
ba7a805b3fe4 added new feature - don't fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 155
diff changeset
78 CITY: foreach my $city (@cities) {
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
79 my $sheep = $city->user;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
80 my $island = $city->island;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
81
232
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 209
diff changeset
82 # TODO update sheep and island information.
156
ba7a805b3fe4 added new feature - don't fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 155
diff changeset
83
ba7a805b3fe4 added new feature - don't fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 155
diff changeset
84 # we don't fight friends.
ba7a805b3fe4 added new feature - don't fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 155
diff changeset
85 # FIXME: This is very dirty for accessing to $::i directly.
ba7a805b3fe4 added new feature - don't fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 155
diff changeset
86 foreach (keys(%{$::i->{friends}})) {
ba7a805b3fe4 added new feature - don't fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 155
diff changeset
87 next CITY if ($sheep->id == $_);
ba7a805b3fe4 added new feature - don't fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 155
diff changeset
88 }
ba7a805b3fe4 added new feature - don't fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 155
diff changeset
89
153
25dcc1fffeef friend or foe identification
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 135
diff changeset
90 # we don't fight with members in same ally.
25dcc1fffeef friend or foe identification
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 135
diff changeset
91 next if($sheep->allyId == $user->allyId);
156
ba7a805b3fe4 added new feature - don't fight with friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 155
diff changeset
92
124
f8c97e5d77ab translated comments.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 122
diff changeset
93 # Ignore the user in vacation which we can not attack.
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
94 next if($city->status eq 'v');
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
95 unless ($city->status eq 'i') {
260
a5bd0050dd12 fixed the wrong syntax.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 259
diff changeset
96 # we fight for island which ownes differnet trade goods.
a5bd0050dd12 fixed the wrong syntax.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 259
diff changeset
97 next CITY if($island->tradegood == $tradegood);
a5bd0050dd12 fixed the wrong syntax.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 259
diff changeset
98
122
11541129a389 fixed for counting ally members.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 108
diff changeset
99 unless (!defined($sheep->allyId) || $sheep->allyId == 0) {
241
64549ddddf4a count by ally score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 232
diff changeset
100 my $ally = Ikariam::Ally->retrieve($user->allyId);
64549ddddf4a count by ally score
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 232
diff changeset
101 my $targetAlly = Ikariam::Ally->retrieve($sheep->allyId);
122
11541129a389 fixed for counting ally members.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 108
diff changeset
102 # We don't want to piss off the big team.
270
6bce423892f4 updated plunderCity and blockadeCity
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 268
diff changeset
103 next CITY if(!defined($ally));
260
a5bd0050dd12 fixed the wrong syntax.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 259
diff changeset
104 next CITY if($ally->score == 0);
a5bd0050dd12 fixed the wrong syntax.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 259
diff changeset
105 next CITY if($targetAlly->score > $ally->score);
a5bd0050dd12 fixed the wrong syntax.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 259
diff changeset
106 next CITY if(defined($ally) && $ally->members > 12);
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
107 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
108 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
109
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
110 # check if we over-attacked
108
d3bece9b06b2 fixed the couting *again*
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 107
diff changeset
111 my $c = Ikariam::Report->search_victim($city->cityId, time - 24*60*60 - 7*60*60)->count();
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
112 # check the current plunders
108
d3bece9b06b2 fixed the couting *again*
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 107
diff changeset
113 foreach (@{$self->{ikariam}->{'military'}->{'homeland'}}) {
122
11541129a389 fixed for counting ally members.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 108
diff changeset
114 # counting for both leaving and coming back.
108
d3bece9b06b2 fixed the couting *again*
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 107
diff changeset
115 $c++ if($_->{to} == $city->cityId || $_->{from} == $city->cityId);
258
689c4c9fa56b fixed loop
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 251
diff changeset
116
689c4c9fa56b fixed loop
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 251
diff changeset
117 # we don't attack same city twice at same time.
689c4c9fa56b fixed loop
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 251
diff changeset
118 next CITY if($_->{to} == $city->cityId);
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
119 }
122
11541129a389 fixed for counting ally members.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 108
diff changeset
120 # we attack one city maximum 4 times a day.
266
53827cc442b6 we attack same city 6 times, if the owner is inactive.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 263
diff changeset
121 if ($city->status eq 'i') {
53827cc442b6 we attack same city 6 times, if the owner is inactive.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 263
diff changeset
122 next CITY if($c >= 6);
53827cc442b6 we attack same city 6 times, if the owner is inactive.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 263
diff changeset
123 } else {
53827cc442b6 we attack same city 6 times, if the owner is inactive.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 263
diff changeset
124 next CITY if($c >= 4);
53827cc442b6 we attack same city 6 times, if the owner is inactive.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 263
diff changeset
125 }
107
554bdd49c703 we should also count the force which is coming back
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 105
diff changeset
126
209
31fca1e55ed5 we don't fight with sheep has only a little money
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 205
diff changeset
127 my $capture = $city->citylevel * ($city->citylevel - 1) * $sheep->trader_score_secondary / 10000;
31fca1e55ed5 we don't fight with sheep has only a little money
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 205
diff changeset
128 next if($capture < 1500);
31fca1e55ed5 we don't fight with sheep has only a little money
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 205
diff changeset
129
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
130 # {
122
11541129a389 fixed for counting ally members.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 108
diff changeset
131 my $line = sprintf("%d %s [%d,%d] %s (%d) %s Attacked %d",
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
132 $capture, $city->status,
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
133 $island->x, $island->y,
104
b369fe3c1992 fixed typo and war counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 101
diff changeset
134 $city->cityname, $city->cityId,
122
11541129a389 fixed for counting ally members.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 108
diff changeset
135 $sheep->name, $c);
11541129a389 fixed for counting ally members.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 108
diff changeset
136
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
137 printf("%s\n", $line);
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
138 # }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
139 return $city->cityId;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
140 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
141 return undef;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
142 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
143
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
144 sub engagement {
125
4374173bab47 collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 124
diff changeset
145 my ($self, $cityId, $x, $y, $tradegood) = @_;
4374173bab47 collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 124
diff changeset
146 my $victim = $self->locateVictim($cityId, $x, $y, $tradegood);
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
147 if(defined($victim)) {
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
148 $self->{ikariam}->changeCity($cityId);
270
6bce423892f4 updated plunderCity and blockadeCity
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 268
diff changeset
149 $self->{ikariam}->plunderCity($victim,
6bce423892f4 updated plunderCity and blockadeCity
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 268
diff changeset
150 {
6bce423892f4 updated plunderCity and blockadeCity
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 268
diff changeset
151 # cargo_army_302 => '2', # 劍士
287
d194ff3edb2f reduced default number of army for plunderCity
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 270
diff changeset
152 cargo_army_303 => '2', # 方陣
270
6bce423892f4 updated plunderCity and blockadeCity
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 268
diff changeset
153 }
6bce423892f4 updated plunderCity and blockadeCity
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 268
diff changeset
154 );
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
155 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
156 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
157
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
158 1;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
159
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
160 package main;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
161
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
162 our $i = new Ikariam($::server, $::user, $::pass);
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
163 our $rules = Ikariam::Warfare::Rules->new($i);
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
164
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
165 $i->login;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
166 my $cities = $i->check;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
167 $i->checkMilitaryAdvisorCombatReports();
197
dbdd7dcc91c6 fixed for friendly troop and corruption
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 179
diff changeset
168 $i->checkFriends();
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
169
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
170 foreach my $cityId (keys(%$cities)) {
259
a4e52feec5a5 fixed a typo in is_attacked. fixed actionPoint number.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 258
diff changeset
171 # next if($cityId == 12345);
a4e52feec5a5 fixed a typo in is_attacked. fixed actionPoint number.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 258
diff changeset
172
105
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 104
diff changeset
173 print Dump($i->{'military'});
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
174 # build and upgrade for cities
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
175 my $tree = LoadFile('warfare.yaml');
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
176 $cities->{$cityId}->{parse_path} = [];
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
177 $cities->{$cityId}->{parse_answer} = undef;
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
178 if(ParseTree($tree, $rules, $cities->{$cityId}) eq 'engagement') {
128
2ff3704cca0e fixed for ignore same tradegood.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 127
diff changeset
179 my $island = Ikariam::Island->retrieve($cities->{$cityId}->{island}->{id});
125
4374173bab47 collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 124
diff changeset
180 $rules->engagement($cityId, $island->{x}, $island->{y}, $island->tradegood);
101
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
181 sleep(30);
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
182 $i->checkMilitaryAdvisorMilitaryMovements();
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
183 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
184 print Dump($cities->{$cityId}->{parse_path});
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
185 }
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
186 DumpFile("warfare-dump.yaml", $cities);
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
187
592d3b3b7898 implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
188 $i->logout;