]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/notifications/all.qc
Fix FL_WEAPON flag overlapping FL_JUMPRELEASED. This unintentional change was introdu...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / notifications / all.qc
index d6db436d0174b2fe672ef2da00a9dbe35aacec68..dd200973bc007804c28258c12343b02130d6ec55 100644 (file)
@@ -1,4 +1,5 @@
 #include "all.qh"
+
 #if defined(CSQC)
        #include <client/announcer.qh>
 #elif defined(MENUQC)
@@ -6,10 +7,9 @@
        #include <common/constants.qh>
        #include <common/net_linked.qh>
        #include <common/teams.qh>
-       #include <server/autocvars.qh>
-       #include <server/constants.qh>
-       #include <server/defs.qh>
+       #include <server/command/getreplies.qh>
        #include <server/mutators/_mod.qh>
+       #include <server/world.qh>
 #endif
 
 // ================================================
@@ -79,6 +79,9 @@ string Notification_CheckArgs(
 
 bool Notification_ShouldSend(NOTIF broadcast, entity to_client, entity other_client)
 {
+       if(!IS_REAL_CLIENT(to_client))
+               return false;
+
        switch (broadcast)
        {
                case NOTIF_ONE:
@@ -447,7 +450,8 @@ void Create_Notification_Entity_Annce(entity notif,
                                                                                float channel,
                                                                                string snd,
                                                                                float vol,
-                                                                               float position)
+                                                                               float position,
+                                                                               float queuetime)
                {
                        // Set MSG_ANNCE information and handle precaching
                        #ifdef CSQC
@@ -463,6 +467,7 @@ void Create_Notification_Entity_Annce(entity notif,
                                                notif.nent_snd = strzone(snd);
                                                notif.nent_vol = vol;
                                                notif.nent_position = position;
+                                               notif.nent_queuetime = queuetime;
                                        }
                                }
                                else
@@ -759,12 +764,12 @@ void Create_Notification_Entity_Choice(entity notif,
 
 // used by MSG_CHOICE to build list of choices
 #ifdef SVQC
-void Notification_GetCvars(entity this)
+void Notification_GetCvars(entity this, entity store)
 {
        FOREACH(Notifications, it.nent_type == MSG_CHOICE && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), {
                GetCvars_handleFloat(
                        this,
-                       CS(this),
+                       store,
                        get_cvars_s,
                        get_cvars_f,
                        msg_choice_choices[it.nent_choice_idx],
@@ -835,14 +840,14 @@ void Dump_Notifications(int fh, bool alsoprint)
                }
        });
 
-       NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications (count = %d):\n", NOTIF_ANNCE_COUNT));
+       NOTIF_WRITE(sprintf("\n// MSG_ANNCE notifications:\n"));
        FOREACH(Notifications, it.nent_type == MSG_ANNCE && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), {
                NOTIF_WRITE_ENTITY(it,
                        "0 = disabled, 1 = enabled if gentle mode is off, 2 = always enabled"
                );
        });
 
-       NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
+       NOTIF_WRITE(sprintf("\n// MSG_INFO notifications:\n"));
        FOREACH(Notifications, it.nent_type == MSG_INFO && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), {
                NOTIF_WRITE_ENTITY(it,
                        "0 = off, 1 = print to console, "
@@ -850,21 +855,21 @@ void Dump_Notifications(int fh, bool alsoprint)
                );
        });
 
-       NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
+       NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications:\n"));
        FOREACH(Notifications, it.nent_type == MSG_CENTER && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), {
                NOTIF_WRITE_ENTITY(it,
                        "0 = off, 1 = centerprint"
                );
        });
 
-       NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications (count = %d):\n", NOTIF_MULTI_COUNT));
+       NOTIF_WRITE(sprintf("\n// MSG_MULTI notifications:\n"));
        FOREACH(Notifications, it.nent_type == MSG_MULTI && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), {
                NOTIF_WRITE_ENTITY(it,
                        "Enable this multiple notification"
                );
        });
 
