From 0230d79328171fd89fe7676417530d68deb5251a Mon Sep 17 00:00:00 2001 From: lemming552 Date: Wed, 7 Nov 2012 20:04:55 -0700 Subject: [PATCH 1/2] Check for too many spies nightly. --- bin/run_daily.sh | 2 +- lib/Lacuna/DB/Result/Building/IntelTraining.pm | 4 ++-- lib/Lacuna/DB/Result/Building/MayhemTraining.pm | 4 ++-- lib/Lacuna/DB/Result/Building/PoliticsTraining.pm | 4 ++-- lib/Lacuna/DB/Result/Building/TheftTraining.pm | 4 ++-- var/upgrades/3.0873.sql | 3 +++ 6 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 var/upgrades/3.0873.sql diff --git a/bin/run_daily.sh b/bin/run_daily.sh index 2d73324e..b469f947 100755 --- a/bin/run_daily.sh +++ b/bin/run_daily.sh @@ -9,4 +9,4 @@ perl diablotin/send_attack.pl& perl saben/send_attack.pl& perl clean_up_mail.pl perl record_rpc.pl - +perl util/check_spy_count.pl & diff --git a/lib/Lacuna/DB/Result/Building/IntelTraining.pm b/lib/Lacuna/DB/Result/Building/IntelTraining.pm index 8c2b65f9..74b8e2b8 100644 --- a/lib/Lacuna/DB/Result/Building/IntelTraining.pm +++ b/lib/Lacuna/DB/Result/Building/IntelTraining.pm @@ -102,7 +102,7 @@ sub training_costs { }; if ($spy_id) { my $spy = $self->get_spy($spy_id); - my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/200)+1; + my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100)+1; my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100)); if ($self->body->happiness < 0) { @@ -116,7 +116,7 @@ sub training_costs { else { my $spies = $self->get_spies->search({ task => { in => ['Counter Espionage','Idle'] } }); while (my $spy = $spies->next) { - my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/200)+1; + my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100)+1; my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100)); if ($self->body->happiness < 0) { diff --git a/lib/Lacuna/DB/Result/Building/MayhemTraining.pm b/lib/Lacuna/DB/Result/Building/MayhemTraining.pm index c261685b..de979750 100644 --- a/lib/Lacuna/DB/Result/Building/MayhemTraining.pm +++ b/lib/Lacuna/DB/Result/Building/MayhemTraining.pm @@ -105,7 +105,7 @@ sub training_costs { }; if ($spy_id) { my $spy = $self->get_spy($spy_id); - my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/200) + 1; + my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100) + 1; my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100)); if ($self->body->happiness < 0) { my $unhappy_workers = abs($self->body->happiness)/100_000; @@ -118,7 +118,7 @@ sub training_costs { else { my $spies = $self->get_spies->search({ task => { in => ['Counter Espionage','Idle'] } }); while (my $spy = $spies->next) { - my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/200) + 1; + my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100) + 1; my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100)); if ($self->body->happiness < 0) { my $unhappy_workers = abs($self->body->happiness)/100_000; diff --git a/lib/Lacuna/DB/Result/Building/PoliticsTraining.pm b/lib/Lacuna/DB/Result/Building/PoliticsTraining.pm index 1ecebc2f..70b0e22a 100644 --- a/lib/Lacuna/DB/Result/Building/PoliticsTraining.pm +++ b/lib/Lacuna/DB/Result/Building/PoliticsTraining.pm @@ -102,7 +102,7 @@ sub training_costs { }; if ($spy_id) { my $spy = $self->get_spy($spy_id); - my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/200) + 1; + my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100) + 1; my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100)); if ($self->body->happiness < 0) { my $unhappy_workers = abs($self->body->happiness)/100_000; @@ -115,7 +115,7 @@ sub training_costs { else { my $spies = $self->get_spies->search({ task => { in => ['Counter Espionage','Idle'] } }); while (my $spy = $spies->next) { - my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/200) + 1; + my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100) + 1; my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100)); if ($self->body->happiness < 0) { my $unhappy_workers = abs($self->body->happiness)/100_000; diff --git a/lib/Lacuna/DB/Result/Building/TheftTraining.pm b/lib/Lacuna/DB/Result/Building/TheftTraining.pm index 65816aea..432c2f64 100644 --- a/lib/Lacuna/DB/Result/Building/TheftTraining.pm +++ b/lib/Lacuna/DB/Result/Building/TheftTraining.pm @@ -102,7 +102,7 @@ sub training_costs { }; if ($spy_id) { my $spy = $self->get_spy($spy_id); - my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/200) + 1; + my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100) + 1; my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100)); if ($self->body->happiness < 0) { my $unhappy_workers = abs($self->body->happiness)/100_000; @@ -115,7 +115,7 @@ sub training_costs { else { my $spies = $self->get_spies->search({ task => { in => ['Counter Espionage','Idle'] } }); while (my $spy = $spies->next) { - my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/200) + 1; + my $xp_level = int(($spy->intel_xp + $spy->mayhem_xp + $spy->politics_xp + $spy->theft_xp)/100) + 1; my $train_time = sprintf('%.0f', 3600 * $xp_level * ((100 - (5 * $self->body->empire->management_affinity)) / 100)); if ($self->body->happiness < 0) { my $unhappy_workers = abs($self->body->happiness)/100_000; diff --git a/var/upgrades/3.0873.sql b/var/upgrades/3.0873.sql new file mode 100644 index 00000000..4388b1a0 --- /dev/null +++ b/var/upgrades/3.0873.sql @@ -0,0 +1,3 @@ +alter table body add column `depression` datetime NOT NULL default '2012-11-10 04:00:00'; +alter table body add column `depressed` datetime NOT NULL default '2012-11-10 04:00:00'; +alter table spies add column next_task varchar(30) NOT NULL defualt 'Idle'; -- 2.54.0 From 912b955d6ee918dae51d247eb145b14d3b8c6584 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Fri, 9 Nov 2012 20:13:39 -0700 Subject: [PATCH 2/2] System Moving. --- lib/Lacuna/AI/Saben.pm | 2 +- lib/Lacuna/DB/Result/Spies.pm | 4 +- lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 221 +++++++++++++++--- var/messages/planet_moved.txt | 8 + var/www/public/changes.txt | 2 +- 5 files changed, 204 insertions(+), 33 deletions(-) create mode 100644 var/messages/planet_moved.txt diff --git a/lib/Lacuna/AI/Saben.pm b/lib/Lacuna/AI/Saben.pm index 0523da3e..09b6ddd0 100644 --- a/lib/Lacuna/AI/Saben.pm +++ b/lib/Lacuna/AI/Saben.pm @@ -130,7 +130,7 @@ sub destroy_world { my @to_demolish = @{$target->building_cache}; $target->delete_buildings(\@to_demolish); $target->update({ - class => 'Lacuna::DB::Result::Map::Body::Asteroid::A'.randint(1,21), + class => 'Lacuna::DB::Result::Map::Body::Asteroid::A'.randint(1,Lacuna::DB::Result::Map::Body->asteroid_types), size => randint(1,10), usable_as_starter_enabled => 0, }); diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index ca7c8469..77aa5ecf 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -802,7 +802,9 @@ sub get_idle_attacker { ->resultset('Lacuna::DB::Result::Spies') ->search( { on_body_id => $self->on_body_id, - task => 'Idle', empire_id => { 'not in' => \@member_ids }, + task => 'Idle', + empire_id => { 'not in' => \@member_ids }, +# Any non-allied spy that calls home the NZ started_assignment => { '<' => DateTime->now->subtract(days => 7) } }, ) ->all; diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index 1595f8cb..e448f1e2 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -217,12 +217,22 @@ sub task_chance { my ($tz_x, $tz_y) = $tzone =~ m/(-?\d+)\|(-?\d+)/; $dist = sprintf "%0.2f", sqrt( ($sz_x - $tz_x)**2 + ($sz_y - $tz_y)**2); $target_id = $target->id; - $target_type = 'zone'; + if ($target->isa('Lacuna::DB::Result::Map::Star')) { + $target_type = 'star'; + } + else { + $target_type = 'zone'; + } } elsif ($task->{name} eq "Move System") { $dist = sprintf "%0.2f", $building->body->calculate_distance_to_target($target)/100; $target_id = $target->id; - $target_type = 'star'; + if ($target->isa('Lacuna::DB::Result::Map::Star')) { + $target_type = 'star'; + } + else { + $target_type = $target->get_type; + } } elsif (ref $target eq 'HASH') { my $bx = $building->body->x; @@ -234,7 +244,12 @@ sub task_chance { else { $dist = sprintf "%0.2f", $building->body->calculate_distance_to_target($target)/100; $target_id = $target->id; - $target_type = $target->get_type; + if ($target->isa('Lacuna::DB::Result::Map::Star')) { + $target_type = 'star'; + } + else { + $target_type = $target->get_type; + } } my $range = $task->{range}; my $return = { @@ -314,10 +329,6 @@ sub generate_singularity { confess [1002, 'Could not find task: '.$task_name]; } my $chance = task_chance($building, $target, $task); - if ($task->{name} eq "Move System") { - $chance->{throw} = 552; - $chance->{reason} = "Not ready yet"; - } if ($chance->{throw} > 0) { confess [ $chance->{throw}, $chance->{reason} ]; } @@ -345,12 +356,18 @@ sub generate_singularity { $tid = $target->{id}; } else { - $btype = $target->get_type; - $tstar = $target->star; - $tid = $target->id; - if (defined($target->empire)) { - $tempire = $target->empire; + if ($target->isa('Lacuna::DB::Result::Map::Star')) { + $btype = 'star'; + $tstar = $target; + } + else { + $btype = $target->get_type; + $tstar = $target->star; + if (defined($target->empire)) { + $tempire = $target->empire; + } } + $tid = $target->id; } unless ($body->waste_stored >= $task->{waste_cost}) { confess [1011, 'You need at least '.$task->{waste_cost}.' waste to run that function of the Black Hole Generator.']; @@ -419,7 +436,7 @@ sub generate_singularity { } else { $confess = 'Only '.$tstar->station->alliance->name. - ' members can colonize planets in the jurisdiction of the space station.'; + ' members can colonize planets in the jurisdiction of that space station.'; } } else { @@ -434,6 +451,18 @@ sub generate_singularity { confess [ 1010, $confess ]; } } + elsif ( $task->{name} eq 'Move System' ) { + unless ($target->isa('Lacuna::DB::Result::Map::Star')) { + confess [1009, "You can not attempt that action on non-stars!\n"]; + } + if ($target->station_id) { + unless ($body->empire->alliance_id && $target->station->alliance_id == $body->empire->alliance_id) { + confess [1009, 'That star system is claimed by '.$tstar->station->alliance->name.'.\n']; + } + } +# Let's check all planets in our system and target system + qualify_moving_sys($building, $target); + } $body->spend_waste($task->{waste_cost})->update; $building->start_work({}, $task->{recovery})->update; @@ -504,7 +533,7 @@ sub generate_singularity { $body->add_news(50, sprintf('The geology of %s has been extensively altered by powers unknown', $target->name)); } elsif ($task->{name} eq "Jump Zone") { - $return_stats = bhg_swap($building, $target); + $return_stats = bhg_swap($building->body, $target); $return_stats->{message} = "Jumped Zone", my $tname; if (ref $target eq 'HASH') { @@ -518,7 +547,7 @@ sub generate_singularity { $body->name, $tname)); } elsif ($task->{name} eq "Swap Places") { - $return_stats = bhg_swap($building, $target); + $return_stats = bhg_swap($building->body, $target); my $tname; if (ref $target eq 'HASH') { $tname = $target->{name}; @@ -531,7 +560,10 @@ sub generate_singularity { $body->name, $tname)); } elsif ($task->{name} eq "Move System") { - confess [552, "Internal Error"]; + $return_stats = bhg_move_system($building, $target); + $body->add_news(50, + sprintf('Astromers are perplexed about the change of the orbiting bodies around %s.', + $target->name)); } else { confess [552, "Internal Error"]; @@ -556,6 +588,7 @@ sub generate_singularity { elsif ($side_type < 95) { $return_stats = bhg_random_decor($building); } +# More side effects (Create some fissures for instance...) else { $return_stats = bhg_size($building, $body, 0); } @@ -573,14 +606,115 @@ sub generate_singularity { }; } -sub bhg_system_swap { - my ($body, $target) = @_; +sub qualify_moving_sys { + my ($building, $target_star) = @_; + my $current_body = $building->body; + my $current_star = $current_body->star; + my $current_empire = $current_body->empire; + my $ceid = $current_empire->id; + my $caid = $current_empire->alliance_id; + + my $bodies = Lacuna->db->resultset('Map::Body')->search({star_id => [ $current_star->id, $target_star->id]}); + + while (my $body = $bodies->next) { + if (defined($body->empire)) { + my $body_empire = $body->empire; + unless ($body_empire->id == $ceid) { + unless ((defined($caid) and defined($body_empire->alliance_id)) and + ($caid == $body_empire->alliance_id)) { + confess [1009, 'You can only move your own alliance member bodies.']; + } + } + } + } + return 1; +} + +sub bhg_move_system { + my ($building, $target_star) = @_; + my $current_body = $building->body; + my $current_star = $current_body->star; + + my $current_bodies = make_orbit_array($current_star); + my $target_bodies = make_orbit_array($target_star); + + my $return_stats = {}; + my @orbiting; + for my $orbit (1..8) { + my $return; + if ($current_bodies->[$orbit] and $target_bodies->[$orbit]) { + $return = bhg_swap($current_bodies->[$orbit], $target_bodies->[$orbit]); + } + elsif ($current_bodies->[$orbit] and !($target_bodies->[$orbit])) { + my $targeted = target_orbit($target_star, $orbit); + $return = bhg_swap($current_bodies->[$orbit], $targeted); + } + elsif (!($current_bodies->[$orbit]) and $target_bodies->[$orbit]) { + my $targeted = target_orbit($current_star, $orbit); + $return = bhg_swap($target_bodies->[$orbit], $targeted); + } + else { + $return = { + id => 0, + message => "Swapped Places", + name => "Empty Orbit", + orbit => $orbit, + }; + } + push @orbiting, $return; + } + return { + id => $target_star->id, + message => "Moved System", + name => $target_star->name, + orbits => \@orbiting, + swapname => $current_star->name, + swapid => $current_star->id, + }; +} + +sub target_orbit { + my ($star, $orbit) = @_; + + my $x = $star->x; + my $y = $star->y; + my $offset = [ + [ $x + 1, $y + 2 ], + [ $x + 2, $y + 1 ], + [ $x + 2, $y - 1 ], + [ $x + 1, $y - 2 ], + [ $x - 1, $y - 2 ], + [ $x - 2, $y - 1 ], + [ $x - 2, $y + 1 ], + [ $x - 1, $y + 2 ], + ]; + my $target = { + id => 0, + name => "Empty Space", + orbit => $orbit, + type => 'empty', + x => $offset->[$orbit]->[0], + y => $offset->[$orbit]->[1], + zone => $star->zone, + star => $star, + star_id => $star->id, + }; + return $target; +} + +sub make_orbit_array { + my ($star) = @_; + my $bodies = Lacuna->db->resultset('Map::Body')->search({star_id => $star->id}); + my @orbits; + while (my $body = $bodies->next) { + $orbits[$body->orbit] = $body; + } + return \@orbits; } sub bhg_swap { # Needs to make sure SS have influence range redone. - my ($building, $target) = @_; - my $body = $building->body; + my ($body, $target) = @_; my $return; my $old_data = { x => $body->x, @@ -644,18 +778,45 @@ sub bhg_swap { } $target->recalc_chains; # Recalc all chains } + if (defined($target->empire)) { + $target->empire->send_predefined_message( + tags => ['Alert'], + filename => 'planet_moved.txt', + params => [$target->x, + $target->y, + $target->orbit, + $target->star->x, + $target->star->y, + $target->star->name, + ], + ); + } } - - my $waste_chain = Lacuna->db->resultset('Lacuna::DB::Result::WasteChain') - ->search({ planet_id => $body->id }); - if ($waste_chain->count > 0) { - while (my $chain = $waste_chain->next) { - $chain->update({ - star_id => $new_data->{star_id} - }); + if ($body->get_type ne 'asteroid') { + my $waste_chain = Lacuna->db->resultset('Lacuna::DB::Result::WasteChain') + ->search({ planet_id => $body->id }); + if ($waste_chain->count > 0) { + while (my $chain = $waste_chain->next) { + $chain->update({ + star_id => $new_data->{star_id} + }); + } } + $body->recalc_chains; # Recalc all chains + } + if (defined($body->empire)) { + $body->empire->send_predefined_message( + tags => ['Alert'], + filename => 'planet_moved.txt', + params => [$body->x, + $body->y, + $body->orbit, + $body->star->x, + $body->star->y, + $body->star->name, + ], + ); } - $body->recalc_chains; # Recalc all chains return { id => $body->id, @@ -1282,7 +1443,7 @@ sub bhg_tasks { { name => 'Swap Places', types => ['asteroid', 'habitable planet', 'gas giant', 'space station', 'empty'], - reason => "All targets.", + reason => "Bodies and empty orbits as targets.", occupied => 1, min_level => 30, range => 10 * $building->level, diff --git a/var/messages/planet_moved.txt b/var/messages/planet_moved.txt new file mode 100644 index 00000000..21c29ce6 --- /dev/null +++ b/var/messages/planet_moved.txt @@ -0,0 +1,8 @@ +We have moved! +~~~ +A blackhole generator must have moved us to %s/%s in orbit %s around {Starmap %s %s %s}. + + +Regards, + +Your Humble Assistant diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 03b32ad2..f3248715 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -9,7 +9,7 @@ - Mod: Captcha not needed for sending spies to your own planets. - Fix: Happiness initialized to zero on new colonies. - Add: BHG can now jump a body to a different zone. - - Add: BHG can exchange an entire system of bodies with another system. (Not functional yet) + - Add: BHG can exchange an entire system of bodies with another system. 3.0872: - Fix: Spies need working infrastructure. -- 2.54.0