| 1 | package BalanceOfPower::Commands::DeclareWar; | ||
| 2 | $BalanceOfPower::Commands::DeclareWar::VERSION = '0.200000'; | ||
| 3 | use v5.10; | ||
| 4 | use Moo; | ||
| 5 | |||
| 6 | use Array::Utils qw(intersect); | ||
| 7 | |||
| 8 | use BalanceOfPower::Constants ":all"; | ||
| 9 | use BalanceOfPower::Utils qw( prev_turn ); | ||
| 10 | |||
| 11 | extends 'BalanceOfPower::Commands::InMilitaryRange'; | ||
| 12 | |||
| 13 | sub get_available_targets | ||
| 14 | { | ||
| 15 | my $self = shift; | ||
| 16 | my @targets = $self->SUPER::get_available_targets(); | ||
| 17 | my @out = (); | ||
| 18 | for(@targets) | ||
| 19 | { | ||
| 20 | my $t = $_; | ||
| 21 | if((! $self->world->is_under_influence($t) || $self->world->is_under_influence($t) ne $self->actor) && | ||
| 22 | ! $self->world->war_busy($t)) | ||
| 23 | { | ||
| 24 | push @out, $t; | ||
| 25 | } | ||
| 26 | } | ||
| 27 | return @out; | ||
| 28 | } | ||
| 29 | |||
| 30 | |||
| 31 | sub IA | ||
| 32 | { | ||
| 33 | my $self = shift; | ||
| 34 | my $actor = $self->get_nation(); | ||
| 35 | my @choose = $self->world->shuffle("Choosing someone to declare war to for ". $actor->name , $self->get_available_targets()); | ||
| 36 | for(@choose) | ||
| 37 | { | ||
| 38 | my $enemy = $self->world->get_nation($_); | ||
| 39 | if($actor->good_prey($enemy, $self->world)) | ||
| 40 | { | ||
| 41 | return "DECLARE WAR TO " . $enemy->name; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | return undef; | ||
| 45 | } | ||
| 46 | |||
| 47 | 1; |