Commit 41317b62 authored by Chen Bill's avatar Chen Bill Committed by GitHub

replace make_pair with value_type (#696)

* replace make_pair with value_type

* using activity_map

* use unordered_map emplace
parent a6ddb761
......@@ -132,7 +132,7 @@ bool card::check_card_setcode(uint32_t code, uint32_t value) {
}
void card::attacker_map::addcard(card* pcard) {
auto fid = pcard ? pcard->fieldid_r : 0;
auto pr = emplace(fid, std::make_pair(pcard, 0));
auto pr = emplace(fid, mapped_type(pcard, 0));
++pr.first->second.second;
}
uint32_t card::attacker_map::findcard(card* pcard) {
......@@ -2238,12 +2238,12 @@ void card::create_relation(const chain& ch) {
relate_effect.emplace(ch.triggering_effect, ch.chain_id);
}
int32_t card::is_has_relation(const chain& ch) {
if (relate_effect.find(std::make_pair(ch.triggering_effect, ch.chain_id)) != relate_effect.end())
if (relate_effect.find(effect_relation::value_type(ch.triggering_effect, ch.chain_id)) != relate_effect.end())
return TRUE;
return FALSE;
}
void card::release_relation(const chain& ch) {
relate_effect.erase(std::make_pair(ch.triggering_effect, ch.chain_id));
relate_effect.erase(effect_relation::value_type(ch.triggering_effect, ch.chain_id));
}
void card::clear_relate_effect() {
relate_effect.clear();
......@@ -2271,7 +2271,7 @@ void card::release_relation(effect* peffect) {
return;
}
}
relate_effect.erase(std::make_pair(peffect, (uint16_t)0));
relate_effect.erase(effect_relation::value_type(peffect, 0));
}
int32_t card::leave_field_redirect(uint32_t reason) {
effect_set es;
......
......@@ -112,7 +112,7 @@ const material_info null_info;
class card {
public:
struct effect_relation_hash {
inline std::size_t operator()(const std::pair<effect*, uint16_t>& v) const {
std::size_t operator()(const std::pair<effect*, uint16_t>& v) const {
return std::hash<uint16_t>()(v.second);
}
};
......
......@@ -167,15 +167,17 @@ union return_value {
int32_t ivalue[SIZE_IVALUE];
int64_t lvalue[SIZE_LVALUE];
};
using option_vector = std::vector<uint32_t>;
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 delayed_effect_collection = std::set<std::pair<effect*, tevent>>;
using activity_map = std::unordered_map<int32_t, std::pair<int32_t, uint32_t>>; // (counter_id, (counter_filter, count[1]|count[0]))
struct processor {
using option_vector = std::vector<uint32_t>;
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 delayed_effect_collection = std::set<std::pair<effect*, tevent>>;
struct chain_limit_t {
chain_limit_t(int32_t f, int32_t p): function(f), player(p) {}
int32_t function{ 0 };
......@@ -349,24 +351,17 @@ struct processor {
uint8_t conti_player{ PLAYER_NONE };
uint8_t select_deck_sequence_revealed{ FALSE };
uint8_t selecting_player{ PLAYER_NONE };
std::unordered_map<uint32_t, std::pair<uint32_t, uint32_t>> summon_counter;
std::unordered_map<uint32_t, std::pair<uint32_t, uint32_t>> normalsummon_counter;
std::unordered_map<uint32_t, std::pair<uint32_t, uint32_t>> spsummon_counter;
std::unordered_map<uint32_t, std::pair<uint32_t, uint32_t>> flipsummon_counter;
std::unordered_map<uint32_t, std::pair<uint32_t, uint32_t>> attack_counter;
std::unordered_map<uint32_t, std::pair<uint32_t, uint32_t>> chain_counter;
activity_map summon_counter;
activity_map normalsummon_counter;
activity_map spsummon_counter;
activity_map flipsummon_counter;
activity_map attack_counter;
activity_map chain_counter;
processor_list recover_damage_reserve;
effect_vector dec_count_reserve;
};
class field {
public:
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];
card* temp_card{};
......
......@@ -562,7 +562,7 @@ int32_t interpreter::call_coroutine(int32_t f, uint32_t param_count, int32_t* yi
return OPERATION_FAIL;
}
++call_depth;
auto ret = coroutines.emplace(f, std::make_pair(rthread, threadref));
auto ret = coroutines.emplace(f, coroutine_map::mapped_type(rthread, threadref));
it = ret.first;
} else {
if(step == 0) {
......
......@@ -4639,47 +4639,29 @@ int32_t scriptlib::duel_add_custom_activity_counter(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
switch(activity_type) {
case ACTIVITY_SUMMON: {
auto iter = pduel->game_field->core.summon_counter.find(counter_id);
if(iter != pduel->game_field->core.summon_counter.end())
break;
pduel->game_field->core.summon_counter[counter_id] = std::make_pair(counter_filter, 0);
pduel->game_field->core.summon_counter.emplace(counter_id, activity_map::mapped_type(counter_filter, 0));
break;
}
case ACTIVITY_NORMALSUMMON: {
auto iter = pduel->game_field->core.normalsummon_counter.find(counter_id);
if(iter != pduel->game_field->core.normalsummon_counter.end())
break;
pduel->game_field->core.normalsummon_counter[counter_id] = std::make_pair(counter_filter, 0);
pduel->game_field->core.normalsummon_counter.emplace(counter_id, activity_map::mapped_type(counter_filter, 0));
break;
}
case ACTIVITY_SPSUMMON: {
auto iter = pduel->game_field->core.spsummon_counter.find(counter_id);
if(iter != pduel->game_field->core.spsummon_counter.end())
break;
pduel->game_field->core.spsummon_counter[counter_id] = std::make_pair(counter_filter, 0);
pduel->game_field->core.spsummon_counter.emplace(counter_id, activity_map::mapped_type(counter_filter, 0));
break;
}
case ACTIVITY_FLIPSUMMON: {
auto iter = pduel->game_field->core.flipsummon_counter.find(counter_id);
if(iter != pduel->game_field->core.flipsummon_counter.end())
break;
pduel->game_field->core.flipsummon_counter[counter_id] = std::make_pair(counter_filter, 0);
pduel->game_field->core.flipsummon_counter.emplace(counter_id, activity_map::mapped_type(counter_filter, 0));
break;
}
case ACTIVITY_ATTACK: {
auto iter = pduel->game_field->core.attack_counter.find(counter_id);
if(iter != pduel->game_field->core.attack_counter.end())
break;
pduel->game_field->core.attack_counter[counter_id] = std::make_pair(counter_filter, 0);
pduel->game_field->core.attack_counter.emplace(counter_id, activity_map::mapped_type(counter_filter, 0));
break;
}
case ACTIVITY_BATTLE_PHASE:
break;
case ACTIVITY_CHAIN: {
auto iter = pduel->game_field->core.chain_counter.find(counter_id);
if(iter != pduel->game_field->core.chain_counter.end())
break;
pduel->game_field->core.chain_counter[counter_id] = std::make_pair(counter_filter, 0);
pduel->game_field->core.chain_counter.emplace(counter_id, activity_map::mapped_type(counter_filter, 0));
break;
}
default:
......@@ -4693,7 +4675,7 @@ int32_t scriptlib::duel_get_custom_activity_count(lua_State *L) {
int32_t playerid = (int32_t)lua_tointeger(L, 2);
int32_t activity_type = (int32_t)lua_tointeger(L, 3);
duel* pduel = interpreter::get_duel_info(L);
int32_t val = 0;
uint32_t val = 0;
switch(activity_type) {
case ACTIVITY_SUMMON: {
auto iter = pduel->game_field->core.summon_counter.find(counter_id);
......
......@@ -1783,7 +1783,7 @@ int32_t field::process_quick_effect(int16_t step, int32_t skip_freechain, uint8_
chain newchain = core.select_chains[returns.ivalue[0]];
core.new_chains.push_back(newchain);
effect* peffect = newchain.triggering_effect;
core.delayed_quick.erase(std::make_pair(peffect, newchain.evt));
core.delayed_quick.erase(delayed_effect_collection::value_type(peffect, newchain.evt));
peffect->get_handler()->set_status(STATUS_CHAINING, TRUE);
peffect->dec_count(priority);
add_process(PROCESSOR_ADD_CHAIN, 0, 0, 0, 0, 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