Commit fa3c18f5 authored by mercury233's avatar mercury233
parents ae8adc53 90a07a09
......@@ -1426,78 +1426,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)
zones |= (1u << 5) | (1u << (16 + 6));
if(s == 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 <= 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(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_mzone >> 16, 1 - 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_szone >> 16, 1 - p, LOCATION_SZONE);
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);
......
......@@ -192,8 +192,6 @@ struct processor {
event_list sub_solving_event;
chain_array select_chains;
chain_array current_chain;
chain_list tpchain;
chain_list ntpchain;
chain_list continuous_chain;
chain_list desrep_chain;
chain_list new_fchain;
......@@ -498,7 +496,6 @@ public:
int32 process_turn(uint16 step, uint8 turn_player);
int32 add_chain(uint16 step);
int32 sort_chain(uint16 step, uint8 tp);
int32 solve_continuous(uint16 step, effect* peffect, uint8 triggering_player);
int32 solve_chain(uint16 step, uint32 chainend_arg1, uint32 chainend_arg2);
int32 break_effect();
......@@ -687,7 +684,7 @@ public:
#define PROCESSOR_SELECT_PLACE 18
#define PROCESSOR_SELECT_POSITION 19
#define PROCESSOR_SELECT_TRIBUTE_P 20
#define PROCESSOR_SORT_CHAIN 21
//#define PROCESSOR_SORT_CHAIN 21
#define PROCESSOR_SELECT_COUNTER 22
#define PROCESSOR_SELECT_SUM 23
#define PROCESSOR_SELECT_DISFIELD 24
......
......@@ -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;
......
......@@ -161,14 +161,6 @@ int32 field::process() {
return PROCESSOR_WAITING + pduel->bufferlen;
}
}
case PROCESSOR_SORT_CHAIN: {
if (sort_chain(it->step, it->arg1)) {
core.units.pop_front();
} else {
it->step++;
}
return pduel->bufferlen;
}
case PROCESSOR_SELECT_COUNTER: {
if (select_counter(it->step, it->arg1, it->arg2, it->arg3, it->arg4 >> 8, it->arg4 & 0xff)) {
core.units.pop_front();
......@@ -1674,8 +1666,6 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free
}
core.new_fchain_s.splice(core.new_fchain_s.begin(), core.new_fchain);
core.new_ochain_s.splice(core.new_ochain_s.begin(), core.new_ochain);
core.tpchain.clear();
core.ntpchain.clear();
core.delayed_quick.clear();
core.delayed_quick_break.swap(core.delayed_quick);
core.current_player = infos.turn_player;
......@@ -1994,35 +1984,56 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free
int32 field::process_quick_effect(int16 step, int32 skip_freechain, uint8 priority) {
switch(step) {
case 0: {
core.tpchain.clear();
core.ntpchain.clear();
if(!core.quick_f_chain.size())
return FALSE;
for(auto ifit = core.quick_f_chain.begin(); ifit != core.quick_f_chain.end(); ++ifit) {
uint8 check_player = infos.turn_player;
if(core.units.begin()->arg3)
check_player = 1 - infos.turn_player;
core.select_chains.clear();
for(auto ifit = core.quick_f_chain.begin(); ifit != core.quick_f_chain.end(); ) {
effect* peffect = ifit->first;
card* phandler = peffect->get_handler();
if(peffect->is_chainable(ifit->second.triggering_player) && peffect->check_count_limit(ifit->second.triggering_player)
&& phandler->is_has_relation(ifit->second)) {
if(ifit->second.triggering_player == infos.turn_player) {
core.tpchain.push_back(ifit->second);
phandler->set_status(STATUS_CHAINING, TRUE);
peffect->dec_count(infos.turn_player);
if(ifit->second.triggering_player == check_player)
core.select_chains.push_back(ifit->second);
} else {
core.ntpchain.push_back(ifit->second);
phandler->set_status(STATUS_CHAINING, TRUE);
peffect->dec_count(1 - infos.turn_player);
}
core.quick_f_chain.erase(ifit++);
continue;
}
++ifit;
}
core.quick_f_chain.clear();
if(core.tpchain.size() > 1)
add_process(PROCESSOR_SORT_CHAIN, 0, 0, 0, 1, infos.turn_player);
if(core.ntpchain.size() > 1)
add_process(PROCESSOR_SORT_CHAIN, 0, 0, 0, 0, infos.turn_player);
if(core.select_chains.size() == 0)
returns.ivalue[0] = -1;
else if(core.select_chains.size() == 1)
returns.ivalue[0] = 0;
else
add_process(PROCESSOR_SELECT_CHAIN, 0, 0, 0, check_player, 0x10000);
return FALSE;
}
case 1: {
if(core.tpchain.size() == 0 && core.ntpchain.size() == 0) {
if(returns.ivalue[0] == -1) {
if(core.quick_f_chain.size()) {
core.units.begin()->arg3 = TRUE;
core.units.begin()->step = -1;
} else if(core.new_chains.size()) {
add_process(PROCESSOR_ADD_CHAIN, 0, 0, 0, 0, 0);
add_process(PROCESSOR_QUICK_EFFECT, 0, 0, 0, FALSE, 1 - core.new_chains.back().triggering_player);
infos.priorities[0] = 0;
infos.priorities[1] = 0;
return TRUE;
}
return FALSE;
}
chain newchain = core.select_chains[returns.ivalue[0]];
effect* peffect = newchain.triggering_effect;
uint8 tp = newchain.triggering_player;
peffect->get_handler()->set_status(STATUS_CHAINING, TRUE);
peffect->dec_count(tp);
core.new_chains.push_back(newchain);
core.quick_f_chain.erase(peffect);
core.units.begin()->step = -1;
return FALSE;
}
case 2: {
chain newchain;
auto evit = core.point_event.begin();
bool pev = true;
......@@ -2178,18 +2189,9 @@ int32 field::process_quick_effect(int16 step, int32 skip_freechain, uint8 priori
if(core.current_chain.size() || (core.hint_timing[0] & TIMING_ATTACK) || (core.hint_timing[1] & TIMING_ATTACK))
core.spe_effect[priority] = core.select_chains.size();
add_process(PROCESSOR_SELECT_CHAIN, 0, 0, 0, priority, core.spe_effect[priority]);
} else {
core.new_chains.splice(core.new_chains.end(), core.tpchain);
core.new_chains.splice(core.new_chains.end(), core.ntpchain);
add_process(PROCESSOR_ADD_CHAIN, 0, 0, 0, 0, 0);
add_process(PROCESSOR_QUICK_EFFECT, 0, 0, 0, FALSE, 1 - core.new_chains.back().triggering_player);
infos.priorities[0] = 0;
infos.priorities[1] = 0;
return TRUE;
}
return FALSE;
}
case 2: {
case 3: {
if(core.select_chains.size() && returns.ivalue[0] != -1) {
chain newchain = core.select_chains[returns.ivalue[0]];
core.new_chains.push_back(newchain);
......@@ -4504,46 +4506,6 @@ int32 field::add_chain(uint16 step) {
}
return TRUE;
}
int32 field::sort_chain(uint16 step, uint8 tp) {
switch(step) {
case 0: {
core.select_cards.clear();
if(tp)
for(auto clit = core.tpchain.begin(); clit != core.tpchain.end(); ++clit)
core.select_cards.push_back(clit->triggering_effect->get_handler());
else
for(auto clit = core.ntpchain.begin(); clit != core.ntpchain.end(); ++clit)
core.select_cards.push_back(clit->triggering_effect->get_handler());
add_process(PROCESSOR_SORT_CARD, 0, 0, 0, tp ? infos.turn_player : (1 - infos.turn_player), 1);
return FALSE;
}
case 1: {
if(returns.bvalue[0] == -1)
return TRUE;
chain_list::iterator clit;
int32 i = 0, count;
if(tp) {
count = core.tpchain.size();
chain_array ch(count);
for(i = 0, clit = core.tpchain.begin(); i < count; ++clit, ++i)
ch[returns.bvalue[i]] = *clit;
core.tpchain.clear();
for(i = 0; i < count; ++i)
core.tpchain.push_back(ch[i]);
} else {
count = core.ntpchain.size();
chain_array ch(count);
for(i = 0, clit = core.ntpchain.begin(); i < count; ++clit, ++i)
ch[returns.bvalue[i]] = *clit;
core.ntpchain.clear();
for(i = 0; i < count; ++i)
core.ntpchain.push_back(ch[i]);
}
return TRUE;
}
}
return TRUE;
}
int32 field::solve_continuous(uint16 step, effect * peffect, uint8 triggering_player) {
switch(step) {
case 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