Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 76 lines (66 sloc) 2.507 kB
44a6e59 Initial checkin for public consumption
T. Alexander Popiel authored
1 #!/usr/bin/perl
2
3 use strict;
4
5 use Client;
6 use Getopt::Long;
d5a24ca @paulbort Part two of changes for Windows compatibility: Use JSON::PP instead of
paulbort authored
7 use JSON::PP;
44a6e59 Initial checkin for public consumption
T. Alexander Popiel authored
8
9 my $config_name = "config.json";
10 my $body_name;
11
12 GetOptions(
13 "config=s" => \$config_name,
14 "body=s" => \$body_name,
4709c66 Removing old references to yaml. All the config is in json, now.
T. Alexander Popiel authored
15 ) or die "$0 --config=foo.json --body=Bar\n";
44a6e59 Initial checkin for public consumption
T. Alexander Popiel authored
16
17 my $client = Client->new(config => $config_name);
18 my $body_id;
19 if ($body_name) {
20 my $planets = $client->empire_status->{planets};
21 for my $id (keys(%$planets)) {
22 $body_id = $id if $planets->{$id} =~ /$body_name/;
23 }
24 die "No matching planet for name $body_name\n" unless $body_id;
25 } else {
26 $body_id = $client->empire_status->{home_planet_id};
27 }
28
29 my %buildings;
30
31 my $result = $client->body_buildable($body_id);
32 for my $name (keys %{$result->{buildable}}) {
33 my $building = $result->{buildable}{$name};
34 $buildings{$name}{1}{cost} = $building->{build}{cost};
35 my %production;
36 my %capacity;
37 for my $resource (qw(food ore water energy waste happiness)) {
38 $production{$resource} = $building->{production}{"${resource}_hour"};
39 $capacity{$resource} = $building->{production}{"${resource}_capacity"};
40 }
41 $buildings{$name}{1}{production} = { %production };
42 $buildings{$name}{1}{capacity} = { %capacity };
43 }
44
45 my $result = $client->body_buildings($body_id);
46 for my $id (keys %{$result->{buildings}}) {
47 my $name = $result->{buildings}{$id}{name};
48 my $url = $result->{buildings}{$id}{url};
49 next if $buildings{$name}{2};
50 for my $level (1..10) {
51 warn "Fetching stats for $level $name\n";
52 my $info = $client->building_stats_for_level($url, $id, $level);
53 unless ($buildings{$name}{$level}{production}) {
54 my %production;
55 my %capacity;
56 for my $resource (qw(food ore water energy waste happiness)) {
57 $production{$resource} = $info->{building}{"${resource}_hour"};
58 $capacity{$resource} = $info->{building}{"${resource}_capacity"};
59 }
60 $buildings{$name}{$level}{production} = { %production };
61 $buildings{$name}{$level}{capacity} = { %capacity };
62 }
63 my %production;
64 my %capacity;
65 for my $resource (qw(food ore water energy waste happiness)) {
66 $production{$resource} = $info->{building}{upgrade}{production}{"${resource}_hour"};
67 $capacity{$resource} = $info->{building}{upgrade}{production}{"${resource}_capacity"};
68 }
69 $buildings{$name}{$level}{upgrade} = $info->{building}{upgrade}{cost};
70 $buildings{$name}{$level+1}{production} = { %production };
71 $buildings{$name}{$level+1}{capacity} = { %capacity };
72 }
73 }
74
75 print encode_json({%buildings})."\n";
Something went wrong with that request. Please try again.