Something went wrong. Try again.
Perl game server for TLE Community
Something went wrong. Try again.
1.6 kB · 73 lines
Perl
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374use 5.010;use strict;use lib '/home/lacuna/server/lib';use Lacuna::DB;use Lacuna;use Lacuna::Util qw(randint format_date);use Getopt::Long;use AnyEvent;$|=1;our $quiet;GetOptions( 'quiet' => \$quiet,);
use Fcntl qw(:flock);# stop multiple copies from runningunless (flock(DATA, LOCK_EX|LOCK_NB)) { print "$0 is already running. Exiting.\n"; exit(1);}
out('Started');my $start = time;
out('Loading DB');our $db = Lacuna->db;our $ai = Lacuna::AI::Trelvestian->new;
my $config = Lacuna->config;
out('Looping through colonies...');my $colonies = $ai->empire->planets;my @attacks;while (my $attacking_colony = $colonies->next) { out('Found colony to attack from named '.$attacking_colony->name); out('Finding target body to attack...'); my $target_colony = $attacking_colony->get_last_attacked_by; next unless defined $target_colony; my @ships = qw(sweeper snark snark2 snark3); out('Attacking '.$target_colony->name); push @attacks, $ai->start_attack($attacking_colony, $target_colony, \@ships); $attacking_colony->delete_last_attacked_by;}
out("Waiting on attacks...");foreach my $attack (@attacks) { $attack->recv if defined $attack;}
my $finish = time;out('Finished');out((($finish - $start)/60)." minutes have elapsed");
################# SUBROUTINES###############
sub out { my $message = shift; unless ($quiet) { say format_date(DateTime->now), " ", $message; }}
__DATA__This exists so flock() code above works.DO NOT REMOVE THIS DATA SECTION.