From cc03d018247cce9ebb3fa08806e579e2bbf36016 Mon Sep 17 00:00:00 2001 From: Iain C Docherty Date: Sun, 21 Apr 2013 09:04:14 -0400 Subject: [PATCH] Preparation before allowing the oracle to see planets in the starmap --- bin/saben/orig_send_attack.pl | 12 +-- bin/summarize_server.pl | 51 ++++++------ lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Alliance.pm | 9 +- lib/Lacuna/DB/Result/Building/Observatory.pm | 2 +- lib/Lacuna/DB/Result/Empire.pm | 87 +++++++++++--------- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 3 +- lib/Lacuna/DB/Result/Probes.pm | 1 + lib/Lacuna/DB/Result/Spies.pm | 83 ++++++++++--------- lib/Lacuna/DB/ResultSet/Probes.pm | 42 ++++++++++ lib/Lacuna/RPC/Building/Observatory.pm | 2 +- lib/Lacuna/RPC/Empire.pm | 32 +++---- lib/Lacuna/Role/Ship/Arrive/DeployProbe.pm | 4 +- lib/Lacuna/Role/Ship/Arrive/DestroyProbes.pm | 10 +-- t/380_Tutorial.t | 2 +- var/upgrades/3.0888.sql | 4 + var/www/public/changes.txt | 3 + 17 files changed, 209 insertions(+), 140 deletions(-) create mode 100644 lib/Lacuna/DB/ResultSet/Probes.pm create mode 100644 var/upgrades/3.0888.sql diff --git a/bin/saben/orig_send_attack.pl b/bin/saben/orig_send_attack.pl index 1d8a0c05..551a56ad 100644 --- a/bin/saben/orig_send_attack.pl +++ b/bin/saben/orig_send_attack.pl @@ -34,10 +34,10 @@ if ($randomize) { out('Loading DB'); our $db = Lacuna->db; -our $empires = $db->resultset('Lacuna::DB::Result::Empire'); -our $spies = $db->resultset('Lacuna::DB::Result::Spies'); -our $ships = $db->resultset('Lacuna::DB::Result::Ships'); -our $targets = $db->resultset('Lacuna::DB::Result::SabenTarget'); +our $empires = $db->resultset('Empire'); +our $spies = $db->resultset('Spies'); +our $ships = $db->resultset('Ships'); +our $targets = $db->resultset('SabenTarget'); my $config = Lacuna->config; out('getting empires...'); @@ -46,7 +46,7 @@ my $lec = $empires->find(1); unless ($skipnews) { out('Send Network 19 messages....'); - my $news = $db->resultset('Lacuna::DB::Result::News'); + my $news = $db->resultset('News'); my @messages = ( 'We are Sābēn. We have penetrated your defenses, and found them lacking. Goodbye.', 'We are Sābēn. We have studied you, and found your weaknesses. You do not have long.', @@ -118,7 +118,7 @@ sub start_attack { my ($saben_colony, $target_colony) = @_; out('Looking for probes...'); my $attack = AnyEvent->condvar; - my $count = $db->resultset('Lacuna::DB::Result::Probes')->search({ empire_id => -1, star_id => $target_colony->star_id })->count; + my $count = $db->resultset('Probes')->search_any({ empire_id => -1, star_id => $target_colony->star_id })->count; if ($count) { out('Has one at star already...'); my $timer = AnyEvent->timer( diff --git a/bin/summarize_server.pl b/bin/summarize_server.pl index 2ffab09b..e5571eca 100644 --- a/bin/summarize_server.pl +++ b/bin/summarize_server.pl @@ -47,14 +47,15 @@ exit; sub generate_overview { out('Generating Overview'); - my $stars = $db->resultset('Lacuna::DB::Result::Map::Star'); - my $bodies = $db->resultset('Lacuna::DB::Result::Map::Body'); + my $stars = $db->resultset('Map::Star'); + my $bodies = $db->resultset('Map::Body'); my @off_limits = $bodies->search({empire_id => {'<' => 2}})->get_column('id')->all; - my $ships = $db->resultset('Lacuna::DB::Result::Ships')->search({body_id => { 'not in' => \@off_limits}}); + my $ships = $db->resultset('Ships')->search({body_id => { 'not in' => \@off_limits}}); my $glyphs = $db->resultset('Glyph')->search({body_id => { 'not in' => \@off_limits}}); - my $buildings = $db->resultset('Lacuna::DB::Result::Building')->search({body_id => { 'not in' => \@off_limits}}); - my $empires = $db->resultset('Lacuna::DB::Result::Empire')->search({id => { '>' => 1}}); - my $probes = $db->resultset('Lacuna::DB::Result::Probes')->search({empire_id => { '>' => 1}}); + my $buildings = $db->resultset('Building')->search({body_id => { 'not in' => \@off_limits}}); + my $empires = $db->resultset('Empire')->search({id => { '>' => 1}}); + # Get all probes, either observatory or oracle + my $probes = $db->resultset('Probes')->search({empire_id => { '>' => 1} }); my $dtformatter = $db->storage->datetime_parser; # basics @@ -62,7 +63,9 @@ sub generate_overview { my %out = ( stars => { count => $stars->count, - probes_count => $probes->count, + # number of probes (observatory) + probes_count => $probes->search({virtual => 0})->count, + # number of probed stars (either observatory or oracle) probed_count => $probes->search(undef, { group_by => ['star_id'] })->count, seized_count => $stars->search({station_id => { '!=' => 'Null' }})->count, }, @@ -179,7 +182,7 @@ sub generate_overview { sub rank_colonies { out('Ranking Colonies'); - my $colonies = $db->resultset('Lacuna::DB::Result::Log::Colony'); + my $colonies = $db->resultset('Log::Colony'); foreach my $field (qw(population)) { my $ranked = $colonies->search(undef, {order_by => [ {-desc => $field}, 'rand()']}); my $counter = 1; @@ -191,7 +194,7 @@ sub rank_colonies { sub rank_empires { out('Ranking Empires'); - my $empires = $db->resultset('Lacuna::DB::Result::Log::Empire'); + my $empires = $db->resultset('Log::Empire'); foreach my $field (qw(empire_size university_level offense_success_rate defense_success_rate dirtiest)) { my $ranked = $empires->search(undef, {order_by => [ {-desc => $field}, 'rand()']}); my $counter = 1; @@ -203,7 +206,7 @@ sub rank_empires { sub rank_alliances { out('Ranking Alliances'); - my $alliances = $db->resultset('Lacuna::DB::Result::Log::Alliance'); + my $alliances = $db->resultset('Log::Alliance'); foreach my $field (qw(influence population space_station_count average_empire_size offense_success_rate defense_success_rate dirtiest)) { my $ranked = $alliances->search(undef, {order_by => [{-desc => $field},'rand()']}); my $counter = 1; @@ -216,16 +219,16 @@ sub rank_alliances { sub delete_old_records { out('Deleting old records'); my $start = shift; - $db->resultset('Lacuna::DB::Result::Log::Alliance')->search({date_stamp => { '<' => $start}})->delete; - $db->resultset('Lacuna::DB::Result::Log::Empire')->search({date_stamp => { '<' => $start}})->delete; - $db->resultset('Lacuna::DB::Result::Log::Colony')->search({date_stamp => { '<' => $start}})->delete; + $db->resultset('Log::Alliance')->search({date_stamp => { '<' => $start}})->delete; + $db->resultset('Log::Empire')->search({date_stamp => { '<' => $start}})->delete; + $db->resultset('Log::Colony')->search({date_stamp => { '<' => $start}})->delete; } sub summarize_alliances { out('Summarizing Alliances'); - my $logs = $db->resultset('Lacuna::DB::Result::Log::Alliance'); - my $alliances = $db->resultset('Lacuna::DB::Result::Alliance'); - my $empire_logs = $db->resultset('Lacuna::DB::Result::Log::Empire'); + my $logs = $db->resultset('Log::Alliance'); + my $alliances = $db->resultset('Alliance'); + my $empire_logs = $db->resultset('Log::Empire'); while (my $alliance = $alliances->next) { next if ! defined $alliance->leader_id; # until Alliances get deleted... out($alliance->name); @@ -276,9 +279,9 @@ sub summarize_alliances { sub summarize_empires { out('Summarizing Empires'); - my $logs = $db->resultset('Lacuna::DB::Result::Log::Empire'); - my $empires = $db->resultset('Lacuna::DB::Result::Empire')->search({ id => {'>' => 1} }); - my $colony_logs = $db->resultset('Lacuna::DB::Result::Log::Colony'); + my $logs = $db->resultset('Log::Empire'); + my $empires = $db->resultset('Empire')->search({ id => {'>' => 1} }); + my $colony_logs = $db->resultset('Log::Colony'); my %mapping; while (my $empire = $empires->next) { out($empire->name); @@ -374,7 +377,7 @@ sub summarize_empires { $logs->new(\%empire_data)->insert; } } - my $ai = $db->resultset('Lacuna::DB::Result::Empire')->search({ id => {'<' => 0} }); + my $ai = $db->resultset('Empire')->search({ id => {'<' => 0} }); out('Summarizing AI for map'); while (my $empire = $ai->next) { my %map_data = ( @@ -385,7 +388,7 @@ sub summarize_empires { home_id => $empire->home_planet_id, ); my @map_colonies; - my $colonies = $db->resultset('Lacuna::DB::Result::Map::Body')->search({ empire_id => $empire->id}); + my $colonies = $db->resultset('Map::Body')->search({ empire_id => $empire->id}); while ( my $colony = $colonies->next) { my %map_col = ( x => $colony->x, @@ -415,9 +418,9 @@ sub summarize_empires { sub summarize_colonies { out('Summarizing Planets'); - my $logs = $db->resultset('Lacuna::DB::Result::Log::Colony'); - my $planets = $db->resultset('Lacuna::DB::Result::Map::Body')->search({ empire_id => {'>' => 1} },{order_by => 'name'}); - my $spy_logs = $db->resultset('Lacuna::DB::Result::Log::Spies'); + my $logs = $db->resultset('Log::Colony'); + my $planets = $db->resultset('Map::Body')->search({ empire_id => {'>' => 1} },{order_by => 'name'}); + my $spy_logs = $db->resultset('Log::Spies'); while (my $planet = $planets->next) { out($planet->name); my $log = $logs->search({planet_id => $planet->id},{rows=>1})->single; diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index f757151c..88668fa9 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0887; +our $VERSION = 3.0888; 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}); diff --git a/lib/Lacuna/DB/Result/Alliance.pm b/lib/Lacuna/DB/Result/Alliance.pm index 72e8812e..c3124060 100644 --- a/lib/Lacuna/DB/Result/Alliance.pm +++ b/lib/Lacuna/DB/Result/Alliance.pm @@ -170,7 +170,7 @@ sub send_invite { elsif ($empire->alliance_id == $self->id) { confess [1010, 'Already a member of this alliance.'] } - my $invite = Lacuna->db->resultset('Lacuna::DB::Result::AllianceInvite')->new({ + my $invite = Lacuna->db->resultset('AllianceInvite')->new({ alliance_id => $self->id, empire_id => $empire->id, })->insert; @@ -214,8 +214,9 @@ sub add_member { } $empire->alliance_id($self->id); $empire->update; - Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search({empire_id => $empire->id})->update({alliance_id => $self->id}); - Lacuna->db->resultset('Lacuna::DB::Result::AllianceInvite')->search({empire_id => $empire->id})->delete; + # I has your probes! + Lacuna->db->resultset('Probes')->search({empire_id => $empire->id})->update({alliance_id => $self->id}); + Lacuna->db->resultset('AllianceInvite')->search({empire_id => $empire->id})->delete; return $self; } @@ -235,7 +236,7 @@ sub remove_member { } $empire->alliance_id(undef); $empire->update; - Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search({empire_id => $empire->id})->update({alliance_id => undef}); + Lacuna->db->resultset('Probes')->search({empire_id => $empire->id})->update({alliance_id => undef}); return $self; } diff --git a/lib/Lacuna/DB/Result/Building/Observatory.pm b/lib/Lacuna/DB/Result/Building/Observatory.pm index bee8e19e..5ecd124d 100644 --- a/lib/Lacuna/DB/Result/Building/Observatory.pm +++ b/lib/Lacuna/DB/Result/Building/Observatory.pm @@ -17,7 +17,7 @@ around 'build_tags' => sub { sub probes { my $self = shift; - return Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search( { body_id => $self->body_id } ); + return Lacuna->db->resultset('Probes')->search_observatory; } use constant controller_class => 'Lacuna::RPC::Building::Observatory'; diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 1f4c6db1..b67e4d37 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -99,18 +99,21 @@ sub sqlt_deploy_hook { } -__PACKAGE__->belongs_to('alliance', 'Lacuna::DB::Result::Alliance', 'alliance_id', { on_delete => 'set null' }); -__PACKAGE__->belongs_to('home_planet', 'Lacuna::DB::Result::Map::Body', 'home_planet_id'); -__PACKAGE__->has_many('spies', 'Lacuna::DB::Result::Spies', 'empire_id'); -__PACKAGE__->has_many('planets', 'Lacuna::DB::Result::Map::Body', 'empire_id'); -__PACKAGE__->has_many('propositions', 'Lacuna::DB::Result::Propositions', 'proposed_by_id'); -__PACKAGE__->has_many('votes', 'Lacuna::DB::Result::Votes', 'empire_id'); -__PACKAGE__->has_many('taxes', 'Lacuna::DB::Result::Taxes', 'empire_id'); -__PACKAGE__->has_many('sent_messages', 'Lacuna::DB::Result::Message', 'from_id'); -__PACKAGE__->has_many('received_messages', 'Lacuna::DB::Result::Message', 'to_id'); -__PACKAGE__->has_many('medals', 'Lacuna::DB::Result::Medals', 'empire_id'); -__PACKAGE__->has_many('probes', 'Lacuna::DB::Result::Probes', 'empire_id'); -__PACKAGE__->belongs_to('latest_message', 'Lacuna::DB::Result::Message', 'latest_message_id', { on_delete => 'set null' }); +__PACKAGE__->belongs_to('alliance', 'Lacuna::DB::Result::Alliance', 'alliance_id', { on_delete => 'set null' }); +__PACKAGE__->belongs_to('home_planet', 'Lacuna::DB::Result::Map::Body', 'home_planet_id'); +__PACKAGE__->belongs_to('latest_message', 'Lacuna::DB::Result::Message', 'latest_message_id', { on_delete => 'set null' }); + +__PACKAGE__->has_many('spies', 'Lacuna::DB::Result::Spies', 'empire_id'); +__PACKAGE__->has_many('planets', 'Lacuna::DB::Result::Map::Body', 'empire_id'); +__PACKAGE__->has_many('propositions', 'Lacuna::DB::Result::Propositions', 'proposed_by_id'); +__PACKAGE__->has_many('votes', 'Lacuna::DB::Result::Votes', 'empire_id'); +__PACKAGE__->has_many('taxes', 'Lacuna::DB::Result::Taxes', 'empire_id'); +__PACKAGE__->has_many('sent_messages', 'Lacuna::DB::Result::Message', 'from_id'); +__PACKAGE__->has_many('received_messages', 'Lacuna::DB::Result::Message', 'to_id'); +__PACKAGE__->has_many('medals', 'Lacuna::DB::Result::Medals', 'empire_id'); +__PACKAGE__->has_many('all_probes', 'Lacuna::DB::Result::Probes', 'empire_id'); +__PACKAGE__->has_many('observatory_probes', 'Lacuna::DB::Result::Probes', {'foreign.empire_id' => 'self.id' and 'self.virtual' => 0}); +__PACKAGE__->has_many('oracle_probes', 'Lacuna::DB::Result::Probes', {'foreign.empire_id' => 'self.id' and 'self.virtual' => 1}); sub self_destruct_date_formatted { my $self = shift; @@ -137,7 +140,7 @@ around name => sub { if (@_) { my $new_name = $_[0]; - Lacuna->db->resultset('Lacuna::DB::Result::Log::EmpireNameChange')->new({ + Lacuna->db->resultset('Log::EmpireNameChange')->new({ empire_id => $self->id, empire_name => $new_name, old_empire_name => $self->$orig, @@ -151,7 +154,7 @@ around update => sub { my ($orig, $self) = (shift, shift); if ( @_ && exists $_[0]->{name} ) { - Lacuna->db->resultset('Lacuna::DB::Result::Log::EmpireNameChange')->new({ + Lacuna->db->resultset('Log::EmpireNameChange')->new({ empire_id => $self->id, empire_name => $_[0]->{name}, old_empire_name => $self->name, @@ -184,7 +187,7 @@ sub update_species { sub determine_species_limits { my ($self) = @_; my @colony_ids = $self->planets->get_column('id')->all; - my $colonies = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->search({ empire_id => $self->id }); + my $colonies = Lacuna->db->resultset('Map::Body')->search({ empire_id => $self->id }); my $min_orbit = $colonies->get_column('orbit')->min; my $max_orbit = $colonies->get_column('orbit')->max; $max_orbit = 7 if $max_orbit > 7; @@ -229,7 +232,7 @@ sub get_species_stats { sub has_medal { my ($self, $type) = @_; - return Lacuna->db->resultset('Lacuna::DB::Result::Medals')->search({empire_id => $self->id, type => $type},{rows=>1})->single; + return Lacuna->db->resultset('Medals')->search({empire_id => $self->id, type => $type},{rows=>1})->single; } sub add_medal { @@ -240,7 +243,7 @@ sub add_medal { $medal->update; } else { - $medal = Lacuna->db->resultset('Lacuna::DB::Result::Medals')->new({ + $medal = Lacuna->db->resultset('Medals')->new({ datestamp => DateTime->now, public => 1, empire_id => $self->id, @@ -344,7 +347,7 @@ sub _adjust_essentia { $self->$type($residual); } } - Lacuna->db->resultset('Lacuna::DB::Result::Log::Essentia')->new({ + Lacuna->db->resultset('Log::Essentia')->new({ empire_id => $self->id, empire_name => $self->name, amount => $value, @@ -478,7 +481,7 @@ sub encrypt_password { sub attach_invite_code { my ($self, $invite_code) = @_; - my $invites = Lacuna->db->resultset('Lacuna::DB::Result::Invite'); + my $invites = Lacuna->db->resultset('Invite'); if (defined $invite_code && $invite_code ne '') { my $invite = $invites->search( {code => $invite_code }, @@ -621,7 +624,7 @@ sub found { $self->home_planet($home_planet); # weaken($self->{_relationship_data}{home_planet}); - $self->add_probe($home_planet->star_id, $home_planet->id); + $self->add_observatory_probe($home_planet->star_id, $home_planet->id); # found colony $home_planet->found_colony($self); @@ -636,7 +639,7 @@ sub found { sub find_home_planet { my ($self) = @_; - my $planets = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body'); + my $planets = Lacuna->db->resultset('Map::Body'); my %search = ( usable_as_starter_enabled => 1, orbit => { between => [ $self->min_orbit, $self->max_orbit] }, @@ -654,7 +657,7 @@ sub find_home_planet { } # determine search area - my $invite = Lacuna->db->resultset('Lacuna::DB::Result::Invite')->search({invitee_id => $self->id},{rows=>1})->single; + my $invite = Lacuna->db->resultset('Invite')->search({invitee_id => $self->id},{rows=>1})->single; if (defined $invite) { $search{zone} = $invite->zone; delete $search{x}; @@ -716,7 +719,7 @@ sub find_home_planet { sub get_invite_friend_url { my ($self) = @_; my $code = create_uuid_as_string(UUID_MD5, $self->id); - my $invites = Lacuna->db->resultset('Lacuna::DB::Result::Invite'); + my $invites = Lacuna->db->resultset('Invite'); my $invite = $invites->search({code => $code},{rows=>1})->single; unless (defined $invite) { $invites->new({ @@ -734,7 +737,7 @@ sub invite_friend { unless (Email::Valid->address($email)) { confess [1009, $email.' does not appear to be a valid email address.']; } - my $invites = Lacuna->db->resultset('Lacuna::DB::Result::Invite'); + my $invites = Lacuna->db->resultset('Invite'); if ($invites->search({email => $email, inviter_id => $self->id })->count) { confess [1009, 'You have already invited '.$email.'.']; } @@ -776,7 +779,7 @@ sub send_message { unless (ref $recipients eq 'ARRAY' && @{$recipients}) { push @{$recipients}, $self->name; } - my $message = Lacuna->db->resultset('Lacuna::DB::Result::Message')->new({ + my $message = Lacuna->db->resultset('Message')->new({ date_sent => DateTime->now, subject => $params{subject}, body => $params{body}, @@ -794,7 +797,7 @@ sub send_message { Lacuna->cache->set($params{repeat_check}, int(DateTime->now->hour / 6), 1, 60 * 60 * 6); } if (exists $params{in_reply_to} && defined $params{in_reply_to} && $params{in_reply_to} ne '') { - my $original = Lacuna->db->resultset('Lacuna::DB::Result::Message')->find($params{in_reply_to}); + my $original = Lacuna->db->resultset('Message')->find($params{in_reply_to}); if (defined $original && !$original->has_replied) { $original->update({has_replied=>1}); } @@ -841,24 +844,28 @@ sub send_predefined_message { sub lacuna_expanse_corp { my $self = shift; - return Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find(1); + return Lacuna->db->resultset('Empire')->find(1); } -sub add_probe { +# Add a 'real' probe. One sent from an observatory. +# +sub add_observatory_probe { my ($self, $star_id, $body_id) = @_; # add probe - Lacuna->db->resultset('Lacuna::DB::Result::Probes')->new({ + Lacuna->db->resultset('Probes')->new({ empire_id => $self->id, star_id => $star_id, body_id => $body_id, alliance_id => $self->alliance_id, + virtual => 0, })->insert; # send notifications # this could be a performance problem in the future depending upon the number of probes in a star system - my $star = Lacuna->db->resultset('Lacuna::DB::Result::Map::Star')->find($star_id); - my $probes = Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search({ star_id => $star_id, empire_id => {'!=', $self->id } }); + my $star = Lacuna->db->resultset('Map::Star')->find($star_id); + # Get all systems that are probed (real or virtual) + my $probes = Lacuna->db->resultset('Probes')->search_any({ star_id => $star_id, empire_id => {'!=', $self->id } }); while (my $probe = $probes->next) { my $that_empire = $probe->empire; next unless defined $that_empire; @@ -879,7 +886,7 @@ sub add_probe { sub next_colony_cost { my ($self, $adjustment) = @_; my $count = $self->planets->count + $adjustment; - $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search( + $count += Lacuna->db->resultset('Ships')->search( { type=> { in => [qw(colony_ship short_range_colony_ship space_station)]}, task=>'travelling', direction=>'out', 'body.empire_id' => $self->id}, { join => 'body' } )->count; @@ -891,6 +898,8 @@ sub next_colony_cost { return sprintf('%.0f', $tally); } +# Get all probes, either observatory or oracle +# has probed_stars => ( is => 'rw', clearer => 'clear_probed_stars', @@ -905,11 +914,13 @@ has probed_stars => ( alliance_id => $self->alliance_id, ); } - my @stars = Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search(\%search)->get_column('star_id')->all; + my @stars = Lacuna->db->resultset('Probes')->search_all(\%search)->get_column('star_id')->all; return \@stars; }, ); +# Get number of probed stars, either observatory or oracle +# has count_probed_stars => ( is => 'rw', lazy => 1, @@ -927,9 +938,9 @@ before delete => sub { $self->votes->delete_all; $self->taxes->delete_all; $self->propositions->delete_all; - Lacuna->db->resultset('Lacuna::DB::Result::Invite')->search({ -or => {invitee_id => $self->id, inviter_id => $self->id }})->delete; + Lacuna->db->resultset('Invite')->search({ -or => {invitee_id => $self->id, inviter_id => $self->id }})->delete; $self->probes->delete; - Lacuna->db->resultset('Lacuna::DB::Result::AllianceInvite')->search({empire_id => $self->id})->delete; + Lacuna->db->resultset('AllianceInvite')->search({empire_id => $self->id})->delete; if ($self->alliance_id) { my $alliance = $self->alliance; if (defined $alliance && $alliance->leader_id == $self->id) { @@ -943,7 +954,7 @@ before delete => sub { while ( my $planet = $planets->next ) { $planet->sanitize; } - my $essentia_log = Lacuna->db->resultset('Lacuna::DB::Result::Log::Essentia'); + my $essentia_log = Lacuna->db->resultset('Log::Essentia'); my $essentia_code; my $config = Lacuna->config; my $sum = $self->essentia - $essentia_log->search({empire_id => $self->id, description => 'tutorial' })->get_column('amount')->sum; @@ -1036,13 +1047,13 @@ sub redeem_essentia_code { sub pay_taxes { my ($self, $station_id, $amount) = @_; - my $taxes = Lacuna->db->resultset('Lacuna::DB::Result::Taxes')->search({empire_id=>$self->id,station_id=>$station_id})->single; + my $taxes = Lacuna->db->resultset('Taxes')->search({empire_id=>$self->id,station_id=>$station_id})->single; if (defined $taxes) { $taxes->{paid_0} += $amount; $taxes->update; } else { - Lacuna->db->resultset('Lacuna::DB::Result::Taxes')->new({ + Lacuna->db->resultset('Taxes')->new({ empire_id => $self->id, station_id => $station_id, paid_0 => $amount, diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index a25ff251..f53c5d28 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -301,7 +301,8 @@ sub sanitize { Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({from_body_id => $self->id})->delete_all; Lacuna->db->resultset('Lacuna::DB::Result::Market')->search({body_id => $self->id})->delete_all; Lacuna->db->resultset('Lacuna::DB::Result::MercenaryMarket')->search({body_id => $self->id})->delete_all; - Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search({body_id => $self->id})->delete; + # We will delete all probes (observatory or oracle), note, must recreate oracle probes if the planet is recolonised + Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search_any({body_id => $self->id})->delete; $self->empire_id(undef); if ($self->get_type eq 'habitable planet' && $self->size >= 40 && $self->size <= 50 && diff --git a/lib/Lacuna/DB/Result/Probes.pm b/lib/Lacuna/DB/Result/Probes.pm index 1669e39b..d7d48e01 100644 --- a/lib/Lacuna/DB/Result/Probes.pm +++ b/lib/Lacuna/DB/Result/Probes.pm @@ -13,6 +13,7 @@ __PACKAGE__->add_columns( star_id => { data_type => 'int', is_nullable => 0 }, body_id => { data_type => 'int', is_nullable => 0 }, alliance_id => { data_type => 'int', is_nullable => 1 }, + virtual => { data_type => 'int', is_nullable => 1, default => 0 }, ); __PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index cb755f77..252e715c 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -743,7 +743,7 @@ sub get_defender { my $defender = Lacuna ->db - ->resultset('Lacuna::DB::Result::Spies') + ->resultset('Spies') ->search( { on_body_id => $self->on_body_id, task => 'Counter Espionage', @@ -773,7 +773,7 @@ sub get_attacker { } my $attacker = Lacuna ->db - ->resultset('Lacuna::DB::Result::Spies') + ->resultset('Spies') ->search( { on_body_id => $self->on_body_id, task => { in => \@tasks }, empire_id => { 'not in' => \@member_ids } }, @@ -801,7 +801,7 @@ sub get_idle_attacker { my @attackers = Lacuna ->db - ->resultset('Lacuna::DB::Result::Spies') + ->resultset('Spies') ->search( { on_body_id => $self->on_body_id, task => 'Idle', @@ -824,7 +824,7 @@ sub get_random_prisoner { my $self = shift; my @prisoners = Lacuna ->db - ->resultset('Lacuna::DB::Result::Spies') + ->resultset('Spies') ->search( { on_body_id => $self->on_body_id, task => 'Captured' }, ) @@ -1483,7 +1483,7 @@ sub can_conduct_advanced_missions { if ($self->on_body->empire->alliance_id && $self->on_body->empire->alliance_id == $self->empire->alliance_id) { confess [1010, 'You cannot attack your alliance mates.']; } - my $ranks = Lacuna->db->resultset('Lacuna::DB::Result::Log::Empire'); + my $ranks = Lacuna->db->resultset('Log::Empire'); my $defender_rank = $ranks->search( { empire_id => $self->on_body->empire_id }, {rows => 1})->get_column('empire_size_rank')->single; my $attacker_rank = $ranks->search( {empire_id => $self->empire_id }, @@ -1532,9 +1532,9 @@ sub steal_planet { $self->on_body->name, $self->on_body->empire->name); -# withdraw trades - for my $market ( Lacuna->db->resultset('Lacuna::DB::Result::Market'), - Lacuna->db->resultset('Lacuna::DB::Result::MercenaryMarket') ) { + # withdraw trades + for my $market ( Lacuna->db->resultset('Market'), + Lacuna->db->resultset('MercenaryMarket') ) { my @to_be_deleted = $market->search({body_id => $self->on_body_id})->get_column('id')->all; foreach my $id (@to_be_deleted) { my $trade = $market->find($id); @@ -1547,7 +1547,7 @@ sub steal_planet { $trade->withdraw; } } -# Remove Supply chains to and from planet + # Remove Supply chains to and from planet foreach my $chain ($self->on_body->out_supply_chains) { $chain->delete; } @@ -1556,15 +1556,15 @@ sub steal_planet { } my $defender_capitol_id = $self->on_body->empire->home_planet_id; - Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({ + Lacuna->db->resultset('Spies')->search({ from_body_id => $self->on_body_id, on_body_id => $self->on_body_id, task => 'Training', })->delete_all; # All spies in training are executed - my $spies = Lacuna->db->resultset('Lacuna::DB::Result::Spies') + my $spies = Lacuna->db->resultset('Spies') ->search({from_body_id => $self->on_body_id}); my $def_capitol = Lacuna->db - ->resultset('Lacuna::DB::Result::Map::Body') + ->resultset('Map::Body') ->find($defender_capitol_id); my $def_int_cap = $def_capitol->get_building_of_class('Lacuna::DB::Result::Building::Intelligence'); @@ -1585,18 +1585,18 @@ sub steal_planet { } } - my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships') + my $ships = Lacuna->db->resultset('Ships') ->search({body_id => $self->on_body_id, task => { '!=' => 'Docked' } }); while (my $ship = $ships->next) { next if ($ship->task eq 'Waste Chain'); if ($ship->task eq 'Waiting On Trade') { -# Ships being delivered from trades or pushes. + # Ships being delivered from trades or pushes. $ship->body_id($defender_capitol_id); $ship->update; } elsif ($ship->task eq 'Supply Chain') { -# Supply chains from planet were deleted so we dock ships + # Supply chains from planet were deleted so we dock ships $ship->task('Docked'); $ship->update; } @@ -1612,7 +1612,7 @@ sub steal_planet { 'dory', 'barge', ]})) { -# Trade ship was outgoing, it will change homeport to capitol + # Trade ship was outgoing, it will change homeport to capitol if ($ship->direction eq 'out') { $ship->body_id($defender_capitol_id); $ship->update; @@ -1623,7 +1623,7 @@ sub steal_planet { @{[ 'colony_ship', 'short_range_colony_ship', ]})) { -# Colony ships show from capitol. + # Colony ships show from capitol. $ship->body_id($defender_capitol_id); $ship->update; } @@ -1631,7 +1631,7 @@ sub steal_planet { $ship->delete; } } -# Shipyards and Intelligence ministries have had all new items deleted, so get rid of timers. + # Shipyards and Intelligence ministries have had all new items deleted, so get rid of timers. my $on_body = $self->on_body; my @bld_timers = grep { ($_->class eq 'Lacuna::DB::Result::Building::Shipyard') || @@ -1643,9 +1643,9 @@ sub steal_planet { $btimer->update; } -# Probes - Lacuna->db->resultset('Lacuna::DB::Result::Probes') - ->search({body_id => $self->on_body_id}) + # Probes + Lacuna->db->resultset('Probes') + ->search_any({body_id => $self->on_body_id}) ->update({empire_id => $self->empire_id, alliance_id => $self->empire->alliance_id}); if ($self->on_body->empire_id < 1) { @@ -1884,7 +1884,7 @@ sub prevent_insurrection { $member_ids[0] = $self->empire->id; } my $conspirators = Lacuna->db - ->resultset('Lacuna::DB::Result::Spies') + ->resultset('Spies') ->search( { on_body_id => $self->on_body_id, task => { 'not in' => ['Killed In Action', 'Travelling', @@ -1924,7 +1924,7 @@ sub capture_kidnapper { sub abduct_operative { my ($self, $defender) = @_; my @types; - my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships'); + my $ships = Lacuna->db->resultset('Ships'); foreach my $type (SHIP_TYPES) { my $ship = $ships->new({type => $type}); if ($ship->pilotable) { @@ -2160,7 +2160,7 @@ sub destroy_resources { sub destroy_chain_ship { my ($self, $defender) = @_; - my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search( + my $ship = Lacuna->db->resultset('Ships')->search( {body_id => $self->on_body->id, task => {'in' => ['Supply Chain', 'Waste Chain'] }}, { rows => 1, order_by => 'rand()' } @@ -2200,7 +2200,7 @@ sub destroy_mining_ship { my ($self, $defender) = @_; my $ministry = $self->on_body->mining_ministry; return $self->building_not_found->id unless defined $ministry; - my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search( + my $ship = Lacuna->db->resultset('Ships')->search( {body_id => $self->on_body->id, task => 'Mining'}, { rows => 1, order_by => 'rand()' } )->single; @@ -2403,7 +2403,7 @@ sub steal_glyph { sub steal_ships { my ($self, $defender) = @_; my @types; - my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships'); + my $ships = Lacuna->db->resultset('Ships'); foreach my $type (SHIP_TYPES) { my $ship = $ships->new({type => $type}); if ($ship->pilotable) { @@ -2602,9 +2602,10 @@ sub shut_down_building { sub take_control_of_probe { my ($self, $defender) = @_; + # we can only take control of an observatory probe my $probe = Lacuna->db - ->resultset('Lacuna::DB::Result::Probes') - ->search({body_id => $self->on_body_id }, + ->resultset('Probes') + ->search_observatory({body_id => $self->on_body_id }, { rows => 1, order_by => 'rand()' } )->single; return $self->probe_not_found->id unless defined $probe; @@ -2644,7 +2645,7 @@ 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') + ->resultset('Excavators') ->search({planet_id => $self->on_body->id}, { rows => 1, order_by => 'rand()' } )->single; @@ -2679,7 +2680,7 @@ sub kill_contact_with_mining_platform { my $ministry = $self->on_body->mining_ministry; return $self->building_not_found->id unless defined $ministry; my $platform = Lacuna->db - ->resultset('Lacuna::DB::Result::MiningPlatforms') + ->resultset('MiningPlatforms') ->search({planet_id => $self->on_body->id}, { rows => 1, order_by => 'rand()' } )->single; @@ -2711,9 +2712,10 @@ sub kill_contact_with_mining_platform { sub hack_observatory_probes { my ($self, $defender) = @_; + my $probe = Lacuna->db - ->resultset('Lacuna::DB::Result::Probes') - ->search({body_id => $self->on_body->id }, + ->resultset('Probes') + ->search_observatory({body_id => $self->on_body->id }, { rows => 1, order_by => 'rand()' } )->single; return $self->probe_not_found->id unless defined $probe; @@ -2749,13 +2751,14 @@ sub hack_offending_probes { my ($self, $defender) = @_; return $self->get_spooked->id unless (defined $defender); my @safe = Lacuna->db - ->resultset('Lacuna::DB::Result::Spies') + ->resultset('Spies') ->search( {task=>'Counter Espionage', on_body_id=>$defender->on_body_id}) ->get_column('empire_id')->all; + # we can only hack observatory probes my $probe = Lacuna->db - ->resultset('Lacuna::DB::Result::Probes') - ->search({star_id => $self->on_body->star_id, + ->resultset('Probes') + ->search_observatory({star_id => $self->on_body->star_id, empire_id => {'not in' => \@safe} }, { rows => 1, order_by => 'rand()' } )->single; @@ -2791,8 +2794,8 @@ sub hack_offending_probes { sub hack_local_probes { my ($self, $defender) = @_; my $probe = Lacuna->db - ->resultset('Lacuna::DB::Result::Probes') - ->search( {star_id => $self->on_body->star_id, + ->resultset('Probes') + ->search_observatory( {star_id => $self->on_body->star_id, empire_id => $self->on_body->empire_id }, { rows => 1, order_by => 'rand()' } )->single; @@ -2883,7 +2886,7 @@ sub spy_report { my @peeps = (['Name','From','Assignment','Level']); my %planets = ( $self->on_body->id => $self->on_body->name ); my $spies = Lacuna->db - ->resultset('Lacuna::DB::Result::Spies') + ->resultset('Spies') ->search( { empire_id => {'!=' => $self->empire_id }, task => {'!=' => 'Travelling' }, on_body_id => $self->on_body_id } ); @@ -2974,7 +2977,7 @@ sub travel_report { sub ship_report { my ($self, $defender) = @_; my $ships = Lacuna->db - ->resultset('Lacuna::DB::Result::Ships') + ->resultset('Ships') ->search( {body_id => $self->on_body->id, task => 'Docked'}); my @ships = (['Name', 'Type', 'Speed', 'Hold Size']); @@ -3182,7 +3185,7 @@ sub counter_intel_report { my @peeps = (['Name','From','Assignment','Level']); my %planets = ( $self->on_body->id => $self->on_body->name ); my $spies = Lacuna->db - ->resultset('Lacuna::DB::Result::Spies') + ->resultset('Spies') ->search( {empire_id => {'!=' => $defender->empire_id}, on_body_id=>$self->on_body_id}); while (my $spook = $spies->next) { diff --git a/lib/Lacuna/DB/ResultSet/Probes.pm b/lib/Lacuna/DB/ResultSet/Probes.pm new file mode 100644 index 00000000..c52d372f --- /dev/null +++ b/lib/Lacuna/DB/ResultSet/Probes.pm @@ -0,0 +1,42 @@ +package Lacuna::DB::ResultSet::Probes; + +use Moose; +use utf8; +no warnings qw(uninitialized); +#use Lacuna; + +extends 'Lacuna::DB::ResultSet'; + +# Search for real probes (as sent out by observatory) +# +sub search_observatory { + my ($self, $args) = @_; + + $args = {} unless defined $args; + $args->{virtual} = 0; + + return $self->search($args); +} + +# Search for virtual probes (as seen by the Oracle) +# +sub search_oracle { + my ($self, $args) = @_; + + $args = {} unless defined $args; + $args->{virtual} = 1; + + return $self->search($args); +} + +# Search for any probes (real or virtual) +# +sub search_any { + my ($self, $args) = @_; + + return $self->search($args); +} + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); + diff --git a/lib/Lacuna/RPC/Building/Observatory.pm b/lib/Lacuna/RPC/Building/Observatory.pm index 2e81c10b..929ec20a 100644 --- a/lib/Lacuna/RPC/Building/Observatory.pm +++ b/lib/Lacuna/RPC/Building/Observatory.pm @@ -49,7 +49,7 @@ sub get_probed_stars { my $building = $self->get_building($empire, $building_id); my @stars; $page_number ||= 1; - my $probes = $building->probes->search(undef,{ rows => 25, page => $page_number }); + my $probes = $building->observatory_probes->search(undef,{ rows => 25, page => $page_number }); while (my $probe = $probes->next) { push @stars, $probe->star->get_status($empire); } diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index 91b2234f..37f1860b 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -17,7 +17,7 @@ sub find { confess [1009, 'Empire name too short. Your search must be at least 3 characters.']; } my $empire = $self->get_empire_by_session($session_id); - my $empires = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->search({name => {'like' => $name.'%'}}, {rows=>100}); + my $empires = Lacuna->db->resultset('Empire')->search({name => {'like' => $name.'%'}}, {rows=>100}); my @list_of_empires; my $limit = 100; while (my $empire = $empires->next) { @@ -52,7 +52,7 @@ sub is_name_valid { sub is_name_unique { my ($self, $name) = @_; - if (Lacuna->db->resultset('Lacuna::DB::Result::Empire')->search({name=>$name})->count) { + if (Lacuna->db->resultset('Empire')->search({name=>$name})->count) { confess [1000, 'Empire name is in use by another player.', 'name']; } return 1; @@ -69,7 +69,7 @@ sub login { unless ($api_key) { confess [1002, 'You need an API Key.']; } - my $empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->search({name=>$name})->next; + my $empire = Lacuna->db->resultset('Empire')->search({name=>$name})->next; unless (defined $empire) { confess [1002, 'Empire does not exist.', $name]; } @@ -82,7 +82,7 @@ sub login { if ($empire->rpc_count > $max) { confess [1010, $empire->name.' has already made the maximum number of requests ('.$max.') you can make for one day.']; } - #Lacuna->db->resultset('Lacuna::DB::Result::Log::RPC')->new({ + #Lacuna->db->resultset('Log::RPC')->new({ # empire_id => $empire->id, # empire_name => $empire->name, # module => ref $self, @@ -115,7 +115,7 @@ sub benchmark { my %out; my $t = [Time::HiRes::gettimeofday]; - my $empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->search({name=>$name})->next; + my $empire = Lacuna->db->resultset('Empire')->search({name=>$name})->next; $out{empire} = Time::HiRes::tv_interval($t); $t = [Time::HiRes::gettimeofday]; @@ -157,7 +157,7 @@ sub benchmark { sub fetch_captcha { my ($self, $plack_request) = @_; my $ip = $plack_request->address; - my $captcha = Lacuna->db->resultset('Lacuna::DB::Result::Captcha')->find(randint(1,Lacuna->config->get('captcha/total'))); + my $captcha = Lacuna->db->resultset('Captcha')->find(randint(1,Lacuna->config->get('captcha/total'))); Lacuna->cache->set('create_empire_captcha', $ip, { guid => $captcha->guid, solution => $captcha->solution }, 60 * 15 ); return { guid => $captcha->guid, @@ -194,7 +194,7 @@ sub change_password { sub send_password_reset_message { my ($self, %options) = @_; my $empire; - my $empires = Lacuna->db->resultset('Lacuna::DB::Result::Empire'); + my $empires = Lacuna->db->resultset('Empire'); if (exists $options{empire_id} && $options{empire_id} ne '') { $empire = $empires->find($options{empire_id}); } @@ -231,7 +231,7 @@ sub reset_password { unless (defined $key && $key ne '') { confess [1002, 'You need a key to reset a password.']; } - my $empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->search({password_recovery_key => $key}, { rows=>1 })->single; + my $empire = Lacuna->db->resultset('Empire')->search({password_recovery_key => $key}, { rows=>1 })->single; unless (defined $empire) { confess [1002, 'The key you provided is invalid. Password not reset.']; } @@ -278,7 +278,7 @@ sub create { # verify username eval { $self->is_name_unique($account{name}) }; if ($@) { # maybe they're trying to finish an incomplete empire - my $empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->search({name=>$account{name}})->next; + my $empire = Lacuna->db->resultset('Empire')->search({name=>$account{name}})->next; if (defined $empire) { if ($empire->stage eq 'new') { if ($empire->is_password_valid($account{password})) { @@ -303,14 +303,14 @@ sub create { if (exists $account{email} && $account{email} ne '') { Lacuna::Verify->new(content=>\$account{email}, throws=>[1005,'The email address specified does not look valid.', 'email']) ->is_email; - if (Lacuna->db->resultset('Lacuna::DB::Result::Empire')->search({email=>$account{email}})->count > 0) { + if (Lacuna->db->resultset('Empire')->search({email=>$account{email}})->count > 0) { confess [1005, 'That email address is already in use by another empire.', 'email']; } $params{email} = $account{email}; } # create account - my $empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->new(\%params)->insert; + my $empire = Lacuna->db->resultset('Empire')->new(\%params)->insert; Lacuna->cache->increment('empires_created', format_date(undef,'%F'), 1, 60 * 60 * 26); # handle invitation @@ -343,7 +343,7 @@ sub found { if ($empire_id eq '') { confess [1002, "You must specify an empire id."]; } - my $empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find($empire_id); + my $empire = Lacuna->db->resultset('Empire')->find($empire_id); unless (defined $empire) { confess [1002, "Invalid empire.", $empire_id]; } @@ -591,7 +591,7 @@ sub edit_profile { if (exists $profile->{email} && $profile->{email} ne '') { Lacuna::Verify->new(content=>\$profile->{email}, throws=>[1005,'The email address specified does not look valid.', 'email']) ->is_email if ($profile->{email}); - if (Lacuna->db->resultset('Lacuna::DB::Result::Empire')->search({email=>$profile->{email}, id=>{ '!=' => $empire->id}})->count > 0) { + if (Lacuna->db->resultset('Empire')->search({email=>$profile->{email}, id=>{ '!=' => $empire->id}})->count > 0) { confess [1005, 'That email address is already in use by another empire.', 'email']; } $empire->email($profile->{email}); @@ -635,7 +635,7 @@ sub set_status_message { sub view_public_profile { my ($self, $session_id, $empire_id) = @_; my $viewer_empire = $self->get_empire_by_session($session_id); - my $viewed_empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find($empire_id); + my $viewed_empire = Lacuna->db->resultset('Empire')->find($empire_id); unless (defined $viewed_empire) { confess [1002, 'The empire you wish to view does not exist.', $empire_id]; } @@ -672,7 +672,7 @@ sub view_public_profile { }; } my @colonies; - my $probes = Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search({empire_id => $viewer_empire->id}); + my $probes = Lacuna->db->resultset('Probes')->search_any({empire_id => $viewer_empire->id}); my $planets = $viewed_empire->planets->search(undef,{order_by => 'name'}); while (my $colony = $planets->next) { if ($colony->id == $viewed_empire->home_planet_id || $probes->search({star_id=>$colony->star_id})->count) { @@ -922,7 +922,7 @@ sub update_species { unless ($empire_id ne '') { confess [1002, "You must specify an empire id."]; } - my $empire = Lacuna->db->resultset('Lacuna::DB::Result::Empire')->find($empire_id); + my $empire = Lacuna->db->resultset('Empire')->find($empire_id); unless (defined $empire) { confess [1002, "Not a valid empire.",'empire_id']; } diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployProbe.pm b/lib/Lacuna/Role/Ship/Arrive/DeployProbe.pm index e81b697e..c807d6e6 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployProbe.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployProbe.pm @@ -11,7 +11,7 @@ after handle_arrival_procedures => sub { # deploy probe my $empire = $self->body->empire; - $empire->add_probe($self->foreign_star_id, $self->body_id); + $empire->add_observatory_probe($self->foreign_star_id, $self->body_id); # all pow $self->delete; @@ -22,7 +22,7 @@ after handle_arrival_procedures => sub { after can_send_to_target => sub { my ($self, $target) = @_; my $body = $self->body; - my $count = Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search({ body_id => $body->id })->count; + my $count = Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search_observatory({ body_id => $body->id })->count; $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({ body_id => $body->id, type=>'probe', task=>'Travelling' })->count; my $max_probes = 0; my ($observatory) = $body->get_buildings_of_class('Lacuna::DB::Result::Building::Observatory'); diff --git a/lib/Lacuna/Role/Ship/Arrive/DestroyProbes.pm b/lib/Lacuna/Role/Ship/Arrive/DestroyProbes.pm index 5a5001d2..583d2f11 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DestroyProbes.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DestroyProbes.pm @@ -9,14 +9,14 @@ after handle_arrival_procedures => sub { # we're coming home return if ($self->direction eq 'in'); - # not a star - return unless $self->foreign_star_id; + # not a star + return unless $self->foreign_star_id; - # find probes to destroy - my $probes = Lacuna->db->resultset('Lacuna::DB::Result::Probes')->search({star_id => $self->foreign_star_id }); + # find observatory probes to destroy + my $probes = Lacuna->db->resultset('Probes')->search_observatory({star_id => $self->foreign_star_id }); my $count; - my $logs = Lacuna->db->resultset('Lacuna::DB::Result::Log::Battles'); + my $logs = Lacuna->db->resultset('Log::Battles'); # destroy those suckers while (my $probe = $probes->next) { diff --git a/t/380_Tutorial.t b/t/380_Tutorial.t index d3f13a50..17824993 100644 --- a/t/380_Tutorial.t +++ b/t/380_Tutorial.t @@ -253,7 +253,7 @@ $building->finish_upgrade; $home->tick; is($empire->tutorial_stage, 'explore', 'observatory'); -$empire->add_probe($home->star_id, $home->id); +$empire->add_observatory_probe($home->star_id, $home->id); $home->tick; is($empire->tutorial_stage, 'the_end', 'explore'); diff --git a/var/upgrades/3.0888.sql b/var/upgrades/3.0888.sql new file mode 100644 index 00000000..5809311c --- /dev/null +++ b/var/upgrades/3.0888.sql @@ -0,0 +1,4 @@ + +alter table probes add column virtual int default 0; + + diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 65462cb5..b5e5e420 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,6 @@ +3.0888: + - Mod: Oracle now shows planets in star map if in range + 3.0887: - Mod: UI star map now shows alliance logos over seized stars - Mod: UI star map now shows fissure logo over planets with fissures on them -- 2.51.2