Skip to content

Commit fe3b72b

Browse files
committed
fix NextFireTimestamp
Changes `NextFireTimestamp` to work as advertised. Fixes scp-fs2open#6256.
1 parent f5a268b commit fe3b72b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

code/scripting/api/objs/subsystem.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,12 +649,21 @@ ADE_VIRTVAR(NextFireTimestamp, l_Subsystem, "number", "The next time the turret
649649
if (!sso->isValid())
650650
return ade_set_error(L, "f", -1.0f);
651651

652-
if(ADE_SETTING_VAR)
652+
float currentTime = f2fl(Missiontime);
653+
654+
if (ADE_SETTING_VAR)
653655
{
654-
sso->ss->turret_next_fire_stamp = (int)(newVal * 1000);
656+
float delta = newVal - currentTime;
657+
if (delta < 0.0f)
658+
{
659+
Warning(LOCATION, "NextFireTimestamp: Specified value is in the past; setting to the current time");
660+
delta = 0.0f;
661+
}
662+
663+
sso->ss->turret_next_fire_stamp = timestamp(fl2i(delta * MILLISECONDS_PER_SECOND));
655664
}
656665

657-
return ade_set_args(L, "f", sso->ss->turret_next_fire_stamp / 1000.0f);
666+
return ade_set_args(L, "f", currentTime + timestamp_until(sso->ss->turret_next_fire_stamp) / i2fl(MILLISECONDS_PER_SECOND));
658667
}
659668

660669
ADE_VIRTVAR(ModelPath, l_Subsystem, "modelpath", "The model path points belonging to this subsystem", "modelpath",

0 commit comments

Comments
 (0)