| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package BalanceOfPower::Executive; | 
| 2 |  |  |  |  |  |  | $BalanceOfPower::Executive::VERSION = '0.400115'; | 
| 3 | 13 |  |  | 13 |  | 65 | use strict; | 
|  | 13 |  |  |  |  | 17 |  | 
|  | 13 |  |  |  |  | 348 |  | 
| 4 | 13 |  |  | 13 |  | 115 | use v5.10; | 
|  | 13 |  |  |  |  | 36 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 13 |  |  | 13 |  | 52 | use Moo; | 
|  | 13 |  |  |  |  | 27 |  | 
|  | 13 |  |  |  |  | 75 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | with 'BalanceOfPower::Role::Logger'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 13 |  |  | 13 |  | 3175 | use BalanceOfPower::Constants ":all"; | 
|  | 13 |  |  |  |  | 24 |  | 
|  | 13 |  |  |  |  | 6614 |  | 
| 11 | 13 |  |  | 13 |  | 78 | use BalanceOfPower::Utils qw(as_active as_title); | 
|  | 13 |  |  |  |  | 21 |  | 
|  | 13 |  |  |  |  | 744 |  | 
| 12 | 13 |  |  | 13 |  | 4177 | use BalanceOfPower::Commands::BuildTroops; | 
|  | 13 |  |  |  |  | 26 |  | 
|  | 13 |  |  |  |  | 450 |  | 
| 13 | 13 |  |  | 13 |  | 4254 | use BalanceOfPower::Commands::InMilitaryRange; | 
|  | 13 |  |  |  |  | 29 |  | 
|  | 13 |  |  |  |  | 519 |  | 
| 14 | 13 |  |  | 13 |  | 4731 | use BalanceOfPower::Commands::DeleteRoute; | 
|  | 13 |  |  |  |  | 31 |  | 
|  | 13 |  |  |  |  | 411 |  | 
| 15 | 13 |  |  | 13 |  | 4337 | use BalanceOfPower::Commands::MilitarySupport; | 
|  | 13 |  |  |  |  | 30 |  | 
|  | 13 |  |  |  |  | 415 |  | 
| 16 | 13 |  |  | 13 |  | 4280 | use BalanceOfPower::Commands::RebelMilitarySupport; | 
|  | 13 |  |  |  |  | 35 |  | 
|  | 13 |  |  |  |  | 376 |  | 
| 17 | 13 |  |  | 13 |  | 4354 | use BalanceOfPower::Commands::RecallRebelMilitarySupport; | 
|  | 13 |  |  |  |  | 40 |  | 
|  | 13 |  |  |  |  | 421 |  | 
| 18 | 13 |  |  | 13 |  | 4496 | use BalanceOfPower::Commands::RecallMilitarySupport; | 
|  | 13 |  |  |  |  | 31 |  | 
|  | 13 |  |  |  |  | 365 |  | 
| 19 | 13 |  |  | 13 |  | 4346 | use BalanceOfPower::Commands::ComTreaty; | 
|  | 13 |  |  |  |  | 29 |  | 
|  | 13 |  |  |  |  | 433 |  | 
| 20 | 13 |  |  | 13 |  | 4312 | use BalanceOfPower::Commands::NagTreaty; | 
|  | 13 |  |  |  |  | 32 |  | 
|  | 13 |  |  |  |  | 419 |  | 
| 21 | 13 |  |  | 13 |  | 4313 | use BalanceOfPower::Commands::LowerDisorder; | 
|  | 13 |  |  |  |  | 30 |  | 
|  | 13 |  |  |  |  | 350 |  | 
| 22 | 13 |  |  | 13 |  | 3874 | use BalanceOfPower::Commands::BoostProduction; | 
|  | 13 |  |  |  |  | 31 |  | 
|  | 13 |  |  |  |  | 352 |  | 
| 23 | 13 |  |  | 13 |  | 4051 | use BalanceOfPower::Commands::AddRoute; | 
|  | 13 |  |  |  |  | 30 |  | 
|  | 13 |  |  |  |  | 371 |  | 
| 24 | 13 |  |  | 13 |  | 4355 | use BalanceOfPower::Commands::EconomicAid; | 
|  | 13 |  |  |  |  | 28 |  | 
|  | 13 |  |  |  |  | 362 |  | 
| 25 | 13 |  |  | 13 |  | 4239 | use BalanceOfPower::Commands::DeclareWar; | 
|  | 13 |  |  |  |  | 32 |  | 
|  | 13 |  |  |  |  | 380 |  | 
| 26 | 13 |  |  | 13 |  | 4637 | use BalanceOfPower::Commands::AidInsurgents; | 
|  | 13 |  |  |  |  | 28 |  | 
|  | 13 |  |  |  |  | 379 |  | 
| 27 | 13 |  |  | 13 |  | 4264 | use BalanceOfPower::Commands::DiplomaticPressure; | 
|  | 13 |  |  |  |  | 27 |  | 
|  | 13 |  |  |  |  | 2533 |  | 
| 28 | 13 |  |  | 13 |  | 8656 | use BalanceOfPower::Commands::MilitaryAid; | 
|  | 13 |  |  |  |  | 24 |  | 
|  | 13 |  |  |  |  | 334 |  | 
| 29 | 13 |  |  | 13 |  | 3754 | use BalanceOfPower::Commands::Progress; | 
|  | 13 |  |  |  |  | 26 |  | 
|  | 13 |  |  |  |  | 11936 |  | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | has actor => ( | 
| 32 |  |  |  |  |  |  | is => 'rw', | 
| 33 |  |  |  |  |  |  | default => sub { undef } | 
| 34 |  |  |  |  |  |  | ); | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | has commands => ( | 
| 37 |  |  |  |  |  |  | is => 'ro', | 
| 38 |  |  |  |  |  |  | default => sub { {} } | 
| 39 |  |  |  |  |  |  | ); | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub init | 
| 42 |  |  |  |  |  |  | { | 
| 43 | 73 |  |  | 73 | 0 | 110 | my $self = shift; | 
| 44 | 73 |  |  |  |  | 229 | $self->log_name("bop-IA.log"); | 
| 45 | 73 |  |  |  |  | 220 | $self->delete_log(); | 
| 46 | 73 |  |  |  |  | 192 | $self->log_active(1); | 
| 47 | 73 |  |  |  |  | 106 | my $world = shift; | 
| 48 | 73 |  |  |  |  | 1799 | my $command = | 
| 49 |  |  |  |  |  |  | BalanceOfPower::Commands::BuildTroops->new( name => "BUILD TROOPS", | 
| 50 |  |  |  |  |  |  | domestic_cost => ARMY_COST, | 
| 51 |  |  |  |  |  |  | world => $world, | 
| 52 |  |  |  |  |  |  | allowed_at_war => 1, ); | 
| 53 | 73 |  |  |  |  | 783 | $self->commands->{"BUILD TROOPS"} = $command; | 
| 54 | 73 |  |  |  |  | 1649 | $command = | 
| 55 |  |  |  |  |  |  | BalanceOfPower::Commands::LowerDisorder->new( name => "LOWER DISORDER", | 
| 56 |  |  |  |  |  |  | world => $world, | 
| 57 |  |  |  |  |  |  | domestic_cost => RESOURCES_FOR_DISORDER ); | 
| 58 | 73 |  |  |  |  | 671 | $self->commands->{"LOWER DISORDER"} = $command; | 
| 59 | 73 |  |  |  |  | 1626 | $command = | 
| 60 |  |  |  |  |  |  | BalanceOfPower::Commands::AddRoute->new( name => "ADD ROUTE", | 
| 61 |  |  |  |  |  |  | world => $world, | 
| 62 |  |  |  |  |  |  | export_cost => ADDING_TRADEROUTE_COST ); | 
| 63 | 73 |  |  |  |  | 664 | $self->commands->{"ADD ROUTE"} = $command; | 
| 64 | 73 |  |  |  |  | 1623 | $command = | 
| 65 |  |  |  |  |  |  | BalanceOfPower::Commands::DeclareWar->new( name => "DECLARE WAR TO", | 
| 66 |  |  |  |  |  |  | synonyms => ["DECLARE WAR"], | 
| 67 |  |  |  |  |  |  | world => $world, | 
| 68 |  |  |  |  |  |  | crisis_needed => 1 ); | 
| 69 | 73 |  |  |  |  | 849 | $self->commands->{"DECLARE WAR TO"} = $command; | 
| 70 | 73 |  |  |  |  | 1604 | $command = | 
| 71 |  |  |  |  |  |  | BalanceOfPower::Commands::DeleteRoute->new( name => "DELETE TRADEROUTE", | 
| 72 |  |  |  |  |  |  | synonyms => ["DELETE ROUTE"], | 
| 73 |  |  |  |  |  |  | world => $world ); | 
| 74 | 73 |  |  |  |  | 761 | $self->commands->{"DELETE TRADEROUTE"} = $command; | 
| 75 | 73 |  |  |  |  | 1587 | $command = | 
| 76 |  |  |  |  |  |  | BalanceOfPower::Commands::BoostProduction->new( name => "BOOST PRODUCTION", | 
| 77 |  |  |  |  |  |  | world => $world, | 
| 78 |  |  |  |  |  |  | ); | 
| 79 | 73 |  |  |  |  | 662 | $self->commands->{"BOOST PRODUCTION"} = $command; | 
| 80 | 73 |  |  |  |  | 1746 | $command = | 
| 81 |  |  |  |  |  |  | BalanceOfPower::Commands::MilitarySupport->new( name => "MILITARY SUPPORT", | 
| 82 |  |  |  |  |  |  | world => $world, | 
| 83 |  |  |  |  |  |  | army_limit => { '>' => ARMY_FOR_SUPPORT } | 
| 84 |  |  |  |  |  |  | ); | 
| 85 | 73 |  |  |  |  | 640 | $self->commands->{"MILITARY SUPPORT"} = $command; | 
| 86 | 73 |  |  |  |  | 1676 | $command = | 
| 87 |  |  |  |  |  |  | BalanceOfPower::Commands::RecallMilitarySupport->new( name => "RECALL MILITARY SUPPORT", | 
| 88 |  |  |  |  |  |  | synonyms => ["RECALL SUPPORT"], | 
| 89 |  |  |  |  |  |  | world => $world, | 
| 90 |  |  |  |  |  |  | allowed_at_war => 1, | 
| 91 |  |  |  |  |  |  | ); | 
| 92 | 73 |  |  |  |  | 916 | $self->commands->{"RECALL MILITARY SUPPORT"} = $command; | 
| 93 | 73 |  |  |  |  | 1794 | $command = | 
| 94 |  |  |  |  |  |  | BalanceOfPower::Commands::AidInsurgents->new( name => "AID INSURGENTS IN", | 
| 95 |  |  |  |  |  |  | synonyms => ["AID INSURGENTS", "AID INSURGENCE"], | 
| 96 |  |  |  |  |  |  | world => $world, | 
| 97 |  |  |  |  |  |  | export_cost => AID_INSURGENTS_COST ); | 
| 98 | 73 |  |  |  |  | 771 | $self->commands->{"AID INSURGENTS IN"} = $command; | 
| 99 | 73 |  |  |  |  | 1726 | $command = | 
| 100 |  |  |  |  |  |  | BalanceOfPower::Commands::ComTreaty->new( name => "TREATY COM WITH", | 
| 101 |  |  |  |  |  |  | synonyms => ["COM TREATY", | 
| 102 |  |  |  |  |  |  | "COM TREATY WITH", | 
| 103 |  |  |  |  |  |  | "TREATY COM", | 
| 104 |  |  |  |  |  |  | ], | 
| 105 |  |  |  |  |  |  | world => $world, | 
| 106 |  |  |  |  |  |  | prestige_cost => TREATY_PRESTIGE_COST, | 
| 107 |  |  |  |  |  |  | treaty_limit => 1, | 
| 108 |  |  |  |  |  |  | ); | 
| 109 | 73 |  |  |  |  | 774 | $self->commands->{"TREATY COM WITH"} = $command; | 
| 110 | 73 |  |  |  |  | 1686 | $command = | 
| 111 |  |  |  |  |  |  | BalanceOfPower::Commands::NagTreaty->new( name => "TREATY NAG WITH", | 
| 112 |  |  |  |  |  |  | synonyms => ["NAG TREATY", | 
| 113 |  |  |  |  |  |  | "NAG TREATY WITH", | 
| 114 |  |  |  |  |  |  | "TREATY NAG" | 
| 115 |  |  |  |  |  |  | ], | 
| 116 |  |  |  |  |  |  | world => $world, | 
| 117 |  |  |  |  |  |  | prestige_cost => TREATY_PRESTIGE_COST, | 
| 118 |  |  |  |  |  |  | treaty_limit => 1, | 
| 119 |  |  |  |  |  |  | ); | 
| 120 | 73 |  |  |  |  | 753 | $self->commands->{"TREATY NAG WITH"} = $command; | 
| 121 | 73 |  |  |  |  | 1569 | $command = | 
| 122 |  |  |  |  |  |  | BalanceOfPower::Commands::EconomicAid->new( name => "ECONOMIC AID FOR", | 
| 123 |  |  |  |  |  |  | synonyms => ["ECONOMIC AID"], | 
| 124 |  |  |  |  |  |  | world => $world, | 
| 125 |  |  |  |  |  |  | export_cost => ECONOMIC_AID_COST, | 
| 126 |  |  |  |  |  |  | ); | 
| 127 | 73 |  |  |  |  | 735 | $self->commands->{"ECONOMIC AID FOR"} = $command; | 
| 128 | 73 |  |  |  |  | 1595 | $command = | 
| 129 |  |  |  |  |  |  | BalanceOfPower::Commands::RebelMilitarySupport->new( name => "REBEL MILITARY SUPPORT", | 
| 130 |  |  |  |  |  |  | world => $world, | 
| 131 |  |  |  |  |  |  | army_limit => { '>' => ARMY_FOR_SUPPORT } | 
| 132 |  |  |  |  |  |  | ); | 
| 133 | 73 |  |  |  |  | 610 | $self->commands->{"REBEL MILITARY SUPPORT"} = $command; | 
| 134 | 73 |  |  |  |  | 1555 | $command = | 
| 135 |  |  |  |  |  |  | BalanceOfPower::Commands::DiplomaticPressure->new( name => "DIPLOMATIC PRESSURE ON", | 
| 136 |  |  |  |  |  |  | world => $world, | 
| 137 |  |  |  |  |  |  | prestige_cost => DIPLOMATIC_PRESSURE_PRESTIGE_COST | 
| 138 |  |  |  |  |  |  | ); | 
| 139 | 73 |  |  |  |  | 721 | $self->commands->{"DIPLOMATIC PRESSURE ON"} = $command; | 
| 140 | 73 |  |  |  |  | 1583 | $command = | 
| 141 |  |  |  |  |  |  | BalanceOfPower::Commands::RecallRebelMilitarySupport->new( name => "RECALL REBEL MILITARY SUPPORT", | 
| 142 |  |  |  |  |  |  | world => $world, | 
| 143 |  |  |  |  |  |  | ); | 
| 144 | 73 |  |  |  |  | 633 | $self->commands->{"RECALL REBEL MILITARY SUPPORT"} = $command; | 
| 145 | 73 |  |  |  |  | 1764 | $command = | 
| 146 |  |  |  |  |  |  | BalanceOfPower::Commands::MilitaryAid->new( name => "MILITARY AID FOR", | 
| 147 |  |  |  |  |  |  | synonyms => ["MILITARY AID"], | 
| 148 |  |  |  |  |  |  | world => $world, | 
| 149 |  |  |  |  |  |  | export_cost => MILITARY_AID_COST, | 
| 150 |  |  |  |  |  |  | ); | 
| 151 | 73 |  |  |  |  | 837 | $self->commands->{"MILITARY AID FOR"} = $command; | 
| 152 | 73 |  |  |  |  | 1622 | $command = | 
| 153 |  |  |  |  |  |  | BalanceOfPower::Commands::Progress->new( name => "PROGRESS", | 
| 154 |  |  |  |  |  |  | world => $world, | 
| 155 |  |  |  |  |  |  | domestic_cost => PROGRESS_COST, | 
| 156 |  |  |  |  |  |  | ); | 
| 157 | 73 |  |  |  |  | 702 | $self->commands->{"PROGRESS"} = $command; | 
| 158 |  |  |  |  |  |  | } | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | sub recognize_command | 
| 162 |  |  |  |  |  |  | { | 
| 163 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 164 | 0 |  |  |  |  | 0 | my $nation = shift; | 
| 165 | 0 |  |  |  |  | 0 | my $query = shift; | 
| 166 | 0 |  |  |  |  | 0 | my $actor = $self->actor; | 
| 167 | 0 |  |  |  |  | 0 | for(keys %{$self->commands}) | 
|  | 0 |  |  |  |  | 0 |  | 
| 168 |  |  |  |  |  |  | { | 
| 169 | 0 |  |  |  |  | 0 | my $c = $self->commands->{$_}; | 
| 170 | 0 |  |  |  |  | 0 | $c->actor($actor); | 
| 171 | 0 | 0 |  |  |  | 0 | if($c->recognize($query)) | 
| 172 |  |  |  |  |  |  | { | 
| 173 | 0 | 0 |  |  |  | 0 | if($c->allowed()) | 
| 174 |  |  |  |  |  |  | { | 
| 175 | 0 |  |  |  |  | 0 | return $c->execute($query, $nation); | 
| 176 |  |  |  |  |  |  | } | 
| 177 |  |  |  |  |  |  | else | 
| 178 |  |  |  |  |  |  | { | 
| 179 | 0 |  |  |  |  | 0 | return { status => -1 }; | 
| 180 |  |  |  |  |  |  | } | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | } | 
| 183 |  |  |  |  |  |  | } | 
| 184 | 0 |  |  |  |  | 0 | return { status => 0 }; | 
| 185 |  |  |  |  |  |  | } | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | sub decide | 
| 188 |  |  |  |  |  |  | { | 
| 189 | 257 |  |  | 257 | 0 | 15754 | my $self = shift; | 
| 190 | 257 |  |  |  |  | 316 | my $order = shift; | 
| 191 | 257 | 100 |  |  |  | 917 | if(! exists $self->commands->{$order}) | 
| 192 |  |  |  |  |  |  | { | 
| 193 | 6 |  |  |  |  | 39 | $self->log($self->actor . ": $order doesn't exists!"); | 
| 194 | 6 |  |  |  |  | 18 | return undef; | 
| 195 |  |  |  |  |  |  | } | 
| 196 | 251 |  |  |  |  | 428 | my $c = $self->commands->{$order}; | 
| 197 | 251 |  |  |  |  | 1315 | $c->actor($self->actor); | 
| 198 | 251 | 100 |  |  |  | 757 | if($c->allowed()) | 
| 199 |  |  |  |  |  |  | { | 
| 200 | 170 |  |  |  |  | 614 | my $command = $c->IA(); | 
| 201 | 170 | 100 |  |  |  | 310 | my $exit_log = $command ? $command : "KO"; | 
| 202 | 170 |  |  |  |  | 801 | $self->log($self->actor . ": executing $order: $exit_log"); | 
| 203 | 170 |  |  |  |  | 599 | return $command; | 
| 204 |  |  |  |  |  |  | } | 
| 205 |  |  |  |  |  |  | else | 
| 206 |  |  |  |  |  |  | { | 
| 207 | 81 |  |  |  |  | 351 | $self->log($self->actor . ": $order not allowed"); | 
| 208 | 81 |  |  |  |  | 214 | return undef; | 
| 209 |  |  |  |  |  |  | } | 
| 210 |  |  |  |  |  |  | } | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | sub allowed_orders | 
| 213 |  |  |  |  |  |  | { | 
| 214 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 215 | 0 |  |  |  |  |  | my @out; | 
| 216 | 0 |  |  |  |  |  | for(keys %{$self->commands}) | 
|  | 0 |  |  |  |  |  |  | 
| 217 |  |  |  |  |  |  | { | 
| 218 | 0 |  |  |  |  |  | my $c = $self->commands->{$_}; | 
| 219 | 0 |  |  |  |  |  | $c->actor($self->actor); | 
| 220 | 0 | 0 |  |  |  |  | if( $c->allowed() ) | 
| 221 |  |  |  |  |  |  | { | 
| 222 | 0 |  |  |  |  |  | push @out, $c->print; | 
| 223 |  |  |  |  |  |  | } | 
| 224 |  |  |  |  |  |  | } | 
| 225 | 0 |  |  |  |  |  | return @out; | 
| 226 |  |  |  |  |  |  | } | 
| 227 |  |  |  |  |  |  |  | 
| 228 |  |  |  |  |  |  | sub print_orders | 
| 229 |  |  |  |  |  |  | { | 
| 230 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 231 | 0 |  |  |  |  |  | my $out = as_title("ORDERS FOR " . $self->actor); | 
| 232 | 0 |  |  |  |  |  | $out .= "\n\n"; | 
| 233 | 0 |  |  |  |  |  | for(keys %{$self->commands}) | 
|  | 0 |  |  |  |  |  |  | 
| 234 |  |  |  |  |  |  | { | 
| 235 | 0 |  |  |  |  |  | my $c = $self->commands->{$_}; | 
| 236 | 0 |  |  |  |  |  | $c->actor($self->actor); | 
| 237 | 0 | 0 |  |  |  |  | if( $c->allowed() ) | 
| 238 |  |  |  |  |  |  | { | 
| 239 | 0 |  |  |  |  |  | $out .= as_active($c->print) . "\n"; | 
| 240 |  |  |  |  |  |  | } | 
| 241 |  |  |  |  |  |  | else | 
| 242 |  |  |  |  |  |  | { | 
| 243 | 0 |  |  |  |  |  | $out .= $c->print . "\n"; | 
| 244 |  |  |  |  |  |  | } | 
| 245 |  |  |  |  |  |  | } | 
| 246 | 0 |  |  |  |  |  | return $out; | 
| 247 |  |  |  |  |  |  | } | 
| 248 |  |  |  |  |  |  |  | 
| 249 |  |  |  |  |  |  | 1; |