Author: tschmitz
Date: Sun Jul 24 23:39:34 2011
New Revision: 50394
URL: http://svn.gna.org/viewcvs/wesnoth?rev=50394&view=rev
Log:
Changed return type of action::execute() from bool to enum.
It can now indicate varying degrees of success.
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=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/action.hpp (original)
+++ trunk/src/whiteboard/action.hpp Sun Jul 24 23:39:34 2011
@@ -43,8 +43,12 @@
virtual void accept(visitor& v) = 0;
- /** Returns true if the action has been completely executed and can be
deleted */
- virtual bool execute() = 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;
/** 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=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/attack.cpp (original)
+++ trunk/src/whiteboard/attack.cpp Sun Jul 24 23:39:34 2011
@@ -101,12 +101,13 @@
v.visit_attack(boost::static_pointer_cast<attack>(shared_from_this()));
}
-bool attack::execute()
-{
- bool execute_successful = true;
-
+action::EXEC_RESULT attack::execute()
+{
if (!valid_)
- execute_successful = false;
+ return action::FAIL;
+
+ //Never continue an execute-all after an attack
+ action::EXEC_RESULT result = action::PARTIAL;
LOG_WB << "Executing: " << shared_from_this() << "\n";
@@ -114,27 +115,26 @@
std::set<map_location> adj_enemies =
mouse_handler.get_adj_enemies(get_dest_hex(), side_number());
- if (execute_successful && route_->steps.size() >= 2)
- {
- if (!move::execute())
- {
- //Move didn't complete for some reason, so we're not at
- //the right hex to execute the attack.
- execute_successful = false;
+ if (route_->steps.size() >= 2)
+ {
+ if(move::execute() != action::SUCCESS)
+ {
+ //Move failed for some reason, so don't attack.
+ result = action::FAIL;
}
//check if new enemies are now visible
else if(mouse_handler.get_adj_enemies(get_dest_hex(),
side_number()) != adj_enemies)
{
- execute_successful = false; //ambush, interrupt attack
- }
- }
-
- if (execute_successful)
+ result = action::FAIL; //ambush, interrupt attack
+ }
+ }
+
+ if (result != action::FAIL)
{
resources::controller->get_mouse_handler_base().attack_enemy(get_dest_hex(),
get_target_hex(), weapon_choice_);
- //only path that returns execute_successful = true
- }
- return execute_successful;
+ //only path that doesn't return action::FAIL
+ }
+ return result;
}
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=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/attack.hpp (original)
+++ trunk/src/whiteboard/attack.hpp Sun Jul 24 23:39:34 2011
@@ -41,7 +41,7 @@
virtual void accept(visitor& v);
- virtual bool execute();
+ virtual action::EXEC_RESULT execute();
/** 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=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/move.cpp (original)
+++ trunk/src/whiteboard/move.cpp Sun Jul 24 23:39:34 2011
@@ -209,21 +209,21 @@
v.visit_move(shared_from_this());
}
-bool move::execute()
+action::EXEC_RESULT move::execute()
{
if (!valid_)
- return false;
+ return action::FAIL;
if (get_source_hex() == get_dest_hex())
- return true; //zero-hex move, used by attack subclass
+ return action::SUCCESS; //zero-hex move, used by attack subclass
//Ensure destination hex is free
if (resources::units->find(get_dest_hex()) != resources::units->end())
- return false;
+ return action::FAIL;
LOG_WB << "Executing: " << shared_from_this() << "\n";
- bool move_finished_completely = false;
+ action::EXEC_RESULT result = action::FAIL;
set_arrow_brightness(ARROW_BRIGHTNESS_HIGHLIGHTED);
fake_unit_->set_hidden(true);
@@ -247,7 +247,7 @@
if (steps_finished && route_->steps.back() == final_location)
{
- move_finished_completely = true;
+ result = action::SUCCESS;
}
else if (final_location == route_->steps.front())
{
@@ -260,7 +260,7 @@
if(unit_it->move_interrupted())
{
// Move was interrupted, probably by enemy unit
sighted: let the game take care of it
- move_finished_completely = true;
+ result = action::SUCCESS;
}
else // @todo: Verify this code path is possible...
{
@@ -286,23 +286,23 @@
}
else //Unit ended up in location outside path, likely
due to a WML event
{
- move_finished_completely = true;
+ result = action::SUCCESS;
WRN_WB << "Unit ended up in location outside
path during move execution.\n";
}
}
}
else //Unit disappeared from the map, likely due to a WML event
{
- move_finished_completely = true;
+ result = action::SUCCESS;
WRN_WB << "Unit disappeared from map during move execution.\n";
}
- if (!move_finished_completely)
+ if(result == action::FAIL)
{
set_arrow_brightness(ARROW_BRIGHTNESS_STANDARD);
fake_unit_->set_hidden(false);
}
- return move_finished_completely;
+ 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=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/move.hpp (original)
+++ trunk/src/whiteboard/move.hpp Sun Jul 24 23:39:34 2011
@@ -45,7 +45,7 @@
virtual void accept(visitor& v);
- virtual bool execute();
+ virtual action::EXEC_RESULT execute();
/** 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=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/recall.cpp (original)
+++ trunk/src/whiteboard/recall.cpp Sun Jul 24 23:39:34 2011
@@ -111,7 +111,7 @@
v.visit_recall(shared_from_this());
}
-bool recall::execute()
+action::EXEC_RESULT recall::execute()
{
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 true;
+ return action::SUCCESS;
}
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=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/recall.hpp (original)
+++ trunk/src/whiteboard/recall.hpp Sun Jul 24 23:39:34 2011
@@ -41,8 +41,7 @@
virtual void accept(visitor& v);
- /** Returns true if the action has been completely executed and can be
deleted */
- virtual bool execute();
+ virtual action::EXEC_RESULT execute();
/** 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=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/recruit.cpp (original)
+++ trunk/src/whiteboard/recruit.cpp Sun Jul 24 23:39:34 2011
@@ -102,13 +102,13 @@
v.visit_recruit(shared_from_this());
}
-bool recruit::execute()
+action::EXEC_RESULT recruit::execute()
{
assert(valid_);
fake_unit_->set_hidden(true);
int side_num = team_index() + 1;
resources::controller->get_menu_handler().do_recruit(unit_name_,
side_num, recruit_hex_);
- return true;
+ return action::SUCCESS;
}
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=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/recruit.hpp (original)
+++ trunk/src/whiteboard/recruit.hpp Sun Jul 24 23:39:34 2011
@@ -45,8 +45,7 @@
virtual void accept(visitor& v);
- /** Returns true if the action has been completely executed and can be
deleted */
- virtual bool execute();
+ virtual action::EXEC_RESULT execute();
/** 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=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/side_actions.cpp (original)
+++ trunk/src/whiteboard/side_actions.cpp Sun Jul 24 23:39:34 2011
@@ -149,7 +149,7 @@
bool is_attack = boost::dynamic_pointer_cast<attack>(*position);
bool finished = execute(position);
- keep_executing = finished && !is_attack && !empty();
+ keep_executing = finished && !empty();
}
}
@@ -165,9 +165,9 @@
LOG_WB << "Before execution, " << *this << "\n";
action_ptr action = *position;
- bool finished;
+ action::EXEC_RESULT exec_result;
try {
- finished = action->execute();
+ exec_result = action->execute();
} catch (end_turn_exception&) {
resources::whiteboard->queue_net_cmd(make_net_cmd_remove(position));
actions_.erase(position);
@@ -178,24 +178,31 @@
resources::whiteboard->possibly_clear_undo();
- if (finished)
+ if(exec_result!=action::FAIL)
{
resources::whiteboard->queue_net_cmd(make_net_cmd_remove(position));
actions_.erase(position);
+ }
+
+ switch(exec_result)
+ {
+ case action::SUCCESS:
LOG_WB << "After execution and deletion, " << *this << "\n";
- validate_actions();
- return true;
- }
- else
- {
+ 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 execution *without* deletion, " << *this <<
"\n";
- validate_actions();
- return false;
- }
+ LOG_WB << "After failed execution *without* deletion, " <<
*this << "\n";
+ break;
+ }
+
+ validate_actions();
+ return exec_result == action::SUCCESS;
}
side_actions::iterator side_actions::queue_move(const pathfind::marked_route&
route, arrow_ptr arrow, fake_unit_ptr fake_unit)
Modified: trunk/src/whiteboard/suppose_dead.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/whiteboard/suppose_dead.cpp?rev=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/suppose_dead.cpp (original)
+++ trunk/src/whiteboard/suppose_dead.cpp Sun Jul 24 23:39:34 2011
@@ -107,10 +107,9 @@
v.visit_suppose_dead(shared_from_this());
}
- bool suppose_dead::execute()
+ action::EXEC_RESULT suppose_dead::execute()
{
- valid_=false;
- return false;
+ return action::PARTIAL; //< Delete this, but don't continue
execution
}
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=50394&r1=50393&r2=50394&view=diff
==============================================================================
--- trunk/src/whiteboard/suppose_dead.hpp (original)
+++ trunk/src/whiteboard/suppose_dead.hpp Sun Jul 24 23:39:34 2011
@@ -52,7 +52,7 @@
virtual void accept(visitor& v);
- virtual bool execute();
+ virtual action::EXEC_RESULT execute();
/** 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