Commit d595155d authored by wind2009's avatar wind2009

Merge remote-tracking branch 'upstream/master'

parents da075384 9da90b8d
#ifndef CORE_BUFFER_H #ifndef CORE_BUFFER_H
#define CORE_BUFFER_H #define CORE_BUFFER_H
#include <cstdio>
#include <cstring> #include <cstring>
#include <vector> #include <vector>
...@@ -21,7 +22,7 @@ inline void buffer_write_block(unsigned char*& p, const void* src, size_t size) ...@@ -21,7 +22,7 @@ inline void buffer_write_block(unsigned char*& p, const void* src, size_t size)
} }
template<typename T> template<typename T>
inline void buffer_write(unsigned char*& p, T value) { inline void buffer_write(unsigned char*& p, T value) {
buffer_write_block(p, &value,sizeof(T)); buffer_write_block(p, &value, sizeof(T));
} }
inline void vector_write_block(std::vector<unsigned char>& buffer, const void* src, size_t size) { inline void vector_write_block(std::vector<unsigned char>& buffer, const void* src, size_t size) {
...@@ -34,4 +35,11 @@ inline void vector_write(std::vector<unsigned char>& buffer, T value) { ...@@ -34,4 +35,11 @@ inline void vector_write(std::vector<unsigned char>& buffer, T value) {
vector_write_block(buffer, &value, sizeof(T)); vector_write_block(buffer, &value, sizeof(T));
} }
inline void vector_fread(std::vector<unsigned char>& buffer, FILE* fp) {
unsigned char temp[4096]{};
while (size_t len = std::fread(temp, 1, sizeof temp, fp))
vector_write_block(buffer, temp, len);
std::fclose(fp);
}
#endif // !CORE_BUFFER_H #endif // !CORE_BUFFER_H
...@@ -15,14 +15,6 @@ ...@@ -15,14 +15,6 @@
#include "buffer.h" #include "buffer.h"
#include <algorithm> #include <algorithm>
const std::unordered_map<uint32, uint32> card::second_code = {
{CARD_MARINE_DOLPHIN, 17955766u},
{CARD_TWINKLE_MOSS, 17732278u},
{CARD_TIMAEUS, 10000050u},
{CARD_CRITIAS, 10000060u},
{CARD_HERMOS, 10000070u}
};
bool card_sort::operator()(card* const& c1, card* const& c2) const { bool card_sort::operator()(card* const& c1, card* const& c2) const {
return c1->cardid < c2->cardid; return c1->cardid < c2->cardid;
} }
...@@ -2611,6 +2603,13 @@ void card::filter_effect_container(const effect_container& container, uint32 cod ...@@ -2611,6 +2603,13 @@ void card::filter_effect_container(const effect_container& container, uint32 cod
eset.add_item(it->second); eset.add_item(it->second);
} }
} }
void card::filter_effect_container(const effect_container& container, uint32 code, effect_filter f, effect_collection& eset) {
auto rg = container.equal_range(code);
for (auto it = rg.first; it != rg.second; ++it) {
if (f(this, it->second))
eset.insert(it->second);
}
}
void card::filter_effect(uint32 code, effect_set* eset, uint8 sort) { void card::filter_effect(uint32 code, effect_set* eset, uint8 sort) {
filter_effect_container(single_effect, code, default_single_filter, *eset); filter_effect_container(single_effect, code, default_single_filter, *eset);
for (const auto& pcard : equiping_cards) for (const auto& pcard : equiping_cards)
...@@ -2736,11 +2735,11 @@ int32 card::filter_summon_procedure(uint8 playerid, effect_set* peset, uint8 ign ...@@ -2736,11 +2735,11 @@ int32 card::filter_summon_procedure(uint8 playerid, effect_set* peset, uint8 ign
effect_set extra_count; effect_set extra_count;
filter_effect(EFFECT_EXTRA_SUMMON_COUNT, &extra_count); filter_effect(EFFECT_EXTRA_SUMMON_COUNT, &extra_count);
for(int32 i = 0; i < extra_count.size(); ++i) { for(int32 i = 0; i < extra_count.size(); ++i) {
std::vector<int32> retval; std::vector<lua_Integer> retval;
extra_count[i]->get_value(this, 0, &retval); extra_count[i]->get_value(this, 0, retval);
int32 new_min = retval.size() > 0 ? retval[0] : 0; int32 new_min = retval.size() > 0 ? static_cast<int32>(retval[0]) : 0;
int32 new_zone = retval.size() > 1 ? retval[1] : 0x1f; uint32 new_zone = retval.size() > 1 ? static_cast<uint32>(retval[1]) : 0x1f;
int32 releasable = retval.size() > 2 ? (retval[2] < 0 ? 0xff00ff + retval[2] : retval[2]) : 0xff00ff; int32 releasable = retval.size() > 2 ? (retval[2] < 0 ? 0xff00ff + static_cast<int32>(retval[2]) : static_cast<int32>(retval[2])) : 0xff00ff;
if(new_min < min) if(new_min < min)
new_min = min; new_min = min;
new_zone &= zone; new_zone &= zone;
...@@ -2769,12 +2768,12 @@ int32 card::check_summon_procedure(effect* proc, uint8 playerid, uint8 ignore_co ...@@ -2769,12 +2768,12 @@ int32 card::check_summon_procedure(effect* proc, uint8 playerid, uint8 ignore_co
effect_set eset; effect_set eset;
filter_effect(EFFECT_EXTRA_SUMMON_COUNT, &eset); filter_effect(EFFECT_EXTRA_SUMMON_COUNT, &eset);
for(int32 i = 0; i < eset.size(); ++i) { for(int32 i = 0; i < eset.size(); ++i) {
std::vector<int32> retval; std::vector<lua_Integer> retval;
eset[i]->get_value(this, 0, &retval); eset[i]->get_value(this, 0, retval);
int32 new_min_tribute = retval.size() > 0 ? retval[0] : 0; int32 new_min_tribute = retval.size() > 0 ? static_cast<int32>(retval[0]) : 0;
int32 new_zone = retval.size() > 1 ? retval[1] : 0x1f; uint32 new_zone = retval.size() > 1 ? static_cast<uint32>(retval[1]) : 0x1f;
int32 releasable = retval.size() > 2 ? (retval[2] < 0 ? 0xff00ff + retval[2] : retval[2]) : 0xff00ff; int32 releasable = retval.size() > 2 ? (retval[2] < 0 ? 0xff00ff + static_cast<int32>(retval[2]) : static_cast<int32>(retval[2])) : 0xff00ff;
if(new_min_tribute < (int32)min_tribute) if(new_min_tribute < min_tribute)
new_min_tribute = min_tribute; new_min_tribute = min_tribute;
new_zone &= zone; new_zone &= zone;
if(is_summonable(proc, new_min_tribute, new_zone, releasable)) if(is_summonable(proc, new_min_tribute, new_zone, releasable))
...@@ -2819,11 +2818,11 @@ int32 card::filter_set_procedure(uint8 playerid, effect_set* peset, uint8 ignore ...@@ -2819,11 +2818,11 @@ int32 card::filter_set_procedure(uint8 playerid, effect_set* peset, uint8 ignore
effect_set extra_count; effect_set extra_count;
filter_effect(EFFECT_EXTRA_SET_COUNT, &extra_count); filter_effect(EFFECT_EXTRA_SET_COUNT, &extra_count);
for(int32 i = 0; i < extra_count.size(); ++i) { for(int32 i = 0; i < extra_count.size(); ++i) {
std::vector<int32> retval; std::vector<lua_Integer> retval;
extra_count[i]->get_value(this, 0, &retval); extra_count[i]->get_value(this, 0, retval);
int32 new_min = retval.size() > 0 ? retval[0] : 0; int32 new_min = retval.size() > 0 ? static_cast<int32>(retval[0]) : 0;
int32 new_zone = retval.size() > 1 ? retval[1] : 0x1f; uint32 new_zone = retval.size() > 1 ? static_cast<uint32>(retval[1]) : 0x1f;
int32 releasable = retval.size() > 2 ? (retval[2] < 0 ? 0xff00ff + retval[2] : retval[2]) : 0xff00ff; int32 releasable = retval.size() > 2 ? (retval[2] < 0 ? 0xff00ff + static_cast<int32>(retval[2]) : static_cast<int32>(retval[2])) : 0xff00ff;
if(new_min < min) if(new_min < min)
new_min = min; new_min = min;
new_zone &= zone; new_zone &= zone;
...@@ -2849,12 +2848,12 @@ int32 card::check_set_procedure(effect* proc, uint8 playerid, uint8 ignore_count ...@@ -2849,12 +2848,12 @@ int32 card::check_set_procedure(effect* proc, uint8 playerid, uint8 ignore_count
effect_set eset; effect_set eset;
filter_effect(EFFECT_EXTRA_SET_COUNT, &eset); filter_effect(EFFECT_EXTRA_SET_COUNT, &eset);
for(int32 i = 0; i < eset.size(); ++i) { for(int32 i = 0; i < eset.size(); ++i) {
std::vector<int32> retval; std::vector<lua_Integer> retval;
eset[i]->get_value(this, 0, &retval); eset[i]->get_value(this, 0, retval);
int32 new_min_tribute = retval.size() > 0 ? retval[0] : 0; int32 new_min_tribute = retval.size() > 0 ? static_cast<int32>(retval[0]) : 0;
int32 new_zone = retval.size() > 1 ? retval[1] : 0x1f; uint32 new_zone = retval.size() > 1 ? static_cast<uint32>(retval[1]) : 0x1f;
int32 releasable = retval.size() > 2 ? (retval[2] < 0 ? 0xff00ff + retval[2] : retval[2]) : 0xff00ff; int32 releasable = retval.size() > 2 ? (retval[2] < 0 ? 0xff00ff + static_cast<int32>(retval[2]) : static_cast<int32>(retval[2])) : 0xff00ff;
if(new_min_tribute < (int32)min_tribute) if(new_min_tribute < min_tribute)
new_min_tribute = min_tribute; new_min_tribute = min_tribute;
new_zone &= zone; new_zone &= zone;
if(is_summonable(proc, new_min_tribute, new_zone, releasable)) if(is_summonable(proc, new_min_tribute, new_zone, releasable))
...@@ -2865,12 +2864,11 @@ int32 card::check_set_procedure(effect* proc, uint8 playerid, uint8 ignore_count ...@@ -2865,12 +2864,11 @@ int32 card::check_set_procedure(effect* proc, uint8 playerid, uint8 ignore_count
return FALSE; return FALSE;
} }
void card::filter_spsummon_procedure(uint8 playerid, effect_set* peset, uint32 summon_type, material_info info) { void card::filter_spsummon_procedure(uint8 playerid, effect_set* peset, uint32 summon_type, material_info info) {
auto pr = field_effect.equal_range(EFFECT_SPSUMMON_PROC); effect_collection proc_set;
uint8 toplayer; filter_effect_container(field_effect, EFFECT_SPSUMMON_PROC, accept_filter, proc_set);
uint8 topos; for (auto& peffect : proc_set) {
for(auto eit = pr.first; eit != pr.second;) { uint8 toplayer{};
effect* peffect = eit->second; uint8 topos{};
++eit;
if(peffect->is_flag(EFFECT_FLAG_SPSUM_PARAM)) { if(peffect->is_flag(EFFECT_FLAG_SPSUM_PARAM)) {
topos = (uint8)peffect->s_range; topos = (uint8)peffect->s_range;
if(peffect->o_range == 0) if(peffect->o_range == 0)
...@@ -2894,10 +2892,9 @@ void card::filter_spsummon_procedure(uint8 playerid, effect_set* peset, uint32 s ...@@ -2894,10 +2892,9 @@ void card::filter_spsummon_procedure(uint8 playerid, effect_set* peset, uint32 s
} }
} }
void card::filter_spsummon_procedure_g(uint8 playerid, effect_set* peset) { void card::filter_spsummon_procedure_g(uint8 playerid, effect_set* peset) {
auto pr = field_effect.equal_range(EFFECT_SPSUMMON_PROC_G); effect_collection proc_set;
for(auto eit = pr.first; eit != pr.second;) { filter_effect_container(field_effect, EFFECT_SPSUMMON_PROC_G, accept_filter, proc_set);
effect* peffect = eit->second; for (auto& peffect : proc_set) {
++eit;
if(!peffect->is_available() || !peffect->check_count_limit(playerid)) if(!peffect->is_available() || !peffect->check_count_limit(playerid))
continue; continue;
if(current.controler != playerid && !peffect->is_flag(EFFECT_FLAG_BOTH_SIDE)) if(current.controler != playerid && !peffect->is_flag(EFFECT_FLAG_BOTH_SIDE))
...@@ -3395,10 +3392,10 @@ int32 card::get_summon_tribute_count() { ...@@ -3395,10 +3392,10 @@ int32 card::get_summon_tribute_count() {
for(int32 i = 0; i < eset.size(); ++i) { for(int32 i = 0; i < eset.size(); ++i) {
if(eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) && eset[i]->count_limit == 0) if(eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) && eset[i]->count_limit == 0)
continue; continue;
std::vector<int32> retval; std::vector<lua_Integer> retval;
eset[i]->get_value(this, 0, &retval); eset[i]->get_value(this, 0, retval);
int32 dec = retval.size() > 0 ? retval[0] : 0; int32 dec = retval.size() > 0 ? static_cast<int32>(retval[0]) : 0;
int32 effect_code = retval.size() > 1 ? retval[1] : 0; int32 effect_code = retval.size() > 1 ? static_cast<int32>(retval[1]) : 0;
if(effect_code > 0) { if(effect_code > 0) {
auto it = std::find(duplicate.begin(), duplicate.end(), effect_code); auto it = std::find(duplicate.begin(), duplicate.end(), effect_code);
if(it == duplicate.end()) if(it == duplicate.end())
...@@ -3428,10 +3425,10 @@ int32 card::get_set_tribute_count() { ...@@ -3428,10 +3425,10 @@ int32 card::get_set_tribute_count() {
for(int32 i = 0; i < eset.size(); ++i) { for(int32 i = 0; i < eset.size(); ++i) {
if(eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) && eset[i]->count_limit == 0) if(eset[i]->is_flag(EFFECT_FLAG_COUNT_LIMIT) && eset[i]->count_limit == 0)
continue; continue;
std::vector<int32> retval; std::vector<lua_Integer> retval;
eset[i]->get_value(this, 0, &retval); eset[i]->get_value(this, 0, retval);
int32 dec = retval.size() > 0 ? retval[0] : 0; int32 dec = retval.size() > 0 ? static_cast<int32>(retval[0]) : 0;
int32 effect_code = retval.size() > 1 ? retval[1] : 0; int32 effect_code = retval.size() > 1 ? static_cast<int32>(retval[1]) : 0;
if(effect_code > 0) { if(effect_code > 0) {
auto it = std::find(duplicate.begin(), duplicate.end(), effect_code); auto it = std::find(duplicate.begin(), duplicate.end(), effect_code);
if(it == duplicate.end()) if(it == duplicate.end())
......
...@@ -109,12 +109,6 @@ struct material_info { ...@@ -109,12 +109,6 @@ struct material_info {
}; };
const material_info null_info; const material_info null_info;
constexpr uint32 CARD_MARINE_DOLPHIN = 78734254;
constexpr uint32 CARD_TWINKLE_MOSS = 13857930;
constexpr uint32 CARD_TIMAEUS = 1784686;
constexpr uint32 CARD_CRITIAS = 11082056;
constexpr uint32 CARD_HERMOS = 46232525;
class card { class card {
public: public:
struct effect_relation_hash { struct effect_relation_hash {
...@@ -149,7 +143,6 @@ public: ...@@ -149,7 +143,6 @@ public:
uint8 location{ 0 }; uint8 location{ 0 };
uint8 sequence{ 0 }; uint8 sequence{ 0 };
}; };
static const std::unordered_map<uint32, uint32> second_code;
int32 ref_handle; int32 ref_handle;
duel* pduel; duel* pduel;
...@@ -327,6 +320,7 @@ public: ...@@ -327,6 +320,7 @@ public:
template<typename T> template<typename T>
void filter_effect_container(const effect_container& container, uint32 code, effect_filter f, T& eset); void filter_effect_container(const effect_container& container, uint32 code, effect_filter f, T& eset);
void filter_effect_container(const effect_container& container, uint32 code, effect_filter f, effect_collection& eset);
void filter_effect(uint32 code, effect_set* eset, uint8 sort = TRUE); void filter_effect(uint32 code, effect_set* eset, uint8 sort = TRUE);
void filter_single_continuous_effect(uint32 code, effect_set* eset, uint8 sort = TRUE); void filter_single_continuous_effect(uint32 code, effect_set* eset, uint8 sort = TRUE);
void filter_self_effect(uint32 code, effect_set* eset, uint8 sort = TRUE); void filter_self_effect(uint32 code, effect_set* eset, uint8 sort = TRUE);
......
#ifndef CARD_DATA_H_ #ifndef CARD_DATA_H_
#define CARD_DATA_H_ #define CARD_DATA_H_
#include <unordered_map>
#include "common.h" #include "common.h"
constexpr int CARD_ARTWORK_VERSIONS_OFFSET = 20; constexpr int CARD_ARTWORK_VERSIONS_OFFSET = 20;
constexpr int SIZE_SETCODE = 16; constexpr int SIZE_SETCODE = 16;
constexpr int CARD_BLACK_LUSTER_SOLDIER2 = 5405695; constexpr uint32 CARD_BLACK_LUSTER_SOLDIER2 = 5405695;
//double name
constexpr uint32 CARD_MARINE_DOLPHIN = 78734254;
constexpr uint32 CARD_TWINKLE_MOSS = 13857930;
constexpr uint32 CARD_TIMAEUS = 1784686;
constexpr uint32 CARD_CRITIAS = 11082056;
constexpr uint32 CARD_HERMOS = 46232525;
const std::unordered_map<uint32, uint32> second_code = {
{CARD_MARINE_DOLPHIN, 17955766u},
{CARD_TWINKLE_MOSS, 17732278u},
{CARD_TIMAEUS, 10000050u},
{CARD_CRITIAS, 10000060u},
{CARD_HERMOS, 10000070u},
};
struct card_data { struct card_data {
uint32 code{}; uint32 code{};
......
...@@ -51,7 +51,7 @@ void duel::clear() { ...@@ -51,7 +51,7 @@ void duel::clear() {
card* duel::new_card(uint32 code) { card* duel::new_card(uint32 code) {
card* pcard = new card(this); card* pcard = new card(this);
cards.insert(pcard); cards.insert(pcard);
if(code) if (code != TEMP_CARD_ID)
::read_card(code, &(pcard->data)); ::read_card(code, &(pcard->data));
pcard->data.code = code; pcard->data.code = code;
lua->register_card(pcard); lua->register_card(pcard);
......
...@@ -697,7 +697,7 @@ int32 effect::get_value(uint32 extraargs) { ...@@ -697,7 +697,7 @@ int32 effect::get_value(uint32 extraargs) {
return res; return res;
} else { } else {
pduel->lua->params.clear(); pduel->lua->params.clear();
return (int32)value; return value;
} }
} }
int32 effect::get_value(card* pcard, uint32 extraargs) { int32 effect::get_value(card* pcard, uint32 extraargs) {
...@@ -708,7 +708,7 @@ int32 effect::get_value(card* pcard, uint32 extraargs) { ...@@ -708,7 +708,7 @@ int32 effect::get_value(card* pcard, uint32 extraargs) {
return res; return res;
} else { } else {
pduel->lua->params.clear(); pduel->lua->params.clear();
return (int32)value; return value;
} }
} }
int32 effect::get_value(effect* peffect, uint32 extraargs) { int32 effect::get_value(effect* peffect, uint32 extraargs) {
...@@ -719,36 +719,36 @@ int32 effect::get_value(effect* peffect, uint32 extraargs) { ...@@ -719,36 +719,36 @@ int32 effect::get_value(effect* peffect, uint32 extraargs) {
return res; return res;
} else { } else {
pduel->lua->params.clear(); pduel->lua->params.clear();
return (int32)value; return value;
} }
} }
void effect::get_value(uint32 extraargs, std::vector<int32>* result) { void effect::get_value(uint32 extraargs, std::vector<lua_Integer>& result) {
if(is_flag(EFFECT_FLAG_FUNC_VALUE)) { if(is_flag(EFFECT_FLAG_FUNC_VALUE)) {
pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE); pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE);
pduel->lua->get_function_value(value, 1 + extraargs, result); pduel->lua->get_function_value(value, 1 + extraargs, result);
} else { } else {
pduel->lua->params.clear(); pduel->lua->params.clear();
result->push_back((int32)value); result.push_back(value);
} }
} }
void effect::get_value(card* pcard, uint32 extraargs, std::vector<int32>* result) { void effect::get_value(card* pcard, uint32 extraargs, std::vector<lua_Integer>& result) {
if(is_flag(EFFECT_FLAG_FUNC_VALUE)) { if(is_flag(EFFECT_FLAG_FUNC_VALUE)) {
pduel->lua->add_param(pcard, PARAM_TYPE_CARD, TRUE); pduel->lua->add_param(pcard, PARAM_TYPE_CARD, TRUE);
pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE); pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE);
pduel->lua->get_function_value(value, 2 + extraargs, result); pduel->lua->get_function_value(value, 2 + extraargs, result);
} else { } else {
pduel->lua->params.clear(); pduel->lua->params.clear();
result->push_back((int32)value); result.push_back(value);
} }
} }
void effect::get_value(effect* peffect, uint32 extraargs, std::vector<int32>* result) { void effect::get_value(effect* peffect, uint32 extraargs, std::vector<lua_Integer>& result) {
if(is_flag(EFFECT_FLAG_FUNC_VALUE)) { if(is_flag(EFFECT_FLAG_FUNC_VALUE)) {
pduel->lua->add_param(peffect, PARAM_TYPE_EFFECT, TRUE); pduel->lua->add_param(peffect, PARAM_TYPE_EFFECT, TRUE);
pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE); pduel->lua->add_param(this, PARAM_TYPE_EFFECT, TRUE);
pduel->lua->get_function_value(value, 2 + extraargs, result); pduel->lua->get_function_value(value, 2 + extraargs, result);
} else { } else {
pduel->lua->params.clear(); pduel->lua->params.clear();
result->push_back((int32)value); result.push_back(value);
} }
} }
int32 effect::get_integer_value() { int32 effect::get_integer_value() {
...@@ -761,7 +761,7 @@ int32 effect::check_value_condition(uint32 extraargs) { ...@@ -761,7 +761,7 @@ int32 effect::check_value_condition(uint32 extraargs) {
return res; return res;
} else { } else {
pduel->lua->params.clear(); pduel->lua->params.clear();
return (int32)value; return value;
} }
} }
void* effect::get_label_object() { void* effect::get_label_object() {
......
...@@ -22,6 +22,7 @@ struct effect_set; ...@@ -22,6 +22,7 @@ struct effect_set;
struct effect_set_v; struct effect_set_v;
enum effect_flag : uint64; enum effect_flag : uint64;
enum effect_flag2 : uint64; enum effect_flag2 : uint64;
enum effect_category :uint64;
enum code_type : int32; enum code_type : int32;
bool is_continuous_event(uint32 code); bool is_continuous_event(uint32 code);
...@@ -98,9 +99,9 @@ public: ...@@ -98,9 +99,9 @@ public:
int32 get_value(uint32 extraargs = 0); int32 get_value(uint32 extraargs = 0);
int32 get_value(card* pcard, uint32 extraargs = 0); int32 get_value(card* pcard, uint32 extraargs = 0);
int32 get_value(effect* peffect, uint32 extraargs = 0); int32 get_value(effect* peffect, uint32 extraargs = 0);
void get_value(uint32 extraargs, std::vector<int32>* result); void get_value(uint32 extraargs, std::vector<lua_Integer>& result);
void get_value(card* pcard, uint32 extraargs, std::vector<int32>* result); void get_value(card* pcard, uint32 extraargs, std::vector<lua_Integer>& result);
void get_value(effect* peffect, uint32 extraargs, std::vector<int32>* result); void get_value(effect* peffect, uint32 extraargs, std::vector<lua_Integer>& result);
int32 get_integer_value(); int32 get_integer_value();
int32 check_value_condition(uint32 extraargs = 0); int32 check_value_condition(uint32 extraargs = 0);
void* get_label_object(); void* get_label_object();
...@@ -214,6 +215,9 @@ enum effect_flag : uint64 { ...@@ -214,6 +215,9 @@ enum effect_flag : uint64 {
EFFECT_FLAG_ACTIVATE_CONDITION = 0x20000000, EFFECT_FLAG_ACTIVATE_CONDITION = 0x20000000,
// EFFECT_FLAG_CVAL_CHECK = 0x40000000, // EFFECT_FLAG_CVAL_CHECK = 0x40000000,
EFFECT_FLAG_IMMEDIATELY_APPLY = 0x80000000, EFFECT_FLAG_IMMEDIATELY_APPLY = 0x80000000,
EFFECT_FLAG_COIN = 0x100000000,
EFFECT_FLAG_DICE = 0x200000000,
EFFECT_FLAG_FUSION_SUMMON = 0x400000000,
}; };
enum effect_flag2 : uint64 { enum effect_flag2 : uint64 {
EFFECT_FLAG2_REPEAT_UPDATE = 0x0001, EFFECT_FLAG2_REPEAT_UPDATE = 0x0001,
...@@ -222,9 +226,52 @@ enum effect_flag2 : uint64 { ...@@ -222,9 +226,52 @@ enum effect_flag2 : uint64 {
EFFECT_FLAG2_OPTION = 0x0008, EFFECT_FLAG2_OPTION = 0x0008,
}; };
constexpr effect_flag operator|(effect_flag flag1, effect_flag flag2) { constexpr effect_flag operator|(effect_flag flag1, effect_flag flag2) {
return static_cast<effect_flag>(static_cast<uint32>(flag1) | static_cast<uint32>(flag2)); return static_cast<effect_flag>(static_cast<uint64>(flag1) | static_cast<uint64>(flag2));
} }
constexpr uint32 INTERNAL_FLAGS = EFFECT_FLAG_INITIAL | EFFECT_FLAG_COPY | EFFECT_FLAG_FUNC_VALUE | EFFECT_FLAG_COUNT_LIMIT | EFFECT_FLAG_FIELD_ONLY | EFFECT_FLAG_ABSOLUTE_TARGET; constexpr uint64 INTERNAL_FLAGS = EFFECT_FLAG_INITIAL | EFFECT_FLAG_COPY | EFFECT_FLAG_FUNC_VALUE | EFFECT_FLAG_COUNT_LIMIT | EFFECT_FLAG_FIELD_ONLY | EFFECT_FLAG_ABSOLUTE_TARGET;
//Category
enum effect_category : uint64 {
CATEGORY_DESTROY = 0x1,
CATEGORY_RELEASE = 0x2,
CATEGORY_REMOVE = 0x4,
CATEGORY_TOHAND = 0x8,
CATEGORY_TODECK = 0x10,
CATEGORY_TOGRAVE = 0x20,
CATEGORY_DECKDES = 0x40,
CATEGORY_HANDES = 0x80,
CATEGORY_SUMMON = 0x100,
CATEGORY_SPECIAL_SUMMON = 0x200,
CATEGORY_TOKEN = 0x400,
CATEGORY_GRAVE_ACTION = 0x800,
CATEGORY_POSITION = 0x1000,
CATEGORY_CONTROL = 0x2000,
CATEGORY_DISABLE = 0x4000,
CATEGORY_DISABLE_SUMMON = 0x8000,
CATEGORY_DRAW = 0x10000,
CATEGORY_SEARCH = 0x20000,
CATEGORY_EQUIP = 0x40000,
CATEGORY_DAMAGE = 0x80000,
CATEGORY_RECOVER = 0x100000,
CATEGORY_ATKCHANGE = 0x200000,
CATEGORY_DEFCHANGE = 0x400000,
CATEGORY_COUNTER = 0x800000,
CATEGORY_COIN = 0x1000000,
CATEGORY_DICE = 0x2000000,
CATEGORY_LEAVE_GRAVE = 0x4000000,
CATEGORY_GRAVE_SPSUMMON = 0x8000000,
CATEGORY_NEGATE = 0x10000000,
CATEGORY_ANNOUNCE = 0x20000000,
CATEGORY_FUSION_SUMMON = 0x40000000,
CATEGORY_TOEXTRA = 0x80000000,
};
const std::map<uint64, uint64> category_checklist{
{CATEGORY_COIN, EFFECT_FLAG_COIN},
{CATEGORY_DICE, EFFECT_FLAG_DICE},
{CATEGORY_FUSION_SUMMON, EFFECT_FLAG_FUSION_SUMMON},
};
//========== Codes ========== //========== Codes ==========
#define EFFECT_IMMUNE_EFFECT 1 // #define EFFECT_IMMUNE_EFFECT 1 //
#define EFFECT_DISABLE 2 // #define EFFECT_DISABLE 2 //
......
...@@ -50,7 +50,9 @@ interpreter::interpreter(duel* pd): coroutines(256) { ...@@ -50,7 +50,9 @@ interpreter::interpreter(duel* pd): coroutines(256) {
interpreter::~interpreter() { interpreter::~interpreter() {
lua_close(lua_state); lua_close(lua_state);
} }
int32 interpreter::register_card(card *pcard) { void interpreter::register_card(card *pcard) {
if (!pcard)
return;
//create a card in by userdata //create a card in by userdata
luaL_checkstack(lua_state, 1, nullptr); luaL_checkstack(lua_state, 1, nullptr);
card ** ppcard = (card**) lua_newuserdata(lua_state, sizeof(card*)); //+1 userdata card ** ppcard = (card**) lua_newuserdata(lua_state, sizeof(card*)); //+1 userdata
...@@ -65,14 +67,13 @@ int32 interpreter::register_card(card *pcard) { ...@@ -65,14 +67,13 @@ int32 interpreter::register_card(card *pcard) {
lua_setmetatable(current_state, -2); //-1 lua_setmetatable(current_state, -2); //-1
lua_pop(current_state, 1); //-1 lua_pop(current_state, 1); //-1
//Initial //Initial
if(pcard->data.code && is_load_script(pcard->data)) { if(is_load_script(pcard->data)) {
pcard->set_status(STATUS_INITIALIZING, TRUE); pcard->set_status(STATUS_INITIALIZING, TRUE);
add_param(pcard, PARAM_TYPE_CARD); add_param(pcard, PARAM_TYPE_CARD);
call_card_function(pcard, "initial_effect", 1, 0); call_card_function(pcard, "initial_effect", 1, 0);
pcard->set_status(STATUS_INITIALIZING, FALSE); pcard->set_status(STATUS_INITIALIZING, FALSE);
} }
pcard->cardid = pduel->game_field->infos.card_id++; pcard->cardid = pduel->game_field->infos.card_id++;
return OPERATION_SUCCESS;
} }
void interpreter::register_effect(effect *peffect) { void interpreter::register_effect(effect *peffect) {
if (!peffect) if (!peffect)
...@@ -505,7 +506,7 @@ int32 interpreter::get_function_value(int32 f, uint32 param_count) { ...@@ -505,7 +506,7 @@ int32 interpreter::get_function_value(int32 f, uint32 param_count) {
} }
return OPERATION_FAIL; return OPERATION_FAIL;
} }
int32 interpreter::get_function_value(int32 f, uint32 param_count, std::vector<int32>* result) { int32 interpreter::get_function_value(int32 f, uint32 param_count, std::vector<lua_Integer>& result) {
int32 is_success = OPERATION_FAIL; int32 is_success = OPERATION_FAIL;
if(!f) { if(!f) {
params.clear(); params.clear();
...@@ -517,14 +518,14 @@ int32 interpreter::get_function_value(int32 f, uint32 param_count, std::vector<i ...@@ -517,14 +518,14 @@ int32 interpreter::get_function_value(int32 f, uint32 param_count, std::vector<i
if (call_function(f, param_count, LUA_MULTRET)) { if (call_function(f, param_count, LUA_MULTRET)) {
int32 stack_newtop = lua_gettop(current_state); int32 stack_newtop = lua_gettop(current_state);
for (int32 index = stack_top + 1; index <= stack_newtop; ++index) { for (int32 index = stack_top + 1; index <= stack_newtop; ++index) {
int32 return_value = 0; lua_Integer return_value = 0;
if(lua_isboolean(current_state, index)) if(lua_isboolean(current_state, index))
return_value = lua_toboolean(current_state, index); return_value = lua_toboolean(current_state, index);
else if(lua_isinteger(current_state, index)) else if(lua_isinteger(current_state, index))
return_value = (int32)lua_tointeger(current_state, index); return_value = lua_tointeger(current_state, index);
else else
return_value = (int32)lua_tonumber(current_state, index); return_value = static_cast<lua_Integer>(lua_tonumber(current_state, index));
result->push_back(return_value); result.push_back(return_value);
} }
lua_settop(current_state, stack_top); lua_settop(current_state, stack_top);
is_success = OPERATION_SUCCESS; is_success = OPERATION_SUCCESS;
...@@ -672,11 +673,13 @@ int32 interpreter::get_function_handle(lua_State* L, int32 index) { ...@@ -672,11 +673,13 @@ int32 interpreter::get_function_handle(lua_State* L, int32 index) {
int32 ref = luaL_ref(L, LUA_REGISTRYINDEX); int32 ref = luaL_ref(L, LUA_REGISTRYINDEX);
return ref; return ref;
} }
duel* interpreter::get_duel_info(lua_State * L) { duel* interpreter::get_duel_info(lua_State* L) {
duel* pduel; duel* pduel;
std::memcpy(&pduel, lua_getextraspace(L), LUA_EXTRASPACE); std::memcpy(&pduel, lua_getextraspace(L), LUA_EXTRASPACE);
return pduel; return pduel;
} }
bool interpreter::is_load_script(card_data data) { bool interpreter::is_load_script(const card_data& data) {
if(data.code == TEMP_CARD_ID)
return false;
return !(data.type & TYPE_NORMAL) || (data.type & TYPE_PENDULUM); return !(data.type & TYPE_NORMAL) || (data.type & TYPE_PENDULUM);
} }
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
explicit interpreter(duel* pd); explicit interpreter(duel* pd);
~interpreter(); ~interpreter();
int32 register_card(card* pcard); void register_card(card* pcard);
void register_effect(effect* peffect); void register_effect(effect* peffect);
void unregister_effect(effect* peffect); void unregister_effect(effect* peffect);
void register_group(group* pgroup); void register_group(group* pgroup);
...@@ -74,7 +74,7 @@ public: ...@@ -74,7 +74,7 @@ public:
int32 check_filter(lua_State* L, 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_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);
int32 get_function_value(int32 f, uint32 param_count, std::vector<int32>* result); int32 get_function_value(int32 f, uint32 param_count, std::vector<lua_Integer>& result);
int32 call_coroutine(int32 f, uint32 param_count, int32* yield_value, uint16 step); int32 call_coroutine(int32 f, uint32 param_count, int32* yield_value, uint16 step);
int32 clone_function_ref(int32 func_ref); int32 clone_function_ref(int32 func_ref);
void* get_ref_object(int32 ref_handler); void* get_ref_object(int32 ref_handler);
...@@ -85,7 +85,7 @@ public: ...@@ -85,7 +85,7 @@ public:
static void function2value(lua_State* L, int32 func_ref); static void function2value(lua_State* L, int32 func_ref);
static int32 get_function_handle(lua_State* L, int32 index); static int32 get_function_handle(lua_State* L, int32 index);
static duel* get_duel_info(lua_State* L); static duel* get_duel_info(lua_State* L);
static bool is_load_script(card_data data); static bool is_load_script(const card_data& data);
template <size_t N, typename... TR> template <size_t N, typename... TR>
static int sprintf(char (&buffer)[N], const char* format, TR... args) { static int sprintf(char (&buffer)[N], const char* format, TR... args) {
......
...@@ -1828,6 +1828,10 @@ int32 scriptlib::card_register_effect(lua_State *L) { ...@@ -1828,6 +1828,10 @@ int32 scriptlib::card_register_effect(lua_State *L) {
pduel->game_field->core.reseted_effects.insert(peffect); pduel->game_field->core.reseted_effects.insert(peffect);
return 0; return 0;
} }
for (auto& entry : category_checklist) {
if (peffect->category & entry.first)
peffect->flag[0] |= entry.second;
}
int32 id; int32 id;
if (peffect->handler) if (peffect->handler)
id = -1; id = -1;
...@@ -1891,7 +1895,7 @@ int32 scriptlib::card_register_flag_effect(lua_State *L) { ...@@ -1891,7 +1895,7 @@ int32 scriptlib::card_register_flag_effect(lua_State *L) {
card* pcard = *(card**) lua_touserdata(L, 1); card* pcard = *(card**) lua_touserdata(L, 1);
int32 code = (lua_tointeger(L, 2) & MAX_CARD_ID) | EFFECT_FLAG_EFFECT; int32 code = (lua_tointeger(L, 2) & MAX_CARD_ID) | EFFECT_FLAG_EFFECT;
int32 reset = (int32)lua_tointeger(L, 3); int32 reset = (int32)lua_tointeger(L, 3);
uint32 flag = (uint32)lua_tointeger(L, 4); uint64 flag = lua_tointeger(L, 4);
int32 count = (int32)lua_tointeger(L, 5); int32 count = (int32)lua_tointeger(L, 5);
lua_Integer lab = 0; lua_Integer lab = 0;
int32 desc = 0; int32 desc = 0;
......
...@@ -97,7 +97,7 @@ int32 scriptlib::duel_register_flag_effect(lua_State *L) { ...@@ -97,7 +97,7 @@ int32 scriptlib::duel_register_flag_effect(lua_State *L) {
return 0; return 0;
int32 code = (lua_tointeger(L, 2) & MAX_CARD_ID) | EFFECT_FLAG_EFFECT; int32 code = (lua_tointeger(L, 2) & MAX_CARD_ID) | EFFECT_FLAG_EFFECT;
int32 reset = (int32)lua_tointeger(L, 3); int32 reset = (int32)lua_tointeger(L, 3);
uint32 flag = (uint32)lua_tointeger(L, 4); uint64 flag = lua_tointeger(L, 4);
int32 count = (int32)lua_tointeger(L, 5); int32 count = (int32)lua_tointeger(L, 5);
lua_Integer lab = 0; lua_Integer lab = 0;
if(lua_gettop(L) >= 6) if(lua_gettop(L) >= 6)
......
...@@ -226,8 +226,8 @@ int32 scriptlib::effect_set_property(lua_State *L) { ...@@ -226,8 +226,8 @@ int32 scriptlib::effect_set_property(lua_State *L) {
check_param_count(L, 2); check_param_count(L, 2);
check_param(L, PARAM_TYPE_EFFECT, 1); check_param(L, PARAM_TYPE_EFFECT, 1);
effect* peffect = *(effect**) lua_touserdata(L, 1); effect* peffect = *(effect**) lua_touserdata(L, 1);
uint32 v1 = (uint32)lua_tointeger(L, 2); uint64 v1 = lua_tointeger(L, 2);
uint32 v2 = (uint32)lua_tointeger(L, 3); uint64 v2 = lua_tointeger(L, 3);
peffect->flag[0] = (peffect->flag[0] & INTERNAL_FLAGS) | (v1 & ~INTERNAL_FLAGS); peffect->flag[0] = (peffect->flag[0] & INTERNAL_FLAGS) | (v1 & ~INTERNAL_FLAGS);
peffect->flag[1] = v2; peffect->flag[1] = v2;
return 0; return 0;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <set>
#include "ocgapi.h" #include "ocgapi.h"
#include "duel.h" #include "duel.h"
#include "card.h" #include "card.h"
...@@ -14,7 +15,6 @@ ...@@ -14,7 +15,6 @@
#include "field.h" #include "field.h"
#include "interpreter.h" #include "interpreter.h"
#include "buffer.h" #include "buffer.h"
#include <set>
static script_reader sreader = default_script_reader; static script_reader sreader = default_script_reader;
static card_reader creader = default_card_reader; static card_reader creader = default_card_reader;
...@@ -35,6 +35,10 @@ byte* read_script(const char* script_name, int* len) { ...@@ -35,6 +35,10 @@ byte* read_script(const char* script_name, int* len) {
return sreader(script_name, len); return sreader(script_name, len);
} }
uint32 read_card(uint32 code, card_data* data) { uint32 read_card(uint32 code, card_data* data) {
if (code == TEMP_CARD_ID) {
data->clear();
return 0;
}
return creader(code, data); return creader(code, data);
} }
uint32 handle_message(void* pduel, uint32 msg_type) { uint32 handle_message(void* pduel, uint32 msg_type) {
...@@ -127,7 +131,9 @@ extern "C" DECL_DLLEXPORT void set_player_info(intptr_t pduel, int32 playerid, i ...@@ -127,7 +131,9 @@ extern "C" DECL_DLLEXPORT void set_player_info(intptr_t pduel, int32 playerid, i
pd->game_field->player[playerid].draw_count = drawcount; pd->game_field->player[playerid].draw_count = drawcount;
} }
extern "C" DECL_DLLEXPORT void get_log_message(intptr_t pduel, char* buf) { extern "C" DECL_DLLEXPORT void get_log_message(intptr_t pduel, char* buf) {
std::strcpy(buf, ((duel*)pduel)->strbuffer); duel* pd = (duel*)pduel;
buf[0] = '\0';
std::strncat(buf, pd->strbuffer, sizeof pd->strbuffer - 1);
} }
extern "C" DECL_DLLEXPORT int32 get_message(intptr_t pduel, byte* buf) { extern "C" DECL_DLLEXPORT int32 get_message(intptr_t pduel, byte* buf) {
int32 len = ((duel*)pduel)->read_buffer(buf); int32 len = ((duel*)pduel)->read_buffer(buf);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#define LEN_FAIL 0 #define LEN_FAIL 0
#define LEN_EMPTY 4 #define LEN_EMPTY 4
#define LEN_HEADER 8 #define LEN_HEADER 8
#define TEMP_CARD_ID 0
class card; class card;
struct card_data; struct card_data;
......
This diff is collapsed.
...@@ -913,7 +913,7 @@ static int32 is_declarable(card_data const& cd, const std::vector<uint32>& opcod ...@@ -913,7 +913,7 @@ static int32 is_declarable(card_data const& cd, const std::vector<uint32>& opcod
stack.pop(); stack.pop();
int32 lhs = stack.top(); int32 lhs = stack.top();
stack.pop(); stack.pop();
stack.push(lhs && rhs); stack.push(static_cast<int32>(lhs && rhs));
} }
break; break;
} }
...@@ -923,7 +923,7 @@ static int32 is_declarable(card_data const& cd, const std::vector<uint32>& opcod ...@@ -923,7 +923,7 @@ static int32 is_declarable(card_data const& cd, const std::vector<uint32>& opcod
stack.pop(); stack.pop();
int32 lhs = stack.top(); int32 lhs = stack.top();
stack.pop(); stack.pop();
stack.push(lhs || rhs); stack.push(static_cast<int32>(lhs || rhs));
} }
break; break;
} }
...@@ -939,7 +939,7 @@ static int32 is_declarable(card_data const& cd, const std::vector<uint32>& opcod ...@@ -939,7 +939,7 @@ static int32 is_declarable(card_data const& cd, const std::vector<uint32>& opcod
if(stack.size() >= 1) { if(stack.size() >= 1) {
int32 val = stack.top(); int32 val = stack.top();
stack.pop(); stack.pop();
stack.push(!val); stack.push(static_cast<int32>(!val));
} }
break; break;
} }
......
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