Skip to content

Commit

Permalink
Reset object animation state in a few places
Browse files Browse the repository at this point in the history
- When going offworld.
- When moving a droid into a transporter.

This prevents a somewhat uncommon case where cyborgs are walking in-place inside menu buttons, for example.

Had to issue a `moveReallyStopDroid()` in the embark event cause units still retained speed inside the transporter...
  • Loading branch information
KJeff01 committed Aug 26, 2024
1 parent f1bf267 commit 84b93d9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
18 changes: 18 additions & 0 deletions src/baseobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,21 @@ StructureBounds getStructureBounds(BASE_STATS const *stats, Vector2i pos, uint16

return StructureBounds(map_coord(pos), Vector2i(1, 1)); // Default to a 1×1 tile.
}

// Reset animation state so some units don't walk in place in the menu sometimes.
void resetObjectAnimationState(BASE_OBJECT *psObj)
{
if (psObj == nullptr)
{
return;
}
if (psObj->type == OBJ_DROID || psObj->type == OBJ_STRUCTURE || psObj->type == OBJ_FEATURE)
{
psObj->timeAnimationStarted = 0;
psObj->animationEvent = ANIM_EVENT_NONE;
}
else
{
debug(LOG_WARNING, "Tried resetting animation state on unknown object type");
}
}
2 changes: 2 additions & 0 deletions src/baseobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@ Vector2i getStatsSize(BASE_STATS const *pType, uint16_t direction);
StructureBounds getStructureBounds(BASE_OBJECT const *object);
StructureBounds getStructureBounds(BASE_STATS const *stats, Vector2i pos, uint16_t direction);

void resetObjectAnimationState(BASE_OBJECT *psObj);

#endif // __INCLUDED_BASEOBJECT_H__
1 change: 1 addition & 0 deletions src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ static void saveMissionData()
{
orderDroid(psDroid, DORDER_STOP, ModeImmediate);
}
resetObjectAnimationState(psDroid);
}

resetHomeStructureObjects(); //get rid of soon-to-be illegal references of droids in repair facilities and rearming pads.
Expand Down
9 changes: 3 additions & 6 deletions src/move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1796,8 +1796,7 @@ static void moveUpdatePersonModel(DROID *psDroid, SDWORD speed, uint16_t directi
}
else if (psDroid->animationEvent == ANIM_EVENT_ACTIVE)
{
psDroid->timeAnimationStarted = 0; // turn off movement animation, since we stopped
psDroid->animationEvent = ANIM_EVENT_NONE;
resetObjectAnimationState(psDroid);
}
return;
}
Expand Down Expand Up @@ -1954,8 +1953,7 @@ static void moveUpdateCyborgModel(DROID *psDroid, SDWORD moveSpeed, uint16_t mov
{
if (psDroid->animationEvent == ANIM_EVENT_ACTIVE)
{
psDroid->timeAnimationStarted = 0;
psDroid->animationEvent = ANIM_EVENT_NONE;
resetObjectAnimationState(psDroid);
}
return;
}
Expand Down Expand Up @@ -2271,8 +2269,7 @@ void moveUpdateDroid(DROID *psDroid)
case MOVEINACTIVE:
if (psDroid->animationEvent == ANIM_EVENT_ACTIVE)
{
psDroid->timeAnimationStarted = 0;
psDroid->animationEvent = ANIM_EVENT_NONE;
resetObjectAnimationState(psDroid);
}
if (bStopped)
{
Expand Down
1 change: 1 addition & 0 deletions src/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ bool orderUpdateDroid(DROID *psDroid)
setDroidTarget(psDroid, nullptr);
psDroid->order.psObj = nullptr;
secondarySetState(psDroid, DSO_RETURN_TO_LOC, DSS_NONE);
moveReallyStopDroid(psDroid);

// Fire off embark event
transporterSetScriptCurrent(transporter);
Expand Down
3 changes: 1 addition & 2 deletions src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3781,8 +3781,7 @@ void structureUpdate(STRUCTURE *psBuilding, bool bMission)
if (!psBuilding->pFunctionality->resourceExtractor.psPowerGen
&& psBuilding->animationEvent == ANIM_EVENT_ACTIVE) // no power generator connected
{
psBuilding->timeAnimationStarted = 0; // so turn off animation, if any
psBuilding->animationEvent = ANIM_EVENT_NONE;
resetObjectAnimationState(psBuilding);
}
else if (psBuilding->pFunctionality->resourceExtractor.psPowerGen
&& psBuilding->animationEvent == ANIM_EVENT_NONE // we have a power generator, but no animation
Expand Down
3 changes: 3 additions & 0 deletions src/transporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,9 @@ void transporterAddDroid(DROID *psTransporter, DROID *psDroidToAdd)
}
return;
}

resetObjectAnimationState(psDroidToAdd);

if (onMission)
{
// removing from droid mission list
Expand Down

0 comments on commit 84b93d9

Please sign in to comment.