Skip to content

Commit

Permalink
use ref in PROCESSOR_SELECT_SYNCHRO (#606)
Browse files Browse the repository at this point in the history
* add interpreter::check_filter

* add lua_State* to filter_matching_card

* add lua_State* to get_release_list

* add lua_State* to get_xyz_material

* add lua_State* to check_tuner_material

* update PROCESSOR_SELECT_SYNCHRO

* use ref in PROCESSOR_SELECT_SYNCHRO

* push pcard in check_tuner_material

* add effect::get_integer_value

* clean up field::check_tuner_material

* always take mg first

* use ref in PROCESSOR_SELECT_SYNCHRO

* remove interpreter::check_matching

* remove Group.ForEach

* use card_set in Duel.SelectSynchroMaterial

* using card_set in global

* using card_vector in global
  • Loading branch information
salix5 committed Jul 27, 2024
1 parent a6f0178 commit a3fe63a
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 221 deletions.
2 changes: 1 addition & 1 deletion card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ void card::xyz_overlay(card_set* materials) {
if(materials->size() == 0)
return;
card_set des, leave_grave, leave_deck;
field::card_vector cv;
card_vector cv;
for(auto& pcard : *materials)
cv.push_back(pcard);
std::sort(cv.begin(), cv.end(), card::card_operation_sort);
Expand Down
5 changes: 3 additions & 2 deletions card.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class effect;
class group;
struct chain;

using card_set = std::set<card*, card_sort>;
using card_vector = std::vector<card*>;

struct card_state {
uint32 code{ 0 };
uint32 code2{ 0 };
Expand Down Expand Up @@ -113,9 +116,7 @@ class card {
return std::hash<uint16>()(v.second);
}
};
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>;
Expand Down
3 changes: 2 additions & 1 deletion duel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class effect;
class field;
class interpreter;

using card_set = std::set<card*, card_sort>;

class duel {
public:
using card_set = std::set<card*, card_sort>;
char strbuffer[256];
std::vector<byte> message_buffer;
interpreter* lua;
Expand Down
3 changes: 3 additions & 0 deletions effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,9 @@ void effect::get_value(effect* peffect, uint32 extraargs, std::vector<int32>* re
result->push_back((int32)value);
}
}
int32 effect::get_integer_value() {
return is_flag(EFFECT_FLAG_FUNC_VALUE) ? 0 : value;
}
int32 effect::check_value_condition(uint32 extraargs) {
if(is_flag(EFFECT_FLAG_FUNC_VALUE)) {
pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE);
Expand Down
1 change: 1 addition & 0 deletions effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class effect {
void get_value(uint32 extraargs, std::vector<int32>* result);
void get_value(card* pcard, uint32 extraargs, std::vector<int32>* result);
void get_value(effect* peffect, uint32 extraargs, std::vector<int32>* result);
int32 get_integer_value();
int32 check_value_condition(uint32 extraargs = 0);
void* get_label_object();
int32 get_speed();
Expand Down
132 changes: 70 additions & 62 deletions field.cpp

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions field.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "common.h"
#include "card.h"
#include "effectset.h"
#include "interpreter.h"
#include <vector>
#include <set>
#include <map>
Expand Down Expand Up @@ -79,7 +80,6 @@ struct chain {
};

struct player_info {
using card_vector = std::vector<card*>;
int32 lp{ 0 };
int32 start_count{ 0 };
int32 draw_count{ 0 };
Expand Down Expand Up @@ -151,12 +151,14 @@ struct processor_unit {
uint32 arg2{ 0 };
uint32 arg3{ 0 };
uint32 arg4{ 0 };
void* ptr1{ nullptr };
void* ptr2{ nullptr };
int32 value1{ 0 };
int32 value2{ 0 };
int32 value3{ 0 };
int32 value4{ 0 };
void* ptr1{ nullptr };
void* ptr2{ nullptr };
void* ptr3{ nullptr };
void* ptr4{ nullptr };
};
constexpr int SIZE_SVALUE = SIZE_RETURN_VALUE / 2;
constexpr int SIZE_IVALUE = SIZE_RETURN_VALUE / 4;
Expand All @@ -169,15 +171,13 @@ union return_value {
};
struct processor {
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) {}
Expand Down Expand Up @@ -364,9 +364,7 @@ struct processor {
class field {
public:
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>;
Expand Down Expand Up @@ -435,19 +433,19 @@ class field {
void filter_affected_cards(effect* peffect, card_set* cset);
void filter_inrange_cards(effect* peffect, card_set* cset);
void filter_player_effect(uint8 playerid, uint32 code, effect_set* eset, uint8 sort = TRUE);
int32 filter_matching_card(int32 findex, uint8 self, uint32 location1, uint32 location2, group* pgroup, card* pexception, group* pexgroup, uint32 extraargs, card** pret = nullptr, int32 fcount = 0, int32 is_target = FALSE);
int32 filter_matching_card(lua_State* L, int32 findex, uint8 self, uint32 location1, uint32 location2, group* pgroup, card* pexception, group* pexgroup, uint32 extraargs, card** pret = nullptr, int32 fcount = 0, int32 is_target = FALSE);
int32 filter_field_card(uint8 self, uint32 location, uint32 location2, group* pgroup);
effect* is_player_affected_by_effect(uint8 playerid, uint32 code);

int32 get_release_list(uint8 playerid, card_set* release_list, card_set* ex_list, card_set* ex_list_oneof, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason);
int32 check_release_list(uint8 playerid, int32 count, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason);
int32 get_release_list(lua_State* L, uint8 playerid, card_set* release_list, card_set* ex_list, card_set* ex_list_oneof, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason);
int32 check_release_list(lua_State* L, uint8 playerid, int32 count, int32 use_con, int32 use_hand, int32 fun, int32 exarg, card* exc, group* exg, uint32 reason);
int32 get_summon_release_list(card* target, card_set* release_list, card_set* ex_list, card_set* ex_list_oneof, group* mg = nullptr, uint32 ex = 0, uint32 releasable = 0xff00ff, uint32 pos = 0x1);
int32 get_summon_count_limit(uint8 playerid);
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 get_xyz_material(card* scard, int32 findex, uint32 lv, int32 maxc, group* mg);
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);
void update_disable_check_list(effect* peffect);
Expand Down Expand Up @@ -479,15 +477,17 @@ class field {
int32 get_must_material_list(uint8 playerid, uint32 limit, card_set* must_list);
int32 check_must_material(group* mg, uint8 playerid, uint32 limit);
void get_synchro_material(uint8 playerid, card_set* material, effect* tuner_limit = nullptr);
int32 check_synchro_material(card* pcard, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg);
int32 check_tuner_material(card* pcard, card* tuner, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg);

//check material
int32 check_synchro_material(lua_State* L, card* pcard, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg);
int32 check_tuner_material(lua_State* L, card* pcard, card* tuner, int32 findex1, int32 findex2, int32 min, int32 max, card* smat, group* mg);
int32 check_other_synchro_material(const card_vector& nsyn, int32 lv, int32 min, int32 max, int32 mcount);
int32 check_tribute(card* pcard, int32 min, int32 max, group* mg, uint8 toplayer, uint32 zone = 0x1f, uint32 releasable = 0xff00ff, uint32 pos = 0x1);
static int32 check_with_sum_limit(const card_vector& mats, int32 acc, int32 index, int32 count, int32 min, int32 max, int32 opmin);
static int32 check_with_sum_limit_m(const card_vector& mats, int32 acc, int32 index, int32 min, int32 max, int32 opmin, int32 must_count);
static int32 check_with_sum_greater_limit(const card_vector& mats, int32 acc, int32 index, int32 opmin);
static int32 check_with_sum_greater_limit_m(const card_vector& mats, int32 acc, int32 index, int32 opmin, int32 must_count);
int32 check_xyz_material(card* pcard, int32 findex, int32 lv, int32 min, int32 max, group* mg);
int32 check_xyz_material(lua_State* L, card* pcard, int32 findex, int32 lv, int32 min, int32 max, group* mg);

int32 is_player_can_draw(uint8 playerid);
int32 is_player_can_discard_deck(uint8 playerid, int32 count);
Expand Down Expand Up @@ -623,7 +623,7 @@ class field {
int32 change_position(uint16 step, group* targets, effect* reason_effect, uint8 reason_player, uint32 enable);
int32 operation_replace(uint16 step, effect* replace_effect, group* targets, card* target, int32 is_destroy);
int32 activate_effect(uint16 step, effect* peffect);
int32 select_synchro_material(int16 step, uint8 playerid, card* pcard, int32 min, int32 max, card* smat, group* mg);
int32 select_synchro_material(int16 step, uint8 playerid, card* pcard, int32 min, int32 max, card* smat, group* mg, int32 filter1, int32 filter2);
int32 select_xyz_material(int16 step, uint8 playerid, uint32 lv, card* pcard, int32 min, int32 max);
int32 select_release_cards(int16 step, uint8 playerid, uint8 cancelable, int32 min, int32 max);
int32 select_tribute_cards(int16 step, card* target, uint8 playerid, uint8 cancelable, int32 min, int32 max, uint8 toplayer, uint32 zone);
Expand Down
3 changes: 2 additions & 1 deletion group.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
class card;
class duel;

using card_set = std::set<card*, card_sort>;

class group {
public:
using card_set = std::set<card*, card_sort>;
duel* pduel;
card_set container;
card_set::iterator it;
Expand Down
28 changes: 14 additions & 14 deletions interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,33 +405,33 @@ int32 interpreter::check_condition(int32 f, uint32 param_count) {
}
return OPERATION_FAIL;
}
int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
if(!findex || lua_isnil(current_state, findex))
int32 interpreter::check_filter(lua_State* L, card* pcard, int32 findex, int32 extraargs) {
if (!findex || lua_isnil(L, findex))
return TRUE;
++no_action;
++call_depth;
luaL_checkstack(current_state, 1 + extraargs, nullptr);
lua_pushvalue(current_state, findex);
interpreter::card2value(current_state, pcard);
for(int32 i = 0; i < extraargs; ++i)
lua_pushvalue(current_state, (int32)(-extraargs - 2));
if (lua_pcall(current_state, 1 + extraargs, 1, 0)) {
sprintf(pduel->strbuffer, "%s", lua_tostring(current_state, -1));
luaL_checkstack(L, 1 + extraargs, nullptr);
lua_pushvalue(L, findex);
card2value(L, pcard);
for (int32 i = 0; i < extraargs; ++i)
lua_pushvalue(L, (int32)(-extraargs - 2));
if (lua_pcall(L, 1 + extraargs, 1, 0)) {
sprintf(pduel->strbuffer, "%s", lua_tostring(L, -1));
handle_message(pduel, 1);
lua_pop(current_state, 1);
lua_pop(L, 1);
--no_action;
--call_depth;
if(call_depth == 0) {
if (call_depth == 0) {
pduel->release_script_group();
pduel->restore_assumes();
}
return OPERATION_FAIL;
}
int32 result = lua_toboolean(current_state, -1);
lua_pop(current_state, 1);
int32 result = lua_toboolean(L, -1);
lua_pop(L, 1);
--no_action;
--call_depth;
if(call_depth == 0) {
if (call_depth == 0) {
pduel->release_script_group();
pduel->restore_assumes();
}
Expand Down
2 changes: 1 addition & 1 deletion interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class interpreter {
int32 call_card_function(card* pcard, const char* f, uint32 param_count, int32 ret_count);
int32 call_code_function(uint32 code, const char* f, uint32 param_count, int32 ret_count);
int32 check_condition(int32 f, uint32 param_count);
int32 check_matching(card* pcard, int32 findex, int32 extraargs);
int32 check_filter(lua_State* L, card* pcard, int32 findex, int32 extraargs);
int32 get_operation_value(card* pcard, int32 findex, int32 extraargs);
int32 get_function_value(int32 f, uint32 param_count);
int32 get_function_value(int32 f, uint32 param_count, std::vector<int32>* result);
Expand Down
16 changes: 8 additions & 8 deletions libcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ int32 scriptlib::card_get_linked_group(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
card::card_set cset;
card_set cset;
pcard->get_linked_cards(&cset);
group* pgroup = pcard->pduel->new_group(cset);
interpreter::group2value(L, pgroup);
Expand All @@ -421,7 +421,7 @@ int32 scriptlib::card_get_linked_group_count(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
card::card_set cset;
card_set cset;
pcard->get_linked_cards(&cset);
lua_pushinteger(L, cset.size());
return 1;
Expand All @@ -444,7 +444,7 @@ int32 scriptlib::card_get_mutual_linked_group(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**)lua_touserdata(L, 1);
card::card_set cset;
card_set cset;
pcard->get_mutual_linked_cards(&cset);
group* pgroup = pcard->pduel->new_group(cset);
interpreter::group2value(L, pgroup);
Expand All @@ -454,7 +454,7 @@ int32 scriptlib::card_get_mutual_linked_group_count(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**)lua_touserdata(L, 1);
card::card_set cset;
card_set cset;
pcard->get_mutual_linked_cards(&cset);
lua_pushinteger(L, cset.size());
return 1;
Expand Down Expand Up @@ -491,7 +491,7 @@ 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);
card::card_set cset;
card_set cset;
pcard->get_column_cards(&cset);
group* pgroup = pcard->pduel->new_group(cset);
interpreter::group2value(L, pgroup);
Expand All @@ -501,7 +501,7 @@ 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);
card::card_set cset;
card_set cset;
pcard->get_column_cards(&cset);
lua_pushinteger(L, cset.size());
return 1;
Expand Down Expand Up @@ -2556,7 +2556,7 @@ int32 scriptlib::card_is_chain_attackable(lua_State *L) {
lua_pushboolean(L, 0);
return 1;
}
field::card_vector cv;
card_vector cv;
pduel->game_field->get_attack_target(attacker, &cv, TRUE);
if(cv.size() == 0 && (monsteronly || attacker->direct_attackable == 0))
lua_pushboolean(L, 0);
Expand Down Expand Up @@ -3281,7 +3281,7 @@ int32 scriptlib::card_get_attackable_target(lua_State *L) {
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
duel* pduel = pcard->pduel;
field::card_vector targets;
card_vector targets;
uint8 chain_attack = FALSE;
if(pduel->game_field->core.chain_attacker_id == pcard->fieldid)
chain_attack = TRUE;
Expand Down
Loading

0 comments on commit a3fe63a

Please sign in to comment.