Skip to content
Browse files

Jackpot AI

  • Loading branch information...
1 parent e93417c commit 99bde85d0bb741a4da2c6f5a3ec11e1cfd60ca91 @lemming552 lemming552 committed Jan 31, 2014
Showing with 235 additions and 3 deletions.
  1. +53 −0 bin/jackpot/add_colonies.pl
  2. +44 −0 bin/jackpot/hourly_update.pl
  3. +1 −1 lib/Lacuna.pm
  4. +4 −2 lib/Lacuna/AI.pm
  5. +130 −0 lib/Lacuna/AI/Jackpot.pm
  6. +3 −0 var/www/public/changes.txt
View
53 bin/jackpot/add_colonies.pl
@@ -0,0 +1,53 @@
+use 5.010;
+use strict;
+use lib '/data/Lacuna-Server/lib';
+use Lacuna::DB;
+use Lacuna;
+use Lacuna::Util qw(format_date);
+use Getopt::Long;
+
+$|=1;
+our $quiet;
+our $add_one;
+GetOptions(
+ quiet => \$quiet,
+# addone => \$add_one,
+);
+
+
+out('Started');
+my $start = time;
+out('Loading DB');
+our $db = Lacuna->db;
+my $config = Lacuna->config;
+my $empires = $db->resultset('Lacuna::DB::Result::Empire');
+my $ai = Lacuna::AI::Jackpot->new;
+my $viable_colonies = $db->resultset('Lacuna::DB::Result::Map::Body')->search(
+ { zone => '0|0', empire_id => undef, size => { between => [40,60]}},
+ { rows => 1, order_by => 'rand()' }
+ );
+my $jackpot = $empires->find(-4);
+unless (defined $jackpot) {
+ out('Creating new empire');
+ $jackpot = $ai->create_empire();
+}
+
+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;
+ }
+}
+
+
View
44 bin/jackpot/hourly_update.pl
@@ -0,0 +1,44 @@
+use 5.010;
+use strict;
+use lib '/data/Lacuna-Server/lib';
+use Lacuna::DB;
+use Lacuna;
+use Lacuna::Util qw(format_date);
+use Getopt::Long;
+$|=1;
+our $quiet;
+GetOptions(
+ 'quiet' => \$quiet,
+);
+
+out('Started');
+my $start = time;
+
+out('Loading AI');
+my $ai = Lacuna::AI::Saben->new;
+
+out('Running Updates');
+$ai->run_all_hourly_colony_updates;
+
+
+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;
+ }
+}
+
+
View
2 lib/Lacuna.pm
@@ -7,7 +7,7 @@ use Config::JSON;
useall __PACKAGE__;
-our $VERSION = 3.0901;
+our $VERSION = 3.0902;
my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf');
my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1});
View
6 lib/Lacuna/AI.pm
@@ -56,8 +56,9 @@ sub create_empire {
);
my $db = Lacuna->db;
my $empire = $db->resultset('Lacuna::DB::Result::Empire')->new(\%attributes)->insert;
- my $zone = $db->resultset('Lacuna::DB::Result::Map::Body')->get_column('zone')->max;
- my $home = $self->viable_colonies->search({zone => $zone},{rows=>1})->single;
+# my $zone = $db->resultset('Lacuna::DB::Result::Map::Body')->get_column('zone')->max;
+# my $home = $self->viable_colonies->search({zone => $zone},{rows=>1})->single;
+ my $home = $self->viable_colonies->search(undef,{rows=>1})->single;
my @to_demolish = @{$home->building_cache};
$home->delete_buildings(\@to_demolish);
$empire->found($home);
@@ -186,6 +187,7 @@ sub add_colonies {
},{
join => 'stars',
rows => 100,
+ order_by => 'rand()'
});
my $body = random_element(\@bodies);
View
130 lib/Lacuna/AI/Jackpot.pm
@@ -0,0 +1,130 @@
+package Lacuna::AI::Jackpot;
+
+use Moose;
+use utf8;
+no warnings qw(uninitialized);
+extends 'Lacuna::AI';
+
+use constant empire_id => -4;
+
+has viable_colonies => (
+ is => 'ro',
+ lazy => 1,
+ default => sub {
+ return Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->search(
+ { empire_id => undef, zone => '0|0', orbit => { between => [1,7] }, size => { between => [30,65]}},
+ );
+ }
+);
+
+sub empire_defaults {
+ return {
+ name => 'Jackpot',
+ status_message => 'Target',
+ description => 'Free for All',
+ species_name => 'Meat Prizes',
+ species_description => 'Targets.',
+ min_orbit => 1,
+ max_orbit => 7,
+ manufacturing_affinity => 7,
+ deception_affinity => 7,
+ research_affinity => 7,
+ management_affinity => 7,
+ farming_affinity => 7,
+ mining_affinity => 7,
+ science_affinity => 7,
+ environmental_affinity => 7,
+ political_affinity => 7,
+ trade_affinity => 7,
+ growth_affinity => 7,
+ is_isolationist => 0,
+ };
+}
+
+sub colony_structures {
+ return (
+ ['Lacuna::DB::Result::Building::Waste::Sequestration', 16],
+ ['Lacuna::DB::Result::Building::Intelligence', 10],
+ ['Lacuna::DB::Result::Building::Security', 15],
+ ['Lacuna::DB::Result::Building::Shipyard', 10],
+ ['Lacuna::DB::Result::Building::SpacePort', 20],
+ ['Lacuna::DB::Result::Building::SpacePort', 20],
+ ['Lacuna::DB::Result::Building::SpacePort', 20],
+ ['Lacuna::DB::Result::Building::SpacePort', 20],
+ ['Lacuna::DB::Result::Building::SpacePort', 20],
+ ['Lacuna::DB::Result::Building::Observatory',15],
+ ['Lacuna::DB::Result::Building::Archaeology',10],
+ ['Lacuna::DB::Result::Building::Trade', 15],
+ ['Lacuna::DB::Result::Building::SAW',20],
+ ['Lacuna::DB::Result::Building::SAW',20],
+ ['Lacuna::DB::Result::Building::SAW',20],
+ ['Lacuna::DB::Result::Building::SAW',20],
+ ['Lacuna::DB::Result::Building::SAW',20],
+ ['Lacuna::DB::Result::Building::Permanent::Volcano',15],
+ ['Lacuna::DB::Result::Building::Permanent::NaturalSpring',15],
+ ['Lacuna::DB::Result::Building::Permanent::InterDimensionalRift',15],
+ ['Lacuna::DB::Result::Building::Permanent::GeoThermalVent',15],
+ ['Lacuna::DB::Result::Building::Permanent::KalavianRuins',15],
+ ['Lacuna::DB::Result::Building::Permanent::MalcudField',15],
+ ['Lacuna::DB::Result::Building::Permanent::AlgaePond',15],
+ ['Lacuna::DB::Result::Building::Permanent::Ravine',15],
+ ['Lacuna::DB::Result::Building::Water::Storage',15],
+ ['Lacuna::DB::Result::Building::Ore::Storage',15],
+ ['Lacuna::DB::Result::Building::Energy::Reserve',15],
+ ['Lacuna::DB::Result::Building::Food::Reserve',15],
+ ['Lacuna::DB::Result::Building::Food::Corn',15],
+ ['Lacuna::DB::Result::Building::Food::Wheat',15],
+ ['Lacuna::DB::Result::Building::Food::Dairy',15],
+);
+}
+
+sub extra_glyph_buildings {
+ return {
+ quantity => 0,
+ min_level => 1,
+ max_level => 1,
+ }
+}
+
+sub spy_missions {
+# Missions run by script
+ return (
+ 'Appropriate Resources',
+ 'Sabotage Resources',
+ );
+}
+
+sub ship_building_priorities {
+ return (
+ ['cargo_ship', 15],
+ ['galleon', 5],
+ );
+}
+
+sub run_hourly_colony_updates {
+ my ($self, $colony) = @_;
+ $self->demolish_bleeders($colony);
+ $self->set_defenders($colony);
+ $self->pod_check($colony, 10);
+ $self->reset_stuff($colony);
+ $self->train_spies($colony);
+ $self->build_ships($colony);
+ $self->run_missions($colony);
+}
+
+sub reset_stuff {
+ my ($self, $colony) = @_;
+
+ my %structures = map { $_[0] => $_[1] } $self->colony_structures;
+
+ foreach my $building (@{$colony->building_cache}) {
+ if ($structures{$building->class} and $structures{$building->class} > $building->level ) {
+ $building->level = $structures{$building->class};
+ $building->update;
+ }
+ }
+#place plans?
+}
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
View
3 var/www/public/changes.txt
@@ -1,3 +1,6 @@
+3.0902:
+ - Add: Jackpot AI
+
3.0901:
- API: Spaceport ship filter includes all relevant tasks.
- Fix: Parliament actually looks at leader's embassy for max members.

0 comments on commit 99bde85

Please sign in to comment.
Something went wrong with that request. Please try again.