Skip to content

Commit

Permalink
SS modules downgrade when they hit 0%
Browse files Browse the repository at this point in the history
  • Loading branch information
lemming552 committed Nov 26, 2013
1 parent f8a49ab commit f853b99
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions lib/Lacuna/DB/Result/Map/Body/Planet.pm
Expand Up @@ -1029,6 +1029,8 @@ sub convert_to_station {
# clean it
my @all_buildings = @{$self->building_cache};
$self->delete_buildings(\@all_buildings);
$self->_plans->delete;
$self->glyph->delete;

# add command building
my $command = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({
Expand Down Expand Up @@ -1667,6 +1669,14 @@ sub tick_to {
$self->toggle_supply_chain(\@supply_chains, $type, 0);
}
}
if ($self->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) {
my @buildings = grep {
$_->efficiency == 0
} @{$self->building_cache};
foreach my $building (@buildings) {
$building->downgrade;
}
}
$self->update;
}

Expand Down Expand Up @@ -2488,14 +2498,11 @@ sub complain_about_lack_of_resources {
# if they run out of resources in storage, then the citizens start bitching
if (!$empire->check_for_repeat_message('complaint_lack_of_'.$resource.$self->id)) {
my $building_name;
foreach my $rpcclass (shuffle (BUILDABLE_CLASSES,SPACE_STATION_MODULES)) {
my $class = $rpcclass->model_class;
next unless ('Infrastructure' ~~ [$class->build_tags]);
# Special conditions for space stations
if ($self->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) {
if ($class eq 'Lacuna::DB::Result::Building::Module::Parliament' || $class eq 'Lacuna::DB::Result::Building::Module::StationCommand') {
if ($self->isa('Lacuna::DB::Result::Map::Body::Planet::Station')) {
foreach my $building ( sort { $b->efficiency <=> $a->efficiency || rand() <=> rand() } @{$self->building_cache} ) {
if ($building->class eq 'Lacuna::DB::Result::Building::Module::Parliament' || $building->class eq 'Lacuna::DB::Result::Building::Module::StationCommand') {
my $others = grep {$_->class !~ /Parliament$|StationCommand$|Crater$/} @{$self->building_cache};
if ( $others ) {
if ($others) {
# If there are other buildings, divert power from them to keep Parliament and Station Command running as long as possible
next;
}
Expand Down Expand Up @@ -2545,6 +2552,18 @@ sub complain_about_lack_of_resources {
}
}
}
else {
$building_name = $building->name;
$building->spend_efficiency(25)->update;
last;
}
}
}
else {
my $class;
foreach my $rpcclass (shuffle (BUILDABLE_CLASSES)) {
$class = $rpcclass->model_class;
next unless ('Infrastructure' ~~ [$class->build_tags]);
}
my ($building) = grep {$_->efficiency > 0} $self->get_buildings_of_class($class);
if (defined $building) {
Expand All @@ -2564,6 +2583,5 @@ sub complain_about_lack_of_resources {
}
}


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

0 comments on commit f853b99

Please sign in to comment.