Example #1
0
/**
 * Redoes this action.
 * @return true on success; false on an error.
 */
bool undo_list::recall_action::redo(int side)
{
	game_display & gui = *resources::screen;
	team &current_team = (*resources::teams)[side-1];

	if ( !current_team.persistent() ) {
		ERR_NG << "Trying to redo a recall for side " << side
			<< ", which has no recall list!\n";
		return false;
	}

	map_location loc = route.front();
	map_location from = recall_from;

	const std::vector<unit> & recalls = current_team.recall_list();
	std::vector<unit>::const_iterator unit_it = find_if_matches_id(recalls, id);
	if ( unit_it == recalls.end() ) {
		ERR_NG << "Trying to redo a recall of '" << id
		       << "', but that unit is not in the recall list.";
		return false;
	}

	const std::string &msg = find_recall_location(side, loc, from, *unit_it);
	if ( msg.empty() ) {
		recorder.redo(replay_data);
		replay_data.clear();
		set_scontext_synced sco;
		recall_unit(id, current_team, loc, from, true, false);

		// Quick error check. (Abuse of [allow_undo]?)
		if ( loc != route.front() ) {
			ERR_NG << "When redoing a recall at " << route.front()
			       << ", the location was moved to " << loc << ".\n";
			// Not really fatal, I suppose. Just update the action so
			// undoing this works.
			route.front() = loc;
		}
	} else {
		gui::dialog(gui, "", msg, gui::OK_ONLY).show();
		return false;
	}

	return true;
}
/**
 * Redoes this action.
 * @return true on success; false on an error.
 */
bool recall_action::redo(int side)
{
    game_display & gui = *resources::screen;
    team &current_team = resources::gameboard->teams()[side-1];

    map_location loc = route.front();
    map_location from = recall_from;

    unit_ptr un = current_team.recall_list().find_if_matches_id(id);
    if ( !un ) {
        ERR_NG << "Trying to redo a recall of '" << id
               << "', but that unit is not in the recall list.";
        return false;
    }

    const std::string &msg = find_recall_location(side, loc, from, *un);
    if ( msg.empty() ) {
        resources::recorder->redo(replay_data);
        replay_data.clear();
        set_scontext_synced sync;
        recall_unit(id, current_team, loc, from, true, false);

        // Quick error check. (Abuse of [allow_undo]?)
        if ( loc != route.front() ) {
            ERR_NG << "When redoing a recall at " << route.front()
                   << ", the location was moved to " << loc << ".\n";
            // Not really fatal, I suppose. Just update the action so
            // undoing this works.
            route.front() = loc;
        }
        sync.do_final_checkup();
    } else {
        gui2::show_transient_message(gui.video(), "", msg);
        return false;
    }

    return true;
}