Commit f7fe6fe4 authored by wind2009's avatar wind2009

Merge remote-tracking branch 'upstream/master'

parents c146c549 a04fddec
This diff is collapsed.
......@@ -26,7 +26,7 @@ struct chain;
struct card_state {
uint32 code{ 0 };
uint32 code2{ 0 };
std::vector<uint32> setcode;
std::vector<uint16_t> setcode;
uint32 type{ 0 };
uint32 level{ 0 };
uint32 rank{ 0 };
......@@ -218,6 +218,7 @@ public:
std::tuple<uint32, uint32> get_original_code_rule() const;
uint32 get_code();
uint32 get_another_code();
static bool check_card_setcode(uint32 code, uint32 value);
int32 is_set_card(uint32 set_code);
int32 is_origin_set_card(uint32 set_code);
int32 is_pre_set_card(uint32 set_code);
......@@ -341,6 +342,7 @@ public:
int32 is_spsummonable(effect* proc, material_info info = null_info);
int32 is_summonable(effect* proc, uint8 min_tribute, uint32 zone = 0x1f, uint32 releasable = 0xff00ff);
int32 is_can_be_summoned(uint8 playerid, uint8 ingore_count, effect* peffect, uint8 min_tribute, uint32 zone = 0x1f);
int32 is_summon_negatable(uint32 sumtype, effect* reason_effect);
int32 get_summon_tribute_count();
int32 get_set_tribute_count();
int32 is_can_be_flip_summoned(uint8 playerid);
......@@ -362,7 +364,7 @@ public:
int32 is_releasable_by_effect(uint8 playerid, effect* reason_effect);
int32 is_capable_send_to_grave(uint8 playerid);
int32 is_capable_send_to_hand(uint8 playerid);
int32 is_capable_send_to_deck(uint8 playerid);
int32 is_capable_send_to_deck(uint8 playerid, uint8 send_activating = FALSE);
int32 is_capable_send_to_extra(uint8 playerid);
int32 is_capable_cost_to_grave(uint8 playerid);
int32 is_capable_cost_to_hand(uint8 playerid);
......@@ -407,6 +409,8 @@ public:
#define SUMMON_VALUE_CUSTOM_TYPE 0x0000ffff
constexpr uint32 DEFAULT_SUMMON_TYPE = SUMMON_VALUE_MAIN_TYPE | SUMMON_VALUE_SUB_TYPE | SUMMON_VALUE_CUSTOM_TYPE;
#define SUMMON_VALUE_FUTURE_FUSION 0x18
//Counter
#define COUNTER_WITHOUT_PERMIT 0x1000
//#define COUNTER_NEED_ENABLE 0x2000
......@@ -434,6 +438,4 @@ constexpr uint32 DEFAULT_SUMMON_TYPE = SUMMON_VALUE_MAIN_TYPE | SUMMON_VALUE_SUB
#define SUMMON_INFO_REASON_EFFECT 0x200
#define SUMMON_INFO_REASON_PLAYER 0x400
#define CARD_ARTWORK_VERSIONS_OFFSET 10
#endif /* CARD_H_ */
#ifndef CARD_DATA_H_
#define CARD_DATA_H_
#include "common.h"
constexpr int CARD_ARTWORK_VERSIONS_OFFSET = 20;
constexpr int SIZE_SETCODE = 16;
constexpr int CARD_BLACK_LUSTER_SOLDIER2 = 5405695;
struct card_data {
uint32 code{ 0 };
uint32 alias{ 0 };
uint64 setcode{ 0 };
uint32 type{ 0 };
uint32 level{ 0 };
uint32 attribute{ 0 };
uint32 race{ 0 };
int32 attack{ 0 };
int32 defense{ 0 };
uint32 lscale{ 0 };
uint32 rscale{ 0 };
uint32 link_marker{ 0 };
uint32 code{};
uint32 alias{};
uint16_t setcode[SIZE_SETCODE]{};
uint32 type{};
uint32 level{};
uint32 attribute{};
uint32 race{};
int32 attack{};
int32 defense{};
uint32 lscale{};
uint32 rscale{};
uint32 link_marker{};
void clear() {
code = 0;
alias = 0;
setcode = 0;
for (auto& x : setcode)
x = 0;
type = 0;
level = 0;
attribute = 0;
......@@ -29,6 +36,37 @@ struct card_data {
rscale = 0;
link_marker = 0;
}
bool is_setcode(uint32 value) const {
uint16_t settype = value & 0x0fff;
uint16_t setsubtype = value & 0xf000;
for (auto& x : setcode) {
if ((x & 0x0fff) == settype && (x & 0xf000 & setsubtype) == setsubtype)
return true;
if (!x)
return false;
}
return false;
}
bool is_alternative() const {
if (code == CARD_BLACK_LUSTER_SOLDIER2)
return false;
return alias && (alias < code + CARD_ARTWORK_VERSIONS_OFFSET) && (code < alias + CARD_ARTWORK_VERSIONS_OFFSET);
}
void set_setcode(uint64 value) {
int ctr = 0;
while (value) {
if (value & 0xffff) {
setcode[ctr] = value & 0xffff;
++ctr;
}
value >>= 16;
}
for (int i = ctr; i < SIZE_SETCODE; ++i)
setcode[i] = 0;
}
};
#endif /* CARD_DATA_H_ */
......@@ -30,6 +30,7 @@ typedef signed char int8;
#define TRUE 1
#define FALSE 0
#define SIZE_MESSAGE_BUFFER 0x2000
#define SIZE_RETURN_VALUE 128
#define PROCESSOR_BUFFER_LEN 0x0fffffff
#define PROCESSOR_FLAG 0xf0000000
......@@ -180,27 +181,27 @@ struct card_sort {
#define REASONS_PROCEDURE (REASON_SYNCHRO | REASON_XYZ | REASON_LINK)
//Status
#define STATUS_DISABLED 0x0001 //
#define STATUS_TO_ENABLE 0x0002 //
#define STATUS_TO_DISABLE 0x0004 //
#define STATUS_PROC_COMPLETE 0x0008 //
#define STATUS_SET_TURN 0x0010 //
#define STATUS_NO_LEVEL 0x0020 //
#define STATUS_BATTLE_RESULT 0x0040 //
#define STATUS_SPSUMMON_STEP 0x0080 //
#define STATUS_FORM_CHANGED 0x0100 //
#define STATUS_SUMMONING 0x0200 //
#define STATUS_EFFECT_ENABLED 0x0400 //
#define STATUS_SUMMON_TURN 0x0800 //
#define STATUS_DESTROY_CONFIRMED 0x1000 //
#define STATUS_LEAVE_CONFIRMED 0x2000 //
#define STATUS_BATTLE_DESTROYED 0x4000 //
#define STATUS_COPYING_EFFECT 0x8000 //
#define STATUS_CHAINING 0x10000 //
#define STATUS_SUMMON_DISABLED 0x20000 //
#define STATUS_ACTIVATE_DISABLED 0x40000 //
#define STATUS_DISABLED 0x0001
#define STATUS_TO_ENABLE 0x0002
#define STATUS_TO_DISABLE 0x0004
#define STATUS_PROC_COMPLETE 0x0008
#define STATUS_SET_TURN 0x0010
#define STATUS_NO_LEVEL 0x0020
#define STATUS_BATTLE_RESULT 0x0040
#define STATUS_SPSUMMON_STEP 0x0080
#define STATUS_FORM_CHANGED 0x0100
#define STATUS_SUMMONING 0x0200
#define STATUS_EFFECT_ENABLED 0x0400
#define STATUS_SUMMON_TURN 0x0800
#define STATUS_DESTROY_CONFIRMED 0x1000
#define STATUS_LEAVE_CONFIRMED 0x2000
#define STATUS_BATTLE_DESTROYED 0x4000
#define STATUS_COPYING_EFFECT 0x8000
#define STATUS_CHAINING 0x10000
#define STATUS_SUMMON_DISABLED 0x20000
#define STATUS_ACTIVATE_DISABLED 0x40000
#define STATUS_EFFECT_REPLACED 0x80000
#define STATUS_FUTURE_FUSION 0x100000
#define STATUS_FLIP_SUMMONING 0x100000
#define STATUS_ATTACK_CANCELED 0x200000
#define STATUS_INITIALIZING 0x400000
#define STATUS_TO_HAND_WITHOUT_CONFIRM 0x800000
......@@ -211,6 +212,7 @@ struct card_sort {
#define STATUS_OPPO_BATTLE 0x10000000
#define STATUS_FLIP_SUMMON_TURN 0x20000000
#define STATUS_SPSUMMON_TURN 0x40000000
#define STATUS_FLIP_SUMMON_DISABLED 0x80000000
//Query list
#define QUERY_CODE 0x1
......
......@@ -140,7 +140,7 @@ void duel::set_responsei(uint32 resp) {
game_field->returns.ivalue[0] = resp;
}
void duel::set_responseb(byte* resp) {
std::memcpy(game_field->returns.bvalue, resp, 64);
std::memcpy(game_field->returns.bvalue, resp, SIZE_RETURN_VALUE);
}
int32 duel::get_next_integer(int32 l, int32 h) {
if (game_field->core.duel_options & DUEL_OLD_REPLAY) {
......
......@@ -629,7 +629,7 @@ int32 field::get_useable_count(card* pcard, uint8 playerid, uint8 location, uint
return get_useable_count_other(pcard, playerid, location, uplayer, reason, zone, list);
}
/**
* @param pcard the card about to move from Extra Deck (NULL means any card in Extra Deck)
* @param pcard the card about to move from Extra Deck (nullptr means any card in Extra Deck)
* @return usable count in zone of playerid's MZONE for pcard
*/
int32 field::get_useable_count_fromex(card* pcard, uint8 playerid, uint8 uplayer, uint32 zone, uint32* list) {
......@@ -659,7 +659,7 @@ int32 field::get_spsummonable_count(card* pcard, uint8 playerid, uint32 zone, ui
return get_tofield_count(pcard, playerid, LOCATION_MZONE, playerid, LOCATION_REASON_TOFIELD, zone, list);
}
/**
* @param pcard the card about to move from Extra Deck (NULL means any card in Extra Deck)
* @param pcard the card about to move from Extra Deck (nullptr means any card in Extra Deck)
* @return the number of available grids in zone of playerid's MZONE for pcard
*/
int32 field::get_spsummonable_count_fromex(card* pcard, uint8 playerid, uint8 uplayer, uint32 zone, uint32* list) {
......
......@@ -155,11 +155,14 @@ struct processor_unit {
int32 value3{ 0 };
int32 value4{ 0 };
};
constexpr int SIZE_SVALUE = SIZE_RETURN_VALUE / 2;
constexpr int SIZE_IVALUE = SIZE_RETURN_VALUE / 4;
constexpr int SIZE_LVALUE = SIZE_RETURN_VALUE / 8;
union return_value {
int8 bvalue[64];
int16 svalue[32];
int32 ivalue[16];
int64 lvalue[8];
int8 bvalue[SIZE_RETURN_VALUE];
int16 svalue[SIZE_SVALUE];
int32 ivalue[SIZE_IVALUE];
int64 lvalue[SIZE_LVALUE];
};
struct processor {
using effect_vector = std::vector<effect*>;
......@@ -276,6 +279,8 @@ struct processor {
uint8 summon_cancelable{ FALSE };
card* attacker{ nullptr };
card* attack_target{ nullptr };
uint8 attacker_player{ PLAYER_NONE };
uint8 attack_target_player{ PLAYER_NONE };
uint32 limit_extra_summon_zone{ 0 };
uint32 limit_extra_summon_releasable{ 0 };
card* limit_tuner{ nullptr };
......@@ -308,6 +313,8 @@ struct processor {
uint8 coin_result[MAX_COIN_COUNT]{};
int32 coin_count{ 0 };
bool is_target_ready{ false };
bool is_gemini_summoning{ false };
bool is_summon_negated{ false };
uint8 to_bp{ FALSE };
uint8 to_m2{ FALSE };
......@@ -427,7 +434,7 @@ public:
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_summon_release_list(card* target, card_set* release_list, card_set* ex_list, card_set* ex_list_oneof, group* mg = NULL, uint32 ex = 0, uint32 releasable = 0xff00ff, uint32 pos = 0x1);
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);
......@@ -570,8 +577,8 @@ public:
void destroy(card* target, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid = 2, uint32 destination = 0, uint32 sequence = 0);
void release(card_set* targets, effect* reason_effect, uint32 reason, uint32 reason_player);
void release(card* target, effect* reason_effect, uint32 reason, uint32 reason_player);
void send_to(card_set* targets, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence, uint32 position);
void send_to(card* target, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence, uint32 position);
void send_to(card_set* targets, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence, uint32 position, uint8 send_activating = FALSE);
void send_to(card* target, effect* reason_effect, uint32 reason, uint32 reason_player, uint32 playerid, uint32 destination, uint32 sequence, uint32 position, uint8 send_activating = FALSE);
void move_to_field(card* target, uint32 move_player, uint32 playerid, uint32 destination, uint32 positions, uint32 enable = FALSE, uint32 ret = 0, uint32 pzone = FALSE, uint32 zone = 0xff);
void change_position(card_set* targets, effect* reason_effect, uint32 reason_player, uint32 au, uint32 ad, uint32 du, uint32 dd, uint32 flag, uint32 enable = FALSE);
void change_position(card* target, effect* reason_effect, uint32 reason_player, uint32 npos, uint32 flag, uint32 enable = FALSE);
......@@ -603,7 +610,7 @@ public:
int32 release_replace(uint16 step, group* targets, card* target);
int32 release(uint16 step, group* targets, effect* reason_effect, uint32 reason, uint8 reason_player);
int32 send_replace(uint16 step, group* targets, card* target);
int32 send_to(uint16 step, group* targets, effect* reason_effect, uint32 reason, uint8 reason_player);
int32 send_to(uint16 step, group* targets, effect* reason_effect, uint32 reason, uint8 reason_player, uint8 send_activating);
int32 discard_deck(uint16 step, uint8 playerid, uint8 count, uint32 reason);
int32 move_to_field(uint16 step, card* target, uint32 enable, uint32 ret, uint32 pzone, uint32 zone);
int32 change_position(uint16 step, group* targets, effect* reason_effect, uint8 reason_player, uint32 enable);
......@@ -759,17 +766,17 @@ public:
#define PROCESSOR_DESTROY_REPLACE 56
#define PROCESSOR_RELEASE_REPLACE 57
#define PROCESSOR_SENDTO_REPLACE 58
#define PROCESSOR_SUMMON_RULE 60 //arg1, arg2
#define PROCESSOR_SPSUMMON_RULE 61 //arg1, arg2, arg3
#define PROCESSOR_SUMMON_RULE 60
#define PROCESSOR_SPSUMMON_RULE 61
#define PROCESSOR_SPSUMMON 62
#define PROCESSOR_FLIP_SUMMON 63 //arg1, arg2
#define PROCESSOR_MSET 64 //arg1, arg2
#define PROCESSOR_FLIP_SUMMON 63
#define PROCESSOR_MSET 64
#define PROCESSOR_SSET 65
#define PROCESSOR_SPSUMMON_STEP 66
#define PROCESSOR_SSET_G 67
#define PROCESSOR_DRAW 70
#define PROCESSOR_DAMAGE 71 //arg1, arg2, arg3
#define PROCESSOR_RECOVER 72 //arg1, arg2, arg3
#define PROCESSOR_DAMAGE 71
#define PROCESSOR_RECOVER 72
#define PROCESSOR_EQUIP 73
#define PROCESSOR_GET_CONTROL 74
#define PROCESSOR_SWAP_CONTROL 75
......
......@@ -48,21 +48,22 @@ interpreter::~interpreter() {
}
int32 interpreter::register_card(card *pcard) {
//create a card in by userdata
luaL_checkstack(lua_state, 1, NULL);
luaL_checkstack(current_state, 1, NULL);
card ** ppcard = (card**) lua_newuserdata(lua_state, sizeof(card*));
luaL_checkstack(lua_state, 1, nullptr);
luaL_checkstack(current_state, 1, nullptr);
card ** ppcard = (card**) lua_newuserdata(lua_state, sizeof(card*)); //+1 userdata
*ppcard = pcard;
pcard->ref_handle = luaL_ref(lua_state, LUA_REGISTRYINDEX);
pcard->ref_handle = luaL_ref(lua_state, LUA_REGISTRYINDEX); //-1
//some userdata may be created in script like token so use current_state
lua_rawgeti(current_state, LUA_REGISTRYINDEX, pcard->ref_handle);
lua_rawgeti(current_state, LUA_REGISTRYINDEX, pcard->ref_handle); //+1 userdata
//load script
if(pcard->data.alias && (pcard->data.alias < pcard->data.code + CARD_ARTWORK_VERSIONS_OFFSET) && (pcard->data.code < pcard->data.alias + CARD_ARTWORK_VERSIONS_OFFSET))
if(pcard->data.is_alternative())
load_card_script(pcard->data.alias);
else
load_card_script(pcard->data.code);
//stack: table cxxx, userdata
//set metatable of pointer to base script
lua_setmetatable(current_state, -2);
lua_pop(current_state, 1);
lua_setmetatable(current_state, -2); //-1
lua_pop(current_state, 1); //-1
//Initial
if(pcard->data.code && (!(pcard->data.type & TYPE_NORMAL) || (pcard->data.type & TYPE_PENDULUM))) {
pcard->set_status(STATUS_INITIALIZING, TRUE);
......@@ -77,7 +78,7 @@ void interpreter::register_effect(effect *peffect) {
if (!peffect)
return;
//create a effect in by userdata
luaL_checkstack(lua_state, 3, NULL);
luaL_checkstack(lua_state, 3, nullptr);
effect ** ppeffect = (effect**) lua_newuserdata(lua_state, sizeof(effect*));
*ppeffect = peffect;
peffect->ref_handle = luaL_ref(lua_state, LUA_REGISTRYINDEX);
......@@ -107,7 +108,7 @@ void interpreter::register_group(group *pgroup) {
if (!pgroup)
return;
//create a group in by userdata
luaL_checkstack(lua_state, 3, NULL);
luaL_checkstack(lua_state, 3, nullptr);
group ** ppgroup = (group**) lua_newuserdata(lua_state, sizeof(group*));
*ppgroup = pgroup;
pgroup->ref_handle = luaL_ref(lua_state, LUA_REGISTRYINDEX);
......@@ -143,32 +144,32 @@ int32 interpreter::load_script(const char* script_name) {
int32 interpreter::load_card_script(uint32 code) {
char class_name[20];
sprintf(class_name, "c%d", code);
luaL_checkstack(current_state, 1, NULL);
lua_getglobal(current_state, class_name);
luaL_checkstack(current_state, 1, nullptr);
lua_getglobal(current_state, class_name); //+1 table cxxx
//if script is not loaded, create and load it
if (lua_isnil(current_state, -1)) {
luaL_checkstack(current_state, 5, NULL);
lua_pop(current_state, 1);
luaL_checkstack(current_state, 5, nullptr);
lua_pop(current_state, 1); //-1
//create a table & set metatable
lua_createtable(current_state, 0, 0);
lua_setglobal(current_state, class_name);
lua_getglobal(current_state, class_name);
lua_getglobal(current_state, "Card");
lua_setmetatable(current_state, -2);
lua_pushstring(current_state, "__index");
lua_pushvalue(current_state, -2);
lua_rawset(current_state, -3);
lua_getglobal(current_state, class_name);
lua_setglobal(current_state, "self_table");
lua_pushinteger(current_state, code);
lua_setglobal(current_state, "self_code");
lua_createtable(current_state, 0, 0); //+1, {}
lua_setglobal(current_state, class_name); //-1
lua_getglobal(current_state, class_name); //+1 table cxxx
lua_getglobal(current_state, "Card"); //+1 Card, table cxxx
lua_setmetatable(current_state, -2); //-1 table cxxx
lua_pushstring(current_state, "__index"); //+1 "__index", table cxxx
lua_pushvalue(current_state, -2); //+1 table cxxx, "__index", table cxxx
lua_rawset(current_state, -3); //-2 table cxxx
lua_getglobal(current_state, class_name); //+1
lua_setglobal(current_state, "self_table"); //-1
lua_pushinteger(current_state, code); //+1
lua_setglobal(current_state, "self_code"); //-1
char script_name[64];
sprintf(script_name, "./script/c%d.lua", code);
int32 res = load_script(script_name);
lua_pushnil(current_state);
lua_setglobal(current_state, "self_table");
lua_pushnil(current_state);
lua_setglobal(current_state, "self_code");
lua_pushnil(current_state); //+1
lua_setglobal(current_state, "self_table"); //-1
lua_pushnil(current_state); //+1
lua_setglobal(current_state, "self_code"); //-1 table cxxx {__index: cxxx }
if(!res) {
return OPERATION_FAIL;
}
......@@ -190,7 +191,7 @@ void interpreter::add_param(int32 param, int32 type, bool front) {
void interpreter::push_param(lua_State* L, bool is_coroutine) {
int32 pushed = 0;
for (const auto& it : params) {
luaL_checkstack(L, 1, NULL);
luaL_checkstack(L, 1, nullptr);
uint32 type = it.second;
switch(type) {
case PARAM_TYPE_INT:
......@@ -300,7 +301,7 @@ int32 interpreter::call_card_function(card* pcard, const char* f, uint32 param_c
return OPERATION_FAIL;
}
card2value(current_state, pcard);
luaL_checkstack(current_state, 1, NULL);
luaL_checkstack(current_state, 1, nullptr);
lua_getfield(current_state, -1, f);
if (!lua_isfunction(current_state, -1)) {
sprintf(pduel->strbuffer, "\"CallCardFunction\"(c%d.%s): attempt to call an error function", pcard->data.code, f);
......@@ -341,7 +342,7 @@ int32 interpreter::call_code_function(uint32 code, const char* f, uint32 param_c
return OPERATION_FAIL;
}
load_card_script(code);
luaL_checkstack(current_state, 1, NULL);
luaL_checkstack(current_state, 1, nullptr);
lua_getfield(current_state, -1, f);
if (!lua_isfunction(current_state, -1)) {
sprintf(pduel->strbuffer, "\"CallCodeFunction\": attempt to call an error function");
......@@ -405,7 +406,7 @@ int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
return TRUE;
++no_action;
++call_depth;
luaL_checkstack(current_state, 1 + extraargs, NULL);
luaL_checkstack(current_state, 1 + extraargs, nullptr);
lua_pushvalue(current_state, findex);
interpreter::card2value(current_state, pcard);
for(int32 i = 0; i < extraargs; ++i)
......@@ -437,7 +438,7 @@ int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraarg
return 0;
++no_action;
++call_depth;
luaL_checkstack(current_state, 1 + extraargs, NULL);
luaL_checkstack(current_state, 1 + extraargs, nullptr);
lua_pushvalue(current_state, findex);
interpreter::card2value(current_state, pcard);
for(int32 i = 0; i < extraargs; ++i)
......@@ -613,7 +614,7 @@ int32 interpreter::call_coroutine(int32 f, uint32 param_count, uint32 * yield_va
}
}
int32 interpreter::clone_function_ref(int32 func_ref) {
luaL_checkstack(current_state, 1, NULL);
luaL_checkstack(current_state, 1, nullptr);
lua_rawgeti(current_state, LUA_REGISTRYINDEX, func_ref);
int32 ref = luaL_ref(current_state, LUA_REGISTRYINDEX);
return ref;
......@@ -621,7 +622,7 @@ int32 interpreter::clone_function_ref(int32 func_ref) {
void* interpreter::get_ref_object(int32 ref_handler) {
if(ref_handler == 0)
return nullptr;
luaL_checkstack(current_state, 1, NULL);
luaL_checkstack(current_state, 1, nullptr);
lua_rawgeti(current_state, LUA_REGISTRYINDEX, ref_handler);
void* p = *(void**)lua_touserdata(current_state, -1);
lua_pop(current_state, 1);
......@@ -629,35 +630,35 @@ void* interpreter::get_ref_object(int32 ref_handler) {
}
//Convert a pointer to a lua value, +1 -0
void interpreter::card2value(lua_State* L, card* pcard) {
luaL_checkstack(L, 1, NULL);
luaL_checkstack(L, 1, nullptr);
if (!pcard || pcard->ref_handle == 0)
lua_pushnil(L);
else
lua_rawgeti(L, LUA_REGISTRYINDEX, pcard->ref_handle);
}
void interpreter::group2value(lua_State* L, group* pgroup) {
luaL_checkstack(L, 1, NULL);
luaL_checkstack(L, 1, nullptr);
if (!pgroup || pgroup->ref_handle == 0)
lua_pushnil(L);
else
lua_rawgeti(L, LUA_REGISTRYINDEX, pgroup->ref_handle);
}
void interpreter::effect2value(lua_State* L, effect* peffect) {
luaL_checkstack(L, 1, NULL);
luaL_checkstack(L, 1, nullptr);
if (!peffect || peffect->ref_handle == 0)
lua_pushnil(L);
else
lua_rawgeti(L, LUA_REGISTRYINDEX, peffect->ref_handle);
}
void interpreter::function2value(lua_State* L, int32 func_ref) {
luaL_checkstack(L, 1, NULL);
luaL_checkstack(L, 1, nullptr);
if (!func_ref)
lua_pushnil(L);
else
lua_rawgeti(L, LUA_REGISTRYINDEX, func_ref);
}
int32 interpreter::get_function_handle(lua_State* L, int32 index) {
luaL_checkstack(L, 1, NULL);
luaL_checkstack(L, 1, nullptr);
lua_pushvalue(L, index);
int32 ref = luaL_ref(L, LUA_REGISTRYINDEX);
return ref;
......
......@@ -2528,9 +2528,9 @@ int32 scriptlib::card_is_chain_attackable(lua_State *L) {
lua_pushboolean(L, 0);
return 1;
}
pduel->game_field->core.select_cards.clear();
pduel->game_field->get_attack_target(attacker, &pduel->game_field->core.select_cards, TRUE);
if(pduel->game_field->core.select_cards.size() == 0 && (monsteronly || attacker->direct_attackable == 0))
field::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);
else
lua_pushboolean(L, 1);
......
This diff is collapsed.
......@@ -22,7 +22,6 @@
class card;
struct card_data;
struct card_info;
class group;
class effect;
class interpreter;
......
This diff is collapsed.
......@@ -226,8 +226,11 @@ int32 field::select_card(uint16 step, uint8 playerid, uint8 cancelable, uint8 mi
returns.bvalue[0] = 0;
if(max == 0 || core.select_cards.empty())
return TRUE;
if(max > 127)
max = 127;
std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort);
if (core.select_cards.size() > UINT8_MAX)
core.select_cards.resize(UINT8_MAX);
if (max > SIZE_RETURN_VALUE - 1)
max = SIZE_RETURN_VALUE - 1;
if(max > core.select_cards.size())
max = (uint8)core.select_cards.size();
if(min > max)
......@@ -245,7 +248,6 @@ int32 field::select_card(uint16 step, uint8 playerid, uint8 cancelable, uint8 mi
pduel->write_buffer8(min);
pduel->write_buffer8(max);
pduel->write_buffer8((uint8)core.select_cards.size());
std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort);
for(auto& pcard : core.select_cards) {
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer32(pcard->get_info_location());
......@@ -282,6 +284,11 @@ int32 field::select_unselect_card(uint16 step, uint8 playerid, uint8 cancelable,
returns.bvalue[i + 1] = i;
return TRUE;
}
std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort);
if (core.select_cards.size() > UINT8_MAX)
core.select_cards.resize(UINT8_MAX);
if (core.unselect_cards.size() > UINT8_MAX)
core.unselect_cards.resize(UINT8_MAX);
pduel->write_buffer8(MSG_SELECT_UNSELECT_CARD);
pduel->write_buffer8(playerid);
pduel->write_buffer8(finishable);
......@@ -289,7 +296,6 @@ int32 field::select_unselect_card(uint16 step, uint8 playerid, uint8 cancelable,
pduel->write_buffer8(min);
pduel->write_buffer8(max);
pduel->write_buffer8((uint8)core.select_cards.size());
std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort);
for(auto& pcard : core.select_cards) {
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer32(pcard->get_info_location());
......@@ -311,7 +317,7 @@ int32 field::select_unselect_card(uint16 step, uint8 playerid, uint8 cancelable,
pduel->write_buffer8(MSG_RETRY);
return FALSE;
}
uint8 m = (uint8)core.select_cards.size() + (uint8)core.unselect_cards.size();
int32 m = core.select_cards.size() + core.unselect_cards.size();
uint8 v = returns.bvalue[1];
if(v < 0 || v >= m) {
pduel->write_buffer8(MSG_RETRY);
......@@ -495,6 +501,9 @@ int32 field::select_tribute(uint16 step, uint8 playerid, uint8 cancelable, uint8
returns.bvalue[0] = 0;
if(max == 0 || core.select_cards.empty())
return TRUE;
std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort);
if (core.select_cards.size() > UINT8_MAX)
core.select_cards.resize(UINT8_MAX);
uint8 tm = 0;
for(auto& pcard : core.select_cards)
tm += pcard->release_param;
......@@ -511,7 +520,6 @@ int32 field::select_tribute(uint16 step, uint8 playerid, uint8 cancelable, uint8
pduel->write_buffer8(min);
pduel->write_buffer8(max);
pduel->write_buffer8((uint8)core.select_cards.size());
std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort);
for(auto& pcard : core.select_cards) {
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer8(pcard->current.controler);
......@@ -591,7 +599,7 @@ int32 field::select_counter(uint16 step, uint8 playerid, uint16 countertype, uin
return FALSE;
} else {
uint16 ct = 0;
for(uint32 i = 0; i < core.select_cards.size(); ++i) {
for(int32 i = 0; i < (int32)core.select_cards.size(); ++i) {
if(core.select_cards[i]->get_counter(countertype) < returns.svalue[i]) {
pduel->write_buffer8(MSG_RETRY);
return FALSE;
......@@ -620,6 +628,11 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32
returns.bvalue[0] = 0;
if(core.select_cards.empty())
return TRUE;
std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort);
if (core.select_cards.size() > UINT8_MAX)
core.select_cards.resize(UINT8_MAX);
if (core.must_select_cards.size() > UINT8_MAX)
core.must_select_cards.resize(UINT8_MAX);
pduel->write_buffer8(MSG_SELECT_SUM);
if(max)
pduel->write_buffer8(0);
......@@ -640,7 +653,6 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32
pduel->write_buffer32(pcard->sum_param);
}
pduel->write_buffer8((uint8)core.select_cards.size());
std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort);
for(auto& pcard : core.select_cards) {
pduel->write_buffer32(pcard->data.code);
pduel->write_buffer8(pcard->current.controler);
......@@ -723,6 +735,8 @@ int32 field::sort_card(int16 step, uint8 playerid) {
}
if(core.select_cards.empty())
return TRUE;
if (core.select_cards.size() > UINT8_MAX)
core.select_cards.resize(UINT8_MAX);
pduel->write_buffer8(MSG_SORT_CARD);
pduel->write_buffer8(playerid);
pduel->write_buffer8((uint8)core.select_cards.size());
......@@ -920,15 +934,7 @@ static int32 is_declarable(card_data const& cd, const std::vector<uint32>& opcod
if(stack.size() >= 1) {
int32 set_code = stack.top();
stack.pop();
uint64 sc = cd.setcode;
bool res = false;
uint32 settype = set_code & 0xfff;
uint32 setsubtype = set_code & 0xf000;
while(sc) {
if((sc & 0xfff) == settype && (sc & 0xf000 & setsubtype) == setsubtype)
res = true;
sc = sc >> 16;
}
bool res = cd.is_setcode(set_code);
stack.push(res);
}
break;
......@@ -966,7 +972,7 @@ static int32 is_declarable(card_data const& cd, const std::vector<uint32>& opcod
if(stack.size() != 1 || stack.top() == 0)
return FALSE;
return cd.code == CARD_MARINE_DOLPHIN || cd.code == CARD_TWINKLE_MOSS
|| (!cd.alias && (cd.type & (TYPE_MONSTER + TYPE_TOKEN)) != (TYPE_MONSTER + TYPE_TOKEN));
|| (!cd.alias && (cd.type & (TYPE_MONSTER | TYPE_TOKEN)) != (TYPE_MONSTER | TYPE_TOKEN));
}
int32 field::announce_card(int16 step, uint8 playerid) {
if(step == 0) {
......@@ -999,6 +1005,8 @@ int32 field::announce_card(int16 step, uint8 playerid) {
}
int32 field::announce_number(int16 step, uint8 playerid) {
if(step == 0) {
if (core.select_options.size() > UINT8_MAX)
core.select_options.resize(UINT8_MAX);
pduel->write_buffer8(MSG_ANNOUNCE_NUMBER);
pduel->write_buffer8(playerid);
pduel->write_buffer8((uint8)core.select_options.size());
......
......@@ -308,7 +308,7 @@ uint32 field::process() {
return pduel->message_buffer.size();
}
case PROCESSOR_SENDTO: {
if (send_to(it->step, it->ptarget, it->peffect, it->arg1, it->arg2))
if (send_to(it->step, it->ptarget, it->peffect, it->arg1, it->arg2, it->arg3))
core.units.pop_front();
else
++it->step;
......@@ -2928,6 +2928,8 @@ int32 field::process_battle_command(uint16 step) {
core.attacker->set_status(STATUS_OPPO_BATTLE, TRUE);
core.attack_target->set_status(STATUS_OPPO_BATTLE, TRUE);
}
core.attacker_player = pa;
core.attack_target_player = pd;
}
effect* damchange = nullptr;
card* reason_card = nullptr;
......@@ -3091,7 +3093,7 @@ int32 field::process_battle_command(uint16 step) {
if(core.battle_destroy_rep.size())
destroy(&core.battle_destroy_rep, 0, REASON_EFFECT | REASON_REPLACE, PLAYER_NONE);
if(core.desrep_chain.size())
add_process(PROCESSOR_OPERATION_REPLACE, 15, NULL, NULL, 0, 0);
add_process(PROCESSOR_OPERATION_REPLACE, 15, nullptr, nullptr, 0, 0);
adjust_all();
return FALSE;
}
......@@ -3164,16 +3166,16 @@ int32 field::process_battle_command(uint16 step) {
card_set ing;
card_set ed;
if(core.attacker->is_status(STATUS_BATTLE_DESTROYED) && (core.attacker->current.reason & REASON_BATTLE)) {
raise_single_event(core.attack_target, 0, EVENT_BATTLE_DESTROYING, 0, core.attacker->current.reason, core.attack_target->current.controler, 0, 1);
raise_single_event(core.attacker, 0, EVENT_BATTLE_DESTROYED, 0, core.attacker->current.reason, core.attack_target->current.controler, 0, 0);
raise_single_event(core.attacker, 0, EVENT_DESTROYED, 0, core.attacker->current.reason, core.attack_target->current.controler, 0, 0);
raise_single_event(core.attack_target, 0, EVENT_BATTLE_DESTROYING, 0, core.attacker->current.reason, core.attack_target_player, 0, 1);
raise_single_event(core.attacker, 0, EVENT_BATTLE_DESTROYED, 0, core.attacker->current.reason, core.attack_target_player, 0, 0);
raise_single_event(core.attacker, 0, EVENT_DESTROYED, 0, core.attacker->current.reason, core.attack_target_player, 0, 0);
ing.insert(core.attack_target);
ed.insert(core.attacker);
}
if(core.attack_target && core.attack_target->is_status(STATUS_BATTLE_DESTROYED) && (core.attack_target->current.reason & REASON_BATTLE)) {
raise_single_event(core.attacker, 0, EVENT_BATTLE_DESTROYING, 0, core.attack_target->current.reason, core.attacker->current.controler, 0, 0);
raise_single_event(core.attack_target, 0, EVENT_BATTLE_DESTROYED, 0, core.attack_target->current.reason, core.attacker->current.controler, 0, 1);
raise_single_event(core.attack_target, 0, EVENT_DESTROYED, 0, core.attack_target->current.reason, core.attacker->current.controler, 0, 1);
raise_single_event(core.attacker, 0, EVENT_BATTLE_DESTROYING, 0, core.attack_target->current.reason, core.attacker_player, 0, 0);
raise_single_event(core.attack_target, 0, EVENT_BATTLE_DESTROYED, 0, core.attack_target->current.reason, core.attacker_player, 0, 1);
raise_single_event(core.attack_target, 0, EVENT_DESTROYED, 0, core.attack_target->current.reason, core.attacker_player, 0, 1);
ing.insert(core.attacker);
ed.insert(core.attack_target);
}
......@@ -3212,6 +3214,8 @@ int32 field::process_battle_command(uint16 step) {
core.attacker->set_status(STATUS_OPPO_BATTLE, FALSE);
if(core.attack_target)
core.attack_target->set_status(STATUS_OPPO_BATTLE, FALSE);
core.attacker_player = PLAYER_NONE;
core.attack_target_player = PLAYER_NONE;
core.units.begin()->step = -1;
infos.phase = PHASE_BATTLE_STEP;
pduel->write_buffer8(MSG_DAMAGE_STEP_END);
......
......@@ -607,6 +607,7 @@ public:
static int32 duel_is_player_can_send_to_grave(lua_State *L);
static int32 duel_is_player_can_send_to_deck(lua_State *L);
static int32 duel_is_player_can_additional_summon(lua_State *L);
static int32 duel_is_chain_solving(lua_State *L);
static int32 duel_is_chain_negatable(lua_State *L);
static int32 duel_is_chain_disablable(lua_State *L);
static int32 duel_is_chain_disabled(lua_State *L);
......
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