Skip to content

Commit

Permalink
no longer load script for temp card (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
salix5 authored Dec 2, 2024
1 parent 9b4a241 commit f150c9a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion duel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void duel::clear() {
card* duel::new_card(uint32 code) {
card* pcard = new card(this);
cards.insert(pcard);
if(code)
if (code != TEMP_CARD_ID)
::read_card(code, &(pcard->data));
pcard->data.code = code;
lua->register_card(pcard);
Expand Down
8 changes: 5 additions & 3 deletions interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void interpreter::register_card(card *pcard) {
lua_setmetatable(current_state, -2); //-1
lua_pop(current_state, 1); //-1
//Initial
if(pcard->data.code && is_load_script(pcard->data)) {
if(is_load_script(pcard->data)) {
pcard->set_status(STATUS_INITIALIZING, TRUE);
add_param(pcard, PARAM_TYPE_CARD);
call_card_function(pcard, "initial_effect", 1, 0);
Expand Down Expand Up @@ -669,11 +669,13 @@ int32 interpreter::get_function_handle(lua_State* L, int32 index) {
int32 ref = luaL_ref(L, LUA_REGISTRYINDEX);
return ref;
}
duel* interpreter::get_duel_info(lua_State * L) {
duel* interpreter::get_duel_info(lua_State* L) {
duel* pduel;
std::memcpy(&pduel, lua_getextraspace(L), LUA_EXTRASPACE);
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);
}
2 changes: 1 addition & 1 deletion interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class interpreter {
static void function2value(lua_State* L, int32 func_ref);
static int32 get_function_handle(lua_State* L, int32 index);
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>
static int sprintf(char (&buffer)[N], const char* format, TR... args) {
Expand Down
6 changes: 5 additions & 1 deletion ocgapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
#include <cstdio>
#include <cstring>
#include <set>
#include "ocgapi.h"
#include "duel.h"
#include "card.h"
Expand All @@ -14,7 +15,6 @@
#include "field.h"
#include "interpreter.h"
#include "buffer.h"
#include <set>

static script_reader sreader = default_script_reader;
static card_reader creader = default_card_reader;
Expand All @@ -35,6 +35,10 @@ byte* read_script(const char* script_name, int* len) {
return sreader(script_name, len);
}
uint32 read_card(uint32 code, card_data* data) {
if (code == TEMP_CARD_ID) {
data->clear();
return 0;
}
return creader(code, data);
}
uint32 handle_message(void* pduel, uint32 msg_type) {
Expand Down
1 change: 1 addition & 0 deletions ocgapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define LEN_FAIL 0
#define LEN_EMPTY 4
#define LEN_HEADER 8
#define TEMP_CARD_ID 0

class card;
struct card_data;
Expand Down

0 comments on commit f150c9a

Please sign in to comment.