Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset object animation state in a few places #4049

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading