]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add antispam cvar, move declarations out of defs.qh and main.qh, and
authorSamual <samual@xonotic.org>
Tue, 18 Oct 2011 15:40:25 +0000 (11:40 -0400)
committerSamual <samual@xonotic.org>
Tue, 18 Oct 2011 15:40:25 +0000 (11:40 -0400)
re-write some more in announcer code

defaultXonotic.cfg
qcsrc/client/Defs.qc
qcsrc/client/announcer.qc
qcsrc/client/autocvars.qh
qcsrc/client/main.qh

index f92882f4424da8b0ca0f2693e7be3a64e0916e95..1e8c20537bf2d703d2579ce8d57e3e1558a3f593 100644 (file)
@@ -960,6 +960,7 @@ seta cl_sound_maptime_warning "1" "play announcer sound telling you the remainin
 seta cl_notify_carried_items "3" "notify you of carried items when you obtain them (e.g. flags in CTF) - 0: disabled, 1: notify of taken items, 2: notify of picking up dropped items, 3: notify of both"
 
 seta cl_announcer default "name of the announcer you wish to use from data/sound/announcer"
+seta cl_announcer_antispam 2 "number of seconds before an announcement of the same sound can be played again"
 
 // startmap_dm is used when running with the -listen or -dedicated commandline options
 set serverconfig server.cfg
index b074aa3b2a7fe88f97793188e18ba839b5f93976..a1a32404dd48ec7d57bdeb83eca8b624433f58fd 100644 (file)
@@ -222,10 +222,6 @@ float spectatee_status;
 // short mapname
 string shortmapname;
 
-//remaining maptime announcer sounds, true when sound was already played
-float announcer_1min;
-float announcer_5min;
-
 // database for misc stuff
 float tempdb;
 float ClientProgsDB;
index 0d64d65350c1af26da21b979a90871bdbe4588ff..7dc6a9d574fa9eafb8cdcc96779a7e56fef516a9 100644 (file)
@@ -1,9 +1,14 @@
 float previous_announcement_time;
+float previous_game_starttime;
 string previous_announcement;
 
+//remaining maptime announcer sounds, true when sound was already played
+float announcer_1min;
+float announcer_5min;
+
 void Announcer_Play(string announcement)
 {
-  if((announcement != previous_announcement) || (time >= (previous_announcement_time + 5)))
+  if((announcement != previous_announcement) || (time >= (previous_announcement_time + autocvar_cl_announcer_antispam)))
   {
     sound(world, CH_INFO, strcat("announcer/", autocvar_cl_announcer, "/", announcement, ".wav"), VOL_BASEVOICE, ATTN_NONE);
     
@@ -12,6 +17,34 @@ void Announcer_Play(string announcement)
   }
 }
 
+void Announcer_Countdown() 
+{
+       float starttime = getstatf(STAT_GAMESTARTTIME);
+       float countdown = (starttime - time);
+       float countdown_rounded = floor(0.5 + countdown);
+       
+       if(countdown <= 0) // countdown has finished, starttime is now
+       {
+               if (!spectatee_status) 
+      centerprint_generic(CPID_GAME_STARTING, _("^1Begin!"), 1, 0);
+      
+               Announcer_Play("begin");
+               announcer_5min = announcer_1min = FALSE; //reset maptime announcers now as well
+               remove(self);
+               return;
+       }
+       else // countdown is still going
+       {
+               if (!spectatee_status)
+                       centerprint_generic(CPID_GAME_STARTING, _("^1Game starts in %d seconds"), 1, countdown_rounded);
+
+               if(countdown_rounded <= 3 && countdown_rounded >= 1) 
+                       Announcer_Play(ftos(countdown_rounded));
+
+               self.nextthink = (starttime - (countdown - 1));
+       }
+}
+
 /**
  * Checks whether the server initiated a map restart (stat_game_starttime changed)
  *
@@ -19,50 +52,28 @@ void Announcer_Play(string announcement)
  * timelimit, fraglimit and game_starttime! Requires engine changes (remove STAT_TIMELIMIT
  * and STAT_FRAGLIMIT to be auto-sent)
  */
