Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add: Added the Waste Exchanger building.

  • Loading branch information...
commit 145504fbaa855f48e8857397e77ff1b7bb94819f 1 parent 5f509ed
@mrmuskrat mrmuskrat authored
View
1  add_a_building.txt
@@ -15,4 +15,5 @@ add to Lacuna::Constants::BUILDABLE_CLASSES
update the tech tree image
# if it's a space station module
+add to Lacuna::Constants::SPACE_STATION_MODULES
add it to the list of buildable modules in SSLa
View
1  bin/lacuna.psgi
@@ -173,6 +173,7 @@ my $app = builder {
Lacuna::RPC::Building::TerraformingPlatform
Lacuna::RPC::Building::University
Lacuna::RPC::Building::WasteEnergy
+ Lacuna::RPC::Building::WasteExchanger
Lacuna::RPC::Building::WasteRecycling
Lacuna::RPC::Building::WasteSequestration
Lacuna::RPC::Building::WasteDigester
View
2  docs/Buildings.pod
@@ -501,6 +501,8 @@ Below is a list of the different types of structures that can be built on planet
=item L<WasteEnergy>
+=item L<WasteExchanger>
+
=item L<WasteRecycling>
=item L<WasteSequestration>
View
73 docs/WasteExchanger.pod
@@ -0,0 +1,73 @@
+=head1 Waste Exchanger Methods
+
+Waste Exchanger is accessible via the URL C</wasteexchanger>.
+
+The Waste Exchanger can be used to convert waste in storage into usable resources.
+
+The list of methods below represents changes and additions to the methods that all L<Buildings> share.
+
+=head2 view ( session_id, building_id )
+
+ {
+ "status" : { ... },
+ "building" : { ... },
+ "recycle" : {
+ "seconds_remaining" : 0,
+ "can" : 1,
+ "seconds_per_resource" : "2.138", # to precalculate the time recycling will take
+ "max_recycle" : 12000,
+ "water" : 0,
+ "energy" : 0,
+ "ore" : 0
+ }
+ }
+
+
+=head2 recycle ( session_id, building_id, water, ore, energy, use_essentia )
+
+Converts waste into water, ore, and energy. You can choose which amounts of each you want, so long as their total does not go over the amount of waste you have on hand. For each unit of waste converted, the recycling center will take 10 seconds to complete the recycling process. However, the amount of time is reduced a bit by the level of the Waster Exchanger. Returns C<view>.
+
+Throws 1010 and 1011.
+
+=head3 session_id
+
+A session id.
+
+=head3 building_id
+
+The unique id of the Waste Exchanger.
+
+=head3 water
+
+An integer representing the amount of water you want.
+
+=head3 ore
+
+An integer representing the amount of ore you want.
+
+=head3 energy
+
+An integer representing the amount of energy you want.
+
+=head3 use_essentia.
+
+Defaults to 0. A boolean indicating that you wish to spend 2 essentia, to have the recycling operation completed immediately.
+
+
+
+
+=head2 subsidize_recycling ( session_id, building_id )
+
+Will spend 2 essentia to complete the current recycling job immediately. Returns C<view>.
+
+Throws 1011.
+
+=head3 session_id
+
+A session id.
+
+=head3 building_id
+
+The unique id of the Waste Exchanger building.
+
+=cut
View
2  lib/Lacuna.pm
@@ -7,7 +7,7 @@ use Config::JSON;
useall __PACKAGE__;
-our $VERSION = 3.0703;
+our $VERSION = 3.0800;
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});
View
1  lib/Lacuna/Constants.pm
@@ -82,6 +82,7 @@ use constant BUILDABLE_CLASSES => (qw(
Lacuna::RPC::Building::Transporter
Lacuna::RPC::Building::University
Lacuna::RPC::Building::WasteEnergy
+ Lacuna::RPC::Building::WasteExchanger
Lacuna::RPC::Building::WasteRecycling
Lacuna::RPC::Building::WasteSequestration
Lacuna::RPC::Building::WasteDigester
View
120 lib/Lacuna/DB/Result/Building/Waste/Exchanger.pm
@@ -0,0 +1,120 @@
+package Lacuna::DB::Result::Building::Waste::Exchanger;
+
+use Moose;
+use utf8;
+no warnings qw(uninitialized);
+extends 'Lacuna::DB::Result::Building::Waste';
+
+use constant controller_class => 'Lacuna::RPC::Building::WasteExchanger';
+
+use constant image => 'wasteexchanger';
+use constant name => 'Waste Exchanger';
+use constant university_prereq => 22;
+
+use constant energy_production => 75;
+use constant ore_production => 75;
+use constant water_production => 75;
+
+use constant food_to_build => 320;
+use constant energy_to_build => 360;
+use constant ore_to_build => 326;
+use constant water_to_build => 410;
+use constant waste_to_build => 190;
+use constant time_to_build => 670;
+
+use constant food_consumption => 16;
+use constant waste_consumption => 225;
+
+use constant waste_storage => 700;
+
+around 'build_tags' => sub {
+ my ($orig, $class) = @_;
+ return ($orig->($class), qw(Storage Energy Ore Water));
+};
+
+has max_recycle => (
+ is => 'ro',
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+ return $self->level * 17_500 * $self->body->empire->environmental_affinity;
+ },
+);
+
+has seconds_per_resource => (
+ is => 'ro',
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+ return 0.75 * $self->time_cost_reduction_bonus($self->level * 3);
+ },
+);
+
+sub can_recycle {
+ my ($self, $water, $ore, $energy, $use_essentia) = @_;
+ $water ||= 0;
+ $ore ||= 0;
+ $energy ||= 0;
+ if ($self->level < 1) {
+ confess [1010, "You can't recycle until the Waste Exchanger is built."];
+ }
+ if ($self->is_working) {
+ confess [1010, "The Waste Exchanger is busy."];
+ }
+ if ($water < 0 || $ore < 0 || $energy < 0) {
+ confess [1011, "You cannot create negative resources."];
+ }
+ if (($water + $ore + $energy) == 0) {
+ confess [1011, "You cannot recycle 0 resources."];
+ }
+ if (($water + $ore + $energy) > $self->body->waste_stored) {
+ confess [1011, "You don't have that much waste in storage.", [($water + $ore + $energy), $self->body->waste_stored]];
+ }
+ if (defined $use_essentia && $use_essentia && $self->body->empire->essentia < 2) {
+ confess [1011, "You don't have enough essentia to subsidize recycling."];
+ }
+ if (($water + $ore + $energy) > $self->max_recycle) {
+ confess [1009, "You may only recycle ".$self->max_recycle." waste at a time."];
+ }
+ return 1;
+}
+
+sub recycle {
+ my ($self, $water, $ore, $energy, $use_essentia) = @_;
+ $self->can_recycle($water, $ore, $energy, $use_essentia);
+
+ # setup
+ my $body = $self->body;
+ my $total = $water + $ore + $energy;
+
+ # start
+ my $seconds = $total * $self->seconds_per_resource;
+ $self->start_work({
+ water_from_recycling => $water,
+ ore_from_recycling => $ore,
+ energy_from_recycling => $energy,
+ }, $seconds);
+
+ # spend
+ $body->spend_waste($total);
+ if ($use_essentia) {
+ $body->empire->spend_essentia(2, 'recycling subsidy')->update;
+ $self->finish_work;
+ }
+ else {
+ $body->update;
+ $self->update;
+ }
+}
+
+before finish_work => sub {
+ my $self = shift;
+ my $planet = $self->body;
+ $planet->add_water($self->work->{water_from_recycling});
+ $planet->add_ore($self->work->{ore_from_recycling});
+ $planet->add_energy($self->work->{energy_from_recycling});
+ $planet->update;
+};
+
+no Moose;
+__PACKAGE__->meta->make_immutable(inline_constructor => 0);
View
1  lib/Lacuna/DB/Result/Medals.pm
@@ -304,6 +304,7 @@ use constant MEDALS => {
Transporter => 'Built Subspace Transporter',
University => 'Built University',
WasteEnergy => 'Built Waste Energy Plant',
+ WasteExchanger => 'Built Waste Exchanger',
WasteRecycling => 'Built Waste Recycling Center',
WasteSequestration => 'Built Waste Sequestration Well',
WasteDigester => 'Built Waste Digester',
View
70 lib/Lacuna/RPC/Building/WasteExchanger.pm
@@ -0,0 +1,70 @@
+package Lacuna::RPC::Building::WasteExchanger;
+
+use Moose;
+use utf8;
+no warnings qw(uninitialized);
+extends 'Lacuna::RPC::Building';
+
+sub app_url {
+ return '/wasteexchanger';
+}
+
+sub model_class {
+ return 'Lacuna::DB::Result::Building::Waste::Exchanger';
+}
+
+around 'view' => sub {
+ my ($orig, $self, $session_id, $building_id) = @_;
+ my $empire = $self->get_empire_by_session($session_id);
+ my $building = $self->get_building($empire, $building_id, skip_offline => 1);
+ my $out = $orig->($self, $empire, $building);
+ if ($building->is_working) {
+ $out->{recycle} = {
+ seconds_remaining => $building->work_seconds_remaining,
+ water => $building->work->{water_from_recycling},
+ ore => $building->work->{ore_from_recycling},
+ energy => $building->work->{energy_from_recycling},
+ can => 0,
+ };
+ }
+ else {
+ $out->{recycle}{can} = (eval { $building->can_recycle(1) }) ? 1 : 0;
+ }
+ $out->{recycle}{seconds_per_resource} = $building->seconds_per_resource;
+ $out->{recycle}{max_recycle} = $building->max_recycle;
+ return $out;
+};
+
+sub recycle {
+ my ($self, $session_id, $building_id, $water, $ore, $energy, $use_essentia) = @_;
+ my $empire = $self->get_empire_by_session($session_id);
+ my $building = $self->get_building($empire, $building_id);
+ $building->recycle($water, $ore, $energy, $use_essentia);
+ return $self->view($empire, $building);
+}
+
+sub subsidize_recycling {
+ my ($self, $session_id, $building_id) = @_;
+ my $empire = $self->get_empire_by_session($session_id);
+ my $building = $self->get_building($empire, $building_id);
+
+ unless ($building->is_working) {
+ confess [1010, "The Waste Exchanger isn't recycling anything."];
+ }
+
+ unless ($empire->essentia >= 2) {
+ confess [1011, "Not enough essentia."];
+ }
+
+ $building->finish_work->update;
+ $empire->spend_essentia(2, 'recycling subsidy after the fact');
+ $empire->update;
+
+ return $self->view($empire, $building);
+}
+
+__PACKAGE__->register_rpc_method_names(qw(recycle subsidize_recycling));
+
+no Moose;
+__PACKAGE__->meta->make_immutable;
+
View
3  var/www/public/changes.txt
@@ -1,4 +1,5 @@
-3.0703
+3.0800
+ - Add: Added the Waste Exchanger building.
- Fix: Space Station modules will now take damage due to lack of resources.
- Fix: Added additional check to FireBFG.
- Fix: New empires will not have smoldering craters on their newly founded planet.
View
1  var/www/public/resources.json
@@ -136,6 +136,7 @@
"/wastedigester" : { "description" : "Converts waste into ore. The higher the building level the more ore is produced and waste consumed.", "wiki" : "http://community.lacunaexpanse.com/wiki/waste-digester" },
"/wasteenergy" : { "description" : "Produces energy by burning your empire's waste. Producing energy this way is far less efficient than other types of energy production, but the benefit is that waste is reduced. The higher the building level the more energy is produced and waste consumed. In order to build and maintain the blast furnace you need a good supply of insulating ores such as zircon, beryl, and gypsum.", "wiki" : "http://community.lacunaexpanse.com/wiki/waste-energy-plant" },
"/wasterecycling" : { "description" : "Allows you to manually convert large batches of waste into energy, ore and water. The more waste you convert, the longer it will take to make the resources you want. The higher the level of the building the faster the conversion will take place. You can also spend a small amount of Essentia to convert the waste instantly.", "wiki" : "http://community.lacunaexpanse.com/wiki/waste-recycling-center" },
+ "/wasteexchanger" : { "description" : "The Waste Exchanger is a combination of a waste recycling center, waste sequestration well, and a waste treatment center. It tears apart waste at a molecular level and recombines it into useful resources.", "wiki" : "http://community.lacunaexpanse.com/wiki/waste-exchanger" },
"/wastesequestration" : { "description" : "Stores waste. Waste that is not stored turns into pollution and lowers your empire's happiness. The higher the building level the more waste can be stored.", "wiki" : "http://community.lacunaexpanse.com/wiki/waste-sequestration-well" },
"/wastetreatment" : { "description" : "Converts waste into water, ore, and energy. Waste treatment requires special chemical compounds derived from halite, sulfur, and trona.", "wiki" : "http://community.lacunaexpanse.com/wiki/waste-treatment-center" },
"/waterproduction" : { "description" : "Converts energy and ore into water. This is especially useful on planets with low concentrations of water. A higher building level means more resources are converted.", "wiki" : "http://community.lacunaexpanse.com/wiki/water-production-plant" },
Please sign in to comment.
Something went wrong with that request. Please try again.