Skip to content

Commit

Permalink
Support [disallow_end_turn]reason= and use it in the tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Nov 24, 2018
1 parent 7034c8f commit ea9fddc
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -82,6 +82,7 @@
* [remove_sound_source] now accepts a comma-separated ID list
* Support [filter_team] in [side] in addition to team_name=
* Support an optional EXTRA_WML argument to {REMOVE_LABEL}.
* Support [disallow_end_turn]reason=
### Miscellaneous and bug fixes
* Rest healing now happens on turn 2. (issue #3562)
* Normal healing now happens on turn 1 for all sides except the first. (issue #3562)
Expand Down
20 changes: 16 additions & 4 deletions data/campaigns/tutorial/scenarios/01_Tutorial_part_1.cfg
Expand Up @@ -132,7 +132,9 @@

# We don't want players ending their turn before the requisite actions have been completed
# Therefor, we frequently disallow or allow end turn as needed
[disallow_end_turn][/disallow_end_turn]
[disallow_end_turn]
reason=_"You cannot end your turn until you have completed the lesson on movement!"
[/disallow_end_turn]
[/event]

[event]
Expand Down Expand Up @@ -519,6 +521,10 @@
message= _"To attack the quintain, first select the attacker (Li’sar), then the target (the quintain). You will see an attack description. Click <b>Attack</b> when you’re ready."
[/message]
)}

[disallow_end_turn]
reason=_"You cannot end your turn until you have attacked the dummy!"
[/disallow_end_turn]
[/event]

# First time the student attacks the quintain
Expand Down Expand Up @@ -620,7 +626,9 @@
[event]
name=turn 2

[disallow_end_turn][/disallow_end_turn]
[disallow_end_turn]
reason=_"You cannot end your turn until you have completed the lesson on healing!"
[/disallow_end_turn]

# works around the situation that the player can't do anything anymore
# if he disobeys orders - inserts [allow_end_turn][/allow_end_turn]
Expand Down Expand Up @@ -685,7 +693,9 @@
[event]
name=turn 3 refresh

[disallow_end_turn][/disallow_end_turn]
[disallow_end_turn]
reason=_"You cannot end your turn until you have completed the lesson on recruiting!"
[/disallow_end_turn]

{ALLOW_END_TURN_AFTER_ATTACK}

Expand Down Expand Up @@ -815,7 +825,9 @@
radius=1 # hexes next to the first quintain
[/store_locations]

[disallow_end_turn][/disallow_end_turn]
[disallow_end_turn]
reason=_"You cannot end your turn until you have completed the lesson on attacking!"
[/disallow_end_turn]

{ALLOW_END_TURN_AFTER_ATTACK}

Expand Down
4 changes: 3 additions & 1 deletion data/campaigns/tutorial/scenarios/02_Tutorial_part_2.cfg
Expand Up @@ -175,7 +175,9 @@
[/then]
[/if]

[disallow_end_turn][/disallow_end_turn]
[disallow_end_turn]
reason=_"You cannot end your turn until you have recruited troops and captured a village!"
[/disallow_end_turn]
[/event]

[event]
Expand Down
2 changes: 1 addition & 1 deletion data/lua/wml-tags.lua
Expand Up @@ -702,7 +702,7 @@ function wml_actions.allow_end_turn(cfg)
end

function wml_actions.disallow_end_turn(cfg)
wesnoth.allow_end_turn(false)
wesnoth.allow_end_turn(cfg.reason or false)
end

function wml_actions.clear_menu_item(cfg)
Expand Down
7 changes: 6 additions & 1 deletion data/schema/core/actionwml.cfg
Expand Up @@ -294,7 +294,12 @@
{SIMPLE_KEY add s_int}
{SIMPLE_KEY current s_unsigned}
[/tag]
{EMPTY_TAG "allow_end_turn,disallow_end_turn" 0 infinite}
{EMPTY_TAG "allow_end_turn" 0 infinite}
[tag]
name="disallow_end_turn"
max=infinite
{DEFAULT_KEY reason t_string ""}
[/tag]
[tag]
name="capture_village"
max=infinite
Expand Down
9 changes: 8 additions & 1 deletion src/game_data.hpp
Expand Up @@ -76,8 +76,14 @@ class game_data : public variable_set {
PHASE phase() const { return phase_; }
void set_phase(PHASE phase) { phase_ = phase; }

const t_string& cannot_end_turn_reason() {
return cannot_end_turn_reason_;
}
bool allow_end_turn() const { return can_end_turn_; }
void set_allow_end_turn(bool value) { can_end_turn_ = value; }
void set_allow_end_turn(bool value, const t_string& reason = "") {
can_end_turn_ = value;
cannot_end_turn_reason_ = reason;
}

/** the last location where a select event fired. Used by wml menu items with needs_select=yes*/
map_location last_selected;
Expand Down Expand Up @@ -112,6 +118,7 @@ class game_data : public variable_set {
config variables_;
PHASE phase_;
bool can_end_turn_;
t_string cannot_end_turn_reason_;
/// the scenario coming next (for campaigns)
std::string next_scenario_;
// the id of a scenario cannot change during a scenario
Expand Down
6 changes: 5 additions & 1 deletion src/menu_events.cpp
Expand Up @@ -534,7 +534,11 @@ bool unmoved_units(
bool menu_handler::end_turn(int side_num)
{
if(!gamedata().allow_end_turn()) {
gui2::show_transient_message("", _("You cannot end your turn yet!"));
t_string reason = gamedata().cannot_end_turn_reason();
if(reason.empty()) {
reason = _("You cannot end your turn yet!");
}
gui2::show_transient_message("", reason);
return false;
}

Expand Down
11 changes: 10 additions & 1 deletion src/scripting/game_lua_kernel.cpp
Expand Up @@ -3668,7 +3668,16 @@ static int intf_debug_ai(lua_State *L)
/// Allow undo sets the flag saying whether the event has mutated the game to false.
int game_lua_kernel::intf_allow_end_turn(lua_State * L)
{
gamedata().set_allow_end_turn(luaW_toboolean(L, 1));
bool allow;
t_string reason;
// The extra iststring is required to prevent totstring from converting a bool value
if(luaW_iststring(L, 1) && luaW_totstring(L, 1, reason)) {
allow = false;
} else {
allow = luaW_toboolean(L, 1);
luaW_totstring(L, 2, reason);
}
gamedata().set_allow_end_turn(allow, reason);
return 0;
}

Expand Down

0 comments on commit ea9fddc

Please sign in to comment.