Games-Lacuna-Client

 view release on metacpan or  search on metacpan

examples/governor.yml  view on Meta::CPAN

        request_below: 0.05
        requested_level: 0.5
        production: 0.01
        recycle_above: 1000
        recycle_reserve: 100
        recycle_selection: full
    profile_production_tolerance: 0.1
    profile_storage_tolerance: 0.1
    reserve_build_queue: 1
    upgrade_selection: lowest_level
keepalive: 3600
push_minimum_load: 0.25
verbosity:
  action: 1
  construction: 1
  message: 1
  production: 0
  pushes: 1
  storage: 0
  summary: 1
  trace: 1

lib/Games/Lacuna/Client/Governor.pm  view on Meta::CPAN

    my $self = shift;
    my $client = $self->{client};
    my $config = $self->{config};

    my $data = $client->empire->view_species_stats();
    $self->{status} = $data->{status};
    my $planets        = $self->{status}->{empire}->{planets};
    my $home_planet_id = $self->{status}->{empire}->{home_planet_id};
    $self->{planet_names} = { map { $_ => $planets->{$_} } keys %$planets };

    my $do_keepalive = 1;
    my $start_time = time();

    $self->load_cache();

    do {
        my @priorities;
        if ( $self->{config}->{dry_run} ) {
            message("Starting dry run, actions are not actually taking place...");
        }
        $do_keepalive = 0;
        for my $pid ( keys %$planets ) {
            next if ( time() < $self->{next_action}->{$pid} );
            trace( "Examining " . $planets->{$pid} ) if ( $self->{config}->{verbosity}->{trace} );
            my $colony_config = merge( $config->{colony}->{ $planets->{$pid} } || {}, $config->{colony}->{_default_} );

            ### Fix the merge w/ priority lists.
            ### Normally Hash::Merge just concats two lists.
            ### We want our more specific array to override.
            if( my $colony_priorities = $config->{colony}{$planets->{$pid}}{priorities} ){
                $colony_config->{priorities} = $colony_priorities;

lib/Games/Lacuna/Client/Governor.pm  view on Meta::CPAN

            $self->do_post_priority($priority);
        }

        Games::Lacuna::Client::PrettyPrint::ship_report($self->{ship_info},$self->{config}->{ship_info_sort}) if defined $self->{ship_info};
        trace(sprintf("%d RPC calls this run",$self->{client}->{total_calls})) if ($self->{config}->{verbosity}->{trace});
        if ( $self->{config}->{dry_run} ) {
            message("Dry run complete.");
            return;
        }
        my $next_action_in = min( grep { $_ > time } values %{ $self->{next_action} } ) - time;
        if ( defined $next_action_in && ( $next_action_in + time ) < ( $config->{keepalive} + $start_time ) ) {
            if ( $next_action_in <= 0 ) {
                $do_keepalive = 0;
            }
            else {
                my $nat_time = ptime($next_action_in);
                trace("Expecting to govern again in $nat_time or so, sleeping...") if ($self->{config}->{verbosity}->{trace});
                sleep( $next_action_in + 5 );
                $do_keepalive = 1;
            }
        }
    } while ($do_keepalive);

    $self->write_cache();
}

sub govern {
    my $self = shift;
    my ($pid, $cfg) = @{$self->{current}}{qw(planet_id config)};
    my $client = $self->{client};

    my $result  = $self->{client}->body( id => $pid )->get_buildings();

lib/Games/Lacuna/Client/Governor.pm  view on Meta::CPAN

This is the maximum permitted age of the cache file, in seconds, before
a refresh is required.  Note the age of the cache file is updated with
each run, so this value may be set high enough that a refresh is never
forced.  Refreshes are pulled on a per-building basis.

=head2 dry_run

If this is true, Governor goes through the motions but does not actually
trigger any actions (such as upgrades, recycling jobs, or pushes).  The
output shows the actions as they would have taken place.  Enabling dry_run
disables keepalive behavior.

=head2 keepalive

This is the window of time, in seconds, to try to keep the governor alive
if more actions are possible.  Basically, if any governed colony's build
queue will be empty before the keepalive window expires, the script will
not terminate, but will instead sleep and wait for that build queue to empty
before once again governing that colony.  Setting this to 0 will
effectively disable this behavior.

=head2 push_max_travel_time

This is the maximum time, in hours, that a push should take (one-way) to
be considered a valid candidate.  This can be used to prevent pushes between
very distant colonies.  If not defined, there is no restriction.



( run in 1.136 second using v1.01-cache-2.11-cpan-39bf76dae61 )