Commit cbf4f0b3 authored by wind2009's avatar wind2009

Merge remote-tracking branch 'upstream/master' into develop

parents ad168b75 ca69f726
......@@ -133,6 +133,11 @@ bool card::card_operation_sort(card* c1, card* c2) {
return c1->current.sequence < c2->current.sequence;
}
}
bool card::check_card_setcode(uint32 code, uint32 value) {
card_data dat;
::read_card(code, &dat);
return dat.is_setcode(value);
}
void card::attacker_map::addcard(card* pcard) {
auto fid = pcard ? pcard->fieldid_r : 0;
auto pr = emplace(fid, std::make_pair(pcard, 0));
......@@ -420,13 +425,13 @@ uint32 card::get_info_location() const {
uint32 l = overlay_target->current.location | LOCATION_OVERLAY;
uint32 s = overlay_target->current.sequence;
uint32 ss = current.sequence;
return c + (l << 8) + (s << 16) + (ss << 24);
return c | (l << 8) | (s << 16) | (ss << 24);
} else {
uint32 c = current.controler;
uint32 l = current.location;
uint32 s = current.sequence;
uint32 ss = current.position;
return c + (l << 8) + (s << 16) + (ss << 24);
return c | (l << 8) | (s << 16) | (ss << 24);
}
}
// get the printed code on card
......@@ -488,11 +493,6 @@ inline bool check_setcode(uint16_t setcode, uint32 value) {
uint32 setsubtype = value & 0xf000U;
return (setcode & 0x0fffU) == settype && (setcode & 0xf000U & setsubtype) == setsubtype;
}
bool card::check_card_setcode(uint32 code, uint32 value) {
card_data dat;
::read_card(code, &dat);
return dat.is_setcode(value);
}
int32 card::is_set_card(uint32 set_code) {
uint32 code1 = get_code();
card_data dat1;
......@@ -1276,18 +1276,18 @@ uint32 card::get_rscale() {
temp.rscale = UINT32_MAX;
return rscale;
}
uint32 card::get_link_marker() {
uint32 card::get_link_marker() const {
if(!(data.type & TYPE_LINK))
return 0;
return data.link_marker;
}
int32 card::is_link_marker(uint32 dir) {
return (int32)(get_link_marker() & dir);
uint32 card::is_link_marker(uint32 dir) const {
return get_link_marker() & dir;
}
uint32 card::get_linked_zone() {
uint32 card::get_linked_zone() const {
if(!(data.type & TYPE_LINK) || current.location != LOCATION_MZONE || is_treated_as_not_on_field())
return 0;
int32 zones = 0;
uint32 zones = 0;
int32 s = current.sequence;
if(s > 0 && s <= 4 && is_link_marker(LINK_MARKER_LEFT))
zones |= 1u << (s - 1);
......@@ -1340,26 +1340,26 @@ void card::get_linked_cards(card_set* cset) {
pduel->game_field->get_cards_in_zone(cset, linked_zone, p, LOCATION_MZONE);
pduel->game_field->get_cards_in_zone(cset, linked_zone >> 16, 1 - p, LOCATION_MZONE);
}
uint32 card::get_mutual_linked_zone() {
uint32 card::get_mutual_linked_zone() const {
if(!(data.type & TYPE_LINK) || current.location != LOCATION_MZONE || is_treated_as_not_on_field())
return 0;
int32 zones = 0;
uint32 zones = 0;
int32 p = current.controler;
int32 s = current.sequence;
uint32 linked_zone = get_linked_zone();
uint32 icheck = 0x1;
for(uint32 i = 0; i < 7; ++i, icheck <<= 1) {
uint32 icheck = 0x1U;
for(int32 i = 0; i < 7; ++i, icheck <<= 1) {
if(icheck & linked_zone) {
card* pcard = pduel->game_field->player[p].list_mzone[i];
if(pcard && (pcard->get_linked_zone() & (1u << s)))
if(pcard && (pcard->get_linked_zone() & (0x1u << s)))
zones |= icheck;
}
}
icheck = 0x10000;
icheck = 0x10000U;
for(uint32 i = 0; i < 7; ++i, icheck <<= 1) {
if(icheck & linked_zone) {
card* pcard = pduel->game_field->player[1 - p].list_mzone[i];
if(pcard && (pcard->get_linked_zone() & (1u << (s + 16))))
if(pcard && (pcard->get_linked_zone() & (0x1u << (s + 16))))
zones |= icheck;
}
}
......@@ -1383,28 +1383,28 @@ int32 card::is_link_state() {
return TRUE;
int32 p = current.controler;
uint32 linked_zone = pduel->game_field->get_linked_zone(p);
if((linked_zone >> current.sequence) & 1)
if((linked_zone >> current.sequence) & 0x1U)
return TRUE;
return FALSE;
}
int32 card::is_extra_link_state() {
if(current.location != LOCATION_MZONE)
return FALSE;
uint32 checked = 1u << current.sequence;
uint32 checked = 0x1U << current.sequence;
uint32 linked_zone = get_mutual_linked_zone();
const auto& list_mzone0 = pduel->game_field->player[current.controler].list_mzone;
const auto& list_mzone1 = pduel->game_field->player[1 - current.controler].list_mzone;
while(true) {
if(((linked_zone >> 5) | (linked_zone >> (16 + 6))) & ((linked_zone >> 6) | (linked_zone >> (16 + 5))) & 1)
if(((linked_zone >> 5) | (linked_zone >> (16 + 6))) & ((linked_zone >> 6) | (linked_zone >> (16 + 5))) & 0x1U)
return TRUE;
int32 checking = (int32)(linked_zone & ~checked);
uint32 checking = linked_zone & ~checked;
if(!checking)
return FALSE;
int32 rightmost = checking & (-checking);
checked |= (uint32)rightmost;
if(rightmost < 0x10000) {
uint32 rightmost = checking & (-checking);
checked |= rightmost;
if(rightmost < 0x10000U) {
for(int32 i = 0; i < 7; ++i) {
if(rightmost & 1) {
if(rightmost & 0x1U) {
card* pcard = list_mzone0[i];
linked_zone |= pcard->get_mutual_linked_zone();
break;
......@@ -1414,7 +1414,7 @@ int32 card::is_extra_link_state() {
} else {
rightmost >>= 16;
for(int32 i = 0; i < 7; ++i) {
if(rightmost & 1) {
if(rightmost & 0x1U) {
card* pcard = list_mzone1[i];
uint32 zone = pcard->get_mutual_linked_zone();
linked_zone |= (zone << 16) | (zone >> 16);
......@@ -1426,7 +1426,7 @@ int32 card::is_extra_link_state() {
}
return FALSE;
}
int32 card::is_position(int32 pos) {
int32 card::is_position(uint32 pos) const {
return current.position & pos;
}
void card::set_status(uint32 x, int32 enabled) {
......@@ -1522,7 +1522,7 @@ uint32 card::get_select_info_location(uint8 *deck_seq_pointer) {
return get_info_location();
}
}
int32 card::is_treated_as_not_on_field() {
int32 card::is_treated_as_not_on_field() const {
return get_status(STATUS_SUMMONING | STATUS_SUMMON_DISABLED | STATUS_ACTIVATE_DISABLED | STATUS_SPSUMMON_STEP);
}
void card::equip(card* target, uint32 send_msg) {
......@@ -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;
......@@ -1650,16 +1649,16 @@ void card::xyz_overlay(card_set* materials) {
}
if(leave_grave.size() || leave_deck.size()) {
if(leave_grave.size()) {
pduel->game_field->raise_event(&leave_grave, EVENT_LEAVE_GRAVE, pduel->game_field->core.reason_effect, REASON_XYZ + REASON_MATERIAL, pduel->game_field->core.reason_player, 0, 0);
pduel->game_field->raise_event(leave_grave, EVENT_LEAVE_GRAVE, pduel->game_field->core.reason_effect, REASON_XYZ + REASON_MATERIAL, pduel->game_field->core.reason_player, 0, 0);
}
if(leave_deck.size()) {
pduel->game_field->raise_event(&leave_deck, EVENT_LEAVE_DECK, pduel->game_field->core.reason_effect, REASON_XYZ + REASON_MATERIAL, pduel->game_field->core.reason_player, 0, 0);
pduel->game_field->raise_event(leave_deck, EVENT_LEAVE_DECK, pduel->game_field->core.reason_effect, REASON_XYZ + REASON_MATERIAL, pduel->game_field->core.reason_player, 0, 0);
}
pduel->game_field->process_single_event();
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();
}
......@@ -1959,6 +1958,7 @@ effect_indexer::iterator card::remove_effect(effect* peffect) {
pduel->game_field->update_disable_check_list(peffect);
}
field_effect.erase(it);
pduel->game_field->remove_effect(peffect);
}
if ((current.controler != PLAYER_NONE) && !get_status(STATUS_DISABLED | STATUS_FORBIDDEN) && !check_target.empty()) {
if (peffect->is_disable_related()) {
......@@ -2002,7 +2002,6 @@ effect_indexer::iterator card::remove_effect(effect* peffect) {
unique_pos[0] = unique_pos[1] = 0;
unique_code = 0;
}
pduel->game_field->remove_effect(peffect);
pduel->game_field->core.reseted_effects.insert(peffect);
return ret;
}
......@@ -3636,7 +3635,7 @@ int32 card::is_setable_szone(uint8 playerid, uint8 ignore_fd) {
}
int32 card::is_affect_by_effect(effect* reason_effect) {
if (is_status(STATUS_SUMMONING))
return reason_effect && (reason_effect->code == EFFECT_CANNOT_DISABLE_SUMMON || reason_effect->code == EFFECT_CANNOT_DISABLE_SPSUMMON);
return reason_effect && affect_summoning_effect.find(reason_effect->code) != affect_summoning_effect.end();
if(!reason_effect || reason_effect->is_flag(EFFECT_FLAG_IGNORE_IMMUNE))
return TRUE;
if(reason_effect->is_immuned(this))
......
......@@ -219,6 +219,7 @@ public:
explicit card(duel* pd);
~card() = default;
static bool card_operation_sort(card* c1, card* c2);
static bool check_card_setcode(uint32 code, uint32 value);
bool is_extra_deck_monster() const { return !!(data.type & TYPES_EXTRA_DECK); }
int32 get_infos(byte* buf, uint32 query_flag, int32 use_cache = TRUE);
......@@ -227,7 +228,6 @@ public:
std::tuple<uint32, uint32> get_original_code_rule() const;
uint32 get_code();
uint32 get_another_code();
static bool check_card_setcode(uint32 code, uint32 value);
int32 is_set_card(uint32 set_code);
int32 is_origin_set_card(uint32 set_code);
int32 is_pre_set_card(uint32 set_code);
......@@ -262,15 +262,15 @@ public:
uint32 get_grave_race(uint8 playerid);
uint32 get_lscale();
uint32 get_rscale();
uint32 get_link_marker();
int32 is_link_marker(uint32 dir);
uint32 get_linked_zone();
uint32 get_link_marker() const;
uint32 is_link_marker(uint32 dir) const;
uint32 get_linked_zone() const;
void get_linked_cards(card_set* cset);
uint32 get_mutual_linked_zone();
uint32 get_mutual_linked_zone() const;
void get_mutual_linked_cards(card_set * cset);
int32 is_link_state();
int32 is_extra_link_state();
int32 is_position(int32 pos);
int32 is_position(uint32 pos) const;
void set_status(uint32 status, int32 enabled);
int32 get_status(uint32 status) const;
int32 is_status(uint32 status) const;
......@@ -279,13 +279,13 @@ public:
int32 is_all_column();
uint8 get_select_sequence(uint8 *deck_seq_pointer);
uint32 get_select_info_location(uint8 *deck_seq_pointer);
int32 is_treated_as_not_on_field();
int32 is_treated_as_not_on_field() const;
void equip(card* target, uint32 send_msg = TRUE);
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();
......
......@@ -49,17 +49,17 @@ typedef signed char int8;
#define CURRENT_RULE 5
//Locations
#define LOCATION_DECK 0x01 //
#define LOCATION_HAND 0x02 //
#define LOCATION_MZONE 0x04 //
#define LOCATION_SZONE 0x08 //
#define LOCATION_GRAVE 0x10 //
#define LOCATION_REMOVED 0x20 //
#define LOCATION_EXTRA 0x40 //
#define LOCATION_OVERLAY 0x80 //
#define LOCATION_ONFIELD 0x0c //
#define LOCATION_FZONE 0x100 //
#define LOCATION_PZONE 0x200 //
#define LOCATION_DECK 0x01U
#define LOCATION_HAND 0x02U
#define LOCATION_MZONE 0x04U
#define LOCATION_SZONE 0x08U
#define LOCATION_GRAVE 0x10U
#define LOCATION_REMOVED 0x20U
#define LOCATION_EXTRA 0x40U
#define LOCATION_OVERLAY 0x80U
#define LOCATION_ONFIELD (LOCATION_MZONE | LOCATION_SZONE)
#define LOCATION_FZONE 0x100U
#define LOCATION_PZONE 0x200U
//For redirect
#define LOCATION_DECKBOT 0x10001 //Return to deck bottom
#define LOCATION_DECKSHF 0x20001 //Return to deck and shuffle
......
......@@ -98,9 +98,10 @@ void duel::delete_effect(effect* peffect) {
delete peffect;
}
int32 duel::read_buffer(byte* buf) {
if(message_buffer.size())
std::memcpy(buf, message_buffer.data(), message_buffer.size());
return (int32)message_buffer.size();
auto size = buffer_size();
if (size)
std::memcpy(buf, message_buffer.data(), size);
return (int32)size;
}
void duel::release_script_group() {
for(auto& pgroup : sgroups) {
......
......@@ -13,6 +13,7 @@
#include "mtrandom.h"
#include <set>
#include <unordered_set>
#include <vector>
class card;
class group;
......@@ -40,6 +41,9 @@ public:
~duel();
void clear();
uint32 buffer_size() const {
return (uint32)message_buffer.size() & PROCESSOR_BUFFER_LEN;
}
card* new_card(uint32 code);
group* new_group();
group* new_group(card* pcard);
......
......@@ -863,7 +863,7 @@ uint32 effect::get_active_type(uint8 uselast) {
} else
return owner->get_type();
}
int32 effect::get_code_type() const {
code_type effect::get_code_type() const {
// start from the highest bit
if (code & 0xf0000000)
return CODE_CUSTOM;
......
......@@ -20,8 +20,11 @@ class effect;
struct tevent;
struct effect_set;
struct effect_set_v;
enum effect_flag : uint32;
enum effect_flag2 : uint32;
enum effect_flag : uint64;
enum effect_flag2 : uint64;
enum code_type : int32;
bool is_continuous_event(uint32 code);
class effect {
public:
......@@ -32,7 +35,6 @@ public:
uint8 effect_owner{ PLAYER_NONE };
uint32 description{ 0 };
uint32 code{ 0 };
uint32 flag[2]{};
uint32 id{ 0 };
uint32 type{ 0 };
uint16 copy_id{ 0 };
......@@ -41,18 +43,19 @@ public:
uint16 o_range{ 0 };
uint8 count_limit{ 0 };
uint8 count_limit_max{ 0 };
uint16 status{ 0 };
int32 reset_count{ 0 };
uint32 reset_flag{ 0 };
uint32 count_code{ 0 };
uint32 category{ 0 };
uint64 category{ 0 };
uint64 flag[2]{};
uint32 hint_timing[2]{};
uint32 card_type{ 0 };
uint32 active_type{ 0 };
uint16 active_location{ 0 };
uint16 active_sequence{ 0 };
card* active_handler{ nullptr };
uint16 status{ 0 };
std::vector<uint32> label;
std::vector<lua_Integer> label;
int32 label_object{ 0 };
int32 condition{ 0 };
int32 cost{ 0 };
......@@ -112,7 +115,7 @@ public:
void set_activate_location();
void set_active_type();
uint32 get_active_type(uint8 uselast = TRUE);
int32 get_code_type() const;
code_type get_code_type() const;
bool is_flag(effect_flag x) const {
return !!(flag[0] & x);
......@@ -178,7 +181,7 @@ constexpr uint32 EFFECT_TYPES_TRIGGER_LIKE = EFFECT_TYPE_ACTIVATE | EFFECT_TYPE_
constexpr uint32 EFFECT_TYPES_CHAIN_LINK = EFFECT_TYPES_TRIGGER_LIKE | EFFECT_TYPE_FLIP | EFFECT_TYPE_IGNITION;
//========== Flags ==========
enum effect_flag : uint32 {
enum effect_flag : uint64 {
EFFECT_FLAG_INITIAL = 0x0001,
EFFECT_FLAG_FUNC_VALUE = 0x0002,
EFFECT_FLAG_COUNT_LIMIT = 0x0004,
......@@ -212,7 +215,7 @@ enum effect_flag : uint32 {
// EFFECT_FLAG_CVAL_CHECK = 0x40000000,
EFFECT_FLAG_IMMEDIATELY_APPLY = 0x80000000,
};
enum effect_flag2 : uint32 {
enum effect_flag2 : uint64 {
EFFECT_FLAG2_REPEAT_UPDATE = 0x0001,
EFFECT_FLAG2_COF = 0x0002,
EFFECT_FLAG2_WICKED = 0x0004,
......@@ -564,10 +567,12 @@ constexpr int32 HALF_DAMAGE = 0x80000001;
#define MAX_CARD_ID 0xfffffff
// The type of effect code
#define CODE_CUSTOM 1 // header + id (28 bits)
#define CODE_COUNTER 2 // header + counter_id (16 bits)
#define CODE_PHASE 3 // header + phase_id (12 bits)
#define CODE_VALUE 4 // numeric value, max = 4095
enum code_type : int32 {
CODE_CUSTOM = 1, // header + id (28 bits)
CODE_COUNTER, // header + counter_id (16 bits)
CODE_PHASE, // header + phase_id (12 bits)
CODE_VALUE, // numeric value, max = 4095
};
const std::unordered_set<uint32> continuous_event{
EVENT_ADJUST,
......@@ -576,6 +581,11 @@ const std::unordered_set<uint32> continuous_event{
EVENT_PRE_BATTLE_DAMAGE,
EVENT_SPSUMMON_SUCCESS_G_P,
};
bool is_continuous_event(uint32 code);
const std::unordered_set<uint32> affect_summoning_effect{
EFFECT_CANNOT_DISABLE_SUMMON,
EFFECT_CANNOT_DISABLE_SPSUMMON,
EVENT_BE_PRE_MATERIAL,
};
#endif /* EFFECT_H_ */
......@@ -486,7 +486,21 @@ void field::set_control(card* pcard, uint8 playerid, uint16 reset_phase, uint8 r
pcard->current.controler = playerid;
}
card* field::get_field_card(uint8 playerid, uint32 general_location, uint8 sequence) {
int32 field::get_pzone_sequence(uint8 pseq) const {
if (core.duel_rule >= NEW_MASTER_RULE) {
if(!pseq)
return 0;
else
return 4;
}
else {
if (!pseq)
return 6;
else
return 7;
}
}
card* field::get_field_card(uint8 playerid, uint32 general_location, uint8 sequence) const {
if (!check_playerid(playerid))
return nullptr;
switch(general_location) {
......@@ -512,12 +526,9 @@ card* field::get_field_card(uint8 playerid, uint32 general_location, uint8 seque
break;
}
case LOCATION_PZONE: {
if(sequence == 0) {
card* pcard = player[playerid].list_szone[core.duel_rule >= NEW_MASTER_RULE ? 0 : 6];
return (pcard && pcard->current.pzone) ? pcard : 0;
} else if(sequence == 1) {
card* pcard = player[playerid].list_szone[core.duel_rule >= NEW_MASTER_RULE ? 4 : 7];
return (pcard && pcard->current.pzone) ? pcard : 0;
if(sequence == 0 || sequence == 1) {
card* pcard = player[playerid].list_szone[get_pzone_sequence(sequence)];
return (pcard && pcard->current.pzone) ? pcard : nullptr;
} else
return nullptr;
break;
......@@ -567,33 +578,28 @@ int32 field::is_location_useable(uint8 playerid, uint32 general_location, uint8
if (general_location == LOCATION_MZONE) {
if (sequence >= (int32)player[playerid].list_mzone.size())
return FALSE;
if(flag & (0x1u << sequence))
if(flag & (0x1U << sequence))
return FALSE;
if(sequence >= 5) {
uint32 oppo = player[1 - playerid].disabled_location | player[1 - playerid].used_location;
if(oppo & (0x1u << (11 - sequence)))
if(oppo & (0x1U << (11 - sequence)))
return FALSE;
}
} else if (general_location == LOCATION_SZONE) {
if (sequence >= player[playerid].szone_size)
return FALSE;
if(flag & (0x100u << sequence))
if(flag & (0x100U << sequence))
return FALSE;
} else if (general_location == LOCATION_FZONE) {
if (sequence >= 1)
return FALSE;
if(flag & (0x100u << (5 + sequence)))
if(flag & (0x100U << (5 + sequence)))
return FALSE;
} else if (general_location == LOCATION_PZONE) {
if (sequence >= 2)
return FALSE;
if(core.duel_rule >= NEW_MASTER_RULE) {
if(flag & (0x100u << (sequence * 4)))
return FALSE;
} else {
if(flag & (0x100u << (6 + sequence)))
return FALSE;
}
if (flag & (0x100U << get_pzone_sequence(sequence)))
return FALSE;
}
return TRUE;
}
......@@ -821,11 +827,11 @@ int32 field::get_kaiser_limit(uint8 playerid, card* using_card) {
}
uint32 field::get_linked_zone(int32 playerid) {
uint32 zones = 0;
for(auto& pcard : player[playerid].list_mzone) {
for(const auto& pcard : player[playerid].list_mzone) {
if(pcard)
zones |= pcard->get_linked_zone() & 0xff;
zones |= pcard->get_linked_zone() & 0xffff;
}
for(auto& pcard : player[1 - playerid].list_mzone) {
for(const auto& pcard : player[1 - playerid].list_mzone) {
if(pcard)
zones |= pcard->get_linked_zone() >> 16;
}
......@@ -889,19 +895,19 @@ int32 field::check_extra_link(int32 playerid) {
if(!player[playerid].list_mzone[5] || !player[playerid].list_mzone[6])
return FALSE;
card* pcard = player[playerid].list_mzone[5];
uint32 checked = 1u << 5;
uint32 checked = 0x1u << 5;
uint32 linked_zone = pcard->get_mutual_linked_zone();
while(true) {
if((linked_zone >> 6) & 1)
if((linked_zone >> 6) & 0x1U)
return TRUE;
int32 checking = (int32)(linked_zone & ~checked);
uint32 checking = linked_zone & ~checked;
if(!checking)
return FALSE;
int32 rightmost = checking & (-checking);
checked |= (uint32)rightmost;
if(rightmost < 0x10000) {
uint32 rightmost = checking & (-checking);
checked |= rightmost;
if(rightmost < 0x10000U) {
for(int32 i = 0; i < 7; ++i) {
if(rightmost & 1) {
if(rightmost & 0x1U) {
pcard = player[playerid].list_mzone[i];
linked_zone |= pcard->get_mutual_linked_zone();
break;
......@@ -911,7 +917,7 @@ int32 field::check_extra_link(int32 playerid) {
} else {
rightmost >>= 16;
for(int32 i = 0; i < 7; ++i) {
if(rightmost & 1) {
if(rightmost & 0x1U) {
pcard = player[1 - playerid].list_mzone[i];
uint32 zone = pcard->get_mutual_linked_zone();
linked_zone |= (zone << 16) | (zone >> 16);
......@@ -1357,7 +1363,7 @@ void field::add_effect_code(uint32 code, uint32 playerid) {
count_map = &core.effect_count_code_duel;
else if(code & EFFECT_COUNT_CODE_CHAIN)
count_map = &core.effect_count_code_chain;
++(*count_map)[code + (playerid << 30)];
(*count_map)[code + (playerid << 30)]++;
}
uint32 field::get_effect_code(uint32 code, uint32 playerid) {
auto* count_map = &core.effect_count_code;
......@@ -1527,7 +1533,7 @@ int32 field::filter_matching_card(lua_State* L, int32 findex, uint8 self, uint32
}
if(location & LOCATION_PZONE) {
for(int32 i = 0; i < 2; ++i) {
card* pcard = player[self].list_szone[core.duel_rule >= NEW_MASTER_RULE ? i * 4 : i + 6];
card* pcard = player[self].list_szone[get_pzone_sequence(i)];
if(pcard && pcard->current.pzone && !pcard->is_treated_as_not_on_field()
&& pcard != pexception && !(pexgroup && pexgroup->has_card(pcard))
&& pduel->lua->check_filter(L, pcard, findex, extraargs)
......@@ -1653,7 +1659,7 @@ int32 field::filter_field_card(uint8 self, uint32 location1, uint32 location2, g
}
if(location & LOCATION_PZONE) {
for(int32 i = 0; i < 2; ++i) {
card* pcard = player[self].list_szone[core.duel_rule >= NEW_MASTER_RULE ? i * 4 : i + 6];
card* pcard = player[self].list_szone[get_pzone_sequence(i)];
if(pcard && pcard->current.pzone) {
result.insert(pcard);
}
......@@ -1679,7 +1685,7 @@ int32 field::filter_field_card(uint8 self, uint32 location1, uint32 location2, g
}
if (pgroup)
pgroup->container.insert(result.begin(), result.end());
return result.size();
return (int32)result.size();
}
effect* field::is_player_affected_by_effect(uint8 playerid, uint32 code) {
auto rg = effects.aura_effect.equal_range(code);
......@@ -1944,11 +1950,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)
......@@ -1956,9 +1962,9 @@ void field::ritual_release(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);
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();
......@@ -2141,6 +2147,8 @@ int32 field::adjust_grant_effect() {
effect* geffect = (effect*)peffect->get_label_object();
if (geffect->type & EFFECT_TYPE_GRANT)
continue;
if (geffect->code == EFFECT_UNIQUE_CHECK)
continue;
card_set cset;
if(peffect->is_available())
filter_affected_cards(peffect, &cset);
......@@ -2155,9 +2163,6 @@ int32 field::adjust_grant_effect() {
if(!pcard->is_affect_by_effect(peffect) || !cset.count(pcard))
remove_set.insert(pcard);
}
//X gains an effect from itself will break card::remove_effect
if (!peffect->is_flag(EFFECT_FLAG_FIELD_ONLY))
add_set.erase(peffect->handler);
for(auto& pcard : add_set) {
effect* ceffect = geffect->clone();
ceffect->owner = pcard;
......
......@@ -126,10 +126,10 @@ struct field_effect {
};
struct field_info {
int32 field_id{ 1 };
int16 copy_id{ 1 };
int16 turn_id{};
int16 turn_id_by_player[2]{};
int16 card_id{ 1 };
uint16 copy_id{ 1 };
uint16 turn_id{};
uint16 turn_id_by_player[2]{};
uint16 card_id{ 1 };
uint16 phase{};
uint8 turn_player{};
uint8 priorities[2]{};
......@@ -388,7 +388,9 @@ public:
void swap_card(card* pcard1, card* pcard2, uint8 new_sequence1, uint8 new_sequence2);
void swap_card(card* pcard1, card* pcard2);
void set_control(card* pcard, uint8 playerid, uint16 reset_phase, uint8 reset_count);
card* get_field_card(uint8 playerid, uint32 general_location, uint8 sequence);
int32 get_pzone_sequence(uint8 pseq) const;
card* get_field_card(uint8 playerid, uint32 general_location, uint8 sequence) const;
int32 is_location_useable(uint8 playerid, uint32 general_location, uint8 sequence) const;
int32 get_useable_count(card* pcard, uint8 playerid, uint8 location, uint8 uplayer, uint32 reason, uint32 zone = 0xff, uint32* list = nullptr);
int32 get_useable_count_fromex(card* pcard, uint8 playerid, uint8 uplayer, uint32 zone = 0xff, uint32* list = nullptr);
......@@ -441,7 +443,7 @@ public:
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);
......@@ -527,7 +529,7 @@ public:
int32 execute_operation(uint16 step, effect* peffect, uint8 triggering_player);
int32 execute_target(uint16 step, effect* peffect, uint8 triggering_player);
void raise_event(card* event_card, uint32 event_code, effect* reason_effect, uint32 reason, uint8 reason_player, uint8 event_player, uint32 event_value);
void raise_event(card_set* event_cards, uint32 event_code, effect* reason_effect, uint32 reason, uint8 reason_player, uint8 event_player, uint32 event_value);
void raise_event(const card_set& event_cards, uint32 event_code, effect* reason_effect, uint32 reason, uint8 reason_player, uint8 event_player, uint32 event_value);
void raise_single_event(card* trigger_card, card_set* event_cards, uint32 event_code, effect* reason_effect, uint32 reason, uint8 reason_player, uint8 event_player, uint32 event_value);
int32 check_event(uint32 code, tevent* pe = nullptr);
int32 check_event_c(effect* peffect, uint8 playerid, int32 neglect_con, int32 neglect_cost, int32 copy_info, tevent* pe = nullptr);
......@@ -564,9 +566,9 @@ public:
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);
......@@ -575,17 +577,17 @@ public:
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);
......@@ -629,7 +631,7 @@ public:
int32 toss_dice(uint16 step, effect* reason_effect, uint8 reason_player, uint8 playerid, uint8 count1, uint8 count2);
int32 rock_paper_scissors(uint16 step, uint8 repeat);
bool check_response(int32 vector_size, int32 min_len, int32 max_len) const;
bool check_response(size_t vector_size, int32 min_len, int32 max_len) const;
int32 select_battle_command(uint16 step, uint8 playerid);
int32 select_idle_command(uint16 step, uint8 playerid);
int32 select_effect_yes_no(uint16 step, uint8 playerid, uint32 description, card* pcard);
......
......@@ -393,10 +393,14 @@ int32 scriptlib::card_get_current_scale(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**)lua_touserdata(L, 1);
if(pcard->current.pzone && pcard->current.sequence == (pcard->pduel->game_field->core.duel_rule >= NEW_MASTER_RULE ? 0 : 6))
lua_pushinteger(L, pcard->get_lscale());
if (pcard->current.pzone) {
if (pcard->current.sequence == pcard->pduel->game_field->get_pzone_sequence(0))
lua_pushinteger(L, pcard->get_lscale());
else
lua_pushinteger(L, pcard->get_rscale());
}
else
lua_pushinteger(L, pcard->get_rscale());
lua_pushinteger(L, pcard->data.lscale);
return 1;
}
int32 scriptlib::card_is_link_marker(lua_State *L) {
......@@ -1889,10 +1893,10 @@ int32 scriptlib::card_register_flag_effect(lua_State *L) {
int32 reset = (int32)lua_tointeger(L, 3);
uint32 flag = (uint32)lua_tointeger(L, 4);
int32 count = (int32)lua_tointeger(L, 5);
int32 lab = 0;
lua_Integer lab = 0;
int32 desc = 0;
if(lua_gettop(L) >= 6)
lab = (int32)lua_tointeger(L, 6);
lab = lua_tointeger(L, 6);
if(lua_gettop(L) >= 7)
desc = (int32)lua_tointeger(L, 7);
if(count == 0)
......@@ -1936,7 +1940,7 @@ int32 scriptlib::card_set_flag_effect_label(lua_State *L) {
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
uint32 code = (lua_tointeger(L, 2) & MAX_CARD_ID) | EFFECT_FLAG_EFFECT;
int32 lab = (int32)lua_tointeger(L, 3);
auto lab = lua_tointeger(L, 3);
auto eit = pcard->single_effect.find(code);
if(eit == pcard->single_effect.end())
lua_pushboolean(L, FALSE);
......
......@@ -43,7 +43,7 @@ int32 scriptlib::debug_add_card(lua_State *L) {
position = POS_FACEDOWN_DEFENSE;
pcard->sendto_param.position = position;
if(location == LOCATION_PZONE) {
int32 seq = pduel->game_field->core.duel_rule >= NEW_MASTER_RULE ? sequence * 4 : sequence + 6;
int32 seq = pduel->game_field->get_pzone_sequence(sequence);
pduel->game_field->add_card(playerid, pcard, LOCATION_SZONE, seq, TRUE);
} else {
pduel->game_field->add_card(playerid, pcard, location, sequence);
......
This diff is collapsed.
......@@ -42,7 +42,7 @@ int32 scriptlib::get_effect_property(lua_State* L, effect_member type) {
lua_pushinteger(L, value);
return 1;
}
int32 scriptlib::is_effect_property(lua_State* L, effect_member type) {
int32 scriptlib::is_effect_has_property(lua_State* L, effect_member type) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_EFFECT, 1);
effect* peffect = *(effect**)lua_touserdata(L, 1);
......@@ -52,9 +52,6 @@ int32 scriptlib::is_effect_property(lua_State* L, effect_member type) {
case MEMBER_CATEGORY:
value = peffect->category;
break;
case MEMBER_CODE:
value = peffect->code;
break;
case MEMBER_RANGE:
value = peffect->range;
break;
......@@ -241,8 +238,7 @@ int32 scriptlib::effect_set_label(lua_State *L) {
effect* peffect = *(effect**) lua_touserdata(L, 1);
peffect->label.clear();
for(int32 i = 2; i <= lua_gettop(L); ++i) {
uint32 v = (uint32)lua_tointeger(L, i);
peffect->label.push_back(v);
peffect->label.push_back(lua_tointeger(L, i));
}
return 0;
}
......@@ -510,8 +506,8 @@ int32 scriptlib::effect_is_has_property(lua_State *L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_EFFECT, 1);
effect* peffect = *(effect**) lua_touserdata(L, 1);
uint32 tflag1 = (uint32)lua_tointeger(L, 2);
uint32 tflag2 = (uint32)lua_tointeger(L, 3);
uint64 tflag1 = lua_tointeger(L, 2);
uint64 tflag2 = lua_tointeger(L, 3);
if (peffect && (!tflag1 || (peffect->flag[0] & tflag1)) && (!tflag2 || (peffect->flag[1] & tflag2)))
lua_pushboolean(L, 1);
else
......@@ -519,13 +515,13 @@ int32 scriptlib::effect_is_has_property(lua_State *L) {
return 1;
}
int32 scriptlib::effect_is_has_category(lua_State *L) {
return is_effect_property(L, MEMBER_CATEGORY);
return is_effect_has_property(L, MEMBER_CATEGORY);
}
int32 scriptlib::effect_is_has_type(lua_State *L) {
return is_effect_property(L, MEMBER_TYPE);
return is_effect_has_property(L, MEMBER_TYPE);
}
int32 scriptlib::effect_is_has_range(lua_State* L) {
return is_effect_property(L, MEMBER_RANGE);
return is_effect_has_property(L, MEMBER_RANGE);
}
int32 scriptlib::effect_is_activatable(lua_State *L) {
check_param_count(L, 2);
......
This diff is collapsed.
......@@ -14,14 +14,14 @@
#include <algorithm>
#include <stack>
bool field::check_response(int32 vector_size, int32 min_len, int32 max_len) const {
bool field::check_response(size_t vector_size, int32 min_len, int32 max_len) const {
const int32 len = returns.bvalue[0];
if (len < min_len || len > max_len)
return false;
std::set<uint8> index_set;
for (int32 i = 0; i < len; ++i) {
uint8 index = returns.bvalue[1 + i];
if (index >=vector_size || index_set.count(index)) {
if (index >= (int32)vector_size || index_set.count(index)) {
return false;
}
index_set.insert(index);
......@@ -787,7 +787,7 @@ int32 field::sort_card(int16 step, uint8 playerid) {
int32 field::announce_race(int16 step, uint8 playerid, int32 count, int32 available) {
if(step == 0) {
int32 scount = 0;
for(int32 ft = 0x1; ft < (1 << RACES_COUNT); ft <<= 1) {
for(uint32 ft = 0x1; ft < (0x1U << RACES_COUNT); ft <<= 1) {
if(ft & available)
++scount;
}
......@@ -803,8 +803,9 @@ int32 field::announce_race(int16 step, uint8 playerid, int32 count, int32 availa
} else {
int32 rc = returns.ivalue[0];
int32 sel = 0;
for(int32 ft = 0x1; ft < (1 << RACES_COUNT); ft <<= 1) {
if(!(ft & rc)) continue;
for(uint32 ft = 0x1; ft < (0x1U << RACES_COUNT); ft <<= 1) {
if(!(ft & rc))
continue;
if(!(ft & available)) {
pduel->write_buffer8(MSG_RETRY);
return FALSE;
......
......@@ -37,7 +37,7 @@ workspace "ocgcoredll"
filter { "configurations:Release", "action:vs*" }
flags { "LinkTimeOptimization" }
staticruntime "On"
disablewarnings { "4267", "4334" }
disablewarnings { "4334" }
filter "action:vs*"
buildoptions { "/utf-8" }
......
This diff is collapsed.
......@@ -310,7 +310,7 @@ public:
//Effect functions
static int32 get_effect_property(lua_State* L, effect_member type);
static int32 is_effect_property(lua_State* L, effect_member type);
static int32 is_effect_has_property(lua_State* L, effect_member type);
static int32 effect_new(lua_State *L);
static int32 effect_newex(lua_State *L);
static int32 effect_clone(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