diff --git a/lib/Lacuna/DB/Result/Alliance.pm b/lib/Lacuna/DB/Result/Alliance.pm index c3124060..be6436f0 100644 --- a/lib/Lacuna/DB/Result/Alliance.pm +++ b/lib/Lacuna/DB/Result/Alliance.pm @@ -231,9 +231,35 @@ sub remove_member { elsif ($empire->id == $self->leader_id && !$delete_leader) { confess [1010, 'The leader of the alliance cannot be removed from the alliance.']; } - elsif ($empire->planets->search({ class => 'Lacuna::DB::Result::Map::Body::Planet::Station'})->count) { - confess [1010, 'A member who owns a space station cannot leave an alliance.']; + elsif ($empire->id == $self->leader_id) { +# Leader is probably self destructing, choose another leader. + my $members = $self->members; + my $last_log = DateTime->now->subtract( years => 5 ); + my $new_lead = $empire; + while (my $member = $members->next) { + if ($member->id != $self->leader_id and $member->last_login > $last_log) { + $new_lead = $member; + $last_log = $member->last_login; + } + } + $self->leader_id($new_lead->id); + $self->update; +#Send email to all alliance members notifying them of change in leadership. + } + + my $stations = $self->stations; + while (my $station = $stations->next) { + if ($station->empire_id == $empire->id) { + $station->empire_id($self->leader_id); + } + foreach my $chain ($station->in_supply_chains) { + if ($chain->planet->empire_id == $empire->id) { + $chain->delete; + } + } + $station->update; } + $empire->alliance_id(undef); $empire->update; Lacuna->db->resultset('Probes')->search({empire_id => $empire->id})->update({alliance_id => undef}); diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 5f9dabc0..a30c7a01 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -959,7 +959,13 @@ before delete => sub { if ($self->alliance_id) { my $alliance = $self->alliance; if (defined $alliance && $alliance->leader_id == $self->id) { - $alliance->delete; + my @members = $alliance->members; + if (scalar @members == 1) { + $alliance->delete; + } + else { + $alliance->remove_member($self, 1); + } } } $self->sent_messages->delete; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index b384c171..8e547b44 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -3,6 +3,9 @@ - Mod: Citadel now repels planetary debris. - Mod: Fissures cause instability, preventing planets from moving. - Mod: Fissures in starter zones don't cause damage. + - Fix: Supply Chains to Space Stations are halted if supplier leaves alliance. + - Mod: If alliance leader quits game, alliance leadership is transferred. + - Mod: If a member of an alliance leaves, space stations of member turned over to leader of alliance. 3.0892: - Fix: Fix schedule to remove past jobs when rescheduling.