diff --git a/UI/FleetWnd.cpp b/UI/FleetWnd.cpp index 18c490df964..99d346477e1 100644 --- a/UI/FleetWnd.cpp +++ b/UI/FleetWnd.cpp @@ -1700,52 +1700,94 @@ class FleetsListBox : public CUIListBox { } virtual void AcceptDrops(const std::vector& wnds, const GG::Pt& pt) { - //std::cout << "FleetsListBox::AcceptDrops" << std::endl; - assert(!wnds.empty()); + DebugLogger() << "FleetsListBox::AcceptDrops"; + if (wnds.empty()) { + ErrorLogger() << "... dropped wnds empty"; + return; + } + if (!m_order_issuing_enabled) { + DebugLogger() << "... order issuing disabled, aborting"; + return; + } + + iterator drop_target_row = RowUnderPt(pt); - assert(m_order_issuing_enabled && drop_target_row != end()); + DebugLogger() << "... drop pt: " << pt; + if (drop_target_row == end()) { + DebugLogger() << "... drop row is end, aborting"; + return; + } + DebugLogger() << "... drop row is in position: " << std::distance(begin(), drop_target_row); // get drop target fleet const FleetRow* drop_target_fleet_row = boost::polymorphic_downcast(*drop_target_row); - assert(drop_target_fleet_row); - - TemporaryPtr target_fleet = GetFleet(drop_target_fleet_row->FleetID()); - assert(target_fleet); + if (!drop_target_fleet_row) { + ErrorLogger() << "... drop target not a fleet row. aborting"; + return; + } - int target_fleet_id = target_fleet->ID(); + int target_fleet_id = drop_target_fleet_row->FleetID(); + TemporaryPtr target_fleet = GetFleet(target_fleet_id); + if (!target_fleet) { + ErrorLogger() << "... unable to get target fleet with id: " << target_fleet_id; + return; + } // sort dropped Wnds to extract fleets or ships dropped. (should only be one or the other in a given drop) std::vector > dropped_fleets; std::vector > dropped_ships; + DebugLogger() << "... getting/sorting dropped fleets or ships..."; for (std::vector::const_iterator it = wnds.begin(); it != wnds.end(); ++it) { const GG::Wnd* wnd = *it; + if (drop_target_fleet_row == wnd) { + ErrorLogger() << "... ... dropped wnd is same as drop target?! skipping"; + continue; + } + if (wnd->DragDropDataType() == FLEET_DROP_TYPE_STRING) { const FleetRow* fleet_row = boost::polymorphic_downcast(wnd); - assert(fleet_row); + if (!fleet_row) { + ErrorLogger() << "... ... unable to get fleet row from dropped wnd"; + continue; + } dropped_fleets.push_back(GetFleet(fleet_row->FleetID())); } else if (wnd->DragDropDataType() == SHIP_DROP_TYPE_STRING) { const ShipRow* ship_row = boost::polymorphic_downcast(wnd); - assert(ship_row); + if (!ship_row) { + ErrorLogger() << "... ... unable to get ship row from dropped wnd"; + continue; + } dropped_ships.push_back(GetShip(ship_row->ShipID())); } } - assert(dropped_ships.empty() != dropped_fleets.empty()); // should only be dropping fleets or ships, not a mix of both + if (dropped_ships.empty() && dropped_fleets.empty()) { + ErrorLogger() << "... no ships or fleets dropped... aborting"; + return; + } + + if (dropped_ships.empty() == dropped_fleets.empty()) { + ErrorLogger() << "... dropped a mix of fleets and ships... aborting"; + return; + } int empire_id = HumanClientApp::GetApp()->EmpireID(); if (!dropped_fleets.empty()) { + DebugLogger() << " ... processing dropped " << dropped_fleets.size() << " fleets"; // dropping fleets. get each ships of all source fleets and transfer to the target fleet - //std::cout << ".... dropped " << dropped_fleets.size() << " fleets" << std::endl; for (std::vector >::const_iterator it = dropped_fleets.begin(); it != dropped_fleets.end(); ++it) { TemporaryPtr dropped_fleet = *it; - assert(dropped_fleet); + if (!dropped_fleet) { + ErrorLogger() << "... ... unable to get dropped fleet?"; + continue; + } int dropped_fleet_id = dropped_fleet->ID(); // get fleet's ships in a vector, as this is what FleetTransferOrder takes @@ -1767,8 +1809,8 @@ class FleetsListBox : public CUIListBox { } } else if (!dropped_ships.empty()) { + DebugLogger() << " ... processing dropped " << dropped_ships.size() << " ships"; // dropping ships. transfer to target fleet. - //std::cout << ".... dropped " << dropped_ships.size() << " ships" << std::endl; // get source fleet of ship(s). assumes all ships are from the same source fleet. TemporaryPtr first_ship = dropped_ships[0]; @@ -1779,7 +1821,10 @@ class FleetsListBox : public CUIListBox { std::set dropped_ships_fleets; for (std::vector >::const_iterator it = dropped_ships.begin(); it != dropped_ships.end(); ++it) { TemporaryPtr ship = *it; - assert(ship); + if (!ship) { + ErrorLogger() << "... ... couldn't get dropped ship?"; + continue; + } ship_ids_vec.push_back(ship->ID()); dropped_ships_fleets.insert(ship->FleetID()); } @@ -1800,6 +1845,7 @@ class FleetsListBox : public CUIListBox { // TODO: moderator action to transfer ships / remove empty fleets } } + DebugLogger() << "FleetsListBox::AcceptDrops finished"; } virtual void DragDropEnter(const GG::Pt& pt, const std::map& drag_drop_wnds, GG::Flags mod_keys)