-       NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications (count = %d):\n", NOTIF_CHOICE_COUNT));
+       NOTIF_WRITE(sprintf("\n// MSG_CHOICE notifications:\n"));
        FOREACH(Notifications, it.nent_type == MSG_CHOICE && (!it.nent_teamnum || it.nent_teamnum == NUM_TEAM_1), {
                NOTIF_WRITE_ENTITY_CHOICE(it,
                        "Choice for this notification 0 = off, 1 = default message, 2 = verbose message",
@@ -959,11 +964,8 @@ void Dump_Notifications(int fh, bool alsoprint)
                "Don't show attacker spree information in MSG_INFO messages if it isn't an achievement"
        );
 
-       NOTIF_WRITE(sprintf(
-               (
-                       "\n// Notification counts (total = %d): "
-                       "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n"
-               ),
+       LOG_INFOF("Notification counts (total = %d): "
+               "MSG_ANNCE = %d, MSG_INFO = %d, MSG_CENTER = %d, MSG_MULTI = %d, MSG_CHOICE = %d\n",
                (
                        NOTIF_ANNCE_COUNT +
                        NOTIF_INFO_COUNT +
@@ -976,7 +978,7 @@ void Dump_Notifications(int fh, bool alsoprint)
                NOTIF_CENTER_COUNT,
                NOTIF_MULTI_COUNT,
                NOTIF_CHOICE_COUNT
-       ));
+       );
        #undef NOTIF_WRITE_HARDCODED
        #undef NOTIF_WRITE_ENTITY
        #undef NOTIF_WRITE
@@ -1177,6 +1179,58 @@ void Local_Notification_centerprint_Add(
        #endif
        centerprint_Add(ORDINAL(cpid), input, stof(arg_slot[0]), stof(arg_slot[1]));
 }
+
+void Local_Notification_Queue_Run(MSG net_type, entity notif)
+{
+       switch (net_type)
+       {
+               case MSG_ANNCE:
+               {
+                       Local_Notification_sound(notif.nent_channel, notif.nent_snd, notif.nent_vol, notif.nent_position);
+                       break;
+               }
+       }
+}
+
+void Local_Notification_Queue_Add(MSG net_type, entity notif, float queue_time)
+{
+       // Guess length if required
+       if(queue_time == 0)
+               queue_time = soundlength(AnnouncerFilename(notif.nent_snd));
+
+       if(queue_time == -1 || time > notif_queue_next_time) {
+               // Run immediately
+               Local_Notification_Queue_Run(net_type, notif);
+               notif_queue_next_time = time + queue_time;
+       } else {
+               // Put in queue
+               if(notif_queue_length >= NOTIF_QUEUE_MAX) return;
+
+               notif_queue_type[notif_queue_length] = net_type;
+               notif_queue_entity[notif_queue_length] = notif;
+               notif_queue_time[notif_queue_length] = notif_queue_next_time;
+
+               notif_queue_next_time += queue_time;
+               ++notif_queue_length;
+       }
+}
+
+void Local_Notification_Queue_Process()
+{
+       if(!notif_queue_length || notif_queue_time[0] > time)
+               return;
+
+       Local_Notification_Queue_Run(notif_queue_type[0], notif_queue_entity[0]);
+
+       // Shift queue to the left
+       --notif_queue_length;
+       for (int j = 0; j < notif_queue_length; ++j) {
+               notif_queue_type[j] = notif_queue_type[j+1];
+               notif_queue_entity[j] = notif_queue_entity[j+1];
+               notif_queue_time[j] = notif_queue_time[j+1];
+       }
+}
+
 #endif
 
 void Local_Notification(MSG net_type, Notification net_name, ...count)
@@ -1249,7 +1303,7 @@ void Local_Notification(MSG net_type, Notification net_name, ...count)
                case MSG_ANNCE:
                {
                        #ifdef CSQC
-                       Local_Notification_sound(notif.nent_channel, notif.nent_snd, notif.nent_vol, notif.nent_position);
+                       Local_Notification_Queue_Add(net_type, notif, notif.nent_queuetime);
                        #else
                        backtrace("MSG_ANNCE on server?... Please notify Samual immediately!\n");
                        #endif
@@ -1357,6 +1411,7 @@ void Local_Notification(MSG net_type, Notification net_name, ...count)
                                found_choice.nent_floatcount,
                                s1, s2, s3, s4,
                                f1, f2, f3, f4);
+                       break;
                }
        }
 }
@@ -1520,7 +1575,7 @@ void Send_Notification(
        MSG net_type, Notification net_name,
        ...count)
 {
-    if (broadcast != NOTIF_ALL && broadcast != NOTIF_ALL_EXCEPT && !IS_REAL_CLIENT(client)) return;
+    if (broadcast == NOTIF_ONE_ONLY && !IS_REAL_CLIENT(client)) return;
        entity notif = net_name;
        string parms = sprintf("%s, '%s', %s, %s",
                Get_Notif_BroadcastName(broadcast),
@@ -1603,7 +1658,7 @@ void Send_Notification(
 
                #define RECURSE_FROM_CHOICE(ent,action) MACRO_BEGIN \
                        if (notif.nent_challow_var && (warmup_stage || (notif.nent_challow_var == 2))) { \
-                               switch (CS(ent).msg_choice_choices[net_name.nent_choice_idx]) \
+                               switch (CS_CVAR(ent).msg_choice_choices[net_name.nent_choice_idx]) \
                                { \
                                        case 1: found_choice = notif.nent_optiona; break; \
                                        case 2: found_choice = notif.nent_optionb; break; \
@@ -1634,7 +1689,7 @@ void Send_Notification(
                        }
                        default:
                        {
-                               FOREACH_CLIENT(IS_REAL_CLIENT(it) && Notification_ShouldSend(broadcast, it, client), {
+                               FOREACH_CLIENT(Notification_ShouldSend(broadcast, it, client), {
                                        RECURSE_FROM_CHOICE(it, continue);
                                });
                                break;