| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package BalanceOfPower::Role::Ruler; | 
| 2 |  |  |  |  |  |  | $BalanceOfPower::Role::Ruler::VERSION = '0.400115'; | 
| 3 | 13 |  |  | 13 |  | 5929 | use strict; | 
|  | 13 |  |  |  |  | 26 |  | 
|  | 13 |  |  |  |  | 434 |  | 
| 4 | 13 |  |  | 13 |  | 57 | use Moo::Role; | 
|  | 13 |  |  |  |  | 17 |  | 
|  | 13 |  |  |  |  | 83 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 13 |  |  | 13 |  | 3537 | use BalanceOfPower::Constants ':all'; | 
|  | 13 |  |  |  |  | 20 |  | 
|  | 13 |  |  |  |  | 7413 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 13 |  |  | 13 |  | 4759 | use BalanceOfPower::Relations::Influence; | 
|  | 13 |  |  |  |  | 42 |  | 
|  | 13 |  |  |  |  | 14188 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | requires 'broadcast_event'; | 
| 11 |  |  |  |  |  |  | requires 'get_nation'; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | has influences => ( | 
| 14 |  |  |  |  |  |  | is => 'ro', | 
| 15 |  |  |  |  |  |  | default => sub { BalanceOfPower::Relations::RelPack->new() }, | 
| 16 |  |  |  |  |  |  | handles => { reset_influences => 'delete_link_for_node', | 
| 17 |  |  |  |  |  |  | add_influence => 'add_link' } | 
| 18 |  |  |  |  |  |  | ); | 
| 19 |  |  |  |  |  |  | sub influences_garbage_collector | 
| 20 |  |  |  |  |  |  | { | 
| 21 | 47 |  |  | 47 | 0 | 85 | my $self = shift; | 
| 22 | 47 |  |  | 6 |  | 493 | $self->influences->garbage_collector(sub { my $rel = shift; return $rel->status == -1 }); | 
|  | 6 |  |  |  |  | 7 |  | 
|  | 6 |  |  |  |  | 17 |  | 
| 23 |  |  |  |  |  |  | } | 
| 24 |  |  |  |  |  |  | sub is_under_influence | 
| 25 |  |  |  |  |  |  | { | 
| 26 | 424 |  |  | 424 | 0 | 430 | my $self = shift; | 
| 27 | 424 |  |  |  |  | 533 | my $nation = shift; | 
| 28 |  |  |  |  |  |  | my @rels = $self->influences->query( | 
| 29 |  |  |  |  |  |  | sub { | 
| 30 | 14 |  |  | 14 |  | 14 | my $rel = shift; | 
| 31 | 14 | 100 |  |  |  | 69 | return 0 if($rel->node2 ne $nation); | 
| 32 | 3 |  |  |  |  | 7 | return $rel->actual_influence() | 
| 33 | 424 |  |  |  |  | 1931 | }, $nation); | 
| 34 | 424 | 100 |  |  |  | 1262 | if(@rels > 0) | 
| 35 |  |  |  |  |  |  | { | 
| 36 | 3 |  |  |  |  | 11 | return $rels[0]->start($nation); | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  | else | 
| 39 |  |  |  |  |  |  | { | 
| 40 | 421 |  |  |  |  | 1305 | return undef; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  | sub print_nation_situation | 
| 44 |  |  |  |  |  |  | { | 
| 45 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 46 | 0 |  |  |  |  | 0 | my $nation = shift; | 
| 47 | 0 |  |  |  |  | 0 | my $domination = $self->is_under_influence($nation); | 
| 48 | 0 | 0 |  |  |  | 0 | return "$nation is under control of $domination" if $domination; | 
| 49 | 0 |  |  |  |  | 0 | my @influence = $self->has_influence($nation); | 
| 50 | 0 | 0 |  |  |  | 0 | if(@influence > 0) | 
| 51 |  |  |  |  |  |  | { | 
| 52 | 0 |  |  |  |  | 0 | my $out = ""; | 
| 53 | 0 |  |  |  |  | 0 | for(@influence) | 
| 54 |  |  |  |  |  |  | { | 
| 55 | 0 |  |  |  |  | 0 | $out .= "$nation has influence on $_\n"; | 
| 56 |  |  |  |  |  |  | } | 
| 57 | 0 |  |  |  |  | 0 | return $out; | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  | else | 
| 60 |  |  |  |  |  |  | { | 
| 61 | 0 |  |  |  |  | 0 | return "$nation is free"; | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  | sub has_influence | 
| 66 |  |  |  |  |  |  | { | 
| 67 | 375 |  |  | 375 | 0 | 432 | my $self = shift; | 
| 68 | 375 |  |  |  |  | 385 | my $nation = shift; | 
| 69 |  |  |  |  |  |  | my @influences = $self->influences->query( | 
| 70 |  |  |  |  |  |  | sub { | 
| 71 | 28 |  |  | 28 |  | 28 | my $rel = shift; | 
| 72 | 28 | 100 |  |  |  | 105 | return 0 if($rel->node1 ne $nation); | 
| 73 | 10 |  |  |  |  | 27 | return $rel->actual_influence() | 
| 74 | 375 |  |  |  |  | 2064 | }, $nation); | 
| 75 | 375 |  |  |  |  | 1063 | my @out = (); | 
| 76 | 375 |  |  |  |  | 508 | for(@influences) | 
| 77 |  |  |  |  |  |  | { | 
| 78 | 10 |  |  |  |  | 27 | push @out, $_->destination($nation); | 
| 79 |  |  |  |  |  |  | } | 
| 80 | 375 |  |  |  |  | 587 | return @out; | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  | sub empire | 
| 83 |  |  |  |  |  |  | { | 
| 84 | 186 |  |  | 186 | 0 | 191 | my $self = shift; | 
| 85 | 186 |  |  |  |  | 163 | my $n = shift; | 
| 86 | 186 | 100 |  |  |  | 332 | if(my $domination = $self->is_under_influence($n)) | 
| 87 |  |  |  |  |  |  | { | 
| 88 | 3 |  |  |  |  | 4 | my $dominator = $domination; | 
| 89 | 3 |  |  |  |  | 8 | my @allies = $self->has_influence($dominator); | 
| 90 | 3 |  |  |  |  | 4 | push @allies, $dominator; | 
| 91 | 3 |  |  |  |  | 9 | return @allies; | 
| 92 |  |  |  |  |  |  | } | 
| 93 |  |  |  |  |  |  | else | 
| 94 |  |  |  |  |  |  | { | 
| 95 | 183 |  |  |  |  | 312 | my @allies = $self->has_influence($n); | 
| 96 | 183 |  |  |  |  | 232 | push @allies, $n; | 
| 97 | 183 |  |  |  |  | 438 | return @allies; | 
| 98 |  |  |  |  |  |  | } | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  | sub occupy | 
| 101 |  |  |  |  |  |  | { | 
| 102 | 3 |  |  | 3 | 0 | 5 | my $self = shift; | 
| 103 | 3 |  |  |  |  | 5 | my $nation = shift; | 
| 104 | 3 |  |  |  |  | 4 | my $occupiers = shift; | 
| 105 | 3 |  |  |  |  | 4 | my $leader = shift; | 
| 106 | 3 |  | 100 |  |  | 10 | my $internal_disorder = shift || 0; | 
| 107 | 3 |  |  |  |  | 9 | $self->get_nation($nation)->occupation($self); | 
| 108 | 3 |  |  |  |  | 10 | my $occupied_progress = $self->get_nation($nation)->progress; | 
| 109 |  |  |  |  |  |  |  | 
| 110 | 3 |  |  |  |  | 4 | my @occupiers_array = @{$occupiers}; | 
|  | 3 |  |  |  |  | 8 |  | 
| 111 | 3 |  |  |  |  | 10 | my $real_leader = $self->is_under_influence($leader); | 
| 112 | 3 | 50 |  |  |  | 8 | if($real_leader) | 
| 113 |  |  |  |  |  |  | { | 
| 114 | 0 |  |  |  |  | 0 | @occupiers_array = grep { $_ ne $real_leader } @occupiers_array; | 
|  | 0 |  |  |  |  | 0 |  | 
| 115 | 0 |  |  |  |  | 0 | push @occupiers_array, $real_leader; | 
| 116 | 0 |  |  |  |  | 0 | $leader = $real_leader; | 
| 117 |  |  |  |  |  |  | } | 
| 118 | 3 |  |  |  |  | 6 | foreach my $c (@occupiers_array) | 
| 119 |  |  |  |  |  |  | { | 
| 120 | 3 | 50 |  |  |  | 6 | if($c eq $leader) | 
| 121 |  |  |  |  |  |  | { | 
| 122 | 3 | 100 |  |  |  | 61 | $self->add_influence(BalanceOfPower::Relations::Influence->new( node1 => $c, | 
| 123 |  |  |  |  |  |  | node2 => $nation, | 
| 124 |  |  |  |  |  |  | status => 0, | 
| 125 |  |  |  |  |  |  | next => $internal_disorder ? 2 : 1, | 
| 126 |  |  |  |  |  |  | clock => 0 )); | 
| 127 | 3 |  |  |  |  | 14 | $self->set_diplomacy($nation, $c, DOMINION_DIPLOMACY); | 
| 128 | 3 |  |  |  |  | 10 | $self->copy_diplomacy($c, $nation); | 
| 129 | 3 | 100 |  |  |  | 10 | if($self->get_nation($c)->progress < $occupied_progress) | 
| 130 |  |  |  |  |  |  | { | 
| 131 | 1 |  |  |  |  | 3 | $self->get_nation($c)->progress($occupied_progress); | 
| 132 | 1 |  |  |  |  | 18 | $self->broadcast_event({ code => 'acquireprogress', | 
| 133 |  |  |  |  |  |  | text => "$c ACQUIRES PROGRESS FROM $nation: $occupied_progress", | 
| 134 |  |  |  |  |  |  | involved => [$c, $nation], | 
| 135 |  |  |  |  |  |  | values => [$occupied_progress] }, $c, $nation); | 
| 136 |  |  |  |  |  |  | } | 
| 137 |  |  |  |  |  |  | } | 
| 138 |  |  |  |  |  |  | else | 
| 139 |  |  |  |  |  |  | { | 
| 140 | 0 |  |  |  |  | 0 | $self->add_influence(BalanceOfPower::Relations::Influence->new( node1 => $c, | 
| 141 |  |  |  |  |  |  | node2 => $nation, | 
| 142 |  |  |  |  |  |  | status => 0, | 
| 143 |  |  |  |  |  |  | clock => 0 )); | 
| 144 | 0 |  |  |  |  | 0 | $self->set_diplomacy($nation, $c, DIPLOMACY_AFTER_OCCUPATION); | 
| 145 | 0 |  |  |  |  | 0 | $self->get_nation($c)->grow(); | 
| 146 |  |  |  |  |  |  | } | 
| 147 | 3 |  |  |  |  | 28 | $self->broadcast_event({code => 'occupy', | 
| 148 |  |  |  |  |  |  | text => "$c OCCUPIES $nation", | 
| 149 |  |  |  |  |  |  | involved => [$c, $nation] }, $c, $nation ); | 
| 150 |  |  |  |  |  |  | } | 
| 151 |  |  |  |  |  |  | } | 
| 152 |  |  |  |  |  |  | sub situation_clock | 
| 153 |  |  |  |  |  |  | { | 
| 154 | 47 |  |  | 47 | 0 | 77 | my $self = shift; | 
| 155 | 47 |  |  |  |  | 161 | foreach my $i ($self->influences->all()) | 
| 156 |  |  |  |  |  |  | { | 
| 157 | 6 |  |  |  |  | 28 | my $old_status = $i->status_label; | 
| 158 | 6 |  |  |  |  | 17 | my $new_status = $i->click(); | 
| 159 | 6 | 50 | 33 |  |  | 32 | if($new_status && $old_status ne $new_status) | 
| 160 |  |  |  |  |  |  | { | 
| 161 | 6 | 50 |  |  |  | 21 | if($new_status eq 'dominate') | 
|  |  | 100 |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | { | 
| 163 | 0 |  |  |  |  | 0 | $self->broadcast_event({ code => 'dominate', | 
| 164 |  |  |  |  |  |  | text => $i->node1 . " DOMINATES " . $i->node2, | 
| 165 |  |  |  |  |  |  | involved => [$i->node1, $i->node2] }, $i->node1, $i->node2); | 
| 166 |  |  |  |  |  |  | } | 
| 167 |  |  |  |  |  |  | elsif($new_status eq 'control') | 
| 168 |  |  |  |  |  |  | { | 
| 169 | 2 |  |  |  |  | 28 | $self->broadcast_event({ code => 'control', | 
| 170 |  |  |  |  |  |  | text => $i->node1 . " CONTROLS " . $i->node2, | 
| 171 |  |  |  |  |  |  | involved => [$i->node1, $i->node2] }, $i->node1, $i->node2); | 
| 172 |  |  |  |  |  |  | } | 
| 173 |  |  |  |  |  |  | } | 
| 174 |  |  |  |  |  |  | } | 
| 175 | 47 |  |  |  |  | 225 | $self->influences_garbage_collector(); | 
| 176 |  |  |  |  |  |  | } | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | sub print_influences | 
| 179 |  |  |  |  |  |  | { | 
| 180 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 181 | 0 |  |  |  |  |  | my $n = shift; | 
| 182 | 0 |  | 0 |  |  |  | my $mode = shift || 'print'; | 
| 183 | 0 |  |  |  |  |  | my @inf = $self->influences->links_for_node($n); | 
| 184 | 0 |  |  |  |  |  | @inf = sort { lc($a->node1) cmp lc($b->node1) } @inf; | 
|  | 0 |  |  |  |  |  |  | 
| 185 | 0 |  |  |  |  |  | return BalanceOfPower::Printer::print($mode, $self, 'print_influences', | 
| 186 |  |  |  |  |  |  | { influences => \@inf } ); | 
| 187 |  |  |  |  |  |  | } | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | 1; |