Commit b0776933 authored by mercury233's avatar mercury233
parents 86d502db 4cc1b185
......@@ -573,7 +573,6 @@ int32 card::get_attack() {
filter_effect(EFFECT_UPDATE_ATTACK, &eset, FALSE);
filter_effect(EFFECT_SET_ATTACK, &eset, FALSE);
filter_effect(EFFECT_SET_ATTACK_FINAL, &eset, FALSE);
filter_effect(EFFECT_SWAP_ATTACK_FINAL, &eset, FALSE);
filter_effect(EFFECT_SET_BASE_ATTACK, &eset, FALSE);
if(!(data.type & TYPE_LINK)) {
filter_effect(EFFECT_SWAP_AD, &eset, FALSE);
......@@ -637,11 +636,6 @@ int32 card::get_attack() {
batk = 0;
atk = -1;
break;
case EFFECT_SWAP_ATTACK_FINAL:
atk = eset[i]->get_value(this);
up_atk = 0;
upc_atk = 0;
break;
case EFFECT_SET_BASE_DEFENSE:
bdef = eset[i]->get_value(this);
if(bdef < 0)
......@@ -773,7 +767,6 @@ int32 card::get_defense() {
filter_effect(EFFECT_UPDATE_DEFENSE, &eset, FALSE);
filter_effect(EFFECT_SET_DEFENSE, &eset, FALSE);
filter_effect(EFFECT_SET_DEFENSE_FINAL, &eset, FALSE);
filter_effect(EFFECT_SWAP_DEFENSE_FINAL, &eset, FALSE);
filter_effect(EFFECT_SWAP_BASE_AD, &eset, FALSE);
filter_effect(EFFECT_SET_BASE_ATTACK, &eset, FALSE);
filter_effect(EFFECT_SET_BASE_DEFENSE, &eset, FALSE);
......@@ -834,11 +827,6 @@ int32 card::get_defense() {
bdef = 0;
def = -1;
break;
case EFFECT_SWAP_DEFENSE_FINAL:
def = eset[i]->get_value(this);
up_def = 0;
upc_def = 0;
break;
case EFFECT_SET_BASE_ATTACK:
batk = eset[i]->get_value(this);
if(batk < 0)
......@@ -1911,7 +1899,8 @@ void card::reset(uint32 id, uint32 reset_type) {
}
}
if(id & RESET_TURN_SET) {
if(effect* peffect = check_control_effect()) {
effect* peffect = std::get<effect*>(refresh_control_status());
if(peffect && (!(peffect->type & EFFECT_TYPE_SINGLE) || peffect->condition)) {
effect* new_effect = pduel->new_effect();
new_effect->id = peffect->id;
new_effect->owner = this;
......@@ -1964,8 +1953,9 @@ void card::refresh_disable_status() {
if(pre_dis != cur_dis)
filter_immune_effect();
}
uint8 card::refresh_control_status() {
std::tuple<uint8, effect*> card::refresh_control_status() {
uint8 final = owner;
effect* ceffect = nullptr;
uint32 last_id = 0;
if(pduel->game_field->core.remove_brainwashing && is_affected_by_effect(EFFECT_REMOVE_BRAINWASHING))
last_id = pduel->game_field->core.last_control_changed_id;
......@@ -1974,18 +1964,11 @@ uint8 card::refresh_control_status() {
if(eset.size()) {
effect* peffect = eset.get_last();
if(peffect->id >= last_id) {
card* pcard = peffect->get_handler();
uint8 val = (uint8)peffect->get_value(this);
if(val != current.controler)
pduel->game_field->core.readjust_map[pcard]++;
if(pduel->game_field->core.readjust_map[pcard] > 5) {
pduel->game_field->send_to(pcard, 0, REASON_RULE, peffect->get_handler_player(), PLAYER_NONE, LOCATION_GRAVE, 0, POS_FACEUP);
return final;
}
final = val;
final = (uint8)peffect->get_value(this);
ceffect = peffect;
}
}
return final;
return { final, ceffect };
}
void card::count_turn(uint16 ct) {
turn_counter = ct;
......@@ -2730,54 +2713,6 @@ effect* card::is_affected_by_effect(int32 code, card* target) {
}
return 0;
}
effect* card::check_control_effect() {
effect* ret_effect = 0;
for (auto& pcard : equiping_cards) {
auto rg = pcard->equip_effect.equal_range(EFFECT_SET_CONTROL);
for (; rg.first != rg.second; ++rg.first) {
effect* peffect = rg.first->second;
if(!ret_effect || peffect->id > ret_effect->id)
ret_effect = peffect;
}
}
for (auto& pcard : effect_target_owner) {
auto rg = pcard->target_effect.equal_range(EFFECT_SET_CONTROL);
for (; rg.first != rg.second; ++rg.first) {
effect* peffect = rg.first->second;
if(!ret_effect || peffect->is_target(pcard) && peffect->id > ret_effect->id)
ret_effect = peffect;
}
}
for (auto& pcard : xyz_materials) {
auto rg = pcard->xmaterial_effect.equal_range(EFFECT_SET_CONTROL);
for (; rg.first != rg.second; ++rg.first) {
effect* peffect = rg.first->second;
if (peffect->type & EFFECT_TYPE_FIELD)
continue;
if(!ret_effect || peffect->id > ret_effect->id)
ret_effect = peffect;
}
}
auto rg = single_effect.equal_range(EFFECT_SET_CONTROL);
for (; rg.first != rg.second; ++rg.first) {
effect* peffect = rg.first->second;
if(!peffect->condition)
continue;
if(!ret_effect || peffect->id > ret_effect->id)
ret_effect = peffect;
}
/*
rg = pduel->game_field->effects.aura_effect.equal_range(EFFECT_SET_CONTROL);
for(; rg.first != rg.second; ++rg.first) {
effect* peffect = rg.first->second;
if(peffect->is_flag(EFFECT_FLAG_PLAYER_TARGET) || !peffect->is_target(this))
continue;
if(!ret_effect || peffect->id > ret_effect->id)
ret_effect = peffect;
}
*/
return ret_effect;
}
int32 card::fusion_check(group* fusion_m, card* cg, uint32 chkf, uint8 not_material) {
group* matgroup = 0;
if(fusion_m && !not_material) {
......
......@@ -14,6 +14,7 @@
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
class card;
class duel;
......@@ -93,14 +94,14 @@ public:
return std::hash<uint16>()(v.second);
}
};
typedef std::vector<card*> card_vector;
typedef std::multimap<uint32, effect*> effect_container;
typedef std::set<card*, card_sort> card_set;
typedef std::unordered_map<effect*, effect_container::iterator> effect_indexer;
typedef std::unordered_set<std::pair<effect*, uint16>, effect_relation_hash> effect_relation;
typedef std::unordered_map<card*, uint32> relation_map;
typedef std::map<uint16, std::array<uint16, 2>> counter_map;
typedef std::map<uint32, int32> effect_count;
using card_vector = std::vector<card*>;
using effect_container = std::multimap<uint32, effect*>;
using card_set = std::set<card*, card_sort>;
using effect_indexer = std::unordered_map<effect*, effect_container::iterator>;
using effect_relation = std::unordered_set<std::pair<effect*, uint16>, effect_relation_hash>;
using relation_map = std::unordered_map<card*, uint32>;
using counter_map = std::map<uint16, std::array<uint16, 2>>;
using effect_count = std::map<uint32, int32>;
class attacker_map : public std::unordered_map<uint16, std::pair<card*, uint32>> {
public:
void addcard(card* pcard);
......@@ -257,7 +258,7 @@ public:
void reset(uint32 id, uint32 reset_type);
void reset_effect_count();
void refresh_disable_status();
uint8 refresh_control_status();
std::tuple<uint8, effect*> refresh_control_status();
void count_turn(uint16 ct);
void create_relation(card* target, uint32 reset);
......@@ -294,7 +295,6 @@ public:
void filter_spsummon_procedure_g(uint8 playerid, effect_set* eset);
effect* is_affected_by_effect(int32 code);
effect* is_affected_by_effect(int32 code, card* target);
effect* check_control_effect();
int32 fusion_check(group* fusion_m, card* cg, uint32 chkf, uint8 not_material);
void fusion_select(uint8 playerid, group* fusion_m, card* cg, uint32 chkf, uint8 not_material);
int32 check_fusion_substitute(card* fcard);
......
......@@ -21,7 +21,7 @@ class interpreter;
class duel {
public:
typedef std::set<card*, card_sort> card_set;
using card_set = std::set<card*, card_sort>;
char strbuffer[256];
byte buffer[0x1000];
uint32 bufferlen;
......
......@@ -301,8 +301,8 @@ inline effect_flag operator|(effect_flag flag1, effect_flag flag2)
#define EFFECT_REVERSE_UPDATE 108 //
#define EFFECT_SWAP_AD 109 //
#define EFFECT_SWAP_BASE_AD 110 //
#define EFFECT_SWAP_ATTACK_FINAL 111
#define EFFECT_SWAP_DEFENSE_FINAL 112
//#define EFFECT_SWAP_ATTACK_FINAL 111
//#define EFFECT_SWAP_DEFENSE_FINAL 112
#define EFFECT_ADD_CODE 113 //
#define EFFECT_CHANGE_CODE 114 //
#define EFFECT_ADD_TYPE 115 //
......
......@@ -520,7 +520,7 @@ void field::swap_card(card* pcard1, card* pcard2) {
return swap_card(pcard1, pcard2, pcard1->current.sequence, pcard2->current.sequence);
}
void field::set_control(card* pcard, uint8 playerid, uint16 reset_phase, uint8 reset_count) {
if((core.remove_brainwashing && pcard->is_affected_by_effect(EFFECT_REMOVE_BRAINWASHING)) || pcard->refresh_control_status() == playerid)
if((core.remove_brainwashing && pcard->is_affected_by_effect(EFFECT_REMOVE_BRAINWASHING)) || std::get<uint8>(pcard->refresh_control_status()) == playerid)
return;
effect* peffect = pduel->new_effect();
if(core.reason_effect)
......
......@@ -44,7 +44,7 @@ struct optarget {
int32 op_param;
};
struct chain {
typedef std::unordered_map<uint32, optarget> opmap;
using opmap = std::unordered_map<uint32, optarget>;
uint16 chain_id;
uint8 chain_count;
uint8 triggering_player;
......@@ -68,7 +68,7 @@ struct chain {
};
struct player_info {
typedef std::vector<card*> card_vector;
using card_vector = std::vector<card*>;
int32 lp;
int32 start_count;
int32 draw_count;
......@@ -88,12 +88,12 @@ struct player_info {
card_vector tag_list_extra;
};
struct field_effect {
typedef std::multimap<uint32, effect*> effect_container;
typedef std::unordered_map<effect*, effect_container::iterator> effect_indexer;
typedef std::unordered_map<effect*, effect*> oath_effects;
typedef std::unordered_set<effect*> effect_collection;
typedef std::unordered_map<card*, effect*> gain_effects;
typedef std::unordered_map<effect*, gain_effects> grant_effect_container;
using effect_container = std::multimap<uint32, effect*>;
using effect_indexer = std::unordered_map<effect*, effect_container::iterator>;
using oath_effects = std::unordered_map<effect*, effect*>;
using effect_collection = std::unordered_set<effect*>;
using gain_effects = std::unordered_map<card*, effect*>;
using grant_effect_container = std::unordered_map<effect*, gain_effects>;
effect_container aura_effect;
effect_container ignition_effect;
......@@ -150,23 +150,23 @@ union return_value {
int64 lvalue[8];
};
struct processor {
typedef std::vector<effect*> effect_vector;
typedef std::vector<card*> card_vector;
typedef std::vector<uint32> option_vector;
typedef std::list<card*> card_list;
typedef std::list<tevent> event_list;
typedef std::list<chain> chain_list;
typedef std::map<effect*, chain> instant_f_list;
typedef std::vector<chain> chain_array;
typedef std::list<processor_unit> processor_list;
typedef std::set<card*, card_sort> card_set;
typedef std::set<std::pair<effect*, tevent>> delayed_effect_collection;
using effect_vector = std::vector<effect*>;
using card_vector = std::vector<card*>;
using option_vector = std::vector<uint32>;
using card_list = std::list<card*>;
using event_list = std::list<tevent>;
using chain_list = std::list<chain>;
using instant_f_list = std::map<effect*, chain>;
using chain_array = std::vector<chain>;
using processor_list = std::list<processor_unit>;
using card_set = std::set<card*, card_sort>;
using delayed_effect_collection = std::set<std::pair<effect*, tevent>>;
struct chain_limit_t {
chain_limit_t(int32 f, int32 p): function(f), player(p) {}
int32 function;
int32 player;
};
typedef std::vector<chain_limit_t> chain_limit_list;
using chain_limit_list = std::vector<chain_limit_t>;
processor_list units;
processor_list subunits;
......@@ -335,16 +335,16 @@ struct processor {
};
class field {
public:
typedef std::multimap<uint32, effect*> effect_container;
typedef std::set<card*, card_sort> card_set;
typedef std::vector<effect*> effect_vector;
typedef std::vector<card*> card_vector;
typedef std::list<card*> card_list;
typedef std::list<tevent> event_list;
typedef std::list<chain> chain_list;
typedef std::map<effect*, chain> instant_f_list;
typedef std::vector<chain> chain_array;
typedef std::list<processor_unit> processor_list;
using effect_container = std::multimap<uint32, effect*>;
using card_set = std::set<card*, card_sort>;
using effect_vector = std::vector<effect*>;
using card_vector = std::vector<card*>;
using card_list = std::list<card*>;
using event_list = std::list<tevent>;
using chain_list = std::list<chain>;
using instant_f_list = std::map<effect*, chain>;
using chain_array = std::vector<chain>;
using processor_list = std::list<processor_unit>;
duel* pduel;
player_info player[2];
......
......@@ -17,7 +17,7 @@ class duel;
class group {
public:
typedef std::set<card*, card_sort> card_set;
using card_set = std::set<card*, card_sort>;
int32 ref_handle;
duel* pduel;
card_set container;
......
......@@ -26,8 +26,8 @@ class duel;
class interpreter {
public:
typedef std::unordered_map<int32, lua_State*> coroutine_map;
typedef std::list<std::pair<void*, uint32>> param_list;
using coroutine_map = std::unordered_map<int32, lua_State*>;
using param_list = std::list<std::pair<void*, uint32>>;
duel* pduel;
char msgbuf[64];
......
......@@ -1274,13 +1274,13 @@ int32 field::process_point_event(int16 step, int32 skip_trigger, int32 skip_free
case 0: {
core.select_chains.clear();
core.point_event.splice(core.point_event.end(), core.instant_event);
core.full_event.splice(core.full_event.end(), core.delayed_activate_event);
if(skip_trigger) {
core.units.begin()->step = 7;
return FALSE;
}
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.full_event.splice(core.full_event.end(), core.delayed_activate_event);
core.delayed_quick.clear();
core.delayed_quick_break.swap(core.delayed_quick);
core.current_player = infos.turn_player;
......@@ -1640,9 +1640,9 @@ int32 field::process_quick_effect(int16 step, int32 skip_freechain, uint8 priori
newchain.set_triggering_state(phandler);
newchain.triggering_player = priority;
core.select_chains.push_back(newchain);
core.delayed_quick_tmp.erase(std::make_pair(peffect, ev));
core.delayed_quick_break.erase(std::make_pair(peffect, ev));
}
core.delayed_quick_tmp.erase(std::make_pair(peffect, ev));
core.delayed_quick_break.erase(std::make_pair(peffect, ev));
}
}
}
......@@ -4843,18 +4843,30 @@ int32 field::adjust_step(uint16 step) {
//control
core.control_adjust_set[0].clear();
core.control_adjust_set[1].clear();
card_set reason_cards;
for(uint8 p = 0; p < 2; ++p) {
for(auto& pcard : player[p].list_mzone) {
if(!pcard) continue;
uint8 cur = pcard->current.controler;
uint8 ref = pcard->refresh_control_status();
if(cur != ref && pcard->is_capable_change_control())
auto res = pcard->refresh_control_status();
uint8 ref = std::get<uint8>(res);
effect* peffect = std::get<effect*>(res);
if(cur != ref && pcard->is_capable_change_control()) {
core.control_adjust_set[p].insert(pcard);
if(peffect && (!(peffect->type & EFFECT_TYPE_SINGLE) || peffect->condition))
reason_cards.insert(peffect->get_handler());
}
}
}
if(core.control_adjust_set[0].size() || core.control_adjust_set[1].size()) {
core.re_adjust = TRUE;
add_process(PROCESSOR_CONTROL_ADJUST, 0, 0, 0, 0, 0);
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)
destroy(rcard, 0, REASON_RULE, PLAYER_NONE);
}
}
core.last_control_changed_id = infos.field_id;
return FALSE;
......@@ -4888,7 +4900,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;
add_process(PROCESSOR_CONTROL_ADJUST, 0, 0, 0, 0, 0);
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;
......
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