From 1542bd93757df11456e9b6258da5523523d28fa9 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 25 Sep 2011 17:04:57 -0600 Subject: [PATCH 1/6] Limit longest extended build time to 60 days. --- lib/Lacuna/DB/Result/Building.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index 41f9dc7b..0253a3b5 100644 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -744,6 +744,7 @@ sub cost_to_upgrade { $time_inflator = 1 if ($time_inflator < 1); my $throttle = Lacuna->config->get('building_build_speed') || 6; my $time_cost = (($self->level+1)/$throttle * $self->time_to_build * $time_inflator ** INFLATION) * $self->time_cost_reduction_bonus * $oversight_reduction; + $time_cost = 5184000 if ($time_cost > 5184000); #60 days $time_cost = 15 if ($time_cost < 15); return { food => sprintf('%.0f',$self->food_to_build * $upgrade_cost * $upgrade_cost_reduction), -- 2.51.2 From 35be8a1e1de67ef4867b5cbf8831b0b05c2c4b81 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 25 Sep 2011 17:08:09 -0600 Subject: [PATCH 2/6] Partial Repair implemented. --- lib/Lacuna/DB/Result/Building.pm | 52 ++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index 0253a3b5..aa5ff463 100644 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -880,26 +880,54 @@ sub can_repair { my ($self, $costs) = @_; $costs ||= $self->get_repair_costs; my $body = $self->body; +# unless ($body->food_stored >= $costs->{food}) { +# confess [1011, 'You need '.$costs->{food}.' food to repair this building.']; +# } +# unless ($body->water_stored >= $costs->{water}) { +# confess [1011, 'You need '.$costs->{water}.' water to repair this building.']; +# } +# unless ($body->ore_stored >= $costs->{ore}) { +# confess [1011, 'You need '.$costs->{ore}.' ore to repair this building.']; +# } +# unless ($body->energy_stored >= $costs->{energy}) { +# confess [1011, 'You need '.$costs->{energy}.' energy to repair this building.']; +# } + return 1; +} + +sub repair { + my ($self, $costs) = @_; + $costs ||= $self->get_repair_costs; + my $body = $self->body; + my $eff = 100; unless ($body->food_stored >= $costs->{food}) { - confess [1011, 'You need '.$costs->{food}.' food to repair this building.']; + my $teff = int(($body->food_stored-50)*100/$costs->{food}); + $eff = $teff if ($teff < $eff); } unless ($body->water_stored >= $costs->{water}) { - confess [1011, 'You need '.$costs->{water}.' water to repair this building.']; + my $teff = int($body->water_stored*100/$costs->{water}); + $eff = $teff if ($teff < $eff); } unless ($body->ore_stored >= $costs->{ore}) { - confess [1011, 'You need '.$costs->{ore}.' ore to repair this building.']; + my $teff = int(($body->ore_stored-50)*100/$costs->{ore}); + $eff = $teff if ($teff < $eff); } unless ($body->energy_stored >= $costs->{energy}) { - confess [1011, 'You need '.$costs->{energy}.' energy to repair this building.']; + my $teff = int($body->energy_stored*100/$costs->{energy}); + $eff = $teff if ($teff < $eff); + } + unless ($eff > 0) { + confess [1011, 'Not enough resources to do a partial repair.']; + } + $self->efficiency($eff); + $costs->{food} = int($eff*$costs->{food}/100); + $costs->{water} = int($eff*$costs->{water}/100); + $costs->{ore} = int($eff*$costs->{ore}/100); + $costs->{energy} = int($eff*$costs->{energy}/100); + if ($eff < 100) { + $eff = $self->efficiency + $eff; + $eff = 100 if ($eff > 100); } - return 1; -} - -sub repair { - my ($self, $costs) = @_; - $costs ||= $self->get_repair_costs; - my $body = $self->body; - $self->efficiency(100); $self->update; $body->spend_food($costs->{food}); $body->spend_water($costs->{water}); -- 2.51.2 From 6929075fe5a89254846e92df90cbae6e15035a35 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 26 Sep 2011 16:06:07 -0600 Subject: [PATCH 3/6] Issue #18; Failed Insurrection captures attacking spies. --- lib/Lacuna/DB/Result/Spies.pm | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index d0c432cc..c98fdca2 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1376,17 +1376,21 @@ sub prevent_insurrection { return $self->get_spooked->id unless (defined $defender); $self->on_body->add_news(50,'Officials prevented a coup d\'�tat today on on %s by capturing %s and comrades.', $self->on_body->name, $self->name); $self->go_to_jail; - my $alliance_id = $defender->empire->alliance_id; + my $alliance_id = $self->empire->alliance_id; + my @member_ids; if ($alliance_id) { - my @member_ids = $defender->empire->alliance->members->get_column('id')->all; - my $conspirators = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({ on_body_id => $self->on_body_id, task => { 'not in' => ['Idle','Travelling','Captured'] }, empire_id => { 'in' => \@member_ids } }); - my $count = randint(5,15); - while (my $conspirator = $conspirators->next ) { - $count--; - $conspirator->go_to_jail; - $conspirator->update; - last if $count < 1; - } + @member_ids = $self->empire->alliance->members->get_column('id')->all; + } + else { + $member_ids[0] = $self->empire->id; + } + my $conspirators = Lacuna->db->resultset('Lacuna::DB::Result::Spies')->search({ on_body_id => $self->on_body_id, task => { 'not in' => ['Killed in Action', 'Travelling','Captured'] }, empire_id => { 'in' => \@member_ids } }); + my $count = randint(5,15); + while (my $conspirator = $conspirators->next ) { + $count--; + $conspirator->go_to_jail; + $conspirator->update; + last if $count < 1; } $defender->on_body->empire->send_predefined_message( tags => ['Spies','Alert'], -- 2.51.2 From c4154572f031454bbeac2c383a49db7c9c0f6e57 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 26 Sep 2011 23:34:27 -0600 Subject: [PATCH 4/6] Allow downgrade of spaceport if there is room. --- lib/Lacuna/DB/Result/Building/SpacePort.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 lib/Lacuna/DB/Result/Building/SpacePort.pm diff --git a/lib/Lacuna/DB/Result/Building/SpacePort.pm b/lib/Lacuna/DB/Result/Building/SpacePort.pm old mode 100644 new mode 100755 index cd1be5b2..d85dec4e --- a/lib/Lacuna/DB/Result/Building/SpacePort.pm +++ b/lib/Lacuna/DB/Result/Building/SpacePort.pm @@ -108,7 +108,7 @@ before delete => sub { before 'can_downgrade' => sub { my $self = shift; - if ($self->ships->count > ($self->level - 1) * 2) { + if ( ($self->max_ships - $self->number_of_ships) < 2) { confess [1013, 'You must scuttle some ships to downgrade the Spaceport.']; } }; -- 2.51.2 From d10d4d07c75fb240589a59d44186aa394b7e3405 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Wed, 28 Sep 2011 17:36:46 -0600 Subject: [PATCH 5/6] Fixed exception if less than 0 resources found --- lib/Lacuna/DB/Result/Building.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) mode change 100644 => 100755 lib/Lacuna/DB/Result/Building.pm diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm old mode 100644 new mode 100755 index aa5ff463..83e8c791 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -744,7 +744,7 @@ sub cost_to_upgrade { $time_inflator = 1 if ($time_inflator < 1); my $throttle = Lacuna->config->get('building_build_speed') || 6; my $time_cost = (($self->level+1)/$throttle * $self->time_to_build * $time_inflator ** INFLATION) * $self->time_cost_reduction_bonus * $oversight_reduction; - $time_cost = 5184000 if ($time_cost > 5184000); #60 days + $time_cost = 5184000 if ($time_cost > 5184000); # 60 Days $time_cost = 15 if ($time_cost < 15); return { food => sprintf('%.0f',$self->food_to_build * $upgrade_cost * $upgrade_cost_reduction), @@ -900,19 +900,19 @@ sub repair { $costs ||= $self->get_repair_costs; my $body = $self->body; my $eff = 100; - unless ($body->food_stored >= $costs->{food}) { + unless ($body->food_stored >= $costs->{food} or $costs->{food} == 0) { my $teff = int(($body->food_stored-50)*100/$costs->{food}); $eff = $teff if ($teff < $eff); } - unless ($body->water_stored >= $costs->{water}) { + unless ($body->water_stored >= $costs->{water} or $costs->{water} == 0) { my $teff = int($body->water_stored*100/$costs->{water}); $eff = $teff if ($teff < $eff); } - unless ($body->ore_stored >= $costs->{ore}) { + unless ($body->ore_stored >= $costs->{ore} or $costs->{ore} == 0) { my $teff = int(($body->ore_stored-50)*100/$costs->{ore}); $eff = $teff if ($teff < $eff); } - unless ($body->energy_stored >= $costs->{energy}) { + unless ($body->energy_stored >= $costs->{energy} or $costs->{energy} == 0) { my $teff = int($body->energy_stored*100/$costs->{energy}); $eff = $teff if ($teff < $eff); } -- 2.51.2 From 8a4eb1980f3465a8908bc2132a4c1b2576f9d694 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 2 Oct 2011 14:56:45 -0600 Subject: [PATCH 6/6] Ability to complete builds via Admin interface --- lib/Lacuna/Web/Admin.pm | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/Web/Admin.pm b/lib/Lacuna/Web/Admin.pm index 5661f2e2..ab1104a5 100644 --- a/lib/Lacuna/Web/Admin.pm +++ b/lib/Lacuna/Web/Admin.pm @@ -193,6 +193,24 @@ sub www_search_stars { return $self->wrap($out); } +sub www_complete_builds { + my ($self, $request, $body_id) = @_; + $body_id ||= $request->param('body_id'); + my $body = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($body_id); + my $buildings = $body->buildings; + while (my $building = $buildings->next) { + next unless ( $building->is_upgrading ); + $building->is_upgrading(0); + $building->upgrade_ends($building->upgrade_started); + $building->level($building->level + 1); + $building->update; + } + $body->needs_recalc(1); + $body->needs_surface_refresh(1); + $body->update; + return $self->wrap(sprintf('All building constuction completed! Back To Body', $request->param('body_id'))); +} + sub www_send_stellar_flare { my ($self, $request, $body_id) = @_; $body_id ||= $request->param('body_id'); @@ -265,9 +283,9 @@ sub www_view_buildings { my $buildings = Lacuna->db->resultset('Lacuna::DB::Result::Building')->search({ body_id => $body_id }, {order_by => ['x','y'] }); my $out = '

View Buildings

'; $out .= sprintf('Back To Body', $body_id); - $out .= ''; + $out .= '
IdNameXYLevelEfficiency
'; while (my $building = $buildings->next) { - $out .= sprintf('', $building->id, $building->name, $building->x, $building->y, $building->level, $building->id, $building->efficiency); + $out .= sprintf('', $building->id, $building->name, $building->x, $building->y, $building->level, $building->is_upgrading, $building->id, $building->efficiency); } $out .= '
IdNameXYLevelInProgressEfficiency
%s%s%s%s%s
%s%s%s%s%s%s
'; return $self->wrap($out); @@ -625,6 +643,7 @@ sub www_view_body { $out .= sprintf('
  • View Plans
  • ', $body->id); $out .= sprintf('
  • View Glyphs
  • ', $body->id); $out .= sprintf('
  • Recalculate Body Stats
  • ', $body->id); + $out .= sprintf('
  • Complete All Builds
  • ', $body->id); $out .= sprintf('
  • Send Stellar Flare
  • ', $body->id); $out .= sprintf('
  • Send Meteor Shower
  • ', $body->id); $out .= sprintf('
  • Send Pestilence
  • ', $body->id); -- 2.51.2