Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/wesnoth/wesnoth
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Mar 1, 2015
2 parents e89f52c + b60809e commit 48ea3d2
Show file tree
Hide file tree
Showing 28 changed files with 347 additions and 497 deletions.
4 changes: 2 additions & 2 deletions src/actions/heal.cpp
Expand Up @@ -24,7 +24,7 @@
#include "../gettext.hpp"
#include "../log.hpp"
#include "../map.hpp"
#include "../replay.hpp"
#include "../play_controller.hpp"
#include "../resources.hpp"
#include "../team.hpp"
#include "../unit.hpp"
Expand Down Expand Up @@ -352,7 +352,7 @@ void calculate_healing(int side, bool update_display)

const team & viewing_team =
(*resources::teams)[resources::screen->viewing_team()];
if (!recorder.is_skipping() && update_display &&
if (!resources::controller->is_skipping_replay() && update_display &&
patient.is_visible_to_team(viewing_team, resources::gameboard->map(), false) )
{
unit_list.push_front(heal_unit(patient, healers, healing, curing == POISON_CURE));
Expand Down
7 changes: 7 additions & 0 deletions src/ai/actions.cpp
Expand Up @@ -44,6 +44,7 @@
#include "../mouse_handler_base.hpp"
#include "../pathfind/teleport.hpp"
#include "../play_controller.hpp"
#include "../playsingle_controller.hpp"
#include "../recall_list_manager.hpp"
#include "../replay_helper.hpp"
#include "../resources.hpp"
Expand Down Expand Up @@ -104,6 +105,12 @@ void action_result::execute()
if(resources::controller->is_end_turn()) {
throw ai_end_turn_exception();
}

if(playsingle_controller* psc = dynamic_cast<playsingle_controller*>(resources::controller)) {
if(psc->get_player_type_changed()) {
throw restart_turn_exception();
}
}
is_execution_ = false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/ai/manager.cpp
Expand Up @@ -798,6 +798,8 @@ void manager::play_turn( side_number side ){
}
catch (const ai_end_turn_exception&) {
}
catch(const restart_turn_exception&) {
}
const int turn_end_time= SDL_GetTicks();
DBG_AI_MANAGER << "side " << side << ": number of user interactions: "<<num_interact_<<std::endl;
DBG_AI_MANAGER << "side " << side << ": total turn time: "<<turn_end_time - turn_start_time << " ms "<< std::endl;
Expand Down
1 change: 0 additions & 1 deletion src/game_end_exceptions.cpp
Expand Up @@ -23,7 +23,6 @@ transient_end_level::transient_end_level()
, linger_mode(true)
, custom_endlevel_music()
, reveal_map(true)
, disabled(false)
{}

end_level_data::end_level_data()
Expand Down
68 changes: 14 additions & 54 deletions src/game_end_exceptions.hpp
Expand Up @@ -30,15 +30,12 @@
#include <string>
#include <exception>
#include <boost/optional.hpp>
#include <boost/variant/variant.hpp>

MAKE_ENUM(LEVEL_RESULT,
(NONE, "none")
(VICTORY, "victory")
(DEFEAT, "defeat")
(QUIT, "quit")
(OBSERVER_END, "observer_end")
(SKIP_TO_LINGER,"skip_to_linger")
)
MAKE_ENUM_STREAM_OPS1(LEVEL_RESULT)

Expand All @@ -61,13 +58,6 @@ class ai_end_turn_exception
IMPLEMENT_LUA_JAILBREAK_EXCEPTION(ai_end_turn_exception)
};


/**
* Struct used to transmit info caught from an end_turn_exception.
*/
struct restart_turn_struct {
};

/**
* Exception used to signal the end of a player turn.
*/
Expand All @@ -82,10 +72,6 @@ class restart_turn_exception
{
}
const char * what() const throw() { return "restart_turn_exception"; }
restart_turn_struct to_struct()
{
return restart_turn_struct();
}

private:

Expand All @@ -96,7 +82,7 @@ class restart_turn_exception
* Struct used to transmit info caught from an end_turn_exception.
*/
struct end_level_struct {
LEVEL_RESULT result;
bool is_quit;
};

/**
Expand All @@ -108,17 +94,17 @@ class end_level_exception
{
public:

end_level_exception(LEVEL_RESULT res)
end_level_exception(bool isquit = false)
: tlua_jailbreak_exception()
, std::exception()
, result(res)
, is_quit(isquit)
{
}

LEVEL_RESULT result;
bool is_quit;

end_level_struct to_struct() {
end_level_struct els = {result};
end_level_struct els = {is_quit};
return els;
}

Expand All @@ -131,7 +117,7 @@ class end_level_exception
/**
* The two end_*_exceptions are caught and transformed to this signaling object
*/
typedef boost::optional<boost::variant<restart_turn_struct, end_level_struct> > possible_end_play_signal;
typedef boost::optional<end_level_struct> possible_end_play_signal;

#define HANDLE_END_PLAY_SIGNAL( X )\
do\
Expand All @@ -140,8 +126,6 @@ do\
X;\
} catch (end_level_exception & e) {\
return possible_end_play_signal(e.to_struct());\
} catch (restart_turn_exception & e) {\
return possible_end_play_signal(e.to_struct());\
}\
}\
while(0)
Expand Down Expand Up @@ -173,35 +157,6 @@ do\
while(0)


