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

add Duel.GetSZoneCount #257

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,46 @@ uint32 field::get_linked_zone(int32 playerid) {
}
return zones;
}
int32 field::get_zone_count(card* pcard, uint8 playerid, uint8 location, uint8 uplayer, uint32 reason, card* mcard, group* mgroup, uint32 zone, uint8 ex, uint32* list) {
uint32 ulocation[2] = { 0, 0 };
card_vector cvector[2];
for(int32 p = 0; p < 2; p++) {
uint32 icheck = 0x1;
card_vector& svector = (location == LOCATION_MZONE) ? player[p].list_mzone : player[p].list_szone;
for(auto& scard : svector) {
if(scard && scard != mcard && !(mgroup && mgroup->container.find(scard) != mgroup->container.end())) {
ulocation[p] |= icheck;
cvector[p].push_back(scard);
} else
cvector[p].push_back(0);
icheck <<= 0x1;
}
if(location == LOCATION_MZONE) {
ulocation[p] |= player[p].used_location & 0xff00;
player[p].list_mzone.swap(cvector[p]);
} else {
ulocation[p] <<= 0x8;
ulocation[p] |= player[p].used_location & 0xff;
player[p].list_szone.swap(cvector[p]);
}
std::swap(ulocation[p], player[p].used_location);
}
int32 count = 0;
if(ex)
count = get_useable_count_fromex(pcard, playerid, uplayer, zone, list);
else
count = get_useable_count_other(pcard, playerid, location, uplayer, reason, zone, list);
player[0].used_location = ulocation[0];
player[1].used_location = ulocation[1];
if(location == LOCATION_MZONE) {
player[0].list_mzone.swap(cvector[0]);
player[1].list_mzone.swap(cvector[1]);
} else {
player[0].list_szone.swap(cvector[0]);
player[1].list_szone.swap(cvector[1]);
}
return count;
}
void field::get_linked_cards(uint8 self, uint8 s, uint8 o, card_set* cset) {
cset->clear();
uint8 c = s;
Expand Down
1 change: 1 addition & 0 deletions field.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ class field {
int32 get_spsummonable_count_fromex_rule4(card* pcard, uint8 playerid, uint8 uplayer, uint32 zone = 0xff, uint32* list = 0);
int32 get_mzone_limit(uint8 playerid, uint8 uplayer, uint32 reason);
int32 get_szone_limit(uint8 playerid, uint8 uplayer, uint32 reason);
int32 get_zone_count(card* pcard, uint8 playerid, uint8 location, uint8 uplayer, uint32 reason, card* mcard, group* mgroup, uint32 zone = 0xff, uint8 ex = FALSE, uint32* list = 0);
uint32 get_linked_zone(int32 playerid);
void get_linked_cards(uint8 self, uint8 s, uint8 o, card_set* cset);
int32 check_extra_link(int32 playerid);
Expand Down
1 change: 1 addition & 0 deletions interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ static const struct luaL_Reg duellib[] = {
{ "CheckSummonedCount", scriptlib::duel_check_summon_count },
{ "GetLocationCount", scriptlib::duel_get_location_count },
{ "GetMZoneCount", scriptlib::duel_get_mzone_count },
{ "GetSZoneCount", scriptlib::duel_get_szone_count },
{ "GetLocationCountFromEx", scriptlib::duel_get_location_count_fromex },
{ "GetUsableMZoneCount", scriptlib::duel_get_usable_mzone_count },
{ "GetLinkedGroup", scriptlib::duel_get_linked_group },
Expand Down
80 changes: 31 additions & 49 deletions libduel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1814,33 +1814,15 @@ int32 scriptlib::duel_get_mzone_count(lua_State *L) {
if(playerid != 0 && playerid != 1)
return 0;
duel* pduel = interpreter::get_duel_info(L);
bool swapped = false;
card* mcard = 0;
group* mgroup = 0;
uint32 used_location[2] = { 0, 0 };
player_info::card_vector list_mzone[2];
if(lua_gettop(L) >= 2 && !lua_isnil(L, 2)) {
if(check_param(L, PARAM_TYPE_CARD, 2, TRUE)) {
mcard = *(card**)lua_touserdata(L, 2);
} else if(check_param(L, PARAM_TYPE_GROUP, 2, TRUE)) {
mgroup = *(group**)lua_touserdata(L, 2);
} else
luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 2);
for(int32 p = 0; p < 2; p++) {
uint32 digit = 1;
for(auto& pcard : pduel->game_field->player[p].list_mzone) {
if(pcard && pcard != mcard && !(mgroup && mgroup->container.find(pcard) != mgroup->container.end())) {
used_location[p] |= digit;
list_mzone[p].push_back(pcard);
} else
list_mzone[p].push_back(0);
digit <<= 1;
}
used_location[p] |= pduel->game_field->player[p].used_location & 0xff00;
std::swap(used_location[p], pduel->game_field->player[p].used_location);
pduel->game_field->player[p].list_mzone.swap(list_mzone[p]);
}
swapped = true;
}
uint32 uplayer = pduel->game_field->core.reason_player;
uint32 reason = LOCATION_REASON_TOFIELD;
Expand All @@ -1852,14 +1834,38 @@ int32 scriptlib::duel_get_mzone_count(lua_State *L) {
if(lua_gettop(L) >= 5)
zone = lua_tointeger(L, 5);
uint32 list = 0;
lua_pushinteger(L, pduel->game_field->get_useable_count(NULL, playerid, LOCATION_MZONE, uplayer, reason, zone, &list));
lua_pushinteger(L, pduel->game_field->get_zone_count(NULL, playerid, LOCATION_MZONE, uplayer, reason, mcard, mgroup, zone, FALSE, &list));
lua_pushinteger(L, list);
if(swapped) {
pduel->game_field->player[0].used_location = used_location[0];
pduel->game_field->player[1].used_location = used_location[1];
pduel->game_field->player[0].list_mzone.swap(list_mzone[0]);
pduel->game_field->player[1].list_mzone.swap(list_mzone[1]);
return 2;
}
int32 scriptlib::duel_get_szone_count(lua_State *L) {
check_param_count(L, 1);
uint32 playerid = lua_tointeger(L, 1);
if(playerid != 0 && playerid != 1)
return 0;
duel* pduel = interpreter::get_duel_info(L);
card* mcard = 0;
group* mgroup = 0;
if(lua_gettop(L) >= 2 && !lua_isnil(L, 2)) {
if(check_param(L, PARAM_TYPE_CARD, 2, TRUE)) {
mcard = *(card**)lua_touserdata(L, 2);
} else if(check_param(L, PARAM_TYPE_GROUP, 2, TRUE)) {
mgroup = *(group**)lua_touserdata(L, 2);
} else
luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 2);
}
uint32 uplayer = pduel->game_field->core.reason_player;
uint32 reason = LOCATION_REASON_TOFIELD;
uint32 zone = 0xff;
if(lua_gettop(L) >= 3)
uplayer = lua_tointeger(L, 3);
if(lua_gettop(L) >= 4)
reason = lua_tointeger(L, 4);
if(lua_gettop(L) >= 5)
zone = lua_tointeger(L, 5);
uint32 list = 0;
lua_pushinteger(L, pduel->game_field->get_zone_count(NULL, playerid, LOCATION_SZONE, uplayer, reason, mcard, mgroup, zone, FALSE, &list));
lua_pushinteger(L, list);
return 2;
}
int32 scriptlib::duel_get_location_count_fromex(lua_State *L) {
Expand All @@ -1871,33 +1877,15 @@ int32 scriptlib::duel_get_location_count_fromex(lua_State *L) {
uint32 uplayer = pduel->game_field->core.reason_player;
if(lua_gettop(L) >= 2)
uplayer = lua_tointeger(L, 2);
bool swapped = false;
card* mcard = 0;
group* mgroup = 0;
uint32 used_location[2] = {0, 0};
player_info::card_vector list_mzone[2];
if(lua_gettop(L) >= 3 && !lua_isnil(L, 3)) {
if(check_param(L, PARAM_TYPE_CARD, 3, TRUE)) {
mcard = *(card**) lua_touserdata(L, 3);
} else if(check_param(L, PARAM_TYPE_GROUP, 3, TRUE)) {
mgroup = *(group**) lua_touserdata(L, 3);
} else
luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 3);
for(int32 p = 0; p < 2; p++) {
uint32 digit = 1;
for(auto& pcard : pduel->game_field->player[p].list_mzone) {
if(pcard && pcard != mcard && !(mgroup && mgroup->container.find(pcard) != mgroup->container.end())) {
used_location[p] |= digit;
list_mzone[p].push_back(pcard);
} else
list_mzone[p].push_back(0);
digit <<= 1;
}
used_location[p] |= pduel->game_field->player[p].used_location & 0xff00;
std::swap(used_location[p], pduel->game_field->player[p].used_location);
pduel->game_field->player[p].list_mzone.swap(list_mzone[p]);
}
swapped = true;
}
card* scard = 0;
if(lua_gettop(L) >= 4) {
Expand All @@ -1908,14 +1896,8 @@ int32 scriptlib::duel_get_location_count_fromex(lua_State *L) {
if(lua_gettop(L) >= 5)
zone = lua_tointeger(L, 5);
uint32 list = 0;
lua_pushinteger(L, pduel->game_field->get_useable_count_fromex(scard, playerid, uplayer, zone, &list));
lua_pushinteger(L, pduel->game_field->get_zone_count(scard, playerid, LOCATION_MZONE, uplayer, LOCATION_REASON_TOFIELD, mcard, mgroup, zone, TRUE, &list));
lua_pushinteger(L, list);
if(swapped) {
pduel->game_field->player[0].used_location = used_location[0];
pduel->game_field->player[1].used_location = used_location[1];
pduel->game_field->player[0].list_mzone.swap(list_mzone[0]);
pduel->game_field->player[1].list_mzone.swap(list_mzone[1]);
}
return 2;
}
int32 scriptlib::duel_get_usable_mzone_count(lua_State *L) {
Expand Down
1 change: 1 addition & 0 deletions scriptlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ class scriptlib {
static int32 duel_check_summon_count(lua_State *L);
static int32 duel_get_location_count(lua_State *L);
static int32 duel_get_mzone_count(lua_State *L);
static int32 duel_get_szone_count(lua_State *L);
static int32 duel_get_location_count_fromex(lua_State *L);
static int32 duel_get_usable_mzone_count(lua_State *L);
static int32 duel_get_linked_group(lua_State *L);
Expand Down