Skip to content

Commit

Permalink
ocgapi: update signature of start_duel(), add player_info::szone_size (
Browse files Browse the repository at this point in the history
…#620)

* default init

* add player_info::szone_size

actual size of LOCATION_SZONE in current rule

* ocgapi: update signature of start_duel()
  • Loading branch information
salix5 committed Aug 29, 2024
1 parent 12abaf9 commit c48f795
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 44 deletions.
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef signed char int8;
#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
#define CURRENT_RULE 5
Expand Down
34 changes: 7 additions & 27 deletions field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,7 @@ bool tevent::operator< (const tevent& v) const {
}
field::field(duel* pduel) {
this->pduel = pduel;
infos.field_id = 1;
infos.copy_id = 1;
infos.can_shuffle = TRUE;
infos.turn_id = 0;
infos.turn_id_by_player[0] = 0;
infos.turn_id_by_player[1] = 0;
infos.card_id = 1;
infos.phase = 0;
infos.turn_player = 0;
for (int32 i = 0; i < 2; ++i) {
//cost[i].count = 0;
//cost[i].amount = 0;
player[i].lp = 8000;
player[i].start_count = 5;
player[i].draw_count = 1;
player[i].disabled_location = 0;
player[i].used_location = 0;
player[i].extra_p_count = 0;
player[i].tag_extra_p_count = 0;
player[i].list_mzone.resize(7, 0);
player[i].list_szone.resize(8, 0);
player[i].list_main.reserve(60);
Expand All @@ -82,8 +64,6 @@ field::field(duel* pduel) {
player[i].list_remove.reserve(75);
player[i].list_extra.reserve(30);
}
returns = { 0 };
temp_card = nullptr;
}
void field::reload_field_info() {
pduel->write_buffer8(MSG_RELOAD_FIELD);
Expand Down Expand Up @@ -300,10 +280,10 @@ void field::move_card(uint8 playerid, card* pcard, uint8 location, uint8 sequenc
if (playerid == preplayer && sequence == presequence)
return;
if(location == LOCATION_MZONE) {
if(sequence >= player[playerid].list_mzone.size() || player[playerid].list_mzone[sequence])
if(sequence >= (int32)player[playerid].list_mzone.size() || player[playerid].list_mzone[sequence])
return;
} else {
if(sequence >= player[playerid].list_szone.size() || player[playerid].list_szone[sequence])
if(sequence >= player[playerid].szone_size || player[playerid].list_szone[sequence])
return;
}
if(preplayer == playerid) {
Expand Down Expand Up @@ -511,14 +491,14 @@ card* field::get_field_card(uint8 playerid, uint32 general_location, uint8 seque
return nullptr;
switch(general_location) {
case LOCATION_MZONE: {
if(sequence < player[playerid].list_mzone.size())
if(sequence < (int32)player[playerid].list_mzone.size())
return player[playerid].list_mzone[sequence];
else
return nullptr;
break;
}
case LOCATION_SZONE: {
if(sequence < player[playerid].list_szone.size())
if(sequence < player[playerid].szone_size)
return player[playerid].list_szone[sequence];
else
return nullptr;
Expand Down Expand Up @@ -585,7 +565,7 @@ int32 field::is_location_useable(uint8 playerid, uint32 general_location, uint8
return FALSE;
uint32 flag = player[playerid].disabled_location | player[playerid].used_location;
if (general_location == LOCATION_MZONE) {
if (sequence >= (int32)player[0].list_mzone.size())
if (sequence >= (int32)player[playerid].list_mzone.size())
return FALSE;
if(flag & (0x1u << sequence))
return FALSE;
Expand All @@ -595,7 +575,7 @@ int32 field::is_location_useable(uint8 playerid, uint32 general_location, uint8
return FALSE;
}
} else if (general_location == LOCATION_SZONE) {
if (sequence >= (int32)player[0].list_szone.size())
if (sequence >= player[playerid].szone_size)
return FALSE;
if(flag & (0x100u << sequence))
return FALSE;
Expand Down Expand Up @@ -1127,7 +1107,7 @@ void field::refresh_player_info(uint8 playerid) {
if (player[playerid].list_mzone[i])
used_flag |= 0x1U << i;
}
for (int32 i = 0; i < (int32)player[playerid].list_szone.size(); ++i) {
for (int32 i = 0; i < player[playerid].szone_size; ++i) {
if (player[playerid].list_szone[i])
used_flag |= 0x100U << i;
}
Expand Down
29 changes: 15 additions & 14 deletions field.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ struct chain {
};

struct player_info {
int32 lp{ 0 };
int32 start_count{ 0 };
int32 draw_count{ 0 };
int32 lp{ 8000 };
int32 start_count{ 5 };
int32 draw_count{ 1 };
uint32 used_location{ 0 };
uint32 disabled_location{ 0 };
uint32 extra_p_count{ 0 };
uint32 tag_extra_p_count{ 0 };
int32 szone_size{ 6 };
card_vector list_mzone;
card_vector list_szone;
card_vector list_main;
Expand Down Expand Up @@ -127,19 +128,19 @@ struct field_effect {
grant_effect_container grant_effect;
};
struct field_info {
int32 field_id{ 0 };
int16 copy_id{ 0 };
int16 turn_id{ 0 };
int32 field_id{ 1 };
int16 copy_id{ 1 };
int16 turn_id{};
int16 turn_id_by_player[2]{};
int16 card_id{ 0 };
uint16 phase{ 0 };
uint8 turn_player{ 0 };
int16 card_id{ 1 };
uint16 phase{};
uint8 turn_player{};
uint8 priorities[2]{};
uint8 can_shuffle{ TRUE };
};
struct lpcost {
int32 count{ 0 };
int32 amount{ 0 };
int32 count{};
int32 amount{};
int32 lpstack[8]{};
};
struct processor_unit {
Expand Down Expand Up @@ -306,7 +307,7 @@ struct processor {
uint8 extra_summon[2]{};
int32 spe_effect[2]{};
int32 last_select_hint[2]{ 0 };
int32 duel_options{ 0 };
uint32 duel_options{ 0 };
int32 duel_rule{ CURRENT_RULE };
uint32 copy_reset{ 0 };
int32 copy_reset_count{ 0 };
Expand Down Expand Up @@ -374,12 +375,12 @@ class field {

duel* pduel;
player_info player[2];
card* temp_card;
card* temp_card{};
field_info infos;
//lpcost cost[2];
field_effect effects;
processor core;
return_value returns;
return_value returns{};
tevent nil_event;

static int32 field_used_count[32];
Expand Down
4 changes: 4 additions & 0 deletions libdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ int32 scriptlib::debug_reload_field_begin(lua_State *L) {
pduel->game_field->core.duel_rule = 1;
else
pduel->game_field->core.duel_rule = CURRENT_RULE;
if (pduel->game_field->core.duel_rule == MASTER_RULE3) {
pduel->game_field->player[0].szone_size = 8;
pduel->game_field->player[1].szone_size = 8;
}
return 0;
}
int32 scriptlib::debug_reload_field_end(lua_State *L) {
Expand Down
8 changes: 6 additions & 2 deletions ocgapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,20 @@ extern "C" DECL_DLLEXPORT intptr_t create_duel(uint_fast32_t seed) {
pduel->random.reset(seed);
return (intptr_t)pduel;
}
extern "C" DECL_DLLEXPORT void start_duel(intptr_t pduel, int32 options) {
extern "C" DECL_DLLEXPORT void start_duel(intptr_t pduel, uint32 options) {
duel* pd = (duel*)pduel;
pd->game_field->core.duel_options |= options & 0xffff;
int32 duel_rule = options >> 16;
if(duel_rule)
pd->game_field->core.duel_rule = duel_rule;
else if(options & DUEL_OBSOLETE_RULING) //provide backward compatibility with replay
pd->game_field->core.duel_rule = 1;
else if(!pd->game_field->core.duel_rule)
if (pd->game_field->core.duel_rule < 1 || pd->game_field->core.duel_rule > CURRENT_RULE)
pd->game_field->core.duel_rule = CURRENT_RULE;
if (pd->game_field->core.duel_rule == MASTER_RULE3) {
pd->game_field->player[0].szone_size = 8;
pd->game_field->player[1].szone_size = 8;
}
pd->game_field->core.shuffle_hand_check[0] = FALSE;
pd->game_field->core.shuffle_hand_check[1] = FALSE;
pd->game_field->core.shuffle_deck_check[0] = FALSE;
Expand Down
2 changes: 1 addition & 1 deletion ocgapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ uint32 read_card(uint32 code, card_data* data);
uint32 handle_message(void* pduel, uint32 message_type);

extern "C" DECL_DLLEXPORT intptr_t create_duel(uint_fast32_t seed);
extern "C" DECL_DLLEXPORT void start_duel(intptr_t pduel, int32 options);
extern "C" DECL_DLLEXPORT void start_duel(intptr_t pduel, uint32 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 get_log_message(intptr_t pduel, char* buf);
Expand Down

0 comments on commit c48f795

Please sign in to comment.