« blib/lib/BalanceOfPower/Commands/DeclareWar.pm
↑ Summary
blib/lib/BalanceOfPower/Commands/Role/TreatiesUnderLimit.pm »
| 1 | package BalanceOfPower::Commands::ComTreaty; | ||
| 2 | $BalanceOfPower::Commands::ComTreaty::VERSION = '0.300010'; | ||
| 3 | use Moo; | ||
| 4 | |||
| 5 | use BalanceOfPower::Utils qw( prev_turn ); | ||
| 6 | |||
| 7 | extends 'BalanceOfPower::Commands::TargetRoute'; | ||
| 8 | with 'BalanceOfPower::Commands::Role::TreatiesUnderLimit'; | ||
| 9 | |||
| 10 | sub get_available_targets | ||
| 11 | { | ||
| 12 | my $self = shift; | ||
| 13 | my @targets = $self->SUPER::get_available_targets(); | ||
| 14 | my $nation = $self->actor; | ||
| 15 | @targets = grep {! $self->world->exists_treaty($nation, $_) } @targets; | ||
| 16 | @targets = grep {! $self->world->diplomacy_status($nation, $_) ne 'HATE' } @targets; | ||
| 17 | return $self->nations_under_treaty_limit(@targets); | ||
| 18 | } | ||
| 19 | |||
| 20 | sub IA | ||
| 21 | { | ||
| 22 | my $self = shift; | ||
| 23 | my $actor = $self->get_nation(); | ||
| 24 | my $prev_year = prev_turn($actor->current_year); | ||
| 25 | my @trade_ok = $actor->get_events("TRADE OK", $prev_year); | ||
| 26 | for(@trade_ok) | ||
| 27 | { | ||
| 28 | my $route = $_; | ||
| 29 | $route =~ s/^TRADE OK //; | ||
| 30 | $route =~ s/ \[.*$//; | ||
| 31 | my $status = $self->world->diplomacy_status($actor->name, $route); | ||
| 32 | if(! $self->world->exists_treaty($actor->name, $route) && $status ne 'HATE') | ||
| 33 | { | ||
| 34 | return "TREATY COM WITH " . $route; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | return undef; | ||
| 38 | } | ||
| 39 | |||
| 40 | 1; |