mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-09 07:40:16 +00:00
Cleaning up the undo code a little.
This commit is contained in:
parent
c308ee3518
commit
77c94414ec
@ -36,8 +36,6 @@ class unit;
|
||||
#include <deque>
|
||||
#include <sstream>
|
||||
|
||||
#define RECRUIT_POS -2
|
||||
|
||||
bool can_recruit_on(const gamemap& map, const map_location& leader, const map_location loc);
|
||||
|
||||
struct end_level_exception;
|
||||
@ -344,6 +342,8 @@ int combat_modifier(const unit_map &units, const map_location &loc,
|
||||
|
||||
/** Records information to be able to undo a movement. */
|
||||
struct undo_action {
|
||||
enum ACTION_TYPE { NONE, RECRUIT, RECALL, DISMISS};
|
||||
|
||||
undo_action(const unit& u,
|
||||
const std::vector<map_location>& rt,
|
||||
int sm, int timebonus = 0, int orig = -1) :
|
||||
@ -351,33 +351,31 @@ struct undo_action {
|
||||
starting_moves(sm),
|
||||
original_village_owner(orig),
|
||||
recall_loc(),
|
||||
recall_pos(-1),
|
||||
type(NONE),
|
||||
affected_unit(u),
|
||||
countdown_time_bonus(timebonus),
|
||||
is_dismiss(false)
|
||||
countdown_time_bonus(timebonus)
|
||||
{}
|
||||
|
||||
undo_action(const unit& u, const map_location& loc, const int pos, const bool dismiss=false) :
|
||||
undo_action(const unit& u, const map_location& loc, const ACTION_TYPE action_type=NONE) :
|
||||
route(),
|
||||
starting_moves(),
|
||||
original_village_owner(),
|
||||
recall_loc(loc),
|
||||
recall_pos(pos),
|
||||
type(action_type),
|
||||
affected_unit(u),
|
||||
countdown_time_bonus(1),
|
||||
is_dismiss(dismiss)
|
||||
countdown_time_bonus(1)
|
||||
{}
|
||||
|
||||
std::vector<map_location> route;
|
||||
int starting_moves;
|
||||
int original_village_owner;
|
||||
map_location recall_loc;
|
||||
int recall_pos; // set to RECRUIT_POS for an undo-able recruit
|
||||
ACTION_TYPE type;
|
||||
unit affected_unit;
|
||||
int countdown_time_bonus;
|
||||
bool is_dismiss; //set to true if the action is a dismissal of a recallable unit
|
||||
bool is_recall() const { return recall_pos >= 0; }
|
||||
bool is_recruit() const { return recall_pos == RECRUIT_POS; }
|
||||
bool is_dismiss() const { return type == DISMISS; }
|
||||
bool is_recall() const { return type == RECALL; }
|
||||
bool is_recruit() const { return type == RECRUIT; }
|
||||
};
|
||||
|
||||
typedef std::deque<undo_action> undo_list;
|
||||
|
@ -104,7 +104,7 @@ namespace events{
|
||||
// Remove the item from filter_textbox memory
|
||||
filter_.delete_item(menu_selection);
|
||||
//add dismissal to the undo stack
|
||||
undo_stack_.push_back(undo_action(u, map_location(), static_cast<int>(index), true));
|
||||
undo_stack_.push_back(undo_action(u, map_location(), undo_action::DISMISS));
|
||||
|
||||
//remove the unit from the recall list
|
||||
std::vector<unit>::iterator dismissed_unit = std::find_if(units_.begin(), units_.end(), boost::bind(&unit::matches_id, _1, u.id()));
|
||||
@ -803,7 +803,7 @@ private:
|
||||
|| new_unit.type()->has_random_traits()) {
|
||||
clear_undo_stack(side_num);
|
||||
} else {
|
||||
undo_stack_.push_back(undo_action(new_unit, loc, RECRUIT_POS));
|
||||
undo_stack_.push_back(undo_action(new_unit, loc, undo_action::RECRUIT));
|
||||
}
|
||||
|
||||
gui_->recalculate_minimap();
|
||||
@ -953,7 +953,7 @@ private:
|
||||
if (shroud_cleared) {
|
||||
clear_undo_stack(side_num);
|
||||
} else {
|
||||
undo_stack_.push_back(undo_action(un, loc, res));
|
||||
undo_stack_.push_back(undo_action(un, loc, undo_action::RECALL));
|
||||
}
|
||||
|
||||
redo_stack_.clear();
|
||||
@ -973,7 +973,7 @@ private:
|
||||
team ¤t_team = teams_[side_num - 1];
|
||||
|
||||
undo_action& action = undo_stack_.back();
|
||||
if (action.is_dismiss) {
|
||||
if (action.is_dismiss()) {
|
||||
//undo a dismissal
|
||||
|
||||
if(!current_team.persistent()) {
|
||||
@ -1088,7 +1088,7 @@ private:
|
||||
team ¤t_team = teams_[side_num - 1];
|
||||
|
||||
undo_action& action = redo_stack_.back();
|
||||
if (action.is_dismiss) {
|
||||
if (action.is_dismiss()) {
|
||||
if(!current_team.persistent()) {
|
||||
ERR_NG << "trying to redo a dismiss for side " << side_num
|
||||
<< ", which has no recall list!\n";
|
||||
|
Loading…
x
Reference in New Issue
Block a user