comparison agent.pl @ 87:4c82cf844aa8

counting navy expenditure
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 26 Oct 2008 15:02:06 +0800
parents a8acf50bf7bb
children 86402d28544f
comparison
equal deleted inserted replaced
86:a8acf50bf7bb 87:4c82cf844aa8
168 sub rule_resource 168 sub rule_resource
169 { 169 {
170 # TODO 170 # TODO
171 } 171 }
172 172
173 sub rule_milityExpenditure 173 # navy
174 sub rule_navyExpenditure
174 { 175 {
175 my ($self, $cityId) = @_; 176 my ($self, $cityId) = @_;
177 # move this to somewhere else.
176 my $workersRatio = { 178 my $workersRatio = {
177 'citizens' => 0.4, 179 'citizens' => 0.4,
178 'specialworkers' => 0.3, 180 'specialworkers' => 0.3,
179 'woodworkers' => 0.7, 181 'woodworkers' => 0.7,
180 }; 182 };
181 183
184 my $currentCost = $self->{'ikariam'}->getNavyExpenditure($cityId);
185 my $netincome = $self->{'ikariam'}->getNetIncome($cityId);
186
187 # 軍費為 兩成 淨收入
188 # 陸軍佔用 0.8
189 # 海軍佔用 0.2
190 my $militaryExpenditure = int($netincome * 0.2 * 0.2);
191
192 if($currentCost < $militaryExpenditure) {
193 printf("Current navy expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure);
194 }
195 }
196
197 # army
198 sub rule_milityExpenditure
199 {
200 my ($self, $cityId) = @_;
201 # move this to somewhere else.
202 my $workersRatio = {
203 'citizens' => 0.4,
204 'specialworkers' => 0.3,
205 'woodworkers' => 0.7,
206 };
207
182 my $currentCost = $self->{'ikariam'}->getMilityExpenditure($cityId); 208 my $currentCost = $self->{'ikariam'}->getMilityExpenditure($cityId);
183 my $netincome = $self->{'ikariam'}->getNetIncome($cityId); 209 my $netincome = $self->{'ikariam'}->getNetIncome($cityId);
184 210
185 # 軍費為 兩成 淨收入 211 # 軍費為 兩成 淨收入
186 my $militaryExpenditure = int($netincome * 0.2); 212 # 陸軍佔用 0.8
213 # 海軍佔用 0.2
214 my $militaryExpenditure = int($netincome * 0.2 * 0.8);
187 215
188 if($currentCost < $militaryExpenditure) { 216 if($currentCost < $militaryExpenditure) {
189 printf("Current mility expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure); 217 printf("Current army expenditure total=%s, affordable %s\n", $currentCost, $militaryExpenditure);
190 } 218 }
191
192 # TODO, 海軍
193
194 } 219 }
195 1; 220 1;
196 221
197 222
198 package main; 223 package main;
229 } 254 }
230 print("\n"); 255 print("\n");
231 256
232 # maybe this should be moved to Rules. 257 # maybe this should be moved to Rules.
233 $i->blanceHurmanResource($cityId); 258 $i->blanceHurmanResource($cityId);
234 # 259 # milityExpenditure
235 $rules->rule_milityExpenditure($cityId); 260 $rules->rule_milityExpenditure($cityId);
261 $rules->rule_navyExpenditure($cityId);
236 262
237 # build and upgrade for cities 263 # build and upgrade for cities
238 $tree = LoadFile('city.yaml'); 264 $tree = LoadFile('city.yaml');
239 $cities->{$cityId}->{parse_path} = []; 265 $cities->{$cityId}->{parse_path} = [];
240 $cities->{$cityId}->{parse_answer} = undef; 266 $cities->{$cityId}->{parse_answer} = undef;