Skip to content

Commit

Permalink
[MIRROR] You no longer goofily swap with others trying to move in the…
Browse files Browse the repository at this point in the history
… same direction as you if you're not faster than them (#4834)

* [MIRROR] You no longer goofily swap with others trying to move in the same direction as you if you're not faster than them [MDB IGNORE] (#4142)

* You no longer goofily swap with others trying to move in the same direction as you if you're not faster than them (#85379)

## About The Pull Request

Currently if you and someone else try to move in the same direction
while standing next to each other, you'll end up swapping places
endlessly which is, while extremely funny, quite frustrating at times to
deal with. This PR prevents this from happening unless you're faster
than the other person, in which case you still push through them. This
way both of you will be able to move forward without goofy ass swapping.

I also moved out the ugly logic tree into its own proc for readability's
sake, I am not piling up more code on that.

## Why It's Good For The Game

Its frustrating to deal with and doesn't make much sense logically. This
just makes sure that if both of you want to move in a certain direction,
you'll be able to do so. You can currently achieve the same effect by
enabling combat mode, so it doesn't change anything balance-wise.

## Changelog
:cl:
qol: You no longer goofily swap with others trying to move in the same
direction as you if you're not faster than them
code: Moved mobswap check logic into a separate proc and made it more
readable
/:cl:

* You no longer goofily swap with others trying to move in the same direction as you if you're not faster than them

---------

Co-authored-by: SmArtKar <[email protected]>
Co-authored-by: NovaBot13 <[email protected]>

* [MIRROR] You no longer goofily swap with others trying to move in the same direction as you if you're not faster than them

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: SmArtKar <[email protected]>
Co-authored-by: NovaBot13 <[email protected]>
Co-authored-by: StealsThePRs <[email protected]>
  • Loading branch information
5 people authored Jul 31, 2024
1 parent b1a43c1 commit 64901d6
Showing 1 changed file with 41 additions and 21 deletions.
62 changes: 41 additions & 21 deletions code/modules/mob/living/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,8 @@
if(now_pushing)
return TRUE

var/they_can_move = TRUE
var/their_combat_mode = FALSE

if(isliving(M))
var/mob/living/L = M
their_combat_mode = L.combat_mode
they_can_move = L.mobility_flags & MOBILITY_MOVE
//Also spread diseases
for(var/thing in diseases)
var/datum/disease/D = thing
Expand Down Expand Up @@ -226,22 +221,7 @@
return TRUE

if(!M.buckled && !M.has_buckled_mobs())
var/mob_swap = FALSE
var/too_strong = (M.move_resist > move_force) //can't swap with immovable objects unless they help us
if(!they_can_move) //we have to physically move them
if(!too_strong)
mob_swap = TRUE
else
//You can swap with the person you are dragging on grab intent, and restrained people in most cases
if(M.pulledby == src && !too_strong)
mob_swap = TRUE
else if(
!(HAS_TRAIT(M, TRAIT_NOMOBSWAP) || HAS_TRAIT(src, TRAIT_NOMOBSWAP)) &&\
((HAS_TRAIT(M, TRAIT_RESTRAINED) && !too_strong) || !their_combat_mode) &&\
(HAS_TRAIT(src, TRAIT_RESTRAINED) || !combat_mode)
)
mob_swap = TRUE
if(mob_swap)
if(can_mobswap_with(M))
//switch our position with M
if(loc && !loc.Adjacent(M.loc))
return TRUE
Expand Down Expand Up @@ -294,6 +274,46 @@
if(prob(I.block_chance*2))
return

/mob/living/proc/can_mobswap_with(mob/other)
if (HAS_TRAIT(other, TRAIT_NOMOBSWAP) || HAS_TRAIT(src, TRAIT_NOMOBSWAP))
return FALSE

var/they_can_move = TRUE
var/their_combat_mode = FALSE

if(isliving(other))
var/mob/living/other_living = other
their_combat_mode = other_living.combat_mode
they_can_move = other_living.mobility_flags & MOBILITY_MOVE

var/too_strong = other.move_resist > move_force

// They cannot move, see if we can push through them
if (!they_can_move)
return !too_strong

// We are pulling them and can move through
if (other.pulledby == src && !too_strong)
return TRUE

// If we're in combat mode and not restrained we don't try to pass through people
if (combat_mode && !HAS_TRAIT(src, TRAIT_RESTRAINED))
return FALSE

// Nor can we pass through non-restrained people in combat mode (or if they're restrained but still too strong for us)
if (their_combat_mode && (!HAS_TRAIT(other, TRAIT_RESTRAINED) || too_strong))
return FALSE

if (isnull(other.client) || isnull(client))
return TRUE

// If both of us are trying to move in the same direction, let the fastest one through first
if (client.intended_direction == other.client.intended_direction)
return cached_multiplicative_slowdown < other.cached_multiplicative_slowdown

// Else, sure, let us pass
return TRUE

/mob/living/get_photo_description(obj/item/camera/camera)
var/list/holding = list()
var/len = length(held_items)
Expand Down

0 comments on commit 64901d6

Please sign in to comment.