internal void ChangeComposition(int?index, HomeportShip ship) { if (index is int i) { if (ship != null) { var fromFleet = ship.Fleet; if (fromFleet != null) { var oldIndex = fromFleet.ships.IndexOf(ship); if (fromFleet == this) { ships.Exchange(i, oldIndex); } else if (i < ships.Count) { var oldShip = ships[i]; ships.RemoveAt(i); fromFleet.ships.RemoveAt(oldIndex); ships.Insert(i, ship); fromFleet.ships.Insert(oldIndex, oldShip); } else { fromFleet.ships.Remove(ship); ships.Add(ship); } } else if (i < ships.Count) { ships[i] = ship; } else { ships.Add(ship); } } else { ships.RemoveAt(i); } } else { while (ships.Count > 1) { ships.RemoveAt(1); } } }