-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathshow_foods.pl
executable file
·98 lines (91 loc) · 3.54 KB
/
show_foods.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/perl
use strict;
use Client;
use Getopt::Long;
use JSON::PP;
use List::Util qw(sum);
my $config_name = "config.json";
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);
my $planets = $client->empire_status->{planets};
my %foods = (
"Planetary Command Center", ["algae"],
"Malcud Fungus Farm", ["fungus"],
"Malcud Burger Packer", ["burger"],
"Algae Cropper", ["algae"],
"Algae Syrup Bottler", ["syrup"],
"Amalgus Bean Plantation", ["bean"],
"Amalgus Bean Soup Cannery", ["soup"],
"Potato Patch", ["potato"],
"Potato Pancake Factory", ["pancake"],
"Denton Root Patch", ["root"],
"Denton Root Chip Frier", ["chip"],
"Corn Plantation", ["corn"],
"Corn Meal Grinder", ["meal"],
"Wheat Farm", ["wheat"],
"Bread Bakery", ["bread"],
"Beeldeban Herder", ["beetle"],
"Beeldeban Protein Shake Factory", ["shake"],
"Apple Orchard", ["apple"],
"Apple Cider Bottler", ["cider"],
"Lapis Orchard", ["lapis"],
"Lapis Pie Bakery", ["pie"],
"Dairy Farm", ["milk"],
"Cheese Maker", ["cheese"],
"Algae Pond", ["algae"],
"Malcud Field", ["fungus"],
"Beeldeban Nest", ["beetle"],
"Lapis Forest", ["lapis"],
"Denton Brambles", ["root"],
"Amalgus Meadow", ["bean"],
"Lost City of Tyleon (A)", [qw(burger syrup soup chip shake pie)],
);
my %stats;
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}});
my @producers = grep { $foods{$_->{name}} } @buildings;
my %produce;
my %producers;
for my $building (@producers) {
my $level = $building->{level};
if ($building->{name} =~ /Tyleon/) {
$level = List::Util::min(map { $_->{level} } grep { $_->{name} =~ /Tyleon/ } @buildings);
}
$stats{$building->{name}}{$level} ||=
$client->building_stats_for_level($building->{url}, $building->{id}, $level);
my $rate = $stats{$building->{name}}{$level}{building}{food_hour};
my @foods = @{$foods{$building->{name}}};
for my $food (@foods) {
$producers{$food}{$building->{name}}{$level}++;
$produce{$food} += $rate / @foods;
$total{$food} += $rate / @foods;
}
}
for my $food (sort keys %produce) {
printf(" %-10s%10.0f/hour ", $food, $produce{$food});
my @seq;
for my $gen (sort keys %{$producers{$food}}) {
my @list;
for my $level (sort keys %{$producers{$food}{$gen}}) {
push @list, "$producers{$food}{$gen}{$level}x$level"
}
push @seq, sprintf("%-32s ", $gen).join(", ", @list);
}
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) {
printf(" %-10s%10.0f/hour\n", $food, $total{$food});
}