void try_cast_prev_spell() { TRACE_FUNC_BEGIN; bool is_prev_spell_ok = false; if (prev_cast_.spell) { //Checking if previous spell is still available (it could for example have been //granted by an item that was dropped) vector<Spell_opt> spell_opts; get_spells_avail(spell_opts); auto spell_opt_cmp = [&](const Spell_opt & opt) {return opt.spell == prev_cast_.spell;}; is_prev_spell_ok = find_if(begin(spell_opts), end(spell_opts), spell_opt_cmp) != end(spell_opts); } if (is_prev_spell_ok) { TRACE << "Previous spell is available, casting" << endl; try_cast(prev_cast_); } else { TRACE << "No previous spell set, player picks spell instead" << endl; player_select_spell_to_cast(); } TRACE_FUNC_END; }
LB_API void *lbind_check(lua_State *L, int idx, const lbind_Type *t) { lbind_Object *obj = (lbind_Object*)lua_touserdata(L, idx); void *u = NULL; if (!check_size(L, idx)) luaL_argerror(L, idx, "invalid lbind userdata"); if (obj != NULL && obj->o.instance == NULL) luaL_argerror(L, idx, "null lbind object"); u = testtypemeta(L, idx, t) ? obj->o.instance : try_cast(L, idx, t); if (u == NULL) lbind_typeerror(L, idx, t->name); return u; }
void player_select_spell_to_cast() { vector<Spell_opt> spell_opts; get_spells_avail(spell_opts); if (spell_opts.empty()) { msg_log::add("I do not know any spells to invoke."); } else { auto spell_opt_sort = [](const Spell_opt & opt1, const Spell_opt & opt2) { return opt1.spell->get_name() < opt2.spell->get_name(); }; sort(spell_opts.begin(), spell_opts.end(), spell_opt_sort); Menu_browser browser(spell_opts.size(), 0); render::draw_map_and_interface(); draw(browser, spell_opts); while (true) { const Menu_action action = menu_input_handling::get_action(browser); switch (action) { case Menu_action::browsed: draw(browser, spell_opts); break; case Menu_action::esc: case Menu_action::space: msg_log::clear(); render::draw_map_and_interface(); return; case Menu_action::selected: try_cast(spell_opts[browser.get_pos().y]); return; default: {} break; } } } }
void player_select_spell_to_cast() { std::vector<Spell_opt> spell_opts; spells_avail(spell_opts); if (spell_opts.empty()) { msg_log::add("I do not know any spells to invoke."); } else //Has spells { Menu_browser browser(spell_opts.size()); render::draw_map_state(); draw(browser, spell_opts); while (true) { const Menu_action action = menu_input::action(browser); switch (action) { case Menu_action::moved: draw(browser, spell_opts); break; case Menu_action::esc: case Menu_action::space: msg_log::clear(); render::draw_map_state(); return; case Menu_action::selected: try_cast(spell_opts[browser.y()]); return; default: break; } } } }
LB_API void *lbind_test(lua_State *L, int idx, const lbind_Type *t) { lbind_Object *obj = (lbind_Object*)lua_touserdata(L, idx); return testtypemeta(L, idx, t) ? obj->o.instance : try_cast(L, idx, t); }
LB_API void *lbind_cast(lua_State *L, int idx, const lbind_Type *t) { lbind_Object *obj = (lbind_Object*)lua_touserdata(L, idx); if (!check_size(L, idx) || obj == NULL || obj->o.instance == NULL) return NULL; return testtypemeta(L, idx, t) ? obj->o.instance : try_cast(L, idx, t); }
LB_API int lbind_isa(lua_State *L, int idx, const lbind_Type *t) { return testtypemeta(L, idx, t) || try_cast(L, idx, t) != NULL; }