From bcd19c9cd0c0cb535e56b34e8afef1501b5192e4 Mon Sep 17 00:00:00 2001 From: donnyjang Date: Sat, 24 Oct 2026 18:35:20 -0700 Subject: [PATCH] core: a Tag team on Master Rule 4/5 has a Field slot per partner (TICKET-384, v1.5.0) Proposal 45. field::has_two_fields() (DUEL_TAG_MODE on Master Rule 4 or 5) gives each team Spell/Trap sequence 5 for the partner who plays the team's first turn and 6 for the other; player_info::tag_partner flips in tag_swap and get_szone_size is 7 there. A Field Spell lands in the playing partner's slot (get_fzone_landing) and replaces only that card; a control change takes the free slot when the playing partner's is taken; a Set offers only the landing slot's bit. LOCATION_FZONE covers both slots in card_state::is_location, filter_matching_card, filter_field_card, is_location_useable and Duel.IsEnvironment; get_field_card(p, LOCATION_FZONE, 0) is the playing partner's field, else the other, and 1 the remaining one. Singles, Match and Master Rule 3 (slot 6 = a Pendulum Zone) are unchanged. Co-Authored-By: Claude Fable 5.1 --- core/card.cpp | 3 +- core/field.cpp | 92 +++++++++++++++++++++++++++++++++------------ core/field.h | 7 ++++ core/libduel.cpp | 21 +++++------ core/operations.cpp | 19 ++++++---- 5 files changed, 98 insertions(+), 44 deletions(-) diff --git a/core/card.cpp b/core/card.cpp index 5cc6ae3..3322043 100644 --- a/core/card.cpp +++ b/core/card.cpp @@ -67,7 +67,8 @@ uint32_t card::get_summon_info() { } bool card_state::is_location(uint32_t loc) const { - if((loc & LOCATION_FZONE) && location == LOCATION_SZONE && sequence == 5) + // [YGOL] proposal 45: slot 6 is the second Field slot in Tag (Master Rule 4/5); a Master Rule 3 Pendulum Zone card there has pzone set + if((loc & LOCATION_FZONE) && location == LOCATION_SZONE && (sequence == 5 || (sequence == 6 && !pzone))) return true; if((loc & LOCATION_PZONE) && location == LOCATION_SZONE && pzone) return true; diff --git a/core/field.cpp b/core/field.cpp index 7a220ff..bf7de36 100644 --- a/core/field.cpp +++ b/core/field.cpp @@ -303,7 +303,7 @@ void field::move_card(uint8_t playerid, card* pcard, uint8_t location, uint8_t s if(sequence >= (int32_t)player[playerid].list_mzone.size() || player[playerid].list_mzone[sequence]) return; } else { - if(sequence >= player[playerid].szone_size || player[playerid].list_szone[sequence]) + if(sequence >= get_szone_size(playerid) || player[playerid].list_szone[sequence]) return; } if(preplayer == playerid) { @@ -569,18 +569,23 @@ card* field::get_field_card(uint8_t playerid, uint32_t general_location, uint8_t break; } case LOCATION_SZONE: { - if(sequence < player[playerid].szone_size) + if(sequence < get_szone_size(playerid)) return player[playerid].list_szone[sequence]; else return nullptr; break; } case LOCATION_FZONE: { - if(sequence == 0) - return player[playerid].list_szone[5]; - else + // [YGOL] proposal 45 Rule 3: 0 = the playing partner's field, else the other one; 1 = the remaining one + if(sequence > 1 || (sequence == 1 && !has_two_fields())) return nullptr; - break; + card* first = player[playerid].list_szone[get_fzone_sequence(playerid, 0)]; + card* second = has_two_fields() ? player[playerid].list_szone[get_fzone_sequence(playerid, 1)] : nullptr; + if(!first) { + first = second; + second = nullptr; + } + return sequence == 0 ? first : second; } case LOCATION_PZONE: { if(sequence == 0 || sequence == 1) { @@ -608,14 +613,14 @@ int32_t field::is_location_useable(uint8_t playerid, uint32_t general_location, return FALSE; } } else if (general_location == LOCATION_SZONE) { - if (sequence >= player[playerid].szone_size) + if (sequence >= get_szone_size(playerid)) return FALSE; if(flag & (0x100U << sequence)) return FALSE; } else if (general_location == LOCATION_FZONE) { - if (sequence >= 1) + if (sequence >= (has_two_fields() ? 2 : 1)) return FALSE; - if(flag & (0x100U << (5 + sequence))) + if(flag & (0x100U << get_fzone_sequence(playerid, sequence))) return FALSE; } else if (general_location == LOCATION_PZONE) { if (sequence >= 2) @@ -625,6 +630,40 @@ int32_t field::is_location_useable(uint8_t playerid, uint32_t general_location, } return TRUE; } +// [YGOL] proposal 45: in Tag on Master Rule 4/5 a team has a Field slot per partner: Spell/Trap sequence 5 for the +// partner who plays the team's first turn, 6 for the other (slot 6 is free there: Master Rule 3 alone uses it as a +// Pendulum Zone). LOCATION_FZONE covers both; Singles, Match and Master Rule 3 keep the one slot. +bool field::has_two_fields() const { + return (core.duel_options & DUEL_TAG_MODE) && core.duel_rule >= NEW_MASTER_RULE; +} +int32_t field::get_szone_size(uint8_t playerid) const { + return has_two_fields() ? 7 : player[playerid].szone_size; +} +// fseq 0 = the playing partner's slot, 1 = the other partner's +uint8_t field::get_fzone_sequence(uint8_t playerid, uint8_t fseq) const { + if(!has_two_fields()) + return 5; + return (player[playerid].tag_partner ^ fseq) ? 6 : 5; +} +// a zone flag that names the Field Zone (callers pass 1 << 5 for "the Field Zone" and the engine picks the slot) +bool field::is_fzone_zone(uint32_t zone) const { + return zone == (0x1U << 5) || (has_two_fields() && zone == (0x1U << 6)); +} +// the slot a Field Spell lands in for playerid: the playing partner's, which it replaces; a card that changes control +// while the playing partner's slot is taken and the other is free takes the free one +uint8_t field::get_fzone_landing(card* pcard, uint8_t playerid) const { + if(!has_two_fields()) + return 5; + if(pcard->current.location == LOCATION_SZONE && pcard->current.controler == playerid + && (pcard->current.sequence == 5 || pcard->current.sequence == 6)) + return pcard->current.sequence; + uint8_t mine = get_fzone_sequence(playerid, 0); + uint8_t other = get_fzone_sequence(playerid, 1); + if(player[playerid].list_szone[mine] && !player[playerid].list_szone[other] + && pcard->current.location == LOCATION_SZONE && pcard->current.controler != playerid) + return other; + return mine; +} /** * Return usable count in `zone` when `uplayer` moves `pcard` to the MZONE or SZONE(0~4) of `playerid` (can be negative). * For LOCATION_MZONE, "usable" means not used, not disabled, satisfying EFFECT_MUST_USE_MZONE, satisfying EFFECT_MAX_MZONE. @@ -1150,7 +1189,7 @@ void field::refresh_player_info(uint8_t playerid) { if (player[playerid].list_mzone[i]) used_flag |= 0x1U << i; } - for (int32_t i = 0; i < player[playerid].szone_size; ++i) { + for (int32_t i = 0; i < get_szone_size(playerid); ++i) { if (player[playerid].list_szone[i]) used_flag |= 0x100U << i; } @@ -1214,6 +1253,7 @@ void field::tag_swap(uint8_t playerid) { pcard->apply_field_effect(); pcard->enable_field_effect(true); } + player[playerid].tag_partner ^= 1; // [YGOL] proposal 45: the other partner's Field slot is the live one now pduel->write_buffer8(MSG_TAG_SWAP); pduel->write_buffer8(playerid); pduel->write_buffer8((uint8_t)player[playerid].list_main.size()); @@ -1565,18 +1605,20 @@ int32_t field::filter_matching_card(lua_State* L, int32_t findex, uint8_t self, } } if(location & LOCATION_FZONE) { - card* pcard = player[self].list_szone[5]; - if(pcard && !pcard->is_treated_as_not_on_field() - && pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) - && pduel->lua->check_filter(L, pcard, findex, extraargs) - && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { - if(pret) { - *pret = pcard; - return TRUE; + for(uint8_t fseq = 0, fzones = has_two_fields() ? 2 : 1; fseq < fzones; ++fseq) { // [YGOL] proposal 45: both Field slots + card* pcard = player[self].list_szone[get_fzone_sequence(self, fseq)]; + if(pcard && !pcard->is_treated_as_not_on_field() + && pcard != pexception && !(pexgroup && pexgroup->has_card(pcard)) + && pduel->lua->check_filter(L, pcard, findex, extraargs) + && (!is_target || pcard->is_capable_be_effect_target(core.reason_effect, core.reason_player))) { + if(pret) { + *pret = pcard; + return TRUE; + } + result.insert(pcard); + if (fcount && (int32_t)result.size() >= fcount) + return TRUE; } - result.insert(pcard); - if (fcount && (int32_t)result.size() >= fcount) - return TRUE; } } if(location & LOCATION_PZONE) { @@ -1700,9 +1742,11 @@ int32_t field::filter_field_card(uint8_t self, uint32_t location1, uint32_t loca } } if(location & LOCATION_FZONE) { - card* pcard = player[self].list_szone[5]; - if(pcard) { - result.insert(pcard); + for(uint8_t fseq = 0, fzones = has_two_fields() ? 2 : 1; fseq < fzones; ++fseq) { // [YGOL] proposal 45: both Field slots + card* pcard = player[self].list_szone[get_fzone_sequence(self, fseq)]; + if(pcard) { + result.insert(pcard); + } } } if(location & LOCATION_PZONE) { diff --git a/core/field.h b/core/field.h index eba935d..eda1490 100644 --- a/core/field.h +++ b/core/field.h @@ -87,6 +87,7 @@ struct player_info { uint32_t extra_p_count{ 0 }; uint32_t tag_extra_p_count{ 0 }; int32_t szone_size{ 6 }; + uint8_t tag_partner{ 0 }; // [YGOL] proposal 45: 0 = the partner who plays the team's first turn (Field slot 5), 1 = the other (slot 6); flips in tag_swap card_vector list_mzone; card_vector list_szone; card_vector list_main; @@ -402,6 +403,12 @@ public: const card_vector* get_field_vector(uint8_t playerid, uint8_t location) const; card* get_field_card(uint8_t playerid, uint32_t general_location, uint8_t sequence) const; int32_t is_location_useable(uint8_t playerid, uint32_t general_location, uint8_t sequence) const; + // [YGOL] proposal 45: Tag on Master Rule 4/5 gives each partner a Field slot (Spell/Trap sequence 5 and 6) + bool has_two_fields() const; + int32_t get_szone_size(uint8_t playerid) const; + uint8_t get_fzone_sequence(uint8_t playerid, uint8_t fseq) const; + uint8_t get_fzone_landing(card* pcard, uint8_t playerid) const; + bool is_fzone_zone(uint32_t zone) const; int32_t get_useable_count(card* pcard, uint8_t playerid, uint8_t location, uint8_t uplayer, uint32_t reason, uint32_t zone = 0xff, uint32_t* list = nullptr); int32_t get_useable_count_fromex(card* pcard, uint8_t playerid, uint8_t uplayer, uint32_t zone = 0xff, uint32_t* list = nullptr); int32_t get_spsummonable_count(card* pcard, uint8_t playerid, uint32_t zone = 0xff, uint32_t* list = nullptr); diff --git a/core/libduel.cpp b/core/libduel.cpp index b6a97a6..3366aa6 100644 --- a/core/libduel.cpp +++ b/core/libduel.cpp @@ -1575,17 +1575,16 @@ int32_t scriptlib::duel_is_environment(lua_State *L) { duel* pduel = interpreter::get_duel_info(L); int32_t ret = 0, fc = 0; if(loc & (LOCATION_FZONE + LOCATION_SZONE)) { - card* pcard = pduel->game_field->player[0].list_szone[5]; - if(pcard && pcard->is_position(POS_FACEUP)) { - fc = 1; - if(code == pcard->get_code() && (playerid == 0 || playerid == PLAYER_ALL)) - ret = 1; - } - pcard = pduel->game_field->player[1].list_szone[5]; - if(pcard && pcard->is_position(POS_FACEUP)) { - fc = 1; - if(code == pcard->get_code() && (playerid == 1 || playerid == PLAYER_ALL)) - ret = 1; + field* pfield = pduel->game_field; + for(uint8_t p = 0; p < 2; ++p) { + for(uint8_t fseq = 0, fzones = pfield->has_two_fields() ? 2 : 1; fseq < fzones; ++fseq) { // [YGOL] proposal 45: both Field slots + card* pcard = pfield->player[p].list_szone[pfield->get_fzone_sequence(p, fseq)]; + if(pcard && pcard->is_position(POS_FACEUP)) { + fc = 1; + if(code == pcard->get_code() && (playerid == p || playerid == PLAYER_ALL)) + ret = 1; + } + } } } if(!ret && (loc & LOCATION_SZONE)) { diff --git a/core/operations.cpp b/core/operations.cpp index 35a9764..cb1916f 100644 --- a/core/operations.cpp +++ b/core/operations.cpp @@ -2459,7 +2459,7 @@ int32_t field::sset(uint16_t step, uint8_t setplayer, uint8_t toplayer, card * t return TRUE; uint32_t flag = 0; if(target->data.type & TYPE_FIELD) { - flag = ~(0x1U << 13); + flag = ~(0x1U << (8 + get_fzone_landing(target, toplayer))); // [YGOL] proposal 45: the partner's Field slot } else { get_useable_count(target, setplayer, LOCATION_SZONE, toplayer, LOCATION_REASON_TOFIELD, zone ? zone : 0xff, &flag); flag = ((flag & 0xff) << 8) | 0xffff00ff; @@ -2567,7 +2567,7 @@ int32_t field::sset_g(uint16_t step, uint8_t setplayer, uint8_t toplayer, group* card_set* set_cards = (card_set*)ptarget; card* target = *set_cards->begin(); if(target->data.type & TYPE_FIELD) { - returns.bvalue[2] = 5; + returns.bvalue[2] = get_fzone_landing(target, toplayer); // [YGOL] proposal 45 return FALSE; } uint32_t flag; @@ -2606,7 +2606,7 @@ int32_t field::sset_g(uint16_t step, uint8_t setplayer, uint8_t toplayer, group* target->enable_field_effect(false); uint32_t zone; if(target->data.type & TYPE_FIELD) { - zone = 0x1U << 5; + zone = 0x1U << get_fzone_landing(target, toplayer); // [YGOL] proposal 45 } else { for(int32_t i = 0; i < 7; i++) { zone = 0x1U << i; @@ -2676,6 +2676,8 @@ int32_t field::sset_g(uint16_t step, uint8_t setplayer, uint8_t toplayer, group* uint8_t ct = (uint8_t)core.operated_set.size(); if(core.set_group_used_zones & (0x1U << 5)) --ct; + if(core.set_group_used_zones & (0x1U << 6)) // [YGOL] proposal 45: the second Field slot + --ct; if(ct <= 1) return FALSE; pduel->write_buffer8(MSG_SHUFFLE_SET_CARD); @@ -4602,9 +4604,10 @@ int32_t field::move_to_field(uint16_t step, card* target, uint32_t enable, uint3 returns.ivalue[0] = FALSE; if((ret == RETURN_TEMP_REMOVE_TO_FIELD) && (!(target->current.reason & REASON_TEMPORARY) || (target->current.reason_effect->owner != core.reason_effect->owner))) return TRUE; - if(location == LOCATION_SZONE && zone == 0x1U << 5 && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL)) { - card* pcard = get_field_card(playerid, LOCATION_SZONE, 5); - if(pcard) { + if(location == LOCATION_SZONE && is_fzone_zone(zone) && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL)) { + // [YGOL] proposal 45: the card replaces only the Field slot it lands in + card* pcard = get_field_card(playerid, LOCATION_SZONE, get_fzone_landing(target, playerid)); + if(pcard && pcard != target) { if(core.duel_rule >= 3) send_to(pcard, 0, REASON_RULE, pcard->current.controler, PLAYER_NONE, LOCATION_GRAVE, 0, 0); else @@ -4683,8 +4686,8 @@ int32_t field::move_to_field(uint16_t step, card* target, uint32_t enable, uint3 } case 1: { uint32_t seq = returns.bvalue[2]; - if(location == LOCATION_SZONE && zone == 0x1U << 5 && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL)) - seq = 5; + if(location == LOCATION_SZONE && is_fzone_zone(zone) && (target->data.type & TYPE_FIELD) && (target->data.type & TYPE_SPELL)) + seq = get_fzone_landing(target, playerid); // [YGOL] proposal 45 if(ret != RETURN_TEMP_REMOVE_TO_FIELD) { if(location != target->current.location) { uint32_t resetflag = 0;