From 45d018fb0c13547b42b59a46d9ddc27e44e8bbf7 Mon Sep 17 00:00:00 2001 From: salix5 Date: Fri, 22 Nov 2024 17:00:11 +0800 Subject: [PATCH 1/9] const reference in card::xyz_overlay --- card.cpp | 7 +++---- card.h | 2 +- libduel.cpp | 7 +++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/card.cpp b/card.cpp index 493e6a39e..18777c6fb 100644 --- a/card.cpp +++ b/card.cpp @@ -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; diff --git a/card.h b/card.h index 9114770a7..1b52ec92b 100644 --- a/card.h +++ b/card.h @@ -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(); diff --git a/libduel.cpp b/libduel.cpp index 211311800..efcd88fb7 100644 --- a/libduel.cpp +++ b/libduel.cpp @@ -3631,11 +3631,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); From 1e1f6b63a87eb791a3504a7fe2b06408dc8bfb08 Mon Sep 17 00:00:00 2001 From: salix5 Date: Fri, 22 Nov 2024 17:04:58 +0800 Subject: [PATCH 2/9] const reference in field::ritual_release --- field.cpp | 4 ++-- field.h | 2 +- libduel.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/field.cpp b/field.cpp index 4ce5e2320..258d1fcd9 100644 --- a/field.cpp +++ b/field.cpp @@ -1927,11 +1927,11 @@ 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) diff --git a/field.h b/field.h index cf7eb68b2..2ee7d4bcc 100644 --- a/field.h +++ b/field.h @@ -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); diff --git a/libduel.cpp b/libduel.cpp index efcd88fb7..72a67e990 100644 --- a/libduel.cpp +++ b/libduel.cpp @@ -3346,7 +3346,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) { From c14a54f49414283f5cca51e09aac704a15ce201f Mon Sep 17 00:00:00 2001 From: salix5 Date: Fri, 22 Nov 2024 17:12:33 +0800 Subject: [PATCH 3/9] const reference in field::get_control --- field.h | 2 +- libduel.cpp | 2 +- operations.cpp | 9 ++++----- processor.cpp | 8 ++++---- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/field.h b/field.h index 2ee7d4bcc..413c4120b 100644 --- a/field.h +++ b/field.h @@ -564,7 +564,7 @@ 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, card* pcard1, card* pcard2, uint32 reset_phase, uint32 reset_count); diff --git a/libduel.cpp b/libduel.cpp index 72a67e990..340968197 100644 --- a/libduel.cpp +++ b/libduel.cpp @@ -1410,7 +1410,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]); diff --git a/operations.cpp b/operations.cpp index ddc3564a0..70b69c651 100644 --- a/operations.cpp +++ b/operations.cpp @@ -112,15 +112,14 @@ void field::remove_counter(uint32 reason, card* pcard, uint32 rplayer, uint32 s, void field::remove_overlay_card(uint32 reason, card* pcard, uint32 rplayer, uint32 s, uint32 o, uint16 min, uint16 max) { add_process(PROCESSOR_REMOVE_OVERLAY, 0, nullptr, (group*)pcard, (rplayer << 16) + (s << 8) + o, (max << 16) + min, reason); } -void field::get_control(card_set* targets, effect* reason_effect, uint32 reason_player, uint32 playerid, uint32 reset_phase, uint32 reset_count, uint32 zone) { - group* ng = pduel->new_group(*targets); +void field::get_control(const card_set& targets, effect* reason_effect, uint32 reason_player, uint32 playerid, uint32 reset_phase, uint32 reset_count, uint32 zone) { + group* ng = pduel->new_group(targets); ng->is_readonly = GTYPE_READ_ONLY; add_process(PROCESSOR_GET_CONTROL, 0, reason_effect, ng, 0, (reason_player << 28) + (playerid << 24) + (reset_phase << 8) + reset_count, zone); } void field::get_control(card* target, effect* reason_effect, uint32 reason_player, uint32 playerid, uint32 reset_phase, uint32 reset_count, uint32 zone) { - card_set tset; - tset.insert(target); - get_control(&tset, reason_effect, reason_player, playerid, reset_phase, reset_count, zone); + card_set tset{ target }; + get_control(tset, reason_effect, reason_player, playerid, reset_phase, reset_count, zone); } void field::swap_control(effect* reason_effect, uint32 reason_player, card_set* targets1, card_set* targets2, uint32 reset_phase, uint32 reset_count) { group* ng1 = pduel->new_group(*targets1); diff --git a/processor.cpp b/processor.cpp index 115a94f77..13c8bd1e3 100644 --- a/processor.cpp +++ b/processor.cpp @@ -4896,8 +4896,8 @@ int32 field::adjust_step(uint16 step) { } if(core.control_adjust_set[0].size() || core.control_adjust_set[1].size()) { core.re_adjust = TRUE; - get_control(&core.control_adjust_set[1 - infos.turn_player], 0, PLAYER_NONE, infos.turn_player, 0, 0, 0xff); - get_control(&core.control_adjust_set[infos.turn_player], 0, PLAYER_NONE, 1 - infos.turn_player, 0, 0, 0xff); + get_control(core.control_adjust_set[1 - infos.turn_player], 0, PLAYER_NONE, infos.turn_player, 0, 0, 0xff); + get_control(core.control_adjust_set[infos.turn_player], 0, PLAYER_NONE, 1 - infos.turn_player, 0, 0, 0xff); for(auto& rcard : reason_cards) { ++core.readjust_map[rcard]; if(core.readjust_map[rcard] > 3) @@ -4936,8 +4936,8 @@ int32 field::adjust_step(uint16 step) { core.remove_brainwashing = res; if(core.control_adjust_set[0].size() || core.control_adjust_set[1].size()) { core.re_adjust = TRUE; - get_control(&core.control_adjust_set[1 - infos.turn_player], 0, PLAYER_NONE, infos.turn_player, 0, 0, 0xff); - get_control(&core.control_adjust_set[infos.turn_player], 0, PLAYER_NONE, 1 - infos.turn_player, 0, 0, 0xff); + get_control(core.control_adjust_set[1 - infos.turn_player], 0, PLAYER_NONE, infos.turn_player, 0, 0, 0xff); + get_control(core.control_adjust_set[infos.turn_player], 0, PLAYER_NONE, 1 - infos.turn_player, 0, 0, 0xff); } } core.units.begin()->step = 7; From 51fdd534f83f7729fd53129259c51d47ef374cab Mon Sep 17 00:00:00 2001 From: salix5 Date: Fri, 22 Nov 2024 17:18:38 +0800 Subject: [PATCH 4/9] const reference in field::swap_control --- field.h | 2 +- libduel.cpp | 2 +- operations.cpp | 14 ++++++-------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/field.h b/field.h index 413c4120b..236a2aed0 100644 --- a/field.h +++ b/field.h @@ -566,7 +566,7 @@ class field { void remove_overlay_card(uint32 reason, card* pcard, uint32 rplayer, uint32 s, uint32 o, uint16 min, uint16 max); 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); diff --git a/libduel.cpp b/libduel.cpp index 340968197..f0cdd3412 100644 --- a/libduel.cpp +++ b/libduel.cpp @@ -1444,7 +1444,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]); diff --git a/operations.cpp b/operations.cpp index 70b69c651..b9e68acb3 100644 --- a/operations.cpp +++ b/operations.cpp @@ -121,19 +121,17 @@ void field::get_control(card* target, effect* reason_effect, uint32 reason_playe card_set tset{ target }; get_control(tset, reason_effect, reason_player, playerid, reset_phase, reset_count, zone); } -void field::swap_control(effect* reason_effect, uint32 reason_player, card_set* targets1, card_set* targets2, uint32 reset_phase, uint32 reset_count) { - group* ng1 = pduel->new_group(*targets1); +void field::swap_control(effect* reason_effect, uint32 reason_player, const card_set& targets1, const card_set& targets2, uint32 reset_phase, uint32 reset_count) { + group* ng1 = pduel->new_group(targets1); ng1->is_readonly = GTYPE_READ_ONLY; - group* ng2 = pduel->new_group(*targets2); + group* ng2 = pduel->new_group(targets2); ng2->is_readonly = GTYPE_READ_ONLY; add_process(PROCESSOR_SWAP_CONTROL, 0, reason_effect, ng1, reason_player, reset_phase, reset_count, 0, ng2); } void field::swap_control(effect* reason_effect, uint32 reason_player, card* pcard1, card* pcard2, uint32 reset_phase, uint32 reset_count) { - card_set tset1; - tset1.insert(pcard1); - card_set tset2; - tset2.insert(pcard2); - swap_control(reason_effect, reason_player, &tset1, &tset2, reset_phase, reset_count); + card_set tset1{ pcard1 }; + card_set tset2{ pcard2 }; + swap_control(reason_effect, reason_player, tset1, tset2, reset_phase, reset_count); } void field::equip(uint32 equip_player, card* equip_card, card* target, uint32 up, uint32 is_step) { add_process(PROCESSOR_EQUIP, 0, nullptr, (group*)target, 0, equip_player + (up << 16) + (is_step << 24), 0, 0, equip_card); From 99cca02aef5394b42267598445846380ddd49ece Mon Sep 17 00:00:00 2001 From: salix5 Date: Fri, 22 Nov 2024 17:25:34 +0800 Subject: [PATCH 5/9] const reference in field::special_summon --- field.h | 2 +- libduel.cpp | 7 +++---- operations.cpp | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/field.h b/field.h index 236a2aed0..2e6c0939e 100644 --- a/field.h +++ b/field.h @@ -575,7 +575,7 @@ 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); diff --git a/libduel.cpp b/libduel.cpp index f0cdd3412..02b216acb 100644 --- a/libduel.cpp +++ b/libduel.cpp @@ -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]); diff --git a/operations.cpp b/operations.cpp index b9e68acb3..6e576c375 100644 --- a/operations.cpp +++ b/operations.cpp @@ -158,10 +158,10 @@ void field::mset(uint32 setplayer, card* target, effect* proc, uint32 ignore_cou void field::special_summon_rule(uint32 sumplayer, card* target, uint32 summon_type, uint32 action_type) { add_process(PROCESSOR_SPSUMMON_RULE, 0, 0, (group*)target, sumplayer, summon_type, action_type); } -void field::special_summon(card_set* target, uint32 sumtype, uint32 sumplayer, uint32 playerid, uint32 nocheck, uint32 nolimit, uint32 positions, uint32 zone) { +void field::special_summon(const card_set& target, uint32 sumtype, uint32 sumplayer, uint32 playerid, uint32 nocheck, uint32 nolimit, uint32 positions, uint32 zone) { if((positions & POS_FACEDOWN) && is_player_affected_by_effect(sumplayer, EFFECT_DIVINE_LIGHT)) positions = (positions & POS_FACEUP) | ((positions & POS_FACEDOWN) >> 1); - for(auto& pcard : *target) { + for(auto& pcard : target) { pcard->temp.reason = pcard->current.reason; pcard->temp.reason_effect = pcard->current.reason_effect; pcard->temp.reason_player = pcard->current.reason_player; @@ -172,7 +172,7 @@ void field::special_summon(card_set* target, uint32 sumtype, uint32 sumplayer, u pcard->current.reason_player = core.reason_player; pcard->spsummon_param = (playerid << 24) + (nocheck << 16) + (nolimit << 8) + positions; } - group* pgroup = pduel->new_group(*target); + group* pgroup = pduel->new_group(target); pgroup->is_readonly = GTYPE_READ_ONLY; add_process(PROCESSOR_SPSUMMON, 0, core.reason_effect, pgroup, core.reason_player, zone); } From 223c9d5570d7244632af3ff787ff398fea915e18 Mon Sep 17 00:00:00 2001 From: salix5 Date: Fri, 22 Nov 2024 17:31:08 +0800 Subject: [PATCH 6/9] const reference in field::release --- field.cpp | 2 +- field.h | 2 +- libduel.cpp | 2 +- operations.cpp | 15 +++++++-------- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/field.cpp b/field.cpp index 258d1fcd9..1591632cf 100644 --- a/field.cpp +++ b/field.cpp @@ -1940,7 +1940,7 @@ void field::ritual_release(const card_set& material) { 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); + 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) { diff --git a/field.h b/field.h index 2e6c0939e..fd8f8aa48 100644 --- a/field.h +++ b/field.h @@ -580,7 +580,7 @@ class field { 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* 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(card* target, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence, uint32 position, uint8 send_activating = FALSE); diff --git a/libduel.cpp b/libduel.cpp index 02b216acb..221eb976e 100644 --- a/libduel.cpp +++ b/libduel.cpp @@ -838,7 +838,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]); diff --git a/operations.cpp b/operations.cpp index 6e576c375..368813e47 100644 --- a/operations.cpp +++ b/operations.cpp @@ -233,8 +233,8 @@ void field::destroy(card* target, effect* reason_effect, uint32 reason, uint32 r tset.insert(target); destroy(&tset, reason_effect, reason, reason_player, playerid, destination, sequence); } -void field::release(card_set* targets, effect* reason_effect, uint32 reason, uint32 reason_player) { - for(auto& pcard : *targets) { +void field::release(const card_set& targets, effect* reason_effect, uint32 reason, uint32 reason_player) { + for(auto& pcard : targets) { pcard->temp.reason = pcard->current.reason; pcard->temp.reason_effect = pcard->current.reason_effect; pcard->temp.reason_player = pcard->current.reason_player; @@ -243,14 +243,13 @@ void field::release(card_set* targets, effect* reason_effect, uint32 reason, uin pcard->current.reason_player = reason_player; pcard->sendto_param.set(pcard->owner, POS_FACEUP, LOCATION_GRAVE); } - group* ng = pduel->new_group(*targets); + group* ng = pduel->new_group(targets); ng->is_readonly = GTYPE_READ_ONLY; add_process(PROCESSOR_RELEASE, 0, reason_effect, ng, reason, reason_player); } void field::release(card* target, effect* reason_effect, uint32 reason, uint32 reason_player) { - card_set tset; - tset.insert(target); - release(&tset, reason_effect, reason, reason_player); + card_set tset{ target }; + release(tset, reason_effect, reason, reason_player); } void field::send_to(card_set* targets, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence, uint32 position, uint8 send_activating) { if(destination & LOCATION_ONFIELD) @@ -1744,7 +1743,7 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui for(auto& pcard : *tributes) pcard->current.reason_card = target; target->set_material(tributes); - release(tributes, 0, REASON_SUMMON | REASON_MATERIAL, sumplayer); + release(*tributes, 0, REASON_SUMMON | REASON_MATERIAL, sumplayer); target->summon_info = SUMMON_TYPE_NORMAL | SUMMON_TYPE_ADVANCE | (LOCATION_HAND << 16); delete tributes; core.units.begin()->peffect = 0; @@ -2335,7 +2334,7 @@ int32 field::mset(uint16 step, uint8 setplayer, card* target, effect* proc, uint for(auto& pcard : *tributes) pcard->current.reason_card = target; target->set_material(tributes); - release(tributes, 0, REASON_SUMMON | REASON_MATERIAL, setplayer); + release(*tributes, 0, REASON_SUMMON | REASON_MATERIAL, setplayer); target->summon_info = SUMMON_TYPE_NORMAL | SUMMON_TYPE_ADVANCE | (LOCATION_HAND << 16); delete tributes; core.units.begin()->peffect = 0; From 30bda862ebe077e0725fde8fe7923c14b8b84d16 Mon Sep 17 00:00:00 2001 From: salix5 Date: Fri, 22 Nov 2024 17:46:46 +0800 Subject: [PATCH 7/9] const reference in field::send_to --- field.cpp | 4 ++-- field.h | 2 +- libduel.cpp | 10 +++++----- operations.cpp | 30 ++++++++++++++---------------- processor.cpp | 6 +++--- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/field.cpp b/field.cpp index 1591632cf..63a19520a 100644 --- a/field.cpp +++ b/field.cpp @@ -1939,9 +1939,9 @@ void field::ritual_release(const card_set& material) { 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); + 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(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(); diff --git a/field.h b/field.h index fd8f8aa48..3db4e1939 100644 --- a/field.h +++ b/field.h @@ -582,7 +582,7 @@ class field { void destroy(card* target, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid = 2, uint32 destination = 0, uint32 sequence = 0); 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); diff --git a/libduel.cpp b/libduel.cpp index 221eb976e..99478a636 100644 --- a/libduel.cpp +++ b/libduel.cpp @@ -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]); @@ -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]); @@ -643,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]); @@ -678,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]); @@ -706,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]); diff --git a/operations.cpp b/operations.cpp index 368813e47..b70629e70 100644 --- a/operations.cpp +++ b/operations.cpp @@ -251,10 +251,10 @@ void field::release(card* target, effect* reason_effect, uint32 reason, uint32 r card_set tset{ target }; release(tset, reason_effect, reason, reason_player); } -void field::send_to(card_set* targets, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence, uint32 position, uint8 send_activating) { +void field::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) { if(destination & LOCATION_ONFIELD) return; - for(auto& pcard : *targets) { + for(auto& pcard : targets) { pcard->temp.reason = pcard->current.reason; pcard->current.reason = reason; if(reason_player != PLAYER_SELFDES) { @@ -278,14 +278,13 @@ void field::send_to(card_set* targets, effect* reason_effect, uint32 reason, uin pos = pcard->current.position; pcard->sendto_param.set(p, pos, destination, sequence); } - group* ng = pduel->new_group(*targets); + group* ng = pduel->new_group(targets); ng->is_readonly = GTYPE_READ_ONLY; add_process(PROCESSOR_SENDTO, 0, reason_effect, ng, reason, reason_player, send_activating); } void field::send_to(card* target, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence, uint32 position, uint8 send_activating) { - card_set tset; - tset.insert(target); - send_to(&tset, reason_effect, reason, reason_player, playerid, destination, sequence, position, send_activating); + card_set tset{ target }; + send_to(tset, reason_effect, reason, reason_player, playerid, destination, sequence, position, send_activating); } void field::move_to_field(card* target, uint32 move_player, uint32 playerid, uint32 destination, uint32 positions, uint32 enable, uint32 ret, uint32 pzone, uint32 zone) { if(!(destination & LOCATION_ONFIELD) || !positions) @@ -855,7 +854,7 @@ int32 field::remove_overlay_card(uint16 step, uint32 reason, card* pcard, uint8 card_set cset; for(int32 i = 0; i < returns.bvalue[0]; ++i) cset.insert(core.select_cards[returns.bvalue[i + 1]]); - send_to(&cset, core.reason_effect, reason, rplayer, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); + send_to(cset, core.reason_effect, reason, rplayer, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); return FALSE; } case 4: { @@ -1349,7 +1348,7 @@ int32 field::trap_monster_adjust(uint16 step) { } if(card_set* to_grave_set = (card_set*)core.units.begin()->ptr1) { if(to_grave_set->size()) - send_to(to_grave_set, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); + send_to(*to_grave_set, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); delete to_grave_set; } return TRUE; @@ -2614,7 +2613,7 @@ int32 field::sset_g(uint16 step, uint8 setplayer, uint8 toplayer, group* ptarget } case 5: { if(core.unable_tofield_set.size()) - send_to(&core.unable_tofield_set, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); + send_to(core.unable_tofield_set, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); return FALSE; } case 6: { @@ -3106,7 +3105,7 @@ int32 field::special_summon_rule(uint16 step, uint8 sumplayer, card* target, uin ++cit; } if(cset.size()) { - send_to(&cset, 0, REASON_RULE, PLAYER_NONE, sumplayer, LOCATION_GRAVE, 0, 0); + send_to(cset, 0, REASON_RULE, PLAYER_NONE, sumplayer, LOCATION_GRAVE, 0, 0); adjust_instant(); } if(pgroup->container.size() == 0) { @@ -3322,7 +3321,7 @@ int32 field::special_summon(uint16 step, effect* reason_effect, uint8 reason_pla } case 1: { if(core.unable_tofield_set.size()) - send_to(&core.unable_tofield_set, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); + send_to(core.unable_tofield_set, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); return FALSE; } case 2: { @@ -4388,7 +4387,7 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3 if(equipings.size()) destroy(&equipings, 0, REASON_RULE + REASON_LOST_TARGET, PLAYER_NONE); if(overlays.size()) - send_to(&overlays, 0, REASON_RULE + REASON_LOST_OVERLAY, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); + send_to(overlays, 0, REASON_RULE + REASON_LOST_OVERLAY, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); adjust_instant(); return FALSE; } @@ -4708,9 +4707,8 @@ int32 field::move_to_field(uint16 step, card* target, uint32 enable, uint32 ret, } if(target->xyz_materials.size()) { target->xyz_materials_previous_count_onfield = (int32)target->xyz_materials.size(); - card_set overlays; - overlays.insert(target->xyz_materials.begin(), target->xyz_materials.end()); - send_to(&overlays, 0, REASON_LOST_OVERLAY + REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); + card_set overlays(target->xyz_materials.begin(), target->xyz_materials.end()); + send_to(overlays, 0, REASON_LOST_OVERLAY + REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); } else { target->xyz_materials_previous_count_onfield = 0; } @@ -4971,7 +4969,7 @@ int32 field::change_position(uint16 step, group * targets, effect * reason_effec destroy(&equipings, 0, REASON_LOST_TARGET + REASON_RULE, PLAYER_NONE); card_set* to_grave_set = (card_set*)core.units.begin()->ptr1; if(to_grave_set->size()) { - send_to(to_grave_set, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); + send_to(*to_grave_set, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); } delete to_grave_set; return FALSE; diff --git a/processor.cpp b/processor.cpp index 13c8bd1e3..84d36f810 100644 --- a/processor.cpp +++ b/processor.cpp @@ -644,7 +644,7 @@ uint32 field::process() { cset.insert(pcard); } if(cset.size()) - send_to(&cset, core.reason_effect, it->arg3, core.reason_player, it->arg1, LOCATION_GRAVE, 0, POS_FACEUP); + send_to(cset, core.reason_effect, it->arg3, core.reason_player, it->arg1, LOCATION_GRAVE, 0, POS_FACEUP); else returns.ivalue[0] = 0; ++it->step; @@ -1253,7 +1253,7 @@ int32 field::process_phase_event(int16 step, int32 phase) { card_set cset; for(int32 i = 0; i < returns.bvalue[0]; ++i) cset.insert(core.select_cards[returns.bvalue[i + 1]]); - send_to(&cset, 0, REASON_RULE + REASON_DISCARD + REASON_ADJUST, infos.turn_player, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); + send_to(cset, 0, REASON_RULE + REASON_DISCARD + REASON_ADJUST, infos.turn_player, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); return FALSE; } case 22: { @@ -4531,7 +4531,7 @@ int32 field::solve_chain(uint16 step, uint32 chainend_arg1, uint32 chainend_arg2 ++cit; } if(core.leave_confirmed.size()) - send_to(&core.leave_confirmed, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); + send_to(core.leave_confirmed, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); return FALSE; } case 12: { From bfe676fa45f3812df5688167a6ff0a5ef233b4e6 Mon Sep 17 00:00:00 2001 From: salix5 Date: Fri, 22 Nov 2024 17:59:43 +0800 Subject: [PATCH 8/9] const reference in field::change_position --- field.h | 2 +- libduel.cpp | 7 +++---- operations.cpp | 6 +++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/field.h b/field.h index 3db4e1939..5e44ddb35 100644 --- a/field.h +++ b/field.h @@ -585,7 +585,7 @@ class field { 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); diff --git a/libduel.cpp b/libduel.cpp index 99478a636..2be3c744c 100644 --- a/libduel.cpp +++ b/libduel.cpp @@ -806,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]); diff --git a/operations.cpp b/operations.cpp index b70629e70..1c418b731 100644 --- a/operations.cpp +++ b/operations.cpp @@ -294,10 +294,10 @@ void field::move_to_field(card* target, uint32 move_player, uint32 playerid, uin target->to_field_param = (move_player << 24) + (playerid << 16) + (destination << 8) + positions; add_process(PROCESSOR_MOVETOFIELD, 0, 0, (group*)target, enable, ret + (pzone << 8), zone); } -void field::change_position(card_set* targets, effect* reason_effect, uint32 reason_player, uint32 au, uint32 ad, uint32 du, uint32 dd, uint32 flag, uint32 enable) { - group* ng = pduel->new_group(*targets); +void field::change_position(const card_set& targets, effect* reason_effect, uint32 reason_player, uint32 au, uint32 ad, uint32 du, uint32 dd, uint32 flag, uint32 enable) { + group* ng = pduel->new_group(targets); ng->is_readonly = GTYPE_READ_ONLY; - for(auto& pcard : *targets) { + for(auto& pcard : targets) { if(pcard->current.position == POS_FACEUP_ATTACK) pcard->position_param = au; else if(pcard->current.position == POS_FACEDOWN_DEFENSE) From 6facb9499d7a9007e38d051a5692cef01b99efc5 Mon Sep 17 00:00:00 2001 From: salix5 Date: Fri, 22 Nov 2024 18:54:40 +0800 Subject: [PATCH 9/9] reference in field::destroy --- card.cpp | 2 +- field.h | 2 +- libduel.cpp | 2 +- operations.cpp | 23 +++++++++++------------ processor.cpp | 4 ++-- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/card.cpp b/card.cpp index 18777c6fb..c5ffb8b81 100644 --- a/card.cpp +++ b/card.cpp @@ -1658,7 +1658,7 @@ void card::xyz_overlay(const 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(); } diff --git a/field.h b/field.h index 5e44ddb35..4e3107138 100644 --- a/field.h +++ b/field.h @@ -578,7 +578,7 @@ class field { 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(const card_set& targets, effect* reason_effect, uint32 reason, uint32 reason_player); void release(card* target, effect* reason_effect, uint32 reason, uint32 reason_player); diff --git a/libduel.cpp b/libduel.cpp index 2be3c744c..7136c6af6 100644 --- a/libduel.cpp +++ b/libduel.cpp @@ -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]); diff --git a/operations.cpp b/operations.cpp index 1c418b731..d7ee229a8 100644 --- a/operations.cpp +++ b/operations.cpp @@ -197,11 +197,11 @@ void field::special_summon_complete(effect* reason_effect, uint8 reason_player) core.hint_timing[reason_player] |= TIMING_SPSUMMON; add_process(PROCESSOR_SPSUMMON, 1, reason_effect, ng, reason_player, 0); } -void field::destroy(card_set* targets, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence) { - for(auto cit = targets->begin(); cit != targets->end();) { +void field::destroy(card_set& targets, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence) { + for(auto cit = targets.begin(); cit != targets.end();) { card* pcard = *cit; if(pcard->is_status(STATUS_DESTROY_CONFIRMED) && core.destroy_canceled.find(pcard) == core.destroy_canceled.end()) { - cit = targets->erase(cit); + cit = targets.erase(cit); continue; } pcard->temp.reason = pcard->current.reason; @@ -224,14 +224,13 @@ void field::destroy(card_set* targets, effect* reason_effect, uint32 reason, uin pcard->sendto_param.set(p, POS_FACEUP, destination, sequence); ++cit; } - group* ng = pduel->new_group(*targets); + group* ng = pduel->new_group(targets); ng->is_readonly = GTYPE_READ_ONLY; add_process(PROCESSOR_DESTROY, 0, reason_effect, ng, reason, reason_player); } void field::destroy(card* target, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence) { - card_set tset; - tset.insert(target); - destroy(&tset, reason_effect, reason, reason_player, playerid, destination, sequence); + card_set tset{ target }; + destroy(tset, reason_effect, reason, reason_player, playerid, destination, sequence); } void field::release(const card_set& targets, effect* reason_effect, uint32 reason, uint32 reason_player) { for(auto& pcard : targets) { @@ -976,7 +975,7 @@ int32 field::get_control(uint16 step, effect* reason_effect, uint8 reason_player case 6: { card_set* destroy_set = (card_set*)core.units.begin()->ptr1; if(destroy_set->size()) - destroy(destroy_set, 0, REASON_RULE, PLAYER_NONE); + destroy(*destroy_set, 0, REASON_RULE, PLAYER_NONE); delete destroy_set; return FALSE; } @@ -1225,7 +1224,7 @@ int32 field::self_destroy(uint16 step, card* ucard, int32 p) { pcard->current.reason_effect = ucard->unique_effect; pcard->current.reason_player = ucard->current.controler; } - destroy(&cset, 0, REASON_RULE, PLAYER_SELFDES); + destroy(cset, 0, REASON_RULE, PLAYER_SELFDES); return FALSE; } case 2: { @@ -4385,7 +4384,7 @@ int32 field::send_to(uint16 step, group * targets, effect * reason_effect, uint3 process_single_event(); process_instant_event(); if(equipings.size()) - destroy(&equipings, 0, REASON_RULE + REASON_LOST_TARGET, PLAYER_NONE); + destroy(equipings, 0, REASON_RULE + REASON_LOST_TARGET, PLAYER_NONE); if(overlays.size()) send_to(overlays, 0, REASON_RULE + REASON_LOST_OVERLAY, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); adjust_instant(); @@ -4699,7 +4698,7 @@ int32 field::move_to_field(uint16 step, card* target, uint32 enable, uint32 ret, pduel->write_buffer32(target->current.reason); if(target->current.location != LOCATION_MZONE) { if(target->equiping_cards.size()) { - destroy(&target->equiping_cards, 0, REASON_LOST_TARGET + REASON_RULE, PLAYER_NONE); + destroy(target->equiping_cards, 0, REASON_LOST_TARGET + REASON_RULE, PLAYER_NONE); for(auto csit = target->equiping_cards.begin(); csit != target->equiping_cards.end();) { auto rm = csit++; (*rm)->unequip(); @@ -4966,7 +4965,7 @@ int32 field::change_position(uint16 step, group * targets, effect * reason_effec raise_event(pos_changed, EVENT_CHANGE_POS, reason_effect, 0, reason_player, 0, 0); process_instant_event(); if(equipings.size()) - destroy(&equipings, 0, REASON_LOST_TARGET + REASON_RULE, PLAYER_NONE); + destroy(equipings, 0, REASON_LOST_TARGET + REASON_RULE, PLAYER_NONE); card_set* to_grave_set = (card_set*)core.units.begin()->ptr1; if(to_grave_set->size()) { send_to(*to_grave_set, 0, REASON_RULE, PLAYER_NONE, PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP); diff --git a/processor.cpp b/processor.cpp index 84d36f810..baf1bc06d 100644 --- a/processor.cpp +++ b/processor.cpp @@ -3091,7 +3091,7 @@ int32 field::process_battle_command(uint16 step) { } case 29: { if(core.battle_destroy_rep.size()) - destroy(&core.battle_destroy_rep, 0, REASON_EFFECT | REASON_REPLACE, PLAYER_NONE); + destroy(core.battle_destroy_rep, 0, REASON_EFFECT | REASON_REPLACE, PLAYER_NONE); if(core.desrep_chain.size()) add_process(PROCESSOR_OPERATION_REPLACE, 15, nullptr, nullptr, 0, 0); adjust_all(); @@ -4971,7 +4971,7 @@ int32 field::adjust_step(uint16 step) { } if(destroy_set.size()) { core.re_adjust = TRUE; - destroy(&destroy_set, 0, REASON_RULE, PLAYER_NONE); + destroy(destroy_set, 0, REASON_RULE, PLAYER_NONE); } return FALSE; }