| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package BalanceOfPower::Role::GameMaster; |
|
2
|
|
|
|
|
|
|
$BalanceOfPower::Role::GameMaster::VERSION = '0.400110'; |
|
3
|
13
|
|
|
13
|
|
4627
|
use strict; |
|
|
13
|
|
|
|
|
16
|
|
|
|
13
|
|
|
|
|
302
|
|
|
4
|
13
|
|
|
13
|
|
114
|
use v5.10; |
|
|
13
|
|
|
|
|
22
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
13
|
|
|
13
|
|
47
|
use Moo::Role; |
|
|
13
|
|
|
|
|
15
|
|
|
|
13
|
|
|
|
|
89
|
|
|
7
|
13
|
|
|
13
|
|
2864
|
use List::Util qw(shuffle); |
|
|
13
|
|
|
|
|
18
|
|
|
|
13
|
|
|
|
|
694
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
13
|
|
|
13
|
|
53
|
use BalanceOfPower::Player; |
|
|
13
|
|
|
|
|
13
|
|
|
|
13
|
|
|
|
|
210
|
|
|
10
|
13
|
|
|
13
|
|
3402
|
use BalanceOfPower::Targets::Fall; |
|
|
13
|
|
|
|
|
21
|
|
|
|
13
|
|
|
|
|
333
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
13
|
|
|
13
|
|
64
|
use BalanceOfPower::Constants ':all'; |
|
|
13
|
|
|
|
|
11
|
|
|
|
13
|
|
|
|
|
12260
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has players => ( |
|
15
|
|
|
|
|
|
|
is => 'rw', |
|
16
|
|
|
|
|
|
|
default => sub { [] } |
|
17
|
|
|
|
|
|
|
); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub get_player |
|
20
|
|
|
|
|
|
|
{ |
|
21
|
29
|
|
|
29
|
0
|
779
|
my $self = shift; |
|
22
|
29
|
|
|
|
|
29
|
my $name = shift; |
|
23
|
29
|
|
|
|
|
21
|
my @good = grep { $_->name eq $name} @{$self->players}; |
|
|
23
|
|
|
|
|
67
|
|
|
|
29
|
|
|
|
|
114
|
|
|
24
|
29
|
100
|
|
|
|
49
|
if(@good) |
|
25
|
|
|
|
|
|
|
{ |
|
26
|
23
|
|
|
|
|
52
|
return $good[0]; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
else |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
6
|
|
|
|
|
16
|
return undef; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
sub create_player |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
3
|
|
|
3
|
0
|
5
|
my $self = shift; |
|
36
|
3
|
|
|
|
|
4
|
my $username = shift; |
|
37
|
3
|
|
|
|
|
5
|
my $position = shift; |
|
38
|
3
|
|
50
|
|
|
17
|
my $money = shift || START_PLAYER_MONEY; |
|
39
|
3
|
|
|
|
|
11
|
my $already = $self->get_player($username); |
|
40
|
3
|
50
|
|
|
|
9
|
if($already) |
|
41
|
|
|
|
|
|
|
{ |
|
42
|
0
|
0
|
|
|
|
0
|
$already->position($position) if $position; |
|
43
|
0
|
0
|
|
|
|
0
|
$already->money($money) if $money; |
|
44
|
0
|
|
|
|
|
0
|
return 0; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
3
|
50
|
|
|
|
8
|
if(! $position) |
|
47
|
|
|
|
|
|
|
{ |
|
48
|
3
|
|
|
|
|
3
|
my @nations = @{$self->nation_names}; |
|
|
3
|
|
|
|
|
14
|
|
|
49
|
3
|
|
|
|
|
12
|
@nations = shuffle @nations; |
|
50
|
3
|
|
|
|
|
7
|
$position = $nations[0]; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
3
|
|
|
|
|
7
|
my $log_name = $username . ".log"; |
|
53
|
3
|
|
|
|
|
6
|
$log_name =~ s/ /_/g; |
|
54
|
3
|
|
|
|
|
35
|
my $pl = BalanceOfPower::Player->new(name => $username, money => $money, log_name => $log_name, log_dir => $self->log_dir, current_year => $self->current_year, position => $position); |
|
55
|
3
|
|
|
|
|
21
|
$pl->delete_log(); |
|
56
|
3
|
|
|
|
|
14
|
$pl->register_event("ENTERING THE GAME"); |
|
57
|
3
|
|
|
|
|
19
|
$self->register_event("$username IS ENTERING THE GAME"); |
|
58
|
3
|
|
|
|
|
13
|
$self->add_player($pl); |
|
59
|
3
|
|
|
|
|
5
|
return 1; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub add_player |
|
64
|
|
|
|
|
|
|
{ |
|
65
|
3
|
|
|
3
|
0
|
4
|
my $self = shift; |
|
66
|
3
|
|
|
|
|
6
|
my $player = shift; |
|
67
|
3
|
50
|
|
|
|
10
|
if($self->get_player($player->name)) |
|
68
|
|
|
|
|
|
|
{ |
|
69
|
0
|
|
|
|
|
0
|
return 0; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
else |
|
72
|
|
|
|
|
|
|
{ |
|
73
|
3
|
|
|
|
|
4
|
push @{$self->players}, $player; |
|
|
3
|
|
|
|
|
10
|
|
|
74
|
3
|
|
|
|
|
5
|
return 1; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
sub delete_player |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
80
|
0
|
|
|
|
|
0
|
my $player = shift; |
|
81
|
0
|
|
|
|
|
0
|
my @players = grep { $_->name ne $player} @{$self->players}; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
82
|
0
|
|
|
|
|
0
|
$self->players(\@players); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
sub player_start_turn |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
46
|
|
|
46
|
0
|
53
|
my $self = shift; |
|
87
|
46
|
|
|
|
|
43
|
for(@{$self->players}) |
|
|
46
|
|
|
|
|
113
|
|
|
88
|
|
|
|
|
|
|
{ |
|
89
|
10
|
|
|
|
|
30
|
$_->current_year($self->current_year); |
|
90
|
10
|
|
|
|
|
27
|
$_->refill_movements(); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub player_targets |
|
95
|
|
|
|
|
|
|
{ |
|
96
|
45
|
|
|
45
|
0
|
49
|
my $self = shift; |
|
97
|
45
|
|
|
|
|
50
|
for(@{$self->players}) |
|
|
45
|
|
|
|
|
122
|
|
|
98
|
|
|
|
|
|
|
{ |
|
99
|
10
|
|
|
|
|
12
|
my $p = $_; |
|
100
|
10
|
100
|
|
|
|
34
|
if($p->no_targets) |
|
101
|
|
|
|
|
|
|
{ |
|
102
|
2
|
|
|
|
|
14
|
my $obj = BalanceOfPower::Targets::Fall->select_random_target($self); |
|
103
|
2
|
50
|
|
|
|
6
|
if($obj) |
|
104
|
|
|
|
|
|
|
{ |
|
105
|
2
|
|
|
|
|
19
|
my $target = BalanceOfPower::Targets::Fall->new(target_obj => $obj, |
|
106
|
|
|
|
|
|
|
government_id => $obj->government_id, |
|
107
|
|
|
|
|
|
|
countdown => TIME_FOR_TARGET); |
|
108
|
2
|
|
|
|
|
1876
|
$p->add_target($target); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
else |
|
112
|
|
|
|
|
|
|
{ |
|
113
|
8
|
|
|
|
|
17
|
$p->check_targets($self); |
|
114
|
8
|
|
|
|
|
19
|
$p->click_targets(); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
sub print_targets |
|
119
|
|
|
|
|
|
|
{ |
|
120
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
121
|
0
|
|
|
|
|
|
my $player = shift; |
|
122
|
0
|
|
0
|
|
|
|
my $mode = shift || 'print'; |
|
123
|
0
|
|
|
|
|
|
my $player_obj = $self->get_player($player); |
|
124
|
0
|
|
|
|
|
|
return BalanceOfPower::Printer::print($mode, $self, 'print_targets', |
|
125
|
|
|
|
|
|
|
{ player => $player, |
|
126
|
|
|
|
|
|
|
points => $player_obj->mission_points, |
|
127
|
|
|
|
|
|
|
targets => $player_obj->targets, |
|
128
|
|
|
|
|
|
|
} ); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |