From 33772928f53cb80c77e467556cd2bd7191f54bb3 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 9 Jul 2012 16:35:39 -0600 Subject: [PATCH 01/22] Neutral Zone params added to lacuna.conf and status of such added. --- docs/Archaeology.pod | 2 +- etc/lacuna.conf.template | 27 +++++++++++++ lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 40 +++++++++++++++++++ lib/Lacuna/RPC/Building/BlackHoleGenerator.pm | 12 +++--- lib/Lacuna/Role/Ship/Send/NeutralZone.pm | 11 +++++ var/www/public/changes.txt | 1 + 7 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 lib/Lacuna/Role/Ship/Send/NeutralZone.pm diff --git a/docs/Archaeology.pod b/docs/Archaeology.pod index 1fce7466..fed25910 100644 --- a/docs/Archaeology.pod +++ b/docs/Archaeology.pod @@ -61,7 +61,7 @@ Returns a summary of all glyphs that may be assembled in this archaeology minist { "id" : "id-goes-here", "type: : "bauxite", - "type" : "bauxite", + "name" : "bauxite", "quantity" : 2 }, ... diff --git a/etc/lacuna.conf.template b/etc/lacuna.conf.template index 81a36a1e..1ff561b2 100644 --- a/etc/lacuna.conf.template +++ b/etc/lacuna.conf.template @@ -1,6 +1,13 @@ # config-file-type: JSON 1 { "access_key" : "XXXX", + "bhg_param" : { +# If any are set to 0, use default. + "success" : 0, + "waste_cost" : 0, + "recovery" : 0, + "side_chance" : 0, + }, "db" : { "dsn" : "DBI:mysql:XXXX", "password" : "XXXX", @@ -51,6 +58,26 @@ "port" : "11211" } ], + "neutral_zone" : { +# If zone is set to a valid zone, x & y are confined to within that zone. +# Coord set to 1 will further narrow Neutral area. +# Setting zone to 0 will only use x & y. +# Setting x & y outside of the zone, will result in nothing be within the NZ. + "active" : 1, + "zone" : 1, + "zone_list" : [ + "-3|0" + ], + "coord" : 0, + "x" : [ + -1000, + -750 + ], + "y" : [ + -250, + 250 + ] + }, "offline" : 0, "paypal" : { "APIPassword" : "XXXX", diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 4fe69b76..c9f91814 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0859; +our $VERSION = 3.0860; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 87c3e500..2fbbab8f 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -729,6 +729,46 @@ sub find_free_space { confess [1009, 'No free space found.']; } +sub in_neutral_zone { + my ($self) = shift; + + my $nz_param = Lacuna->config->get('neutral_zone'); + if ($nz_param) { + return 0 unless $nz_param->{active}; + my $zone = $self->zone; + my $x = $self->x; + my $y = $self->y; + if ($nz_param->{zone} and $nz_param->{coord}) { +# Needs to be in both to qualify as in + my $in_zone = 0; + for my $z_test (@{$nz_param->{zone_list}}) { + $in_zone = 1 if ($zone == $z_test); + } + return 0 unless $in_zone; + if ($x >= $nz_param->{x}[0] and + $x <= $nz_param->{x}[1] and + $y >= $nz_param->{y}[0] and + $y <= $nz_param->{y}[1])) { + return 1; + } + } + elsif ($nz_param->{zone}) { + for my $z_test (@zones) { + return 1 if ($zone == $z_test); + } + } + elsif ($nz_param->{coord}) { + if ($x >= $nz_param->{x}[0] and + $x <= $nz_param->{x}[1] and + $y >= $nz_param->{y}[0] and + $y <= $nz_param->{y}[1])) { + return 1; + } + } + } + return 0; +} + sub check_for_available_build_space { my ($self, $x, $y) = @_; if ($x > 5 || $x < -5 || $y > 5 || $y < -5) { diff --git a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm index db49fdf6..e51320b5 100644 --- a/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm +++ b/lib/Lacuna/RPC/Building/BlackHoleGenerator.pm @@ -214,12 +214,12 @@ sub generate_singularity { if ($chance->{throw} > 0) { confess [ $chance->{throw}, $chance->{reason} ]; } - my $bhg_test = Lacuna->config->get('bhg_test'); - if ($bhg_test) { - $task->{waste_cost} = $bhg_test->{waste_cost} if ($bhg_test->{waste_cost}); - $task->{recovery} = $bhg_test->{recovery} if ($bhg_test->{recovery}); - $task->{side_chance} = $bhg_test->{side_chance} if ($bhg_test->{side_chance}); - $chance->{success} = $bhg_test->{success} if ($bhg_test->{success}); + my $bhg_param = Lacuna->config->get('bhg_param'); + if ($bhg_param) { + $task->{waste_cost} = $bhg_param->{waste_cost} if ($bhg_param->{waste_cost}); + $task->{recovery} = $bhg_param->{recovery} if ($bhg_param->{recovery}); + $task->{side_chance} = $bhg_param->{side_chance} if ($bhg_param->{side_chance}); + $chance->{success} = $bhg_param->{success} if ($bhg_param->{success}); } my $btype; diff --git a/lib/Lacuna/Role/Ship/Send/NeutralZone.pm b/lib/Lacuna/Role/Ship/Send/NeutralZone.pm new file mode 100644 index 00000000..d8edd2e5 --- /dev/null +++ b/lib/Lacuna/Role/Ship/Send/NeutralZone.pm @@ -0,0 +1,11 @@ +package Lacuna::Role::Ship::Send::NeutralZone; + +use strict; +use Moose::Role; + +after can_send_to_target => sub { + my ($self, $target) = @_; + confess [1009, 'Can not be sent from the Neutral Zone.'] if $self->in_neutral_zone; + confess [1009, 'Can not be sent to the Neutral Zone.'] if $target->in_neutral_zone; + +1; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 5627dc45..efc97902 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,6 +1,7 @@ 3.0860: - Fix: Scows deliver the amount of waste in their payload, not capacity. - Fix: Space Station Command accessible via UI. + - Mod: Neutral Zone now enforced via Code. 3.0859: - Mod: Web UI, arch min has better display of glyphs, can produce multiple plans in one go -- 2.51.2 From cacf2230cc1fa7f1620a24362a6c258cec9722ea Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 12 Jul 2012 13:00:45 -0600 Subject: [PATCH 02/22] Ships, Spies, and SS can't do much from or to NZ. --- lib/Lacuna/DB/Result/Map.pm | 40 +++++++++++++++++++ lib/Lacuna/DB/Result/Map/Body/Planet.pm | 40 ------------------- lib/Lacuna/DB/Result/Ships/Bleeder.pm | 1 + lib/Lacuna/DB/Result/Ships/Detonator.pm | 1 + .../DB/Result/Ships/ObservatorySeeker.pm | 1 + lib/Lacuna/DB/Result/Ships/Placebo.pm | 1 + lib/Lacuna/DB/Result/Ships/Placebo2.pm | 1 + lib/Lacuna/DB/Result/Ships/Placebo3.pm | 1 + lib/Lacuna/DB/Result/Ships/Placebo4.pm | 1 + lib/Lacuna/DB/Result/Ships/Placebo5.pm | 1 + lib/Lacuna/DB/Result/Ships/Placebo6.pm | 1 + lib/Lacuna/DB/Result/Ships/Scanner.pm | 1 + lib/Lacuna/DB/Result/Ships/Scow.pm | 1 + lib/Lacuna/DB/Result/Ships/ScowFast.pm | 1 + lib/Lacuna/DB/Result/Ships/ScowLarge.pm | 1 + lib/Lacuna/DB/Result/Ships/ScowMega.pm | 1 + .../DB/Result/Ships/SecurityMinistrySeeker.pm | 1 + lib/Lacuna/DB/Result/Ships/Snark.pm | 1 + lib/Lacuna/DB/Result/Ships/Snark2.pm | 1 + lib/Lacuna/DB/Result/Ships/Snark3.pm | 1 + lib/Lacuna/DB/Result/Ships/SpacePortSeeker.pm | 1 + lib/Lacuna/DB/Result/Ships/SpyPod.pm | 1 + lib/Lacuna/DB/Result/Ships/SpyShuttle.pm | 1 + lib/Lacuna/DB/Result/Ships/Surveyor.pm | 1 + lib/Lacuna/DB/Result/Ships/Sweeper.pm | 1 + lib/Lacuna/DB/Result/Ships/Thud.pm | 1 + lib/Lacuna/DB/Result/Spies.pm | 4 ++ lib/Lacuna/RPC/Building/Parliament.pm | 6 +++ lib/Lacuna/Role/Ship/Send/NeutralZone.pm | 7 ++++ 29 files changed, 81 insertions(+), 40 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map.pm b/lib/Lacuna/DB/Result/Map.pm index 190cf6a4..adc91430 100644 --- a/lib/Lacuna/DB/Result/Map.pm +++ b/lib/Lacuna/DB/Result/Map.pm @@ -73,5 +73,45 @@ sub determine_zone_coord_from_xy_coord { return int($coord / zone_size); } +sub in_neutral_zone { + my ($self) = shift; + + my $nz_param = Lacuna->config->get('neutral_zone'); + if ($nz_param) { + return 0 unless $nz_param->{active}; + my $zone = $self->zone; + my $x = $self->x; + my $y = $self->y; + if ($nz_param->{zone} and $nz_param->{coord}) { +# Needs to be in both to qualify as in + my $in_zone = 0; + for my $z_test (@{$nz_param->{zone_list}}) { + $in_zone = 1 if ($zone == $z_test); + } + return 0 unless $in_zone; + if ($x >= $nz_param->{x}[0] and + $x <= $nz_param->{x}[1] and + $y >= $nz_param->{y}[0] and + $y <= $nz_param->{y}[1])) { + return 1; + } + } + elsif ($nz_param->{zone}) { + for my $z_test (@zones) { + return 1 if ($zone == $z_test); + } + } + elsif ($nz_param->{coord}) { + if ($x >= $nz_param->{x}[0] and + $x <= $nz_param->{x}[1] and + $y >= $nz_param->{y}[0] and + $y <= $nz_param->{y}[1])) { + return 1; + } + } + } + return 0; +} + no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 2fbbab8f..87c3e500 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -729,46 +729,6 @@ sub find_free_space { confess [1009, 'No free space found.']; } -sub in_neutral_zone { - my ($self) = shift; - - my $nz_param = Lacuna->config->get('neutral_zone'); - if ($nz_param) { - return 0 unless $nz_param->{active}; - my $zone = $self->zone; - my $x = $self->x; - my $y = $self->y; - if ($nz_param->{zone} and $nz_param->{coord}) { -# Needs to be in both to qualify as in - my $in_zone = 0; - for my $z_test (@{$nz_param->{zone_list}}) { - $in_zone = 1 if ($zone == $z_test); - } - return 0 unless $in_zone; - if ($x >= $nz_param->{x}[0] and - $x <= $nz_param->{x}[1] and - $y >= $nz_param->{y}[0] and - $y <= $nz_param->{y}[1])) { - return 1; - } - } - elsif ($nz_param->{zone}) { - for my $z_test (@zones) { - return 1 if ($zone == $z_test); - } - } - elsif ($nz_param->{coord}) { - if ($x >= $nz_param->{x}[0] and - $x <= $nz_param->{x}[1] and - $y >= $nz_param->{y}[0] and - $y <= $nz_param->{y}[1])) { - return 1; - } - } - } - return 0; -} - sub check_for_available_build_space { my ($self, $x, $y) = @_; if ($x > 5 || $x < -5 || $y > 5 || $y < -5) { diff --git a/lib/Lacuna/DB/Result/Ships/Bleeder.pm b/lib/Lacuna/DB/Result/Ships/Bleeder.pm index 713c857f..0d3c2b79 100644 --- a/lib/Lacuna/DB/Result/Ships/Bleeder.pm +++ b/lib/Lacuna/DB/Result/Ships/Bleeder.pm @@ -18,6 +18,7 @@ use constant base_combat => 1700; use constant base_hold_size => 0; use constant build_tags => ['War']; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Detonator.pm b/lib/Lacuna/DB/Result/Ships/Detonator.pm index 334a634b..6600f49f 100644 --- a/lib/Lacuna/DB/Result/Ships/Detonator.pm +++ b/lib/Lacuna/DB/Result/Ships/Detonator.pm @@ -18,6 +18,7 @@ use constant base_stealth => 0; use constant base_hold_size => 0; use constant build_tags => ['War']; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::AsteroidStarUninhabited"; with "Lacuna::Role::Ship::Send::IsHostile"; with "Lacuna::Role::Ship::Arrive::TriggerDefense"; diff --git a/lib/Lacuna/DB/Result/Ships/ObservatorySeeker.pm b/lib/Lacuna/DB/Result/Ships/ObservatorySeeker.pm index aedf0fba..d3606388 100644 --- a/lib/Lacuna/DB/Result/Ships/ObservatorySeeker.pm +++ b/lib/Lacuna/DB/Result/Ships/ObservatorySeeker.pm @@ -18,6 +18,7 @@ use constant base_stealth => 2700; use constant target_building => ['Lacuna::DB::Result::Building::Observatory']; use constant build_tags => ['War']; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Placebo.pm b/lib/Lacuna/DB/Result/Ships/Placebo.pm index cc547025..385ab263 100644 --- a/lib/Lacuna/DB/Result/Ships/Placebo.pm +++ b/lib/Lacuna/DB/Result/Ships/Placebo.pm @@ -18,6 +18,7 @@ use constant base_stealth => 2500; use constant base_hold_size => 0; use constant build_tags => [qw(War)]; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Placebo2.pm b/lib/Lacuna/DB/Result/Ships/Placebo2.pm index 7ee9e2a8..01bffa36 100644 --- a/lib/Lacuna/DB/Result/Ships/Placebo2.pm +++ b/lib/Lacuna/DB/Result/Ships/Placebo2.pm @@ -19,6 +19,7 @@ use constant base_hold_size => 0; use constant build_tags => [qw(War)]; use constant type_formatted => 'Placebo II'; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Placebo3.pm b/lib/Lacuna/DB/Result/Ships/Placebo3.pm index ad19d85e..111314a2 100644 --- a/lib/Lacuna/DB/Result/Ships/Placebo3.pm +++ b/lib/Lacuna/DB/Result/Ships/Placebo3.pm @@ -19,6 +19,7 @@ use constant base_hold_size => 0; use constant build_tags => [qw(War)]; use constant type_formatted => 'Placebo III'; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Placebo4.pm b/lib/Lacuna/DB/Result/Ships/Placebo4.pm index 3a947186..89fddd17 100644 --- a/lib/Lacuna/DB/Result/Ships/Placebo4.pm +++ b/lib/Lacuna/DB/Result/Ships/Placebo4.pm @@ -19,6 +19,7 @@ use constant base_hold_size => 0; use constant build_tags => [qw(War)]; use constant type_formatted => 'Placebo IV'; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Placebo5.pm b/lib/Lacuna/DB/Result/Ships/Placebo5.pm index bcbd1960..bc0585ae 100644 --- a/lib/Lacuna/DB/Result/Ships/Placebo5.pm +++ b/lib/Lacuna/DB/Result/Ships/Placebo5.pm @@ -19,6 +19,7 @@ use constant base_hold_size => 0; use constant build_tags => [qw(War)]; use constant type_formatted => 'Placebo V'; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Placebo6.pm b/lib/Lacuna/DB/Result/Ships/Placebo6.pm index 904bad1a..aae853f9 100644 --- a/lib/Lacuna/DB/Result/Ships/Placebo6.pm +++ b/lib/Lacuna/DB/Result/Ships/Placebo6.pm @@ -19,6 +19,7 @@ use constant base_hold_size => 0; use constant build_tags => [qw(War)]; use constant type_formatted => 'Placebo VI'; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Scanner.pm b/lib/Lacuna/DB/Result/Ships/Scanner.pm index c4577e06..d80f2178 100644 --- a/lib/Lacuna/DB/Result/Ships/Scanner.pm +++ b/lib/Lacuna/DB/Result/Ships/Scanner.pm @@ -18,6 +18,7 @@ use constant base_stealth => 1850; use constant base_hold_size => 0; use constant build_tags => [qw(Exploration Intelligence)]; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::MaybeHostile"; with "Lacuna::Role::Ship::Arrive::TriggerDefense"; diff --git a/lib/Lacuna/DB/Result/Ships/Scow.pm b/lib/Lacuna/DB/Result/Ships/Scow.pm index 249dc2ab..3a4a610b 100644 --- a/lib/Lacuna/DB/Result/Ships/Scow.pm +++ b/lib/Lacuna/DB/Result/Ships/Scow.pm @@ -18,6 +18,7 @@ use constant base_stealth => 0; use constant base_hold_size => 2000; use constant build_tags => [qw(War WasteChain)]; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::PlanetAndStar"; with "Lacuna::Role::Ship::Send::MaybeHostile"; with "Lacuna::Role::Ship::Arrive::TriggerDefense"; diff --git a/lib/Lacuna/DB/Result/Ships/ScowFast.pm b/lib/Lacuna/DB/Result/Ships/ScowFast.pm index 43e7b752..52fa8159 100644 --- a/lib/Lacuna/DB/Result/Ships/ScowFast.pm +++ b/lib/Lacuna/DB/Result/Ships/ScowFast.pm @@ -20,6 +20,7 @@ use constant base_hold_size => 2000; use constant base_berth_level => 20; use constant build_tags => [qw(War WasteChain)]; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::PlanetAndStar"; with "Lacuna::Role::Ship::Send::MaybeHostile"; with "Lacuna::Role::Ship::Arrive::TriggerDefense"; diff --git a/lib/Lacuna/DB/Result/Ships/ScowLarge.pm b/lib/Lacuna/DB/Result/Ships/ScowLarge.pm index 2a3c1d1f..a0e837d4 100644 --- a/lib/Lacuna/DB/Result/Ships/ScowLarge.pm +++ b/lib/Lacuna/DB/Result/Ships/ScowLarge.pm @@ -19,6 +19,7 @@ use constant base_hold_size => 12000; use constant base_berth_level => 15; use constant build_tags => [qw(War WasteChain)]; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::PlanetAndStar"; with "Lacuna::Role::Ship::Send::MaybeHostile"; with "Lacuna::Role::Ship::Arrive::TriggerDefense"; diff --git a/lib/Lacuna/DB/Result/Ships/ScowMega.pm b/lib/Lacuna/DB/Result/Ships/ScowMega.pm index cadb28ad..263ca500 100644 --- a/lib/Lacuna/DB/Result/Ships/ScowMega.pm +++ b/lib/Lacuna/DB/Result/Ships/ScowMega.pm @@ -19,6 +19,7 @@ use constant base_hold_size => 300000; use constant base_berth_level => 25; use constant build_tags => [qw(War WasteChain)]; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::PlanetAndStar"; with "Lacuna::Role::Ship::Send::MaybeHostile"; with "Lacuna::Role::Ship::Arrive::TriggerDefense"; diff --git a/lib/Lacuna/DB/Result/Ships/SecurityMinistrySeeker.pm b/lib/Lacuna/DB/Result/Ships/SecurityMinistrySeeker.pm index a21120f5..b1bdab95 100644 --- a/lib/Lacuna/DB/Result/Ships/SecurityMinistrySeeker.pm +++ b/lib/Lacuna/DB/Result/Ships/SecurityMinistrySeeker.pm @@ -18,6 +18,7 @@ use constant base_stealth => 2700; use constant target_building => ['Lacuna::DB::Result::Building::Security','Lacuna::DB::Result::Building::Module::PoliceStation']; use constant build_tags => ['War']; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Snark.pm b/lib/Lacuna/DB/Result/Ships/Snark.pm index 3986868d..ceb5c997 100644 --- a/lib/Lacuna/DB/Result/Ships/Snark.pm +++ b/lib/Lacuna/DB/Result/Ships/Snark.pm @@ -18,6 +18,7 @@ use constant base_combat => 2000; use constant base_hold_size => 0; use constant build_tags => ['War']; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Snark2.pm b/lib/Lacuna/DB/Result/Ships/Snark2.pm index c1f5e86e..aa9b0907 100644 --- a/lib/Lacuna/DB/Result/Ships/Snark2.pm +++ b/lib/Lacuna/DB/Result/Ships/Snark2.pm @@ -20,6 +20,7 @@ use constant build_tags => ['War']; use constant type_formatted => 'Snark II'; use constant splash_radius => 1; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Snark3.pm b/lib/Lacuna/DB/Result/Ships/Snark3.pm index d4248a6f..0ff3229f 100644 --- a/lib/Lacuna/DB/Result/Ships/Snark3.pm +++ b/lib/Lacuna/DB/Result/Ships/Snark3.pm @@ -20,6 +20,7 @@ use constant build_tags => ['War']; use constant type_formatted => 'Snark III'; use constant splash_radius => 2; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/SpacePortSeeker.pm b/lib/Lacuna/DB/Result/Ships/SpacePortSeeker.pm index 9007ffb3..064ad0a7 100644 --- a/lib/Lacuna/DB/Result/Ships/SpacePortSeeker.pm +++ b/lib/Lacuna/DB/Result/Ships/SpacePortSeeker.pm @@ -18,6 +18,7 @@ use constant base_stealth => 2700; use constant target_building => ['Lacuna::DB::Result::Building::SpacePort']; use constant build_tags => ['War']; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/SpyPod.pm b/lib/Lacuna/DB/Result/Ships/SpyPod.pm index 1de8b103..40d8f587 100644 --- a/lib/Lacuna/DB/Result/Ships/SpyPod.pm +++ b/lib/Lacuna/DB/Result/Ships/SpyPod.pm @@ -19,6 +19,7 @@ use constant pilotable => 1; use constant build_tags => ['Intelligence']; use constant max_occupants => 1; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/SpyShuttle.pm b/lib/Lacuna/DB/Result/Ships/SpyShuttle.pm index 6a9d878b..073951d1 100644 --- a/lib/Lacuna/DB/Result/Ships/SpyShuttle.pm +++ b/lib/Lacuna/DB/Result/Ships/SpyShuttle.pm @@ -19,6 +19,7 @@ use constant pilotable => 1; use constant build_tags => ['Intelligence']; use constant max_occupants => 4; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Ships/Surveyor.pm b/lib/Lacuna/DB/Result/Ships/Surveyor.pm index 5d1b6bd5..5e83e4d6 100644 --- a/lib/Lacuna/DB/Result/Ships/Surveyor.pm +++ b/lib/Lacuna/DB/Result/Ships/Surveyor.pm @@ -18,6 +18,7 @@ use constant base_stealth => 3000; use constant base_hold_size => 0; use constant build_tags => [qw(Exploration Intelligence)]; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::MaybeHostile"; with "Lacuna::Role::Ship::Arrive::TriggerDefense"; diff --git a/lib/Lacuna/DB/Result/Ships/Sweeper.pm b/lib/Lacuna/DB/Result/Ships/Sweeper.pm index ac5b0353..2ecb383a 100644 --- a/lib/Lacuna/DB/Result/Ships/Sweeper.pm +++ b/lib/Lacuna/DB/Result/Ships/Sweeper.pm @@ -18,6 +18,7 @@ use constant base_stealth => 2800; use constant pilotable => 1; use constant build_tags => ['War']; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Body"; with "Lacuna::Role::Ship::Send::NotIsolationist"; with "Lacuna::Role::Ship::Send::IsHostile"; diff --git a/lib/Lacuna/DB/Result/Ships/Thud.pm b/lib/Lacuna/DB/Result/Ships/Thud.pm index 7e41d103..223b6f11 100644 --- a/lib/Lacuna/DB/Result/Ships/Thud.pm +++ b/lib/Lacuna/DB/Result/Ships/Thud.pm @@ -18,6 +18,7 @@ use constant base_combat => 2100; use constant base_hold_size => 0; use constant build_tags => ['War']; +with "Lacuna::Role::Ship::Send::NeutralZone"; with "Lacuna::Role::Ship::Send::Planet"; with "Lacuna::Role::Ship::Send::Inhabited"; with "Lacuna::Role::Ship::Send::NotIsolationist"; diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index be093622..21cc78c5 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -241,6 +241,10 @@ sub get_possible_assignments { if ($self->on_body->empire_id == $self->from_body->empire_id) { push @assignments, $self->defensive_assignments; } + # In or from the Neutral Zone, defense only + elsif ($self->on_body->in_neutral_zone or $self->from_body->in_neutral_zone) { + push @assignments, $self->defensive_assignments; + } # at allies you can defend and attack elsif ($self->on_body->empire->alliance_id && $self->on_body->empire->alliance_id == $self->from_body->empire->alliance_id) { diff --git a/lib/Lacuna/RPC/Building/Parliament.pm b/lib/Lacuna/RPC/Building/Parliament.pm index b965373a..02514c8c 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -279,10 +279,16 @@ sub propose_seize_star { unless ($star_id) { confess [1002, 'Must specify a star id to seize.']; } + if ($self->in_neutral_zone) { + confess [1009, 'Your station is in the Neutral Zone and is not allowed to seize any star.']; + } my $star = Lacuna->db->resultset('Lacuna::DB::Result::Map::Star')->find($star_id); unless (defined $star) { confess [1002, 'Could not find the star.']; } + if ($star->in_neutral_zone) { + confess [1009, 'That star is in the Neutral Zone and can not be seized.']; + } if ($star->station_id) { confess [1009, 'That star is already controlled by a station.']; } diff --git a/lib/Lacuna/Role/Ship/Send/NeutralZone.pm b/lib/Lacuna/Role/Ship/Send/NeutralZone.pm index d8edd2e5..69020ac5 100644 --- a/lib/Lacuna/Role/Ship/Send/NeutralZone.pm +++ b/lib/Lacuna/Role/Ship/Send/NeutralZone.pm @@ -5,6 +5,13 @@ use Moose::Role; after can_send_to_target => sub { my ($self, $target) = @_; +# For scows to be sent to stars. Still allows Detonators to stars, but not as bad of an issue for now. + return 1 if ($target->isa('Lacuna::DB::Result::Map::Star')); + + if (defined $target->empire_id) { + return 1 if ($target->empire_id == $self->empire_id); # We don't care if people hit themselves. + } + confess [1009, 'Can not be sent from the Neutral Zone.'] if $self->in_neutral_zone; confess [1009, 'Can not be sent to the Neutral Zone.'] if $target->in_neutral_zone; -- 2.51.2 From 6ee85cb314fd31d54de7db97c098e2f5aff56dfc Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Sat, 14 Jul 2012 16:00:54 -0400 Subject: [PATCH 03/22] Updated cron jobs --- bin/run_daily.sh | 2 ++ bin/run_four_hourly.sh | 5 +++++ bin/run_hourly.sh | 1 - bin/run_two_hourly.sh | 6 ++++++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 bin/run_four_hourly.sh create mode 100644 bin/run_two_hourly.sh diff --git a/bin/run_daily.sh b/bin/run_daily.sh index 53ecd872..2d73324e 100755 --- a/bin/run_daily.sh +++ b/bin/run_daily.sh @@ -8,3 +8,5 @@ perl rotate_taxes_paid.pl perl diablotin/send_attack.pl& perl saben/send_attack.pl& perl clean_up_mail.pl +perl record_rpc.pl + diff --git a/bin/run_four_hourly.sh b/bin/run_four_hourly.sh new file mode 100644 index 00000000..243e790d --- /dev/null +++ b/bin/run_four_hourly.sh @@ -0,0 +1,5 @@ +#!/bin/bash +export PATH=/data/apps/bin:$PATH +cd /data/Lacuna-Server/bin +perl summarize_spies.pl >>/var/log/four_hourly.log 2>>/var/log/four_hourly.log + diff --git a/bin/run_hourly.sh b/bin/run_hourly.sh index 34dd1173..90c1a47c 100755 --- a/bin/run_hourly.sh +++ b/bin/run_hourly.sh @@ -3,7 +3,6 @@ export PATH=/data/apps/bin:$PATH cd /data/Lacuna-Server/bin perl clean_up_empires.pl >>/tmp/hourly.log 2>>/tmp/hourly.log perl sanitize_ss.pl >>/tmp/hourly.log 2>>/tmp/hourly.log -perl tick_planets.pl >>/tmp/tick_planets.log 2>>/tmp/tick_planets.log perl summarize_server.pl >>/tmp/hourly.log 2>>/tmp/hourly.log perl summarize_economy.pl >>/tmp/hourly.log 2>>/tmp/hourly.log perl generate_news_feeds.pl >>/tmp/news_feeds.log 2>>/tmp/news_feeds.log diff --git a/bin/run_two_hourly.sh b/bin/run_two_hourly.sh new file mode 100644 index 00000000..eeb234d5 --- /dev/null +++ b/bin/run_two_hourly.sh @@ -0,0 +1,6 @@ +#!/bin/bash +export PATH=/data/apps/bin:$PATH +cd /data/Lacuna-Server/bin +perl tick_planets.pl >>/var/log/tick_planets.log 2>>/var/log/tick_planets.log +perl summarize_server.pl >>/var/log/run_two_hourly.log 2>>/var/log/run_two_hourly.log + -- 2.51.2 From 385172385c6155265ef1645cc9f98274f8fce8d1 Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Sat, 14 Jul 2012 17:21:09 -0400 Subject: [PATCH 04/22] Tidy up, removing old unwanted modules --- ...ete_all_trades.pm => delete_all_trades.pl} | 0 lib/Lacuna/DB/Result/Plans.pm | 105 ------------------ 2 files changed, 105 deletions(-) rename bin/{delete_all_trades.pm => delete_all_trades.pl} (100%) delete mode 100644 lib/Lacuna/DB/Result/Plans.pm diff --git a/bin/delete_all_trades.pm b/bin/delete_all_trades.pl similarity index 100% rename from bin/delete_all_trades.pm rename to bin/delete_all_trades.pl diff --git a/lib/Lacuna/DB/Result/Plans.pm b/lib/Lacuna/DB/Result/Plans.pm deleted file mode 100644 index 42d3973e..00000000 --- a/lib/Lacuna/DB/Result/Plans.pm +++ /dev/null @@ -1,105 +0,0 @@ -package Lacuna::DB::Result::Plans; - -use 5.010; -use Moose; -use utf8; -no warnings qw(uninitialized); -extends 'Lacuna::DB::Result'; -use Lacuna::Util qw(format_date); -use DateTime; - -__PACKAGE__->table('plans'); -__PACKAGE__->add_columns( - body_id => { data_type => 'int', size => 11, is_nullable => 0 }, - class => { data_type => 'varchar', size => 255, is_nullable => 0 }, - level => { data_type => 'tinyint', is_nullable => 0 }, - extra_build_level => { data_type => 'tinyint', is_nullable => 1, default_value => 0 }, -); - -sub level_formatted { - my $self = shift; - my $level = $self->level; - if ($self->extra_build_level) { - $level .= '+'.$self->extra_build_level; - } - return $level; -} - -my $recipes = { - 'Lacuna::DB::Result::Building::Permanent::LibraryOfJith' => [qw(anthracite bauxite beryl chalcopyrite)], - 'Lacuna::DB::Result::Building::Permanent::BeeldebanNest' => [qw(anthracite trona kerogen)], - 'Lacuna::DB::Result::Building::Permanent::Sand' => [qw(bauxite)], - 'Lacuna::DB::Result::Building::Permanent::MassadsHenge' => [qw(bauxite trona kerogen monazite)], - 'Lacuna::DB::Result::Building::Permanent::CitadelOfKnope' => [qw(beryl sulfur monazite galena)], - 'Lacuna::DB::Result::Building::Permanent::AmalgusMeadow' => [qw(beryl trona)], - 'Lacuna::DB::Result::Building::Permanent::Lagoon' => [qw(chalcopyrite)], - 'Lacuna::DB::Result::Building::Permanent::GeoThermalVent' => [qw(chalcopyrite sulfur)], - 'Lacuna::DB::Result::Building::Permanent::GratchsGauntlet' => [qw(chromite bauxite gold kerogen)], - 'Lacuna::DB::Result::Building::Permanent::MalcudField' => [qw(fluorite kerogen)], - 'Lacuna::DB::Result::Building::Permanent::KalavianRuins' => [qw(galena gold)], - 'Lacuna::DB::Result::Building::Permanent::Lake' => [qw(goethite)], - 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk A' => [qw(goethite halite gypsum trona)], - 'Lacuna::DB::Result::Building::Permanent::OracleOfAnid' => [qw(gold uraninite bauxite goethite)], - 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk B' => [qw(gold anthracite uraninite bauxite)], - 'Lacuna::DB::Result::Building::Permanent::Beach1' => [qw(gypsum)], - 'Lacuna::DB::Result::Building::Permanent::Beach9' => [qw(gypsum anthracite)], - 'Lacuna::DB::Result::Building::Permanent::Beach7' => [qw(gypsum chalcopyrite)], - 'Lacuna::DB::Result::Building::Permanent::Beach11' => [qw(gypsum chromite)], - 'Lacuna::DB::Result::Building::Permanent::Beach13' => [qw(gypsum galena)], - 'Lacuna::DB::Result::Building::Permanent::Beach12' => [qw(gypsum goethite)], - 'Lacuna::DB::Result::Building::Permanent::Beach2' => [qw(gypsum gypsum)], - 'Lacuna::DB::Result::Building::Permanent::Beach5' => [qw(gypsum halite)], - 'Lacuna::DB::Result::Building::Permanent::Beach3' => [qw(gypsum magnetite)], - 'Lacuna::DB::Result::Building::Permanent::Beach10' => [qw(gypsum methane)], - 'Lacuna::DB::Result::Building::Permanent::Beach6' => [qw(gypsum rutile)], - 'Lacuna::DB::Result::Building::Permanent::Beach8' => [qw(gypsum sulfur)], - 'Lacuna::DB::Result::Building::Permanent::PantheonOfHagness' => [qw(gypsum trona beryl anthracite)], - 'Lacuna::DB::Result::Building::Permanent::Beach4' => [qw(gypsum uraninite)], - 'Lacuna::DB::Result::Building::Permanent::LapisForest' => [qw(halite anthracite)], - 'Lacuna::DB::Result::Building::Permanent::BlackHoleGenerator' => [qw(kerogen beryl anthracite monazite)], - 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk C' => [qw(kerogen methane sulfur zircon)], - 'Lacuna::DB::Result::Building::Permanent::TempleOfTheDrajilites'=> [qw(kerogen rutile chromite chalcopyrite)], - 'Lacuna::DB::Result::Building::Permanent::NaturalSpring' => [qw(magnetite halite)], - 'Lacuna::DB::Result::Building::Permanent::Volcano' => [qw(magnetite uraninite)], - 'Lacuna::DB::Result::Building::Permanent::Grove' => [qw(methane)], - 'Lacuna::DB::Result::Building::Permanent::InterDimensionalRift' => [qw(methane zircon fluorite)], - 'Lacuna::DB::Result::Building::Permanent::TerraformingPlatform' => [qw(methane zircon magnetite beryl)], - 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk D' => [qw(monazite fluorite beryl magnetite)], - 'Lacuna::DB::Result::Building::Permanent::CrashedShipSite' => [qw(monazite trona gold bauxite)], -# 'Lacuna::DB::Result::Building::Permanent::KasternsKeep' => [qw(monazite uraninite sulfur trona)], - 'Lacuna::DB::Result::Building::Permanent::Crater' => [qw(rutile)], - 'Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk E' => [qw(rutile chromite chalcopyrite galena)], - 'Lacuna::DB::Result::Building::Permanent::DentonBrambles' => [qw(rutile goethite)], - 'Lacuna::DB::Result::Building::Permanent::GasGiantPlatform' => [qw(sulfur methane galena anthracite)], - 'Lacuna::DB::Result::Building::Permanent::RockyOutcrop' => [qw(trona)], - 'Lacuna::DB::Result::Building::Permanent::AlgaePond' => [qw(uraninite methane)], - 'Lacuna::DB::Result::Building::Permanent::Ravine' => [qw(zircon methane galena fluorite)], -}; - -# given a plan class, return the glyph recipe -# (note, Halls must specify A,B,C,D or E) -# -sub get_glyph_recipe { - my ($class,$plan_class) = @_; - - return $recipes->{$plan_class}; -} - -# Given glyphs, return the plan (if any) -sub check_glyph_recipe { - my ($class, $glyphs) = @_; - - my ($plan_class) = grep {@{$recipes->{$_}} ~~ @$glyphs} keys %$recipes; - if (defined $plan_class) { - # Sort out different Halls recipes - $plan_class =~ s/HallsOfVrbansk.*$/HallsOfVrbansk/; - } - - return $plan_class; -} - - -__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Map::Body', 'body_id'); - -no Moose; -__PACKAGE__->meta->make_immutable(inline_constructor => 0); -- 2.51.2 From 6a1c32ffe5320d0e0d39b5944144c63d6b640e2d Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 16 Jul 2012 08:37:15 -0600 Subject: [PATCH 05/22] Couple errors fixed. --- lib/Lacuna/DB/Result/Map.pm | 10 +++++----- lib/Lacuna/Role/Ship/Send/NeutralZone.pm | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map.pm b/lib/Lacuna/DB/Result/Map.pm index adc91430..be704dee 100644 --- a/lib/Lacuna/DB/Result/Map.pm +++ b/lib/Lacuna/DB/Result/Map.pm @@ -86,26 +86,26 @@ sub in_neutral_zone { # Needs to be in both to qualify as in my $in_zone = 0; for my $z_test (@{$nz_param->{zone_list}}) { - $in_zone = 1 if ($zone == $z_test); + $in_zone = 1 if ($zone eq $z_test); } return 0 unless $in_zone; if ($x >= $nz_param->{x}[0] and $x <= $nz_param->{x}[1] and $y >= $nz_param->{y}[0] and - $y <= $nz_param->{y}[1])) { + $y <= $nz_param->{y}[1]) { return 1; } } elsif ($nz_param->{zone}) { - for my $z_test (@zones) { - return 1 if ($zone == $z_test); + for my $z_test (@{$nz_param->{zone_list}}) { + return 1 if ($zone eq $z_test); } } elsif ($nz_param->{coord}) { if ($x >= $nz_param->{x}[0] and $x <= $nz_param->{x}[1] and $y >= $nz_param->{y}[0] and - $y <= $nz_param->{y}[1])) { + $y <= $nz_param->{y}[1]) { return 1; } } diff --git a/lib/Lacuna/Role/Ship/Send/NeutralZone.pm b/lib/Lacuna/Role/Ship/Send/NeutralZone.pm index 69020ac5..66f6a41c 100644 --- a/lib/Lacuna/Role/Ship/Send/NeutralZone.pm +++ b/lib/Lacuna/Role/Ship/Send/NeutralZone.pm @@ -9,10 +9,12 @@ after can_send_to_target => sub { return 1 if ($target->isa('Lacuna::DB::Result::Map::Star')); if (defined $target->empire_id) { - return 1 if ($target->empire_id == $self->empire_id); # We don't care if people hit themselves. + return 1 if ($target->empire_id == $self->body->empire_id); # We don't care if people hit themselves. } - confess [1009, 'Can not be sent from the Neutral Zone.'] if $self->in_neutral_zone; + confess [1009, 'Can not be sent from the Neutral Zone.'] if $self->body->in_neutral_zone; confess [1009, 'Can not be sent to the Neutral Zone.'] if $target->in_neutral_zone; +}; + 1; -- 2.51.2 From 505bafae7ba9238b2fd36abc609bfaff7ecd760a Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 16 Jul 2012 08:38:32 -0600 Subject: [PATCH 06/22] Updated version and changes.txt --- lib/Lacuna.pm | 2 +- var/www/public/changes.txt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index c9f91814..b661ccea 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0860; +our $VERSION = 3.0861; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index efc97902..b159d5cf 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,7 +1,9 @@ +3.0861: + - Mod: Neutral Zone now enforced via Code. + 3.0860: - Fix: Scows deliver the amount of waste in their payload, not capacity. - Fix: Space Station Command accessible via UI. - - Mod: Neutral Zone now enforced via Code. 3.0859: - Mod: Web UI, arch min has better display of glyphs, can produce multiple plans in one go -- 2.51.2 From 9fba814da68132189992dbbf6e8811ec5f1f7063 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 16 Jul 2012 17:07:25 -0600 Subject: [PATCH 07/22] Zone to Area --- lib/Lacuna/Role/Ship/Send/NeutralArea.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/Lacuna/Role/Ship/Send/NeutralArea.pm diff --git a/lib/Lacuna/Role/Ship/Send/NeutralArea.pm b/lib/Lacuna/Role/Ship/Send/NeutralArea.pm new file mode 100644 index 00000000..84d3bab6 --- /dev/null +++ b/lib/Lacuna/Role/Ship/Send/NeutralArea.pm @@ -0,0 +1,20 @@ +package Lacuna::Role::Ship::Send::NeutralArea; + +use strict; +use Moose::Role; + +after can_send_to_target => sub { + my ($self, $target) = @_; +# For scows to be sent to stars. Still allows Detonators to stars, but not as bad of an issue for now. + return 1 if ($target->isa('Lacuna::DB::Result::Map::Star')); + + if (defined $target->empire_id) { + return 1 if ($target->empire_id == $self->body->empire_id); # We don't care if people hit themselves. + } + + confess [1009, 'Can not be sent from the Neutral Area.'] if $self->body->in_neutral_area; + confess [1009, 'Can not be sent to the Neutral Area.'] if $target->in_neutral_area; + +}; + +1; -- 2.51.2 From d19d37119cd33483079f711908cecc8311832fcc Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 16 Jul 2012 17:26:22 -0600 Subject: [PATCH 08/22] Glyph fix for missions. --- lib/Lacuna/DB/Result/Mission.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Mission.pm b/lib/Lacuna/DB/Result/Mission.pm index 15e00f2f..821d6fea 100644 --- a/lib/Lacuna/DB/Result/Mission.pm +++ b/lib/Lacuna/DB/Result/Mission.pm @@ -111,6 +111,7 @@ sub add_rewards { $body->update; # glyphs +# Need to restructure glyphs in Missions to account for quantity if (exists $rewards->{glyphs}) { foreach my $glyph (@{$rewards->{glyphs}}) { $body->add_glyph($glyph); @@ -135,6 +136,7 @@ sub add_rewards { } # plans +# Need to restructure plans in Missions to account for quantity if (exists $rewards->{plans}) { foreach my $plan (@{$rewards->{plans}}) { $body->add_plan($plan->{classname}, $plan->{level}, $plan->{extra_build_level}); @@ -166,7 +168,7 @@ sub spend_objectives { # glyphs if (exists $objectives->{glyphs}) { foreach my $glyph (@{$objectives->{glyphs}}) { - $body->glyphs->search({ type => $glyph },{rows => 1})->single->delete; + $body->use_glyph( $type, 1); } } -- 2.51.2 From b2a773bd46e579a2190f6aee0f50c8e29578e042 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 16 Jul 2012 18:20:50 -0600 Subject: [PATCH 09/22] Finish fix for glyph missions. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 2 +- lib/Lacuna/DB/Result/Mission.pm | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index ccc7c965..1859afdc 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -690,7 +690,7 @@ sub make_plan { $count{$type} = $self->body->use_glyph($type, $quantity); $min_used = $count{$type} if ($min_used < $count{$type}); } -# Check if all glyphs were used +# Check if all glyphs were used in case of timing issues. if ($min_used < $quantity) { for my $type (@{$glyphs}) { if ($min_used < $count{$type}) { diff --git a/lib/Lacuna/DB/Result/Mission.pm b/lib/Lacuna/DB/Result/Mission.pm index 821d6fea..8de71cbd 100644 --- a/lib/Lacuna/DB/Result/Mission.pm +++ b/lib/Lacuna/DB/Result/Mission.pm @@ -168,7 +168,7 @@ sub spend_objectives { # glyphs if (exists $objectives->{glyphs}) { foreach my $glyph (@{$objectives->{glyphs}}) { - $body->use_glyph( $type, 1); + $body->use_glyph( $glyph, 1); } } @@ -241,9 +241,17 @@ sub check_objectives { foreach my $glyph (@{$objectives->{glyphs}}) { $glyphs{$glyph}++; } - foreach my $glyph (keys %glyphs) { - if ($body->glyphs->search({ type => $glyph })->count < $glyphs{$glyph} ) { - confess [1013, 'You do not have enough '.$glyph.' glyphs needed to complete this mission.']; + foreach my $type (keys %glyphs) { + my $glyph = Lacuna->db->resultset('Lacuna::DB::Result::Glyph')->search({ + type => $type, + body_id => $body->id, + })->single; + unless (defined($glyph)) { + confess [ 1002, "You don't have any glyphs of $type."]; + } + if ($glyph->quantity < $glyphs{$type}) { + confess [ 1002, + "You don't have $glyphs{$type} glyphs of $type, you only have ".$glyph->quantity]; } } } -- 2.51.2 From 734208c847268d8f2824f3adbeb3fda26b1013f6 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 16 Jul 2012 18:25:57 -0600 Subject: [PATCH 10/22] Updated version and change.txt --- lib/Lacuna.pm | 2 +- var/www/public/changes.txt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index c9f91814..b661ccea 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0860; +our $VERSION = 3.0861; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 31118ead..0051b36b 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,6 @@ +3.0861: + - Fix: Glyphs for missions properly checked and used. + 3.0860: - Fix: Scows deliver the amount of waste in their payload, not capacity. - Fix: Space Station Command accessible via UI. -- 2.51.2 From e3d2d628a14be8d15e0de3bbdf119f8e6457ff05 Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Tue, 17 Jul 2012 13:53:50 -0400 Subject: [PATCH 11/22] Changes to calculation of resources --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 228 ++++++++++++++---------- var/www/public/changes.txt | 3 + 2 files changed, 135 insertions(+), 96 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 87c3e500..2afb2b62 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -1097,29 +1097,31 @@ sub recalc_stats { } $stats{max_berth} = 1; #calculate building production - my ($gas_giant_platforms, $terraforming_platforms, $station_command, $pantheon_of_hagness, $ore_production_hour, $ore_consumption_hour) = 0; + my ($gas_giant_platforms, $terraforming_platforms, $station_command, $pantheon_of_hagness, $ore_production_hour, $ore_consumption_hour, $food_production_hour, $food_consumption_hour) = 0; foreach my $building (@{$self->building_cache}) { - $stats{waste_capacity} += $building->waste_capacity; - $stats{water_capacity} += $building->water_capacity; + $stats{waste_capacity} += $building->waste_capacity; + $stats{water_capacity} += $building->water_capacity; $stats{energy_capacity} += $building->energy_capacity; - $stats{food_capacity} += $building->food_capacity; - $stats{ore_capacity} += $building->ore_capacity; - $stats{happiness_hour} += $building->happiness_hour; - $stats{waste_hour} += $building->waste_hour; - $stats{energy_hour} += $building->energy_hour; - $stats{water_hour} += $building->water_hour; - $ore_consumption_hour += $building->ore_consumption_hour; - $ore_production_hour += $building->ore_production_hour; - $stats{food_consumption_hour} += $building->food_consumption_hour; + $stats{food_capacity} += $building->food_capacity; + $stats{ore_capacity} += $building->ore_capacity; + $stats{happiness_hour} += $building->happiness_hour; + $stats{waste_hour} += $building->waste_hour; + $stats{energy_hour} += $building->energy_hour; + $stats{water_hour} += $building->water_hour; + $ore_consumption_hour += $building->ore_consumption_hour; + $ore_production_hour += $building->ore_production_hour; + $food_consumption_hour += $building->food_consumption_hour; + foreach my $type (@{$building->produces_food_items}) { my $method = $type.'_production_hour'; - $stats{$method} += $building->$method(); + $stats{$method} += $building->$method(); + $food_production_hour += $building->$method(); } if ($building->isa('Lacuna::DB::Result::Building::SpacePort') and $building->efficiency == 100) { $stats{max_berth} = $building->level if ($building->level > $stats{max_berth}); } if ($building->isa('Lacuna::DB::Result::Building::Ore::Ministry')) { - my $platforms = Lacuna->db->resultset('Lacuna::DB::Result::MiningPlatforms')->search({planet_id => $self->id}); + my $platforms = Lacuna->db->resultset('MiningPlatforms')->search({planet_id => $self->id}); while (my $platform = $platforms->next) { foreach my $type (ORE_TYPES) { my $method = $type.'_hour'; @@ -1129,7 +1131,7 @@ sub recalc_stats { } if ($building->isa('Lacuna::DB::Result::Building::Trade')) { # Calculate the amount of waste to deduct based on the waste_chains - my $waste_chains = Lacuna->db->resultset('Lacuna::DB::Result::WasteChain')->search({planet_id => $self->id}); + my $waste_chains = Lacuna->db->resultset('WasteChain')->search({planet_id => $self->id}); while (my $waste_chain = $waste_chains->next) { my $percent = $waste_chain->percent_transferred; $percent = $percent > 100 ? 100 : $percent; @@ -1138,7 +1140,10 @@ sub recalc_stats { $stats{waste_hour} -= $waste_hour; } # calculate the resources being chained *from* this planet - my $output_chains = Lacuna->db->resultset('Lacuna::DB::Result::SupplyChain')->search({planet_id => $self->id}); + my $output_chains = Lacuna->db->resultset('SupplyChain')->search({ + planet_id => $self->id, + stalled => {"!=" => 1}, + }); while (my $out_chain = $output_chains->next) { my $percent = $out_chain->percent_transferred; $percent = $percent > 100 ? 100 : $percent; @@ -1162,15 +1167,17 @@ sub recalc_stats { $station_command += $building->level; } } + $stats{food_consumption_hour} = $food_consumption_hour; # active supply chains sent *to* this planet - my $input_chains = Lacuna->db->resultset('Lacuna::DB::Result::SupplyChain')->search({ - target_id => $self->id, - stalled => 0, - },{prefetch => 'building'} - ); - while (my $in_chain = $input_chains->next) { + my $input_chains = Lacuna->db->resultset('SupplyChain')->search({ + target_id => $self->id, + stalled => 0, + },{ + prefetch => 'building', + }); + while (my $in_chain = $input_chains->next) { my $percent = $in_chain->percent_transferred; $percent = $percent > 100 ? 100 : $percent; $percent *= $in_chain->building->efficiency / 100; @@ -1186,32 +1193,32 @@ sub recalc_stats { $stats{$method} += $domestic_ore_hour; } - # For all ore production that is positive, deduct a percentage for ore consumption - my $positive_ore_hour = 0; - foreach my $type (ORE_TYPES) { - my $resource_name = $self->resource_name($type); - if ($stats{$resource_name} > 0) { - $positive_ore_hour += $stats{$resource_name}; - } - } - my $reduce_factor = 1; - if ($positive_ore_hour and $positive_ore_hour >= $ore_consumption_hour) { - $reduce_factor = $ore_consumption_hour / $positive_ore_hour; - } - foreach my $type (ORE_TYPES) { - my $resource_name = $self->resource_name($type); - if ($stats{$resource_name} > 0) { - $stats{$resource_name} -= $stats{$resource_name} * $reduce_factor; - } - } - $stats{ore_hour} = $positive_ore_hour - $ore_consumption_hour; +# # For all ore production that is positive, deduct a percentage for ore consumption +# my $positive_ore_hour = 0; +# foreach my $type (ORE_TYPES) { +# my $resource_name = $self->resource_name($type); +# if ($stats{$resource_name} > 0) { +# $positive_ore_hour += $stats{$resource_name}; +# } +# } +# my $reduce_factor = 1; +# if ($positive_ore_hour and $positive_ore_hour >= $ore_consumption_hour) { +# $reduce_factor = $ore_consumption_hour / $positive_ore_hour; +# } +# foreach my $type (ORE_TYPES) { +# my $resource_name = $self->resource_name($type); +# if ($stats{$resource_name} > 0) { +# $stats{$resource_name} -= $stats{$resource_name} * $reduce_factor; +# } +# } +# $stats{ore_hour} = $positive_ore_hour - $ore_consumption_hour; # deal with negative amounts stored - $self->water_stored = 0 if $self->water_stored < 0; - $self->energy_stored = 0 if $self->energy_stored < 0; + $self->water_stored(0) if $self->water_stored < 0; + $self->energy_stored(0) if $self->energy_stored < 0; for my $type (FOOD_TYPES, ORE_TYPES) { - my $stype = $type.'_stored'; - $self->$stype(0) if ($self->$stype < 0); + my $stype = $type.'_stored'; + $self->$stype(0) if ($self->$stype < 0); } # deal with storage overages @@ -1244,20 +1251,20 @@ sub recalc_stats { $stats{plots_available} = $max_plots - $self->building_count; # Decrease happiness production if short on plots. if ($stats{plots_available} < 0) { - my $plot_tax = int(50 * 1.62 ** (abs($stats{plots_available})-1)); - # Set max to at least -10k - my $neg_hr = $self->happiness > 100_000 ? -1 * $self->happiness/10 : -10_000; + my $plot_tax = int(50 * 1.62 ** (abs($stats{plots_available})-1)); + # Set max to at least -10k + my $neg_hr = $self->happiness > 100_000 ? -1 * $self->happiness/10 : -10_000; - if ( $stats{happiness_hour} < 0 and $stats{happiness_hour} > $neg_hr) { - $stats{happiness_hour} = $neg_hr; - } - elsif ( ( $stats{happiness_hour} - $neg_hr) < $plot_tax) { - $stats{happiness_hour} = $neg_hr; - } - else { - $stats{happiness_hour} -= $plot_tax; - } - $stats{happiness_hour} = -100_000_000_000 if ($stats{happiness_hour} < -100_000_000_000); + if ( $stats{happiness_hour} < 0 and $stats{happiness_hour} > $neg_hr) { + $stats{happiness_hour} = $neg_hr; + } + elsif ( ( $stats{happiness_hour} - $neg_hr) < $plot_tax) { + $stats{happiness_hour} = $neg_hr; + } + else { + $stats{happiness_hour} -= $plot_tax; + } + $stats{happiness_hour} = -100_000_000_000 if ($stats{happiness_hour} < -100_000_000_000); } $self->update(\%stats); @@ -1356,8 +1363,6 @@ sub tick { # synchronize completion of tasks foreach my $key (sort keys %todo) { my ($object, $job) = ($todo{$key}{object}, $todo{$key}{type}); -# $object->body($self); -# weaken($object->{_relationship_data}{body}); if ($job eq 'ship built') { $self->tick_to($object->date_available); $object->finish_construction; @@ -1426,21 +1431,21 @@ sub tick_to { } # Process excavator sites if ( my $arch = $self->archaeology) { - if ($arch->efficiency == 100) { - my $dig_sec = $now->epoch - $arch->last_check->epoch; - if ($dig_sec >= 3600) { - my $dig_hours = int($dig_sec/3600); - my $new_ld = $arch->last_check->add( seconds => ($dig_hours * 3600)); - $dig_hours = 3 if $dig_hours > 3; - for (1..$dig_hours) { - $arch->run_excavators; - } - $arch->last_check($new_ld); - $arch->update; + if ($arch->efficiency == 100) { + my $dig_sec = $now->epoch - $arch->last_check->epoch; + if ($dig_sec >= 3600) { + my $dig_hours = int($dig_sec/3600); + my $new_ld = $arch->last_check->add( seconds => ($dig_hours * 3600)); + $dig_hours = 3 if $dig_hours > 3; + for (1..$dig_hours) { + $arch->run_excavators; + } + $arch->last_check($new_ld); + $arch->update; + } } - } - else { - $arch->last_check($now); + else { + $arch->last_check($now); } } # happiness @@ -1519,35 +1524,67 @@ sub tick_to { # food my %food; - my $food_produced; - my $food_hour = 0; + my $food_produced = 0; foreach my $type (FOOD_TYPES) { my $production_hour_method = $type.'_production_hour'; - $food_hour += $self->$production_hour_method; $food{$type} = sprintf('%.0f', $self->$production_hour_method() * $tick_rate); - $food_produced += $food{$type}; + if ($food{$type} > 0) { + $food_produced += $food{$type}; + } } - # subtract food consumption and save - if ($food_produced > 0) { - my $food_consumed = sprintf('%.0f', $self->food_consumption_hour * $tick_rate); + my $food_consumed = sprintf('%.0f', $self->food_consumption_hour * $tick_rate); + if ($food_produced > 0 and $food_produced >= $food_consumed) { + # Then consumption just comes out of production foreach my $type (FOOD_TYPES) { - $food{$type} -= sprintf('%.0f', ($food{$type} * $food_consumed) / $food_produced); - $self->add_food_type($type, $food{$type}); + if ($food{$type} > 0) { + $food{$type} -= sprintf('%.0f', $food{$type} * $food_consumed / $food_produced); + } +# $self->add_food_type($type, $food{$type}) if $food{$type} > 0; } } else { - $self->spend_food(abs($food_produced), 0); + # We are consuming more than we are producing + # The difference between consumed and produced comes out of storage + $food_consumed -= $food_produced; + if ($food_consumed > 0) { + my $total_food = $self->food_stored; + if ($total_food > 0) { + # + my $deduct_ratio = $food_consumed / $total_food; + foreach my $type (FOOD_TYPES) { + my $type_stored = $self->type_stored($type); + $food{$type} = 0 if $food{$type} > 0; + if ($deduct_ratio > 1) { + # then spend it all + $self->spend_food_type($type, $type_stored); + $food_consumed -= $type_stored; + } + else { + $self->spend_food_type($type, $type_stored * $deduct_ratio); + $food_consumed -= $type_stored * $deduct_ratio; + } + } + + } + # if we *still* have food to consume when we have nothing then we are in trouble! + if ($food_consumed > 0) { + # deduct an arbitrary food-stuff + $self->spend_food_type('algae', $food_consumed); + } + } } - if ($food_hour == 0 && $self->food_hour != 0) { - if ($self->food_hour < 0) { - $self->spend_food(sprintf('%.0f', abs($self->food_hour) * $tick_rate), 1); + # Now deal with remaining individual food stuffs + foreach my $type (FOOD_TYPES) { + if ($food{$type} > 0) { + $self->add_food_type($type, $food{$type}); } - else { - $self->add_food(sprintf('%.0f', $self->food_hour * $tick_rate)); + elsif ($food{$type} < 0) { + $self->spend_food_type($type, abs($food{$type})); + print STDERR "#### SPEND FOOD [$type] QUANTITY [".$food{$type}."]\n"; } } # deal with negative amounts stored - # and deal with any supply-chains + # and stall/unstall any supply-chains my @supply_chains = $self->out_supply_chains->all; if ($self->water_stored <= 0) { @@ -1566,9 +1603,8 @@ sub tick_to { } for my $type (FOOD_TYPES, ORE_TYPES) { - my $stype = $type.'_stored'; - if ($self->$stype <= 0) { - $self->$stype(0); + if ($self->type_stored($type) <= 0) { + $self->type_stored($type, 0); $self->toggle_supply_chain(\@supply_chains, $type, 1); } else { @@ -1579,12 +1615,12 @@ sub tick_to { } sub toggle_supply_chain { - my ($self, $chains_ref, $resource, $new_state) = @_; + my ($self, $chains_ref, $resource, $stalled) = @_; - my @chains = grep {$_->stalled == $new_state ? 0 : 1, $_->resource_type eq $resource } @$chains_ref; + my @chains = grep {$_->stalled != $stalled, $_->resource_type eq $resource } @$chains_ref; foreach my $chain (@chains) { - $chain->stalled($new_state); + $chain->stalled($stalled); $chain->update; $chain->target->needs_recalc(1); $chain->target->update; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 31118ead..736845c6 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,6 @@ +xxxxxx: + - Add: Added water and energy to PCC and SCC Resources details + 3.0860: - Fix: Scows deliver the amount of waste in their payload, not capacity. - Fix: Space Station Command accessible via UI. -- 2.51.2 From b21e657dadaf0caea167d269219867ac7903b3f9 Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Tue, 17 Jul 2012 17:28:57 -0400 Subject: [PATCH 12/22] Updated ore resource calculation to work like food --- lib/Lacuna/DB/Result/Map/Body.pm | 2 +- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 94 +++++++++++++++++-------- var/upgrades/3.0861.sql | 1 + 3 files changed, 66 insertions(+), 31 deletions(-) create mode 100644 var/upgrades/3.0861.sql diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index 87071dde..bc9b70a0 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -72,7 +72,7 @@ __PACKAGE__->add_columns( fluorite_hour => { data_type => 'bigint', default_value => 0 }, beryl_hour => { data_type => 'bigint', default_value => 0 }, magnetite_hour => { data_type => 'bigint', default_value => 0 }, - ore_hour => { data_type => 'bigint', default_value => 0 }, + ore_consumption_hour => { data_type => 'bigint', default_value => 0 }, food_capacity => { data_type => 'bigint', default_value => 0 }, food_consumption_hour => { data_type => 'bigint', default_value => 0 }, lapis_production_hour => { data_type => 'bigint', default_value => 0 }, diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 2eb8af61..e1c787f0 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -262,7 +262,7 @@ sub sanitize { energy_hour energy_stored energy_capacity water_hour water_stored water_capacity ore_capacity rutile_stored chromite_stored chalcopyrite_stored galena_stored gold_stored uraninite_stored bauxite_stored goethite_stored halite_stored gypsum_stored trona_stored kerogen_stored methane_stored anthracite_stored - sulfur_stored zircon_stored monazite_stored fluorite_stored beryl_stored magnetite_stored ore_hour + sulfur_stored zircon_stored monazite_stored fluorite_stored beryl_stored magnetite_stored food_capacity food_consumption_hour lapis_production_hour potato_production_hour apple_production_hour root_production_hour corn_production_hour cider_production_hour wheat_production_hour bread_production_hour soup_production_hour chip_production_hour pie_production_hour pancake_production_hour milk_production_hour @@ -1167,6 +1167,7 @@ sub recalc_stats { } } $stats{food_consumption_hour} = $food_consumption_hour; + $stats{ore_consumption_hour} = $ore_consumption_hour; # active supply chains sent *to* this planet my $input_chains = $self->in_supply_chains->search({ @@ -1191,26 +1192,6 @@ sub recalc_stats { $stats{$method} += $domestic_ore_hour; } -# # For all ore production that is positive, deduct a percentage for ore consumption -# my $positive_ore_hour = 0; -# foreach my $type (ORE_TYPES) { -# my $resource_name = $self->resource_name($type); -# if ($stats{$resource_name} > 0) { -# $positive_ore_hour += $stats{$resource_name}; -# } -# } -# my $reduce_factor = 1; -# if ($positive_ore_hour and $positive_ore_hour >= $ore_consumption_hour) { -# $reduce_factor = $ore_consumption_hour / $positive_ore_hour; -# } -# foreach my $type (ORE_TYPES) { -# my $resource_name = $self->resource_name($type); -# if ($stats{$resource_name} > 0) { -# $stats{$resource_name} -= $stats{$resource_name} * $reduce_factor; -# } -# } -# $stats{ore_hour} = $positive_ore_hour - $ore_consumption_hour; - # deal with negative amounts stored $self->water_stored(0) if $self->water_stored < 0; $self->energy_stored(0) if $self->energy_stored < 0; @@ -1474,22 +1455,65 @@ sub tick_to { } # ore + my %ore; + my $ore_produced = 0; foreach my $type (ORE_TYPES) { - my $hour_method = $type.'_hour'; - if ($self->$hour_method < 0 ) { - $self->spend_ore_type($type, sprintf('%.0f',abs($self->$hour_method) * $tick_rate)); + my $method = $type.'_hour'; + $ore{$type} = sprintf('%.0f', $self->$method() * $tick_rate); + if ($ore{$type} > 0) { + $ore_produced += $ore{$type}; } - elsif ($self->$hour_method > 0 ) { - $self->add_ore_type($type, sprintf('%.0f', $self->$hour_method * $tick_rate)); + } + my $ore_consumed = sprintf('%.0f', $self->ore_consumption_hour * $tick_rate); + if ($ore_produced > 0 and $ore_produced >= $ore_consumed) { + # then consumption comes out of production + foreach my $type (ORE_TYPES) { + if ($ore{$type} > 0) { + $ore{$type} -= sprintf('%.0f', $ore{$type} * $ore_consumed / $ore_produced); + } } } - if ($self->ore_hour > 0) { - $self->add_ore(sprintf('%.0f', $self->ore_hour * $tick_rate)); + else { + # We are consuming more than we are producing + # The difference between consumed and produced comes out of storage + $ore_consumed -= $ore_produced; + if ($ore_consumed > 0) { + my $total_ore = $self->ore_stored; + if ($total_ore > 0) { + my $deduct_ratio = $ore_consumed / $total_ore; + foreach my $type (ORE_TYPES) { + my $type_stored = $self->type_stored($type); + $ore{$type} = 0 if $ore{$type} > 0; + if ($deduct_ratio > 1) { + $self->spend_ore_type($type, $type_stored); + $ore_consumed -= $type_stored; + } + else { + $self->spend_ore_type($type, $type_stored * $deduct_ratio); + $ore_consumed -= $type_stored * $deduct_ratio; + } + } + + } + # if we *still* have ore to consume when we have nothing then we are in trouble! + if ($ore_consumed > 0) { + # deduct an arbitrary ore-stuff + $self->spend_ore_type('gold', $ore_consumed); + } + } } - if ($self->ore_hour < 0) { - $self->spend_ore(sprintf('%.0f', abs($self->ore_hour) * $tick_rate, 'complain')); + # Now deal with remaining individual ore stuffs + foreach my $type (ORE_TYPES) { + if ($ore{$type} > 0) { + $self->add_ore_type($type, $ore{$type}); + } + elsif ($ore{$type} < 0) { + $self->spend_ore_type($type, abs($ore{$type})); + print STDERR "#### SPEND ORE [$type] QUANTITY [".$ore{$type}."]\n"; + } } + # food my %food; my $food_produced = 0; @@ -1925,6 +1949,16 @@ sub spend_ore { return $self; } +sub ore_hour { + my ($self) = @_; + my $tally = 0; + foreach my $ore (ORE_TYPES) { + my $method = $ore."_hour"; + $tally += $self->$method; + } + $tally -= $self->ore_consumption_hour; + return $tally; +} sub food_hour { my ($self) = @_; diff --git a/var/upgrades/3.0861.sql b/var/upgrades/3.0861.sql new file mode 100644 index 00000000..69cb5ec3 --- /dev/null +++ b/var/upgrades/3.0861.sql @@ -0,0 +1 @@ +alter table body add column ore_consumption_hour bigint not null default 0; -- 2.51.2 From c7dc90dd201de8a6f0253fc14c4f22613f2716b3 Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Wed, 18 Jul 2012 03:45:48 -0400 Subject: [PATCH 13/22] Updated changes --- var/www/public/changes.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index f087ce59..36ffb304 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,5 +1,7 @@ 3.0861: - Add: Added water and energy to PCC and SCC Resources details +- Mod: Resource calculations now work correctly, but the proof is too large to fit in the margin. +- Mod: Supply chains that stall should no longer cause damage on the sending colony - Fix: Glyphs for missions properly checked and used. 3.0860: -- 2.51.2 From 06c6ac08f4e5e1b6df393f13a0fcc833e8d8c708 Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Wed, 18 Jul 2012 14:13:50 -0400 Subject: [PATCH 14/22] Removed diagnostic messages --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index e1c787f0..58c85ccb 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -1509,7 +1509,6 @@ sub tick_to { } elsif ($ore{$type} < 0) { $self->spend_ore_type($type, abs($ore{$type})); - print STDERR "#### SPEND ORE [$type] QUANTITY [".$ore{$type}."]\n"; } } @@ -1571,7 +1570,6 @@ sub tick_to { } elsif ($food{$type} < 0) { $self->spend_food_type($type, abs($food{$type})); - print STDERR "#### SPEND FOOD [$type] QUANTITY [".$food{$type}."]\n"; } } # deal with negative amounts stored @@ -1611,7 +1609,6 @@ sub toggle_supply_chain { my @chains = grep {$_->stalled != $stalled and $_->resource_type eq $resource } @$chains_ref; foreach my $chain (@chains) { - print STDERR "@@@ Toggle supply chain for [$resource] to [$stalled]\n"; $chain->stalled($stalled); $chain->update; $chain->target->needs_recalc(1); -- 2.51.2 From 3d2bf6dad7041caa4d22583f5805056cbf64e88c Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Thu, 19 Jul 2012 12:31:58 -0400 Subject: [PATCH 15/22] Space Stations now take damage if they run out of resources --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 58c85ccb..2252dbba 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -1498,7 +1498,7 @@ sub tick_to { # if we *still* have ore to consume when we have nothing then we are in trouble! if ($ore_consumed > 0) { # deduct an arbitrary ore-stuff - $self->spend_ore_type('gold', $ore_consumed); + $self->spend_ore_type('gold', $ore_consumed, 'complain'); } } } @@ -1559,7 +1559,7 @@ sub tick_to { # if we *still* have food to consume when we have nothing then we are in trouble! if ($food_consumed > 0) { # deduct an arbitrary food-stuff - $self->spend_food_type('algae', $food_consumed); + $self->spend_food_type('algae', $food_consumed, 'complain'); } } } -- 2.51.2 From 5cd90d68b500e6738a7dff569998aaf1f395c425 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 19 Jul 2012 12:23:22 -0600 Subject: [PATCH 16/22] Fixes for plans and glyphs being called incorrectly in functions. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 2 +- lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm | 4 ++-- lib/Lacuna/DB/Result/Spies.pm | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 1859afdc..55ac77ed 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -662,7 +662,7 @@ sub make_plan { # types my %count; if ( grep /\D/, @{$glyphs} ) { - $plan_class = Lacuna::DB::Result::Plans->check_glyph_recipe($glyphs); + $plan_class = Lacuna::DB::Result::Plan->check_glyph_recipe($glyphs); if (not $plan_class) { confess [1002, 'The glyphs specified do not fit together in that manner.']; } diff --git a/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm b/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm index aa550476..b22cc266 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent/TheDillonForge.pm @@ -64,7 +64,7 @@ sub split_plan { if (not $plan) { confess [1002, 'You cannot split a plan you do not have.']; } - my $glyphs = Lacuna::DB::Result::Plans->get_glyph_recipe($class); + my $glyphs = Lacuna::DB::Result::Plan->get_glyph_recipe($class); if (not $glyphs) { confess [1002, 'You can only split plans that have a glyph recipe.']; } @@ -147,7 +147,7 @@ before finish_work => sub { my $hall_type = $hall_types[randint(0,4)]; $plan_class .= " $hall_type"; } - my $glyphs = Lacuna::DB::Result::Plans->get_glyph_recipe($plan_class); + my $glyphs = Lacuna::DB::Result::Plan->get_glyph_recipe($plan_class); my @many_glyphs = shuffle map { @$glyphs } (1..$halls); my $glyphs_built; my $total_glyphs = 0; diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index be093622..f2178dad 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -1903,7 +1903,7 @@ sub destroy_plan { sub destroy_glyph { my ($self, $defender) = @_; - my $glyph = $self->on_body->glyphs->search(undef, {rows => 1, order_by => 'rand()'})->single; + my $glyph = $self->on_body->glyph->search(undef, {rows => 1, order_by => 'rand()'})->single; return $self->mission_objective_not_found('glyph')->id unless defined $glyph; $self->things_destroyed( $self->things_destroyed + 1 ); my $stolen = $glyph->type.' glyph'; @@ -2116,7 +2116,7 @@ sub steal_glyph { { rows => 1, order_by => 'rand()' } )->single; return $self->ship_not_found->id unless defined $ship; - my $glyph = $on_body->glyphs->search(undef, {rows => 1, order_by => 'rand()'})->single; + my $glyph = $on_body->glyph->search(undef, {rows => 1, order_by => 'rand()'})->single; return $self->mission_objective_not_found('glyph')->id unless defined $glyph; $ship->body($self->from_body); weaken($ship->{_relationship_data}{body}); @@ -2127,8 +2127,7 @@ sub steal_glyph { spies => [ $self->id ], glyphs => [ { name => $glyph->type, - quantity => $glyph->quantity, - glyph_id => $glyph->id, + quantity => 1, } ], }, ); -- 2.51.2 From cc48cd3eca5a1238f446c211ff83d8981fa1c4d6 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 19 Jul 2012 12:37:57 -0600 Subject: [PATCH 17/22] One more fix --- lib/Lacuna/RPC/Building/TheDillonForge.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/RPC/Building/TheDillonForge.pm b/lib/Lacuna/RPC/Building/TheDillonForge.pm index 401739e3..9c12f3b6 100644 --- a/lib/Lacuna/RPC/Building/TheDillonForge.pm +++ b/lib/Lacuna/RPC/Building/TheDillonForge.pm @@ -55,7 +55,7 @@ sub _forge_tasks { PLAN: for my $plan (@{$body->plan_cache}) { # Can only split plans with recipes - next PLAN if not Lacuna::DB::Result::Plans->get_glyph_recipe($plan->class); + next PLAN if not Lacuna::DB::Result::Plan->get_glyph_recipe($plan->class); my ($class) = $plan->class =~ m/Lacuna::DB::Result::Building::(.*)$/; -- 2.51.2 From 0e22cefa25969f346e60cfc3e9b00c453a118f80 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 19 Jul 2012 15:17:39 -0600 Subject: [PATCH 18/22] Fixed situation with non possible objectives in missions. --- lib/Lacuna/DB/Result/Mission.pm | 4 ++-- lib/Lacuna/RPC/Building/MissionCommand.pm | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Lacuna/DB/Result/Mission.pm b/lib/Lacuna/DB/Result/Mission.pm index 8de71cbd..caed028a 100644 --- a/lib/Lacuna/DB/Result/Mission.pm +++ b/lib/Lacuna/DB/Result/Mission.pm @@ -398,7 +398,7 @@ sub format_items { $target = $stars->find($movement->{target_star_id}); } unless (defined($target)) { - warn "fleet movement target not found"; +# warn "fleet movement target not found"; next; } push @{$item_tmp}, 'Send '.$ship->type_formatted.' to '.$target->name.' ('.$target->x.','.$target->y.').'; @@ -421,7 +421,7 @@ sub format_items { if (defined($item_tmp)) { push @{$item_arr}, @{consolidate_items($item_tmp)}; } - + return $item_arr; } diff --git a/lib/Lacuna/RPC/Building/MissionCommand.pm b/lib/Lacuna/RPC/Building/MissionCommand.pm index 1dd90dcf..cf0c773b 100644 --- a/lib/Lacuna/RPC/Building/MissionCommand.pm +++ b/lib/Lacuna/RPC/Building/MissionCommand.pm @@ -27,12 +27,16 @@ sub get_missions { next if $params->get('max_university_level') < $empire->university_level; next if Lacuna->cache->get($mission->mission_file_name, $empire->id); push @listed, $mission->mission_file_name; + my $objectives = $mission->format_objectives; + next unless defined($objectives); + my $rewards = $mission->format_rewards; + next unless defined($rewards); push @missions, { id => $mission->id, name => $params->get('name'), description => $params->get('description'), - objectives => $mission->format_objectives, - rewards => $mission->format_rewards, + objectives => $objectives, + rewards => $rewards, max_university_level => $params->get('max_university_level'), date_posted => $mission->date_posted_formatted, }; -- 2.51.2 From e2db57dc5fe79f3c72b49f5cdbb5f0f19f4513b3 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 19 Jul 2012 16:10:23 -0600 Subject: [PATCH 19/22] No stopping colony ships, etc... in Neutral area --- lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index 18f3e895..f0f23504 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -11,6 +11,9 @@ after handle_arrival_procedures => sub { # no defense at stars return unless $self->foreign_body_id; + # No defense in Neutral Area. (Can't stop colonization, mining, etc...) + return if $self->in_neutral_area; + my $body_attacked = $self->foreign_body; my $ship_body = $self->body; my $is_planet = $body_attacked->isa('Lacuna::DB::Result::Map::Body::Planet'); -- 2.51.2 From 3af244179369016d53a5bb490d9383305b97e8c4 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 19 Jul 2012 16:19:28 -0600 Subject: [PATCH 20/22] Why we test on local server first... --- lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index f0f23504..a56af9bd 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -12,7 +12,7 @@ after handle_arrival_procedures => sub { return unless $self->foreign_body_id; # No defense in Neutral Area. (Can't stop colonization, mining, etc...) - return if $self->in_neutral_area; + return if $self->foreign_body->in_neutral_area; my $body_attacked = $self->foreign_body; my $ship_body = $self->body; -- 2.51.2 From 75716be62e0b3b18420a076ec243f69d94fb502b Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Fri, 20 Jul 2012 17:57:47 -0400 Subject: [PATCH 21/22] Fixed fractional resources showing in summary --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 28 +++++++------------------ 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 2252dbba..4fd72267 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -917,8 +917,6 @@ sub build_building { sub found_colony { my ($self, $empire) = @_; $self->empire_id($empire->id); -# $self->empire($empire); -# weaken($self->{_relationship_data}{empire}); $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); $self->update; @@ -1481,17 +1479,13 @@ sub tick_to { my $total_ore = $self->ore_stored; if ($total_ore > 0) { my $deduct_ratio = $ore_consumed / $total_ore; + $deduct_ratio = 1 if $deduct_ratio > 1; foreach my $type (ORE_TYPES) { my $type_stored = $self->type_stored($type); $ore{$type} = 0 if $ore{$type} > 0; - if ($deduct_ratio > 1) { - $self->spend_ore_type($type, $type_stored); - $ore_consumed -= $type_stored; - } - else { - $self->spend_ore_type($type, $type_stored * $deduct_ratio); - $ore_consumed -= $type_stored * $deduct_ratio; - } + my $to_deduct = sprintf('%.0f', $type_stored * $deduct_ratio); + $self->spend_ore_type($type, $to_deduct); + $ore_consumed -= $to_deduct; } } @@ -1541,20 +1535,14 @@ sub tick_to { if ($total_food > 0) { # my $deduct_ratio = $food_consumed / $total_food; + $deduct_ratio = 1 if $deduct_ratio > 1; foreach my $type (FOOD_TYPES) { my $type_stored = $self->type_stored($type); $food{$type} = 0 if $food{$type} > 0; - if ($deduct_ratio > 1) { - # then spend it all - $self->spend_food_type($type, $type_stored); - $food_consumed -= $type_stored; - } - else { - $self->spend_food_type($type, $type_stored * $deduct_ratio); - $food_consumed -= $type_stored * $deduct_ratio; - } + my $to_deduct = sprintf('%.0f', $type_stored * $deduct_ratio); + $self->spend_food_type($type, $to_deduct); + $food_consumed -= $to_deduct; } - } # if we *still* have food to consume when we have nothing then we are in trouble! if ($food_consumed > 0) { -- 2.51.2 From 134037426513106ac5c697d36ec6cacb67f0c8cd Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Sat, 21 Jul 2012 11:47:28 -0400 Subject: [PATCH 22/22] Supply chains that stall send a message --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 11 +++++++++++ var/messages/stalled_chain.txt | 7 +++++++ var/www/public/changes.txt | 11 ++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 var/messages/stalled_chain.txt diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 4fd72267..86d273e7 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -1603,6 +1603,17 @@ sub toggle_supply_chain { $chain->target->update; $self->needs_recalc(1); $self->update; + my $empire = $self->empire; + if ($stalled + and defined $empire + and not $empire->check_for_repeat_message('supply_stalled'.$chain->id)) { + $empire->send_predefined_message( + filename => 'stalled_chain.txt', + params => [$self->id, $self->name, $chain->resource_type], + repeat_check=> 'supply_stalled'.$chain->id, + tags => ['Complaint','Alert'], + ); + } } } diff --git a/var/messages/stalled_chain.txt b/var/messages/stalled_chain.txt new file mode 100644 index 00000000..093d7e49 --- /dev/null +++ b/var/messages/stalled_chain.txt @@ -0,0 +1,7 @@ +Transport Workers Strike +~~~ +Transport workers on {Planet %s %s} went on strike today when stocks of %s ran out. A spokesman from the union said that Supply chains would not be restarted until such time as stocks were replenished and that furthermore the union would not be held responsible for any damage caused. + +Regards, + +Your Humble Assistant diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 2153f7a1..322c7864 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,10 +1,11 @@ 3.0861: - Mod: Neutral Zone now enforced via Code. -- Add: Added water and energy to PCC and SCC Resources details -- Mod: Resource calculations now work correctly, but the proof is too large to fit in the margin. -- Mod: Supply chains that stall should no longer cause damage on the sending colony -- Fix: Glyphs for missions properly checked and used. - + - Add: Added water and energy to PCC and SCC Resources details + - Mod: Resource calculations now work correctly, but the proof is too large to fit in the margin. + - Mod: Supply chains that stall should no longer cause damage on the sending colony + - Fix: Glyphs for missions properly checked and used. + - Add: Supply chains that stall send a message + 3.0860: - Fix: Scows deliver the amount of waste in their payload, not capacity. - Fix: Space Station Command accessible via UI. -- 2.51.2