| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package BalanceOfPower::Commands::DeleteRoute; | 
| 2 |  |  |  |  |  |  | $BalanceOfPower::Commands::DeleteRoute::VERSION = '0.400115'; | 
| 3 | 13 |  |  | 13 |  | 56 | use Moo; | 
|  | 13 |  |  |  |  | 19 |  | 
|  | 13 |  |  |  |  | 68 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 13 |  |  | 13 |  | 3027 | use BalanceOfPower::Utils qw( prev_turn ); | 
|  | 13 |  |  |  |  | 24 |  | 
|  | 13 |  |  |  |  | 5654 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | extends 'BalanceOfPower::Commands::TargetRoute'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub get_available_targets | 
| 10 |  |  |  |  |  |  | { | 
| 11 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 12 | 0 |  |  |  |  | 0 | my @targets = $self->SUPER::get_available_targets(); | 
| 13 | 0 |  |  |  |  | 0 | my $nation = $self->actor; | 
| 14 | 0 |  |  |  |  | 0 | @targets = grep {! $self->world->exists_treaty_by_type($nation, $_, 'commercial') } @targets; | 
|  | 0 |  |  |  |  | 0 |  | 
| 15 | 0 |  |  |  |  | 0 | return @targets; | 
| 16 |  |  |  |  |  |  | } | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | sub execute | 
| 19 |  |  |  |  |  |  | { | 
| 20 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 21 | 0 |  |  |  |  | 0 | my $query = shift; | 
| 22 | 0 |  |  |  |  | 0 | my $nation = shift; | 
| 23 | 0 |  |  |  |  | 0 | my $result = $self->SUPER::execute($query, $nation); | 
| 24 | 0 | 0 |  |  |  | 0 | if($result->{status} == 1) | 
| 25 |  |  |  |  |  |  | { | 
| 26 | 0 |  |  |  |  | 0 | my $command = $result->{command}; | 
| 27 | 0 |  |  |  |  | 0 | $command .= "->" . $self->actor; | 
| 28 | 0 |  |  |  |  | 0 | return { status => 1, command => $command }; | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  | else | 
| 31 |  |  |  |  |  |  | { | 
| 32 | 0 |  |  |  |  | 0 | return $result; | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | sub IA | 
| 37 |  |  |  |  |  |  | { | 
| 38 | 6 |  |  | 6 | 0 | 11 | my $self = shift; | 
| 39 | 6 |  |  |  |  | 15 | my $actor = $self->get_nation(); | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 6 |  |  |  |  | 30 | my $prev_year = prev_turn($actor->current_year); | 
| 42 | 6 |  |  |  |  | 27 | my @trade_ko = $actor->get_events("TRADE KO", $prev_year); | 
| 43 | 6 | 50 |  |  |  | 29 | if(@trade_ko > 1) | 
|  |  | 50 |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | { | 
| 45 | 0 |  |  |  |  | 0 | for(@trade_ko) | 
| 46 |  |  |  |  |  |  | { | 
| 47 | 0 |  |  |  |  | 0 | my $to_delete = $_; | 
| 48 | 0 |  |  |  |  | 0 | $to_delete =~ s/TRADE KO //; | 
| 49 | 0 | 0 |  |  |  | 0 | if(! $self->world->exists_treaty_by_type($actor->name, $to_delete, 'commercial')) | 
| 50 |  |  |  |  |  |  | { | 
| 51 | 0 |  |  |  |  | 0 | return "DELETE TRADEROUTE " . $actor->name . "->" . $to_delete; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  | elsif(@trade_ko == 1) | 
| 56 |  |  |  |  |  |  | { | 
| 57 | 0 |  |  |  |  | 0 | my @older_trade_ko = $actor->get_events("TRADE KO", prev_turn($prev_year)); | 
| 58 | 0 | 0 |  |  |  | 0 | if(@older_trade_ko > 0) | 
| 59 |  |  |  |  |  |  | { | 
| 60 | 0 |  |  |  |  | 0 | my $to_delete = $trade_ko[$#trade_ko]; | 
| 61 | 0 |  |  |  |  | 0 | $to_delete =~ s/TRADE KO //; | 
| 62 | 0 | 0 |  |  |  | 0 | if(! $self->world->exists_treaty_by_type($actor->name, $to_delete, 'commercial')) | 
| 63 |  |  |  |  |  |  | { | 
| 64 | 0 |  |  |  |  | 0 | return "DELETE TRADEROUTE " . $actor->name . "->" . $to_delete; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  | } | 
| 68 | 6 |  |  |  |  | 12 | return undef; | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | 1; |