Commit 46fab452 authored by nanahira's avatar nanahira
parents 4091e788 e4f0de84
......@@ -1915,7 +1915,7 @@ void card::remove_effect(effect* peffect, effect_container::iterator it) {
if (!(data.type & TYPE_NORMAL) || (data.type & TYPE_PENDULUM)) {
set_status(STATUS_INITIALIZING, TRUE);
pduel->lua->add_param(this, PARAM_TYPE_CARD);
pduel->lua->call_card_function(this, (char*) "initial_effect", 1, 0);
pduel->lua->call_card_function(this, "initial_effect", 1, 0);
set_status(STATUS_INITIALIZING, FALSE);
}
}
......@@ -1964,7 +1964,7 @@ int32 card::copy_effect(uint32 code, uint32 reset, uint32 count) {
pduel->game_field->core.copy_reset = reset;
pduel->game_field->core.copy_reset_count = count;
pduel->lua->add_param(this, PARAM_TYPE_CARD);
pduel->lua->call_code_function(code, (char*) "initial_effect", 1, 0);
pduel->lua->call_code_function(code, "initial_effect", 1, 0);
pduel->game_field->infos.copy_id++;
set_status(STATUS_COPYING_EFFECT, FALSE);
pduel->game_field->core.copy_reset = cr;
......@@ -2007,7 +2007,7 @@ int32 card::replace_effect(uint32 code, uint32 reset, uint32 count) {
pduel->game_field->core.copy_reset_count = count;
set_status(STATUS_INITIALIZING | STATUS_COPYING_EFFECT, TRUE);
pduel->lua->add_param(this, PARAM_TYPE_CARD);
pduel->lua->call_code_function(code, (char*) "initial_effect", 1, 0);
pduel->lua->call_code_function(code, "initial_effect", 1, 0);
set_status(STATUS_INITIALIZING | STATUS_COPYING_EFFECT, FALSE);
pduel->game_field->infos.copy_id++;
pduel->game_field->core.copy_reset = cr;
......
......@@ -825,13 +825,12 @@ void interpreter::unregister_group(group *pgroup) {
pgroup->ref_handle = 0;
}
int32 interpreter::load_script(const char* script_name) {
int32 error;
int32 len = 0;
byte* buffer = read_script(script_name, &len);
if (!buffer)
return OPERATION_FAIL;
no_action++;
error = luaL_loadbuffer(current_state, (char*)buffer, len, script_name) || lua_pcall(current_state, 0, 0, 0);
int32 error = luaL_loadbuffer(current_state, (char*)buffer, len, script_name) || lua_pcall(current_state, 0, 0, 0);
if (error) {
interpreter::strcpy(pduel->strbuffer, lua_tostring(current_state, -1));
handle_message(pduel, 1);
......@@ -844,7 +843,6 @@ int32 interpreter::load_script(const char* script_name) {
}
int32 interpreter::load_card_script(uint32 code) {
char class_name[20];
char script_name[64];
sprintf(class_name, "c%d", code);
lua_getglobal(current_state, class_name);
//if script is not loaded, create and load it
......@@ -859,6 +857,7 @@ int32 interpreter::load_card_script(uint32 code) {
lua_pushstring(current_state, "__index");
lua_pushvalue(current_state, -2);
lua_rawset(current_state, -3);
char script_name[64];
sprintf(script_name, "./script/c%d.lua", code);
if(!load_script(script_name)) {
return OPERATION_FAIL;
......@@ -879,10 +878,9 @@ void interpreter::add_param(ptr param, int32 type, bool front) {
params.emplace_back((void*)param, type);
}
void interpreter::push_param(lua_State* L, bool is_coroutine) {
uint32 type;
int32 pushed = 0;
for (const auto& it : params) {
type = it.second;
uint32 type = it.second;
switch(type) {
case PARAM_TYPE_INT:
lua_pushinteger(L, (ptr) it.first);
......@@ -1071,7 +1069,6 @@ int32 interpreter::call_code_function(uint32 code, const char* f, uint32 param_c
return OPERATION_SUCCESS;
}
int32 interpreter::check_condition(int32 f, uint32 param_count) {
int32 result;
if(!f) {
params.clear();
return TRUE;
......@@ -1079,7 +1076,7 @@ int32 interpreter::check_condition(int32 f, uint32 param_count) {
no_action++;
call_depth++;
if (call_function(f, param_count, 1)) {
result = lua_toboolean(current_state, -1);
int32 result = lua_toboolean(current_state, -1);
lua_pop(current_state, 1);
no_action--;
call_depth--;
......@@ -1098,7 +1095,6 @@ int32 interpreter::check_condition(int32 f, uint32 param_count) {
return OPERATION_FAIL;
}
int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
int32 result;
if(!findex || lua_isnil(current_state, findex))
return TRUE;
no_action++;
......@@ -1119,7 +1115,7 @@ int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
}
return OPERATION_FAIL;
}
result = lua_toboolean(current_state, -1);
int32 result = lua_toboolean(current_state, -1);
lua_pop(current_state, 1);
no_action--;
call_depth--;
......@@ -1130,7 +1126,6 @@ int32 interpreter::check_matching(card* pcard, int32 findex, int32 extraargs) {
return result;
}
int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraargs) {
int32 result;
if(!findex || lua_isnil(current_state, findex))
return 0;
no_action++;
......@@ -1151,7 +1146,7 @@ int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraarg
}
return OPERATION_FAIL;
}
result = std::round(lua_tonumber(current_state, -1));
int32 result = std::round(lua_tonumber(current_state, -1));
lua_pop(current_state, 1);
no_action--;
call_depth--;
......@@ -1162,7 +1157,6 @@ int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraarg
return result;
}
int32 interpreter::get_function_value(int32 f, uint32 param_count) {
int32 result;
if(!f) {
params.clear();
return 0;
......@@ -1170,6 +1164,7 @@ int32 interpreter::get_function_value(int32 f, uint32 param_count) {
no_action++;
call_depth++;
if (call_function(f, param_count, 1)) {
int32 result = 0;
if (lua_isboolean(current_state, -1))
result = lua_toboolean(current_state, -1);
else
......
......@@ -337,6 +337,6 @@ extern "C" DECL_DLLEXPORT void set_responsei(ptr pduel, int32 value) {
extern "C" DECL_DLLEXPORT void set_responseb(ptr pduel, byte* buf) {
((duel*)pduel)->set_responseb(buf);
}
extern "C" DECL_DLLEXPORT int32 preload_script(ptr pduel, char* script, int32 len) {
extern "C" DECL_DLLEXPORT int32 preload_script(ptr pduel, const char* script, int32 len) {
return ((duel*)pduel)->lua->load_script(script);
}
......@@ -49,7 +49,7 @@ extern "C" DECL_DLLEXPORT int32 query_field_card(ptr pduel, uint8 playerid, uint
extern "C" DECL_DLLEXPORT int32 query_field_info(ptr pduel, byte* buf);
extern "C" DECL_DLLEXPORT void set_responsei(ptr pduel, int32 value);
extern "C" DECL_DLLEXPORT void set_responseb(ptr pduel, byte* buf);
extern "C" DECL_DLLEXPORT int32 preload_script(ptr pduel, char* script, int32 len);
extern "C" DECL_DLLEXPORT int32 preload_script(ptr pduel, const char* script, int32 len);
byte* default_script_reader(const char* script_name, int* len);
uint32 default_card_reader(uint32 code, card_data* data);
uint32 default_message_handler(void* pduel, uint32 msg_type);
......
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