Skip to content
Browse files

Misc small updates, allow build_queue update to specify target level

  • Loading branch information...
1 parent 63c5d3f commit 4c65179c100d357e3d3aa750c501613795bccbe7 T. Alexander Popiel committed
Showing with 20 additions and 12 deletions.
  1. +7 −5 build_queue.pl
  2. +1 −1 mailman.pl
  3. +3 −1 send_plans.pl
  4. +6 −2 show_foods.pl
  5. +3 −3 show_happy.pl
View
12 build_queue.pl
@@ -207,9 +207,10 @@
}
}
}
- if ($command =~ /^upgrade (\d+) (.*)/o) {
- my $level = $1;
- my $name = $2;
+ if ($command =~ /^upgrade (\<?)(\d+) (.*)/o) {
+ my $upTo = $1;
+ my $level = $2;
+ my $name = $3;
my $realname = $name;
next if @builds;
@@ -224,7 +225,8 @@
for my $id (keys %{$buildings->{buildings}}) {
my $building = $buildings->{buildings}{$id};
print "Matching against $building->{level} $building->{name}\n" if $debug;
- if ($building->{name} eq $name && (!$level || $building->{level} == $level) && $building->{level} < 30) {
+ if ($building->{name} eq $name && $building->{level} < 30 &&
+ (!$level || ($upTo ? $building->{level} < $level : $building->{level} == $level))) {
$building->{id} = $id;
my $message = upgrade_check($building, 1);
if ($message) {
@@ -238,7 +240,7 @@
my $upgrade = $client->building_upgrade($building->{url}, $id);
emit("Upgrading $building->{level} $name, complete at ".Client::format_time(Client::parse_time($upgrade->{building}{pending_build}{end})));
if ($retain) {
- emit("Retaining upgrade command for $level $realname");
+ emit("Retaining upgrade command for $upTo$level $realname");
}
else {
splice(@queue, $j, 1);
View
2 mailman.pl
@@ -95,7 +95,7 @@ sub match_planet {
}
if (grep(/Probe/, @{$message->{tags}}) && !$message->{has_read}) {
my $detail = $client->call(inbox => read_message => $message->{id});
- if ($detail->{message}{body} =~ /\{Empire \d+ (last|kiamo)\}/) {
+ if ($detail->{message}{body} =~ /\{Empire \d+ (last|kiamo|fireartist)\}/) {
emit("Trashing $message->{id}") if $debug;
push(@trash, $message->{id});
}
View
4 send_plans.pl
@@ -20,6 +20,7 @@
my $quiet = 0;
my $wanted;
my $plan_type = "Halls of Vrbansk";
+my $extra_levels = 0;
my $noaction;
GetOptions(
@@ -31,6 +32,7 @@
"count=s" => \$wanted,
"ship=s" => \$ship_name,
"name|type=s" => \$plan_type,
+ "extra=i" => \$extra_levels,
) or die "$0 --config=foo.json --body=Bar --body=Baz --count=all\n";
die "Must specify two bodies\n" unless @body_name == 2;
@@ -74,7 +76,7 @@
$plans = $client->body_plans($body_id[0]);
@plans = @{$plans->{plans}};
-@plans = grep { $_->{name} =~ /$plan_type/ } @plans;
+@plans = grep { $_->{name} =~ /$plan_type/ && $_->{extra_build_level} == $extra_levels } @plans;
my $available = ($plans[0] || {})->{quantity} || 0;
View
8 show_foods.pl
@@ -5,13 +5,14 @@
use Client;
use Getopt::Long;
use JSON::PP;
-use List::Util;
+use List::Util qw(sum);
my $config_name = "config.json";
-my $body_name;
+my @body_names;
GetOptions(
"config=s" => \$config_name,
+ "body=s" => \@body_names,
) or die "$0 --config=foo.json --body=Bar\n";
my $client = Client->new(config => $config_name);
@@ -54,6 +55,7 @@
my %total = map { ($_->[0] => 0) } values %foods;
$total{$_} = 0 for keys %total;
for my $body_id (sort { $planets->{$a} cmp $planets->{$b} } keys(%$planets)) {
+ next unless grep { $planets->{$body_id} =~ /$_/ } @body_names;
my $buildings = $client->body_buildings($body_id);
print "$planets->{$body_id}: orbit $buildings->{status}{body}{orbit}, net $buildings->{status}{body}{food_hour} food/hr\n";
my @buildings = map { { %{$buildings->{buildings}{$_}}, id => $_ } } keys(%{$buildings->{buildings}});
@@ -87,6 +89,8 @@
}
print join("; ", @seq)."\n";
}
+ my $produce = sum(values(%produce));
+ print " produce: $produce, net $buildings->{status}{body}{food_hour} (".int(100 * $buildings->{status}{body}{food_hour} / $produce)."%)\n";
}
print "\nTotal:\n";
for my $food (sort keys %total) {
View
6 show_happy.pl
@@ -5,7 +5,7 @@
use Client;
use Getopt::Long;
use JSON::PP;
-use List::Util qw(max);
+use List::Util qw(min max);
my $config_name = "config.json";
my $waste = 0;
@@ -30,12 +30,12 @@
my $rate = $client->body_status($id)->{waste_hour};
my $overage = 0;
if ($rate < 0) {
- $overage = max(0, -$rate - $client->body_status($id)->{waste_stored});
+ $overage = min(0, $rate + $client->body_status($id)->{waste_stored});
} else {
$overage = max(0, $rate - $client->body_status($id)->{waste_capacity} + $client->body_status($id)->{waste_stored});
}
my $perhour = sprintf("%0.0f ", $slop ? $overage : ($waste
- ? $client->body_status($id)->{happiness_hour} - $overage
+ ? $client->body_status($id)->{happiness_hour} - max($overage, -$overage)
: $client->body_status($id)->{happiness_hour}));
1 while $perhour =~ s/(\d)(\d\d\d)(\D)/$1,$2$3/;
printf("%20s %15s/hr %s\n", $happy, $perhour, $planets->{$id});

0 comments on commit 4c65179

Please sign in to comment.
Something went wrong with that request. Please try again.