Commit 96adddc1 authored by salix5's avatar salix5

fix right shift, bitwise and in playerop.cpp

parent deda06c5
......@@ -53,11 +53,11 @@ int32 field::select_battle_command(uint16 step, uint8 playerid) {
pduel->write_buffer8(0);
return FALSE;
} else {
uint32 t = returns.ivalue[0] & 0xffff;
uint32 s = returns.ivalue[0] >> 16;
int32 t = (uint32)returns.ivalue[0] & 0xffff;
int32 s = (uint32)returns.ivalue[0] >> 16;
if(t < 0 || t > 3 || s < 0
|| (t == 0 && s >= core.select_chains.size())
|| (t == 1 && s >= core.attackable_cards.size())
|| (t == 0 && s >= (int32)core.select_chains.size())
|| (t == 1 && s >= (int32)core.attackable_cards.size())
|| (t == 2 && !core.to_m2)
|| (t == 3 && !core.to_ep)) {
pduel->write_buffer8(MSG_RETRY);
......@@ -140,18 +140,18 @@ int32 field::select_idle_command(uint16 step, uint8 playerid) {
pduel->write_buffer8(0);
return FALSE;
} else {
uint32 t = returns.ivalue[0] & 0xffff;
uint32 s = returns.ivalue[0] >> 16;
int32 t = (uint32)returns.ivalue[0] & 0xffff;
int32 s = (uint32)returns.ivalue[0] >> 16;
if(t < 0 || t > 8 || s < 0
|| (t == 0 && s >= core.summonable_cards.size())
|| (t == 1 && s >= core.spsummonable_cards.size())
|| (t == 2 && s >= core.repositionable_cards.size())
|| (t == 3 && s >= core.msetable_cards.size())
|| (t == 4 && s >= core.ssetable_cards.size())
|| (t == 5 && s >= core.select_chains.size())
|| (t == 0 && s >= (int32)core.summonable_cards.size())
|| (t == 1 && s >= (int32)core.spsummonable_cards.size())
|| (t == 2 && s >= (int32)core.repositionable_cards.size())
|| (t == 3 && s >= (int32)core.msetable_cards.size())
|| (t == 4 && s >= (int32)core.ssetable_cards.size())
|| (t == 5 && s >= (int32)core.select_chains.size())
|| (t == 6 && (infos.phase != PHASE_MAIN1 || !core.to_bp))
|| (t == 7 && !core.to_ep)
|| (t == 8 && !(infos.can_shuffle && player[playerid].list_hand.size() > 1))) {
|| (t == 8 && !(infos.can_shuffle && (int32)player[playerid].list_hand.size() > 1))) {
pduel->write_buffer8(MSG_RETRY);
return FALSE;
}
......@@ -386,7 +386,7 @@ int32 field::select_place(uint16 step, uint8 playerid, uint32 flag, uint8 count)
if(step == 0) {
if((playerid == 1) && (core.duel_options & DUEL_SIMPLE_AI)) {
flag = ~flag;
int32 filter;
uint32 filter;
int32 pzone = 0;
if(flag & 0x7f) {
returns.bvalue[0] = 1;
......@@ -441,7 +441,8 @@ int32 field::select_place(uint16 step, uint8 playerid, uint32 flag, uint8 count)
} else {
uint8 pt = 0;
uint32 selected = 0;
for(int8 i = 0; i < 1 || i < count; ++i) {
int32 len = std::max(1, (int32)count);
for (int32 i = 0; i < len; ++i) {
uint8 p = returns.bvalue[pt];
uint8 l = returns.bvalue[pt + 1];
uint8 s = returns.bvalue[pt + 2];
......@@ -453,10 +454,10 @@ int32 field::select_place(uint16 step, uint8 playerid, uint32 flag, uint8 count)
pduel->write_buffer8(MSG_RETRY);
return FALSE;
}
if(sel & (0x1 << 5))
sel |= 0x1 << (16 + 6);
if(sel & (0x1 << 6))
sel |= 0x1 << (16 + 5);
if(sel & (0x1u << 5))
sel |= 0x1u << (16 + 6);
if(sel & (0x1u << 6))
sel |= 0x1u << (16 + 5);
selected |= sel;
pt += 3;
}
......@@ -475,11 +476,11 @@ int32 field::select_position(uint16 step, uint8 playerid, uint32 code, uint8 pos
return TRUE;
}
if((playerid == 1) && (core.duel_options & DUEL_SIMPLE_AI)) {
if(positions & 0x4)
if((uint32)positions & 0x4)
returns.ivalue[0] = 0x4;
else if(positions & 0x1)
else if((uint32)positions & 0x1)
returns.ivalue[0] = 0x1;
else if(positions & 0x8)
else if((uint32)positions & 0x8)
returns.ivalue[0] = 0x8;
else
returns.ivalue[0] = 0x2;
......@@ -621,7 +622,7 @@ int32 field::select_counter(uint16 step, uint8 playerid, uint16 countertype, uin
}
return TRUE;
}
static int32 select_sum_check1(const int32* oparam, int32 size, int32 index, int32 acc, int32 opmin) {
static int32 select_sum_check1(const uint32* oparam, int32 size, int32 index, int32 acc, int32 opmin) {
if(acc == 0 || index == size)
return FALSE;
int32 o1 = oparam[index] & 0xffff;
......@@ -650,7 +651,7 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32
if(max < min)
max = min;
pduel->write_buffer8(playerid);
pduel->write_buffer32(acc & 0xffff);
pduel->write_buffer32((uint32)acc & 0xffff);
pduel->write_buffer8(min);
pduel->write_buffer8(max);
pduel->write_buffer8((uint8)core.must_select_cards.size());
......@@ -673,9 +674,11 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32
return FALSE;
} else {
std::set<int32> c;
int32 mcount = (int32)core.must_select_cards.size();
if (mcount > UINT8_MAX)
mcount = UINT8_MAX;
if(max) {
int32 oparam[16];
int32 mcount = (int32)core.must_select_cards.size();
uint32 oparam[512]{};
if(returns.bvalue[0] < min + mcount || returns.bvalue[0] > max + mcount) {
pduel->write_buffer8(MSG_RETRY);
return FALSE;
......@@ -698,15 +701,14 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32
}
return TRUE;
} else {
int32 mcount = (int32)core.must_select_cards.size();
int32 sum = 0, mx = 0, mn = 0x7fffffff;
for(int32 i = 0; i < mcount; ++i) {
int32 op = core.must_select_cards[i]->sum_param;
uint32 op = core.must_select_cards[i]->sum_param;
int32 o1 = op & 0xffff;
int32 o2 = op >> 16;
int32 ms = (o2 && o2 < o1) ? o2 : o1;
sum += ms;
mx += (o2 > o1) ? o2 : o1;
mx += std::max(o1, o2);
if(ms < mn)
mn = ms;
}
......@@ -718,12 +720,12 @@ int32 field::select_with_sum_limit(int16 step, uint8 playerid, int32 acc, int32
return FALSE;
}
c.insert(v);
int32 op = core.select_cards[v]->sum_param;
uint32 op = core.select_cards[v]->sum_param;
int32 o1 = op & 0xffff;
int32 o2 = op >> 16;
int32 ms = (o2 && o2 < o1) ? o2 : o1;
sum += ms;
mx += (o2 > o1) ? o2 : o1;
mx += std::max(o1, o2);
if(ms < mn)
mn = ms;
}
......
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