Commit d7dc36c5 authored by nekrozar's avatar nekrozar Committed by mercury233

add function (#92)

parent 3865e448
......@@ -1293,6 +1293,22 @@ uint32 card::get_mutual_linked_zone() {
}
return zones;
}
int32 card::is_link_state() {
if(!(get_type() & TYPE_MONSTER))
return FALSE;
card::card_set cset1;
this->get_linked_cards(&cset1);
if(cset1.size() > 0)
return TRUE;
field::card_set cset2;
int32 p = current.controler;
uint32 linked_zone = pduel->game_field->get_linked_zone(p) | pduel->game_field->get_linked_zone(1 - p);
pduel->game_field->get_cards_in_zone(&cset2, linked_zone, p);
pduel->game_field->get_cards_in_zone(&cset2, linked_zone, 1 - p);
if(cset2.find(this) != cset2.end())
return TRUE;
return FALSE;
}
int32 card::is_position(int32 pos) {
return current.position & pos;
}
......
......@@ -199,6 +199,7 @@ public:
uint32 get_linked_zone();
void get_linked_cards(card_set* cset);
uint32 get_mutual_linked_zone();
int32 is_link_state();
int32 is_position(int32 pos);
void set_status(uint32 status, int32 enabled);
int32 get_status(uint32 status);
......
......@@ -704,6 +704,18 @@ uint32 field::get_linked_zone(int32 playerid) {
}
return zones;
}
void field::get_linked_cards(uint8 self, uint8 s, uint8 o, card_set* cset) {
cset->clear();
uint8 c = s;
for(int32 p = 0; p < 2; ++p) {
if(c) {
uint32 linked_zone = get_linked_zone(self);
get_cards_in_zone(cset, linked_zone, self);
}
self = 1 - self;
c = o;
}
}
int32 field::check_extra_link(int32 playerid) {
if(!player[playerid].list_mzone[5] || !player[playerid].list_mzone[6])
return FALSE;
......
......@@ -351,6 +351,7 @@ public:
int32 get_mzone_limit(uint8 playerid, uint8 uplayer, uint32 reason);
int32 get_szone_limit(uint8 playerid, uint8 uplayer, uint32 reason);
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);
int32 check_extra_link(int32 playerid, card* pcard, int32 sequence);
void get_cards_in_zone(card_set* cset, uint32 zone, int32 playerid);
......
......@@ -45,6 +45,7 @@ static const struct luaL_Reg cardlib[] = {
{ "GetLinkedGroup", scriptlib::card_get_linked_group },
{ "GetLinkedGroupCount", scriptlib::card_get_linked_group_count },
{ "GetLinkedZone", scriptlib::card_get_linked_zone },
{ "IsLinkState", scriptlib::card_is_link_state },
{ "GetAttribute", scriptlib::card_get_attribute },
{ "GetOriginalAttribute", scriptlib::card_get_origin_attribute },
{ "GetFusionAttribute", scriptlib::card_get_fusion_attribute },
......@@ -413,6 +414,8 @@ static const struct luaL_Reg duellib[] = {
{ "GetLocationCount", scriptlib::duel_get_location_count },
{ "GetLocationCountFromEx", scriptlib::duel_get_location_count_fromex },
{ "GetUsableMZoneCount", scriptlib::duel_get_usable_mzone_count },
{ "GetLinkedGroup", scriptlib::duel_get_linked_group },
{ "GetLinkedGroupCount", scriptlib::duel_get_linked_group_count },
{ "GetLinkedZone", scriptlib::duel_get_linked_zone },
{ "GetFieldCard", scriptlib::duel_get_field_card },
{ "CheckLocation", scriptlib::duel_check_location },
......
......@@ -297,6 +297,13 @@ int32 scriptlib::card_get_linked_zone(lua_State *L) {
lua_pushinteger(L, pcard->get_linked_zone());
return 1;
}
int32 scriptlib::card_is_link_state(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
lua_pushboolean(L, pcard->is_link_state());
return 1;
}
int32 scriptlib::card_get_attribute(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
......
......@@ -1588,6 +1588,33 @@ int32 scriptlib::duel_get_usable_mzone_count(lua_State *L) {
lua_pushinteger(L, pduel->game_field->get_useable_count(playerid, LOCATION_MZONE, uplayer, LOCATION_REASON_TOFIELD, zone));
return 1;
}
int32 scriptlib::duel_get_linked_group(lua_State *L) {
check_param_count(L, 3);
uint32 rplayer = lua_tointeger(L, 1);
if(rplayer != 0 && rplayer != 1)
return 0;
uint32 s = lua_tointeger(L, 2);
uint32 o = lua_tointeger(L, 3);
duel* pduel = interpreter::get_duel_info(L);
field::card_set cset;
pduel->game_field->get_linked_cards(rplayer, s, o, &cset);
group* pgroup = pduel->new_group(cset);
interpreter::group2value(L, pgroup);
return 1;
}
int32 scriptlib::duel_get_linked_group_count(lua_State *L) {
check_param_count(L, 3);
uint32 rplayer = lua_tointeger(L, 1);
if(rplayer != 0 && rplayer != 1)
return 0;
uint32 s = lua_tointeger(L, 2);
uint32 o = lua_tointeger(L, 3);
duel* pduel = interpreter::get_duel_info(L);
field::card_set cset;
pduel->game_field->get_linked_cards(rplayer, s, o, &cset);
lua_pushinteger(L, cset.size());
return 1;
}
int32 scriptlib::duel_get_linked_zone(lua_State *L) {
check_param_count(L, 1);
uint32 playerid = lua_tointeger(L, 1);
......
......@@ -47,6 +47,7 @@ public:
static int32 card_get_linked_group(lua_State *L);
static int32 card_get_linked_group_count(lua_State *L);
static int32 card_get_linked_zone(lua_State *L);
static int32 card_is_link_state(lua_State *L);
static int32 card_get_attribute(lua_State *L);
static int32 card_get_origin_attribute(lua_State *L);
static int32 card_get_fusion_attribute(lua_State *L);
......@@ -410,6 +411,8 @@ public:
static int32 duel_get_location_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);
static int32 duel_get_linked_group_count(lua_State *L);
static int32 duel_get_linked_zone(lua_State *L);
static int32 duel_get_field_card(lua_State *L);
static int32 duel_check_location(lua_State *L);
......
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