Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #112

Merged
merged 2 commits into from Oct 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 26 additions & 4 deletions bin/util/normalize_spies.pl
Expand Up @@ -39,10 +39,18 @@
my $emp_bodies = $bodies->search({empire_id=>$empire->id});
my $total_allowed_spies = 0;
my $total_spies = 0;
my $int_min_stat = {};
while (my $body = $emp_bodies->next) {
my $bid = $body->id;
my $int_min = $body->get_building_of_class('Lacuna::DB::Result::Building::Intelligence');
$total_allowed_spies += $int_min->max_spies if (defined($int_min));
$total_spies += $int_min->spy_count if (defined($int_min));
if (defined($int_min)) {
$total_allowed_spies += $int_min->max_spies;
$total_spies += $int_min->spy_count;
$int_min_stat->{$bid} = {
max_spies => $int_min->max_spies,
cur_spies => 0,
};
}
}
out($empire->name.' limited to '.$total_allowed_spies.' of '.$total_spies);
my $excess = {
Expand All @@ -53,7 +61,7 @@
};
my $count = 0;
while (my $spy = $emp_spies->next) {
if ($count++ <= $total_allowed_spies) {
if ($count++ < $total_allowed_spies) {
my $tot_excess = 0;
my @spread;
for my $type (qw(intel mayhem politics theft)) {
Expand Down Expand Up @@ -107,7 +115,7 @@
else {
$spy->update({
task => 'Retiring',
defense_mission_count => 150,
# defense_mission_count => 150,
available_on => DateTime->now->add(days => 14),
});
for my $type (qw(intel mayhem politics theft)) {
Expand All @@ -132,6 +140,20 @@
$excess->{$type} -= $room;
$spy->$arg($room + $curxp);
}
my $home_id = $spy->from_body_id;
if ($int_min_stat->{$home_id}->{cur_spies} < $int_min_stat->{$home_id}->{max_spies}) {
$int_min_stat->{$home_id}->{cur_spies}++;
}
else {
for my $bid (keys %{$int_min_stat}) {
if ($int_min_stat->{$bid}->{cur_spies} < $int_min_stat->{$bid}->{max_spies}) {
$int_min_stat->{$bid}->{cur_spies}++;
$spy->from_body_id($bid);
last;
}
}
}

$spy->update_level;
$spy->update;
}
Expand Down
90 changes: 86 additions & 4 deletions lib/Lacuna/DB/Result/Spies.pm
Expand Up @@ -243,7 +243,9 @@ sub get_possible_assignments {
}
# In or from the Neutral Area, defense only
elsif ($self->on_body->in_neutral_area or $self->from_body->in_neutral_area) {
push @assignments, $self->defensive_assignments;
if ($self->on_body->empire->alliance_id && $self->on_body->empire->alliance_id == $self->from_body->empire->alliance_id) {
push @assignments, $self->defensive_assignments;
}
}

# at allies you can defend and attack
Expand Down Expand Up @@ -488,7 +490,7 @@ has home_field_advantage => (
my $div = 2;
if ($body->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) {
$building = 'Module::PoliceStation';
$div = 1;
$div = 1;
}
my $hq = $body->get_building_of_class('Lacuna::DB::Result::Building::'.$building);
if (defined $hq) {
Expand Down Expand Up @@ -1266,6 +1268,8 @@ sub sabotage_resources {
when (5) { return $self->destroy_resources(@_) }
when (6) { return $self->destroy_plan(@_) }
when (7) { return $self->destroy_glyph(@_) }
when (8) { return $self->destroy_chain_ship(@_) }
when (9) { return $self->destroy_excavator(@_) }
}
}

Expand Down Expand Up @@ -1877,7 +1881,8 @@ sub destroy_infrastructure {
my ($building) = sort {rand() <=> rand()} grep {$_->efficiency > 0} @{$self->on_body->building_cache};

return $self->building_not_found->id unless defined $building;
return $self->building_not_found->id if ($building->class eq 'Lacuna::DB::Result::PlanetaryCommand');
return $self->building_not_found->id if ($building->class eq 'Lacuna::DB::Result::Building::PlanetaryCommand' or
$building->class eq 'Lacuna::DB::Result::Building::Module::StationCommand');

$self->on_body->empire->send_predefined_message(
tags => ['Spies','Alert'],
Expand Down Expand Up @@ -2032,6 +2037,44 @@ sub destroy_resources {
return $message->id;
}

sub destroy_chain_ship {
my ($self, $defender) = @_;
my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search(
{body_id => $self->on_body->id,
task => {'in' => ['Supply Chain', 'Waste Chain'] },
{ rows => 1, order_by => 'rand()' }
)->single;
return $self->ship_not_found->id unless $ship;
my $stype = "supply chain";
if ($ship->task eq "Waste Chain") {
$stype = "waste chain";
}
$ship->delete;
$self->on_body->recalc_chains;
$self->on_body->empire->send_predefined_message(
tags => ['Spies','Alert'],
filename => 'ship_blew_up_at_port.txt',
params => [$stype.' '.$ship->type_formatted,
$self->on_body->id,
$self->on_body->name],
);
$self->things_destroyed( $self->things_destroyed + 1 );
$self->on_body->add_news(90,
'Today, officials on %s are investigating the explosion of a %s ship at the Space Port.',
$self->on_body->name, $stype);
return $self->empire->send_predefined_message(
tags => ['Intelligence'],
filename => 'sabotage_report.txt',
params => [$stype.' ship',
$self->on_body->x,
$self->on_body->y,
$self->on_body->name,
$self->name,
$self->from_body->id,
$self->from_body->name],
)->id;
}

sub destroy_mining_ship {
my ($self, $defender) = @_;
my $ministry = $self->on_body->mining_ministry;
Expand Down Expand Up @@ -2376,11 +2419,14 @@ sub thwart_thief {
sub shut_down_building {
my ($self, $defender) = @_;
my @classnames = (
'Lacuna::DB::Result::Building::Archaeology',
'Lacuna::DB::Result::Building::Shipyard',
'Lacuna::DB::Result::Building::Park',
'Lacuna::DB::Result::Building::Waste::Recycling',
'Lacuna::DB::Result::Building::Development',
'Lacuna::DB::Result::Building::Intelligence',
'Lacuna::DB::Result::Building::Observatory',
'Lacuna::DB::Result::Building::SAW',
'Lacuna::DB::Result::Building::Trade',
'Lacuna::DB::Result::Building::Transporter',
);
Expand Down Expand Up @@ -2447,6 +2493,40 @@ sub take_control_of_probe {
return $message->id;
}

sub destroy_excavator {
my $arch = $self->on_body->archaeology;
return $self->building_not_found->id unless defined $arch;
my $excavator = Lacuna->db
->resultset('Lacuna::DB::Result::Excavators')
->search({planet_id => $self->on_body->id},
{ rows => 1, order_by => 'rand()' }
)->single;
return $self->mission_objective_not_found('excavator')->id unless defined $excavator;
my $body = $excavator->body;
return $self->mission_objective_not_found('excavator')->id unless defined $body;
$arch->remove_excavator($excavator);
$self->on_body->empire->send_predefined_message(
tags => ['Spies','Alert'],
filename => 'we_lost_contact_with_an_excavator.txt',
params => [$body->x, $body->y, $body->name],
);
$self->things_destroyed( $self->things_destroyed + 1 );
$self->on_body->add_news(50,
'The %s excavator on %s exploded.',
$self->on_body->empire->name,
$asteroid->name);
return $self->empire->send_predefined_message(
tags => ['Intelligence'],
filename => 'we_disabled_an_excavator.txt',
params => [$asteroid->x,
$asteroid->y,
$asteroid->name,
$self->on_body->empire->id,
$self->on_body->empire->name,
$self->format_from],
)->id;
}

sub kill_contact_with_mining_platform {
my ($self, $defender) = @_;
my $ministry = $self->on_body->mining_ministry;
Expand Down Expand Up @@ -2663,7 +2743,9 @@ sub spy_report {
unless (exists $planets{$spook->from_body_id}) {
$planets{$spook->from_body_id} = $spook->from_body->name;
}
push @peeps, [$spook->name, $planets{$spook->from_body_id}, $spook->task, $spook->level];
unless ($spook->task eq 'Travelling') {
push @peeps, [$spook->name, $planets{$spook->from_body_id}, $spook->task, $spook->level];
}
}
unless (scalar @peeps > 1) {
$peeps[0] = ["No", "Enemy", "Spies", "Found" ];
Expand Down
8 changes: 8 additions & 0 deletions var/messages/we_disabled_an_excavator.txt
@@ -0,0 +1,8 @@
Excavator Disabled
~~~
We have destroyed an excavator on {Starmap %s %s %s}, which was controlled by {Empire %s %s}.

More to come,

%s

7 changes: 7 additions & 0 deletions var/messages/we_lost_contact_with_an_excavator.txt
@@ -0,0 +1,7 @@
Excavator Lost
~~~
I'm sorry to say we have lost contact with the excavator on {Starmap %s %s %s}. Our technicians do not believe this is a recoverable situation.

Regards,

Your Humble Assistant