diff --git a/card.cpp b/card.cpp index 6ef63db60..7984d2ef7 100644 --- a/card.cpp +++ b/card.cpp @@ -1579,7 +1579,7 @@ void card::xyz_overlay(card_set* materials) { if(materials->size() == 0) return; card_set des, leave_grave, leave_deck; - field::card_vector cv; + card_vector cv; for(auto& pcard : *materials) cv.push_back(pcard); std::sort(cv.begin(), cv.end(), card::card_operation_sort); diff --git a/card.h b/card.h index 17bd42576..1aff307c7 100644 --- a/card.h +++ b/card.h @@ -24,6 +24,9 @@ class effect; class group; struct chain; +using card_set = std::set; +using card_vector = std::vector; + struct card_state { uint32 code{ 0 }; uint32 code2{ 0 }; @@ -113,9 +116,7 @@ class card { return std::hash()(v.second); } }; - using card_vector = std::vector; using effect_container = std::multimap; - using card_set = std::set; using effect_indexer = std::unordered_map; using effect_relation = std::unordered_set, effect_relation_hash>; using relation_map = std::unordered_map; diff --git a/duel.h b/duel.h index 121986ca6..ec1e002d7 100644 --- a/duel.h +++ b/duel.h @@ -20,9 +20,10 @@ class effect; class field; class interpreter; +using card_set = std::set; + class duel { public: - using card_set = std::set; char strbuffer[256]; std::vector message_buffer; interpreter* lua; diff --git a/effect.cpp b/effect.cpp index d2ce46ca2..7552381a1 100644 --- a/effect.cpp +++ b/effect.cpp @@ -739,6 +739,9 @@ void effect::get_value(effect* peffect, uint32 extraargs, std::vector* re result->push_back((int32)value); } } +int32 effect::get_integer_value() { + return is_flag(EFFECT_FLAG_FUNC_VALUE) ? 0 : value; +} int32 effect::check_value_condition(uint32 extraargs) { if(is_flag(EFFECT_FLAG_FUNC_VALUE)) { pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE); diff --git a/effect.h b/effect.h index e07e04fbe..ec29f4ce1 100644 --- a/effect.h +++ b/effect.h @@ -97,6 +97,7 @@ class effect { void get_value(uint32 extraargs, std::vector* result); void get_value(card* pcard, uint32 extraargs, std::vector* result); void get_value(effect* peffect, uint32 extraargs, std::vector* result); + int32 get_integer_value(); int32 check_value_condition(uint32 extraargs = 0); void* get_label_object(); int32 get_speed(); diff --git a/field.cpp b/field.cpp index 41cc83efb..9824051a0 100644 --- a/field.cpp +++ b/field.cpp @@ -1463,7 +1463,7 @@ void field::filter_player_effect(uint8 playerid, uint32 code, effect_set* eset, if(sort) eset->sort(); } -int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, uint32 location2, group* pgroup, card* pexception, group* pexgroup, uint32 extraargs, card** pret, int32 fcount, int32 is_target) { +int32 field::filter_matching_card(lua_State* L, int32 findex, uint8 self, uint32 location1, uint32 location2, group* pgroup, card* pexception, group* pexgroup, uint32 extraargs, card** pret, int32 fcount, int32 is_target) { if(self != 0 && self != 1) return FALSE; card_set result; @@ -1473,7 +1473,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui for(auto& pcard : player[self].list_mzone) { if(pcard && !pcard->is_treated_as_not_on_field() && pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) - && pduel->lua->check_matching(pcard, findex, extraargs) + && pduel->lua->check_filter(L, pcard, findex, extraargs) && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { if(pret) { *pret = pcard; @@ -1489,7 +1489,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui for(auto& pcard : player[self].list_szone) { if(pcard && !pcard->is_treated_as_not_on_field() && pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) - && pduel->lua->check_matching(pcard, findex, extraargs) + && pduel->lua->check_filter(L, pcard, findex, extraargs) && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { if(pret) { *pret = pcard; @@ -1505,7 +1505,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui card* pcard = player[self].list_szone[5]; if(pcard && !pcard->is_treated_as_not_on_field() && pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) - && pduel->lua->check_matching(pcard, findex, extraargs) + && pduel->lua->check_filter(L, pcard, findex, extraargs) && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { if(pret) { *pret = pcard; @@ -1521,7 +1521,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui card* pcard = player[self].list_szone[core.duel_rule >= NEW_MASTER_RULE ? i * 4 : i + 6]; if(pcard && pcard->current.pzone && !pcard->is_treated_as_not_on_field() && pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) - && pduel->lua->check_matching(pcard, findex, extraargs) + && pduel->lua->check_filter(L, pcard, findex, extraargs) && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { if(pret) { *pret = pcard; @@ -1536,7 +1536,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui if(location & LOCATION_DECK) { for(auto cit = player[self].list_main.rbegin(); cit != player[self].list_main.rend(); ++cit) { if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit)) - && pduel->lua->check_matching(*cit, findex, extraargs) + && pduel->lua->check_filter(L, *cit, findex, extraargs) && (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { if(pret) { *pret = *cit; @@ -1551,7 +1551,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui if(location & LOCATION_EXTRA) { for(auto cit = player[self].list_extra.rbegin(); cit != player[self].list_extra.rend(); ++cit) { if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit)) - && pduel->lua->check_matching(*cit, findex, extraargs) + && pduel->lua->check_filter(L, *cit, findex, extraargs) && (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { if(pret) { *pret = *cit; @@ -1566,7 +1566,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui if(location & LOCATION_HAND) { for(auto& pcard : player[self].list_hand) { if(pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) - && pduel->lua->check_matching(pcard, findex, extraargs) + && pduel->lua->check_filter(L, pcard, findex, extraargs) && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { if(pret) { *pret = pcard; @@ -1581,7 +1581,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui if(location & LOCATION_GRAVE) { for(auto cit = player[self].list_grave.rbegin(); cit != player[self].list_grave.rend(); ++cit) { if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit)) - && pduel->lua->check_matching(*cit, findex, extraargs) + && pduel->lua->check_filter(L, *cit, findex, extraargs) && (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { if(pret) { *pret = *cit; @@ -1596,7 +1596,7 @@ int32 field::filter_matching_card(int32 findex, uint8 self, uint32 location1, ui if(location & LOCATION_REMOVED) { for(auto cit = player[self].list_remove.rbegin(); cit != player[self].list_remove.rend(); ++cit) { if(*cit != pexception && !(pexgroup && pexgroup->has_card(*cit)) - && pduel->lua->check_matching(*cit, findex, extraargs) + && pduel->lua->check_filter(L, *cit, findex, extraargs) && (!is_target || (*cit)->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { if(pret) { *pret = *cit; @@ -1681,13 +1681,13 @@ effect* field::is_player_affected_by_effect(uint8 playerid, uint32 code) { } return nullptr; } -int32 field::get_release_list(uint8 playerid, card_set* release_list, card_set* ex_list, card_set* ex_list_oneof, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason) { +int32 field::get_release_list(lua_State* L, uint8 playerid, card_set* release_list, card_set* ex_list, card_set* ex_list_oneof, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason) { uint32 rcount = 0; effect* re = core.reason_effect; for(auto& pcard : player[playerid].list_mzone) { if(pcard && pcard != exc && !(exg && exg->has_card(pcard)) && pcard->is_releasable_by_nonsummon(playerid, reason) && (reason != REASON_EFFECT || pcard->is_releasable_by_effect(playerid, re)) - && (!use_con || pduel->lua->check_matching(pcard, fun, exarg))) { + && (!use_con || pduel->lua->check_filter(L, pcard, fun, exarg))) { if(release_list) release_list->insert(pcard); pcard->release_param = 1; @@ -1698,7 +1698,7 @@ int32 field::get_release_list(uint8 playerid, card_set* release_list, card_set* for(auto& pcard : player[playerid].list_hand) { if(pcard && pcard != exc && !(exg && exg->has_card(pcard)) && pcard->is_releasable_by_nonsummon(playerid, reason) && (reason != REASON_EFFECT || pcard->is_releasable_by_effect(playerid, re)) - && (!use_con || pduel->lua->check_matching(pcard, fun, exarg))) { + && (!use_con || pduel->lua->check_filter(L, pcard, fun, exarg))) { if(release_list) release_list->insert(pcard); pcard->release_param = 1; @@ -1711,7 +1711,7 @@ int32 field::get_release_list(uint8 playerid, card_set* release_list, card_set* if(pcard && pcard != exc && !(exg && exg->has_card(pcard)) && (pcard->is_position(POS_FACEUP) || !use_con) && pcard->is_releasable_by_nonsummon(playerid, reason) && (reason != REASON_EFFECT || pcard->is_releasable_by_effect(playerid, re)) - && (!use_con || pduel->lua->check_matching(pcard, fun, exarg))) { + && (!use_con || pduel->lua->check_filter(L, pcard, fun, exarg))) { pcard->release_param = 1; if(pcard->is_affected_by_effect(EFFECT_EXTRA_RELEASE)) { if(ex_list) @@ -1734,10 +1734,10 @@ int32 field::get_release_list(uint8 playerid, card_set* release_list, card_set* } return rcount + ex_oneof_max; } -int32 field::check_release_list(uint8 playerid, int32 count, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason) { +int32 field::check_release_list(lua_State* L, uint8 playerid, int32 count, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason) { card_set relcard; card_set relcard_oneof; - get_release_list(playerid, &relcard, &relcard, &relcard_oneof, use_con, use_hand, fun, exarg, exc, exg, reason); + get_release_list(L, playerid, &relcard, &relcard, &relcard_oneof, use_con, use_hand, fun, exarg, exc, exg, reason); bool has_oneof = false; for(auto& pcard : core.must_select_cards) { auto it = relcard.find(pcard); @@ -1951,13 +1951,13 @@ void field::ritual_release(card_set* material) { release(&rel, core.reason_effect, REASON_RITUAL + REASON_EFFECT + REASON_MATERIAL, core.reason_player); send_to(&rem, core.reason_effect, REASON_RITUAL + REASON_EFFECT + REASON_MATERIAL, core.reason_player, PLAYER_NONE, LOCATION_REMOVED, 0, POS_FACEUP); } -void field::get_xyz_material(card* scard, int32 findex, uint32 lv, int32 maxc, group* mg) { +void field::get_xyz_material(lua_State* L, card* scard, int32 findex, uint32 lv, int32 maxc, group* mg) { core.xmaterial_lst.clear(); uint32 xyz_level; if(mg) { for (auto& pcard : mg->container) { if(pcard->is_can_be_xyz_material(scard) && (xyz_level = pcard->check_xyz_level(scard, lv)) - && (findex == 0 || pduel->lua->check_matching(pcard, findex, 0))) + && (findex == 0 || pduel->lua->check_filter(L, pcard, findex, 0))) core.xmaterial_lst.emplace((xyz_level >> 12) & 0xf, pcard); } } else { @@ -1965,13 +1965,13 @@ void field::get_xyz_material(card* scard, int32 findex, uint32 lv, int32 maxc, g for(auto& pcard : player[playerid].list_mzone) { if(pcard && pcard->is_position(POS_FACEUP) && !pcard->is_treated_as_not_on_field() && pcard->is_can_be_xyz_material(scard) && (xyz_level = pcard->check_xyz_level(scard, lv)) - && (findex == 0 || pduel->lua->check_matching(pcard, findex, 0))) + && (findex == 0 || pduel->lua->check_filter(L, pcard, findex, 0))) core.xmaterial_lst.emplace((xyz_level >> 12) & 0xf, pcard); } for(auto& pcard : player[1 - playerid].list_mzone) { if(pcard && pcard->is_position(POS_FACEUP) && !pcard->is_treated_as_not_on_field() && pcard->is_can_be_xyz_material(scard) && (xyz_level = pcard->check_xyz_level(scard, lv)) - && pcard->is_affected_by_effect(EFFECT_XYZ_MATERIAL) && (findex == 0 || pduel->lua->check_matching(pcard, findex, 0))) + && pcard->is_affected_by_effect(EFFECT_XYZ_MATERIAL) && (findex == 0 || pduel->lua->check_filter(L, pcard, findex, 0))) core.xmaterial_lst.emplace((xyz_level >> 12) & 0xf, pcard); } } @@ -2544,29 +2544,29 @@ void field::get_synchro_material(uint8 playerid, card_set* material, effect* tun } } } -int32 field::check_synchro_material(card* pcard, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg) { +int32 field::check_synchro_material(lua_State* L, card* pcard, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg) { if(mg) { for(auto& tuner : mg->container) { - if(check_tuner_material(pcard, tuner, findex1, findex2, min, max, smat, mg)) + if(check_tuner_material(L, pcard, tuner, findex1, findex2, min, max, nullptr, mg)) return TRUE; } } else { card_set material; get_synchro_material(pcard->current.controler, &material); for(auto& tuner : material) { - if(check_tuner_material(pcard, tuner, findex1, findex2, min, max, smat, mg)) + if(check_tuner_material(L, pcard, tuner, findex1, findex2, min, max, smat, nullptr)) return TRUE; } } return FALSE; } -int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg) { +int32 field::check_tuner_material(lua_State* L, card* pcard, card* tuner, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg) { if(!tuner || (tuner->current.location == LOCATION_MZONE && !tuner->is_position(POS_FACEUP)) || !tuner->is_tuner(pcard) || !tuner->is_can_be_synchro_material(pcard)) return FALSE; effect* pcheck = tuner->is_affected_by_effect(EFFECT_SYNCHRO_CHECK); if(pcheck) pcheck->get_value(tuner); - if((mg && !mg->has_card(tuner)) || !pduel->lua->check_matching(tuner, findex1, 0)) { + if((mg && !mg->has_card(tuner)) || !pduel->lua->check_filter(L, tuner, findex1, 0)) { pduel->restore_assumes(); return FALSE; } @@ -2578,7 +2578,7 @@ int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32 } pduel->lua->add_param(pcustom, PARAM_TYPE_EFFECT); pduel->lua->add_param(pcard, PARAM_TYPE_CARD); - pduel->lua->add_param(findex2, PARAM_TYPE_INDEX); + pduel->lua->add_param(interpreter::get_function_handle(L, findex2), PARAM_TYPE_FUNCTION); pduel->lua->add_param(min, PARAM_TYPE_INT); pduel->lua->add_param(max, PARAM_TYPE_INT); if(pduel->lua->check_condition(pcustom->target, 5)) { @@ -2590,27 +2590,23 @@ int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32 } int32 playerid = pcard->current.controler; card_set must_list; - int32 mct = get_must_material_list(playerid, EFFECT_MUST_BE_SMATERIAL, &must_list); - auto tit = must_list.find(tuner); - if(tit != must_list.end()) { - --mct; - must_list.erase(tit); - } - int32 ct = get_spsummonable_count(pcard, playerid); + get_must_material_list(playerid, EFFECT_MUST_BE_SMATERIAL, &must_list); + must_list.erase(tuner); + int32 location_count = get_spsummonable_count(pcard, playerid); card_set handover_zone_cards; - if(ct <= 0) { + if(location_count <= 0) { uint32 must_use_zone_flag = 0; filter_must_use_mzone(playerid, playerid, LOCATION_REASON_TOFIELD, pcard, &must_use_zone_flag); uint32 handover_zone = get_rule_zone_fromex(playerid, pcard) & ~must_use_zone_flag; get_cards_in_zone(&handover_zone_cards, handover_zone, playerid, LOCATION_MZONE); if(handover_zone_cards.find(tuner) != handover_zone_cards.end()) - ++ct; + ++location_count; } int32 location = LOCATION_MZONE; effect* tuner_limit = tuner->is_affected_by_effect(EFFECT_TUNER_MATERIAL_LIMIT); if(tuner_limit) { - if(tuner_limit->value) - location = tuner_limit->value; + if(tuner_limit->get_integer_value()) + location = tuner_limit->get_integer_value(); if(tuner_limit->is_flag(EFFECT_FLAG_SPSUM_PARAM)) { if(tuner_limit->s_range && tuner_limit->s_range > min) min = tuner_limit->s_range; @@ -2644,7 +2640,14 @@ int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32 if(smat) { if(pcheck) pcheck->get_value(smat); - if((smat->current.location == LOCATION_MZONE && !smat->is_position(POS_FACEUP)) || !smat->is_can_be_synchro_material(pcard, tuner) || !pduel->lua->check_matching(smat, findex2, 1)) { + if((smat->current.location == LOCATION_MZONE && !smat->is_position(POS_FACEUP)) || !smat->is_can_be_synchro_material(pcard, tuner)) { + pduel->restore_assumes(); + return FALSE; + } + interpreter::card2value(L, pcard); + auto res = pduel->lua->check_filter(L, smat, findex2, 1); + lua_pop(L, 1); + if (!res) { pduel->restore_assumes(); return FALSE; } @@ -2657,7 +2660,7 @@ int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32 return FALSE; } } - if(tuner_limit->value && !(smat->current.location & location)) { + if(tuner_limit->get_integer_value() && !((uint32)smat->current.location & tuner_limit->get_integer_value())) { pduel->restore_assumes(); return FALSE; } @@ -2667,19 +2670,13 @@ int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32 nsyn.push_back(smat); smat->sum_param = smat->get_synchro_level(pcard); ++mcount; - if(mct > 0) { - auto sit = must_list.find(smat); - if(sit != must_list.end()) { - --mct; - must_list.erase(sit); - } - } - if(ct <= 0) { + must_list.erase(smat); + if(location_count <= 0) { if(handover_zone_cards.find(smat) != handover_zone_cards.end()) - ++ct; + ++location_count; } if(min == 0) { - if(ct > 0 && check_with_sum_limit_m(nsyn, lv, 0, 0, 0, 0xffff, 2)) { + if(location_count > 0 && check_with_sum_limit_m(nsyn, lv, 0, 0, 0, 0xffff, 2)) { pduel->restore_assumes(); return TRUE; } @@ -2689,13 +2686,18 @@ int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32 } } } - if(mct > 0) { + if(must_list.size()) { for(auto& mcard : must_list) { - if(mcard == tuner || mcard == smat) - continue; if(pcheck) pcheck->get_value(mcard); - if((mcard->current.location == LOCATION_MZONE && !mcard->is_position(POS_FACEUP)) || !mcard->is_can_be_synchro_material(pcard, tuner) || !pduel->lua->check_matching(mcard, findex2, 1)) { + if((mcard->current.location == LOCATION_MZONE && !mcard->is_position(POS_FACEUP)) || !mcard->is_can_be_synchro_material(pcard, tuner)) { + pduel->restore_assumes(); + return FALSE; + } + interpreter::card2value(L, pcard); + auto res = pduel->lua->check_filter(L, mcard, findex2, 1); + lua_pop(L, 1); + if (!res) { pduel->restore_assumes(); return FALSE; } @@ -2731,22 +2733,25 @@ int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32 if(!pduel->lua->get_function_value(tuner_limit->target, 2)) continue; } - if(tuner_limit->value && !(pm->current.location & location)) + if(tuner_limit->get_integer_value() && !((uint32)pm->current.location & tuner_limit->get_integer_value())) continue; } if(pcheck) pcheck->get_value(pm); if(pm->current.location == LOCATION_MZONE && !pm->is_position(POS_FACEUP)) continue; - if(!pduel->lua->check_matching(pm, findex2, 1)) + interpreter::card2value(L, pcard); + auto res = pduel->lua->check_filter(L, pm, findex2, 1); + lua_pop(L, 1); + if (!res) continue; nsyn.push_back(pm); pm->sum_param = pm->get_synchro_level(pcard); } } else { - card_set cv; - get_synchro_material(playerid, &cv, tuner_limit); - for(auto& pm : cv) { + card_set material_set; + get_synchro_material(playerid, &material_set, tuner_limit); + for(auto& pm : material_set) { if(!pm || pm == tuner || pm == smat || must_list.find(pm) != must_list.end() || !pm->is_can_be_synchro_material(pcard, tuner)) continue; if(tuner_limit && tuner_limit->target) { @@ -2759,13 +2764,16 @@ int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32 pcheck->get_value(pm); if(pm->current.location == LOCATION_MZONE && !pm->is_position(POS_FACEUP)) continue; - if(!pduel->lua->check_matching(pm, findex2, 1)) + interpreter::card2value(L, pcard); + auto res = pduel->lua->check_filter(L, pm, findex2, 1); + lua_pop(L, 1); + if (!res) continue; nsyn.push_back(pm); pm->sum_param = pm->get_synchro_level(pcard); } } - if(ct > 0) { + if(location_count > 0) { int32 ret = check_other_synchro_material(nsyn, lv, min, max, mcount); pduel->restore_assumes(); return ret; @@ -2935,8 +2943,8 @@ int32 field::check_with_sum_greater_limit_m(const card_vector& mats, int32 acc, return TRUE; return FALSE; } -int32 field::check_xyz_material(card* scard, int32 findex, int32 lv, int32 min, int32 max, group* mg) { - get_xyz_material(scard, findex, lv, max, mg); +int32 field::check_xyz_material(lua_State* L, card* scard, int32 findex, int32 lv, int32 min, int32 max, group* mg) { + get_xyz_material(L, scard, findex, lv, max, mg); int32 playerid = scard->current.controler; int32 ct = get_spsummonable_count(scard, playerid); card_set handover_zone_cards; diff --git a/field.h b/field.h index d3072db2a..d7f6109b4 100644 --- a/field.h +++ b/field.h @@ -11,6 +11,7 @@ #include "common.h" #include "card.h" #include "effectset.h" +#include "interpreter.h" #include #include #include @@ -79,7 +80,6 @@ struct chain { }; struct player_info { - using card_vector = std::vector; int32 lp{ 0 }; int32 start_count{ 0 }; int32 draw_count{ 0 }; @@ -151,12 +151,14 @@ struct processor_unit { uint32 arg2{ 0 }; uint32 arg3{ 0 }; uint32 arg4{ 0 }; - void* ptr1{ nullptr }; - void* ptr2{ nullptr }; int32 value1{ 0 }; int32 value2{ 0 }; int32 value3{ 0 }; int32 value4{ 0 }; + void* ptr1{ nullptr }; + void* ptr2{ nullptr }; + void* ptr3{ nullptr }; + void* ptr4{ nullptr }; }; constexpr int SIZE_SVALUE = SIZE_RETURN_VALUE / 2; constexpr int SIZE_IVALUE = SIZE_RETURN_VALUE / 4; @@ -169,7 +171,6 @@ union return_value { }; struct processor { using effect_vector = std::vector; - using card_vector = std::vector; using option_vector = std::vector; using card_list = std::list; using event_list = std::list; @@ -177,7 +178,6 @@ struct processor { using instant_f_list = std::map; using chain_array = std::vector; using processor_list = std::list; - using card_set = std::set; using delayed_effect_collection = std::set>; struct chain_limit_t { chain_limit_t(int32 f, int32 p): function(f), player(p) {} @@ -364,9 +364,7 @@ struct processor { class field { public: using effect_container = std::multimap; - using card_set = std::set; using effect_vector = std::vector; - using card_vector = std::vector; using card_list = std::list; using event_list = std::list; using chain_list = std::list; @@ -435,19 +433,19 @@ class field { void filter_affected_cards(effect* peffect, card_set* cset); void filter_inrange_cards(effect* peffect, card_set* cset); void filter_player_effect(uint8 playerid, uint32 code, effect_set* eset, uint8 sort = TRUE); - int32 filter_matching_card(int32 findex, uint8 self, uint32 location1, uint32 location2, group* pgroup, card* pexception, group* pexgroup, uint32 extraargs, card** pret = nullptr, int32 fcount = 0, int32 is_target = FALSE); + int32 filter_matching_card(lua_State* L, int32 findex, uint8 self, uint32 location1, uint32 location2, group* pgroup, card* pexception, group* pexgroup, uint32 extraargs, card** pret = nullptr, int32 fcount = 0, int32 is_target = FALSE); int32 filter_field_card(uint8 self, uint32 location, uint32 location2, group* pgroup); effect* is_player_affected_by_effect(uint8 playerid, uint32 code); - int32 get_release_list(uint8 playerid, card_set* release_list, card_set* ex_list, card_set* ex_list_oneof, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason); - int32 check_release_list(uint8 playerid, int32 count, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason); + int32 get_release_list(lua_State* L, uint8 playerid, card_set* release_list, card_set* ex_list, card_set* ex_list_oneof, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason); + int32 check_release_list(lua_State* L, uint8 playerid, int32 count, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason); int32 get_summon_release_list(card* target, card_set* release_list, card_set* ex_list, card_set* ex_list_oneof, group* mg = nullptr, uint32 ex = 0, uint32 releasable = 0xff00ff, uint32 pos = 0x1); int32 get_summon_count_limit(uint8 playerid); int32 get_draw_count(uint8 playerid); void get_ritual_material(uint8 playerid, effect* peffect, card_set* material, uint8 no_level = FALSE); void get_fusion_material(uint8 playerid, card_set* material_all, card_set* material_base, uint32 location); void ritual_release(card_set* material); - void get_xyz_material(card* scard, int32 findex, uint32 lv, int32 maxc, group* mg); + void get_xyz_material(lua_State* L, card* scard, int32 findex, uint32 lv, int32 maxc, group* mg); void get_overlay_group(uint8 self, uint8 s, uint8 o, card_set* pset); int32 get_overlay_count(uint8 self, uint8 s, uint8 o); void update_disable_check_list(effect* peffect); @@ -479,15 +477,17 @@ class field { int32 get_must_material_list(uint8 playerid, uint32 limit, card_set* must_list); int32 check_must_material(group* mg, uint8 playerid, uint32 limit); void get_synchro_material(uint8 playerid, card_set* material, effect* tuner_limit = nullptr); - int32 check_synchro_material(card* pcard, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg); - int32 check_tuner_material(card* pcard, card* tuner, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg); + + //check material + int32 check_synchro_material(lua_State* L, card* pcard, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg); + int32 check_tuner_material(lua_State* L, card* pcard, card* tuner, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg); int32 check_other_synchro_material(const card_vector& nsyn, int32 lv, int32 min, int32 max, int32 mcount); int32 check_tribute(card* pcard, int32 min, int32 max, group* mg, uint8 toplayer, uint32 zone = 0x1f, uint32 releasable = 0xff00ff, uint32 pos = 0x1); static int32 check_with_sum_limit(const card_vector& mats, int32 acc, int32 index, int32 count, int32 min, int32 max, int32 opmin); static int32 check_with_sum_limit_m(const card_vector& mats, int32 acc, int32 index, int32 min, int32 max, int32 opmin, int32 must_count); static int32 check_with_sum_greater_limit(const card_vector& mats, int32 acc, int32 index, int32 opmin); static int32 check_with_sum_greater_limit_m(const card_vector& mats, int32 acc, int32 index, int32 opmin, int32 must_count); - int32 check_xyz_material(card* pcard, int32 findex, int32 lv, int32 min, int32 max, group* mg); + int32 check_xyz_material(lua_State* L, card* pcard, int32 findex, int32 lv, int32 min, int32 max, group* mg); int32 is_player_can_draw(uint8 playerid); int32 is_player_can_discard_deck(uint8 playerid, int32 count); @@ -623,7 +623,7 @@ class field { int32 change_position(uint16 step, group* targets, effect* reason_effect, uint8 reason_player, uint32 enable); int32 operation_replace(uint16 step, effect* replace_effect, group* targets, card* target, int32 is_destroy); int32 activate_effect(uint16 step, effect* peffect); - int32 select_synchro_material(int16 step, uint8 playerid, card* pcard, int32 min, int32 max, card* smat, group* mg); + int32 select_synchro_material(int16 step, uint8 playerid, card* pcard, int32 min, int32 max, card* smat, group* mg, int32 filter1, int32 filter2); int32 select_xyz_material(int16 step, uint8 playerid, uint32 lv, card* pcard, int32 min, int32 max); int32 select_release_cards(int16 step, uint8 playerid, uint8 cancelable, int32 min, int32 max); int32 select_tribute_cards(int16 step, card* target, uint8 playerid, uint8 cancelable, int32 min, int32 max, uint8 toplayer, uint32 zone); diff --git a/group.h b/group.h index fce727980..7fbf794b8 100644 --- a/group.h +++ b/group.h @@ -16,9 +16,10 @@ class card; class duel; +using card_set = std::set; + class group { public: - using card_set = std::set; duel* pduel; card_set container; card_set::iterator it; diff --git a/interpreter.cpp b/interpreter.cpp index 1963bc7f8..e0963c1d9 100644 --- a/interpreter.cpp +++ b/interpreter.cpp @@ -405,33 +405,33 @@ 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(); } diff --git a/interpreter.h b/interpreter.h index 0c0d594ce..a035a5f6c 100644 --- a/interpreter.h +++ b/interpreter.h @@ -71,7 +71,7 @@ class interpreter { 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_matching(card* pcard, int32 findex, int32 extraargs); + int32 check_filter(lua_State* L, 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); int32 get_function_value(int32 f, uint32 param_count, std::vector* result); diff --git a/libcard.cpp b/libcard.cpp index cc92b8c53..c62de1ba5 100644 --- a/libcard.cpp +++ b/libcard.cpp @@ -411,7 +411,7 @@ int32 scriptlib::card_get_linked_group(lua_State *L) { check_param_count(L, 1); check_param(L, PARAM_TYPE_CARD, 1); card* pcard = *(card**) lua_touserdata(L, 1); - card::card_set cset; + card_set cset; pcard->get_linked_cards(&cset); group* pgroup = pcard->pduel->new_group(cset); interpreter::group2value(L, pgroup); @@ -421,7 +421,7 @@ int32 scriptlib::card_get_linked_group_count(lua_State *L) { check_param_count(L, 1); check_param(L, PARAM_TYPE_CARD, 1); card* pcard = *(card**) lua_touserdata(L, 1); - card::card_set cset; + card_set cset; pcard->get_linked_cards(&cset); lua_pushinteger(L, cset.size()); return 1; @@ -444,7 +444,7 @@ int32 scriptlib::card_get_mutual_linked_group(lua_State *L) { check_param_count(L, 1); check_param(L, PARAM_TYPE_CARD, 1); card* pcard = *(card**)lua_touserdata(L, 1); - card::card_set cset; + card_set cset; pcard->get_mutual_linked_cards(&cset); group* pgroup = pcard->pduel->new_group(cset); interpreter::group2value(L, pgroup); @@ -454,7 +454,7 @@ int32 scriptlib::card_get_mutual_linked_group_count(lua_State *L) { check_param_count(L, 1); check_param(L, PARAM_TYPE_CARD, 1); card* pcard = *(card**)lua_touserdata(L, 1); - card::card_set cset; + card_set cset; pcard->get_mutual_linked_cards(&cset); lua_pushinteger(L, cset.size()); return 1; @@ -491,7 +491,7 @@ int32 scriptlib::card_get_column_group(lua_State *L) { check_param_count(L, 1); check_param(L, PARAM_TYPE_CARD, 1); card* pcard = *(card**) lua_touserdata(L, 1); - card::card_set cset; + card_set cset; pcard->get_column_cards(&cset); group* pgroup = pcard->pduel->new_group(cset); interpreter::group2value(L, pgroup); @@ -501,7 +501,7 @@ int32 scriptlib::card_get_column_group_count(lua_State *L) { check_param_count(L, 1); check_param(L, PARAM_TYPE_CARD, 1); card* pcard = *(card**) lua_touserdata(L, 1); - card::card_set cset; + card_set cset; pcard->get_column_cards(&cset); lua_pushinteger(L, cset.size()); return 1; @@ -2556,7 +2556,7 @@ int32 scriptlib::card_is_chain_attackable(lua_State *L) { lua_pushboolean(L, 0); return 1; } - field::card_vector cv; + card_vector cv; pduel->game_field->get_attack_target(attacker, &cv, TRUE); if(cv.size() == 0 && (monsteronly || attacker->direct_attackable == 0)) lua_pushboolean(L, 0); @@ -3281,7 +3281,7 @@ int32 scriptlib::card_get_attackable_target(lua_State *L) { check_param(L, PARAM_TYPE_CARD, 1); card* pcard = *(card**) lua_touserdata(L, 1); duel* pduel = pcard->pduel; - field::card_vector targets; + card_vector targets; uint8 chain_attack = FALSE; if(pduel->game_field->core.chain_attacker_id == pcard->fieldid) chain_attack = TRUE; diff --git a/libduel.cpp b/libduel.cpp index c0a34cbdc..10e0247fc 100644 --- a/libduel.cpp +++ b/libduel.cpp @@ -577,7 +577,7 @@ int32 scriptlib::duel_special_summon(lua_State *L) { if(lua_gettop(L) >= 8) zone = (uint32)lua_tointeger(L, 8); if(pcard) { - field::card_set cset; + card_set cset; cset.insert(pcard); pduel->game_field->special_summon(&cset, sumtype, sumplayer, playerid, nocheck, nolimit, positions, zone); } else @@ -807,7 +807,7 @@ int32 scriptlib::duel_change_form(lua_State *L) { if(top > 4) dd = (uint32)lua_tointeger(L, 5); if(top > 5 && lua_toboolean(L, 6)) flag |= NO_FLIP_EFFECT; if(pcard) { - field::card_set cset; + card_set cset; cset.insert(pcard); pduel->game_field->change_position(&cset, pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, au, ad, du, dd, flag, TRUE); } else @@ -934,7 +934,7 @@ int32 scriptlib::duel_swap_sequence(lua_State *L) { && pcard1->is_affect_by_effect(pduel->game_field->core.reason_effect) && pcard2->is_affect_by_effect(pduel->game_field->core.reason_effect)) { pduel->game_field->swap_card(pcard1, pcard2); - field::card_set swapped; + card_set swapped; swapped.insert(pcard1); swapped.insert(pcard2); pduel->game_field->raise_single_event(pcard1, 0, EVENT_MOVE, pduel->game_field->core.reason_effect, 0, pduel->game_field->core.reason_player, player, 0); @@ -1363,7 +1363,7 @@ int32 scriptlib::duel_equip(lua_State *L) { } int32 scriptlib::duel_equip_complete(lua_State *L) { duel* pduel = interpreter::get_duel_info(L); - field::card_set etargets; + card_set etargets; for(auto& equip_card : pduel->game_field->core.equiping_cards) { if(equip_card->is_position(POS_FACEUP)) equip_card->enable_field_effect(true); @@ -1517,7 +1517,7 @@ int32 scriptlib::duel_discard_hand(lua_State *L) { uint32 max = (uint32)lua_tointeger(L, 4); uint32 reason = (uint32)lua_tointeger(L, 5); group* pgroup = pduel->new_group(); - pduel->game_field->filter_matching_card(2, playerid, LOCATION_HAND, 0, pgroup, pexception, pexgroup, extraargs); + pduel->game_field->filter_matching_card(L, 2, playerid, LOCATION_HAND, 0, pgroup, pexception, pexgroup, extraargs); pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end()); if(pduel->game_field->core.select_cards.size() == 0) { lua_pushinteger(L, 0); @@ -1674,7 +1674,7 @@ int32 scriptlib::duel_change_attack_target(lua_State *L) { lua_pushboolean(L, 0); return 1; } - field::card_vector cv; + card_vector cv; pduel->game_field->get_attack_target(attacker, &cv, pduel->game_field->core.chain_attack); if(target && std::find(cv.begin(), cv.end(), target) != cv.end() || !target && !attacker->is_affected_by_effect(EFFECT_CANNOT_DIRECT_ATTACK)) { @@ -1865,7 +1865,7 @@ int32 scriptlib::duel_disable_summon(lua_State *L) { } uint8 sumplayer = PLAYER_NONE; effect* reason_effect = pduel->game_field->core.reason_effect; - field::card_set negated_cards; + card_set negated_cards; if (sumtype == SUMMON_TYPE_DUAL || sumtype & SUMMON_TYPE_FLIP) { if (!pcard->is_summon_negatable(sumtype, reason_effect)) return 0; @@ -1975,7 +1975,7 @@ int32 scriptlib::duel_get_mzone_count(lua_State *L) { card* mcard = nullptr; group* mgroup = nullptr; uint32 used_location[2] = { 0, 0 }; - player_info::card_vector list_mzone[2]; + card_vector list_mzone[2]; if(lua_gettop(L) >= 2 && !lua_isnil(L, 2)) { if(check_param(L, PARAM_TYPE_CARD, 2, TRUE)) { mcard = *(card**)lua_touserdata(L, 2); @@ -2034,7 +2034,7 @@ int32 scriptlib::duel_get_location_count_fromex(lua_State *L) { card* mcard = nullptr; group* mgroup = nullptr; uint32 used_location[2] = {0, 0}; - player_info::card_vector list_mzone[2]; + card_vector list_mzone[2]; if(lua_gettop(L) >= 3 && !lua_isnil(L, 3)) { if(check_param(L, PARAM_TYPE_CARD, 3, TRUE)) { mcard = *(card**) lua_touserdata(L, 3); @@ -2124,7 +2124,7 @@ int32 scriptlib::duel_get_linked_group(lua_State *L) { uint32 s = (uint32)lua_tointeger(L, 2); uint32 o = (uint32)lua_tointeger(L, 3); duel* pduel = interpreter::get_duel_info(L); - field::card_set cset; + card_set cset; pduel->game_field->get_linked_cards(rplayer, s, o, &cset); group* pgroup = pduel->new_group(cset); interpreter::group2value(L, pgroup); @@ -2138,7 +2138,7 @@ int32 scriptlib::duel_get_linked_group_count(lua_State *L) { uint32 s = (uint32)lua_tointeger(L, 2); uint32 o = (uint32)lua_tointeger(L, 3); duel* pduel = interpreter::get_duel_info(L); - field::card_set cset; + card_set cset; pduel->game_field->get_linked_cards(rplayer, s, o, &cset); lua_pushinteger(L, cset.size()); return 1; @@ -2564,7 +2564,7 @@ int32 scriptlib::duel_get_matching_group(lua_State *L) { uint32 location1 = (uint32)lua_tointeger(L, 3); uint32 location2 = (uint32)lua_tointeger(L, 4); group* pgroup = pduel->new_group(); - pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs); + pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs); interpreter::group2value(L, pgroup); return 1; } @@ -2589,7 +2589,7 @@ int32 scriptlib::duel_get_matching_count(lua_State *L) { uint32 location1 = (uint32)lua_tointeger(L, 3); uint32 location2 = (uint32)lua_tointeger(L, 4); group* pgroup = pduel->new_group(); - pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs); + pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs); uint32 count = (uint32)pgroup->container.size(); lua_pushinteger(L, count); return 1; @@ -2615,7 +2615,7 @@ int32 scriptlib::duel_get_first_matching_card(lua_State *L) { uint32 location1 = (uint32)lua_tointeger(L, 3); uint32 location2 = (uint32)lua_tointeger(L, 4); card* pret = nullptr; - pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, &pret); + pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, &pret); if(pret) interpreter::card2value(L, pret); else lua_pushnil(L); @@ -2642,7 +2642,7 @@ int32 scriptlib::duel_is_existing_matching_card(lua_State *L) { uint32 location1 = (uint32)lua_tointeger(L, 3); uint32 location2 = (uint32)lua_tointeger(L, 4); uint32 fcount = (uint32)lua_tointeger(L, 5); - lua_pushboolean(L, pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, nullptr, fcount)); + lua_pushboolean(L, pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, nullptr, fcount)); return 1; } /** @@ -2672,7 +2672,7 @@ int32 scriptlib::duel_select_matching_cards(lua_State *L) { uint32 min = (uint32)lua_tointeger(L, 6); uint32 max = (uint32)lua_tointeger(L, 7); group* pgroup = pduel->new_group(); - pduel->game_field->filter_matching_card(2, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs); + pduel->game_field->filter_matching_card(L, 2, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs); pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end()); pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16)); return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) { @@ -2704,7 +2704,7 @@ int32 scriptlib::duel_get_release_group(lua_State *L) { reason = (uint32)lua_tointeger(L, 3); duel* pduel = interpreter::get_duel_info(L); group* pgroup = pduel->new_group(); - pduel->game_field->get_release_list(playerid, &pgroup->container, &pgroup->container, &pgroup->container, FALSE, hand, 0, 0, nullptr, nullptr, reason); + pduel->game_field->get_release_list(L, playerid, &pgroup->container, &pgroup->container, &pgroup->container, FALSE, hand, 0, 0, nullptr, nullptr, reason); interpreter::group2value(L, pgroup); return 1; } @@ -2725,7 +2725,7 @@ int32 scriptlib::duel_get_release_group_count(lua_State *L) { if (lua_gettop(L) >= 3) reason = (uint32)lua_tointeger(L, 3); duel* pduel = interpreter::get_duel_info(L); - lua_pushinteger(L, pduel->game_field->get_release_list(playerid, nullptr, nullptr, FALSE, FALSE, hand, 0, 0, nullptr, nullptr, reason)); + lua_pushinteger(L, pduel->game_field->get_release_list(L, playerid, nullptr, nullptr, nullptr, FALSE, hand, 0, 0, nullptr, nullptr, reason)); return 1; } int32 scriptlib::duel_check_release_group(lua_State *L) { @@ -2748,7 +2748,7 @@ int32 scriptlib::duel_check_release_group(lua_State *L) { pexgroup = *(group**) lua_touserdata(L, 4); uint32 extraargs = lua_gettop(L) - must_param; duel* pduel = interpreter::get_duel_info(L); - int32 result = pduel->game_field->check_release_list(playerid, fcount, use_con, FALSE, 2, extraargs, pexception, pexgroup, REASON_COST); + int32 result = pduel->game_field->check_release_list(L, playerid, fcount, use_con, FALSE, 2, extraargs, pexception, pexgroup, REASON_COST); pduel->game_field->core.must_select_cards.clear(); lua_pushboolean(L, result); return 1; @@ -2778,7 +2778,7 @@ int32 scriptlib::duel_select_release_group(lua_State *L) { pduel->game_field->core.release_cards.clear(); pduel->game_field->core.release_cards_ex.clear(); pduel->game_field->core.release_cards_ex_oneof.clear(); - pduel->game_field->get_release_list(playerid, &pduel->game_field->core.release_cards, &pduel->game_field->core.release_cards_ex, &pduel->game_field->core.release_cards_ex_oneof, use_con, FALSE, 2, extraargs, pexception, pexgroup, REASON_COST); + pduel->game_field->get_release_list(L, playerid, &pduel->game_field->core.release_cards, &pduel->game_field->core.release_cards_ex, &pduel->game_field->core.release_cards_ex_oneof, use_con, FALSE, 2, extraargs, pexception, pexgroup, REASON_COST); pduel->game_field->add_process(PROCESSOR_SELECT_RELEASE, 0, 0, 0, playerid, (max << 16) + min); return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) { duel* pduel = (duel*)ctx; @@ -2813,7 +2813,7 @@ int32 scriptlib::duel_check_release_group_ex(lua_State *L) { pexgroup = *(group**) lua_touserdata(L, 6); uint32 extraargs = lua_gettop(L) - must_param; duel* pduel = interpreter::get_duel_info(L); - int32 result = pduel->game_field->check_release_list(playerid, fcount, use_con, use_hand, 2, extraargs, pexception, pexgroup, reason); + int32 result = pduel->game_field->check_release_list(L, playerid, fcount, use_con, use_hand, 2, extraargs, pexception, pexgroup, reason); pduel->game_field->core.must_select_cards.clear(); lua_pushboolean(L, result); return 1; @@ -2845,7 +2845,7 @@ int32 scriptlib::duel_select_release_group_ex(lua_State *L) { pduel->game_field->core.release_cards.clear(); pduel->game_field->core.release_cards_ex.clear(); pduel->game_field->core.release_cards_ex_oneof.clear(); - pduel->game_field->get_release_list(playerid, &pduel->game_field->core.release_cards, &pduel->game_field->core.release_cards_ex, &pduel->game_field->core.release_cards_ex_oneof, use_con, use_hand, 2, extraargs, pexception, pexgroup, reason); + pduel->game_field->get_release_list(L, playerid, &pduel->game_field->core.release_cards, &pduel->game_field->core.release_cards_ex, &pduel->game_field->core.release_cards_ex_oneof, use_con, use_hand, 2, extraargs, pexception, pexgroup, reason); pduel->game_field->add_process(PROCESSOR_SELECT_RELEASE, 0, 0, 0, playerid, (max << 16) + min); return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) { duel* pduel = (duel*)ctx; @@ -2990,7 +2990,7 @@ int32 scriptlib::duel_get_target_count(lua_State *L) { uint32 location2 = (uint32)lua_tointeger(L, 4); group* pgroup = pduel->new_group(); uint32 count = 0; - pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs, nullptr, 0, TRUE); + pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs, nullptr, 0, TRUE); count = (uint32)pgroup->container.size(); lua_pushinteger(L, count); return 1; @@ -3016,7 +3016,7 @@ int32 scriptlib::duel_is_existing_target(lua_State *L) { uint32 location1 = (uint32)lua_tointeger(L, 3); uint32 location2 = (uint32)lua_tointeger(L, 4); uint32 count = (uint32)lua_tointeger(L, 5); - lua_pushboolean(L, pduel->game_field->filter_matching_card(1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, nullptr, count, TRUE)); + lua_pushboolean(L, pduel->game_field->filter_matching_card(L, 1, (uint8)self, location1, location2, 0, pexception, pexgroup, extraargs, nullptr, count, TRUE)); return 1; } /** @@ -3048,7 +3048,7 @@ int32 scriptlib::duel_select_target(lua_State *L) { if(pduel->game_field->core.current_chain.size() == 0) return 0; group* pgroup = pduel->new_group(); - pduel->game_field->filter_matching_card(2, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs, nullptr, 0, TRUE); + pduel->game_field->filter_matching_card(L, 2, (uint8)self, location1, location2, pgroup, pexception, pexgroup, extraargs, nullptr, 0, TRUE); pduel->game_field->core.select_cards.assign(pgroup->container.begin(), pgroup->container.end()); pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid, min + (max << 16)); return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) { @@ -3184,7 +3184,7 @@ int32 scriptlib::duel_get_synchro_material(lua_State *L) { if (lua_gettop(L) >= 2) facedown = lua_toboolean(L, 2); duel* pduel = interpreter::get_duel_info(L); - group::card_set mats; + card_set mats; pduel->game_field->get_synchro_material(playerid, &mats); group* pgroup = pduel->new_group(); for (auto cit = mats.begin(); cit != mats.end(); ++cit) { @@ -3220,14 +3220,27 @@ int32 scriptlib::duel_select_synchro_material(lua_State *L) { check_param(L, PARAM_TYPE_GROUP, 8); mg = *(group**) lua_touserdata(L, 8); } - if(mg) - pduel->game_field->add_process(PROCESSOR_SELECT_SYNCHRO, 0, (effect*)mg, (group*)pcard, playerid, min + (max << 16)); - else - pduel->game_field->add_process(PROCESSOR_SELECT_SYNCHRO, 0, (effect*)smat, (group*)pcard, playerid + 0x10000, min + (max << 16)); - lua_pushvalue(L, 3); - lua_pushvalue(L, 4); - lua_pushvalue(L, 2); - lua_xmove(L, pduel->lua->lua_state, 3); + auto filter1 = interpreter::get_function_handle(L, 3); + auto filter2 = interpreter::get_function_handle(L, 4); + card_set select_cards; + if (mg) { + for (auto& pm : mg->container) { + if (pduel->game_field->check_tuner_material(L, pcard, pm, 3, 4, min, max, nullptr, mg)) + select_cards.insert(pm); + } + pduel->game_field->core.select_cards.assign(select_cards.begin(), select_cards.end()); + pduel->game_field->add_process(PROCESSOR_SELECT_SYNCHRO, 0, nullptr, nullptr, playerid, min + (max << 16), filter1, filter2, pcard, mg); + } + else { + card_set material; + pduel->game_field->get_synchro_material(playerid, &material); + for (auto& tuner : material) { + if (pduel->game_field->check_tuner_material(L, pcard, tuner, 3, 4, min, max, smat, nullptr)) + select_cards.insert(tuner); + } + pduel->game_field->core.select_cards.assign(select_cards.begin(), select_cards.end()); + pduel->game_field->add_process(PROCESSOR_SELECT_SYNCHRO, 0, nullptr, nullptr, playerid + 0x10000, min + (max << 16), filter1, filter2, pcard, smat); + } return lua_yield(L, 0); } int32 scriptlib::duel_check_synchro_material(lua_State *L) { @@ -3251,8 +3264,7 @@ int32 scriptlib::duel_check_synchro_material(lua_State *L) { check_param(L, PARAM_TYPE_GROUP, 7); mg = *(group**) lua_touserdata(L, 7); } - lua_pushvalue(L, 1); - lua_pushboolean(L, pduel->game_field->check_synchro_material(pcard, 2, 3, min, max, smat, mg)); + lua_pushboolean(L, pduel->game_field->check_synchro_material(L, pcard, 2, 3, min, max, smat, mg)); return 1; } int32 scriptlib::duel_select_tuner_material(lua_State *L) { @@ -3276,18 +3288,14 @@ int32 scriptlib::duel_select_tuner_material(lua_State *L) { check_param(L, PARAM_TYPE_GROUP, 8); mg = *(group**) lua_touserdata(L, 8); } - lua_pushvalue(L, 2); - if(!pduel->game_field->check_tuner_material(pcard, tuner, 4, 5, min, max, 0, mg)) + if(!pduel->game_field->check_tuner_material(L, pcard, tuner, 4, 5, min, max, nullptr, mg)) return 0; - lua_pop(L, 1); pduel->game_field->core.select_cards.clear(); pduel->game_field->core.select_cards.push_back(tuner); pduel->game_field->returns.bvalue[1] = 0; - pduel->game_field->add_process(PROCESSOR_SELECT_SYNCHRO, 1, (effect*)mg, (group*)pcard, playerid, min + (max << 16)); - lua_pushvalue(L, 4); - lua_pushvalue(L, 5); - lua_pushvalue(L, 2); - lua_xmove(L, pduel->lua->lua_state, 3); + auto filter1 = interpreter::get_function_handle(L, 4); + auto filter2 = interpreter::get_function_handle(L, 5); + pduel->game_field->add_process(PROCESSOR_SELECT_SYNCHRO, 1, nullptr, nullptr, playerid, min + (max << 16), filter1, filter2, pcard, mg); return lua_yield(L, 0); } int32 scriptlib::duel_check_tuner_material(lua_State *L) { @@ -3308,8 +3316,7 @@ int32 scriptlib::duel_check_tuner_material(lua_State *L) { check_param(L, PARAM_TYPE_GROUP, 7); mg = *(group**) lua_touserdata(L, 7); } - lua_pushvalue(L, 1); - lua_pushboolean(L, pduel->game_field->check_tuner_material(pcard, tuner, 3, 4, min, max, 0, mg)); + lua_pushboolean(L, pduel->game_field->check_tuner_material(L, pcard, tuner, 3, 4, min, max, nullptr, mg)); return 1; } int32 scriptlib::duel_get_ritual_material(lua_State *L) { @@ -3581,7 +3588,7 @@ int32 scriptlib::duel_check_xyz_material(lua_State *L) { check_param(L, PARAM_TYPE_GROUP, 6); mg = *(group**) lua_touserdata(L, 6); } - lua_pushboolean(L, scard->pduel->game_field->check_xyz_material(scard, findex, lv, minc, maxc, mg)); + lua_pushboolean(L, scard->pduel->game_field->check_xyz_material(L, scard, findex, lv, minc, maxc, mg)); return 1; } int32 scriptlib::duel_select_xyz_material(lua_State *L) { @@ -3604,9 +3611,9 @@ int32 scriptlib::duel_select_xyz_material(lua_State *L) { mg = *(group**) lua_touserdata(L, 7); } duel* pduel = scard->pduel; - if(!pduel->game_field->check_xyz_material(scard, findex, lv, minc, maxc, mg)) + if(!pduel->game_field->check_xyz_material(L, scard, findex, lv, minc, maxc, mg)) return 0; - pduel->game_field->get_xyz_material(scard, findex, lv, maxc, mg); + pduel->game_field->get_xyz_material(L, scard, findex, lv, maxc, mg); scard->pduel->game_field->add_process(PROCESSOR_SELECT_XMATERIAL, 0, 0, (group*)scard, playerid + (lv << 16), minc + (maxc << 16)); return lua_yield(L, 0); } @@ -3624,7 +3631,7 @@ int32 scriptlib::duel_overlay(lua_State *L) { } else return luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 2); if(pcard) { - card::card_set cset; + card_set cset; cset.insert(pcard); target->xyz_overlay(&cset); } else diff --git a/libgroup.cpp b/libgroup.cpp index ad17b66dc..453ebea69 100644 --- a/libgroup.cpp +++ b/libgroup.cpp @@ -133,28 +133,12 @@ int32 scriptlib::group_get_count(lua_State *L) { lua_pushinteger(L, pgroup->container.size()); return 1; } -int32 scriptlib::group_for_each(lua_State *L) { - check_param_count(L, 2); - check_param(L, PARAM_TYPE_GROUP, 1); - check_param(L, PARAM_TYPE_FUNCTION, 2); - duel* pduel = interpreter::get_duel_info(L); - group* pgroup = *(group**) lua_touserdata(L, 1); - int32 f = interpreter::get_function_handle(L, 2); - int32 extraargs = lua_gettop(L) - 2; - for (auto& pcard : pgroup->container) { - pduel->lua->add_param(pcard, PARAM_TYPE_CARD); - for(int32 i = 0; i < extraargs; ++i) - pduel->lua->add_param(-extraargs + i, PARAM_TYPE_INDEX); - pduel->lua->call_function(f, 1 + extraargs, 0); - } - return 0; -} int32 scriptlib::group_filter(lua_State *L) { check_param_count(L, 3); check_param(L, PARAM_TYPE_GROUP, 1); check_param(L, PARAM_TYPE_FUNCTION, 2); group* pgroup = *(group**) lua_touserdata(L, 1); - field::card_set cset(pgroup->container); + card_set cset(pgroup->container); if(check_param(L, PARAM_TYPE_CARD, 3, TRUE)) { card* pexception = *(card**) lua_touserdata(L, 3); cset.erase(pexception); @@ -167,7 +151,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); } } @@ -179,7 +163,7 @@ int32 scriptlib::group_filter_count(lua_State *L) { check_param(L, PARAM_TYPE_GROUP, 1); check_param(L, PARAM_TYPE_FUNCTION, 2); group* pgroup = *(group**) lua_touserdata(L, 1); - field::card_set cset(pgroup->container); + card_set cset(pgroup->container); if(check_param(L, PARAM_TYPE_CARD, 3, TRUE)) { card* pexception = *(card**) lua_touserdata(L, 3); cset.erase(pexception); @@ -192,7 +176,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); @@ -204,7 +188,7 @@ int32 scriptlib::group_filter_select(lua_State *L) { check_param(L, PARAM_TYPE_GROUP, 1); check_param(L, PARAM_TYPE_FUNCTION, 3); group* pgroup = *(group**) lua_touserdata(L, 1); - field::card_set cset(pgroup->container); + card_set cset(pgroup->container); if(check_param(L, PARAM_TYPE_CARD, 6, TRUE)) { card* pexception = *(card**) lua_touserdata(L, 6); cset.erase(pexception); @@ -222,7 +206,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)); @@ -242,7 +226,7 @@ int32 scriptlib::group_select(lua_State *L) { check_param_count(L, 5); check_param(L, PARAM_TYPE_GROUP, 1); group* pgroup = *(group**) lua_touserdata(L, 1); - field::card_set cset(pgroup->container); + card_set cset(pgroup->container); if(check_param(L, PARAM_TYPE_CARD, 5, TRUE)) { card* pexception = *(card**) lua_touserdata(L, 5); cset.erase(pexception); @@ -380,7 +364,7 @@ int32 scriptlib::group_cancelable_select(lua_State *L) { check_param_count(L, 5); check_param(L, PARAM_TYPE_GROUP, 1); group* pgroup = *(group**) lua_touserdata(L, 1); - field::card_set cset(pgroup->container); + card_set cset(pgroup->container); if(check_param(L, PARAM_TYPE_CARD, 5, TRUE)) { card* pexception = *(card**) lua_touserdata(L, 5); cset.erase(pexception); @@ -420,7 +404,7 @@ int32 scriptlib::group_is_exists(lua_State *L) { check_param(L, PARAM_TYPE_GROUP, 1); check_param(L, PARAM_TYPE_FUNCTION, 2); group* pgroup = *(group**) lua_touserdata(L, 1); - field::card_set cset(pgroup->container); + card_set cset(pgroup->container); if(check_param(L, PARAM_TYPE_CARD, 4, TRUE)) { card* pexception = *(card**) lua_touserdata(L, 4); cset.erase(pexception); @@ -439,7 +423,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; @@ -464,7 +448,7 @@ int32 scriptlib::group_check_with_sum_equal(lua_State *L) { if(max < min) max = min; int32 extraargs = lua_gettop(L) - 5; - field::card_vector cv(pduel->game_field->core.must_select_cards); + card_vector cv(pduel->game_field->core.must_select_cards); int32 mcount = (int32)cv.size(); for(auto& pcard : pgroup->container) { auto it = std::find(pduel->game_field->core.must_select_cards.begin(), pduel->game_field->core.must_select_cards.end(), pcard); @@ -502,7 +486,7 @@ int32 scriptlib::group_select_with_sum_equal(lua_State *L) { auto it = std::remove(pduel->game_field->core.select_cards.begin(), pduel->game_field->core.select_cards.end(), pcard); pduel->game_field->core.select_cards.erase(it, pduel->game_field->core.select_cards.end()); } - field::card_vector cv(pduel->game_field->core.must_select_cards); + card_vector cv(pduel->game_field->core.must_select_cards); int32 mcount = (int32)cv.size(); cv.insert(cv.end(), pduel->game_field->core.select_cards.begin(), pduel->game_field->core.select_cards.end()); for(auto& pcard : cv) @@ -535,7 +519,7 @@ int32 scriptlib::group_check_with_sum_greater(lua_State *L) { duel* pduel = pgroup->pduel; int32 acc = (int32)lua_tointeger(L, 3); int32 extraargs = lua_gettop(L) - 3; - field::card_vector cv(pduel->game_field->core.must_select_cards); + card_vector cv(pduel->game_field->core.must_select_cards); int32 mcount = (int32)cv.size(); for(auto& pcard : pgroup->container) { auto it = std::find(pduel->game_field->core.must_select_cards.begin(), pduel->game_field->core.must_select_cards.end(), pcard); @@ -565,7 +549,7 @@ int32 scriptlib::group_select_with_sum_greater(lua_State *L) { auto it = std::remove(pduel->game_field->core.select_cards.begin(), pduel->game_field->core.select_cards.end(), pcard); pduel->game_field->core.select_cards.erase(it, pduel->game_field->core.select_cards.end()); } - field::card_vector cv(pduel->game_field->core.must_select_cards); + card_vector cv(pduel->game_field->core.must_select_cards); int32 mcount = (int32)cv.size(); cv.insert(cv.end(), pduel->game_field->core.select_cards.begin(), pduel->game_field->core.select_cards.end()); for(auto& pcard : cv) @@ -692,7 +676,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 +751,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; } @@ -855,7 +839,7 @@ int32 scriptlib::group_meta_band(lua_State* L) { return luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 2); duel* pduel = interpreter::get_duel_info(L); group* pgroup = pduel->new_group(); - field::card_set check_set; + card_set check_set; if(check_param(L, PARAM_TYPE_CARD, 1, TRUE)) { card* ccard = *(card**) lua_touserdata(L, 1); check_set.insert(ccard); @@ -924,7 +908,6 @@ static const struct luaL_Reg grouplib[] = { { "GetFirst", scriptlib::group_get_first }, { "GetCount", scriptlib::group_get_count }, { "__len", scriptlib::group_get_count }, - { "ForEach", scriptlib::group_for_each }, { "Filter", scriptlib::group_filter }, { "FilterCount", scriptlib::group_filter_count }, { "FilterSelect", scriptlib::group_filter_select }, diff --git a/ocgapi.cpp b/ocgapi.cpp index d50b24d20..659dfcc45 100644 --- a/ocgapi.cpp +++ b/ocgapi.cpp @@ -189,7 +189,7 @@ extern "C" DECL_DLLEXPORT int32 query_card(intptr_t pduel, uint8 playerid, uint8 if(location & LOCATION_ONFIELD) pcard = ptduel->game_field->get_field_card(playerid, location, sequence); else { - field::card_vector* lst = nullptr; + card_vector* lst = nullptr; if (location == LOCATION_HAND) lst = &ptduel->game_field->player[playerid].list_hand; else if (location == LOCATION_GRAVE) @@ -273,7 +273,7 @@ extern "C" DECL_DLLEXPORT int32 query_field_card(intptr_t pduel, uint8 playerid, } } else { - field::card_vector* lst = nullptr; + card_vector* lst = nullptr; if(location == LOCATION_HAND) lst = &player.list_hand; else if(location == LOCATION_GRAVE) diff --git a/operations.cpp b/operations.cpp index 70b2d308b..b3a06b192 100644 --- a/operations.cpp +++ b/operations.cpp @@ -5287,23 +5287,9 @@ int32 field::activate_effect(uint16 step, effect* peffect) { } return TRUE; } -int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, int32 min, int32 max, card* smat, group* mg) { +int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, int32 min, int32 max, card* smat, group* mg, int32 filter1, int32 filter2) { switch(step) { case 0: { - core.select_cards.clear(); - if(mg) { - for(auto& pm : mg->container) { - if(check_tuner_material(pcard, pm, -3, -2, min, max, smat, mg)) - core.select_cards.push_back(pm); - } - } else { - card_set material; - get_synchro_material(playerid, &material); - for(auto& tuner : material) { - if(check_tuner_material(pcard, tuner, -3, -2, min, max, smat, mg)) - core.select_cards.push_back(tuner); - } - } if(core.select_cards.size() == 0) return TRUE; pduel->write_buffer8(MSG_HINT); @@ -5315,7 +5301,6 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in } case 1: { if(returns.ivalue[0] == -1) { - lua_pop(pduel->lua->current_state, 3); pduel->lua->add_param(nullptr, PARAM_TYPE_GROUP); core.limit_tuner = 0; return TRUE; @@ -5331,7 +5316,7 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in return FALSE; core.synchro_materials.clear(); pduel->lua->add_param(pcard, PARAM_TYPE_CARD); - pduel->lua->add_param(-2, PARAM_TYPE_INDEX); + pduel->lua->add_param(filter2, PARAM_TYPE_FUNCTION); pduel->lua->add_param(min, PARAM_TYPE_INT); pduel->lua->add_param(max, PARAM_TYPE_INT); core.sub_solving_event.push_back(nil_event); @@ -5342,7 +5327,6 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in return FALSE; } case 2: { - lua_pop(pduel->lua->current_state, 3); group* pgroup = pduel->new_group(core.synchro_materials); pgroup->container.insert(core.limit_tuner); pduel->lua->add_param(pgroup, PARAM_TYPE_GROUP); @@ -5441,7 +5425,9 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in pcheck->get_value(pm); if(pm->current.location == LOCATION_MZONE && !pm->is_position(POS_FACEUP)) continue; - if(!pduel->lua->check_matching(pm, -2, 1)) + pduel->lua->add_param(pm, PARAM_TYPE_CARD); + pduel->lua->add_param(pcard, PARAM_TYPE_CARD); + if (!pduel->lua->check_condition(filter2, 2)) continue; nsyn.push_back(pm); pm->sum_param = pm->get_synchro_level(pcard); @@ -5462,7 +5448,9 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in pcheck->get_value(pm); if(pm->current.location == LOCATION_MZONE && !pm->is_position(POS_FACEUP)) continue; - if(!pduel->lua->check_matching(pm, -2, 1)) + pduel->lua->add_param(pm, PARAM_TYPE_CARD); + pduel->lua->add_param(pcard, PARAM_TYPE_CARD); + if (!pduel->lua->check_condition(filter2, 2)) continue; nsyn.push_back(pm); pm->sum_param = pm->get_synchro_level(pcard); @@ -5516,8 +5504,8 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in select_cards->swap(core.select_cards); card_vector* must_select_cards = new card_vector; must_select_cards->swap(core.must_select_cards); - core.units.begin()->ptr1 = select_cards; - core.units.begin()->ptr2 = must_select_cards; + core.units.begin()->ptr3 = select_cards; + core.units.begin()->ptr4 = must_select_cards; pduel->write_buffer8(MSG_HINT); pduel->write_buffer8(HINT_SELECTMSG); pduel->write_buffer8(playerid); @@ -5527,10 +5515,10 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in } case 6: { card* pcard = core.select_cards[returns.bvalue[1]]; - card_vector* select_cards = (card_vector*)core.units.begin()->ptr1; + card_vector* select_cards = (card_vector*)core.units.begin()->ptr3; auto it = std::find(select_cards->begin(), select_cards->end(), pcard); select_cards->erase(it); - card_vector* must_select_cards = (card_vector*)core.units.begin()->ptr2; + card_vector* must_select_cards = (card_vector*)core.units.begin()->ptr4; must_select_cards->push_back(pcard); select_cards->swap(core.select_cards); must_select_cards->swap(core.must_select_cards); @@ -5593,7 +5581,6 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in return FALSE; } case 8: { - lua_pop(pduel->lua->current_state, 3); group* pgroup = pduel->new_group(); int32 mcount = (int32)core.must_select_cards.size(); for(int32 i = mcount; i < returns.bvalue[0]; ++i) { @@ -5608,7 +5595,6 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in return TRUE; } case 9: { - lua_pop(pduel->lua->current_state, 3); group* pgroup = pduel->new_group(); pgroup->container.insert(core.limit_tuner); pgroup->container.insert(smat); diff --git a/processor.cpp b/processor.cpp index f4b79cf41..2ff811f94 100644 --- a/processor.cpp +++ b/processor.cpp @@ -609,10 +609,10 @@ uint32 field::process() { } case PROCESSOR_SELECT_SYNCHRO: { int32 ret = TRUE; - if(!(it->arg1 >> 16)) - ret = select_synchro_material(it->step, it->arg1 & 0xffff, (card*)it->ptarget, it->arg2 & 0xffff, it->arg2 >> 16, 0, (group*)it->peffect); + if (!(it->arg1 >> 16)) + ret = select_synchro_material(it->step, it->arg1 & 0xffff, (card*)it->ptr1, it->arg2 & 0xffff, it->arg2 >> 16, nullptr, (group*)it->ptr2, it->arg3, it->arg4); else - ret = select_synchro_material(it->step, it->arg1 & 0xffff, (card*)it->ptarget, it->arg2 & 0xffff, it->arg2 >> 16, (card*)it->peffect, 0); + ret = select_synchro_material(it->step, it->arg1 & 0xffff, (card*)it->ptr1, it->arg2 & 0xffff, it->arg2 >> 16, (card*)it->ptr2, nullptr, it->arg3, it->arg4); if(ret) core.units.pop_front(); else diff --git a/scriptlib.h b/scriptlib.h index b10ada622..2255dda92 100644 --- a/scriptlib.h +++ b/scriptlib.h @@ -366,7 +366,6 @@ class scriptlib { static int32 group_get_next(lua_State *L); static int32 group_get_first(lua_State *L); static int32 group_get_count(lua_State *L); - static int32 group_for_each(lua_State *L); static int32 group_filter(lua_State *L); static int32 group_filter_count(lua_State *L); static int32 group_filter_select(lua_State *L);