| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package BalanceOfPower::Commands::MilitarySupport; | 
| 2 |  |  |  |  |  |  | $BalanceOfPower::Commands::MilitarySupport::VERSION = '0.400115'; | 
| 3 | 13 |  |  | 13 |  | 66 | use BalanceOfPower::Constants ":all"; | 
|  | 13 |  |  |  |  | 18 |  | 
|  | 13 |  |  |  |  | 7778 |  | 
| 4 | 13 |  |  | 13 |  | 74 | use Moo; | 
|  | 13 |  |  |  |  | 22 |  | 
|  | 13 |  |  |  |  | 68 |  | 
| 5 | 13 |  |  | 13 |  | 3561 | use Array::Utils qw(intersect); | 
|  | 13 |  |  |  |  | 33 |  | 
|  | 13 |  |  |  |  | 4881 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | extends 'BalanceOfPower::Commands::TargetNation'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub get_available_targets | 
| 10 |  |  |  |  |  |  | { | 
| 11 | 1 |  |  | 1 | 0 | 3 | my $self = shift; | 
| 12 | 1 |  |  |  |  | 5 | my $player = $self->actor; | 
| 13 | 1 |  |  |  |  | 6 | return grep { $self->world->get_nation($_)->accept_military_support($player, $self->world) } $self->world->get_friends($player); | 
|  | 1 |  |  |  |  | 6 |  | 
| 14 |  |  |  |  |  |  | } | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | sub IA | 
| 17 |  |  |  |  |  |  | { | 
| 18 | 2 |  |  | 2 | 0 | 5 | my $self = shift; | 
| 19 | 2 |  |  |  |  | 6 | my $actor = $self->get_nation(); | 
| 20 | 2 | 100 |  |  |  | 23 | return undef if($actor->army < ARMY_TO_GIVE_MILITARY_SUPPORT); | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 1 |  |  |  |  | 8 | my @crises = $self->world->get_crises($actor->name); | 
| 23 | 1 |  |  |  |  | 15 | my @friends = $self->world->shuffle("Choosing friend to support for " . $actor->name, $self->world->get_friends($actor->name)); | 
| 24 | 1 |  |  |  |  | 6 | my @targets = $self->get_available_targets(); | 
| 25 | 1 |  |  |  |  | 11 | @friends = $self->world->shuffle("Mixing friends for military support for " . $actor->name, intersect(@friends, @targets)); | 
| 26 | 1 | 50 |  |  |  | 6 | if(@crises > 0) | 
| 27 |  |  |  |  |  |  | { | 
| 28 | 1 |  |  |  |  | 29 | foreach my $c ($self->world->shuffle("Mixing crisis for war for " . $actor->name, @crises)) | 
| 29 |  |  |  |  |  |  | { | 
| 30 | 1 |  |  |  |  | 9 | my $enemy = $self->world->get_nation($c->destination($actor->name)); | 
| 31 | 1 | 50 |  |  |  | 9 | next if $self->world->war_busy($enemy->name); | 
| 32 | 1 |  |  |  |  | 4 | for(@friends) | 
| 33 |  |  |  |  |  |  | { | 
| 34 | 1 | 50 |  |  |  | 7 | if($self->world->border_exists($_, $enemy->name)) | 
| 35 |  |  |  |  |  |  | { | 
| 36 | 1 |  |  |  |  | 5 | return "MILITARY SUPPORT " . $_; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  | } | 
| 41 | 0 | 0 |  |  |  |  | if(@friends) | 
| 42 |  |  |  |  |  |  | { | 
| 43 | 0 |  |  |  |  |  | my $f = $friends[0]; | 
| 44 | 0 |  |  |  |  |  | return "MILITARY SUPPORT " . $f; | 
| 45 |  |  |  |  |  |  | } | 
| 46 | 0 |  |  |  |  |  | return undef; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | 1; |