Skip to content

Commit

Permalink
archaeologist-ysth: option to avoid bodies with low or variable total…
Browse files Browse the repository at this point in the history
… ore
  • Loading branch information
ysth committed Dec 9, 2012
1 parent 9cd317c commit a8aad0f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions archaeologist-ysth.pl
Expand Up @@ -64,6 +64,7 @@
my $optimize = 1;
my $avoid_populated = 0;
my $avoid_seized = 0;
my $avoid_small = 0;
my $noaction = 0;
my $purge = 0;
my $debug = 0;
Expand All @@ -80,6 +81,7 @@
"optimize!" => \$optimize,
"avoid_populated!" => \$avoid_populated,
"avoid_seized!" => \$avoid_seized,
"avoid_small_bodies!" => \$avoid_small,
"noaction|dryrun|n!" => \$noaction,
"purge!" => \$purge,
"debug|d+" => \$debug,
Expand Down Expand Up @@ -306,6 +308,7 @@ sub db_find_body_for_ore {
my $ores_q = join(",", map { "o.$_ as $_" } @ores);
my $ores = join(",", map { "o.$_" } @ores);
my $no_station = ( $avoid_seized ? ' and o.station_id is null' : '' );
my $no_small = ( $avoid_small ? " and o.subtype not in ('p33','a5','a6','a7','a8','a9','a10','a11','a12','a13','a14','a15','a16','a17','a18','a19','a20','debris1','a22','a23','a24','a26','a26')" : '' );
my $result = $star_db->selectrow_hashref(qq(
select * from (
select o.x as x, o.y as y, o.body_id as body_id, o.name as name,
Expand All @@ -316,7 +319,7 @@ sub db_find_body_for_ore {
select star_id from orbitals
where empire_id is not null and empire_id <> ?
) s on (o.star_id = s.star_id)
where o.empire_id is null and o.excavated_by is null and o.type in ('asteroid','habitable planet') and s.star_id is null$no_station
where o.empire_id is null and o.excavated_by is null and o.type in ('asteroid','habitable planet') and s.star_id is null$no_small$no_station
) q
where dist < (? * ?)
order by ore desc, dist
Expand All @@ -333,14 +336,15 @@ sub db_find_body_types {
my $ores = join(",", map { "o.$_" } @ores);
my $dist2 = $max * $max;
my $no_station = ( $avoid_seized ? ' and o.station_id is null' : '' );
my $no_small = ( $avoid_small ? " and o.subtype not in ('p33','a5','a6','a7','a8','a9','a10','a11','a12','a13','a14','a15','a16','a17','a18','a19','a20','debris1','a22','a23','a24','a26','a26')" : '' );
my $query = $star_db->prepare(qq(
select * from (
select $ores_q, min((o.x - ?) * (o.x - ?) + (o.y - ?) * (o.y - ?)) as dist, o.subtype as subtype from orbitals o
left join (
select star_id from orbitals
where empire_id is not null and empire_id <> ?
) s on (o.star_id = s.star_id)
where o.empire_id is null and o.excavated_by is null and o.type in ('asteroid','habitable planet') and s.star_id is null$no_station
where o.empire_id is null and o.excavated_by is null and o.type in ('asteroid','habitable planet') and s.star_id is null$no_small$no_station
group by o.subtype
) q where dist < $dist2
));
Expand Down

0 comments on commit a8aad0f

Please sign in to comment.