line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Role::CommonAttributes; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1370
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
53
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
488
|
use MooseX::Role::Parameterized; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
parameter 'attributes' => ( |
9
|
|
|
|
|
|
|
isa => 'ArrayRef[Str]', |
10
|
|
|
|
|
|
|
required => 1, |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
role { |
14
|
|
|
|
|
|
|
my $p = shift; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
if ('dispose_percentage' ~~ $p->attributes) { |
17
|
|
|
|
|
|
|
has 'dispose_percentage' => ( |
18
|
|
|
|
|
|
|
isa => 'Int', |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
required=>1, |
21
|
|
|
|
|
|
|
default => 80, |
22
|
|
|
|
|
|
|
documentation => 'Dispose waste if waste storage is n-% full', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
if ('start_building_at' ~~ $p->attributes) { |
27
|
|
|
|
|
|
|
has 'start_building_at' => ( |
28
|
|
|
|
|
|
|
isa => 'Int', |
29
|
|
|
|
|
|
|
is => 'rw', |
30
|
|
|
|
|
|
|
required=> 1, |
31
|
|
|
|
|
|
|
default => 0, |
32
|
|
|
|
|
|
|
documentation => 'Upgrade buildings if there are less than N buildings in the build queue', |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if ('plan_for_hours' ~~ $p->attributes) { |
37
|
|
|
|
|
|
|
has 'plan_for_hours' => ( |
38
|
|
|
|
|
|
|
isa => 'Num', |
39
|
|
|
|
|
|
|
is => 'rw', |
40
|
|
|
|
|
|
|
required=> 1, |
41
|
|
|
|
|
|
|
default => 1, |
42
|
|
|
|
|
|
|
documentation => 'Plan N hours ahead', |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
if ('keep_waste_hours' ~~ $p->attributes) { |
47
|
|
|
|
|
|
|
has 'keep_waste_hours' => ( |
48
|
|
|
|
|
|
|
isa => 'Num', |
49
|
|
|
|
|
|
|
is => 'rw', |
50
|
|
|
|
|
|
|
required=> 1, |
51
|
|
|
|
|
|
|
default => 24, |
52
|
|
|
|
|
|
|
documentation => 'Keep enough waste for N hours', |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
if ('target_planet' ~~ $p->attributes) { |
57
|
|
|
|
|
|
|
has 'target_planet' => ( |
58
|
|
|
|
|
|
|
is => 'rw', |
59
|
|
|
|
|
|
|
isa => 'Str', |
60
|
|
|
|
|
|
|
required=> 1, |
61
|
|
|
|
|
|
|
documentation => 'Target planet (Name, ID or Coordinates) [Required]', |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
has 'target_planet_data' => ( |
65
|
|
|
|
|
|
|
isa => 'HashRef', |
66
|
|
|
|
|
|
|
is => 'rw', |
67
|
|
|
|
|
|
|
traits => ['NoGetopt'], |
68
|
|
|
|
|
|
|
lazy_build => 1, |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
method '_build_target_planet_data' => sub { |
71
|
|
|
|
|
|
|
my ($self) = @_; |
72
|
|
|
|
|
|
|
my $target_planet; |
73
|
|
|
|
|
|
|
given ($self->target_planet) { |
74
|
|
|
|
|
|
|
when (/^\d+$/) { |
75
|
|
|
|
|
|
|
$target_planet = $self->get_body_by_id($_); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
when (/^(?<x>-?\d+),(?<y>-?\d+)$/) { |
78
|
|
|
|
|
|
|
$target_planet = $self->get_body_by_xy($+{x},$+{y}); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
default { |
81
|
|
|
|
|
|
|
$target_planet = $self->get_body_by_name($_); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
unless (defined $target_planet) { |
85
|
|
|
|
|
|
|
$self->abort('Could not find target planet "%s"',$self->target_planet); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
return $target_planet; |
88
|
|
|
|
|
|
|
}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
if ('mytarget_planet' ~~ $p->attributes) { |
92
|
|
|
|
|
|
|
has 'target_planet' => ( |
93
|
|
|
|
|
|
|
is => 'rw', |
94
|
|
|
|
|
|
|
isa => 'Str', |
95
|
|
|
|
|
|
|
required=> 1, |
96
|
|
|
|
|
|
|
documentation => 'Target planet [Required]', |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
has 'target_planet_data' => ( |
100
|
|
|
|
|
|
|
isa => 'HashRef', |
101
|
|
|
|
|
|
|
is => 'rw', |
102
|
|
|
|
|
|
|
traits => ['NoGetopt'], |
103
|
|
|
|
|
|
|
lazy_build => 1, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
method '_build_target_planet_data' => sub { |
106
|
|
|
|
|
|
|
my ($self) = @_; |
107
|
|
|
|
|
|
|
my $target_planet = $self->my_body_status($self->target_planet); |
108
|
|
|
|
|
|
|
unless (defined $target_planet) { |
109
|
|
|
|
|
|
|
$self->abort('Could not find target planet "%s"',$self->target_planet); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
return $target_planet; |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
if ('home_planet' ~~ $p->attributes) { |
116
|
|
|
|
|
|
|
has 'home_planet' => ( |
117
|
|
|
|
|
|
|
is => 'rw', |
118
|
|
|
|
|
|
|
isa => 'Str', |
119
|
|
|
|
|
|
|
required=> 1, |
120
|
|
|
|
|
|
|
documentation => 'Home planet [Required]', |
121
|
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
has 'home_planet_data' => ( |
124
|
|
|
|
|
|
|
isa => 'HashRef', |
125
|
|
|
|
|
|
|
is => 'rw', |
126
|
|
|
|
|
|
|
traits => ['NoGetopt'], |
127
|
|
|
|
|
|
|
lazy_build => 1, |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
method '_build_home_planet_data' => sub { |
130
|
|
|
|
|
|
|
my ($self) = @_; |
131
|
|
|
|
|
|
|
my $home_planet = $self->my_body_status($self->home_planet); |
132
|
|
|
|
|
|
|
unless (defined $home_planet) { |
133
|
|
|
|
|
|
|
$self->abort('Could not find home planet "%s"',$self->home_planet); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
return $home_planet; |
136
|
|
|
|
|
|
|
}; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
}; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=encoding utf8 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 NAME |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Games::Lacuna::Role::CommonAttributes -Â Attributes utilized by multiple actions |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 SYNOPSIS |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
package Games::Lacuna::Task::Action::MyTask; |
151
|
|
|
|
|
|
|
use Moose; |
152
|
|
|
|
|
|
|
extends qw(Games::Lacuna::Task::Action); |
153
|
|
|
|
|
|
|
with 'Games::Lacuna::Task::Role::CommonAttributes' => { attributes => ['dispose_percentage'] }; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 DESCRIPTION |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The following accessors and helper methods are available on request |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 home_planet |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Own planet. Planet stast can be accessed via the C<home_planet_data> method. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 target_planet |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Foreign planet. Planet stast can be accessed via the C<target_planet_data> |
166
|
|
|
|
|
|
|
method. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 dispose_percentage |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Dispose waste if waste storage is n-% full |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 start_building_at |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Upgrade buildings if there are less than N buildings in the build queue |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 plan_for_hours |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Plan N hours ahead |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 keep_waste_hours |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Keep enough waste for N hours', |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |