Skip to content

Commit

Permalink
Replaced various fleetwnd drop handling asserts with error log output…
Browse files Browse the repository at this point in the history
… and abort, and added/uncommented various bits of debug logging output.
  • Loading branch information
geoffthemedio committed Jun 24, 2015
1 parent 75d51a8 commit 6652f69
Showing 1 changed file with 61 additions and 15 deletions.
76 changes: 61 additions & 15 deletions UI/FleetWnd.cpp
Expand Up @@ -1700,52 +1700,94 @@ class FleetsListBox : public CUIListBox {
}

virtual void AcceptDrops(const std::vector<GG::Wnd*>& 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<FleetRow*>(*drop_target_row);
assert(drop_target_fleet_row);

TemporaryPtr<Fleet> 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<Fleet> 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<TemporaryPtr<Fleet> > dropped_fleets;
std::vector<TemporaryPtr<Ship> > dropped_ships;

DebugLogger() << "... getting/sorting dropped fleets or ships...";
for (std::vector<Wnd*>::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<const FleetRow*>(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<const ShipRow*>(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<TemporaryPtr<Fleet> >::const_iterator it = dropped_fleets.begin(); it != dropped_fleets.end(); ++it) {
TemporaryPtr<const Fleet> 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
Expand All @@ -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<const Ship> first_ship = dropped_ships[0];
Expand All @@ -1779,7 +1821,10 @@ class FleetsListBox : public CUIListBox {
std::set<int> dropped_ships_fleets;
for (std::vector<TemporaryPtr<Ship> >::const_iterator it = dropped_ships.begin(); it != dropped_ships.end(); ++it) {
TemporaryPtr<const Ship> 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());
}
Expand All @@ -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<Wnd*, GG::Pt>& drag_drop_wnds, GG::Flags<GG::ModKey> mod_keys)
Expand Down

0 comments on commit 6652f69

Please sign in to comment.