line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Lacuna::Task::Action::OptimizeProbes; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1833
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
61
|
|
4
|
|
|
|
|
|
|
our $VERSION = $Games::Lacuna::Task::VERSION; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
472
|
use Moose -traits => 'NoAutomatic'; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
extends qw(Games::Lacuna::Task::Action); |
8
|
|
|
|
|
|
|
with qw(Games::Lacuna::Task::Role::PlanetRun |
9
|
|
|
|
|
|
|
Games::Lacuna::Task::Role::Stars); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub description { |
12
|
|
|
|
|
|
|
return q[Check for duplicate probes]; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'optimize_alliance' => ( |
16
|
|
|
|
|
|
|
is => 'rw', |
17
|
|
|
|
|
|
|
isa => 'Bool', |
18
|
|
|
|
|
|
|
default => 0, |
19
|
|
|
|
|
|
|
documentation => 'Remove probes from solar systems with ally presence [Default: false]' |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has '_probe_cache' => ( |
24
|
|
|
|
|
|
|
is => 'rw', |
25
|
|
|
|
|
|
|
isa => 'HashRef', |
26
|
|
|
|
|
|
|
required => 1, |
27
|
|
|
|
|
|
|
default => sub { {} }, |
28
|
|
|
|
|
|
|
traits => ['Hash','NoGetopt'], |
29
|
|
|
|
|
|
|
handles => { |
30
|
|
|
|
|
|
|
add_probe_cache => 'set', |
31
|
|
|
|
|
|
|
has_probe_cache => 'exists', |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub process_planet { |
36
|
|
|
|
|
|
|
my ($self,$planet_stats) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Get observatory |
39
|
|
|
|
|
|
|
my $observatory = $self->find_building($planet_stats->{id},'Observatory'); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return |
42
|
|
|
|
|
|
|
unless $observatory; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Get observatory probed stars |
45
|
|
|
|
|
|
|
my $observatory_object = $self->build_object($observatory); |
46
|
|
|
|
|
|
|
my $observatory_data = $self->paged_request( |
47
|
|
|
|
|
|
|
object => $observatory_object, |
48
|
|
|
|
|
|
|
method => 'get_probed_stars', |
49
|
|
|
|
|
|
|
total => 'star_count', |
50
|
|
|
|
|
|
|
data => 'stars', |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Loop all stars |
54
|
|
|
|
|
|
|
foreach my $star_data (@{$observatory_data->{stars}}) { |
55
|
|
|
|
|
|
|
# Update cache |
56
|
|
|
|
|
|
|
$star_data->{last_checked} = time(); |
57
|
|
|
|
|
|
|
$star_data->{is_probed} = 1; |
58
|
|
|
|
|
|
|
$self->set_star_cache($star_data); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $star_id = $star_data->{id}; |
61
|
|
|
|
|
|
|
my $abandon = $self->has_probe_cache($star_id); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
if (! $abandon && $self->optimize_alliance) { |
64
|
|
|
|
|
|
|
my $has_ally = 0; |
65
|
|
|
|
|
|
|
my $has_self = 0; |
66
|
|
|
|
|
|
|
foreach my $body (@{$star_data->{bodies}}) { |
67
|
|
|
|
|
|
|
if (defined $body->{empire}) { |
68
|
|
|
|
|
|
|
given ($body->{empire}{alignment}) { |
69
|
|
|
|
|
|
|
when ('self') { |
70
|
|
|
|
|
|
|
$has_self++; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
when ('ally') { |
73
|
|
|
|
|
|
|
$has_ally++; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
if ($has_ally && !$has_self) { |
80
|
|
|
|
|
|
|
$abandon = 1; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
if ($abandon) { |
85
|
|
|
|
|
|
|
$self->log('notice',"Abandoning probe from %s in %s",$planet_stats->{name},$star_data->{name}); |
86
|
|
|
|
|
|
|
$self->request( |
87
|
|
|
|
|
|
|
object => $observatory_object, |
88
|
|
|
|
|
|
|
method => 'abandon_probe', |
89
|
|
|
|
|
|
|
params => [$star_id], |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# Check star status again |
93
|
|
|
|
|
|
|
$self->_get_star_api($star_data->{id},$star_data->{x},$star_data->{y}); |
94
|
|
|
|
|
|
|
} else { |
95
|
|
|
|
|
|
|
$self->add_probe_cache($star_id,1); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
101
|
|
|
|
|
|
|
no Moose; |
102
|
|
|
|
|
|
|
1; |