Commit e631d73f authored by Chen Bill's avatar Chen Bill

add interpreter::check_filter

parent cbca8ce7
......@@ -404,38 +404,41 @@ int32 interpreter::check_condition(int32 f, uint32 param_count) {
}
return OPERATION_FAIL;
}
int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
if(!findex || lua_isnil(current_state, findex))
int32 interpreter::check_filter(lua_State* L, card* pcard, int32 findex, int32 extraargs) {
if (!findex || lua_isnil(L, findex))
return TRUE;
++no_action;
++call_depth;
luaL_checkstack(current_state, 1 + extraargs, nullptr);
lua_pushvalue(current_state, findex);
interpreter::card2value(current_state, pcard);
for(int32 i = 0; i < extraargs; ++i)
lua_pushvalue(current_state, (int32)(-extraargs - 2));
if (lua_pcall(current_state, 1 + extraargs, 1, 0)) {
sprintf(pduel->strbuffer, "%s", lua_tostring(current_state, -1));
luaL_checkstack(L, 1 + extraargs, nullptr);
lua_pushvalue(L, findex);
card2value(L, pcard);
for (int32 i = 0; i < extraargs; ++i)
lua_pushvalue(L, (int32)(-extraargs - 2));
if (lua_pcall(L, 1 + extraargs, 1, 0)) {
sprintf(pduel->strbuffer, "%s", lua_tostring(L, -1));
handle_message(pduel, 1);
lua_pop(current_state, 1);
lua_pop(L, 1);
--no_action;
--call_depth;
if(call_depth == 0) {
if (call_depth == 0) {
pduel->release_script_group();
pduel->restore_assumes();
}
return OPERATION_FAIL;
}
int32 result = lua_toboolean(current_state, -1);
lua_pop(current_state, 1);
int32 result = lua_toboolean(L, -1);
lua_pop(L, 1);
--no_action;
--call_depth;
if(call_depth == 0) {
if (call_depth == 0) {
pduel->release_script_group();
pduel->restore_assumes();
}
return result;
}
int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
return check_filter(current_state, pcard, findex, extraargs);
}
int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraargs) {
if(!findex || lua_isnil(current_state, findex))
return 0;
......
......@@ -70,6 +70,7 @@ public:
int32 call_card_function(card* pcard, const char* f, uint32 param_count, int32 ret_count);
int32 call_code_function(uint32 code, const char* f, uint32 param_count, int32 ret_count);
int32 check_condition(int32 f, uint32 param_count);
int32 check_filter(lua_State* L, card* pcard, int32 findex, int32 extraargs);
int32 check_matching(card* pcard, int32 findex, int32 extraargs);
int32 get_operation_value(card* pcard, int32 findex, int32 extraargs);
int32 get_function_value(int32 f, uint32 param_count);
......
......@@ -167,7 +167,7 @@ int32 scriptlib::group_filter(lua_State *L) {
group* new_group = pduel->new_group();
uint32 extraargs = lua_gettop(L) - 3;
for(auto& pcard : cset) {
if(pduel->lua->check_matching(pcard, 2, extraargs)) {
if(pduel->lua->check_filter(L, pcard, 2, extraargs)) {
new_group->container.insert(pcard);
}
}
......@@ -192,7 +192,7 @@ int32 scriptlib::group_filter_count(lua_State *L) {
uint32 extraargs = lua_gettop(L) - 3;
uint32 count = 0;
for (auto& pcard : cset) {
if(pduel->lua->check_matching(pcard, 2, extraargs))
if(pduel->lua->check_filter(L, pcard, 2, extraargs))
++count;
}
lua_pushinteger(L, count);
......@@ -222,7 +222,7 @@ int32 scriptlib::group_filter_select(lua_State *L) {
uint32 extraargs = lua_gettop(L) - 6;
pduel->game_field->core.select_cards.clear();
for (auto& pcard : cset) {
if(pduel->lua->check_matching(pcard, 3, extraargs))
if(pduel->lua->check_filter(L, pcard, 3, extraargs))
pduel->game_field->core.select_cards.push_back(pcard);
}
pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16));
......@@ -439,7 +439,7 @@ int32 scriptlib::group_is_exists(lua_State *L) {
return 1;
}
for (auto& pcard : cset) {
if(pduel->lua->check_matching(pcard, 2, extraargs)) {
if(pduel->lua->check_filter(L, pcard, 2, extraargs)) {
++fcount;
if(fcount >= count) {
result = TRUE;
......@@ -692,7 +692,7 @@ int32 scriptlib::group_remove(lua_State *L) {
return 0;
pgroup->is_iterator_dirty = true;
for (auto cit = pgroup->container.begin(); cit != pgroup->container.end();) {
if((*cit) != pexception && pduel->lua->check_matching(*cit, 2, extraargs)) {
if((*cit) != pexception && pduel->lua->check_filter(L, *cit, 2, extraargs)) {
cit = pgroup->container.erase(cit);
}
else
......@@ -767,7 +767,7 @@ int32 scriptlib::group_search_card(lua_State *L) {
duel* pduel = pgroup->pduel;
uint32 extraargs = lua_gettop(L) - 2;
for (auto& pcard : pgroup->container) {
if (pduel->lua->check_matching(pcard, 2, extraargs)) {
if (pduel->lua->check_filter(L, pcard, 2, extraargs)) {
interpreter::card2value(L, pcard);
return 1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment