From fae14f4e98c98773561179648f06f9b98fdf4e3c Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 5 Sep 2020 17:38:38 -0700 Subject: [PATCH] De-duplicate stuck prevention for the player/SCM Stuck prevention (pushing the player/supercrewmate out if they are inside a wall) has been factored out into its own function, so it's no longer copy-pasted but slightly tweaked just for the supercrewmate. --- desktop_version/src/Entity.cpp | 60 +++++++++++++++------------------- desktop_version/src/Entity.h | 2 ++ 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/desktop_version/src/Entity.cpp b/desktop_version/src/Entity.cpp index fdf13d55..853cf539 100644 --- a/desktop_version/src/Entity.cpp +++ b/desktop_version/src/Entity.cpp @@ -4603,43 +4603,12 @@ void entityclass::entitycollisioncheck() } //can't have the player being stuck... - int j = getplayer(); - skipdirblocks = true; - if (j > -1 && !testwallsx(j, entities[j].xp, entities[j].yp)) - { - //Let's try to get out... - if (entities[j].rule == 0) - { - if(game.gravitycontrol==0) - { - entities[j].yp -= 3; - } - else - { - entities[j].yp += 3; - } - } - } - skipdirblocks = false; + stuckprevention(getplayer()); //Can't have the supercrewmate getting stuck either! if (game.supercrewmate) { - j = getscm(); - skipdirblocks = true; - if (!testwallsx(j, entities[j].xp, entities[j].yp)) - { - //Let's try to get out... - if(game.gravitycontrol==0) - { - entities[j].yp -= 3; - } - else - { - entities[j].yp += 3; - } - } - skipdirblocks = false; + stuckprevention(getscm()); } //Is the player colliding with any damageblocks? @@ -4802,3 +4771,28 @@ void entityclass::collisioncheck(int i, int j, bool scm /*= false*/) break; } } + +void entityclass::stuckprevention(int t) +{ + if (!INBOUNDS(t, entities)) + { + puts("stuckprevention() out-of-bounds!"); + return; + } + + skipdirblocks = true; + // Can't have this entity (player or supercrewmate) being stuck... + if (!testwallsx(t, entities[t].xp, entities[t].yp)) + { + // Let's try to get out... + if (game.gravitycontrol == 0) + { + entities[t].yp -= 3; + } + else + { + entities[t].yp += 3; + } + } + skipdirblocks = false; +} diff --git a/desktop_version/src/Entity.h b/desktop_version/src/Entity.h index 27826839..3135a676 100644 --- a/desktop_version/src/Entity.h +++ b/desktop_version/src/Entity.h @@ -160,6 +160,8 @@ public: void collisioncheck(int i, int j, bool scm = false); + void stuckprevention(int t); + std::vector entities;