Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix broken ship update task and add better logging

  • Loading branch information...
commit a293aa49872d861da0d88ae3756149996d01eb2d 1 parent 9bb33cf
@maros authored
Showing with 12 additions and 10 deletions.
  1. +12 −10 lib/Games/Lacuna/Task/Action/ShipUpdate.pm
View
22 lib/Games/Lacuna/Task/Action/ShipUpdate.pm
@@ -96,6 +96,7 @@ sub process_planet {
my $old_ships = {};
my $threshold = $self->threshold / 100 + 1;
+ SHIPS:
foreach my $ship (@{$ships_data->{ships}}) {
my $ship_type = $ship->{type};
$ship_type =~ s/\d$//;
@@ -107,21 +108,24 @@ sub process_planet {
next
unless defined $self->best_ships->{$ship_type};
- my $best_ship = $self->get_best_ships($ship_type);
+ my $best_ship = $self->get_best_ship($ship_type);
my $ship_is_ok = 1;
foreach my $attribute (@ATTRIBUTES) {
- if ($best_ship->{$attribute} / $threshold > $ship->{$attribute}) {
- $self->log('debug','Ship %s on %s is outdated (%s %i vs. %i)',$ship->{name},$planet_stats->{name},$attribute,$ship->{$attribute},$best_ship->{$attribute});
+ if ($ship->{$attribute} > $best_ship->{$attribute}) {
+ next SHIPS;
+ }
+ if ($best_ship->{$attribute} / $threshold < $ship->{$attribute}) {
$ship_is_ok = 0;
- last;
}
}
next
if $ship_is_ok;
+ $self->log('debug','Ship %s on %s is outdated',$ship->{name},$planet_stats->{name});
+
$old_ships->{$ship_type} ||= [];
push (@{$old_ships->{$ship_type}},$ship);
@@ -129,7 +133,7 @@ sub process_planet {
foreach my $ship_type (sort { scalar @{$old_ships->{$b}} <=> scalar @{$old_ships->{$a}} } keys %{$old_ships}) {
my $old_ships = $old_ships->{$ship_type};
- my $best_ships = $self->get_best_ships($ship_type);
+ my $best_ships = $self->get_best_ship($ship_type);
my $build_planet_id = $best_ships->{planet};
my $build_planet_stats = $self->get_best_planet($build_planet_id);
next
@@ -170,17 +174,15 @@ sub process_planet {
sub _build_best_ships {
my ($self) = @_;
- $self->log('info',"Get best build planet for each ship type");
-
my $best_ships = {};
foreach my $planet_stats ($self->get_planets) {
+ $self->log('info',"Checking best ships at planet %s",$planet_stats->{name});
my ($buildable_ships,$docks_available) = $self->get_buildable_ships($planet_stats);
BUILDABLE_SHIPS:
while (my ($type,$data) = each %{$buildable_ships}) {
$data->{planet} = $planet_stats->{id};
$best_ships->{$type} ||= $data;
- warn $data;
foreach my $attribute (@ATTRIBUTES) {
if ($best_ships->{$type}{$attribute} < $data->{$attribute}) {
@@ -197,8 +199,6 @@ sub _build_best_ships {
sub _build_best_planets {
my ($self) = @_;
- $self->log('info',"Get info about best build planets");
-
my $best_planets = {};
foreach my $best_ship ($self->best_ship_types) {
my $planet_id = $self->get_best_ship($best_ship)->{planet};
@@ -218,6 +218,8 @@ sub _build_best_planets {
shipyards => $available_shipyards,
};
}
+
+ $self->log('info',"Best %s can be buildt at %s",$self->my_body_status($planet_id)->{name});
}
return $best_planets;
Please sign in to comment.
Something went wrong with that request. Please try again.