From cfbdc10fd86003e4a74f4551990721b3407e73c0 Mon Sep 17 00:00:00 2001 From: Mark Lemming Date: Wed, 25 Dec 2013 19:05:57 -0700 Subject: [PATCH] db0 fix, xmas2013 giveaway and a more robust swap. --- bin/util/christmas_2013.pl | 89 +++++++++++++++++++ bin/util/swap_bodies.pl | 14 ++- lib/Lacuna/DB/Result/Spies.pm | 8 ++ lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 14 ++- 4 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 bin/util/christmas_2013.pl diff --git a/bin/util/christmas_2013.pl b/bin/util/christmas_2013.pl new file mode 100644 index 00000000..5d33cc28 --- /dev/null +++ b/bin/util/christmas_2013.pl @@ -0,0 +1,89 @@ +use 5.010; +use strict; +use lib '/data/Lacuna-Server/lib'; +use Lacuna::DB; +use Lacuna; +use Lacuna::Util qw(randint format_date); +use Getopt::Long; +$|=1; +our $quiet; +our $all; +GetOptions( + 'quiet' => \$quiet, + 'all' => \$all, +); + + +out('Started'); +my $start = time; + +out('Loading DB'); +our $db = Lacuna->db; +my $empires = $db->resultset('Empire'); + +my $lec = $empires->find(1); + +if (not $all) { + $empires = $empires->search({ is_admin => 1 }); +} + +$empires = $empires->search({ id => {'>' => 1}}); + +my $message = q{As what your Species calls 'Christmas' has arrived, it seems that it +is now traditional to send gifts to each other at this time. + +In order to foster good will between all species we have taken the liberty of sending you +two plans for Sub Space Depots and a special gift. + +How you use these is up to you. You may use them yourselves, perhaps on one of your new +colonies. Some of the more mature species may decide that at your level of technology +you have little use for them yourselves, in which case you may wish to extend the +hand/tenticle/pseudopod (delete as appropriate) of friendship and share them with some of +the less developed empires. + +In any case, we wish you well for your next solar orbital period. + +Your Trading Partner, + +Tou Re Ell + +Lacuna Expanse Corp}; + +out('Sending Messages'); +while (my $empire = $empires->next) { + my $home = $empire->home_planet; + next unless defined $home; + out('Sending message to '.$empire->name.' on '.$home->name.'.'); + my $btype = $home->get_type; + unless ($btype eq 'habitable planet' or $btype eq 'gas giant') { + out('Home planet type is '.$btype.'! Skipping.'); + next; + } + $empire->send_message( + tag => 'Correspondence', + subject => 'A Gift.', + from => $lec, + body => $message, + ); + + $home->add_plan('Lacuna::DB::Result::Building::SubspaceSupplyDepot', 1, 0, 2); + $home->add_plan('Lacuna::DB::Result::Building::Permanent::KalavianRuins', 1, 7, 1); +} + +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; + } +} + + diff --git a/bin/util/swap_bodies.pl b/bin/util/swap_bodies.pl index 5edbc9ed..95e3c355 100644 --- a/bin/util/swap_bodies.pl +++ b/bin/util/swap_bodies.pl @@ -106,8 +106,6 @@ sub bhg_swap { }); } } - $target->recalc_chains; # Recalc all chains - recalc_incoming_supply($target); if ($new_data->{type} eq 'space station') { drop_stars_beyond_range($target); } @@ -151,8 +149,6 @@ sub bhg_swap { }); } } - $body->recalc_chains; # Recalc all chains - recalc_incoming_supply($body); if ($body->get_type eq 'space station') { drop_stars_beyond_range($body); } @@ -195,6 +191,16 @@ sub bhg_swap { ], ); } + unless ($new_data->{type} eq "empty" or $new_data->{type} eq 'asteroid') { + $target->recalc_chains; # Recalc all chains + recalc_incoming_supply($target); + } + if ($body->get_type ne 'asteroid') { + $body->recalc_chains; # Recalc all chains + recalc_incoming_supply($body); + } + $body->update({needs_recalc => 1}); + $target->update({needs_recalc => 1}); return { id => $body->id, diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 2fa69002..cd8609b3 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -807,6 +807,14 @@ sub run_political_propaganda { my $mission_skill = 'politics_xp'; my $oratory = int( ($self->defense + $self->$mission_skill)/500 + 0.5);; + if ($oratory < 1) { + return { result => 'Failure', + reason => random_element(['I have no idea what you mean.', + 'Gabba Gabba Hey!', + 'They\'re laughing at me!', + 'I have morale objections.']) }; + } + my $sboost = $self->on_body->spy_happy_boost; $sboost += $oratory; my $mission_count_add = int($sboost/$oratory); diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index df6387ee..023e1619 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -1225,8 +1225,6 @@ sub bhg_swap { }); } } - $target->recalc_chains; # Recalc all chains - recalc_incoming_supply($target); if ($new_data->{type} eq 'space station') { drop_stars_beyond_range($target); } @@ -1274,8 +1272,6 @@ sub bhg_swap { }); } } - $body->recalc_chains; # Recalc all chains - recalc_incoming_supply($body); if ($body->get_type eq 'space station') { drop_stars_beyond_range($body); } @@ -1322,6 +1318,16 @@ sub bhg_swap { ], ); } + unless ($new_data->{type} eq "empty" or $new_data->{type} eq 'asteroid') { + $target->recalc_chains; # Recalc all chains + recalc_incoming_supply($target); + } + if ($body->get_type ne 'asteroid') { + $body->recalc_chains; # Recalc all chains + recalc_incoming_supply($body); + } + $body->update({needs_recalc => 1}); + $target->update({needs_recalc => 1}); return { id => $body->id, -- 2.51.2