From 90baf20356481d002464dcb896cf91e0c67aaa82 Mon Sep 17 00:00:00 2001 From: mercury233 Date: Sat, 15 Apr 2023 17:23:35 +0800 Subject: [PATCH 1/2] update sum_param --- field.cpp | 27 +++++++++++++++++++-------- playerop.cpp | 24 +++++++++++++++--------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/field.cpp b/field.cpp index 15c1ef737..52ceee787 100644 --- a/field.cpp +++ b/field.cpp @@ -2864,12 +2864,20 @@ int32 field::check_tribute(card* pcard, int32 min, int32 max, group* mg, uint8 t return FALSE; return TRUE; } +static void get_sum_params(uint32 sum_param, int32& op1, int32& op2) { + op1 = sum_param & 0xffff; + op2 = (sum_param >> 16) & 0xffff; + if(op2 & 0x8000) { + op1 = sum_param & 0x7fffffff; + op2 = 0; + } +} 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; + int32 op1, op2; + get_sum_params(mats[index]->sum_param, op1, op2); if(((op1 == acc && acc + opmin > op1) || (op2 && op2 == acc && acc + opmin > op2)) && count >= min) return TRUE; index++; @@ -2887,8 +2895,9 @@ int32 field::check_with_sum_limit_m(const card_vector& mats, int32 acc, int32 in 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; + int32 op1; + int32 op2; + get_sum_params(mats[index]->sum_param, op1, op2); 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, std::min(opmin, op2), must_count)) @@ -2897,8 +2906,9 @@ int32 field::check_with_sum_limit_m(const card_vector& mats, int32 acc, int32 in } int32 field::check_with_sum_greater_limit(const card_vector& mats, int32 acc, int32 index, int32 opmin) { while(index < (int32)mats.size()) { - int32 op1 = mats[index]->sum_param & 0xffff; - int32 op2 = (mats[index]->sum_param >> 16) & 0xffff; + int32 op1; + int32 op2; + get_sum_params(mats[index]->sum_param, op1, op2); if((acc <= op1 && acc + opmin > op1) || (op2 && acc <= op2 && acc + opmin > op2)) return TRUE; index++; @@ -2916,8 +2926,9 @@ int32 field::check_with_sum_greater_limit_m(const card_vector& mats, int32 acc, return check_with_sum_greater_limit(mats, acc, index, opmin); if(index >= (int32)mats.size()) return FALSE; - int32 op1 = mats[index]->sum_param & 0xffff; - int32 op2 = (mats[index]->sum_param >> 16) & 0xffff; + int32 op1; + int32 op2; + get_sum_params(mats[index]->sum_param, op1, op2); if(check_with_sum_greater_limit_m(mats, acc - op1, index + 1, std::min(opmin, op1), must_count)) return TRUE; if(op2 && check_with_sum_greater_limit_m(mats, acc - op2, index + 1, std::min(opmin, op2), must_count)) diff --git a/playerop.cpp b/playerop.cpp index 8a38ed076..4c5ba1dc2 100644 --- a/playerop.cpp +++ b/playerop.cpp @@ -605,11 +605,19 @@ int32 field::select_counter(uint16 step, uint8 playerid, uint16 countertype, uin } return TRUE; } +static void get_sum_params(int32 sum_param, int32& op1, int32& op2) { + op1 = sum_param & 0xffff; + op2 = (sum_param >> 16) & 0xffff; + if(op2 & 0x8000) { + op1 = sum_param & 0x7fffffff; + op2 = 0; + } +} 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; + int32 o1, o2; + get_sum_params(oparam[index], o1, o2); if(index == size - 1) 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))) @@ -628,7 +636,7 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32 if(max < min) max = min; pduel->write_buffer8(playerid); - pduel->write_buffer32(acc & 0xffff); + pduel->write_buffer32(acc); pduel->write_buffer8(min); pduel->write_buffer8(max); pduel->write_buffer8((uint8)core.must_select_cards.size()); @@ -679,9 +687,8 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32 int32 mcount = (int32)core.must_select_cards.size(); int32 sum = 0, mx = 0, mn = 0x7fffffff; for(int32 i = 0; i < mcount; ++i) { - int32 op = core.must_select_cards[i]->sum_param; - int32 o1 = op & 0xffff; - int32 o2 = op >> 16; + int32 o1, o2; + get_sum_params(core.must_select_cards[i]->sum_param, o1, o2); int32 ms = (o2 && o2 < o1) ? o2 : o1; sum += ms; mx += (o2 > o1) ? o2 : o1; @@ -696,9 +703,8 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32 return FALSE; } c.insert(v); - int32 op = core.select_cards[v]->sum_param; - int32 o1 = op & 0xffff; - int32 o2 = op >> 16; + int32 o1, o2; + get_sum_params(core.select_cards[v]->sum_param, o1, o2); int32 ms = (o2 && o2 < o1) ? o2 : o1; sum += ms; mx += (o2 > o1) ? o2 : o1; From 076284d3860c38866238c385b20c2b1e5be6883d Mon Sep 17 00:00:00 2001 From: mercury233 Date: Sat, 15 Apr 2023 20:29:40 +0800 Subject: [PATCH 2/2] fix --- playerop.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/playerop.cpp b/playerop.cpp index 4c5ba1dc2..f1b668107 100644 --- a/playerop.cpp +++ b/playerop.cpp @@ -605,7 +605,7 @@ int32 field::select_counter(uint16 step, uint8 playerid, uint16 countertype, uin } return TRUE; } -static void get_sum_params(int32 sum_param, int32& op1, int32& op2) { +static void get_sum_params(uint32 sum_param, int32& op1, int32& op2) { op1 = sum_param & 0xffff; op2 = (sum_param >> 16) & 0xffff; if(op2 & 0x8000) { @@ -613,7 +613,7 @@ static void get_sum_params(int32 sum_param, int32& op1, int32& op2) { op2 = 0; } } -static int32 select_sum_check1(const int32* oparam, int32 size, int32 index, int32 acc, int32 opmin) { +static int32 select_sum_check1(const uint32* oparam, int32 size, int32 index, int32 acc, int32 opmin) { if(acc == 0 || index == size) return FALSE; int32 o1, o2; @@ -660,7 +660,7 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32 } else { std::set c; if(max) { - int32 oparam[16]; + uint32 oparam[16]; int32 mcount = (int32)core.must_select_cards.size(); if(returns.bvalue[0] < min + mcount || returns.bvalue[0] > max + mcount) { pduel->write_buffer8(MSG_RETRY);