Commit 09230d32 authored by DailyShana's avatar DailyShana

update check with sum equal

cannot select unnecessary opval==0
parent 5418965e
......@@ -2512,7 +2512,7 @@ int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32
ct++;
}
if(min == 0) {
if(ct > 0 && check_with_sum_limit_m(nsyn, lv, 0, 0, 0, 2)) {
if(ct > 0 && check_with_sum_limit_m(nsyn, lv, 0, 0, 0, 0xffff, 2)) {
pduel->restore_assumes();
return TRUE;
}
......@@ -2592,7 +2592,7 @@ int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32
}
int32 field::check_other_synchro_material(const card_vector& nsyn, int32 lv, int32 min, int32 max, int32 mcount) {
if(!(core.global_flag & GLOBALFLAG_SCRAP_CHIMERA)) {
if(check_with_sum_limit_m(nsyn, lv, 0, min, max, mcount)) {
if(check_with_sum_limit_m(nsyn, lv, 0, min, max, 0xffff, mcount)) {
return TRUE;
}
return FALSE;
......@@ -2604,7 +2604,7 @@ int32 field::check_other_synchro_material(const card_vector& nsyn, int32 lv, int
break;
}
if(!pscrap) {
if(check_with_sum_limit_m(nsyn, lv, 0, min, max, mcount)) {
if(check_with_sum_limit_m(nsyn, lv, 0, min, max, 0xffff, mcount)) {
return TRUE;
}
return FALSE;
......@@ -2615,7 +2615,7 @@ int32 field::check_other_synchro_material(const card_vector& nsyn, int32 lv, int
nsyn_filtered.push_back(pm);
}
if(nsyn_filtered.size() == nsyn.size()) {
if(check_with_sum_limit_m(nsyn, lv, 0, min, max, mcount)) {
if(check_with_sum_limit_m(nsyn, lv, 0, min, max, 0xffff, mcount)) {
return TRUE;
}
} else {
......@@ -2624,7 +2624,7 @@ int32 field::check_other_synchro_material(const card_vector& nsyn, int32 lv, int
if(pscrap->get_value(nsyn[i]))
mfiltered = false;
}
if(mfiltered && check_with_sum_limit_m(nsyn_filtered, lv, 0, min, max, mcount)) {
if(mfiltered && check_with_sum_limit_m(nsyn_filtered, lv, 0, min, max, 0xffff, mcount)) {
return TRUE;
}
for(int32 i = 0; i < mcount; ++i) {
......@@ -2637,7 +2637,7 @@ int32 field::check_other_synchro_material(const card_vector& nsyn, int32 lv, int
if(!pm->is_affected_by_effect(EFFECT_SCRAP_CHIMERA))
nsyn_removed.push_back(pm);
}
if(check_with_sum_limit_m(nsyn_removed, lv, 0, min, max, mcount)) {
if(check_with_sum_limit_m(nsyn_removed, lv, 0, min, max, 0xffff, mcount)) {
return TRUE;
}
}
......@@ -2678,34 +2678,34 @@ int32 field::check_tribute(card* pcard, int32 min, int32 max, group* mg, uint8 t
return FALSE;
return TRUE;
}
int32 field::check_with_sum_limit(const card_vector& mats, int32 acc, int32 index, int32 count, int32 min, int32 max) {
int32 field::check_with_sum_limit(const card_vector& mats, int32 acc, int32 index, int32 count, int32 min, int32 max, int32 opmin) {
if(count > max)
return FALSE;
while(index < (int32)mats.size()) {
int32 op1 = mats[index]->sum_param & 0xffff;
int32 op2 = (mats[index]->sum_param >> 16) & 0xffff;
if((op1 == acc || op2 == acc) && count >= min)
if(((op1 == acc && acc + opmin > op1) || (op2 && op2 == acc && acc + opmin > op2)) && count >= min)
return TRUE;
index++;
if(acc > op1 && check_with_sum_limit(mats, acc - op1, index, count + 1, min, max))
if(acc > op1 && check_with_sum_limit(mats, acc - op1, index, count + 1, min, max, std::min(opmin, op1)))
return TRUE;
if(op2 && acc > op2 && check_with_sum_limit(mats, acc - op2, index, count + 1, min, max))
if(op2 && acc > op2 && check_with_sum_limit(mats, acc - op2, index, count + 1, min, max, std::min(opmin, op2)))
return TRUE;
}
return FALSE;
}
int32 field::check_with_sum_limit_m(const card_vector& mats, int32 acc, int32 index, int32 min, int32 max, int32 must_count) {
int32 field::check_with_sum_limit_m(const card_vector& mats, int32 acc, int32 index, int32 min, int32 max, int32 opmin, int32 must_count) {
if(acc == 0)
return index == must_count && 0 >= min && 0 <= max;
if(index == must_count)
return check_with_sum_limit(mats, acc, index, 1, min, max);
return check_with_sum_limit(mats, acc, index, 1, min, max, opmin);
if(index >= (int32)mats.size())
return FALSE;
int32 op1 = mats[index]->sum_param & 0xffff;
int32 op2 = (mats[index]->sum_param >> 16) & 0xffff;
if(acc >= op1 && check_with_sum_limit_m(mats, acc - op1, index + 1, min, max, must_count))
if(acc >= op1 && check_with_sum_limit_m(mats, acc - op1, index + 1, min, max, std::min(opmin, op1), must_count))
return TRUE;
if(op2 && acc >= op2 && check_with_sum_limit_m(mats, acc - op2, index + 1, min, max, must_count))
if(op2 && acc >= op2 && check_with_sum_limit_m(mats, acc - op2, index + 1, min, max, std::min(opmin, op2), must_count))
return TRUE;
return FALSE;
}
......
......@@ -447,8 +447,8 @@ public:
int32 check_tuner_material(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);
static int32 check_with_sum_limit_m(const card_vector& mats, int32 acc, int32 index, int32 min, int32 max, int32 must_count);
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);
......
......@@ -416,7 +416,7 @@ int32 scriptlib::group_check_with_sum_equal(lua_State *L) {
pduel->game_field->core.must_select_cards.clear();
for(auto& pcard : cv)
pcard->sum_param = pduel->lua->get_operation_value(pcard, 2, extraargs);
lua_pushboolean(L, field::check_with_sum_limit_m(cv, acc, 0, min, max, mcount));
lua_pushboolean(L, field::check_with_sum_limit_m(cv, acc, 0, min, max, 0xffff, mcount));
return 1;
}
int32 scriptlib::group_select_with_sum_equal(lua_State *L) {
......@@ -447,7 +447,7 @@ int32 scriptlib::group_select_with_sum_equal(lua_State *L) {
cv.insert(cv.end(), pduel->game_field->core.select_cards.begin(), pduel->game_field->core.select_cards.end());
for(auto& pcard : cv)
pcard->sum_param = pduel->lua->get_operation_value(pcard, 3, extraargs);
if(!field::check_with_sum_limit_m(cv, acc, 0, min, max, mcount)) {
if(!field::check_with_sum_limit_m(cv, acc, 0, min, max, 0xffff, mcount)) {
pduel->game_field->core.must_select_cards.clear();
group* empty_group = pduel->new_group();
interpreter::group2value(L, empty_group);
......
......@@ -5242,7 +5242,7 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in
nsyn.push_back(smat);
tuner->sum_param = tuner->get_synchro_level(pcard);
smat->sum_param = smat->get_synchro_level(pcard);
if(check_with_sum_limit_m(nsyn, lv, 0, 0, 0, 2))
if(check_with_sum_limit_m(nsyn, lv, 0, 0, 0, 0xffff, 2))
core.units.begin()->step = 8;
}
return FALSE;
......@@ -5416,8 +5416,8 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in
if(nsyn[i]->is_affected_by_effect(EFFECT_SCRAP_CHIMERA))
mremoved = false;
}
if(mfiltered && check_with_sum_limit_m(nsyn_filtered, lv, 0, min, max, mcount)) {
if(mremoved && check_with_sum_limit_m(nsyn_removed, lv, 0, min, max, mcount)) {
if(mfiltered && check_with_sum_limit_m(nsyn_filtered, lv, 0, min, max, 0xffff, mcount)) {
if(mremoved && check_with_sum_limit_m(nsyn_removed, lv, 0, min, max, 0xffff, mcount)) {
add_process(PROCESSOR_SELECT_YESNO, 0, 0, 0, playerid, peffect->description);
core.units.begin()->step = 9;
return FALSE;
......
......@@ -599,15 +599,15 @@ int32 field::select_counter(uint16 step, uint8 playerid, uint16 countertype, uin
}
return TRUE;
}
static int32 select_sum_check1(const int32* oparam, int32 size, int32 index, int32 acc) {
static int32 select_sum_check1(const int32* oparam, int32 size, int32 index, int32 acc, int32 opmin) {
if(acc == 0 || index == size)
return FALSE;
int32 o1 = oparam[index] & 0xffff;
int32 o2 = oparam[index] >> 16;
if(index == size - 1)
return acc == o1 || acc == o2;
return (acc > o1 && select_sum_check1(oparam, size, index + 1, acc - o1))
|| (o2 > 0 && acc > o2 && select_sum_check1(oparam, size, index + 1, acc - o2));
return (acc == o1 && acc + opmin > o1) || (o2 && acc == o2 && acc + opmin > o2);
return (acc > o1 && select_sum_check1(oparam, size, index + 1, acc - o1, std::min(o1, opmin)))
|| (o2 > 0 && acc > o2 && select_sum_check1(oparam, size, index + 1, acc - o2, std::min(o2, opmin)));
}
int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32 min, int32 max) {
if(step == 0) {
......@@ -664,7 +664,7 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32
c[v] = 1;
oparam[i] = core.select_cards[v]->sum_param;
}
if(!select_sum_check1(oparam, returns.bvalue[0], 0, acc)) {
if(!select_sum_check1(oparam, returns.bvalue[0], 0, acc, 0xffff)) {
pduel->write_buffer8(MSG_RETRY);
return FALSE;
}
......
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