Skip to content

Commit

Permalink
added basic space station infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
JT Smith committed Mar 9, 2011
1 parent 82e3720 commit 78a6ca7
Show file tree
Hide file tree
Showing 26 changed files with 511 additions and 13 deletions.
2 changes: 1 addition & 1 deletion add_a_building.txt
Expand Up @@ -7,7 +7,7 @@ add to bin/lacuna.psgi
add to Lacuna::DB::Result::Medals
add to var/www/public/resources.json
upload a medal image
upload the building images in all 4 sizes
upload the building images in all 5 sizes
create wiki entry

# if buildable
Expand Down
4 changes: 4 additions & 0 deletions bin/lacuna.psgi
Expand Up @@ -167,6 +167,10 @@ $urlmap->map(Lacuna::RPC::Building::SSLa->new->to_app_with_url);
$urlmap->map(Lacuna::RPC::Building::SSLb->new->to_app_with_url);
$urlmap->map(Lacuna::RPC::Building::SSLc->new->to_app_with_url);
$urlmap->map(Lacuna::RPC::Building::SSLd->new->to_app_with_url);
$urlmap->map(Lacuna::RPC::Building::StationCommand->new->to_app_with_url);
$urlmap->map(Lacuna::RPC::Building::Parliament->new->to_app_with_url);
$urlmap->map(Lacuna::RPC::Building::Warehouse->new->to_app_with_url);
$urlmap->map(Lacuna::RPC::Building::IBS->new->to_app_with_url);


# admin
Expand Down
6 changes: 6 additions & 0 deletions docs/Body.pod
Expand Up @@ -140,6 +140,8 @@ The id of the body you wish to retrieve the buildings on.

Provides a list of all the building types that are available to be built on a given space on a planet that are within a specific tag.

B<NOTE:> Calling C<get_buildable> on a Space Station will result in an exception. Use L<Parliament> instead.

