Skip to content

Commit 1b79e3c

Browse files
author
newby
committed
Sync grenade timers with cease fire
It's rather frustrating that ceasefire causes all the active grenade timers to lose sync (the visual timer pauses, but the sound just keeps playing). Implement actual pause/unpause of the timer sound around ceasefire start/end.
1 parent e701692 commit 1b79e3c

File tree

5 files changed

+70
-59
lines changed

5 files changed

+70
-59
lines changed

csqc/csextradefs.qc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,12 @@ class CsGrenTimer {
467467
float grentype, float timer_flags) Set;
468468
nonvirtual void() Stop;
469469

470+
nonvirtual void() PauseSound {
471+
if (flags_ & FL_GT_SOUND) // -volume => stop.
472+
soundupdate(this, CHAN_VOICE, "", -1, 0, 0, 0, 0);
473+
};
474+
nonvirtual void() StartSound;
475+
470476
static float next_index_;
471477
static CsGrenTimer last_;
472478

@@ -485,6 +491,19 @@ class CsGrenTimer {
485491
last_ = grentimers[next_index_];
486492
return last_;
487493
};
494+
static void() SyncPause {
495+
// Time froze, but sound kept running, realign.
496+
for (float i = 0; i < grentimers.length; i++)
497+
if (grentimers[i].active)
498+
grentimers[i].PauseSound();
499+
};
500+
501+
static void() SyncUnpause {
502+
// Time froze, but sound kept running, realign.
503+
for (float i = 0; i < grentimers.length; i++)
504+
if (grentimers[i].active)
505+
grentimers[i].StartSound();
506+
};
488507

489508
static CsGrenTimer() GetLast { return last_; };
490509
};

csqc/events.qc

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ void() CSQC_Parse_Event = {
301301
case MSG_VOTE_MAP_DELETE:
302302
RemoveVoteMap(readstring(), FALSE);
303303
break;
304+
case MSG_PAUSE:
305+
CsGrenTimer::SyncPause();
306+
break;
307+
case MSG_UNPAUSE:
308+
CsGrenTimer::SyncUnpause();
309+
break;
304310
}
305311
}
306312

@@ -317,6 +323,19 @@ string GetGrenTimerSound() {
317323
return wav;
318324
}
319325

326+
void CsGrenTimer::StartSound() {
327+
if !(this.flags_ & FL_GT_SOUND)
328+
return;
329+
330+
string wav = GetGrenTimerSound();
331+
float volume = CVARF(FOCMD_GRENTIMERVOLUME);
332+
333+
// Note there's a bug where soundupdate returns false for a new sample, even
334+
// though it's started.
335+
soundupdate(this, CHAN_VOICE, wav, volume, 0, 0, 0, sound_offset());
336+
}
337+
338+
320339
void CsGrenTimer::Set(float primed_at, float expires_at, float _grentype,
321340
float timer_flags) {
322341
grentype_ = _grentype;
@@ -330,22 +349,12 @@ void CsGrenTimer::Set(float primed_at, float expires_at, float _grentype,
330349
expires_at_ -= rtt/2;
331350
}
332351

333-
if !(this.flags_ & FL_GT_SOUND)
334-
return;
335-
336-
string wav = GetGrenTimerSound();
337-
float volume = CVARF(FOCMD_GRENTIMERVOLUME);
338-
339-
// Note there's a bug where soundupdate returns false for a new sample, even
340-
// though it's started.
341-
soundupdate(this, CHAN_VOICE, wav, volume, 0, 0, 0, sound_offset());
352+
StartSound();
342353
}
343354

344-
345355
void CsGrenTimer::Stop() {
346356
expires_at_ = -1;
347-
if (flags_ & FL_GT_SOUND)
348-
soundupdate(this, CHAN_VOICE, "", -1, 0, 0, 0, 0); // -volume => stop.
357+
PauseSound(); // Pause is really stop.
349358
flags_ = 0;
350359
}
351360

share/commondefs.qc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#define MSG_VOTE_MAP_ADD 20
3333
#define MSG_VOTE_MAP_DELETE 21
3434
#define MSG_PLAYERDIE 22
35+
#define MSG_PAUSE 23
36+
#define MSG_UNPAUSE 24
3537