-void CheckForGamestartChange() {
-       float startTime;
-       startTime = getstatf(STAT_GAMESTARTTIME);
-       if (previous_game_starttime != startTime) {
-               if ((time + 5.0) < startTime) {
-                       //if connecting to server while restart was active don't always play prepareforbattle
-                       sound(world, CH_INFO, strcat("announcer/", autocvar_cl_announcer, "/prepareforbattle.wav"), VOL_BASEVOICE, ATTN_NONE);
+void Announcer_Gamestart() 
+{
+       float startTime = getstatf(STAT_GAMESTARTTIME);
+       
+       if (previous_game_starttime != startTime) 
+       {
+               if ((time + 5.0) < startTime) //if connecting to server while restart was active don't always play prepareforbattle
+               {
+                       Announcer_Play("prepareforbattle");
                }
-               if (time < startTime) {
-                       restartAnnouncer = spawn();
-                       restartAnnouncer.think = restartAnnouncer_Think;
-                       restartAnnouncer.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
+               if (time < startTime) 
+               {
+      entity e;
+      e = spawn();
+                       e.think = Announcer_Countdown;
+                       e.nextthink = startTime - floor(startTime - time); //synchronize nextthink to startTime
                }
        }
+       
        previous_game_starttime = startTime;
 }
 
-void restartAnnouncer_Think() {
-       float countdown_rounded, countdown;
-       countdown = getstatf(STAT_GAMESTARTTIME) - time;
-       countdown_rounded = floor(0.5 + countdown);
-       if(countdown <= 0) {
-               if (!spectatee_status) //do cprint only for players
-                       centerprint_generic(CPID_GAME_STARTING, _("^1Begin!"), 1, 0);
-
-               sound(world, CH_INFO, strcat("announcer/", autocvar_cl_announcer, "/begin.wav"), VOL_BASEVOICE, ATTN_NONE);
-               //reset maptime announcers now as well
-               announcer_5min = announcer_1min = FALSE;
-
-               remove(self);
-               return;
-       }
-       else {
-               if (!spectatee_status) //do cprint only for players
-                       centerprint_generic(CPID_GAME_STARTING, _("^1Game starts in %d seconds"), 1, countdown_rounded);
-
-               if(countdown_rounded <= 3 && countdown_rounded >= 1) {
-                       sound(world, CH_INFO, strcat("announcer/", autocvar_cl_announcer, "/", ftos(countdown_rounded), ".wav"), VOL_BASEVOICE, ATTN_NONE);
-               }
-
-               self.nextthink = getstatf(STAT_GAMESTARTTIME) - (countdown - 1);
-       }
-}
-
 /**
  * Plays the 1minute or 5 minutes (of maptime) remaining sound, if client wants it
  */
@@ -159,7 +170,7 @@ void carrierAnnouncer() {
 
 void Announcer()
 {
-  CheckForGamestartChange();
+  Announcer_Gamestart();
        maptimeAnnouncer();
        carrierAnnouncer();
 }
index 7259761c204406119b377876e73bd7377c6db012..c62546b1fd15c1fa43108b65adf1712ca990880d 100644 (file)
@@ -19,6 +19,7 @@ float autocvar_camera_speed_roll;
 float autocvar_chase_active;
 float autocvar_cl_allow_uid2name;
 string autocvar_cl_announcer;
+float autocvar_cl_announcer_antispam;
 float autocvar_cl_autodemo_delete;
 float autocvar_cl_autodemo_delete_keeprecords;
 float autocvar_cl_casings;
index 9ea50c02b33d285aabce80a91a0504e470b2977f..58a0bad1969c8dbdaee95fcff27c75390f23a303 100644 (file)
@@ -131,10 +131,6 @@ float ready_waiting_for_me;
 float vote_waiting;
 float vote_waiting_for_me;
 
-float previous_game_starttime;
-entity restartAnnouncer; //a temporary entity which will play the countdown sounds 3, 2, 1 for the client
-void restartAnnouncer_Think();
-
 float current_zoomfraction;
 
 float cs_project_is_b0rked;