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

field: use const reference in overloaded functions #671

Merged
merged 9 commits into from
Nov 22, 2024
Merged
9 changes: 4 additions & 5 deletions card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1569,12 +1569,11 @@ int32 card::get_old_union_count() {
}
return count;
}
void card::xyz_overlay(card_set* materials) {
if(materials->empty())
void card::xyz_overlay(const card_set& materials) {
if(materials.empty())
return;
card_set des, leave_grave, leave_deck;
card_vector cv;
cv.assign(materials->begin(), materials->end());
card_vector cv(materials.begin(), materials.end());
std::sort(cv.begin(), cv.end(), card::card_operation_sort);
if(pduel->game_field->core.global_flag & GLOBALFLAG_DECK_REVERSE_CHECK) {
int32 d0 = (int32)pduel->game_field->player[0].list_main.size() - 1, s0 = d0;
Expand Down Expand Up @@ -1659,7 +1658,7 @@ void card::xyz_overlay(card_set* materials) {
pduel->game_field->process_instant_event();
}
if(des.size())
pduel->game_field->destroy(&des, 0, REASON_LOST_TARGET + REASON_RULE, PLAYER_NONE);
pduel->game_field->destroy(des, 0, REASON_LOST_TARGET + REASON_RULE, PLAYER_NONE);
else
pduel->game_field->adjust_instant();
}
Expand Down
2 changes: 1 addition & 1 deletion card.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class card {
void unequip();
int32 get_union_count();
int32 get_old_union_count();
void xyz_overlay(card_set* materials);
void xyz_overlay(const card_set& materials);
void xyz_add(card* mat);
void xyz_remove(card* mat);
void apply_field_effect();
Expand Down
10 changes: 5 additions & 5 deletions field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1927,21 +1927,21 @@ void field::get_fusion_material(uint8 playerid, card_set* material_all, card_set
}
material_all->insert(material_base->begin(), material_base->end());
}
void field::ritual_release(card_set* material) {
void field::ritual_release(const card_set& material) {
card_set rel;
card_set rem;
card_set tgy;
for(auto& pcard : *material) {
for(const auto& pcard : material) {
if(pcard->current.location == LOCATION_GRAVE)
rem.insert(pcard);
else if(pcard->current.location == LOCATION_OVERLAY || pcard->current.location == LOCATION_EXTRA)
tgy.insert(pcard);
else
rel.insert(pcard);
}
send_to(&tgy, core.reason_effect, REASON_RITUAL + REASON_EFFECT + REASON_MATERIAL, core.reason_player, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP);
release(&rel, core.reason_effect, REASON_RITUAL + REASON_EFFECT + REASON_MATERIAL, core.reason_player);
send_to(&rem, core.reason_effect, REASON_RITUAL + REASON_EFFECT + REASON_MATERIAL, core.reason_player, PLAYER_NONE, LOCATION_REMOVED, 0, POS_FACEUP);
send_to(tgy, core.reason_effect, REASON_RITUAL + REASON_EFFECT + REASON_MATERIAL, core.reason_player, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP);
release(rel, core.reason_effect, REASON_RITUAL + REASON_EFFECT + REASON_MATERIAL, core.reason_player);
send_to(rem, core.reason_effect, REASON_RITUAL + REASON_EFFECT + REASON_MATERIAL, core.reason_player, PLAYER_NONE, LOCATION_REMOVED, 0, POS_FACEUP);
}
void field::get_xyz_material(lua_State* L, card* scard, int32 findex, uint32 lv, int32 maxc, group* mg) {
core.xmaterial_lst.clear();
Expand Down
16 changes: 8 additions & 8 deletions field.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ class field {
int32 get_draw_count(uint8 playerid);
void get_ritual_material(uint8 playerid, effect* peffect, card_set* material, uint8 no_level = FALSE);
void get_fusion_material(uint8 playerid, card_set* material_all, card_set* material_base, uint32 location);
void ritual_release(card_set* material);
void ritual_release(const card_set& material);
void get_xyz_material(lua_State* L, card* scard, int32 findex, uint32 lv, int32 maxc, group* mg);
void get_overlay_group(uint8 self, uint8 s, uint8 o, card_set* pset);
int32 get_overlay_count(uint8 self, uint8 s, uint8 o);
Expand Down Expand Up @@ -564,9 +564,9 @@ class field {
void change_target_param(uint8 chaincount, int32 param);
void remove_counter(uint32 reason, card* pcard, uint32 rplayer, uint32 s, uint32 o, uint32 countertype, uint32 count);
void remove_overlay_card(uint32 reason, card* pcard, uint32 rplayer, uint32 s, uint32 o, uint16 min, uint16 max);
void get_control(card_set* targets, effect* reason_effect, uint32 reason_player, uint32 playerid, uint32 reset_phase, uint32 reset_count, uint32 zone);
void get_control(const card_set& targets, effect* reason_effect, uint32 reason_player, uint32 playerid, uint32 reset_phase, uint32 reset_count, uint32 zone);
void get_control(card* target, effect* reason_effect, uint32 reason_player, uint32 playerid, uint32 reset_phase, uint32 reset_count, uint32 zone);
void swap_control(effect* reason_effect, uint32 reason_player, card_set* targets1, card_set* targets2, uint32 reset_phase, uint32 reset_count);
void swap_control(effect* reason_effect, uint32 reason_player, const card_set& targets1, const card_set& targets2, uint32 reset_phase, uint32 reset_count);
void swap_control(effect* reason_effect, uint32 reason_player, card* pcard1, card* pcard2, uint32 reset_phase, uint32 reset_count);
void equip(uint32 equip_player, card* equip_card, card* target, uint32 up, uint32 is_step);
void draw(effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, int32 count);
Expand All @@ -575,17 +575,17 @@ class field {
void summon(uint32 sumplayer, card* target, effect* proc, uint32 ignore_count, uint32 min_tribute, uint32 zone = 0x1f, uint32 action_type = SUMMON_IN_IDLE);
void mset(uint32 setplayer, card* target, effect* proc, uint32 ignore_count, uint32 min_tribute, uint32 zone = 0x1f, uint32 action_type = SUMMON_IN_IDLE);
void special_summon_rule(uint32 sumplayer, card* target, uint32 summon_type, uint32 action_type = SUMMON_IN_IDLE);
void special_summon(card_set* target, uint32 sumtype, uint32 sumplayer, uint32 playerid, uint32 nocheck, uint32 nolimit, uint32 positions, uint32 zone);
void special_summon(const card_set& target, uint32 sumtype, uint32 sumplayer, uint32 playerid, uint32 nocheck, uint32 nolimit, uint32 positions, uint32 zone);
void special_summon_step(card* target, uint32 sumtype, uint32 sumplayer, uint32 playerid, uint32 nocheck, uint32 nolimit, uint32 positions, uint32 zone);
void special_summon_complete(effect* reason_effect, uint8 reason_player);
void destroy(card_set* targets, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid = 2, uint32 destination = 0, uint32 sequence = 0);
void destroy(card_set& targets, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid = 2, uint32 destination = 0, uint32 sequence = 0);
void destroy(card* target, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid = 2, uint32 destination = 0, uint32 sequence = 0);
void release(card_set* targets, effect* reason_effect, uint32 reason, uint32 reason_player);
void release(const card_set& targets, effect* reason_effect, uint32 reason, uint32 reason_player);
void release(card* target, effect* reason_effect, uint32 reason, uint32 reason_player);
void send_to(card_set* targets, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence, uint32 position, uint8 send_activating = FALSE);
void send_to(const card_set& targets, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence, uint32 position, uint8 send_activating = FALSE);
void send_to(card* target, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence, uint32 position, uint8 send_activating = FALSE);
void move_to_field(card* target, uint32 move_player, uint32 playerid, uint32 destination, uint32 positions, uint32 enable = FALSE, uint32 ret = 0, uint32 pzone = FALSE, uint32 zone = 0xff);
void change_position(card_set* targets, effect* reason_effect, uint32 reason_player, uint32 au, uint32 ad, uint32 du, uint32 dd, uint32 flag, uint32 enable = FALSE);
void change_position(const card_set& targets, effect* reason_effect, uint32 reason_player, uint32 au, uint32 ad, uint32 du, uint32 dd, uint32 flag, uint32 enable = FALSE);
void change_position(card* target, effect* reason_effect, uint32 reason_player, uint32 npos, uint32 flag, uint32 enable = FALSE);
void operation_replace(int32 type, int32 step, group* targets);
void select_tribute_cards(card* target, uint8 playerid, uint8 cancelable, int32 min, int32 max, uint8 toplayer, uint32 zone);
Expand Down
41 changes: 19 additions & 22 deletions libduel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ int32 scriptlib::duel_destroy(lua_State *L) {
if(pcard)
pduel->game_field->destroy(pcard, pduel->game_field->core.reason_effect, reason, reason_player, PLAYER_NONE, dest, 0);
else
pduel->game_field->destroy(&(pgroup->container), pduel->game_field->core.reason_effect, reason, reason_player, PLAYER_NONE, dest, 0);
pduel->game_field->destroy(pgroup->container, pduel->game_field->core.reason_effect, reason, reason_player, PLAYER_NONE, dest, 0);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
Expand Down Expand Up @@ -240,7 +240,7 @@ int32 scriptlib::duel_remove(lua_State *L) {
if(pcard)
pduel->game_field->send_to(pcard, pduel->game_field->core.reason_effect, reason, reason_player, PLAYER_NONE, LOCATION_REMOVED, 0, pos);
else
pduel->game_field->send_to(&(pgroup->container), pduel->game_field->core.reason_effect, reason, reason_player, PLAYER_NONE, LOCATION_REMOVED, 0, pos);
pduel->game_field->send_to(pgroup->container, pduel->game_field->core.reason_effect, reason, reason_player, PLAYER_NONE, LOCATION_REMOVED, 0, pos);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
Expand Down Expand Up @@ -268,7 +268,7 @@ int32 scriptlib::duel_sendto_grave(lua_State *L) {
if(pcard)
pduel->game_field->send_to(pcard, pduel->game_field->core.reason_effect, reason, reason_player, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP);
else
pduel->game_field->send_to(&(pgroup->container), pduel->game_field->core.reason_effect, reason, reason_player, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP);
pduel->game_field->send_to(pgroup->container, pduel->game_field->core.reason_effect, reason, reason_player, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
Expand Down Expand Up @@ -577,11 +577,10 @@ int32 scriptlib::duel_special_summon(lua_State *L) {
if(lua_gettop(L) >= 8)
zone = (uint32)lua_tointeger(L, 8);
if(pcard) {
card_set cset;
cset.insert(pcard);
pduel->game_field->special_summon(&cset, sumtype, sumplayer, playerid, nocheck, nolimit, positions, zone);
card_set cset{ pcard };
pduel->game_field->special_summon(cset, sumtype, sumplayer, playerid, nocheck, nolimit, positions, zone);
} else
pduel->game_field->special_summon(&(pgroup->container), sumtype, sumplayer, playerid, nocheck, nolimit, positions, zone);
pduel->game_field->special_summon(pgroup->container, sumtype, sumplayer, playerid, nocheck, nolimit, positions, zone);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
Expand Down Expand Up @@ -644,7 +643,7 @@ int32 scriptlib::duel_sendto_hand(lua_State *L) {
if(pcard)
pduel->game_field->send_to(pcard, pduel->game_field->core.reason_effect, reason, reason_player, playerid, LOCATION_HAND, 0, POS_FACEUP);
else
pduel->game_field->send_to(&(pgroup->container), pduel->game_field->core.reason_effect, reason, reason_player, playerid, LOCATION_HAND, 0, POS_FACEUP);
pduel->game_field->send_to(pgroup->container, pduel->game_field->core.reason_effect, reason, reason_player, playerid, LOCATION_HAND, 0, POS_FACEUP);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
Expand Down Expand Up @@ -679,7 +678,7 @@ int32 scriptlib::duel_sendto_deck(lua_State *L) {
if (pcard)
pduel->game_field->send_to(pcard, pduel->game_field->core.reason_effect, reason, reason_player, playerid, LOCATION_DECK, sequence, POS_FACEUP, send_activating);
else
pduel->game_field->send_to(&(pgroup->container), pduel->game_field->core.reason_effect, reason, reason_player, playerid, LOCATION_DECK, sequence, POS_FACEUP, send_activating);
pduel->game_field->send_to(pgroup->container, pduel->game_field->core.reason_effect, reason, reason_player, playerid, LOCATION_DECK, sequence, POS_FACEUP, send_activating);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
Expand Down Expand Up @@ -707,7 +706,7 @@ int32 scriptlib::duel_sendto_extra(lua_State *L) {
if(pcard)
pduel->game_field->send_to(pcard, pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, LOCATION_EXTRA, 0, POS_FACEUP);
else
pduel->game_field->send_to(&(pgroup->container), pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, LOCATION_EXTRA, 0, POS_FACEUP);
pduel->game_field->send_to(pgroup->container, pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, LOCATION_EXTRA, 0, POS_FACEUP);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
Expand Down Expand Up @@ -807,11 +806,10 @@ int32 scriptlib::duel_change_form(lua_State *L) {
if(top > 4) dd = (uint32)lua_tointeger(L, 5);
if(top > 5 && lua_toboolean(L, 6)) flag |= NO_FLIP_EFFECT;
if(pcard) {
card_set cset;
cset.insert(pcard);
pduel->game_field->change_position(&cset, pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, au, ad, du, dd, flag, TRUE);
card_set cset{ pcard };
pduel->game_field->change_position(cset, pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, au, ad, du, dd, flag, TRUE);
} else
pduel->game_field->change_position(&(pgroup->container), pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, au, ad, du, dd, flag, TRUE);
pduel->game_field->change_position(pgroup->container, pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, au, ad, du, dd, flag, TRUE);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
Expand Down Expand Up @@ -839,7 +837,7 @@ int32 scriptlib::duel_release(lua_State *L) {
if(pcard)
pduel->game_field->release(pcard, pduel->game_field->core.reason_effect, reason, reason_player);
else
pduel->game_field->release(&(pgroup->container), pduel->game_field->core.reason_effect, reason, reason_player);
pduel->game_field->release(pgroup->container, pduel->game_field->core.reason_effect, reason, reason_player);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
Expand Down Expand Up @@ -1410,7 +1408,7 @@ int32 scriptlib::duel_get_control(lua_State *L) {
if(pcard)
pduel->game_field->get_control(pcard, pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, playerid, reset_phase, reset_count, zone);
else
pduel->game_field->get_control(&pgroup->container, pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, playerid, reset_phase, reset_count, zone);
pduel->game_field->get_control(pgroup->container, pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, playerid, reset_phase, reset_count, zone);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushinteger(L, pduel->game_field->returns.ivalue[0]);
Expand Down Expand Up @@ -1444,7 +1442,7 @@ int32 scriptlib::duel_swap_control(lua_State *L) {
if(pcard1)
pduel->game_field->swap_control(pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, pcard1, pcard2, reset_phase, reset_count);
else
pduel->game_field->swap_control(pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, &pgroup1->container, &pgroup2->container, reset_phase, reset_count);
pduel->game_field->swap_control(pduel->game_field->core.reason_effect, pduel->game_field->core.reason_player, pgroup1->container, pgroup2->container, reset_phase, reset_count);
return lua_yieldk(L, 0, (lua_KContext)pduel, [](lua_State *L, int32 status, lua_KContext ctx) {
duel* pduel = (duel*)ctx;
lua_pushboolean(L, pduel->game_field->returns.ivalue[0]);
Expand Down Expand Up @@ -3346,7 +3344,7 @@ int32 scriptlib::duel_release_ritual_material(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_GROUP, 1);
group* pgroup = *(group**) lua_touserdata(L, 1);
pgroup->pduel->game_field->ritual_release(&pgroup->container);
pgroup->pduel->game_field->ritual_release(pgroup->container);
return lua_yield(L, 0);
}
int32 scriptlib::duel_get_fusion_material(lua_State *L) {
Expand Down Expand Up @@ -3631,11 +3629,10 @@ int32 scriptlib::duel_overlay(lua_State *L) {
} else
return luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 2);
if(pcard) {
card_set cset;
cset.insert(pcard);
target->xyz_overlay(&cset);
card_set cset{ pcard };
target->xyz_overlay(cset);
} else
target->xyz_overlay(&pgroup->container);
target->xyz_overlay(pgroup->container);
uint32 adjust = TRUE;
if(lua_gettop(L) > 2) {
adjust = lua_toboolean(L, 3);
Expand Down
Loading