{
"max_items_in_build_queue" : 6,
"build_queue" : {
Expand Down Expand Up @@ -296,6 +298,8 @@ A tag that will limit the list of buildings to return. Required. Cannot be C<Now

Renames a body, provided the empire attached to the session owns the body. Returns a 1 on success.

B<NOTE:> Calling C<rename> on a Space Station will result in an exception. Use L<Parliament> instead.

Throws 1000, 1002 and 1010.

=head3 session_id
Expand All @@ -316,6 +320,8 @@ The new name of the body.

Abandon's a colony, and destroys everything on the planet. Returns a status block.

B<NOTE:> Calling C<abandon> on a Space Station will result in an exception. Use L<Parliament> instead.

=head3 session_id

A session id.
Expand Down
3 changes: 2 additions & 1 deletion docs/Buildings.pod
Expand Up @@ -269,8 +269,9 @@ A session id.

The unique id of the building.

=head1 Space Station Modules


Space stations have buildings too (called Modules), but they don't behave exactly the same as ground based buildings. See the L<Modules> documentation for more information.

=head1 Building Types

Expand Down
7 changes: 7 additions & 0 deletions docs/IBS.pod
@@ -0,0 +1,7 @@
=head1 Interstellar Broadcast System Methods

Interstellar Broadcast System is accessible via the URL C</ibs>.

The list of methods below represents changes and additions to the methods that all L<Modules> share.

=cut
25 changes: 25 additions & 0 deletions docs/Modules.pod
@@ -0,0 +1,25 @@
=head1 Modules vs Buildings

Modules are special types of L<Buildings> that can only be built on a space station.

Modules produce no resources, and therefore may be built to consume resources beyond your production levels.

Modules can only be built, repaired, upgraded, downgraded, and demolished via acts of L<Parliament>. Therefore modules don't inherit the C<build>, C<upgrade>, C<downgrade>, C<demolish>, and C<repair> methods from L<Buildings>.

=head1 Module Types

Below is a list of the different types of structures that can be built on space stations in Lacuna.

=over

=item L<IBS>

=item L<Parliament>

=item L<StationCommand>

=item L<Warehouse>

=back

=cut
7 changes: 7 additions & 0 deletions docs/Parliament.pod
@@ -0,0 +1,7 @@
=head1 Parliament Methods

Parliament is accessible via the URL C</parliament>.

The list of methods below represents changes and additions to the methods that all L<Modules> share.

=cut
83 changes: 83 additions & 0 deletions docs/StationCommand.pod
@@ -0,0 +1,83 @@
=head1 Station Command Methods

Station Command Center is accessible via the URL C</stationcommand>.

The list of methods below represents changes and additions to the methods that all L<Modules> share.

=head2 view ( session_id, building_id )

Command extends the view method to include a C<planet> section.

{
"building" : { ... },
"status" : { ... },
"next_colony_cost" : 750000, # the amount of happiness required to settle your next colony
"planet" : {
"id" : "id-goes-here",
"x" : -4,
"y" : 10,
"z" : 6,
"star_id" : "id-goes-here",
"orbit" : 3,
"type" : "habitable planet",
"name" : "Earth",
"image" : "p13",
"size" : 67,
"water" : 900,
"ore" : {
"gold" : 3399,
"bauxite" : 4000,
...
},
"building_count" : 7,
"population" : 470000,
"happiness" : 3939,
"happiness_hour" : 25,
"food_stored" : 33329,
"food_capacity" : 40000,
"food_hour" : 229,
"energy_stored" : 39931,
"energy_capacity" : 43000,
"energy_hour" : 391,
"ore_hour" 284,
"ore_capacity" 35000,
"ore_stored" 1901,
"waste_hour" : 933,
"waste_stored" : 9933,
"waste_capacity" : 13000,
"water_stored" : 9929,
"water_hour" : 295,
"water_capacity" : 51050
}
}


=head2 view_plans ( session_id, building_id )

Returns a list of all the plans you've collected through various means.

{
"status" : { ... },
"plans" : [
{
"name" : "Malcud Fungus Farm",
"level" : 1,
"extra_build_level" : 5
},
...
]
}

If the C<level> is 1, and there is an C<extra_build_level>, that means that the building will be built up to 1 plus the extra build level when complete. So in the example above, it would be a level 6 directly after being built.


=head3 session_id

A session id.

=head3 building_id

The unique id of the PCC.


=cut
7 changes: 7 additions & 0 deletions docs/Warehouse.pod
@@ -0,0 +1,7 @@
=head1 Warehouse Methods

Warehouse is accessible via the URL C</warehouse>.

The list of methods below represents changes and additions to the methods that all L<Modules> share.

=cut
11 changes: 11 additions & 0 deletions lib/Lacuna/DB/Result/Building.pm
Expand Up @@ -549,6 +549,9 @@ sub has_special_resources {
sub can_build {
my ($self, $body) = @_;

# check body type
$self->can_build_on;

# check goldilox zone
if ($body->orbit < $self->min_orbit || $body->orbit > $self->max_orbit) {
confess [1013, "This building may only be built between orbits ".$self->min_orbit." and ".$self->max_orbit.".", [$self->min_orbit, $self->max_orbit]];
Expand Down Expand Up @@ -577,6 +580,14 @@ sub can_build {
return 1;
}

sub can_build_on {
my $self = shift;
if (!$self->isa('Lacuna::DB::Result::Map::Body::Planet') || $self->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) {
confess [1009, 'Can only be built on habitable planets and gas giants.'];
}
return 1;
}


# DEMOLISH

Expand Down
116 changes: 116 additions & 0 deletions lib/Lacuna/DB/Result/Building/Module.pm
@@ -0,0 +1,116 @@
package Lacuna::DB::Result::Building::Module;

use Moose;
use utf8;
no warnings qw(uninitialized);
extends 'Lacuna::DB::Result::Building';

around 'build_tags' => sub {
my ($orig, $class) = @_;
return ($orig->($class), qw(Infrastructure));
};

sub image_level {
my $self = shift;
return $self->image;
}

use constant energy_consumption => 200;
use constant water_consumption => 100;
use constant food_consumption => 100;
use constant ore_consumption => 100;
use constant energy_to_build => 500;
use constant food_to_build => 100;
use constant ore_to_build => 500;
use constant water_to_build => 150;

around spend_efficiency => sub {
my ($orig, $self, $amount) = @_;
if ($self->efficiency <= $amount) {
if ($self->level <= 1 && eval{$self->can_demolish}) {
$self->demolish;
}
elsif ($self->level > 1 && eval{$self->can_downgrade}) {
$self->downgrade;
}
else {
$orig->($self, $amount);
}
}
else {
$orig->($self, $amount);
}
return $self;
};

sub cost_to_upgrade {
return {
food => 0,
ore => 0,
water => 0,
energy => 0,
waste => 0,
time => 60,
};
}

around can_upgrade => sub {
my ($orig, $self, $cost, $from_parliament) = @_;
if ($from_parliament) {
$orig->($self, $cost);
}
else {
confess [1010, 'Space station modules can only be upgraded by an act of Parliament.'];
}
};

around can_downgrade => sub {
my ($orig, $self, $cost, $from_parliament) = @_;
if ($from_parliament) {
$orig->($self, $cost);
}
else {
confess [1010, 'Space station modules can only be downgraded by an act of Parliament.'];
}
};

around can_demolish => sub {
my ($orig, $self, $cost, $from_parliament) = @_;
if ($from_parliament) {
$orig->($self, $cost);
}
else {
confess [1010, 'Space station modules can only be demolished by an act of Parliament.'];
}
};

around can_build => sub {
my ($orig, $self, $cost, $from_parliament) = @_;
if ($from_parliament) {
$orig->($self, $cost);
}
else {
confess [1010, 'Space station modules can only be built by an act of Parliament.'];
}
};

around can_repair => sub {
my ($orig, $self, $cost, $from_parliament) = @_;
if ($from_parliament) {
$orig->($self, $cost);
}
else {
confess [1010, 'Space station modules can only be repaired by an act of Parliament.'];
}
};

sub can_build_on {
my $self = shift;
if ($self->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) {
confess [1009, 'Can only be built on space stations.'];
}
return 1;
}

no Moose;
__PACKAGE__->meta->make_immutable(inline_constructor => 0);
15 changes: 15 additions & 0 deletions lib/Lacuna/DB/Result/Building/Module/IBS.pm
@@ -0,0 +1,15 @@
package Lacuna::DB::Result::Building::Module::IBS;

use Moose;
use utf8;
no warnings qw(uninitialized);
extends 'Lacuna::DB::Result::Building::Module';

use constant controller_class => 'Lacuna::RPC::Building::IBS';
use constant image => 'ibs';
use constant name => 'Interstellar Broadcast System';
use constant max_instances_per_planet => 1;


no Moose;
__PACKAGE__->meta->make_immutable(inline_constructor => 0);
16 changes: 16 additions & 0 deletions lib/Lacuna/DB/Result/Building/Module/Parliament.pm
@@ -0,0 +1,16 @@
package Lacuna::DB::Result::Building::Module::Parliament;

use Moose;
use utf8;
no warnings qw(uninitialized);
extends 'Lacuna::DB::Result::Building::Module';

use constant controller_class => 'Lacuna::RPC::Building::Parliament';
use constant image => 'parliament';
use constant name => 'Parliament';
use constant max_instances_per_planet => 1;



no Moose;
__PACKAGE__->meta->make_immutable(inline_constructor => 0);
15 changes: 15 additions & 0 deletions lib/Lacuna/DB/Result/Building/Module/StationCommand.pm
@@ -0,0 +1,15 @@
package Lacuna::DB::Result::Building::Module::StationCommand;

use Moose;
use utf8;
no warnings qw(uninitialized);
extends 'Lacuna::DB::Result::Building::Module';

use constant controller_class => 'Lacuna::RPC::Building::StationCommand';
use constant image => 'stationcommand';
use constant name => 'Station Command Center';
use constant max_instances_per_planet => 1;


no Moose;
__PACKAGE__->meta->make_immutable(inline_constructor => 0);

0 comments on commit 78a6ca7

Please sign in to comment.