Commit e4a284aa authored by DailyShana's avatar DailyShana

clean up

parent dda0bd01
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "group.h" #include "group.h"
#include "interpreter.h" #include "interpreter.h"
#include "ocgapi.h" #include "ocgapi.h"
#include <memory.h>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
...@@ -84,13 +83,13 @@ card::card(duel* pd) { ...@@ -84,13 +83,13 @@ card::card(duel* pd) {
direct_attackable = 0; direct_attackable = 0;
summon_info = 0; summon_info = 0;
status = 0; status = 0;
memset(&q_cache, 0xff, sizeof(query_cache)); std::memset(&q_cache, 0xff, sizeof(query_cache));
equiping_target = 0; equiping_target = 0;
pre_equip_target = 0; pre_equip_target = 0;
overlay_target = 0; overlay_target = 0;
memset(&current, 0, sizeof(card_state)); std::memset(&current, 0, sizeof(card_state));
memset(&previous, 0, sizeof(card_state)); std::memset(&previous, 0, sizeof(card_state));
memset(&temp, 0xff, sizeof(card_state)); std::memset(&temp, 0xff, sizeof(card_state));
unique_pos[0] = unique_pos[1] = 0; unique_pos[0] = unique_pos[1] = 0;
spsummon_counter[0] = spsummon_counter[1] = 0; spsummon_counter[0] = spsummon_counter[1] = 0;
spsummon_counter_rst[0] = spsummon_counter_rst[1] = 0; spsummon_counter_rst[0] = spsummon_counter_rst[1] = 0;
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "effect.h" #include "effect.h"
#include "group.h" #include "group.h"
#include "ocgapi.h" #include "ocgapi.h"
#include <memory.h>
duel::duel() { duel::duel() {
lua = new interpreter(this); lua = new interpreter(this);
...@@ -96,7 +95,7 @@ void duel::delete_effect(effect* peffect) { ...@@ -96,7 +95,7 @@ void duel::delete_effect(effect* peffect) {
delete peffect; delete peffect;
} }
int32 duel::read_buffer(byte* buf) { int32 duel::read_buffer(byte* buf) {
memcpy(buf, buffer, bufferlen); std::memcpy(buf, buffer, bufferlen);
return bufferlen; return bufferlen;
} }
void duel::release_script_group() { void duel::release_script_group() {
...@@ -138,7 +137,7 @@ void duel::set_responsei(uint32 resp) { ...@@ -138,7 +137,7 @@ void duel::set_responsei(uint32 resp) {
game_field->returns.ivalue[0] = resp; game_field->returns.ivalue[0] = resp;
} }
void duel::set_responseb(byte* resp) { void duel::set_responseb(byte* resp) {
memcpy(game_field->returns.bvalue, resp, 64); std::memcpy(game_field->returns.bvalue, resp, 64);
} }
int32 duel::get_next_integer(int32 l, int32 h) { int32 duel::get_next_integer(int32 l, int32 h) {
return (int32) (random.real() * (h - l + 1)) + l; return (int32) (random.real() * (h - l + 1)) + l;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#ifndef FIELD_H_ #ifndef FIELD_H_
#define FIELD_H_ #define FIELD_H_
#include "memory.h"
#include "common.h" #include "common.h"
#include "effectset.h" #include "effectset.h"
#include <vector> #include <vector>
...@@ -19,7 +18,6 @@ ...@@ -19,7 +18,6 @@
#include <functional> #include <functional>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <cmath>
class card; class card;
struct card_data; struct card_data;
...@@ -206,7 +204,6 @@ struct processor { ...@@ -206,7 +204,6 @@ struct processor {
chain_list new_ochain_b; chain_list new_ochain_b;
chain_list new_ochain_h; chain_list new_ochain_h;
chain_list new_chains; chain_list new_chains;
chain_list tmp_chain;
delayed_effect_collection delayed_quick_tmp; delayed_effect_collection delayed_quick_tmp;
delayed_effect_collection delayed_quick_break; delayed_effect_collection delayed_quick_break;
delayed_effect_collection delayed_quick; delayed_effect_collection delayed_quick;
......
...@@ -832,7 +832,7 @@ int32 interpreter::call_function(int32 f, uint32 param_count, int32 ret_count) { ...@@ -832,7 +832,7 @@ int32 interpreter::call_function(int32 f, uint32 param_count, int32 ret_count) {
return OPERATION_FAIL; return OPERATION_FAIL;
} }
if (param_count != params.size()) { if (param_count != params.size()) {
sprintf(pduel->strbuffer, "\"CallFunction\": incorrect parameter count (%d expected, %ud pushed)", param_count, params.size()); sprintf(pduel->strbuffer, "\"CallFunction\": incorrect parameter count (%d expected, %zu pushed)", param_count, params.size());
handle_message(pduel, 1); handle_message(pduel, 1);
params.clear(); params.clear();
return OPERATION_FAIL; return OPERATION_FAIL;
...@@ -1029,7 +1029,7 @@ int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraarg ...@@ -1029,7 +1029,7 @@ int32 interpreter::get_operation_value(card* pcard, int32 findex, int32 extraarg
} }
return OPERATION_FAIL; return OPERATION_FAIL;
} }
result = round(lua_tonumber(current_state, -1)); result = std::round(lua_tonumber(current_state, -1));
lua_pop(current_state, 1); lua_pop(current_state, 1);
no_action--; no_action--;
call_depth--; call_depth--;
...@@ -1051,7 +1051,7 @@ int32 interpreter::get_function_value(int32 f, uint32 param_count) { ...@@ -1051,7 +1051,7 @@ int32 interpreter::get_function_value(int32 f, uint32 param_count) {
if (lua_isboolean(current_state, -1)) if (lua_isboolean(current_state, -1))
result = lua_toboolean(current_state, -1); result = lua_toboolean(current_state, -1);
else else
result = round(lua_tonumber(current_state, -1)); result = std::round(lua_tonumber(current_state, -1));
lua_pop(current_state, 1); lua_pop(current_state, 1);
no_action--; no_action--;
call_depth--; call_depth--;
...@@ -1085,7 +1085,7 @@ int32 interpreter::get_function_value(int32 f, uint32 param_count, std::vector<i ...@@ -1085,7 +1085,7 @@ int32 interpreter::get_function_value(int32 f, uint32 param_count, std::vector<i
if (lua_isboolean(current_state, index)) if (lua_isboolean(current_state, index))
return_value = lua_toboolean(current_state, index); return_value = lua_toboolean(current_state, index);
else else
return_value = round(lua_tonumber(current_state, index)); return_value = std::round(lua_tonumber(current_state, index));
result->push_back(return_value); result->push_back(return_value);
} }
lua_settop(current_state, stack_top); lua_settop(current_state, stack_top);
...@@ -1146,7 +1146,7 @@ int32 interpreter::call_coroutine(int32 f, uint32 param_count, uint32 * yield_va ...@@ -1146,7 +1146,7 @@ int32 interpreter::call_coroutine(int32 f, uint32 param_count, uint32 * yield_va
if (result == 0) { if (result == 0) {
coroutines.erase(f); coroutines.erase(f);
if(yield_value) if(yield_value)
*yield_value = lua_isboolean(rthread, -1) ? lua_toboolean(rthread, -1) : round(lua_tonumber(rthread, -1)); *yield_value = lua_isboolean(rthread, -1) ? lua_toboolean(rthread, -1) : lua_tointeger(rthread, -1);
current_state = lua_state; current_state = lua_state;
call_depth--; call_depth--;
if(call_depth == 0) { if(call_depth == 0) {
......
...@@ -24,6 +24,7 @@ extern "C" { ...@@ -24,6 +24,7 @@ extern "C" {
#include <list> #include <list>
#include <vector> #include <vector>
#include <cstring> #include <cstring>
#include <cmath>
class card; class card;
class effect; class effect;
......
...@@ -33,7 +33,7 @@ int32 scriptlib::duel_get_lp(lua_State *L) { ...@@ -33,7 +33,7 @@ int32 scriptlib::duel_get_lp(lua_State *L) {
int32 scriptlib::duel_set_lp(lua_State *L) { int32 scriptlib::duel_set_lp(lua_State *L) {
check_param_count(L, 2); check_param_count(L, 2);
int32 p = lua_tointeger(L, 1); int32 p = lua_tointeger(L, 1);
int32 lp = round(lua_tonumber(L, 2)); int32 lp = std::round(lua_tonumber(L, 2));
if(lp < 0) lp = 0; if(lp < 0) lp = 0;
if(p != 0 && p != 1) if(p != 0 && p != 1)
return 0; return 0;
......
...@@ -264,7 +264,7 @@ int32 scriptlib::effect_set_value(lua_State *L) { ...@@ -264,7 +264,7 @@ int32 scriptlib::effect_set_value(lua_State *L) {
if(lua_isboolean(L, 2)) if(lua_isboolean(L, 2))
peffect->value = lua_toboolean(L, 2); peffect->value = lua_toboolean(L, 2);
else else
peffect->value = round(lua_tonumber(L, 2)); peffect->value = std::round(lua_tonumber(L, 2));
} }
return 0; return 0;
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "card.h" #include "card.h"
#include "ocgapi.h" #include "ocgapi.h"
#include <memory.h>
#include <algorithm> #include <algorithm>
#include <stack> #include <stack>
...@@ -263,15 +262,14 @@ int32 field::select_card(uint16 step, uint8 playerid, uint8 cancelable, uint8 mi ...@@ -263,15 +262,14 @@ int32 field::select_card(uint16 step, uint8 playerid, uint8 cancelable, uint8 mi
} else { } else {
if(cancelable && returns.ivalue[0] == -1) if(cancelable && returns.ivalue[0] == -1)
return TRUE; return TRUE;
byte c[64];
memset(c, 0, 64);
if(returns.bvalue[0] < min || returns.bvalue[0] > max) { if(returns.bvalue[0] < min || returns.bvalue[0] > max) {
pduel->write_buffer8(MSG_RETRY); pduel->write_buffer8(MSG_RETRY);
return FALSE; return FALSE;
} }
uint8 m = core.select_cards.size(), v = 0; byte c[64] = {};
uint8 m = core.select_cards.size();
for(int32 i = 0; i < returns.bvalue[0]; ++i) { for(int32 i = 0; i < returns.bvalue[0]; ++i) {
v = returns.bvalue[i + 1]; uint8 v = returns.bvalue[i + 1];
if(v < 0 || v >= m || v >= 63 || c[v]) { if(v < 0 || v >= m || v >= 63 || c[v]) {
pduel->write_buffer8(MSG_RETRY); pduel->write_buffer8(MSG_RETRY);
return FALSE; return FALSE;
...@@ -442,11 +440,11 @@ int32 field::select_place(uint16 step, uint8 playerid, uint32 flag, uint8 count) ...@@ -442,11 +440,11 @@ int32 field::select_place(uint16 step, uint8 playerid, uint32 flag, uint8 count)
returns.bvalue[0] = 0; returns.bvalue[0] = 0;
return FALSE; return FALSE;
} else { } else {
uint8 pt = 0, p, l, s; uint8 pt = 0;
for(int8 i = 0; i < count; ++i) { for(int8 i = 0; i < count; ++i) {
p = returns.bvalue[pt]; uint8 p = returns.bvalue[pt];
l = returns.bvalue[pt + 1]; uint8 l = returns.bvalue[pt + 1];
s = returns.bvalue[pt + 2]; uint8 s = returns.bvalue[pt + 2];
if((p != 0 && p != 1) if((p != 0 && p != 1)
|| ((l != LOCATION_MZONE) && (l != LOCATION_SZONE)) || ((l != LOCATION_MZONE) && (l != LOCATION_SZONE))
|| ((0x1u << s) & (flag >> (((p == playerid) ? 0 : 16) + ((l == LOCATION_MZONE) ? 0 : 8))))) { || ((0x1u << s) & (flag >> (((p == playerid) ? 0 : 16) + ((l == LOCATION_MZONE) ? 0 : 8))))) {
...@@ -516,10 +514,9 @@ int32 field::select_tribute(uint16 step, uint8 playerid, uint8 cancelable, uint8 ...@@ -516,10 +514,9 @@ int32 field::select_tribute(uint16 step, uint8 playerid, uint8 cancelable, uint8
pduel->write_buffer8(min); pduel->write_buffer8(min);
pduel->write_buffer8(max); pduel->write_buffer8(max);
pduel->write_buffer8(core.select_cards.size()); pduel->write_buffer8(core.select_cards.size());
card* pcard;
std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort); std::sort(core.select_cards.begin(), core.select_cards.end(), card::card_operation_sort);
for(uint32 i = 0; i < core.select_cards.size(); ++i) { for(uint32 i = 0; i < core.select_cards.size(); ++i) {
pcard = core.select_cards[i]; card* pcard = core.select_cards[i];
pduel->write_buffer32(pcard->data.code); pduel->write_buffer32(pcard->data.code);
pduel->write_buffer8(pcard->current.controler); pduel->write_buffer8(pcard->current.controler);
pduel->write_buffer8(pcard->current.location); pduel->write_buffer8(pcard->current.location);
...@@ -530,12 +527,11 @@ int32 field::select_tribute(uint16 step, uint8 playerid, uint8 cancelable, uint8 ...@@ -530,12 +527,11 @@ int32 field::select_tribute(uint16 step, uint8 playerid, uint8 cancelable, uint8
} else { } else {
if(cancelable && returns.ivalue[0] == -1) if(cancelable && returns.ivalue[0] == -1)
return TRUE; return TRUE;
byte c[64];
memset(c, 0, 64);
if(returns.bvalue[0] > max) { if(returns.bvalue[0] > max) {
pduel->write_buffer8(MSG_RETRY); pduel->write_buffer8(MSG_RETRY);
return FALSE; return FALSE;
} }
byte c[64] = {};
uint8 m = core.select_cards.size(), tt = 0; uint8 m = core.select_cards.size(), tt = 0;
for(int32 i = 0; i < returns.bvalue[0]; ++i) { for(int32 i = 0; i < returns.bvalue[0]; ++i) {
int8 v = returns.bvalue[i + 1]; int8 v = returns.bvalue[i + 1];
...@@ -663,8 +659,7 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32 ...@@ -663,8 +659,7 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32
} }
return FALSE; return FALSE;
} else { } else {
byte c[64]; byte c[64] = {};
memset(c, 0, 64);
if(max) { if(max) {
int32 oparam[16]; int32 oparam[16];
int32 mcount = core.must_select_cards.size(); int32 mcount = core.must_select_cards.size();
...@@ -752,16 +747,17 @@ int32 field::sort_card(int16 step, uint8 playerid, uint8 is_chain) { ...@@ -752,16 +747,17 @@ int32 field::sort_card(int16 step, uint8 playerid, uint8 is_chain) {
} }
return FALSE; return FALSE;
} else { } else {
if(returns.bvalue[0] == -1) if(returns.ivalue[0] == -1)
return TRUE; return TRUE;
uint8 seq[64]; byte c[64] = {};
memset(seq, 0, 64); uint8 m = core.select_cards.size();
for(uint32 i = 0; i < core.select_cards.size(); ++i) { for(uint8 i = 0; i < m; ++i) {
if(returns.bvalue[i] < 0 || returns.bvalue[i] >= (int32)core.select_cards.size() || seq[(int32)returns.bvalue[i]]) { uint8 v = returns.bvalue[i];
if(v < 0 || v >= m || c[v]) {
pduel->write_buffer8(MSG_RETRY); pduel->write_buffer8(MSG_RETRY);
return FALSE; return FALSE;
} }
seq[(int32)returns.bvalue[i]] = 1; c[v] = 1;
} }
return TRUE; return TRUE;
} }
......
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