Commit ad00f8bf authored by mercury233's avatar mercury233 Committed by GitHub

fix card_operation_sort undefined behavior (#589)

parent 476c8892
...@@ -106,11 +106,13 @@ bool card::card_operation_sort(card* c1, card* c2) { ...@@ -106,11 +106,13 @@ bool card::card_operation_sort(card* c1, card* c2) {
return true; return true;
} }
// faceup deck cards should go at the very first // faceup deck cards should go at the very first
if(c1->current.position != c2->current.position) { auto c1_faceup = c1->current.position & POS_FACEUP;
if(c1->current.position & POS_FACEUP) auto c2_faceup = c2->current.position & POS_FACEUP;
return false; if(c1_faceup || c2_faceup) {
if(c1_faceup && c2_faceup)
return c1->current.sequence > c2->current.sequence;
else else
return true; return c2_faceup;
} }
// sort deck as card property // sort deck as card property
auto c1_type = c1->data.type & 0x7; auto c1_type = c1->data.type & 0x7;
...@@ -120,7 +122,7 @@ bool card::card_operation_sort(card* c1, card* c2) { ...@@ -120,7 +122,7 @@ bool card::card_operation_sort(card* c1, card* c2) {
return c1_type > c2_type; return c1_type > c2_type;
if(c1_type & TYPE_MONSTER) { if(c1_type & TYPE_MONSTER) {
if (c1->data.level != c2->data.level) if (c1->data.level != c2->data.level)
return c1->data.level > c2->data.level; return c1->data.level < c2->data.level;
// TODO: more sorts here // TODO: more sorts here
} }
if(c1->data.code != c2->data.code) if(c1->data.code != c2->data.code)
......
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