Skip to content

Commit

Permalink
refactor undo_action class
Browse files Browse the repository at this point in the history
First we split the undo_ation into subclasses (undo_action_base, undo_action
and shroud_clearing_action) so that undo actions that don't clear shroud don't
contain the route and view_info data.
Also the non undoable actions now don't need to implement undo() and redo()

Second we move the undo action classes to different files.
  • Loading branch information
gfgtdf committed May 19, 2015
1 parent cd756b7 commit 138f7c9
Show file tree
Hide file tree
Showing 18 changed files with 909 additions and 777 deletions.
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -701,7 +701,14 @@ set(wesnoth-main_SRC
actions/create.cpp
actions/heal.cpp
actions/move.cpp
actions/shroud_clearing_action.cpp
actions/undo.cpp
actions/undo_action.cpp
actions/undo_dismiss_action.cpp
actions/undo_move_action.cpp
actions/undo_recall_action.cpp
actions/undo_recruit_action.cpp
actions/undo_update_shroud_action.cpp
actions/vision.cpp
addon/client.cpp
addon/info.cpp
Expand Down
7 changes: 7 additions & 0 deletions src/SConscript
Expand Up @@ -189,7 +189,14 @@ wesnoth_sources = Split("""
actions/create.cpp
actions/heal.cpp
actions/move.cpp
actions/shroud_clearing_action.cpp
actions/undo.cpp
actions/undo_action.cpp
actions/undo_dismiss_action.cpp
actions/undo_move_action.cpp
actions/undo_recall_action.cpp
actions/undo_recruit_action.cpp
actions/undo_update_shroud_action.cpp
actions/vision.cpp
addon/client.cpp
addon/info.cpp
Expand Down
1 change: 1 addition & 0 deletions src/actions/shroud_clearing_action.cpp
@@ -0,0 +1 @@
#include "shroud_clearing_action.hpp"
53 changes: 53 additions & 0 deletions src/actions/shroud_clearing_action.hpp
@@ -0,0 +1,53 @@
#pragma once

#include "vision.hpp"
#include "../map_location.hpp"
#include "../unit_ptr.hpp"

#include <boost/noncopyable.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/optional.hpp>
namespace actions
{
/// base class for classes that clear srhoud (move/recruit/recall)
struct shroud_clearing_action
{

shroud_clearing_action(const config& cfg)
: route()
, view_info(cfg.child_or_empty("unit"))
{
read_locations(cfg, route);
}

shroud_clearing_action(const unit_const_ptr u, const map_location& loc)
: route(1, loc)
, view_info(*u)
{

}

typedef std::vector<map_location> t_route;

shroud_clearing_action(const unit_const_ptr u, const t_route::const_iterator& begin, const t_route::const_iterator& end)
: route(begin, end)
, view_info(*u)
{

}

/// The hexes occupied by the affected unit during this action.
/// For recruits and recalls this only contains one hex.
t_route route;
/// A record of the affected unit's ability to see.
clearer_info view_info;

void write(config & cfg) const
{
write_locations(route, cfg);
view_info.write(cfg.add_child("unit"));
}

virtual ~shroud_clearing_action() {}
};
}

0 comments on commit 138f7c9

Please sign in to comment.