diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index 99d0ff47..5c98723b 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -655,12 +655,16 @@ sub can_demolish { } sub demolish { - my ($self) = @_; + my ($self, $theft) = @_; my $body = $self->body; - $body->add_waste(sprintf('%.0f',$self->ore_to_build * $self->upgrade_cost)); - $body->spend_happiness(sprintf('%.0f',$self->food_to_build * $self->upgrade_cost)); + + if (!$theft) { + $body->add_waste(sprintf('%.0f',$self->ore_to_build * $self->upgrade_cost)); + $body->spend_happiness(sprintf('%.0f',$self->food_to_build * $self->upgrade_cost)); + } # Remove the building from the cache + $self->level(0); my $idx = first_index {$_->id == $self->id} @{$body->building_cache}; if (defined $idx) { my @blist = @{$body->building_cache}; @@ -686,7 +690,7 @@ sub downgrade { my ($self, $theft) = @_; if ($self->level == 1) { $self->can_demolish; - return $self->demolish; + return $self->demolish($theft); } $self->level( $self->level - 1); $self->efficiency(100); diff --git a/lib/Lacuna/DB/Result/Building/Module/Parliament.pm b/lib/Lacuna/DB/Result/Building/Module/Parliament.pm index c9f78755..e250b9b4 100644 --- a/lib/Lacuna/DB/Result/Building/Module/Parliament.pm +++ b/lib/Lacuna/DB/Result/Building/Module/Parliament.pm @@ -19,5 +19,30 @@ sub propositions { return Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->search({station_id => $self->body->id}); } +after downgrade => sub { + my ($self, $theft) = @_; + + # if the parliament is downgraded such that certain laws aren't supported + # anymore, remove those laws. + + my @unsupported_laws; + my $level = $self->effective_level; + + push @unsupported_laws, 'Writ' if $level < 4; + push @unsupported_laws, 'Jurisdiction' if $level < 7; + push @unsupported_laws, 'MembersOnlyMiningRights' if $level < 13; + push @unsupported_laws, 'Taxation' if $level < 15; + push @unsupported_laws, 'MembersOnlyColonization' if $level < 18; + push @unsupported_laws, 'MembersOnlyExcavation' if $level < 20; + push @unsupported_laws, 'BHGNeutralized' if $level < 23; + + my $laws = $self->body->laws->search(type => { in => \@unsupported_laws }); + while (my $law = $laws->next) + { + $law->delete; + } + +}; + no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Laws.pm b/lib/Lacuna/DB/Result/Laws.pm index 13948cf9..862f1007 100644 --- a/lib/Lacuna/DB/Result/Laws.pm +++ b/lib/Lacuna/DB/Result/Laws.pm @@ -24,6 +24,7 @@ __PACKAGE__->typecast_map(type => { Jurisdiction => 'Lacuna::DB::Result::Laws::Jurisdiction', MembersOnlyColonization => 'Lacuna::DB::Result::Laws::MembersOnlyColonization', MembersOnlyMiningRights => 'Lacuna::DB::Result::Laws::MembersOnlyMiningRights', + MembersOnlyExcavation => 'Lacuna::DB::Result::Laws::MembersOnlyExcavation', Taxation => 'Lacuna::DB::Result::Laws::Taxation', Writ => 'Lacuna::DB::Result::Laws::Writ', }); diff --git a/lib/Lacuna/DB/Result/Propositions/FireBfg.pm b/lib/Lacuna/DB/Result/Propositions/FireBfg.pm index 42b8cf41..08f529fe 100644 --- a/lib/Lacuna/DB/Result/Propositions/FireBfg.pm +++ b/lib/Lacuna/DB/Result/Propositions/FireBfg.pm @@ -50,7 +50,9 @@ before pass => sub { } } elsif ($parl) { - $parl->level($parl->level - 1); + # to ensure it can be downgraded by this. + $parl->is_upgrading(0); + $parl->downgrade(1); # no point producing waste/unhappy if ($parl->level >= 1) { $parl->spend_efficiency(120); # becomes 25% @@ -59,12 +61,13 @@ before pass => sub { } else { - $parl->demolish; + # this should never happen: BFGs simply cannot pass + # if the parliament goes below 7 - nothing is still seized. $self->station->add_news(99, sprintf('The parliament of %s suffered a critical malfunction today while trying to fire their BFG.', $self->station->name)); } $self->station->update; - $self->pass_extra_message('Unfortunately, by the time the proposition passed, the station no longer had sufficient resources to fire with.'); + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the station no longer had sufficient resources to fire with and suffered major damage.'); } else { $self->pass_extra_message('Unfortunately, by the time the proposition passed, there was no parliament to enact it.');