BalanceOfPower

 view release on metacpan or  search on metacpan

lib/BalanceOfPower/Commands/DeclareWar.pm  view on Meta::CPAN


sub get_available_targets
{
    my $self = shift;
    my @targets = $self->SUPER::get_available_targets();
    my @out = ();
    for(@targets)
    {
        my $t = $_;
        if((! $self->world->is_under_influence($t) || $self->world->is_under_influence($t) ne $self->actor) &&
            ! $self->world->war_busy($t))
        {
            push @out, $t;
        }
    }
    return @out;
}


sub IA
{

lib/BalanceOfPower/Commands/MilitarySupport.pm  view on Meta::CPAN


    my @crises = $self->world->get_crises($actor->name);
    my @friends = $self->world->shuffle("Choosing friend to support for " . $actor->name, $self->world->get_friends($actor->name));
    my @targets = $self->get_available_targets();
    @friends = $self->world->shuffle("Mixing friends for military support for " . $actor->name, intersect(@friends, @targets));
    if(@crises > 0)
    {
        foreach my $c ($self->world->shuffle("Mixing crisis for war for " . $actor->name, @crises))
        {
            my $enemy = $self->world->get_nation($c->destination($actor->name));
            next if $self->world->war_busy($enemy->name);
            for(@friends)
            {
                if($self->world->border_exists($_, $enemy->name))
                {
                    return "MILITARY SUPPORT " . $_;
                }
            }
        }
    }
    if(@friends)

lib/BalanceOfPower/Role/Warlord.pm  view on Meta::CPAN

requires 'get_allies';
requires 'supported';
requires 'supporter';
requires 'military_support_garbage_collector';
requires 'random';
requires 'change_diplomacy';
requires 'get_crises';
requires 'delete_crisis';
requires 'discard_war_bonds';
requires 'cash_war_bonds';
requires 'war_busy';

has wars => (
    is => 'ro',
    default => sub { BalanceOfPower::Relations::RelPack->new() },
    handles => { at_war => 'first_link_for_node',
                 add_war => 'add_link',
                 get_wars => 'links_for_node',
                 war_exists => 'exists_link',
                 delete_war_link => 'delete_link',
                 get_attackers => 'links_for_node2'

lib/BalanceOfPower/Role/Warlord.pm  view on Meta::CPAN

    {
        return { how => 'border', who => undef };
    }
    my @supported = $self->supporter($nation1);
    for(@supported)
    {
        my $nation_supported = $_->destination($nation1);
        my $treaty = $self->exists_treaty_by_type($nation_supported, $nation2, 'no aggression');
        if(! $hostile || ! $treaty)
        {
            if(! $self->war_busy($nation_supported))
            {
                if($nation_supported eq $nation2)
                {
                    return { how => 'supporting', who => undef};
                }
                if($self->border_exists($nation_supported, $nation2))
                {
                    return { how => 'support', who => $nation_supported};
                }
            }
            else
            {
            }
        }
    }
    my @empire = $self->empire($nation1);
    for(@empire)
    {
        my $ally = $_;
        if(! $self->war_busy($ally))
        {
                return { how => 'linked', who => undef } if $ally eq $nation2;
                return { how => 'control', who => $ally } if $self->border_exists($ally, $nation2);
        }
    }
    return 0;
}

sub war_current_year
{

lib/BalanceOfPower/Role/Warlord.pm  view on Meta::CPAN

    my $self = shift;
    my $attacker = shift || "";
    my $defender = shift || "";

    if(! $self->war_exists($attacker->name, $defender->name))
    {
        $self->broadcast_event({ code => 'crisisescalate', 
                                 text => "CRISIS BETWEEN " . $attacker->name . " AND " . $defender->name . " BECAME WAR", 
                                 involved => [$attacker->name, $defender->name] }, $attacker->name, $defender->name); 
        my @attacker_coalition = $self->empire($attacker->name);
        @attacker_coalition = grep { ! $self->war_busy($_) } @attacker_coalition;
        my @defender_coalition = $self->empire($defender->name);
        @defender_coalition = grep { ! $self->war_busy($_) } @defender_coalition;
    
        #Allies management
        my @attacker_allies = $self->get_allies($attacker->name);
        my @defender_allies = $self->get_allies($defender->name);
        for(@attacker_allies)
        {
            my $ally_name = $_->destination($attacker->name);
            my $ally = $self->get_nation( $ally_name );
            if($ally->good_prey($defender, $self, ALLY_CONFLICT_LEVEL_FOR_INVOLVEMENT, 0 ))
            {

lib/BalanceOfPower/Targets/Fall.pm  view on Meta::CPAN

    return $self->target_obj->government_id > $self->government_id;
}
sub select_random_target
{
    my $self = shift;
    my $world = shift;
    my @possible_targets = ();
    for(@{$world->nations})
    {
        my $n = $_;
        if((! $world->war_busy($n->name)) &&
           $n->internal_disorder < INTERNAL_DISORDER_LIMIT_FOR_CHOOSE )
        {
            push @possible_targets, $n;
        }
    }
    if(@possible_targets > 0)
    {
        @possible_targets = $world->shuffle("Choosing FALL target", @possible_targets);
        return $possible_targets[0];
    }

lib/BalanceOfPower/World.pm  view on Meta::CPAN

           $nation->build_troops();
        }
        elsif($command =~ /^BOOST PRODUCTION$/)
        {
           $nation->boost_production();
        }
        elsif($command =~ /DECLARE WAR TO (.*)$/)
        {
            my $attacker = $nation;
            my $defender = $self->get_nation($1);
            if(! $self->war_busy($attacker->name) && ! $self->war_busy($defender->name))
            {
                $self->create_war($attacker, $defender);
            }
        }
        elsif($command =~ /^MILITARY SUPPORT (.*)$/)
        {
            my $supporter = $nation;
            my $supported = $self->get_nation($1);
            if($supported->accept_military_support($supporter->name, $self))
            {

lib/BalanceOfPower/World.pm  view on Meta::CPAN

        $nation1->subtract_production('export', AID_INSURGENTS_COST);
        $nation2->add_internal_disorder(INSURGENTS_AID, $self);
    }
}


# INTERNAL DISORDER END ######################################################

# WAR ######################################################################

sub war_busy
{
    my $self = shift;
    my $n = shift;
    return $self->at_civil_war($n) || $self->at_war($n);
}

sub warfare
{
    my $self = shift;
    $self->fight_wars();

lib/BalanceOfPower/World.pm  view on Meta::CPAN

    $plan{'ground'} = {};
    $plan{'air'} = {};
    my @for_commerce = $self->route_destinations_for_node($from);
    
    my @at_borders = $self->near_nations($from, 1);
    foreach my $n(@for_commerce)
    {
        if(! grep { $_ eq $n } @already)
        {
            my $youcan = 'OK';
            $youcan = 'KO' if($self->war_busy($from) || $self->war_busy($n));
            $plan{'air'}->{$n}->{status} = $youcan;
            my $cost = $self->distance($from, $n) * AIR_TRAVEL_COST_FOR_DISTANCE;
            $cost = AIR_TRAVEL_CAP_COST if $cost > AIR_TRAVEL_CAP_COST;
            $plan{'air'}->{$n}->{cost} = $cost if($youcan eq 'OK');
            push @already, $n if $youcan eq 'OK';
        }
    }
    foreach my $n(@at_borders)
    {
        if(! grep { $_ eq $n } @already)



( run in 0.539 second using v1.01-cache-2.11-cpan-87723dcf8b7 )