Skip to content

Commit

Permalink
fix card_operation_sort segfault (Fluorohydride#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
purerosefallen authored May 14, 2024
1 parent 3fd1f4e commit 476c889
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,35 +98,34 @@ bool card::card_operation_sort(card* c1, card* c2) {
else
return c1->current.sequence < c2->current.sequence;
} else if (c1->current.location & LOCATION_DECK && !pduel->game_field->core.select_deck_seq_preserved) {
// faceup deck cards should go at the very first
if(c1->current.position != c2->current.position) {
if(c1->current.position & POS_FACEUP)
return false;
else
return true;
}
// if deck reversed and the card being at the top, it should go first
if(pduel->game_field->core.deck_reversed) {
if(c1->current.sequence == pduel->game_field->player[cp1].list_main.size() - 1)
return false;
if(c2->current.sequence == pduel->game_field->player[cp2].list_main.size() - 1)
return true;
}
// faceup deck cards should go at the very first
if(c1->current.position != c2->current.position) {
if(c1->current.position & POS_FACEUP)
return false;
else
return true;
}
// sort deck as card property
auto c1_type = c1->data.type & 0x7;
auto c2_type = c2->data.type & 0x7;
// monster should go before spell, and then trap
if(c1_type != c2_type)
return c1_type > c2_type;
if(c1_type & TYPE_MONSTER) {
// sort monster by level, then code
if(c1->data.level != c2->data.level)
return c1->data.level < c2->data.level;
else
return c1->data.code > c2->data.code;
} else
// spell and trap should go by code
if (c1->data.level != c2->data.level)
return c1->data.level > c2->data.level;
// TODO: more sorts here
}
if(c1->data.code != c2->data.code)
return c1->data.code > c2->data.code;
return c1->current.sequence > c2->current.sequence;
} else {
if(c1->current.location & (LOCATION_DECK | LOCATION_EXTRA | LOCATION_GRAVE | LOCATION_REMOVED))
return c1->current.sequence > c2->current.sequence;
Expand Down

0 comments on commit 476c889

Please sign in to comment.