Commit 6988cf33 authored by fallenstardust's avatar fallenstardust

sync ocgcore

parent f82a88c5
......@@ -1218,6 +1218,7 @@ void card::get_linked_cards(card_set* cset) {
int32 p = current.controler;
uint32 linked_zone = get_linked_zone();
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() {
if(!(data.type & TYPE_LINK) || current.location != LOCATION_MZONE)
......@@ -1356,6 +1357,7 @@ void card::get_mutual_linked_cards(card_set* cset) {
int32 p = current.controler;
uint32 mutual_linked_zone = get_mutual_linked_zone();
pduel->game_field->get_cards_in_zone(cset, mutual_linked_zone, p, LOCATION_MZONE);
pduel->game_field->get_cards_in_zone(cset, mutual_linked_zone >> 16, 1 - p, LOCATION_MZONE);
}
int32 card::is_link_state() {
if(current.location != LOCATION_MZONE)
......@@ -1428,76 +1430,58 @@ int32 card::is_status(uint32 status) {
return TRUE;
return FALSE;
}
uint32 card::get_column_zone(int32 loc1, int32 left, int32 right) {
uint32 card::get_column_zone(int32 location) {
int32 zones = 0;
int32 loc2 = current.location;
int32 s = current.sequence;
if(!(loc1 & LOCATION_ONFIELD) || !(loc2 & LOCATION_ONFIELD) || loc2 == LOCATION_SZONE && s >=5 || left < 0 || right < 0)
uint8 seq = current.sequence;
if(!(location & LOCATION_ONFIELD) || !(current.location & LOCATION_ONFIELD) || current.location == LOCATION_SZONE && seq >= 5)
return 0;
if(s <= 4) {
if(loc1 != loc2)
zones |= 1u << s;
zones |= 1u << (16 + (4 - s));
if(loc1 & LOCATION_MZONE) {
if(s == 1)
if(seq <= 4) {
if(location & LOCATION_MZONE) {
if(!(current.location & LOCATION_MZONE))
zones |= 1u << seq;
zones |= 1u << (16 + (4 - seq));
if(seq == 1)
zones |= (1u << 5) | (1u << (16 + 6));
if(s == 3)
if(seq == 3)
zones |= (1u << 6) | (1u << (16 + 5));
}
}
if(s == 5)
zones |= (1u << 1) | (1u << (16 + 3));
if(s == 6)
zones |= (1u << 3) | (1u << (16 + 1));
for(int32 i = 1; i <= left; ++i) {
int32 seq = s - i;
if(s == 5)
seq = 1 - i;
if(s == 6)
seq = 3 - i;
if(seq >= 0 && seq <= 4) {
zones |= 1u << seq | 1u << (16 + (4 - seq));
if(loc1 & LOCATION_MZONE) {
if(seq == 1)
zones |= (1u << 5) | (1u << (16 + 6));
if(seq == 3)
zones |= (1u << 6) | (1u << (16 + 5));
}
if(location & LOCATION_SZONE) {
if(!(current.location & LOCATION_SZONE))
zones |= 1u << (seq + 8);
zones |= 1u << (16 + 8 + (4 - seq));
}
}
for(int32 i = 1; i <= right; ++i) {
int32 seq = s + i;
if(s == 5)
seq = 1 + i;
if(s == 6)
seq = 3 + i;
if(seq >= 0 && seq <= 4) {
zones |= 1u << seq | 1u << (16 + (4 - seq));
if(loc1 & LOCATION_MZONE) {
if(seq == 1)
zones |= (1u << 5) | (1u << (16 + 6));
if(seq == 3)
zones |= (1u << 6) | (1u << (16 + 5));
}
}
if(seq == 5) {
if(location & LOCATION_MZONE)
zones |= (1u << 1) | (1u << (16 + 3));
if(location & LOCATION_SZONE)
zones |= (1u << (8 + 1)) | (1u << (16 + 8 + 3));
}
if(seq == 6) {
if(location & LOCATION_MZONE)
zones |= (1u << 3) | (1u << (16 + 1));
if(location & LOCATION_SZONE)
zones |= (1u << (8 + 3)) | (1u << (16 + 8 + 1));
}
return zones;
}
void card::get_column_cards(card_set* cset, int32 left, int32 right) {
void card::get_column_cards(card_set* cset) {
cset->clear();
if(!(current.location & LOCATION_ONFIELD))
return;
int32 p = current.controler;
uint32 column_mzone = get_column_zone(LOCATION_MZONE, left, right);
uint32 column_szone = get_column_zone(LOCATION_SZONE, left, right);
uint32 column_mzone = get_column_zone(LOCATION_MZONE);
uint32 column_szone = get_column_zone(LOCATION_SZONE);
pduel->game_field->get_cards_in_zone(cset, column_mzone, p, LOCATION_MZONE);
pduel->game_field->get_cards_in_zone(cset, column_szone, p, LOCATION_SZONE);
pduel->game_field->get_cards_in_zone(cset, column_mzone >> 16, 1 - p, LOCATION_MZONE);
pduel->game_field->get_cards_in_zone(cset, column_szone >> 8, p, LOCATION_SZONE);
pduel->game_field->get_cards_in_zone(cset, column_szone >> 24, 1 - p, LOCATION_SZONE);
}
int32 card::is_all_column() {
if(!(current.location & LOCATION_ONFIELD))
return FALSE;
card_set cset;
get_column_cards(&cset, 0, 0);
get_column_cards(&cset);
int32 full = 3;
if(pduel->game_field->core.duel_rule >= 4 && (current.sequence == 1 || current.sequence == 3))
full++;
......
......@@ -233,8 +233,8 @@ public:
void set_status(uint32 status, int32 enabled);
int32 get_status(uint32 status);
int32 is_status(uint32 status);
uint32 get_column_zone(int32 loc1, int32 left, int32 right);
void get_column_cards(card_set* cset, int32 left, int32 right);
uint32 get_column_zone(int32 location);
void get_column_cards(card_set* cset);
int32 is_all_column();
void equip(card *target, uint32 send_msg = TRUE);
......
......@@ -816,7 +816,7 @@ void field::get_linked_cards(uint8 self, uint8 s, uint8 o, card_set* cset) {
uint8 c = s;
for(int32 p = 0; p < 2; ++p) {
if(c) {
uint32 linked_zone = get_linked_zone(self) & 0xffff;
uint32 linked_zone = get_linked_zone(self);
get_cards_in_zone(cset, linked_zone, self, LOCATION_MZONE);
}
self = 1 - self;
......@@ -883,50 +883,15 @@ int32 field::check_extra_link(int32 playerid, card* pcard, int32 sequence) {
void field::get_cards_in_zone(card_set* cset, uint32 zone, int32 playerid, int32 location) {
if(!(location & LOCATION_ONFIELD))
return;
uint32 icheck;
if(location & LOCATION_MZONE) {
card_vector& svector_s = player[playerid].list_mzone;
icheck = 0x1;
for(auto it = svector_s.begin(); it != svector_s.end(); ++it) {
if(zone & icheck) {
card* pcard = *it;
if(pcard)
cset->insert(pcard);
}
icheck <<= 1;
}
card_vector& svector_o = player[1 - playerid].list_mzone;
icheck = 0x10000;
for(auto it = svector_o.begin(); it != svector_o.end(); ++it) {
if(zone & icheck) {
card* pcard = *it;
if(pcard)
cset->insert(pcard);
}
icheck <<= 1;
}
}
if(location & LOCATION_SZONE) {
card_vector& svector_s = player[playerid].list_szone;
icheck = 0x100;
for(auto it = svector_s.begin(); it != svector_s.end(); ++it) {
if(zone & icheck) {
card* pcard = *it;
if(pcard)
cset->insert(pcard);
}
icheck <<= 1;
}
card_vector& svector_o = player[1 - playerid].list_szone;
icheck = 0x1000000;
for(auto it = svector_o.begin(); it != svector_o.end(); ++it) {
if(zone & icheck) {
card* pcard = *it;
if(pcard)
cset->insert(pcard);
}
icheck <<= 1;
card_vector& svector = (location == LOCATION_MZONE) ? player[playerid].list_mzone : player[playerid].list_szone;
uint32 icheck = 0x1;
for(auto it = svector.begin(); it != svector.end(); ++it) {
if(zone & icheck) {
card* pcard = *it;
if(pcard)
cset->insert(pcard);
}
icheck <<= 1;
}
}
void field::shuffle(uint8 playerid, uint8 location) {
......@@ -2638,7 +2603,7 @@ int32 field::check_tuner_material(card* pcard, card* tuner, int32 findex1, int32
card_set linked_cards;
if(ct <= 0) {
uint32 linked_zone = core.duel_rule >= 4 ? get_linked_zone(playerid) | (1u << 5) | (1u << 6) : 0x1f;
get_cards_in_zone(&linked_cards, linked_zone & 0xffff, playerid, LOCATION_MZONE);
get_cards_in_zone(&linked_cards, linked_zone, playerid, LOCATION_MZONE);
if(linked_cards.find(tuner) != linked_cards.end())
ct++;
}
......@@ -2936,7 +2901,7 @@ int32 field::check_xyz_material(card* scard, int32 findex, int32 lv, int32 min,
if(ct <= 0) {
int32 ft = ct;
uint32 linked_zone = core.duel_rule >= 4 ? get_linked_zone(playerid) | (1u << 5) | (1u << 6) : 0x1f;
get_cards_in_zone(&linked_cards, linked_zone & 0xffff, playerid, LOCATION_MZONE);
get_cards_in_zone(&linked_cards, linked_zone, playerid, LOCATION_MZONE);
for(auto cit = core.xmaterial_lst.begin(); cit != core.xmaterial_lst.end(); ++cit) {
card* pcard = cit->second;
if(linked_cards.find(pcard) != linked_cards.end())
......
......@@ -374,7 +374,7 @@ public:
void get_linked_cards(uint8 self, uint8 s, uint8 o, card_set* cset);
int32 check_extra_link(int32 playerid);
int32 check_extra_link(int32 playerid, card* pcard, int32 sequence);
void get_cards_in_zone(card_set* cset, uint32 zone, int32 playerid, int32 location = 0xc);
void get_cards_in_zone(card_set* cset, uint32 zone, int32 playerid, int32 location);
void shuffle(uint8 playerid, uint8 location);
void reset_sequence(uint8 playerid, uint8 location);
void swap_deck_and_grave(uint8 playerid);
......
......@@ -424,14 +424,8 @@ int32 scriptlib::card_get_column_group(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
int32 left = 0;
int32 right = 0;
if(lua_gettop(L) >= 2)
left = lua_tointeger(L, 2);
if(lua_gettop(L) >= 3)
right = lua_tointeger(L, 3);
card::card_set cset;
pcard->get_column_cards(&cset, left, right);
pcard->get_column_cards(&cset);
group* pgroup = pcard->pduel->new_group(cset);
interpreter::group2value(L, pgroup);
return 1;
......@@ -440,14 +434,8 @@ int32 scriptlib::card_get_column_group_count(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
int32 left = 0;
int32 right = 0;
if(lua_gettop(L) >= 2)
left = lua_tointeger(L, 2);
if(lua_gettop(L) >= 3)
right = lua_tointeger(L, 3);
card::card_set cset;
pcard->get_column_cards(&cset, left, right);
pcard->get_column_cards(&cset);
lua_pushinteger(L, cset.size());
return 1;
}
......@@ -456,16 +444,10 @@ int32 scriptlib::card_get_column_zone(lua_State *L) {
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
int32 loc = lua_tointeger(L, 2);
int32 left = 0;
int32 right = 0;
int32 cp = pcard->current.controler;
if(lua_gettop(L) >= 3)
left = lua_tointeger(L, 3);
if(lua_gettop(L) >= 4)
right = lua_tointeger(L, 4);
if(lua_gettop(L) >= 5 && !lua_isnil(L, 5))
cp = lua_tointeger(L, 5);
uint32 zone = pcard->get_column_zone(loc, left, right);
if(lua_gettop(L) >= 3 && !lua_isnil(L, 3))
cp = lua_tointeger(L, 3);
uint32 zone = pcard->get_column_zone(loc);
if(cp == 1 - pcard->current.controler)
lua_pushinteger(L, (((zone & 0xffff) << 16) | (zone >> 16)));
else
......
......@@ -1516,8 +1516,6 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui
}
effect* peffect = core.select_effects[returns.ivalue[0]];
core.units.begin()->peffect = peffect;
int32 unlimited = -1;
bool force_select = false;
core.select_effects.clear();
core.select_options.clear();
if(ignore_count || core.summon_count[sumplayer] < get_summon_count_limit(sumplayer)) {
......@@ -1532,12 +1530,9 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui
int32 new_zone = retval.size() > 1 ? retval[1] : 0x1f;
int32 releasable = retval.size() > 2 ? (retval[2] < 0 ? 0xff00ff + retval[2] : retval[2]) : 0xff00ff;
new_zone &= zone;
bool unchanged = (new_zone == zone);
if(peffect) {
if(new_min_tribute < (int32)min_tribute) {
if(new_min_tribute < (int32)min_tribute)
new_min_tribute = min_tribute;
unchanged = false;
}
if(!target->is_summonable(peffect, new_min_tribute, new_zone, releasable))
continue;
} else {
......@@ -1550,25 +1545,17 @@ int32 field::summon(uint16 step, uint8 sumplayer, card* target, effect* proc, ui
min = min_tribute;
if(max < min)
continue;
if(min < new_min_tribute) {
if(min < new_min_tribute)
min = new_min_tribute;
unchanged = false;
}
if(!check_tribute(target, min, max, 0, target->current.controler, new_zone, releasable))
continue;
}
if(unlimited < 0 && unchanged)
unlimited = (int32)core.select_effects.size();
if(eset[i]->operation)
force_select = true;
core.select_effects.push_back(eset[i]);
core.select_options.push_back(eset[i]->description);
}
}
if(core.select_options.size() == 1)
returns.ivalue[0] = 0;
else if(!force_select && unlimited >= 0)
returns.ivalue[0] = unlimited;
else
add_process(PROCESSOR_SELECT_OPTION, 0, 0, 0, sumplayer, 0);
return FALSE;
......@@ -2062,8 +2049,6 @@ int32 field::mset(uint16 step, uint8 setplayer, card* target, effect* proc, uint
}
effect* peffect = core.select_effects[returns.ivalue[0]];
core.units.begin()->peffect = peffect;
int32 unlimited = -1;
bool force_select = false;
core.select_effects.clear();
core.select_options.clear();
if(ignore_count || core.summon_count[setplayer] < get_summon_count_limit(setplayer)) {
......@@ -2078,12 +2063,9 @@ int32 field::mset(uint16 step, uint8 setplayer, card* target, effect* proc, uint
int32 new_zone = retval.size() > 1 ? retval[1] : 0x1f;
int32 releasable = retval.size() > 2 ? (retval[2] < 0 ? 0xff00ff + retval[2] : retval[2]) : 0xff00ff;
new_zone &= zone;
bool unchanged = (new_zone == zone);
if(peffect) {
if(new_min_tribute < (int32)min_tribute) {
if(new_min_tribute < (int32)min_tribute)
new_min_tribute = min_tribute;
unchanged = false;
}
if(!target->is_summonable(peffect, new_min_tribute, new_zone, releasable))
continue;
} else {
......@@ -2096,25 +2078,17 @@ int32 field::mset(uint16 step, uint8 setplayer, card* target, effect* proc, uint
min = min_tribute;
if(max < min)
continue;
if(min < new_min_tribute) {
if(min < new_min_tribute)
min = new_min_tribute;
unchanged = false;
}
if(!check_tribute(target, min, max, 0, target->current.controler, new_zone, releasable, POS_FACEDOWN_DEFENSE))
continue;
}
if(unlimited < 0 && unchanged)
unlimited = (int32)core.select_effects.size();
if(eset[i]->operation)
force_select = true;
core.select_effects.push_back(eset[i]);
core.select_options.push_back(eset[i]->description);
}
}
if(core.select_options.size() == 1)
returns.ivalue[0] = 0;
else if(!force_select && unlimited >= 0)
returns.ivalue[0] = unlimited;
else
add_process(PROCESSOR_SELECT_OPTION, 0, 0, 0, setplayer, 0);
return FALSE;
......@@ -5067,7 +5041,7 @@ int32 field::select_synchro_material(int16 step, uint8 playerid, card* pcard, in
}
card_set linked_cards;
uint32 linked_zone = core.duel_rule >= 4 ? get_linked_zone(playerid) | (1u << 5) | (1u << 6) : 0x1f;
get_cards_in_zone(&linked_cards, linked_zone & 0xffff, playerid, LOCATION_MZONE);
get_cards_in_zone(&linked_cards, linked_zone, playerid, LOCATION_MZONE);
if(linked_cards.find(tuner) != linked_cards.end())
ct++;
if(smat && linked_cards.find(smat) != linked_cards.end())
......@@ -5296,7 +5270,7 @@ int32 field::select_xyz_material(int16 step, uint8 playerid, uint32 lv, card* sc
card_set linked_cards;
if(ct <= 0) {
uint32 linked_zone = core.duel_rule >= 4 ? get_linked_zone(playerid) | (1u << 5) | (1u << 6) : 0x1f;
get_cards_in_zone(&linked_cards, linked_zone & 0xffff, playerid, LOCATION_MZONE);
get_cards_in_zone(&linked_cards, linked_zone, playerid, LOCATION_MZONE);
}
for(auto mit = core.operated_set.begin(); mit != core.operated_set.end(); ++mit) {
card* pcard = *mit;
......@@ -5382,7 +5356,7 @@ int32 field::select_xyz_material(int16 step, uint8 playerid, uint32 lv, card* sc
}
card_set linked_cards;
uint32 linked_zone = core.duel_rule >= 4 ? get_linked_zone(playerid) | (1u << 5) | (1u << 6) : 0x1f;
get_cards_in_zone(&linked_cards, linked_zone & 0xffff, playerid, LOCATION_MZONE);
get_cards_in_zone(&linked_cards, linked_zone, playerid, LOCATION_MZONE);
int32 ft = ct + std::count_if(core.operated_set.begin(), core.operated_set.end(),
[=](card* pcard) { return linked_cards.find(pcard) != linked_cards.end(); });
if(ft > 0) {
......@@ -5565,7 +5539,7 @@ int32 field::select_xyz_material(int16 step, uint8 playerid, uint32 lv, card* sc
return FALSE;
card_set linked_cards;
uint32 linked_zone = core.duel_rule >= 4 ? get_linked_zone(playerid) | (1u << 5) | (1u << 6) : 0x1f;
get_cards_in_zone(&linked_cards, linked_zone & 0xffff, playerid, LOCATION_MZONE);
get_cards_in_zone(&linked_cards, linked_zone, playerid, LOCATION_MZONE);
int32 ft = ct + std::count_if(core.operated_set.begin(), core.operated_set.end(),
[=](card* pcard) { return linked_cards.find(pcard) != linked_cards.end(); });
if(ft > 0)
......
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