« lib/BalanceOfPower/Commands/DiplomaticPressure.pm
↑ Summary
lib/BalanceOfPower/Commands/DeclareWar.pm »
| 1 | package BalanceOfPower::Role::Supporter; | ||||||||||
| 2 | 11 | $BalanceOfPower::Role::Supporter::VERSION = '0.200000'; | |||||||||
| 3 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 11 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 11 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 11 | ▶ | use BalanceOfPower::Relations::MilitarySupport; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 11 | ▶ | use BalanceOfPower::Constants ':all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 11 | requires 'get_nation'; | |||||||||
| 11 | 11 | requires 'at_civil_war'; | |||||||||
| 12 | 11 | requires 'war_report'; | |||||||||
| 13 | |||||||||||
| 14 | has military_supports => ( | ||||||||||
| 15 | is => 'ro', | ||||||||||
| 16 | 14 | ▶ | default => sub { BalanceOfPower::Relations::RelPack->new() }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 11 | handles => { add_military_support => 'add_link', | |||||||||
| 18 | delete_military_support => 'delete_link', | ||||||||||
| 19 | exists_military_support => 'exists_link', | ||||||||||
| 20 | already_in_military_support => 'first_link_for_node', | ||||||||||
| 21 | supports => 'links_for_node', | ||||||||||
| 22 | supporter => 'links_for_node1', | ||||||||||
| 23 | supported => 'first_link_for_node2', | ||||||||||
| 24 | print_military_supports => 'print_links', | ||||||||||
| 25 | reset_supports => 'delete_link_for_node' | ||||||||||
| 26 | } | ||||||||||
| 27 | ); | ||||||||||
| 28 | has rebel_military_supports => ( | ||||||||||
| 29 | is => 'ro', | ||||||||||
| 30 | 14 | ▶ | default => sub { BalanceOfPower::Relations::RelPack->new() }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 11 | handles => { add_rebel_military_support => 'add_link', | |||||||||
| 32 | delete_rebel_military_support => 'delete_link', | ||||||||||
| 33 | exists_rebel_military_support => 'exists_link', | ||||||||||
| 34 | rebel_supports => 'links_for_node', | ||||||||||
| 35 | rebel_supporter => 'links_for_node1', | ||||||||||
| 36 | rebel_supported => 'first_link_for_node2', | ||||||||||
| 37 | print_rebel_military_supports => 'print_links', | ||||||||||
| 38 | reset_rebel_supports => 'delete_link_for_node' | ||||||||||
| 39 | } | ||||||||||
| 40 | ); | ||||||||||
| 41 | |||||||||||
| 42 | sub start_military_support | ||||||||||
| 43 | { | ||||||||||
| 44 | 6 | ▶ | my $self = shift; | ||||||||
|
Subroutine
start_military_support: called CC=5 SCAR=18.5
Pod
undocumented
| |||||||||||
| 45 | 6 | my $nation1 = shift; | |||||||||
| 46 | 6 | my $nation2 = shift; | |||||||||
| 47 | 6 | ▶ | return 0 if($nation1->army < ARMY_FOR_SUPPORT); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 6 | my $precedent_sup = $self->exists_military_support($nation1->name, $nation2->name); | |||||||||
| 49 | 6 | ▶ | if($precedent_sup) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | { | ||||||||||
| 51 | 0 | $precedent_sup->casualities(-1 * ARMY_FOR_SUPPORT); | |||||||||
| 52 | 0 | $self->broadcast_event("MILITARY SUPPORT TO " . $nation2->name . " INCREASED BY " . $nation1->name, $nation1->name, $nation2->name); | |||||||||
| 53 | 0 | $self->change_diplomacy($nation1->name, $nation2->name, DIPLOMACY_FACTOR_INCREASING_SUPPORT); | |||||||||
| 54 | 0 | return 1; | |||||||||
| 55 | } | ||||||||||
| 56 | 6 | ▶ | if($self->supported($nation2->name)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | { | ||||||||||
| 58 | 0 | $self->broadcast_event($nation2->name . " ALREADY SUPPORTED. MILITARY SUPPORT IMPOSSIBILE FOR " . $nation1->name, $nation1->name, $nation2->name); | |||||||||
| 59 | 0 | return 0; | |||||||||
| 60 | } | ||||||||||
| 61 | 6 | my $supported = $self->supported($nation1->name); | |||||||||
| 62 | 6 | ▶ | if($supported) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | { | ||||||||||
| 64 | 0 | $self->stop_military_support($self->get_nation($supported->node1), $self->get_nation($supported->node2)); | |||||||||
| 65 | } | ||||||||||
| 66 | 6 | $nation1->add_army(-1 * ARMY_FOR_SUPPORT); | |||||||||
| 67 | 6 | $self->add_military_support( | |||||||||
| 68 | BalanceOfPower::Relations::MilitarySupport->new( | ||||||||||
| 69 | node1 => $nation1->name, | ||||||||||
| 70 | node2 => $nation2->name, | ||||||||||
| 71 | army => ARMY_FOR_SUPPORT)); | ||||||||||
| 72 | 6 | $self->broadcast_event("MILITARY SUPPORT TO " . $nation2->name . " STARTED BY " . $nation1->name, $nation1->name, $nation2->name); | |||||||||
| 73 | 6 | $self->war_report($nation1->name . " started military support for " . $nation2->name, $nation2->name); | |||||||||
| 74 | 6 | $self->change_diplomacy($nation1->name, $nation2->name, DIPLOMACY_FACTOR_STARTING_SUPPORT); | |||||||||
| 75 | } | ||||||||||
| 76 | sub start_rebel_military_support | ||||||||||
| 77 | { | ||||||||||
| 78 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
start_rebel_military_support: called CC=5 SCAR=18.6
Pod
undocumented
| |||||||||||
| 79 | 1 | my $nation1 = shift; | |||||||||
| 80 | 1 | my $nation2 = shift; | |||||||||
| 81 | 1 | ▶ | return 0 if($nation1->army < REBEL_ARMY_FOR_SUPPORT); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 1 | ▶ | return 0 if(! $self->at_civil_war($nation2->name)); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 1 | my $precedent_sup = $self->exists_rebel_military_support($nation1->name, $nation2->name); | |||||||||
| 84 | 1 | ▶ | if($precedent_sup) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 85 | { | ||||||||||
| 86 | 0 | $precedent_sup->casualities(-1 * ARMY_FOR_SUPPORT); | |||||||||
| 87 | 0 | $self->broadcast_event("REBEL MILITARY SUPPORT AGAINST " . $nation2->name . " INCREASED BY " . $nation1->name, $nation1->name, $nation2->name); | |||||||||
| 88 | 0 | $self->change_diplomacy($nation1->name, $nation2->name, DIPLOMACY_FACTOR_INCREASING_REBEL_SUPPORT); | |||||||||
| 89 | 0 | return 1; | |||||||||
| 90 | } | ||||||||||
| 91 | 1 | ▶ | if($self->rebel_supported($nation2->name)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | { | ||||||||||
| 93 | 0 | $self->broadcast_event("REBELS IN " . $nation2->name . " ALREADY SUPPORTED. REBEL MILITARY SUPPORT IMPOSSIBILE FOR " . $nation1->name, $nation1->name, $nation2->name); | |||||||||
| 94 | 0 | return 0; | |||||||||
| 95 | } | ||||||||||
| 96 | 1 | $nation1->add_army(-1 * ARMY_FOR_SUPPORT); | |||||||||
| 97 | 1 | $self->add_rebel_military_support( | |||||||||
| 98 | BalanceOfPower::Relations::MilitarySupport->new( | ||||||||||
| 99 | node1 => $nation1->name, | ||||||||||
| 100 | node2 => $nation2->name, | ||||||||||
| 101 | army => ARMY_FOR_SUPPORT)); | ||||||||||
| 102 | 1 | $self->broadcast_event("REBEL MILITARY SUPPORT AGAINST " . $nation2->name . " STARTED BY " . $nation1->name, $nation1->name, $nation2->name); | |||||||||
| 103 | 1 | $self->change_diplomacy($nation1->name, $nation2->name, DIPLOMACY_FACTOR_STARTING_REBEL_SUPPORT); | |||||||||
| 104 | } | ||||||||||
| 105 | sub stop_military_support | ||||||||||
| 106 | { | ||||||||||
| 107 | 3 | ▶ | my $self = shift; | ||||||||
|
Subroutine
stop_military_support: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 108 | 3 | my $node1 = shift; | |||||||||
| 109 | 3 | my $node2 = shift; | |||||||||
| 110 | 3 | my $avoid_diplomacy = shift; | |||||||||
| 111 | 3 | my $milsup = $self->exists_military_support($node1->name, $node2->name); | |||||||||
| 112 | 3 | ▶ | return if (! $milsup); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 113 | 1 | $self->delete_military_support($node1->name, $node2->name); | |||||||||
| 114 | 1 | $node1->add_army($milsup->army); | |||||||||
| 115 | 1 | $self->broadcast_event("MILITARY SUPPORT FOR " . $node2->name . " STOPPED BY " . $node1->name, $node1->name, $node2->name); | |||||||||
| 116 | 1 | $self->war_report($node1->name . " stopped military support for " . $node2->name, $node2->name); | |||||||||
| 117 | 1 | ▶ | if(! $avoid_diplomacy) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | { | ||||||||||
| 119 | 1 | $self->change_diplomacy($node1->name, $node2->name, -1 * DIPLOMACY_FACTOR_BREAKING_SUPPORT); | |||||||||
| 120 | } | ||||||||||
| 121 | } | ||||||||||
| 122 | sub stop_rebel_military_support | ||||||||||
| 123 | { | ||||||||||
| 124 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
stop_rebel_military_support: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 125 | 1 | my $node1 = shift; | |||||||||
| 126 | 1 | my $node2 = shift; | |||||||||
| 127 | 1 | my $milsup = $self->exists_rebel_military_support($node1->name, $node2->name); | |||||||||
| 128 | 1 | ▶ | return if (! $milsup); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | 1 | $self->delete_rebel_military_support($node1->name, $node2->name); | |||||||||
| 130 | 1 | $node1->add_army($milsup->army); | |||||||||
| 131 | 1 | $self->broadcast_event("REBEL MILITARY SUPPORT AGAINST " . $node2->name . " STOPPED BY " . $node1->name, $node1->name, $node2->name); | |||||||||
| 132 | } | ||||||||||
| 133 | sub military_support_garbage_collector | ||||||||||
| 134 | { | ||||||||||
| 135 | 29 | ▶ | my $self = shift; | ||||||||
|
Subroutine
military_support_garbage_collector: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 136 | 29 | ▶ | $self->military_supports->garbage_collector(sub { my $rel = shift; return $rel->army <= 0 }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 137 | } | ||||||||||
| 138 | sub rebel_military_support_garbage_collector | ||||||||||
| 139 | { | ||||||||||
| 140 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
rebel_military_support_garbage_collector: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||
| 141 | 4 | ▶ | $self->rebel_military_supports->garbage_collector(sub { my $rel = shift; return $rel->army <= 0 }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||
| 142 | } | ||||||||||
| 143 | |||||||||||
| 144 | 11 | 1; | |||||||||