Permalink
Browse files

More random starter planet selection in starter areas.

  • Loading branch information...
1 parent 9dac7a7 commit 028deee3f68d6ef23fb023d175b26e0f8ed3749c @lemming552 lemming552 committed Mar 7, 2013
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/Lacuna/DB/Result/Empire.pm
@@ -6,7 +6,7 @@ no warnings qw(uninitialized);
extends 'Lacuna::DB::Result';
use DateTime;
use Scalar::Util qw(weaken);
-use Lacuna::Util qw(format_date);
+use Lacuna::Util qw(format_date randint);
use Digest::SHA;
use List::MoreUtils qw(uniq);
use Email::Stuff;
@@ -662,13 +662,20 @@ sub find_home_planet {
}
# search FIXME Note, this is temporary, should create a single query
- # that returns all possible planets. 'rows 250' is not guaranteed to
+ # that returns all possible planets. 'rows 100' is not guaranteed to
# find a planet.
- my $possible_planets = $planets->search(\%search, { rows => 250 });
+ # Slightly better scheme. At least we're likely to get a different group of planets.
+ my $possible_count = $planets->search(\%search);
+ my $offset = 0;
+ if ($possible_count > 100) {
+ $offset = randint(0,$possible_count-100);
+ }
+ my @possible_planets = $planets->search(\%search, { offset => $offset, rows => 100 });
# find an uncontested planet in the possible planets
my $home_planet;
- while (my $planet = $possible_planets->next) {
+ while (scalar @possible_planets > 0) {
+ my $planet = splice (@possible_planets, randint(0,scalar @possible_planets), 1);
# skip planets with member's only colonization
next if ($planet->empire); # If a planet is qualified, but inhabited.
if ($planet->star->station_id) {

0 comments on commit 028deee

Please sign in to comment.