Skip to content

Commit

Permalink
Clean up population calculation, moving it to individual buildings, a…
Browse files Browse the repository at this point in the history
…llowing

some buildings to dictate their population growth rate differently than
others, including no population for bleeders, pods, and permanent buildings.
  • Loading branch information
dmcbride committed Jun 27, 2015
1 parent 3c84fb2 commit 5f2b3f3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
14 changes: 14 additions & 0 deletions lib/Lacuna/DB/Result/Building.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,20 @@ sub spend_efficiency {
return $self;
}

# POPULATION

has population => (
is => 'ro',
lazy => 1,
builder => '_build_population',
);

sub _build_population {
my ($self) = @_;

$self->effective_level * 10_000;
}

{
local *ensure_class_loaded = sub {}; # graham's crazy fix for circular dependency, may break if DynamicSubclass gets upgraded
__PACKAGE__->typecast_map(class => {
Expand Down
4 changes: 4 additions & 0 deletions lib/Lacuna/DB/Result/Building/DeployedBleeder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ use constant water_consumption => 250;
use constant waste_production => 1000;
use constant happiness_consumption => 1000;

# bleeders come with no population
sub _build_population {
0
}

no Moose;
__PACKAGE__->meta->make_immutable(inline_constructor => 0);
5 changes: 5 additions & 0 deletions lib/Lacuna/DB/Result/Building/Permanent.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ sub sortable_name {
'25'.shift->name
}

# permanent buildings come with no population
sub _build_population {
0
}

no Moose;
__PACKAGE__->meta->make_immutable(inline_constructor => 0);
4 changes: 4 additions & 0 deletions lib/Lacuna/DB/Result/Building/SupplyPod.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ use constant energy_storage => 2000;
use constant ore_storage => 2000;
use constant water_storage => 2000;

# supply pods come with no population
sub _build_population {
0
}

no Moose;
__PACKAGE__->meta->make_immutable(inline_constructor => 0);
11 changes: 3 additions & 8 deletions lib/Lacuna/DB/Result/Map/Body/Planet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use utf8;
no warnings qw(uninitialized);
extends 'Lacuna::DB::Result::Map::Body';
use Lacuna::Constants qw(FOOD_TYPES ORE_TYPES BUILDABLE_CLASSES SPACE_STATION_MODULES);
use List::Util qw(shuffle max min none);
use List::Util qw(shuffle max min none sum);
use Lacuna::Util qw(randint format_date random_element);
use DateTime;
use Data::Dumper;
Expand Down Expand Up @@ -605,13 +605,8 @@ has population => (
sub _build_population {
my ($self) = @_;

my $population = 0;
foreach my $building (@{$self->building_cache}) {
next if $building->class =~ /Lacuna::DB::Result::Building::Permanent/;
next if $building->class eq 'Lacuna::DB::Result::Building::DeployedBleeder';
$population += $building->effective_level * 10_000;
}
return $population;
my $population = sum map { $_->population } @{$self->building_cache};
return $population;
}

has building_count => (
Expand Down
1 change: 1 addition & 0 deletions var/www/public/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Add: homeworld highlighted and always at the top of the public profile
- Mod: Spies from tech levels above 15 on Jackpot are bounced automatically instead of jailed.
- Fix: allow_bhg_by_alliance rejection fixed.
- Fix: Supply Pods don't count toward population.

3.0911:
- Add: Reduce opacity for less-well-controlled stars.
Expand Down

2 comments on commit 5f2b3f3

@Imzogelmo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know whether to be honored or saddened that this never got used in the field.

@nataliethistime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It hasn't gone live yet. There's still a chance! 👿

Please sign in to comment.