Games-Lacuna-Client
view release on metacpan or search on metacpan
examples/glyphinator.pl view on Meta::CPAN
(((o.x - ?) * (o.x - ?) + (o.y - ?) * (o.y - ?)) $rand) as sort_dist
$last_checked
from orbitals o
join stars s on o.star_id = s.id
where (type in ('habitable planet', 'asteroid', 'gas giant') or type is null)
and (last_excavated is null or date(last_excavated) < date('now', '-30 days'))
and o.x between ? and ?
and o.y between ? and ?
and dist <= $max_squared
and dist >= $min_squared
$skip_sql
$safe_zone
$inhabited
$zone
$inner_box
order by sort_dist $order
limit $count
SQL
# select columns,x/y betweens
my @vals = (
$base_x, $base_x, $base_y, $base_y,
$base_x, $base_x, $base_y, $base_y,
$base_x - $current_max,
$base_x + $current_max,
$base_y - $current_max,
$base_y + $current_max,
@$skip,
);
if ($batch->{zone}) {
push @vals, $batch->{zone};
}
if ($current_min > 0) {
push @vals,
$base_x - $current_min,
$base_x + $current_min,
$base_y - $current_min,
$base_y + $current_min,
}
$find_dest->execute(@vals);
while (my $row = $find_dest->fetchrow_hashref) {
my $dest_name = "$row->{star_name} $row->{orbit}";
my $dist = int(sqrt($row->{dist}));
verbose("Selected destination $dest_name, which is " . pluralize($dist, "unit") . " away\n");
my $zone = $row->{zone};
unless ($zone) {
my $x_zone = int($row->{x} / 250);
my $y_zone = int($row->{y} / 250);
$zone = "$x_zone|$y_zone";
}
push @results, [$dest_name, $row->{x}, $row->{y}, $dist, $zone, $row->{checked_epoch} || 0];
push @$skip, $dest_name;
}
}
return @results;
}
sub update_last_sent {
my ($x, $y) = @_;
my $r = $star_db->do(q{update orbitals set last_excavated = datetime(?,'unixepoch') where x = ? and y = ?}, {}, time(), $x, $y);
unless ($r > 0) {
diag("Warning: could not update orbitals table for body at $x, $y!\n");
}
}
sub mark_orbit_empty {
my ($x, $y) = @_;
my $r = $star_db->do(q{update orbitals set type = 'empty' where x = ? and y = ?}, {}, $x, $y);
unless ($r > 0) {
diag("Warning: could not update orbitals table for body at $x, $y!\n");
}
}
sub mark_orbit_occupied {
my ($x, $y) = @_;
my $r = $star_db->do(q{update orbitals set empire_id = -1 where x = ? and y = ?}, {}, $x, $y);
unless ($r > 0) {
diag("Warning: could not update orbitals table for body at $x, $y!\n");
}
}
sub usage {
diag(<<END);
Usage: $0 [options]
This program will manage your glyph hunting worries with minimal manual
intervention required. It will notice archeology digs, ready-to-launch
excavators, and idle shipyards and notify you of them. It can start digs
for the most needed glyphs, and send excavators to the nearest available
bodies.
This is suitable for automation with cron(8) or at(1), but you should
know that it tends to use a substantial number of API calls, often 50-100
per run. With the daily limit of 5000, including all web UI usage, you
will want to keep these at a relatively infrequent interval, such as every
60 minutes at most.
Options:
--verbose - Output extra information.
--quiet - Print no output except for errors.
--config <file> - Specify a GLC config file, normally lacuna.yml.
--db <file> - Specify a star database, normally stars.db.
--planet <name> - Specify a planet to process. This option can be
passed multiple times to indicate several planets.
If this is not specified, all relevant colonies will
be inspected.
--continuous [<min>] - Run the program in a continuous loop until interrupted.
If an argument is supplied, it should be the number of
minutes to sleep between runs. If unspecified, the
default is 360 (6 hours). If all arch digs will finish
before the next scheduled loop and --do-digs is specified,
it will instead run at that time.
--do-digs - Begin archaeology digs on any planets which are idle.
--min-ore <amount> - Do not begin digs with less ore in reserve than this
amount. The default is 10,000.
( run in 0.530 second using v1.01-cache-2.11-cpan-39bf76dae61 )