Skip to content

Commit

Permalink
Added support for a facing= key in [recall] (#1819)
Browse files Browse the repository at this point in the history
This is necessary, as it is otherwise impossible to specify the facing of the recalled unit.
  • Loading branch information
ln-zookeeper committed Jul 12, 2017
1 parent 986b190 commit 1aa1ce6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
16 changes: 10 additions & 6 deletions src/actions/create.cpp
Expand Up @@ -608,7 +608,7 @@ namespace { // Helpers for place_recruit()
}// anonymous namespace
//Used by recalls and recruits
place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_location, const map_location& recruited_from,
int cost, bool is_recall, bool show, bool fire_event, bool full_movement,
int cost, bool is_recall, map_location::DIRECTION facing, bool show, bool fire_event, bool full_movement,
bool wml_triggered)
{
place_recruit_result res(false, 0, false);
Expand All @@ -632,7 +632,11 @@ place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_locat
unit_map::iterator & new_unit_itor = add_result.first;
map_location current_loc = recruit_location;

set_recruit_facing(new_unit_itor, *u, recruit_location, leader_loc);
if (facing == map_location::NDIRECTIONS) {
set_recruit_facing(new_unit_itor, *u, recruit_location, leader_loc);
} else {
new_unit_itor->set_facing(facing);
}

// Do some bookkeeping.
recruit_checksums(*u, wml_triggered);
Expand Down Expand Up @@ -703,7 +707,7 @@ void recruit_unit(const unit_type & u_type, int side_num, const map_location & l


// Place the recruit.
place_recruit_result res = place_recruit(new_unit, loc, from, u_type.cost(), false, show);
place_recruit_result res = place_recruit(new_unit, loc, from, u_type.cost(), false, map_location::NDIRECTIONS, show);
statistics::recruit_unit(*new_unit);

// To speed things a bit, don't bother with the undo stack during
Expand All @@ -730,7 +734,7 @@ void recruit_unit(const unit_type & u_type, int side_num, const map_location & l
*/
bool recall_unit(const std::string & id, team & current_team,
const map_location & loc, const map_location & from,
bool show, bool use_undo)
map_location::DIRECTION facing, bool show, bool use_undo)
{
unit_ptr recall = current_team.recall_list().extract_if_matches_id(id);

Expand All @@ -747,11 +751,11 @@ bool recall_unit(const std::string & id, team & current_team,
place_recruit_result res;
if (recall->recall_cost() < 0) {
res = place_recruit(recall, loc, from, current_team.recall_cost(),
true, show);
true, facing, show);
}
else {
res = place_recruit(recall, loc, from, recall->recall_cost(),
true, show);
true, facing, show);
}
statistics::recall_unit(*recall);

Expand Down
6 changes: 4 additions & 2 deletions src/actions/create.hpp
Expand Up @@ -145,12 +145,12 @@ std::vector<unit_const_ptr > get_recalls(int side, const map_location &recall_lo
* Place a unit into the game.
* The unit will be placed on @a recruit_location, which should be retrieved
* through a call to recruit_location().
* @param facing the desired facing for the unit, map_location::NDIRECTIONS to determine facing automatically.
* @returns true if an event (or fog clearing) has mutated the game state.
*/
typedef std::tuple<bool /*event modified*/, int /*previous village owner side*/, bool /*capture bonus time*/> place_recruit_result;
place_recruit_result place_recruit(unit_ptr u, const map_location &recruit_location, const map_location& recruited_from,
int cost, bool is_recall, bool show = false, bool fire_event = true, bool full_movement = false,
bool wml_triggered = false);
int cost, bool is_recall, map_location::DIRECTION facing = map_location::NDIRECTIONS, bool show = false, bool fire_event = true, bool full_movement = false, bool wml_triggered = false);

/**
* Recruits a unit of the given type for the given side.
Expand All @@ -170,9 +170,11 @@ void recruit_unit(const unit_type & u_type, int side_num, const map_location & l
* found, and it handles moving the unit to the board, paying gold, firing events,
* tracking statistics, updating the undo stack (unless @a use_undo is false), and
* recording the recall (unless @a use_recorder is false).
* @param facing the desired facing for the unit, map_location::NDIRECTIONS to determine facing automatically.
* @returns false if the recall could not be found in the team's recall list.
*/
bool recall_unit(const std::string & id, team & current_team,
const map_location & loc, const map_location & from,
map_location::DIRECTION facing = map_location::NDIRECTIONS,
bool show=true, bool use_undo=true);
}//namespace actions
7 changes: 5 additions & 2 deletions src/game_events/action_wml.cpp
Expand Up @@ -484,6 +484,7 @@ WML_HANDLER_FUNCTION(recall,, cfg)
DBG_NG << "...valid location for the recall found. Recalling.\n";
avail.erase(u); // Erase before recruiting, since recruiting can fire more events
actions::place_recruit(to_recruit, loc, leader->get_location(), 0, true,
map_location::parse_direction(cfg["facing"]),
cfg["show"].to_bool(true), cfg["fire_event"].to_bool(false),
true, true);
return;
Expand All @@ -499,8 +500,10 @@ WML_HANDLER_FUNCTION(recall,, cfg)
DBG_NG << "No usable leader found, but found usable location. Recalling.\n";
avail.erase(u); // Erase before recruiting, since recruiting can fire more events
map_location null_location = map_location::null_location();
actions::place_recruit(to_recruit, loc, null_location, 0, true, cfg["show"].to_bool(true),
cfg["fire_event"].to_bool(false), true, true);
actions::place_recruit(to_recruit, loc, null_location, 0, true,
map_location::parse_direction(cfg["facing"]),
cfg["show"].to_bool(true), cfg["fire_event"].to_bool(false),
true, true);
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/synced_commands.cpp
Expand Up @@ -137,7 +137,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(recall, child, use_undo, show, error_handler)
map_location loc(child, resources::gamedata);
map_location from(child.child_or_empty("from"), resources::gamedata);

if ( !actions::recall_unit(unit_id, current_team, loc, from, show, use_undo) ) {
if ( !actions::recall_unit(unit_id, current_team, loc, from, map_location::NDIRECTIONS, show, use_undo) ) {
error_handler("illegal recall: unit_id '" + unit_id + "' could not be found within the recall list.\n", true);
//when recall_unit returned false nothing happend so we can safety return false;
return false;
Expand Down

0 comments on commit 1aa1ce6

Please sign in to comment.