enum END_PLAY_SIGNAL_TYPE {END_TURN, END_LEVEL};

class get_signal_type : public boost::static_visitor<END_PLAY_SIGNAL_TYPE> {
public:
END_PLAY_SIGNAL_TYPE operator()(restart_turn_struct &) const
{
return END_TURN;
}

END_PLAY_SIGNAL_TYPE operator()(end_level_struct& ) const
{
return END_LEVEL;
}
};

class get_result : public boost::static_visitor<LEVEL_RESULT> {
public:
LEVEL_RESULT operator()(restart_turn_struct & ) const
{
return NONE;
}

LEVEL_RESULT operator()(end_level_struct & s) const
{
return s.result;
}
};


/**
* The non-persistent part of end_level_data
*/
Expand All @@ -213,7 +168,6 @@ struct transient_end_level{
bool linger_mode; /**< Should linger mode be invoked? */
std::string custom_endlevel_music; /**< Custom short music played at the end. */
bool reveal_map; /**< Should we reveal map when game is ended? (Multiplayer only) */
bool disabled; /**< Limits execution of tag [endlevel] to a single time > */
};

/**
Expand All @@ -228,7 +182,7 @@ struct end_level_data
bool replay_save; /**< Should a replay save be made? */
bool proceed_to_next_level; /**< whether to proceed to the next scenario, equals (res == VICTORY) in sp. We need to save this in saves during linger mode. > */
transient_end_level transient;

bool is_victory;
void write(config& cfg) const;

void read(const config& cfg);
Expand All @@ -240,5 +194,11 @@ struct end_level_data
return r;
}
};

inline void throw_quit_game_exception()
{
// Distinguish 'Quit' from 'Regular' end_level_exceptions to solve the following problem:
// If a player quits the game during an event after an [endlevel] occurs, the game won't
// Quit but continue with the [endlevel] instead.
throw end_level_exception(true);
}
#endif /* ! GAME_END_EXCEPTIONS_HPP_INCLUDED */
2 changes: 1 addition & 1 deletion src/game_events/action_wml.cpp
Expand Up @@ -635,7 +635,7 @@ WML_HANDLER_FUNCTION(message, event_info, cfg)
}

has_input = !options.empty() || has_text_input;
if (!has_input && get_replay_source().is_skipping()) {
if (!has_input && resources::controller->is_skipping_replay()) {
// No input to get and the user is not interested either.
return;
}
Expand Down
104 changes: 47 additions & 57 deletions src/game_initialization/playcampaign.cpp
Expand Up @@ -171,7 +171,8 @@ LEVEL_RESULT play_replay(display& disp, saved_game& gamestate, const config& gam
e.show(disp);
}
}
return NONE;
//TODO: when can this happen?
return VICTORY;
}

