LuaAI:
(1) Lua CA_wrapper slightly refactored, in preparation for adding CA definitons using external files (2) --debug_lua command line argument added. Unused at the moment, but will be used for Lua debug mechanisms
This commit is contained in:
parent
9711244de8
commit
57aa197583
8 changed files with 49 additions and 21 deletions
|
@ -296,7 +296,7 @@ end
|
|||
|
||||
|
||||
function my_ai:do_moves()
|
||||
|
||||
wesnoth.message("ldbg", tostring(wesnoth.game_config.debug_lua))
|
||||
my_leader = wesnoth.get_units({side = 1, can_recruit=yes})[1].name
|
||||
|
||||
|
||||
|
|
|
@ -53,18 +53,16 @@ static lg::log_domain log_ai_engine_lua("ai/engine/lua");
|
|||
|
||||
typedef boost::shared_ptr< lua_object<int> > lua_int_obj;
|
||||
|
||||
class lua_candidate_action_wrapper : public candidate_action {
|
||||
public:
|
||||
lua_candidate_action_wrapper( rca_context &context, const config &cfg, lua_ai_context &lua_ai_ctx)
|
||||
: candidate_action(context,cfg),evaluation_(cfg["evaluation"]),evaluation_action_handler_(),
|
||||
execution_(cfg["execution"]),execution_action_handler_(),serialized_evaluation_state_()
|
||||
class lua_candidate_action_wrapper_base : public candidate_action {
|
||||
|
||||
public:
|
||||
lua_candidate_action_wrapper_base( rca_context &context, const config &cfg)
|
||||
: candidate_action(context, cfg),evaluation_action_handler_(),execution_action_handler_(),serialized_evaluation_state_()
|
||||
{
|
||||
evaluation_action_handler_ = boost::shared_ptr<lua_ai_action_handler>(resources::lua_kernel->create_lua_ai_action_handler(evaluation_.c_str(),lua_ai_ctx));
|
||||
execution_action_handler_ = boost::shared_ptr<lua_ai_action_handler>(resources::lua_kernel->create_lua_ai_action_handler(execution_.c_str(),lua_ai_ctx));
|
||||
// do nothing
|
||||
}
|
||||
|
||||
virtual ~lua_candidate_action_wrapper() {}
|
||||
|
||||
virtual ~lua_candidate_action_wrapper_base() {}
|
||||
|
||||
virtual double evaluate()
|
||||
{
|
||||
|
@ -88,22 +86,42 @@ public:
|
|||
execution_action_handler_->handle(serialized_evaluation_state_, false, l_obj);
|
||||
}
|
||||
}
|
||||
|
||||
virtual config to_config() const {
|
||||
config cfg = candidate_action::to_config();
|
||||
cfg.add_child("state",serialized_evaluation_state_);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
protected:
|
||||
boost::shared_ptr<lua_ai_action_handler> evaluation_action_handler_;
|
||||
boost::shared_ptr<lua_ai_action_handler> execution_action_handler_;
|
||||
config serialized_evaluation_state_;
|
||||
};
|
||||
|
||||
class lua_candidate_action_wrapper : public lua_candidate_action_wrapper_base {
|
||||
|
||||
public:
|
||||
lua_candidate_action_wrapper( rca_context &context, const config &cfg, lua_ai_context &lua_ai_ctx)
|
||||
: lua_candidate_action_wrapper_base(context,cfg),evaluation_(cfg["evaluation"]),execution_(cfg["execution"])
|
||||
{
|
||||
evaluation_action_handler_ = boost::shared_ptr<lua_ai_action_handler>(resources::lua_kernel->create_lua_ai_action_handler(evaluation_.c_str(),lua_ai_ctx));
|
||||
execution_action_handler_ = boost::shared_ptr<lua_ai_action_handler>(resources::lua_kernel->create_lua_ai_action_handler(execution_.c_str(),lua_ai_ctx));
|
||||
}
|
||||
|
||||
virtual ~lua_candidate_action_wrapper() {}
|
||||
|
||||
virtual config to_config() const
|
||||
{
|
||||
config cfg = candidate_action::to_config();
|
||||
config cfg = lua_candidate_action_wrapper_base::to_config();
|
||||
cfg["evaluation"] = evaluation_;
|
||||
cfg["execution"] = execution_;
|
||||
cfg.add_child("state",serialized_evaluation_state_);
|
||||
cfg["execution"] = execution_;
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string evaluation_;
|
||||
boost::shared_ptr<lua_ai_action_handler> evaluation_action_handler_;
|
||||
std::string evaluation_;
|
||||
std::string execution_;
|
||||
boost::shared_ptr<lua_ai_action_handler> execution_action_handler_;
|
||||
config serialized_evaluation_state_;
|
||||
};
|
||||
|
||||
class lua_sticky_candidate_action_wrapper : public lua_candidate_action_wrapper {
|
||||
|
@ -120,7 +138,7 @@ public:
|
|||
{
|
||||
if (resources::units->find(bound_unit_->underlying_id()).valid())
|
||||
{
|
||||
return lua_candidate_action_wrapper::evaluate();
|
||||
return lua_candidate_action_wrapper_base::evaluate();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -131,7 +149,7 @@ public:
|
|||
|
||||
virtual void execute()
|
||||
{
|
||||
lua_candidate_action_wrapper::execute();
|
||||
lua_candidate_action_wrapper_base::execute();
|
||||
this->disable(); // we do not want to execute the same sticky CA twice -> will be moved out to Lua later
|
||||
}
|
||||
private:
|
||||
|
|
|
@ -51,6 +51,7 @@ commandline_options::commandline_options ( int argc, char** argv ) :
|
|||
config_dir(),
|
||||
data_dir(),
|
||||
debug(false),
|
||||
debug_lua(false),
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
debug_dot_domain(),
|
||||
debug_dot_level(),
|
||||
|
@ -127,6 +128,7 @@ commandline_options::commandline_options ( int argc, char** argv ) :
|
|||
("config-path", "prints the path of the user config directory and exits.")
|
||||
("data-dir", po::value<std::string>(), "overrides the data directory with the one specified.")
|
||||
("debug,d", "enables additional command mode options in-game.")
|
||||
("debug_lua", "enables some Lua debugging mechanisms")
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
("debug-dot-level", po::value<std::string>(), "sets the level of the debug dot files. <arg> should be a comma separated list of levels. These files are used for debugging the widgets especially the for the layout engine. When enabled the engine will produce dot files which can be converted to images with the dot tool. Available levels: size (generate the size info of the widget), state (generate the state info of the widget).")
|
||||
("debug-dot-domain", po::value<std::string>(), "sets the domain of the debug dot files. <arg> should be a comma separated list of domains. See --debug-dot-level for more info. Available domains: show (generate the data when the dialog is about to be shown), layout (generate the data during the layout phase - might result in multiple files). The data can also be generated when the F12 is pressed in a dialog.")
|
||||
|
@ -255,6 +257,8 @@ commandline_options::commandline_options ( int argc, char** argv ) :
|
|||
data_dir = vm["data-dir"].as<std::string>();
|
||||
if (vm.count("debug"))
|
||||
debug = true;
|
||||
if (vm.count("debug_lua"))
|
||||
debug_lua = true;
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
if (vm.count("debug-dot-domain")) {
|
||||
debug_dot_domain = vm["debug-dot-domain"].as<std::string>();
|
||||
|
|
|
@ -49,6 +49,8 @@ public:
|
|||
boost::optional<std::string> data_dir;
|
||||
/// True if --debug was given on the command line. Enables debug mode.
|
||||
bool debug;
|
||||
/// True if --debug_lua was given in the commandline. Enables some Lua debugging mechanisms.
|
||||
bool debug_lua;
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
/// Non-empty if --debug-dot-domain was given on the command line.
|
||||
boost::optional<std::string> debug_dot_domain;
|
||||
|
|
|
@ -138,6 +138,9 @@ static int process_command_args(const commandline_options& cmdline_opts) {
|
|||
// don't update font as we already updating it in game ctor
|
||||
//font_manager_.update_font_path();
|
||||
}
|
||||
if(cmdline_opts.debug_lua) {
|
||||
game_config::debug_lua = true;
|
||||
}
|
||||
if(cmdline_opts.gunzip) {
|
||||
const std::string input_file(*cmdline_opts.gunzip);
|
||||
if(!is_gzip_file(input_file)) {
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace game_config
|
|||
const std::string revision = VERSION;
|
||||
#endif
|
||||
std::string wesnoth_program_dir;
|
||||
bool debug = false, editor = false, ignore_replay_errors = false, mp_debug = false, exit_at_end = false, new_syntax = false, no_delay = false, small_gui = false, disable_autosave = false;
|
||||
bool debug = false, debug_lua = false, editor = false, ignore_replay_errors = false, mp_debug = false, exit_at_end = false, new_syntax = false, no_delay = false, small_gui = false, disable_autosave = false;
|
||||
|
||||
int cache_compression_level = 6;
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace game_config
|
|||
/** Default percentage gold carried over to the next scenario. */
|
||||
extern const int gold_carryover_percentage;
|
||||
|
||||
extern bool debug, editor, ignore_replay_errors, mp_debug, exit_at_end, new_syntax, no_delay, small_gui, disable_autosave;
|
||||
extern bool debug, debug_lua, editor, ignore_replay_errors, mp_debug, exit_at_end, new_syntax, no_delay, small_gui, disable_autosave;
|
||||
|
||||
extern int cache_compression_level;
|
||||
|
||||
|
|
|
@ -1890,6 +1890,7 @@ static int impl_game_config_get(lua_State *L)
|
|||
return_int_attrib("last_turn", resources::tod_manager->number_of_turns());
|
||||
return_string_attrib("version", game_config::version);
|
||||
return_bool_attrib("debug", game_config::debug);
|
||||
return_bool_attrib("debug_lua", game_config::debug_lua);
|
||||
return_bool_attrib("mp_debug", game_config::mp_debug);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue