Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update sum_param of MSG_SELECT_SUM #493

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -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))
Expand All @@ -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++;
Expand All @@ -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))
Expand Down
28 changes: 17 additions & 11 deletions playerop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,11 +605,19 @@ 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, int32 opmin) {
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;
}
}
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 = oparam[index] & 0xffff;
int32 o2 = oparam[index] >> 16;
int32 o1, o2;
get_sum_params(oparam[index], o1, o2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use static member:

field::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)))
Expand All @@ -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());
Expand All @@ -652,7 +660,7 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32
} else {
std::set<int32> 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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down