Commit 9dda3094 authored by wind2009's avatar wind2009

Merge branch 'develop' into develop-8888

parents d3a70f2e f144324b
......@@ -23,44 +23,44 @@ These functions create the game itself and then manipulate it.
- `intptr_t create_duel(uint_fast32_t seed);`
Create a the instance of the duel with a PRNG seed.
- `void start_duel(intptr_t pduel, uint32 options);`
- `void start_duel(intptr_t pduel, uint32_t options);`
Start the duel.
- `void end_duel(intptr_t pduel);`
End the duel.
- `void set_player_info(intptr_t pduel, int32 playerid, int32 lp, int32 startcount, int32 drawcount);`
- `void set_player_info(intptr_t pduel, int32_t playerid, int32_t lp, int32_t startcount, int32_t drawcount);`
Set up the duel information.
- `void get_log_message(intptr_t pduel, char* buf);`
- `int32 get_message(intptr_t pduel, byte* buf);`
- `int32_t get_message(intptr_t pduel, byte* buf);`
- `int32 process(intptr_t pduel);`
- `int32_t process(intptr_t pduel);`
Do a game tick.
- `void new_card(intptr_t pduel, uint32 code, uint8 owner, uint8 playerid, uint8 location, uint8 sequence, uint8 position);`
- `void new_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position);`
Add a card to the duel state.
- `void new_tag_card(intptr_t pduel, uint32 code, uint8 owner, uint8 location);`
- `void new_tag_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t location);`
Add a new card to the tag pool.
- `int32 query_field_card(intptr_t pduel, uint8 playerid, uint8 location, uint32 query_flag, byte* buf, int32 use_cache);`
- `int32_t query_field_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint32_t query_flag, byte* buf, int32_t use_cache);`
Get a card in a specific location.
- `int32 query_field_count(intptr_t pduel, uint8 playerid, uint8 location);`
- `int32_t query_field_count(intptr_t pduel, uint8_t playerid, uint8_t location);`
Get the number of cards in a specific location.
- `int32 query_field_card(intptr_t pduel, uint8 playerid, uint8 location, uint32 query_flag, byte* buf, int32 use_cache);`
- `int32_t query_field_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint32_t query_flag, byte* buf, int32_t use_cache);`
Get all cards in some location.
- `int32 query_field_info(intptr_t pduel, byte* buf);`
- `int32_t query_field_info(intptr_t pduel, byte* buf);`
- `void set_responsei(intptr_t pduel, int32 value);`
- `void set_responsei(intptr_t pduel, int32_t value);`
- `void set_responseb(intptr_t pduel, byte* buf);`
- `int32 preload_script(intptr_t pduel, const char* script_name);`
- `int32_t preload_script(intptr_t pduel, const char* script_name);`
# Lua functions
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -6,16 +6,16 @@
constexpr int CARD_ARTWORK_VERSIONS_OFFSET = 20;
constexpr int SIZE_SETCODE = 16;
constexpr uint32 CARD_BLACK_LUSTER_SOLDIER2 = 5405695;
constexpr uint32_t 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;
constexpr uint32_t CARD_MARINE_DOLPHIN = 78734254;
constexpr uint32_t CARD_TWINKLE_MOSS = 13857930;
constexpr uint32_t CARD_TIMAEUS = 1784686;
constexpr uint32_t CARD_CRITIAS = 11082056;
constexpr uint32_t CARD_HERMOS = 46232525;
const std::unordered_map<uint32, uint32> second_code = {
const std::unordered_map<uint32_t, uint32_t> second_code = {
{CARD_MARINE_DOLPHIN, 17955766u},
{CARD_TWINKLE_MOSS, 17732278u},
{CARD_TIMAEUS, 10000050u},
......@@ -24,18 +24,18 @@ const std::unordered_map<uint32, uint32> second_code = {
};
struct card_data {
uint32 code{};
uint32 alias{};
uint32_t code{};
uint32_t 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{};
uint32_t type{};
uint32_t level{};
uint32_t attribute{};
uint32_t race{};
int32_t attack{};
int32_t defense{};
uint32_t lscale{};
uint32_t rscale{};
uint32_t link_marker{};
void clear() {
code = 0;
......@@ -53,7 +53,7 @@ struct card_data {
link_marker = 0;
}
bool is_setcode(uint32 value) const {
bool is_setcode(uint32_t value) const {
uint16_t settype = value & 0x0fff;
uint16_t setsubtype = value & 0xf000;
for (auto& x : setcode) {
......@@ -71,7 +71,7 @@ struct card_data {
return alias && (alias < code + CARD_ARTWORK_VERSIONS_OFFSET) && (code < alias + CARD_ARTWORK_VERSIONS_OFFSET);
}
void set_setcode(uint64 value) {
void set_setcode(uint64_t value) {
int ctr = 0;
while (value) {
if (value & 0xffff) {
......@@ -84,7 +84,7 @@ struct card_data {
setcode[i] = 0;
}
uint32 get_original_code() const {
uint32_t get_original_code() const {
return is_alternative() ? alias : code;
}
};
......
......@@ -10,15 +10,11 @@
#include <stdint.h>
#include <assert.h>
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
typedef unsigned char byte;
typedef long long int64;
typedef int int32;
typedef short int16;
typedef signed char int8;
inline bool check_playerid(int32_t playerid) {
return playerid >= 0 && playerid <= 1;
}
#define MATCH_ALL(x,y) (((x)&(y))==(y))
#define MATCH_ANY(x,y) ((x)&(y))
......@@ -39,10 +35,6 @@ typedef signed char int8;
#define PROCESSOR_WAITING 0x10000000
#define PROCESSOR_END 0x20000000
#ifndef NULL
#define NULL 0
#endif
#define MASTER_RULE3 3 //Master Rule 3 (2014)
#define NEW_MASTER_RULE 4 //New Master Rule (2017)
#define MASTER_RULE_2020 5 //Master Rule 2020
......@@ -197,7 +189,7 @@ typedef signed char int8;
#define STATUS_NO_LEVEL 0x0020
#define STATUS_BATTLE_RESULT 0x0040
#define STATUS_SPSUMMON_STEP 0x0080
#define STATUS_FORM_CHANGED 0x0100
#define STATUS_CANNOT_CHANGE_FORM 0x0100
#define STATUS_SUMMONING 0x0200
#define STATUS_EFFECT_ENABLED 0x0400
#define STATUS_SUMMON_TURN 0x0800
......
......@@ -52,7 +52,7 @@ void duel::clear() {
game_field->rose_card = 0;
game_field->rose_level = 0;
}
card* duel::new_card(uint32 code) {
card* duel::new_card(uint32_t code) {
card* pcard = new card(this);
cards.insert(pcard);
if (code != TEMP_CARD_ID)
......@@ -101,11 +101,11 @@ void duel::delete_effect(effect* peffect) {
effects.erase(peffect);
delete peffect;
}
int32 duel::read_buffer(byte* buf) {
int32_t duel::read_buffer(byte* buf) {
auto size = buffer_size();
if (size)
std::memcpy(buf, message_buffer.data(), size);
return (int32)size;
return (int32_t)size;
}
void duel::release_script_group() {
for(auto& pgroup : sgroups) {
......@@ -125,25 +125,25 @@ void duel::restore_assumes() {
void duel::write_buffer(const void* data, int size) {
vector_write_block(message_buffer, data, size);
}
void duel::write_buffer32(uint32 value) {
void duel::write_buffer32(uint32_t value) {
vector_write<uint32_t>(message_buffer, value);
}
void duel::write_buffer16(uint16 value) {
void duel::write_buffer16(uint16_t value) {
vector_write<uint16_t>(message_buffer, value);
}
void duel::write_buffer8(uint8 value) {
void duel::write_buffer8(uint8_t value) {
vector_write<unsigned char>(message_buffer, value);
}
void duel::clear_buffer() {
message_buffer.clear();
}
void duel::set_responsei(uint32 resp) {
void duel::set_responsei(uint32_t resp) {
game_field->returns.ivalue[0] = resp;
}
void duel::set_responseb(byte* resp) {
std::memcpy(game_field->returns.bvalue, resp, SIZE_RETURN_VALUE);
}
int32 duel::get_next_integer(int32 l, int32 h) {
int32_t duel::get_next_integer(int32_t l, int32_t h) {
if (game_field->core.duel_options & DUEL_OLD_REPLAY) {
return random.get_random_integer_old(l, h);
}
......
......@@ -42,10 +42,10 @@ public:
~duel();
void clear();
uint32 buffer_size() const {
return (uint32)message_buffer.size() & PROCESSOR_BUFFER_LEN;
uint32_t buffer_size() const {
return (uint32_t)message_buffer.size() & PROCESSOR_BUFFER_LEN;
}
card* new_card(uint32 code);
card* new_card(uint32_t code);
group* new_group();
group* new_group(card* pcard);
group* new_group(const card_set& cset);
......@@ -55,15 +55,15 @@ public:
void delete_effect(effect* peffect);
void release_script_group();
void restore_assumes();
int32 read_buffer(byte* buf);
int32_t read_buffer(byte* buf);
void write_buffer(const void* data, int size);
void write_buffer32(uint32 value);
void write_buffer16(uint16 value);
void write_buffer8(uint8 value);
void write_buffer32(uint32_t value);
void write_buffer16(uint16_t value);
void write_buffer8(uint8_t value);
void clear_buffer();
void set_responsei(uint32 resp);
void set_responsei(uint32_t resp);
void set_responseb(byte* resp);
int32 get_next_integer(int32 l, int32 h);
int32_t get_next_integer(int32_t l, int32_t h);
private:
group* register_group(group* pgroup);
};
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -27,8 +27,8 @@ public:
duel* pduel;
card_set container;
card_set::iterator it;
int32 ref_handle{ 0 };
uint32 is_readonly{ GTYPE_DEFAULT };
int32_t ref_handle{ 0 };
uint32_t is_readonly{ GTYPE_DEFAULT };
bool is_iterator_dirty{ true };
bool has_card(card* c) {
......
This diff is collapsed.
......@@ -23,7 +23,7 @@ class effect;
class group;
class duel;
enum LuaParamType : int32 {
enum LuaParamType : int32_t {
PARAM_TYPE_INT = 0x01,
PARAM_TYPE_STRING = 0x02,
PARAM_TYPE_CARD = 0x04,
......@@ -38,9 +38,9 @@ class interpreter {
public:
union lua_param {
void* ptr;
int32 integer;
int32_t integer;
};
using coroutine_map = std::unordered_map<int32, std::pair<lua_State*, int32>>;
using coroutine_map = std::unordered_map<int32_t, std::pair<lua_State*, int32_t>>;
using param_list = std::list<std::pair<lua_param, LuaParamType>>;
duel* pduel;
......@@ -50,10 +50,10 @@ public:
param_list params;
param_list resumes;
coroutine_map coroutines;
int32 no_action;
int32 call_depth;
int32 disable_action_check;
int32 preloaded;
int32_t no_action;
int32_t call_depth;
int32_t disable_action_check;
int32_t preloaded;
explicit interpreter(duel* pd);
~interpreter();
......@@ -64,28 +64,28 @@ public:
void register_group(group* pgroup);
void unregister_group(group* pgroup);
int32 load_script(const char* script_name);
int32 load_card_script(uint32 code);
int32_t load_script(const char* script_name);
int32_t load_card_script(uint32_t code);
void add_param(void* param, LuaParamType type, bool front = false);
void add_param(int32 param, LuaParamType type, bool front = false);
void add_param(int32_t param, LuaParamType type, bool front = false);
void push_param(lua_State* L, bool is_coroutine = false);
int32 call_function(int32 f, uint32 param_count, int32 ret_count);
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_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<lua_Integer>& result);
int32 call_coroutine(int32 f, uint32 param_count, int32* yield_value, uint16 step);
int32 clone_function_ref(int32 func_ref);
void* get_ref_object(int32 ref_handler);
int32_t call_function(int32_t f, uint32_t param_count, int32_t ret_count);
int32_t call_card_function(card* pcard, const char* f, uint32_t param_count, int32_t ret_count);
int32_t call_code_function(uint32_t code, const char* f, uint32_t param_count, int32_t ret_count);
int32_t check_condition(int32_t f, uint32_t param_count);
int32_t check_filter(lua_State* L, card* pcard, int32_t findex, int32_t extraargs);
int32_t get_operation_value(card* pcard, int32_t findex, int32_t extraargs);
int32_t get_function_value(int32_t f, uint32_t param_count);
int32_t get_function_value(int32_t f, uint32_t param_count, std::vector<lua_Integer>& result);
int32_t call_coroutine(int32_t f, uint32_t param_count, int32_t* yield_value, uint16_t step);
int32_t clone_function_ref(int32_t func_ref);
void* get_ref_object(int32_t ref_handler);
static void card2value(lua_State* L, card* pcard);
static void group2value(lua_State* L, group* pgroup);
static void effect2value(lua_State* L, effect* peffect);
static void function2value(lua_State* L, int32 func_ref);
static int32 get_function_handle(lua_State* L, int32 index);
static void function2value(lua_State* L, int32_t func_ref);
static int32_t get_function_handle(lua_State* L, int32_t index);
static duel* get_duel_info(lua_State* L);
static bool is_load_script(const card_data& data);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -28,35 +28,35 @@ class effect;
class interpreter;
typedef byte* (*script_reader)(const char*, int*);
typedef uint32 (*card_reader)(uint32, card_data*);
typedef uint32 (*message_handler)(intptr_t, uint32);
typedef uint32_t (*card_reader)(uint32_t, card_data*);
typedef uint32_t (*message_handler)(intptr_t, uint32_t);
extern "C" DECL_DLLEXPORT void set_script_reader(script_reader f);
extern "C" DECL_DLLEXPORT void set_card_reader(card_reader f);
extern "C" DECL_DLLEXPORT void set_message_handler(message_handler f);
byte* read_script(const char* script_name, int* len);
uint32 read_card(uint32 code, card_data* data);
uint32 handle_message(void* pduel, uint32 message_type);
uint32_t read_card(uint32_t code, card_data* data);
uint32_t handle_message(void* pduel, uint32_t message_type);
extern "C" DECL_DLLEXPORT intptr_t create_duel(uint_fast32_t seed);
extern "C" DECL_DLLEXPORT void start_duel(intptr_t pduel, uint32 options);
extern "C" DECL_DLLEXPORT void start_duel(intptr_t pduel, uint32_t options);
extern "C" DECL_DLLEXPORT void end_duel(intptr_t pduel);
extern "C" DECL_DLLEXPORT void set_player_info(intptr_t pduel, int32 playerid, int32 lp, int32 startcount, int32 drawcount);
extern "C" DECL_DLLEXPORT void set_player_info(intptr_t pduel, int32_t playerid, int32_t lp, int32_t startcount, int32_t drawcount);
extern "C" DECL_DLLEXPORT void get_log_message(intptr_t pduel, char* buf);
extern "C" DECL_DLLEXPORT int32 get_message(intptr_t pduel, byte* buf);
extern "C" DECL_DLLEXPORT uint32 process(intptr_t pduel);
extern "C" DECL_DLLEXPORT void new_card(intptr_t pduel, uint32 code, uint8 owner, uint8 playerid, uint8 location, uint8 sequence, uint8 position);
extern "C" DECL_DLLEXPORT void new_tag_card(intptr_t pduel, uint32 code, uint8 owner, uint8 location);
extern "C" DECL_DLLEXPORT int32 query_card(intptr_t pduel, uint8 playerid, uint8 location, uint8 sequence, int32 query_flag, byte* buf, int32 use_cache);
extern "C" DECL_DLLEXPORT int32 query_field_count(intptr_t pduel, uint8 playerid, uint8 location);
extern "C" DECL_DLLEXPORT int32 query_field_card(intptr_t pduel, uint8 playerid, uint8 location, uint32 query_flag, byte* buf, int32 use_cache);
extern "C" DECL_DLLEXPORT int32 query_field_info(intptr_t pduel, byte* buf);
extern "C" DECL_DLLEXPORT void set_responsei(intptr_t pduel, int32 value);
extern "C" DECL_DLLEXPORT int32_t get_message(intptr_t pduel, byte* buf);
extern "C" DECL_DLLEXPORT uint32_t process(intptr_t pduel);
extern "C" DECL_DLLEXPORT void new_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t playerid, uint8_t location, uint8_t sequence, uint8_t position);
extern "C" DECL_DLLEXPORT void new_tag_card(intptr_t pduel, uint32_t code, uint8_t owner, uint8_t location);
extern "C" DECL_DLLEXPORT int32_t query_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint8_t sequence, int32_t query_flag, byte* buf, int32_t use_cache);
extern "C" DECL_DLLEXPORT int32_t query_field_count(intptr_t pduel, uint8_t playerid, uint8_t location);
extern "C" DECL_DLLEXPORT int32_t query_field_card(intptr_t pduel, uint8_t playerid, uint8_t location, uint32_t query_flag, byte* buf, int32_t use_cache);
extern "C" DECL_DLLEXPORT int32_t query_field_info(intptr_t pduel, byte* buf);
extern "C" DECL_DLLEXPORT void set_responsei(intptr_t pduel, int32_t value);
extern "C" DECL_DLLEXPORT void set_responseb(intptr_t pduel, byte* buf);
extern "C" DECL_DLLEXPORT int32 preload_script(intptr_t pduel, const char* script_name);
extern "C" DECL_DLLEXPORT int32_t preload_script(intptr_t pduel, const char* script_name);
byte* default_script_reader(const char* script_name, int* len);
uint32 default_card_reader(uint32 code, card_data* data);
uint32 default_message_handler(intptr_t pduel, uint32 msg_type);
uint32_t default_card_reader(uint32_t code, card_data* data);
uint32_t default_message_handler(intptr_t pduel, uint32_t msg_type);
#endif /* OCGAPI_H_ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -7,9 +7,9 @@
#include "scriptlib.h"
#include "duel.h"
static int32 check_data_type(lua_State* L, int32 index, const char* tname) {
static int32_t check_data_type(lua_State* L, int32_t index, const char* tname) {
luaL_checkstack(L, 2, nullptr);
int32 result = FALSE;
int32_t result = FALSE;
if(lua_getmetatable(L, index)) {
lua_getglobal(L, tname);
if(lua_rawequal(L, -1, -2))
......@@ -18,11 +18,11 @@ static int32 check_data_type(lua_State* L, int32 index, const char* tname) {
}
return result;
}
int32 scriptlib::check_param(lua_State* L, int32 param_type, int32 index, int32 retfalse) {
int32_t scriptlib::check_param(lua_State* L, int32_t param_type, int32_t index, int32_t retfalse) {
switch (param_type) {
case PARAM_TYPE_CARD: {
luaL_checkstack(L, 1, nullptr);
int32 result = FALSE;
int32_t result = FALSE;
if(lua_isuserdata(L, index) && lua_getmetatable(L, index)) {
result = check_data_type(L, -1, "Card");
lua_pop(L, 1);
......@@ -70,12 +70,12 @@ int32 scriptlib::check_param(lua_State* L, int32 param_type, int32 index, int32
return FALSE;
}
int32 scriptlib::check_param_count(lua_State* L, int32 count) {
int32_t scriptlib::check_param_count(lua_State* L, int32_t count) {
if (lua_gettop(L) < count)
return luaL_error(L, "%d Parameters are needed.", count);
return TRUE;
}
int32 scriptlib::check_action_permission(lua_State* L) {
int32_t scriptlib::check_action_permission(lua_State* L) {
duel* pduel = interpreter::get_duel_info(L);
if(pduel->lua->no_action && !pduel->lua->disable_action_check)
return luaL_error(L, "Action is not allowed here.");
......
This diff is collapsed.
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