Commit f2a5661d authored by salix5's avatar salix5 Committed by GitHub

API Change: change signature of query_card, simplify location handling (#807)

parent 60c3c4f0
......@@ -498,13 +498,44 @@ int32_t field::get_pzone_sequence(uint8_t pseq) const {
return 7;
}
}
const card_vector* field::get_field_vector(uint8_t playerid, uint8_t location) const {
if (!check_playerid(playerid))
return nullptr;
switch (location) {
case LOCATION_MZONE:
return &player[playerid].list_mzone;
case LOCATION_SZONE:
return &player[playerid].list_szone;
case LOCATION_DECK:
return &player[playerid].list_main;
case LOCATION_HAND:
return &player[playerid].list_hand;
case LOCATION_GRAVE:
return &player[playerid].list_grave;
case LOCATION_REMOVED:
return &player[playerid].list_remove;
case LOCATION_EXTRA:
return &player[playerid].list_extra;
default:
return nullptr;
}
}
card* field::get_field_card(uint8_t playerid, uint32_t general_location, uint8_t sequence) const {
if (!check_playerid(playerid))
return nullptr;
switch(general_location) {
case LOCATION_MZONE: {
if(sequence < (int32_t)player[playerid].list_mzone.size())
return player[playerid].list_mzone[sequence];
case LOCATION_MZONE:
case LOCATION_DECK:
case LOCATION_HAND:
case LOCATION_GRAVE:
case LOCATION_REMOVED:
case LOCATION_EXTRA: {
auto ptr = get_field_vector(playerid, general_location);
if (!ptr)
return nullptr;
auto& container = *ptr;
if (sequence < container.size())
return container[sequence];
else
return nullptr;
break;
......@@ -531,41 +562,6 @@ card* field::get_field_card(uint8_t playerid, uint32_t general_location, uint8_t
return nullptr;
break;
}
case LOCATION_DECK: {
if(sequence < player[playerid].list_main.size())
return player[playerid].list_main[sequence];
else
return nullptr;
break;
}
case LOCATION_HAND: {
if(sequence < player[playerid].list_hand.size())
return player[playerid].list_hand[sequence];
else
return nullptr;
break;
}
case LOCATION_GRAVE: {
if(sequence < player[playerid].list_grave.size())
return player[playerid].list_grave[sequence];
else
return nullptr;
break;
}
case LOCATION_REMOVED: {
if(sequence < player[playerid].list_remove.size())
return player[playerid].list_remove[sequence];
else
return nullptr;
break;
}
case LOCATION_EXTRA: {
if(sequence < player[playerid].list_extra.size())
return player[playerid].list_extra[sequence];
else
return nullptr;
break;
}
}
return nullptr;
}
......
......@@ -383,6 +383,7 @@ public:
void set_control(card* pcard, uint8_t playerid, uint16_t reset_phase, uint8_t reset_count);
int32_t get_pzone_sequence(uint8_t pseq) const;
const card_vector* get_field_vector(uint8_t playerid, uint8_t location) const;
card* get_field_card(uint8_t playerid, uint32_t general_location, uint8_t sequence) const;
int32_t is_location_useable(uint8_t playerid, uint32_t general_location, uint8_t sequence) const;
int32_t get_useable_count(card* pcard, uint8_t playerid, uint8_t location, uint8_t uplayer, uint32_t reason, uint32_t zone = 0xff, uint32_t* list = nullptr);
......
......@@ -204,7 +204,7 @@ OCGCORE_API void new_tag_card(intptr_t pduel, uint32_t code, uint8_t owner, uint
* @param buf int32_t array
* @return buffer length in bytes
*/
OCGCORE_API int32_t query_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, int32_t query_flag, byte* buf, int32_t use_cache) {
OCGCORE_API int32_t query_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint32_t query_flag, byte* buf, int32_t use_cache) {
if (!check_playerid(playerid))
return LEN_FAIL;
duel* ptduel = (duel*)pduel;
......@@ -213,22 +213,13 @@ OCGCORE_API int32_t query_card(intptr_t pduel, uint8_t playerid, uint8_t locatio
if (location == LOCATION_MZONE || location == LOCATION_SZONE)
pcard = ptduel->game_field->get_field_card(playerid, location, sequence);
else {
card_vector* lst = nullptr;
if (location == LOCATION_HAND)
lst = &ptduel->game_field->player[playerid].list_hand;
else if (location == LOCATION_GRAVE)
lst = &ptduel->game_field->player[playerid].list_grave;
else if (location == LOCATION_REMOVED)
lst = &ptduel->game_field->player[playerid].list_remove;
else if (location == LOCATION_EXTRA)
lst = &ptduel->game_field->player[playerid].list_extra;
else if (location == LOCATION_DECK)
lst = &ptduel->game_field->player[playerid].list_main;
else
auto ptr = ptduel->game_field->get_field_vector(playerid, location);
if(!ptr)
return LEN_FAIL;
if (sequence >= (int32_t)lst->size())
auto& lst = *ptr;
if (sequence >= lst.size())
return LEN_FAIL;
pcard = (*lst)[sequence];
pcard = lst[sequence];
}
if (pcard) {
return pcard->get_infos(buf, query_flag, use_cache);
......
......@@ -53,7 +53,7 @@ OCGCORE_API int32_t get_message(intptr_t pduel, byte* buf);
OCGCORE_API uint32_t process(intptr_t pduel);
OCGCORE_API void new_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position);
OCGCORE_API void new_tag_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t location);
OCGCORE_API int32_t query_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, int32_t query_flag, byte* buf, int32_t use_cache);
OCGCORE_API int32_t query_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, uint32_t query_flag, byte* buf, int32_t use_cache);
OCGCORE_API int32_t query_field_count(intptr_t pduel, uint8_t playerid, uint8_t location);
OCGCORE_API int32_t query_field_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint32_t query_flag, byte* buf, int32_t use_cache);
OCGCORE_API int32_t query_field_info(intptr_t pduel, byte* buf);
......
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