Skip to content

Commit

Permalink
AI don't sweep if nothing found. bhg_neutralized works on saben target.
Browse files Browse the repository at this point in the history
  • Loading branch information
lemming552 committed Dec 6, 2013
1 parent 53eddfc commit 9a05477
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
16 changes: 15 additions & 1 deletion lib/Lacuna/AI.pm
Expand Up @@ -465,12 +465,26 @@ sub set_defenders {
say 'SET DEFENDERS';
my $local_spies = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({from_body_id => $colony->id, on_body_id => $colony->id});
my $on_sweep = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({from_body_id => $colony->id, on_body_id => $colony->id, task => "Security Sweep"})->count;
my $enemies = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({on_body_id => $colony->id, task => { '!=' => 'Captured'}, empire_id => { '!=' => $self->empire_id }})->count;
$on_sweep = 10 if ($enemies == 0);
while (my $spy = $local_spies->next) {
if ($spy->is_available) {
if ($spy->task eq 'Security Sweep' or $on_sweep < 10) {
say " Spy ID: ".$spy->id." sweeping";
$spy->assign('Security Sweep');
my $spy_result = $spy->assign('Security Sweep');
$spy->update;
if ($spy_result->{message_id}) {
my $message = Lacuna->db->resultset('Lacuna::DB::Result::Message')->find($spy_result->{message_id});
say "message: ".$message->subject;
if ($message && $message->subject eq "Spy Report") {
$on_sweep += 10; #No spies to find
say " spy report, no more sweeps.";
}
elsif ($message && $message->subject eq "Enemy Captured") {
$on_sweep--;
say " caught someone, more sweeps.";
}
}
$on_sweep++;
}
elsif ($spy->task ne 'Counter Espionage') {
Expand Down
14 changes: 9 additions & 5 deletions lib/Lacuna/AI/Saben.pm
Expand Up @@ -145,14 +145,16 @@ sub run_hourly_colony_updates {
sub destroy_world {
my ($self, $colony) = @_;
say "Looking for world to destroy...";
my $target = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->search({
my $targets = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->search({
zone => $colony->zone,
size => { between => [46, 75] },
empire_id => undef,
},
{ rows => 1}
)->single;
if (defined $target) {
{ rows => 20}
);
my $blownup = 0;
while (my $target = $targets->next) {
next if $target->is_bhg_neutralized;
say "Found ".$target->name;
my @to_demolish = @{$target->building_cache};
$target->delete_buildings(\@to_demolish);
Expand All @@ -163,8 +165,10 @@ sub destroy_world {
});
say "Turned into ".$target->class;
$colony->add_news(100, 'We are Sābēn. We have destroyed '.$target->name.'. Leave now.');
$blownup = 1;
last;
}
else {
if ($blownup == 0) {
say "Nothing to destroy.";
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Lacuna/DB/Result/Spies.pm
Expand Up @@ -963,15 +963,15 @@ sub get_idle_attacker {
$member_ids[0] = $self->empire->id;
}

my @attackers = Lacuna
->db
->resultset('Spies')
my $db = Lacuna->db;
my $dtf = $db->storage->datetime_parser;
my @attackers = $db->resultset('Spies')
->search(
{ on_body_id => $self->on_body_id,
task => 'Idle',
empire_id => { 'not in' => \@member_ids },
# Any non-allied spy that calls home the NZ
started_assignment => { '<' => DateTime->now->subtract(days => 7) } },
started_assignment => { '<' => $dtf->format_datetime(DateTime->now->subtract(days => 7)) } },
)
->all;

Expand Down

0 comments on commit 9a05477

Please sign in to comment.