Commit 976ff898 authored by Chen Bill's avatar Chen Bill

change returns.bvalue to uint8

parent 96adddc1
...@@ -160,7 +160,7 @@ constexpr int SIZE_SVALUE = SIZE_RETURN_VALUE / 2; ...@@ -160,7 +160,7 @@ constexpr int SIZE_SVALUE = SIZE_RETURN_VALUE / 2;
constexpr int SIZE_IVALUE = SIZE_RETURN_VALUE / 4; constexpr int SIZE_IVALUE = SIZE_RETURN_VALUE / 4;
constexpr int SIZE_LVALUE = SIZE_RETURN_VALUE / 8; constexpr int SIZE_LVALUE = SIZE_RETURN_VALUE / 8;
union return_value { union return_value {
int8 bvalue[SIZE_RETURN_VALUE]; uint8 bvalue[SIZE_RETURN_VALUE];
int16 svalue[SIZE_SVALUE]; int16 svalue[SIZE_SVALUE];
int32 ivalue[SIZE_IVALUE]; int32 ivalue[SIZE_IVALUE];
int64 lvalue[SIZE_LVALUE]; int64 lvalue[SIZE_LVALUE];
...@@ -628,6 +628,7 @@ public: ...@@ -628,6 +628,7 @@ public:
int32 toss_dice(uint16 step, effect* reason_effect, uint8 reason_player, uint8 playerid, uint8 count1, uint8 count2); int32 toss_dice(uint16 step, effect* reason_effect, uint8 reason_player, uint8 playerid, uint8 count1, uint8 count2);
int32 rock_paper_scissors(uint16 step, uint8 repeat); int32 rock_paper_scissors(uint16 step, uint8 repeat);
bool check_response(int32 vector_size, int32 min_len, int32 max_len) const;
int32 select_battle_command(uint16 step, uint8 playerid); int32 select_battle_command(uint16 step, uint8 playerid);
int32 select_idle_command(uint16 step, uint8 playerid); int32 select_idle_command(uint16 step, uint8 playerid);
int32 select_effect_yes_no(uint16 step, uint8 playerid, uint32 description, card* pcard); int32 select_effect_yes_no(uint16 step, uint8 playerid, uint32 description, card* pcard);
......
...@@ -328,14 +328,15 @@ int32 scriptlib::group_select_unselect(lua_State *L) { ...@@ -328,14 +328,15 @@ int32 scriptlib::group_select_unselect(lua_State *L) {
pduel->game_field->add_process(PROCESSOR_SELECT_UNSELECT_CARD, 0, 0, 0, playerid + (cancelable << 16), min + (max << 16), finishable); pduel->game_field->add_process(PROCESSOR_SELECT_UNSELECT_CARD, 0, 0, 0, playerid + (cancelable << 16), min + (max << 16), finishable);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) { return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx; duel* pduel = (duel*)ctx;
if(pduel->game_field->returns.bvalue[0] == -1) { if(pduel->game_field->returns.ivalue[0] == -1) {
lua_pushnil(L); lua_pushnil(L);
} else { } else {
card* pcard; card* pcard;
if((size_t)pduel->game_field->returns.bvalue[1] < pduel->game_field->core.select_cards.size()) const int32 index = pduel->game_field->returns.bvalue[1];
pcard = pduel->game_field->core.select_cards[pduel->game_field->returns.bvalue[1]]; if(index < (int32)pduel->game_field->core.select_cards.size())
pcard = pduel->game_field->core.select_cards[index];
else else
pcard = pduel->game_field->core.unselect_cards[pduel->game_field->returns.bvalue[1] - pduel->game_field->core.select_cards.size()]; pcard = pduel->game_field->core.unselect_cards[index - pduel->game_field->core.select_cards.size()];
interpreter::card2value(L, pcard); interpreter::card2value(L, pcard);
} }
return 1; return 1;
...@@ -401,7 +402,7 @@ int32 scriptlib::group_cancelable_select(lua_State *L) { ...@@ -401,7 +402,7 @@ int32 scriptlib::group_cancelable_select(lua_State *L) {
pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid + 0x10000, min + (max << 16)); pduel->game_field->add_process(PROCESSOR_SELECT_CARD, 0, 0, 0, playerid + 0x10000, min + (max << 16));
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) { return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx; duel* pduel = (duel*)ctx;
if(pduel->game_field->returns.bvalue[0] == -1) { if(pduel->game_field->returns.ivalue[0] == -1) {
lua_pushnil(L); lua_pushnil(L);
} else { } else {
group* pgroup = pduel->new_group(); group* pgroup = pduel->new_group();
......
...@@ -6173,7 +6173,7 @@ int32 field::select_release_cards(int16 step, uint8 playerid, uint8 cancelable, ...@@ -6173,7 +6173,7 @@ int32 field::select_release_cards(int16 step, uint8 playerid, uint8 cancelable,
} }
case 7: { case 7: {
core.select_cards.clear(); core.select_cards.clear();
returns.bvalue[0] = (int8)core.operated_set.size(); returns.bvalue[0] = (uint8)core.operated_set.size();
int32 i = 0; int32 i = 0;
for(auto cit = core.operated_set.begin(); cit != core.operated_set.end(); ++cit, ++i) { for(auto cit = core.operated_set.begin(); cit != core.operated_set.end(); ++cit, ++i) {
core.select_cards.push_back(*cit); core.select_cards.push_back(*cit);
...@@ -6374,7 +6374,7 @@ int32 field::select_tribute_cards(int16 step, card* target, uint8 playerid, uint ...@@ -6374,7 +6374,7 @@ int32 field::select_tribute_cards(int16 step, card* target, uint8 playerid, uint
} }
case 9: { case 9: {
core.select_cards.clear(); core.select_cards.clear();
returns.bvalue[0] = (int8)core.operated_set.size(); returns.bvalue[0] = (uint8)core.operated_set.size();
int32 i = 0; int32 i = 0;
for(auto cit = core.operated_set.begin(); cit != core.operated_set.end(); ++cit, ++i) { for(auto cit = core.operated_set.begin(); cit != core.operated_set.end(); ++cit, ++i) {
core.select_cards.push_back(*cit); core.select_cards.push_back(*cit);
......
...@@ -14,6 +14,20 @@ ...@@ -14,6 +14,20 @@
#include <algorithm> #include <algorithm>
#include <stack> #include <stack>
bool field::check_response(int32 vector_size, int32 min_len, int32 max_len) const {
const int32 len = returns.bvalue[0];
if (len < min_len || len > max_len)
return false;
std::set<uint8> index_set;
for (int32 i = 0; i < len; ++i) {
uint8 index = returns.bvalue[1 + i];
if (index >=vector_size || index_set.count(index)) {
return false;
}
index_set.insert(index);
}
return true;
}
int32 field::select_battle_command(uint16 step, uint8 playerid) { int32 field::select_battle_command(uint16 step, uint8 playerid) {
if(step == 0) { if(step == 0) {
pduel->write_buffer8(MSG_SELECT_BATTLECMD); pduel->write_buffer8(MSG_SELECT_BATTLECMD);
...@@ -256,21 +270,15 @@ int32 field::select_card(uint16 step, uint8 playerid, uint8 cancelable, uint8 mi ...@@ -256,21 +270,15 @@ int32 field::select_card(uint16 step, uint8 playerid, uint8 cancelable, uint8 mi
} }
return FALSE; return FALSE;
} else { } else {
if(cancelable && returns.ivalue[0] == -1) if (returns.ivalue[0] == -1) {
return TRUE; if (cancelable)
if(returns.bvalue[0] < min || returns.bvalue[0] > max) { return TRUE;
pduel->write_buffer8(MSG_RETRY); pduel->write_buffer8(MSG_RETRY);
return FALSE; return FALSE;
} }
std::set<int8> c; if (!check_response(core.select_cards.size(), min, max)) {
uint8 m = (uint8)core.select_cards.size(); pduel->write_buffer8(MSG_RETRY);
for(int32 i = 0; i < returns.bvalue[0]; ++i) { return FALSE;
int8 v = returns.bvalue[i + 1];
if(v < 0 || v >= m || c.count(v)) {
pduel->write_buffer8(MSG_RETRY);
return FALSE;
}
c.insert(v);
} }
return TRUE; return TRUE;
} }
...@@ -317,13 +325,7 @@ int32 field::select_unselect_card(uint16 step, uint8 playerid, uint8 cancelable, ...@@ -317,13 +325,7 @@ int32 field::select_unselect_card(uint16 step, uint8 playerid, uint8 cancelable,
pduel->write_buffer8(MSG_RETRY); pduel->write_buffer8(MSG_RETRY);
return FALSE; return FALSE;
} }
if(returns.bvalue[0] == 0 || returns.bvalue[0] > 1) { if (!check_response(core.select_cards.size() + core.unselect_cards.size(), 1, 1)) {
pduel->write_buffer8(MSG_RETRY);
return FALSE;
}
int32 m = core.select_cards.size() + core.unselect_cards.size();
uint8 v = returns.bvalue[1];
if(v < 0 || v >= m) {
pduel->write_buffer8(MSG_RETRY); pduel->write_buffer8(MSG_RETRY);
return FALSE; return FALSE;
} }
...@@ -373,8 +375,12 @@ int32 field::select_chain(uint16 step, uint8 playerid, uint8 spe_count, uint8 fo ...@@ -373,8 +375,12 @@ int32 field::select_chain(uint16 step, uint8 playerid, uint8 spe_count, uint8 fo
} }
return FALSE; return FALSE;
} else { } else {
if(!forced && returns.ivalue[0] == -1) if (returns.ivalue[0] == -1) {
return TRUE; if (!forced)
return TRUE;
pduel->write_buffer8(MSG_RETRY);
return FALSE;
}
if(returns.ivalue[0] < 0 || returns.ivalue[0] >= (int32)core.select_chains.size()) { if(returns.ivalue[0] < 0 || returns.ivalue[0] >= (int32)core.select_chains.size()) {
pduel->write_buffer8(MSG_RETRY); pduel->write_buffer8(MSG_RETRY);
return FALSE; return FALSE;
...@@ -536,17 +542,21 @@ int32 field::select_tribute(uint16 step, uint8 playerid, uint8 cancelable, uint8 ...@@ -536,17 +542,21 @@ int32 field::select_tribute(uint16 step, uint8 playerid, uint8 cancelable, uint8
} }
return FALSE; return FALSE;
} else { } else {
if(cancelable && returns.ivalue[0] == -1) if (returns.ivalue[0] == -1) {
return TRUE; if (cancelable)
return TRUE;
pduel->write_buffer8(MSG_RETRY);
return FALSE;
}
if(returns.bvalue[0] > max) { if(returns.bvalue[0] > max) {
pduel->write_buffer8(MSG_RETRY); pduel->write_buffer8(MSG_RETRY);
return FALSE; return FALSE;
} }
std::set<int8> c; std::set<uint8> c;
uint8 m = (uint8)core.select_cards.size(), tt = 0; int32 m = (int32)core.select_cards.size(), tt = 0;
for(int32 i = 0; i < returns.bvalue[0]; ++i) { for(int32 i = 0; i < returns.bvalue[0]; ++i) {
int8 v = returns.bvalue[i + 1]; uint8 v = returns.bvalue[i + 1];
if(v < 0 || v >= m || c.count(v)) { if(v >= m || c.count(v)) {
pduel->write_buffer8(MSG_RETRY); pduel->write_buffer8(MSG_RETRY);
return FALSE; return FALSE;
} }
...@@ -742,7 +752,7 @@ int32 field::sort_card(int16 step, uint8 playerid) { ...@@ -742,7 +752,7 @@ int32 field::sort_card(int16 step, uint8 playerid) {
if(step == 0) { if(step == 0) {
returns.bvalue[0] = 0; returns.bvalue[0] = 0;
if((playerid == 1) && (core.duel_options & DUEL_SIMPLE_AI)) { if((playerid == 1) && (core.duel_options & DUEL_SIMPLE_AI)) {
returns.bvalue[0] = -1; returns.bvalue[0] = 0xff;
return TRUE; return TRUE;
} }
if(core.select_cards.empty()) if(core.select_cards.empty())
...@@ -760,13 +770,13 @@ int32 field::sort_card(int16 step, uint8 playerid) { ...@@ -760,13 +770,13 @@ int32 field::sort_card(int16 step, uint8 playerid) {
} }
return FALSE; return FALSE;
} else { } else {
if(returns.bvalue[0] == -1) if(returns.bvalue[0] == 0xff)
return TRUE; return TRUE;
std::set<int8> c; std::set<uint8> c;
uint8 m = (uint8)core.select_cards.size(); int32 m = (int32)core.select_cards.size();
for(uint8 i = 0; i < m; ++i) { for(int32 i = 0; i < m; ++i) {
int8 v = returns.bvalue[i]; uint8 v = returns.bvalue[i];
if(v < 0 || v >= m || c.count(v)) { if(v >= m || c.count(v)) {
pduel->write_buffer8(MSG_RETRY); pduel->write_buffer8(MSG_RETRY);
return FALSE; return FALSE;
} }
......
...@@ -674,12 +674,12 @@ uint32 field::process() { ...@@ -674,12 +674,12 @@ uint32 field::process() {
add_process(PROCESSOR_SORT_CARD, 0, 0, 0, sort_player, 0); add_process(PROCESSOR_SORT_CARD, 0, 0, 0, sort_player, 0);
++it->step; ++it->step;
} else { } else {
if(returns.bvalue[0] != -1) { if(returns.bvalue[0] != 0xff) {
card* tc[16]; card* tc[16];
for(i = 0; i < count; ++i) for(i = 0; i < count; ++i)
player[target_player].list_main.pop_back(); player[target_player].list_main.pop_back();
for(i = 0; i < count; ++i) for(i = 0; i < count; ++i)
tc[(uint8)returns.bvalue[i]] = core.select_cards[i]; tc[returns.bvalue[i]] = core.select_cards[i];
for(i = 0; i < count; ++i) { for(i = 0; i < count; ++i) {
player[target_player].list_main.push_back(tc[count - i - 1]); player[target_player].list_main.push_back(tc[count - i - 1]);
tc[count - i - 1]->current.sequence = (uint8)player[target_player].list_main.size() - 1; tc[count - i - 1]->current.sequence = (uint8)player[target_player].list_main.size() - 1;
......
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