static LEVEL_RESULT playsingle_scenario(const config& game_config,
Expand All @@ -188,28 +189,23 @@ static LEVEL_RESULT playsingle_scenario(const config& game_config,

LEVEL_RESULT res = playcontroller.play_scenario(story, skip_replay);

if (res == QUIT)
{
return QUIT;
}

end_level = playcontroller.get_end_level_data_const();

if (res != QUIT)
show_carryover_message(state_of_game, playcontroller, disp, end_level, res);
if(!disp.video().faked())
{
//if we are loading from linger mode then we already did this.
if(res != SKIP_TO_LINGER)
{
show_carryover_message(state_of_game, playcontroller, disp, end_level, res);
}
if(!disp.video().faked())
{
try {
playcontroller.maybe_linger();
} catch(end_level_exception& e) {
if (e.result == QUIT) {
return QUIT;
}
}
try {
playcontroller.maybe_linger();
} catch(end_level_exception&) {
return QUIT;
}
}
state_of_game.set_snapshot(playcontroller.to_config());

return res;
}

Expand All @@ -226,31 +222,30 @@ static LEVEL_RESULT playmp_scenario(const config& game_config,
game_config, tdata, disp.video(), skip_replay, blindfold_replay, io_type == IO_SERVER);
LEVEL_RESULT res = playcontroller.play_scenario(story, skip_replay);

end_level = playcontroller.get_end_level_data_const();

//Check if the player started as mp client and changed to host
if (io_type == IO_CLIENT && playcontroller.is_host())
io_type = IO_SERVER;

if (res != QUIT)
if (res == QUIT)
{
if(res != OBSERVER_END && res != SKIP_TO_LINGER)
{
//We need to call this before linger because it prints the defeated/victory message.
//(we want to see that message before entering the linger mode)
show_carryover_message(state_of_game, playcontroller, disp, end_level, res);
}
if(!disp.video().faked())
{
try {
playcontroller.maybe_linger();
} catch(end_level_exception& e) {
if (e.result == QUIT) {
return QUIT;
}
}
}
return QUIT;
}

end_level = playcontroller.get_end_level_data_const();

if(res != OBSERVER_END)
{
//We need to call this before linger because it prints the defeated/victory message.
//(we want to see that message before entering the linger mode)
show_carryover_message(state_of_game, playcontroller, disp, end_level, res);
}
if(!disp.video().faked())
{
try {
playcontroller.maybe_linger();
} catch(end_level_exception&) {
return QUIT;
}
}
playcontroller.update_savegame_snapshot();
return res;
Expand Down Expand Up @@ -317,40 +312,35 @@ LEVEL_RESULT play_game(game_display& disp, saved_game& gamestate,
if (is_unit_test) {
return res;
}
//in this case we might have skipped state.set_snapshot which means we cannot do gamestate.convert_to_start_save();
if(res == QUIT)
{
if(res == QUIT) {
return res;
}

// Save-management options fire on game end.
// This means: (a) we have a victory, or
// (b) we're multiplayer live, in which
// case defeat is also game end. Someday,
// if MP campaigns ever work again, we might
// need to change this test.
if (res == VICTORY || (game_type == game_classification::MULTIPLAYER && res == DEFEAT)) {
if (preferences::delete_saves())
savegame::clean_saves(gamestate.classification().label);

if (preferences::save_replays() && end_level.replay_save) {
savegame::replay_savegame save(gamestate, preferences::save_compression_format());
save.save_game_automatic(disp.video(), true);
}
// proceed_to_next_level <=> 'any human side recieved victory'
// If 'any human side recieved victory' we do the Save-management options
// Otherwise we are done now
if(!end_level.proceed_to_next_level) {
return res;
}

if (preferences::delete_saves()) {
savegame::clean_saves(gamestate.classification().label);
}
if (preferences::save_replays() && end_level.replay_save) {
savegame::replay_savegame save(gamestate, preferences::save_compression_format());
save.save_game_automatic(disp.video(), true);
}

gamestate.convert_to_start_save();
recorder.clear();

// On DEFEAT, QUIT, or OBSERVER_END, we're done now

//If there is no next scenario we're done now.
if(!end_level.proceed_to_next_level || gamestate.get_scenario_id().empty())
if(gamestate.get_scenario_id().empty())
{
return res;
}
else if(res == OBSERVER_END)
{
// TODO: does it make sense to ask this question if we are currently the host?
const int dlg_res = gui2::show_message(disp.video(), _("Game Over"),
_("This scenario has ended. Do you want to continue the campaign?"),
gui2::tmessage::yes_no_buttons);
Expand Down

0 comments on commit 48ea3d2

Please sign in to comment.