Commit 4956a4dc authored by nanahira's avatar nanahira

update CreateGroup, FromCards, AddCard, Merge, RemoveCard, Sub in Group lib

parent 422b1999
...@@ -14,6 +14,19 @@ ...@@ -14,6 +14,19 @@
int32 scriptlib::group_new(lua_State *L) { int32 scriptlib::group_new(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L); duel* pduel = interpreter::get_duel_info(L);
group* pgroup = pduel->new_group(); group* pgroup = pduel->new_group();
for(int32 i = 1; i <= lua_gettop(L); ++i) {
if(!lua_isnil(L, i)) {
if(check_param(L, PARAM_TYPE_CARD, i, TRUE)) {
card* pcard = *(card**) lua_touserdata(L, i);
pgroup->container.insert(pcard);
} else if (check_param(L, PARAM_TYPE_GROUP, i, TRUE)) {
group* mgroup = *(group**) lua_touserdata(L, i);
pgroup->container.insert(mgroup->container.begin(), mgroup->container.end());
} else {
luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", i);
}
}
}
interpreter::group2value(L, pgroup); interpreter::group2value(L, pgroup);
return 1; return 1;
} }
...@@ -26,19 +39,6 @@ int32 scriptlib::group_clone(lua_State *L) { ...@@ -26,19 +39,6 @@ int32 scriptlib::group_clone(lua_State *L) {
interpreter::group2value(L, newgroup); interpreter::group2value(L, newgroup);
return 1; return 1;
} }
int32 scriptlib::group_from_cards(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
group* pgroup = pduel->new_group();
for(int32 i = 0; i < lua_gettop(L); ++i) {
if(!lua_isnil(L, i + 1)) {
check_param(L, PARAM_TYPE_CARD, i + 1);
card* pcard = *(card**) lua_touserdata(L, i + 1);
pgroup->container.insert(pcard);
}
}
interpreter::group2value(L, pgroup);
return 1;
}
int32 scriptlib::group_delete(lua_State *L) { int32 scriptlib::group_delete(lua_State *L) {
check_param_count(L, 1); check_param_count(L, 1);
check_param(L, PARAM_TYPE_GROUP, 1); check_param(L, PARAM_TYPE_GROUP, 1);
...@@ -71,24 +71,46 @@ int32 scriptlib::group_clear(lua_State *L) { ...@@ -71,24 +71,46 @@ int32 scriptlib::group_clear(lua_State *L) {
return 0; return 0;
} }
int32 scriptlib::group_add_card(lua_State *L) { int32 scriptlib::group_add_card(lua_State *L) {
check_param_count(L, 2); check_param_count(L, 1);
check_param(L, PARAM_TYPE_GROUP, 1); check_param(L, PARAM_TYPE_GROUP, 1);
check_param(L, PARAM_TYPE_CARD, 2);
group* pgroup = *(group**) lua_touserdata(L, 1); group* pgroup = *(group**) lua_touserdata(L, 1);
card* pcard = *(card**) lua_touserdata(L, 2);
if (pgroup->is_readonly != 1) { if (pgroup->is_readonly != 1) {
pgroup->container.insert(pcard); for(int32 i = 2; i <= lua_gettop(L); ++i) {
if(!lua_isnil(L, i)) {
if(check_param(L, PARAM_TYPE_CARD, i, TRUE)) {
card* pcard = *(card**) lua_touserdata(L, i);
pgroup->container.insert(pcard);
} else if (check_param(L, PARAM_TYPE_GROUP, i, TRUE)) {
group* mgroup = *(group**) lua_touserdata(L, i);
pgroup->container.insert(mgroup->container.begin(), mgroup->container.end());
} else {
luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", i);
}
}
}
} }
return 0; return 0;
} }
int32 scriptlib::group_remove_card(lua_State *L) { int32 scriptlib::group_remove_card(lua_State *L) {
check_param_count(L, 2); check_param_count(L, 1);
check_param(L, PARAM_TYPE_GROUP, 1); check_param(L, PARAM_TYPE_GROUP, 1);
check_param(L, PARAM_TYPE_CARD, 2);
group* pgroup = *(group**) lua_touserdata(L, 1); group* pgroup = *(group**) lua_touserdata(L, 1);
card* pcard = *(card**) lua_touserdata(L, 2);
if (pgroup->is_readonly != 1) { if (pgroup->is_readonly != 1) {
pgroup->container.erase(pcard); for(int32 i = 2; i <= lua_gettop(L); ++i) {
if(!lua_isnil(L, i)) {
if(check_param(L, PARAM_TYPE_CARD, i, TRUE)) {
card* pcard = *(card**) lua_touserdata(L, i);
pgroup->container.erase(pcard);
} else if (check_param(L, PARAM_TYPE_GROUP, i, TRUE)) {
group* sgroup = *(group**) lua_touserdata(L, i);
for (auto& pcard : sgroup->container) {
pgroup->container.erase(pcard);
}
} else {
luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", i);
}
}
}
} }
return 0; return 0;
} }
...@@ -638,30 +660,6 @@ int32 scriptlib::group_remove(lua_State *L) { ...@@ -638,30 +660,6 @@ int32 scriptlib::group_remove(lua_State *L) {
} }
return 0; return 0;
} }
int32 scriptlib::group_merge(lua_State *L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_GROUP, 1);
check_param(L, PARAM_TYPE_GROUP, 2);
group* pgroup = *(group**) lua_touserdata(L, 1);
group* mgroup = *(group**) lua_touserdata(L, 2);
if(pgroup->is_readonly == 1)
return 0;
pgroup->container.insert(mgroup->container.begin(), mgroup->container.end());
return 0;
}
int32 scriptlib::group_sub(lua_State *L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_GROUP, 1);
check_param(L, PARAM_TYPE_GROUP, 2);
group* pgroup = *(group**) lua_touserdata(L, 1);
group* sgroup = *(group**) lua_touserdata(L, 2);
if(pgroup->is_readonly == 1)
return 0;
for (auto& pcard : sgroup->container) {
pgroup->container.erase(pcard);
}
return 0;
}
int32 scriptlib::group_equal(lua_State *L) { int32 scriptlib::group_equal(lua_State *L) {
check_param_count(L, 2); check_param_count(L, 2);
check_param(L, PARAM_TYPE_GROUP, 1); check_param(L, PARAM_TYPE_GROUP, 1);
...@@ -848,13 +846,15 @@ int32 scriptlib::group_meta_bxor(lua_State* L) { ...@@ -848,13 +846,15 @@ int32 scriptlib::group_meta_bxor(lua_State* L) {
static const struct luaL_Reg grouplib[] = { static const struct luaL_Reg grouplib[] = {
{ "CreateGroup", scriptlib::group_new }, { "CreateGroup", scriptlib::group_new },
{ "FromCards", scriptlib::group_new },
{ "KeepAlive", scriptlib::group_keep_alive }, { "KeepAlive", scriptlib::group_keep_alive },
{ "DeleteGroup", scriptlib::group_delete }, { "DeleteGroup", scriptlib::group_delete },
{ "Clone", scriptlib::group_clone }, { "Clone", scriptlib::group_clone },
{ "FromCards", scriptlib::group_from_cards },
{ "Clear", scriptlib::group_clear }, { "Clear", scriptlib::group_clear },
{ "AddCard", scriptlib::group_add_card }, { "AddCard", scriptlib::group_add_card },
{ "Merge", scriptlib::group_add_card },
{ "RemoveCard", scriptlib::group_remove_card }, { "RemoveCard", scriptlib::group_remove_card },
{ "Sub", scriptlib::group_remove_card },
{ "GetNext", scriptlib::group_get_next }, { "GetNext", scriptlib::group_get_next },
{ "GetFirst", scriptlib::group_get_first }, { "GetFirst", scriptlib::group_get_first },
{ "GetCount", scriptlib::group_get_count }, { "GetCount", scriptlib::group_get_count },
...@@ -876,8 +876,6 @@ static const struct luaL_Reg grouplib[] = { ...@@ -876,8 +876,6 @@ static const struct luaL_Reg grouplib[] = {
{ "GetSum", scriptlib::group_get_sum }, { "GetSum", scriptlib::group_get_sum },
{ "GetClassCount", scriptlib::group_get_class_count }, { "GetClassCount", scriptlib::group_get_class_count },
{ "Remove", scriptlib::group_remove }, { "Remove", scriptlib::group_remove },
{ "Merge", scriptlib::group_merge },
{ "Sub", scriptlib::group_sub },
{ "Equal", scriptlib::group_equal }, { "Equal", scriptlib::group_equal },
{ "IsContains", scriptlib::group_is_contains }, { "IsContains", scriptlib::group_is_contains },
{ "SearchCard", scriptlib::group_search_card }, { "SearchCard", scriptlib::group_search_card },
......
...@@ -328,7 +328,6 @@ public: ...@@ -328,7 +328,6 @@ public:
//Group functions //Group functions
static int32 group_new(lua_State *L); static int32 group_new(lua_State *L);
static int32 group_clone(lua_State *L); static int32 group_clone(lua_State *L);
static int32 group_from_cards(lua_State *L);
static int32 group_delete(lua_State *L); static int32 group_delete(lua_State *L);
static int32 group_keep_alive(lua_State *L); static int32 group_keep_alive(lua_State *L);
static int32 group_clear(lua_State *L); static int32 group_clear(lua_State *L);
...@@ -354,8 +353,6 @@ public: ...@@ -354,8 +353,6 @@ public:
static int32 group_get_sum(lua_State *L); static int32 group_get_sum(lua_State *L);
static int32 group_get_class_count(lua_State *L); static int32 group_get_class_count(lua_State *L);
static int32 group_remove(lua_State *L); static int32 group_remove(lua_State *L);
static int32 group_merge(lua_State *L);
static int32 group_sub(lua_State *L);
static int32 group_equal(lua_State *L); static int32 group_equal(lua_State *L);
static int32 group_is_contains(lua_State *L); static int32 group_is_contains(lua_State *L);
static int32 group_search_card(lua_State *L); static int32 group_search_card(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