3638
#define FLAGINFO_HOME 1
3739
#define FLAGINFO_CARRIED 2

ssqc/admin.qc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,25 @@ void () Admin_CeaseFire = {
187187
}
188188
};
189189

190+
void NotifyPauseUnpause(float is_pause) {
191+
entity p = find (world, classname, "player");
192+
while (p) {
193+
if (p.netname == "" || !infokeyf(p, INFOKEY_P_CSQCACTIVE))
194+
continue;
195+
196+
msg_entity = p;
197+
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
198+
WriteByte(MSG_MULTICAST, is_pause ? MSG_PAUSE : MSG_UNPAUSE);
199+
multicast('0 0 0', MULTICAST_ONE_R_NOSPECS);
200+
201+
p = find(p, classname, "player");
202+
}
203+
}
204+
190205
void () Admin_Pause = {
191206
if (!is_paused) {
192207
setpause(1);
208+
NotifyPauseUnpause(TRUE);
193209
is_paused = 1;
194210
cs_paused = 1;
195211
pause_actor = self.netname;

ssqc/mvdsv.qc

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void (float duration) GE_PausedTic = {
107107
local entity p;
108108
if (unpause_requested && (unpause_countdown == 0)) {
109109
unpause_countdown = duration + 5;
110+
unpause_lastcountnumber = 5;
110111
}
111112
if (unpause_requested) {
112113
if ((duration >= unpause_countdown)) {
@@ -116,56 +117,20 @@ void (float duration) GE_PausedTic = {
116117
unpause_requested = 0;
117118
unpause_lastcountnumber = 0;
118119
setpause(0);
119-
}
120-
else {
121-
if (duration >= (unpause_countdown - 4) && (unpause_lastcountnumber == 0)) {
122-
unpause_lastcountnumber = 4;
123-
p = find (world, classname, "player");
124-
while (p) {
125-
if (p.netname != "") {
126-
stuffcmd(p, "play buttons/switch04.wav\n");
127-
}
128-
p = find(p, classname, "player");
129-
}
130-
bprint(PRINT_HIGH, "Unpausing in 4 seconds\n" );
131-
132-
}
133-
else if (duration >= (unpause_countdown - 3) && (unpause_lastcountnumber == 4)) {
134-
unpause_lastcountnumber = 3;
135-
p = find (world, classname, "player");
136-
while (p) {
137-
if (p.netname != "") {
138-
stuffcmd(p, "play buttons/switch04.wav\n");
139-
}
140-
p = find(p, classname, "player");
141-
}
142-
bprint(PRINT_HIGH, "Unpausing in 3 seconds\n" );
143-
}
144-
else if (duration >= (unpause_countdown - 2) && (unpause_lastcountnumber == 3)) {
145-
unpause_lastcountnumber = 2;
146-
p = find (world, classname, "player");
147-
while (p) {
148-
if (p.netname != "") {
149-
stuffcmd(p, "play buttons/switch04.wav\n");
150-
}
151-
p = find(p, classname, "player");
152-
}
153-
bprint(PRINT_HIGH, "Unpausing in 2 seconds\n" );
154-
}
155-
else if (duration >= (unpause_countdown - 1) && (unpause_lastcountnumber == 2)) {
156-
unpause_lastcountnumber = 1;
157-
p = find (world, classname, "player");
158-
while (p) {
159-
if (p.netname != "") {
160-
stuffcmd(p, "play buttons/switch04.wav\n");
161-
}
162-
p = find(p, classname, "player");
163-
}
164-
bprint(PRINT_HIGH, "Unpausing in 1 second\n" );
120+
NotifyPauseUnpause(FALSE);
121+
} else if (duration >= unpause_countdown - (unpause_lastcountnumber)) {
122+
unpause_lastcountnumber--;
123+
p = find (world, classname, "player");
124+
while (p) {
125+
if (p.netname != "")
126+
stuffcmd(p, "play buttons/switch04.wav\n");
127+
p = find(p, classname, "player");
165128
}
129+
bprint(PRINT_HIGH,
130+
sprintf("Unpausing in %d seconds\n", unpause_lastcountnumber));
166131
}
167132
}
168-
}
133+
}
169134

170135
void(float pauseduration) SV_PausedTic = {
171136
GE_PausedTic(pauseduration);

0 commit comments

Comments
 (0)