From ab26985fde42d29788c876c549036624d466248e Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 18 Jan 2021 12:44:22 -0800 Subject: [PATCH] Re-fix crewmate directions (without copy-pasting) This once again fixes the facing directions of crewmates upon room load, except now it covers more cases. So, here is the saga so far: - 2.0 (presumably) to 2.2: crewmate direction fix is special-cased at the end of mapclass::loadlevel(). Only covers crewmates created during the room load, does not cover crewmates created from scripts, only covers state 18 of crewmates. - 2.3 currently (after #220): crewmate direction fix is moved to entityclass::createentity(), which covers every avenue of crewmate creation (including from scripts), but still only covers state 18. - This commit: crewmate direction fix now covers every possible state of the crewmate, also does not copy-paste any code. What I've done instead is to make it so createentity() will immediately call updateentities() on the pushed-back entity. This is kludge-y, but is completely okay to do, because unlike other entities, crewmate entities never change their state or have any side-effects from double-evaluation, meaning calling updateentities() on them is idempotent and it's okay to call their updateentities() more than once. This does have the slight danger that if the states of crewmates were to change in the future to no longer be idempotent, this would end up resulting in a somewhat hard-to-track-down double-evaluation bug, but it's worth taking that risk. This fix is not applied to entity 14 (the supercrewmate) because it is possible that calling updateentities() on it will immediately remove the entity, which is not idempotent (it's changing the state of something outside the object). Supercrewmates are a bit difficult to work with outside of the main game anyways, and if you spawn them you could probably just use the changedir() script command to fix their direction, so I'm not inclined to fix this for them anyway. --- desktop_version/src/Entity.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/desktop_version/src/Entity.cpp b/desktop_version/src/Entity.cpp index 6bb8a702..68b696a6 100644 --- a/desktop_version/src/Entity.cpp +++ b/desktop_version/src/Entity.cpp @@ -2113,6 +2113,24 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo { entities.push_back(entity); } + + /* Fix crewmate facing directions + * This is a bit kludge-y but it's better than copy-pasting + * and is okay to do because entity 12 does not change state on its own + */ + if (entity.type == 12) + { + size_t indice; + if (reuse) + { + indice = entptr - entities.data(); + } + else + { + indice = entities.size() - 1; + } + updateentities(indice); + } } //Returns true if entity is removed