Skip to content

Commit

Permalink
Set timer padding sexp (#5535)
Browse files Browse the repository at this point in the history
* set timer padding sexp

* allow negative padding
  • Loading branch information
MjnMixael authored Oct 14, 2023
1 parent febd8cd commit 02233fc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
4 changes: 2 additions & 2 deletions code/hud/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1778,8 +1778,8 @@ void HudGaugeMissionTime::render(float /*frametime*/)
int minutes=0;
int seconds=0;

mission_time = f2fl(Missiontime); // convert to seconds

mission_time = f2fl(Missiontime) + (float)The_mission.HUD_timer_padding; // convert to seconds
minutes=(int)(mission_time/60);
seconds=(int)mission_time%60;

Expand Down
3 changes: 2 additions & 1 deletion code/mission/missionparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "gamesnd/eventmusic.h"
#include "globalincs/alphacolors.h"
#include "globalincs/linklist.h"
#include "hud/hud.h"
#include "hud/hudescort.h"
#include "hud/hudets.h"
#include "hud/hudsquadmsg.h"
Expand Down Expand Up @@ -6525,7 +6526,7 @@ void mission::Reset()
cutscenes.clear( );

gravity = vmd_zero_vector;

HUD_timer_padding = 0;
volumetrics.reset();
}

Expand Down
1 change: 1 addition & 0 deletions code/mission/missionparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ typedef struct mission {
tl::optional<volumetric_nebula> volumetrics;
sound_env sound_environment;
vec3d gravity;
int HUD_timer_padding;

// Goober5000
int command_persona;
Expand Down
31 changes: 31 additions & 0 deletions code/parse/sexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ SCP_vector<sexp_oper> Operators = {
{ "time-docked", OP_TIME_DOCKED, 3, 3, SEXP_INTEGER_OPERATOR, },
{ "time-undocked", OP_TIME_UNDOCKED, 3, 3, SEXP_INTEGER_OPERATOR, },
{ "time-to-goal", OP_TIME_TO_GOAL, 1, 1, SEXP_INTEGER_OPERATOR, }, // tcrayford
{ "set-hud-timer-padding", OP_SET_HUD_TIME_PAD, 1, 1, SEXP_ACTION_OPERATOR, }, // MjnMixael

//Conditionals Category
{ "cond", OP_COND, 1, INT_MAX, SEXP_CONDITIONAL_OPERATOR,},
Expand Down Expand Up @@ -19185,6 +19186,18 @@ int sexp_time_to_goal(int n)
return time;
}

void sexp_set_hud_time_pad(int n)
{
bool is_nan, is_nan_forever;
int pad;

pad = eval_num(n, is_nan, is_nan_forever);
if (is_nan || is_nan_forever)
return;

The_mission.HUD_timer_padding = pad;
}

// Karajorma
void sexp_reset_orders (int /*n*/)
{
Expand Down Expand Up @@ -27839,6 +27852,11 @@ int eval_sexp(int cur_node, int referenced_node)
sexp_val = sexp_time_to_goal(node);
break;

case OP_SET_HUD_TIME_PAD:
sexp_set_hud_time_pad(node);
sexp_val = SEXP_TRUE;
break;


// Karajorma
case OP_RESET_ORDERS:
Expand Down Expand Up @@ -29648,6 +29666,7 @@ int query_operator_return_type(int op)
case OP_NOP:
case OP_GOALS_ID:
case OP_SEND_MESSAGE:
case OP_SET_HUD_TIME_PAD:
case OP_SELF_DESTRUCT:
case OP_NEXT_MISSION:
case OP_END_CAMPAIGN:
Expand Down Expand Up @@ -30446,6 +30465,9 @@ int query_operator_argument_type(int op, int argnum)
case OP_TIME_TO_GOAL:
return OPF_SHIP;

case OP_SET_HUD_TIME_PAD:
return OPF_NUMBER;

case OP_WAS_DESTROYED_BY_DELAY:
if (argnum == 0)
return OPF_POSITIVE;
Expand Down Expand Up @@ -34440,6 +34462,7 @@ int get_category(int op_id)
case OP_TIME_DOCKED:
case OP_TIME_UNDOCKED:
case OP_TIME_TO_GOAL:
case OP_SET_HUD_TIME_PAD:
return OP_CATEGORY_TIME;

case OP_SHIELDS_LEFT:
Expand Down Expand Up @@ -36330,6 +36353,14 @@ SCP_vector<sexp_help_struct> Sexp_help = {
"Returns a number value. Takes 1 argument...\r\n"
"\t1:\tName of ship to check waypoint time." },

// MjnMixael
{ OP_SET_HUD_TIME_PAD, "Set HUD Timer Padding (Action operator)\r\n"
"\tSets an additional padding that is added only to the visible clock on the HUD. "
"It does not affect the actual mission time or the mission log! Time is an illusion "
"and the illusion here exists only on the HUD.\r\n\r\n"
"Takes 1 argument...\r\n"
"\t1:\tThe amount of time to add to the clock in seconds." },

{ OP_AFTERBURNER_LEFT, "Afterburner left\r\n"
"\tReturns a ship's current engine energy as a percentage.\r\n"
"\t1: Ship name\r\n" },
Expand Down
1 change: 1 addition & 0 deletions code/parse/sexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ enum : int {
OP_TIME_DOCKED,
OP_TIME_UNDOCKED,
OP_TIME_TO_GOAL, // tcrayford
OP_SET_HUD_TIME_PAD, // MjnMixael

// OP_CATEGORY_STATUS

Expand Down
16 changes: 16 additions & 0 deletions code/scripting/api/libs/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,22 @@ ADE_FUNC(getMissionTime, l_Mission, nullptr, "Game time in seconds since the mis
return ade_set_args(L, "x", Missiontime);
}

ADE_VIRTVAR(MissionHUDTimerPadding,
l_Mission,
"number",
"Gets or sets padding currently applied to the HUD mission timer.",
"number",
"the padding in seconds")
{
int pad;

if (ADE_SETTING_VAR && ade_get_args(L, "*i", &pad)) {
The_mission.HUD_timer_padding = pad;
}

return ade_set_args(L, "i", The_mission.HUD_timer_padding);
}

//WMC - These are in freespace.cpp
ADE_FUNC(loadMission, l_Mission, "string missionName", "Loads a mission", "boolean", "True if mission was loaded, otherwise false")
{
Expand Down

0 comments on commit 02233fc

Please sign in to comment.