Skip to content

Commit

Permalink
Merge pull request #337 from dusty-qw/pausing
Browse files Browse the repository at this point in the history
PAUSE: countdown warning for pause/unpause
  • Loading branch information
tcsabina authored Mar 30, 2024
2 parents 2f61822 + 39be271 commit 1b74289
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/g_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ void log_close(void);
extern fileHandle_t log_handle;

// commands.c
void WillPause();
typedef struct cmd_s
{
char *name;
Expand Down
102 changes: 95 additions & 7 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -8333,26 +8333,51 @@ void setTeleportCap()

// }

float when_to_pause;
int when_to_unpause;
int pauseduration;
int pauses_remaining;
char pause_name[50];

void PausedTic(int duration)
{
pauseduration = duration;
gedict_t *p;
int time = 0;
static int prevtime = 0;

if (when_to_unpause && when_to_unpause > duration)
{
time = max(0, (when_to_unpause - duration) / 1000) + 1;

G_cp2all("%s\n\n%d", "unpausing", time);

if (time != prevtime) {
for (p = world; (p = find_client(p));)
{
stuffcmd(p, "play buttons/switch04.wav\n");
}

prevtime = time;
}
}

// Unpause on schedule, or if the game has ended for some reason
if ((!k_matchLess && match_in_progress != 2)
|| (when_to_unpause && duration >= when_to_unpause))
{
when_to_unpause = pauseduration = 0; // reset our globals

G_cp2all(" "); // clear centerprint
G_bprint(2, "game unpaused\n");
trap_setpause(0);
}
}

void TogglePause()
{
int minutes, seconds;
gedict_t *p;

if (!k_matchLess)
{
// NON matchless
Expand All @@ -8377,14 +8402,43 @@ void TogglePause()
return;
}

when_to_unpause = pauseduration + 2000; // schedule unpause in 2000 ms
when_to_unpause = pauseduration + 3000; // schedule unpause in 3000 ms

G_bprint(2, "%s unpaused the game (will resume in 2 seconds)\n", self->netname);
G_bprint(2, "%s unpaused the game (will resume in 3 seconds)\n", self->netname);
}
else
{
// PAUSE

if (when_to_pause)
{
G_sprint(self, 2, "Pause already in progress.\n");

return;
}

if ((p = find(world, FOFCLSN, "timer")))
{
minutes = p->cnt;
seconds = p->cnt2;
if (seconds == 60)
{
seconds = 0;
}
else
{
minutes--;
}

//can't pause if less than 3 seconds left in match
if (!minutes && seconds <= 3)
{
G_sprint(self, 2, "Too late to pause. Please wait for match to finish.\n");

return;
}
}

// admins may ignore not allowed pause
if (!cvar("pausable") && !is_adm(self) && !PlayerCanPause(self))
{
Expand All @@ -8393,12 +8447,46 @@ void TogglePause()
return;
}

pauseduration = when_to_unpause = 0; // reset our globals
when_to_pause = g_globalvars.time + 3;
snprintf(pause_name, sizeof(pause_name), self->netname);
pauses_remaining = self->k_pauseRequests;
}
}

void WillPause()
{
gedict_t *p;
int time = when_to_pause - g_globalvars.time+1;
static int prevtime = 0;

G_bprint(2, "%s paused the game. He has %d remaining request(s).\n", self->netname,
self->k_pauseRequests);
trap_setpause(1);
if (!when_to_pause)
{
return;
}

if (time > 0)
{
if (time != prevtime) {
for (p = world; (p = find_client(p));)
{
stuffcmd(p, "play buttons/switch04.wav\n");
}

prevtime = time;
}

G_cp2all("%s\n\n%d", "pausing", time);

return;
}
G_cp2all(" "); // clear centerprint
when_to_pause = 0;

pauseduration = when_to_unpause = 0; // reset our globals

G_bprint(2, "%s paused the game. He has %d remaining request(s).\n", pause_name,
pauses_remaining);
trap_setpause(1);
}

void ToggleArena()
Expand Down
2 changes: 2 additions & 0 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,8 @@ void StartFrame(int time)
check_fcheck();

TeamplayGameTick();

WillPause();
}

// Check the same spawnflags as items only visible in DM for monsters as well.
Expand Down

0 comments on commit 1b74289

Please sign in to comment.