Author: tschmitz
Date: Sat Aug 6 00:37:12 2011
New Revision: 50616
URL: http://svn.gna.org/viewcvs/wesnoth?rev=50616&view=rev
Log:
Changed signature of action::execute().
Now there are two output parameters instead of a single return value.
Modified:
trunk/src/whiteboard/action.hpp
trunk/src/whiteboard/attack.cpp
trunk/src/whiteboard/attack.hpp
trunk/src/whiteboard/move.cpp
trunk/src/whiteboard/move.hpp
trunk/src/whiteboard/recall.cpp
trunk/src/whiteboard/recall.hpp
trunk/src/whiteboard/recruit.cpp
trunk/src/whiteboard/recruit.hpp
trunk/src/whiteboard/side_actions.cpp
trunk/src/whiteboard/suppose_dead.cpp
trunk/src/whiteboard/suppose_dead.hpp
Modified: trunk/src/whiteboard/action.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/action.hpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/action.hpp (original)
+++ trunk/src/whiteboard/action.hpp Sat Aug 6 00:37:12 2011
@@ -43,12 +43,12 @@
virtual void accept(visitor& v) = 0;
- enum EXEC_RESULT {
- FAIL //< Don't delete this, and don't continue execution
- , PARTIAL //< Delete this, but don't continue execution
- , SUCCESS //< Delete this, and continue execution
- };
- virtual EXEC_RESULT execute() = 0;
+ /**
+ * Output parameters:
+ * success: Whether or not to continue an execute-all after this
execution
+ * complete: Whether or not to delete this action after execution
+ */
+ virtual void execute(bool& success, bool& complete) = 0;
/** Applies temporarily the result of this action to the specified unit
map. */
virtual void apply_temp_modifier(unit_map& unit_map) = 0;
Modified: trunk/src/whiteboard/attack.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/attack.cpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/attack.cpp (original)
+++ trunk/src/whiteboard/attack.cpp Sat Aug 6 00:37:12 2011
@@ -107,31 +107,31 @@
v.visit_attack(boost::static_pointer_cast<attack>(shared_from_this()));
}
-action::EXEC_RESULT attack::execute()
-{
- if (!valid_)
- return action::FAIL;
-
+void attack::execute(bool& success, bool& complete)
+{
//Never continue an execute-all after an attack
- action::EXEC_RESULT result = action::PARTIAL;
+ success = false;
+
+ if (!valid_) {
+ complete = false;
+ return;
+ }
LOG_WB << "Executing: " << shared_from_this() << "\n";
if (route_->steps.size() >= 2)
{
- if(move::execute() != action::SUCCESS)
- {
+ bool m_success, m_complete;
+ move::execute(m_success,m_complete);
+ if(!m_success) {
//Move failed for some reason, so don't attack.
- result = action::FAIL;
+ complete = false;
+ return;
}
}
- if (result != action::FAIL)
- {
-
resources::controller->get_mouse_handler_base().attack_enemy(get_dest_hex(),
get_target_hex(), weapon_choice_);
- //only path that doesn't return action::FAIL
- }
- return result;
+
resources::controller->get_mouse_handler_base().attack_enemy(get_dest_hex(),
get_target_hex(), weapon_choice_);
+ complete = true;
}
void attack::apply_temp_modifier(unit_map& unit_map)
Modified: trunk/src/whiteboard/attack.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/attack.hpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/attack.hpp (original)
+++ trunk/src/whiteboard/attack.hpp Sat Aug 6 00:37:12 2011
@@ -41,7 +41,7 @@
virtual void accept(visitor& v);
- virtual action::EXEC_RESULT execute();
+ virtual void execute(bool& success, bool& complete);
/** Applies temporarily the result of this action to the specified unit
map. */
virtual void apply_temp_modifier(unit_map& unit_map);
Modified: trunk/src/whiteboard/move.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.cpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/move.cpp (original)
+++ trunk/src/whiteboard/move.cpp Sat Aug 6 00:37:12 2011
@@ -221,21 +221,26 @@
v.visit_move(shared_from_this());
}
-action::EXEC_RESULT move::execute()
-{
- if (!valid_)
- return action::FAIL;
-
- if (get_source_hex() == get_dest_hex())
- return action::SUCCESS; //zero-hex move, used by attack subclass
+void move::execute(bool& success, bool& complete)
+{
+ if (!valid_) {
+ success = complete = false;
+ return;
+ }
+
+ if (get_source_hex() == get_dest_hex()) {
+ //zero-hex move, used by attack subclass
+ success = complete = true;
+ return;
+ }
//Ensure destination hex is free
- if
(get_visible_unit(get_dest_hex(),resources::teams->at(viewer_team())) != NULL)
- return action::FAIL;
+ if
(get_visible_unit(get_dest_hex(),resources::teams->at(viewer_team())) != NULL) {
+ success = complete = false;
+ return;
+ }
LOG_WB << "Executing: " << shared_from_this() << "\n";
-
- action::EXEC_RESULT result = action::FAIL;
set_arrow_brightness(ARROW_BRIGHTNESS_HIGHLIGHTED);
hide_fake_unit();
@@ -264,7 +269,7 @@
if (final_location == route_->steps.front())
{
LOG_WB << "Move execution resulted in zero movement.\n";
- result = action::FAIL;
+ success = complete = false;
}
else if (final_location.valid() &&
(unit_it = resources::units->find(final_location)) !=
resources::units->end()
@@ -272,6 +277,8 @@
{
if (steps_finished && route_->steps.back() == final_location)
//reached destination
{
+ complete = true;
+
//check if new enemies are now visible
if(enemy_sighted
||
mouse_handler.get_adj_enemies(final_location,side_number()) != adj_enemies)
@@ -280,10 +287,10 @@
//reset to a single-hex path, just in case
*this is a wb::attack
arrow_.reset();
route_->steps =
std::vector<map_location>(1,route_->steps.back());
- result = action::PARTIAL;
+ success = false;
}
else // Everything went smoothly
- result = action::SUCCESS;
+ success = true;
}
else // Move was interrupted, probably by enemy unit sighted
{
@@ -307,26 +314,26 @@
//FIXME: probably better to use the new
calculate_new_route instead of doing this
route_->steps = new_path;
arrow_->set_path(new_path);
+ success = complete = false;
}
else //Unit ended up in location outside path, likely
due to a WML event
{
- result = action::SUCCESS;
WRN_WB << "Unit ended up in location outside
path during move execution.\n";
+ success = complete = true;
}
}
}
else //Unit disappeared from the map, likely due to a WML event
{
- result = action::SUCCESS;
WRN_WB << "Unit disappeared from map during move execution.\n";
- }
-
- if(result == action::FAIL)
+ success = complete = true;
+ }
+
+ if(!complete)
{
set_arrow_brightness(ARROW_BRIGHTNESS_STANDARD);
show_fake_unit();
}
- return result;
}
map_location move::get_source_hex() const
Modified: trunk/src/whiteboard/move.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/move.hpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/move.hpp (original)
+++ trunk/src/whiteboard/move.hpp Sat Aug 6 00:37:12 2011
@@ -46,7 +46,7 @@
virtual void accept(visitor& v);
- virtual action::EXEC_RESULT execute();
+ virtual void execute(bool& success, bool& complete);
/** Return the unit targeted by this action. Null if unit doesn't
exist. */
virtual unit* get_unit() const { return unit_; }
Modified: trunk/src/whiteboard/recall.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/recall.cpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/recall.cpp (original)
+++ trunk/src/whiteboard/recall.cpp Sat Aug 6 00:37:12 2011
@@ -111,7 +111,7 @@
v.visit_recall(shared_from_this());
}
-action::EXEC_RESULT recall::execute()
+void recall::execute(bool& success, bool& complete)
{
assert(valid_);
assert(temp_unit_);
@@ -119,7 +119,7 @@
resources::controller->get_menu_handler().do_recall(*temp_unit_,
team_index() + 1, recall_hex_);
delete temp_unit_;
temp_unit_ = NULL;
- return action::SUCCESS;
+ success = complete = true;
}
void recall::apply_temp_modifier(unit_map& unit_map)
Modified: trunk/src/whiteboard/recall.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/recall.hpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/recall.hpp (original)
+++ trunk/src/whiteboard/recall.hpp Sat Aug 6 00:37:12 2011
@@ -41,7 +41,7 @@
virtual void accept(visitor& v);
- virtual action::EXEC_RESULT execute();
+ virtual void execute(bool& success, bool& complete);
/** Applies temporarily the result of this action to the specified unit
map. */
virtual void apply_temp_modifier(unit_map& unit_map);
Modified: trunk/src/whiteboard/recruit.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/recruit.cpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/recruit.cpp (original)
+++ trunk/src/whiteboard/recruit.cpp Sat Aug 6 00:37:12 2011
@@ -102,13 +102,13 @@
v.visit_recruit(shared_from_this());
}
-action::EXEC_RESULT recruit::execute()
+void recruit::execute(bool& success, bool& complete)
{
assert(valid_);
fake_unit_.reset();
int side_num = team_index() + 1;
resources::controller->get_menu_handler().do_recruit(unit_name_,
side_num, recruit_hex_);
- return action::SUCCESS;
+ success = complete = true;
}
void recruit::apply_temp_modifier(unit_map& unit_map)
Modified: trunk/src/whiteboard/recruit.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/recruit.hpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/recruit.hpp (original)
+++ trunk/src/whiteboard/recruit.hpp Sat Aug 6 00:37:12 2011
@@ -45,7 +45,7 @@
virtual void accept(visitor& v);
- virtual action::EXEC_RESULT execute();
+ virtual void execute(bool& success, bool& complete);
/** Applies temporarily the result of this action to the specified unit
map. */
virtual void apply_temp_modifier(unit_map& unit_map);
Modified: trunk/src/whiteboard/side_actions.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/side_actions.cpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.cpp (original)
+++ trunk/src/whiteboard/side_actions.cpp Sat Aug 6 00:37:12 2011
@@ -162,9 +162,10 @@
LOG_WB << "Before execution, " << *this << "\n";
action_ptr action = *position;
- action::EXEC_RESULT exec_result;
+ bool result;
+ bool should_erase;
try {
- exec_result = action->execute();
+ action->execute(result,should_erase);
} catch (end_turn_exception&) {
resources::whiteboard->queue_net_cmd(team_index_,make_net_cmd_remove(position));
actions_.erase(position);
@@ -176,33 +177,26 @@
if(resources::whiteboard->should_clear_undo())
resources::whiteboard->clear_undo();
- if(exec_result!=action::FAIL)
- {
+ LOG_WB << "After " << (result? "successful": "failed") << " execution ";
+ if(should_erase)
+ {
+ LOG_WB << "with deletion, ";
resources::whiteboard->queue_net_cmd(team_index_,make_net_cmd_remove(position));
actions_.erase(position);
}
else //action may have revised itself; let's tell our allies.
+ {
+ LOG_WB << "without deletion, ";
resources::whiteboard->queue_net_cmd(team_index_,make_net_cmd_replace(position,*position));
- switch(exec_result)
- {
- case action::SUCCESS:
- LOG_WB << "After execution and deletion, " << *this << "\n";
- break;
- case action::PARTIAL:
- LOG_WB << "After failed execution *with* deletion, " << *this
<< "\n";
- break;
- case action::FAIL:
//Idea that needs refining: move action at the end of the queue
if it failed executing:
//actions_.erase(position);
//actions_.insert(end(), action);
-
- LOG_WB << "After failed execution *without* deletion, " <<
*this << "\n";
- break;
- }
+ }
+ LOG_WB << *this << "\n";
validate_actions();
- return exec_result == action::SUCCESS;
+ return result;
}
void side_actions::hide()
Modified: trunk/src/whiteboard/suppose_dead.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/suppose_dead.cpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/suppose_dead.cpp (original)
+++ trunk/src/whiteboard/suppose_dead.cpp Sat Aug 6 00:37:12 2011
@@ -107,10 +107,8 @@
v.visit_suppose_dead(shared_from_this());
}
- action::EXEC_RESULT suppose_dead::execute()
- {
- return action::PARTIAL; //< Delete this, but don't continue
execution
- }
+ void suppose_dead::execute(bool& success, bool& complete)
+ {success = false; complete = true;}
void suppose_dead::apply_temp_modifier(unit_map& unit_map)
{
Modified: trunk/src/whiteboard/suppose_dead.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/suppose_dead.hpp?rev=50616&r1=50615&r2=50616&view=diff
==============================================================================
--- trunk/src/whiteboard/suppose_dead.hpp (original)
+++ trunk/src/whiteboard/suppose_dead.hpp Sat Aug 6 00:37:12 2011
@@ -52,7 +52,7 @@
virtual void accept(visitor& v);
- virtual action::EXEC_RESULT execute();
+ virtual void execute(bool& success, bool& complete);
/** Applies temporarily the result of this action to
the specified unit map. */
virtual void apply_temp_modifier(unit_map& unit_map);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits