Commit e090c4f9 authored by Chen Bill's avatar Chen Bill Committed by GitHub

update check extra link (#664)

* fix warning C4267

* card: use const member function

* update field::check_extra_link

* update card::is_position
parent a83134ef
...@@ -1276,18 +1276,18 @@ uint32 card::get_rscale() { ...@@ -1276,18 +1276,18 @@ uint32 card::get_rscale() {
temp.rscale = UINT32_MAX; temp.rscale = UINT32_MAX;
return rscale; return rscale;
} }
uint32 card::get_link_marker() { uint32 card::get_link_marker() const {
if(!(data.type & TYPE_LINK)) if(!(data.type & TYPE_LINK))
return 0; return 0;
return data.link_marker; return data.link_marker;
} }
int32 card::is_link_marker(uint32 dir) { uint32 card::is_link_marker(uint32 dir) const {
return (int32)(get_link_marker() & dir); return get_link_marker() & dir;
} }
uint32 card::get_linked_zone() { uint32 card::get_linked_zone() const {
if(!(data.type & TYPE_LINK) || current.location != LOCATION_MZONE || is_treated_as_not_on_field()) if(!(data.type & TYPE_LINK) || current.location != LOCATION_MZONE || is_treated_as_not_on_field())
return 0; return 0;
int32 zones = 0; uint32 zones = 0;
int32 s = current.sequence; int32 s = current.sequence;
if(s > 0 && s <= 4 && is_link_marker(LINK_MARKER_LEFT)) if(s > 0 && s <= 4 && is_link_marker(LINK_MARKER_LEFT))
zones |= 1u << (s - 1); zones |= 1u << (s - 1);
...@@ -1340,10 +1340,10 @@ void card::get_linked_cards(card_set* cset) { ...@@ -1340,10 +1340,10 @@ void card::get_linked_cards(card_set* cset) {
pduel->game_field->get_cards_in_zone(cset, linked_zone, p, LOCATION_MZONE); pduel->game_field->get_cards_in_zone(cset, linked_zone, p, LOCATION_MZONE);
pduel->game_field->get_cards_in_zone(cset, linked_zone >> 16, 1 - p, LOCATION_MZONE); pduel->game_field->get_cards_in_zone(cset, linked_zone >> 16, 1 - p, LOCATION_MZONE);
} }
uint32 card::get_mutual_linked_zone() { uint32 card::get_mutual_linked_zone() const {
if(!(data.type & TYPE_LINK) || current.location != LOCATION_MZONE || is_treated_as_not_on_field()) if(!(data.type & TYPE_LINK) || current.location != LOCATION_MZONE || is_treated_as_not_on_field())
return 0; return 0;
int32 zones = 0; uint32 zones = 0;
int32 p = current.controler; int32 p = current.controler;
int32 s = current.sequence; int32 s = current.sequence;
uint32 linked_zone = get_linked_zone(); uint32 linked_zone = get_linked_zone();
...@@ -1351,15 +1351,15 @@ uint32 card::get_mutual_linked_zone() { ...@@ -1351,15 +1351,15 @@ uint32 card::get_mutual_linked_zone() {
for(int32 i = 0; i < 7; ++i, icheck <<= 1) { for(int32 i = 0; i < 7; ++i, icheck <<= 1) {
if(icheck & linked_zone) { if(icheck & linked_zone) {
card* pcard = pduel->game_field->player[p].list_mzone[i]; card* pcard = pduel->game_field->player[p].list_mzone[i];
if(pcard && (pcard->get_linked_zone() & (1u << s))) if(pcard && (pcard->get_linked_zone() & (0x1u << s)))
zones |= icheck; zones |= icheck;
} }
} }
icheck = 0x10000; icheck = 0x10000U;
for(uint32 i = 0; i < 7; ++i, icheck <<= 1) { for(uint32 i = 0; i < 7; ++i, icheck <<= 1) {
if(icheck & linked_zone) { if(icheck & linked_zone) {
card* pcard = pduel->game_field->player[1 - p].list_mzone[i]; card* pcard = pduel->game_field->player[1 - p].list_mzone[i];
if(pcard && (pcard->get_linked_zone() & (1u << (s + 16)))) if(pcard && (pcard->get_linked_zone() & (0x1u << (s + 16))))
zones |= icheck; zones |= icheck;
} }
} }
...@@ -1383,28 +1383,28 @@ int32 card::is_link_state() { ...@@ -1383,28 +1383,28 @@ int32 card::is_link_state() {
return TRUE; return TRUE;
int32 p = current.controler; int32 p = current.controler;
uint32 linked_zone = pduel->game_field->get_linked_zone(p); uint32 linked_zone = pduel->game_field->get_linked_zone(p);
if((linked_zone >> current.sequence) & 1) if((linked_zone >> current.sequence) & 0x1U)
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
int32 card::is_extra_link_state() { int32 card::is_extra_link_state() {
if(current.location != LOCATION_MZONE) if(current.location != LOCATION_MZONE)
return FALSE; return FALSE;
uint32 checked = 1u << current.sequence; uint32 checked = 0x1U << current.sequence;
uint32 linked_zone = get_mutual_linked_zone(); uint32 linked_zone = get_mutual_linked_zone();
const auto& list_mzone0 = pduel->game_field->player[current.controler].list_mzone; const auto& list_mzone0 = pduel->game_field->player[current.controler].list_mzone;
const auto& list_mzone1 = pduel->game_field->player[1 - current.controler].list_mzone; const auto& list_mzone1 = pduel->game_field->player[1 - current.controler].list_mzone;
while(true) { while(true) {
if(((linked_zone >> 5) | (linked_zone >> (16 + 6))) & ((linked_zone >> 6) | (linked_zone >> (16 + 5))) & 1) if(((linked_zone >> 5) | (linked_zone >> (16 + 6))) & ((linked_zone >> 6) | (linked_zone >> (16 + 5))) & 0x1U)
return TRUE; return TRUE;
int32 checking = (int32)(linked_zone & ~checked); uint32 checking = linked_zone & ~checked;
if(!checking) if(!checking)
return FALSE; return FALSE;
int32 rightmost = checking & (-checking); uint32 rightmost = checking & (-checking);
checked |= (uint32)rightmost; checked |= rightmost;
if(rightmost < 0x10000) { if(rightmost < 0x10000U) {
for(int32 i = 0; i < 7; ++i) { for(int32 i = 0; i < 7; ++i) {
if(rightmost & 1) { if(rightmost & 0x1U) {
card* pcard = list_mzone0[i]; card* pcard = list_mzone0[i];
linked_zone |= pcard->get_mutual_linked_zone(); linked_zone |= pcard->get_mutual_linked_zone();
break; break;
...@@ -1414,7 +1414,7 @@ int32 card::is_extra_link_state() { ...@@ -1414,7 +1414,7 @@ int32 card::is_extra_link_state() {
} else { } else {
rightmost >>= 16; rightmost >>= 16;
for(int32 i = 0; i < 7; ++i) { for(int32 i = 0; i < 7; ++i) {
if(rightmost & 1) { if(rightmost & 0x1U) {
card* pcard = list_mzone1[i]; card* pcard = list_mzone1[i];
uint32 zone = pcard->get_mutual_linked_zone(); uint32 zone = pcard->get_mutual_linked_zone();
linked_zone |= (zone << 16) | (zone >> 16); linked_zone |= (zone << 16) | (zone >> 16);
...@@ -1426,7 +1426,7 @@ int32 card::is_extra_link_state() { ...@@ -1426,7 +1426,7 @@ int32 card::is_extra_link_state() {
} }
return FALSE; return FALSE;
} }
int32 card::is_position(int32 pos) { int32 card::is_position(uint32 pos) const {
return current.position & pos; return current.position & pos;
} }
void card::set_status(uint32 x, int32 enabled) { void card::set_status(uint32 x, int32 enabled) {
...@@ -1522,7 +1522,7 @@ uint32 card::get_select_info_location(uint8 *deck_seq_pointer) { ...@@ -1522,7 +1522,7 @@ uint32 card::get_select_info_location(uint8 *deck_seq_pointer) {
return get_info_location(); return get_info_location();
} }
} }
int32 card::is_treated_as_not_on_field() { int32 card::is_treated_as_not_on_field() const {
return get_status(STATUS_SUMMONING | STATUS_SUMMON_DISABLED | STATUS_ACTIVATE_DISABLED | STATUS_SPSUMMON_STEP); return get_status(STATUS_SUMMONING | STATUS_SUMMON_DISABLED | STATUS_ACTIVATE_DISABLED | STATUS_SPSUMMON_STEP);
} }
void card::equip(card* target, uint32 send_msg) { void card::equip(card* target, uint32 send_msg) {
......
...@@ -262,15 +262,15 @@ public: ...@@ -262,15 +262,15 @@ public:
uint32 get_grave_race(uint8 playerid); uint32 get_grave_race(uint8 playerid);
uint32 get_lscale(); uint32 get_lscale();
uint32 get_rscale(); uint32 get_rscale();
uint32 get_link_marker(); uint32 get_link_marker() const;
int32 is_link_marker(uint32 dir); uint32 is_link_marker(uint32 dir) const;
uint32 get_linked_zone(); uint32 get_linked_zone() const;
void get_linked_cards(card_set* cset); void get_linked_cards(card_set* cset);
uint32 get_mutual_linked_zone(); uint32 get_mutual_linked_zone() const;
void get_mutual_linked_cards(card_set * cset); void get_mutual_linked_cards(card_set * cset);
int32 is_link_state(); int32 is_link_state();
int32 is_extra_link_state(); int32 is_extra_link_state();
int32 is_position(int32 pos); int32 is_position(uint32 pos) const;
void set_status(uint32 status, int32 enabled); void set_status(uint32 status, int32 enabled);
int32 get_status(uint32 status) const; int32 get_status(uint32 status) const;
int32 is_status(uint32 status) const; int32 is_status(uint32 status) const;
...@@ -279,7 +279,7 @@ public: ...@@ -279,7 +279,7 @@ public:
int32 is_all_column(); int32 is_all_column();
uint8 get_select_sequence(uint8 *deck_seq_pointer); uint8 get_select_sequence(uint8 *deck_seq_pointer);
uint32 get_select_info_location(uint8 *deck_seq_pointer); uint32 get_select_info_location(uint8 *deck_seq_pointer);
int32 is_treated_as_not_on_field(); int32 is_treated_as_not_on_field() const;
void equip(card* target, uint32 send_msg = TRUE); void equip(card* target, uint32 send_msg = TRUE);
void unequip(); void unequip();
......
...@@ -804,11 +804,11 @@ int32 field::get_szone_limit(uint8 playerid, uint8 uplayer, uint32 reason) { ...@@ -804,11 +804,11 @@ int32 field::get_szone_limit(uint8 playerid, uint8 uplayer, uint32 reason) {
} }
uint32 field::get_linked_zone(int32 playerid) { uint32 field::get_linked_zone(int32 playerid) {
uint32 zones = 0; uint32 zones = 0;
for(auto& pcard : player[playerid].list_mzone) { for(const auto& pcard : player[playerid].list_mzone) {
if(pcard) if(pcard)
zones |= pcard->get_linked_zone() & 0xff; zones |= pcard->get_linked_zone() & 0xffff;
} }
for(auto& pcard : player[1 - playerid].list_mzone) { for(const auto& pcard : player[1 - playerid].list_mzone) {
if(pcard) if(pcard)
zones |= pcard->get_linked_zone() >> 16; zones |= pcard->get_linked_zone() >> 16;
} }
...@@ -872,19 +872,19 @@ int32 field::check_extra_link(int32 playerid) { ...@@ -872,19 +872,19 @@ int32 field::check_extra_link(int32 playerid) {
if(!player[playerid].list_mzone[5] || !player[playerid].list_mzone[6]) if(!player[playerid].list_mzone[5] || !player[playerid].list_mzone[6])
return FALSE; return FALSE;
card* pcard = player[playerid].list_mzone[5]; card* pcard = player[playerid].list_mzone[5];
uint32 checked = 1u << 5; uint32 checked = 0x1u << 5;
uint32 linked_zone = pcard->get_mutual_linked_zone(); uint32 linked_zone = pcard->get_mutual_linked_zone();
while(true) { while(true) {
if((linked_zone >> 6) & 1) if((linked_zone >> 6) & 0x1U)
return TRUE; return TRUE;
int32 checking = (int32)(linked_zone & ~checked); uint32 checking = linked_zone & ~checked;
if(!checking) if(!checking)
return FALSE; return FALSE;
int32 rightmost = checking & (-checking); uint32 rightmost = checking & (-checking);
checked |= (uint32)rightmost; checked |= rightmost;
if(rightmost < 0x10000) { if(rightmost < 0x10000U) {
for(int32 i = 0; i < 7; ++i) { for(int32 i = 0; i < 7; ++i) {
if(rightmost & 1) { if(rightmost & 0x1U) {
pcard = player[playerid].list_mzone[i]; pcard = player[playerid].list_mzone[i];
linked_zone |= pcard->get_mutual_linked_zone(); linked_zone |= pcard->get_mutual_linked_zone();
break; break;
...@@ -894,7 +894,7 @@ int32 field::check_extra_link(int32 playerid) { ...@@ -894,7 +894,7 @@ int32 field::check_extra_link(int32 playerid) {
} else { } else {
rightmost >>= 16; rightmost >>= 16;
for(int32 i = 0; i < 7; ++i) { for(int32 i = 0; i < 7; ++i) {
if(rightmost & 1) { if(rightmost & 0x1U) {
pcard = player[1 - playerid].list_mzone[i]; pcard = player[1 - playerid].list_mzone[i];
uint32 zone = pcard->get_mutual_linked_zone(); uint32 zone = pcard->get_mutual_linked_zone();
linked_zone |= (zone << 16) | (zone >> 16); linked_zone |= (zone << 16) | (zone >> 16);
...@@ -1662,7 +1662,7 @@ int32 field::filter_field_card(uint8 self, uint32 location1, uint32 location2, g ...@@ -1662,7 +1662,7 @@ int32 field::filter_field_card(uint8 self, uint32 location1, uint32 location2, g
} }
if (pgroup) if (pgroup)
pgroup->container.insert(result.begin(), result.end()); pgroup->container.insert(result.begin(), result.end());
return result.size(); return (int32)result.size();
} }
effect* field::is_player_affected_by_effect(uint8 playerid, uint32 code) { effect* field::is_player_affected_by_effect(uint8 playerid, uint32 code) {
auto rg = effects.aura_effect.equal_range(code); auto rg = effects.aura_effect.equal_range(code);
......
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