]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Other improvements to the multiple centerprints system
authorterencehill <piuntn@gmail.com>
Sun, 12 Jun 2011 22:25:37 +0000 (00:25 +0200)
committerterencehill <piuntn@gmail.com>
Sun, 12 Jun 2011 22:25:37 +0000 (00:25 +0200)
Server now uses Send_CSQC_Centerprint_Generic instead of centerprint_builtin to send messages, so that it's possible to send more parameters (id, duration and countdown_num) without adding them to the msg (like the id before). If duration is not set, then the default duration will be used, that is hud_panel_centerprint_time.

In the countdown case, the server can send only the first msg of a series with the same id and the client can continue the countdown by its own; the next countdown messages can be sent by the server anyway, for example to change the countdown msg or for whatever reason. Countdown can be stopped by the server at any time by sending an empty msg (always same id).

The centerprint function in the client now is a wrapper for centerprint_generic, which actually handles the new parameters and add the msgs to the list.

Changes on minstagib_ammocheck are neccessary to correctly stop the out of ammo countdown.

Still other work to do anyway...

14 files changed:
qcsrc/client/Main.qc
qcsrc/client/hud.qc
qcsrc/client/main.qh
qcsrc/client/miscfunctions.qc
qcsrc/common/constants.qh
qcsrc/server/arena.qc
qcsrc/server/cl_client.qc
qcsrc/server/defs.qh
qcsrc/server/g_world.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/mutators/mutator_nix.qc
qcsrc/server/t_items.qc
qcsrc/server/teamplay.qc
qcsrc/server/w_minstanex.qc

index 0cc1563916a035793579d15b412c98f10af3e3df..796b300c668a58a25a27f167ceac04f8792b49b3 100644 (file)
@@ -1318,6 +1318,16 @@ void Net_Notify() {
        {
                HUD_Centerprint(ReadString(), ReadString(), ReadShort(), ReadByte());
        }
+       else if(type == CSQC_CENTERPRINT_GENERIC)
+       {
+                                                               //      id                      string          time    countdown_num
+               float id;
+               id = ReadByte();
+               if (id == 0)
+                       centerprint_generic(id, ReadString(), 0, 0);
+               else
+                       centerprint_generic(id, ReadString(), ReadByte(), ReadByte());
+       }
 }
 
 void Net_WeaponComplain() {
index 6c4fe426d55b282b7a28096568aa6cff23cb22c8..a5b8f080a1cec5e7867011979738beb0e6fbf44a 100644 (file)
@@ -4339,45 +4339,41 @@ float cpm_index;
 string centerprint_messages[CENTERPRINT_MAX_MSGS];
 float centerprint_msgID[CENTERPRINT_MAX_MSGS];
 float centerprint_time[CENTERPRINT_MAX_MSGS];
+float centerprint_expire_time[CENTERPRINT_MAX_MSGS];
+float centerprint_countdown_num[CENTERPRINT_MAX_MSGS];
 
-string msg_without_CPID(string s)
-{
-       return substring(s, strstrofs(s, " ", 0) + 1, strlen(s));
-}
-float get_CPID(string s)
-{
-       if(substring(s, 0, 1) != "\r")
-               return 0;
-       return stof(substring(s, 1, strstrofs(s, " ", 0)));
-}
-void centerprint(string strMessage)
+void centerprint_generic(float new_id, string strMessage, float duration, float countdown_num)
 {
        float i, j;
 
-       if(autocvar_hud_panel_centerprint_time <= 0)
+       if(strMessage == "" && new_id == 0)
                return;
 
-       if(strMessage == "")
-               return;
-
-       float new_id = get_CPID(strMessage);
+       if(duration == 0)
+               duration = autocvar_hud_panel_centerprint_time;
 
        for (i=0, j=cpm_index; i<CENTERPRINT_MAX_MSGS; ++i, ++j)
        {
                if (j == CENTERPRINT_MAX_MSGS)
                        j = 0;
-               if (new_id && new_id == centerprint_msgID[j] && centerprint_time[j] + autocvar_hud_panel_centerprint_time >= time)
+               if (new_id && new_id == centerprint_msgID[j]) // && centerprint_expire_time[j] >= time
                {
                        if(centerprint_messages[j])
                                strunzone(centerprint_messages[j]);
-                       centerprint_messages[j] = strzone(msg_without_CPID(strMessage));
-                       centerprint_time[j] = time;
+                       centerprint_messages[j] = strzone(strMessage);
+
+                       centerprint_time[j] = duration;
+                       centerprint_expire_time[j] = time + duration;
+                       centerprint_countdown_num[j] = countdown_num;
                        return;
                }
                if(centerprint_messages[j] == strMessage)
                {
-                       centerprint_time[j] = time;
                        centerprint_msgID[j] = new_id;
+
+                       centerprint_time[j] = duration;
+                       centerprint_expire_time[j] = time + duration;
+                       centerprint_countdown_num[j] = countdown_num;
                        return;
                }
        }
@@ -4387,12 +4383,16 @@ void centerprint(string strMessage)
                cpm_index = CENTERPRINT_MAX_MSGS - 1;
        if(centerprint_messages[cpm_index])
                strunzone(centerprint_messages[cpm_index]);
-       if (new_id)
-               centerprint_messages[cpm_index] = strzone(msg_without_CPID(strMessage));
-       else
-               centerprint_messages[cpm_index] = strzone(strMessage);
+       centerprint_messages[cpm_index] = strzone(strMessage);
        centerprint_msgID[cpm_index] = new_id;
-       centerprint_time[cpm_index] = time;
+       centerprint_time[cpm_index] = duration;
+       centerprint_expire_time[cpm_index] = time + duration;
+       centerprint_countdown_num[cpm_index] = countdown_num;
+}
+
+void centerprint(string strMessage)
+{
+       centerprint_generic(0, strMessage, autocvar_hud_panel_centerprint_time, 0);
 }
 
 // CenterPrint (#16)
@@ -4457,21 +4457,34 @@ void HUD_CenterPrint (void)
        {
                if (j == CENTERPRINT_MAX_MSGS)
                        j = 0;
-               if (centerprint_time[j] + autocvar_hud_panel_centerprint_time < time)
-                       continue;
-               else if (centerprint_time[j] + autocvar_hud_panel_centerprint_time - fade > time)
+               if (centerprint_expire_time[j] < time)
+               {
+                       if (centerprint_countdown_num[j])
+                       {
+                               centerprint_countdown_num[j] = centerprint_countdown_num[j] - 1;
+                               if (centerprint_countdown_num[j] == 0)
+                                       continue;
+                               centerprint_expire_time[j] = centerprint_expire_time[j] + centerprint_time[j];
+                       }
+                       else
+                               continue;
+               }
+               if (centerprint_expire_time[j] - fade > time)
                {
                        a = 1 * alpha_factor;
                        sz = 1;
                }
-               else if (centerprint_time[j] + autocvar_hud_panel_centerprint_time > time)
+               else if (centerprint_expire_time[j] > time)
                {
-                       a = (centerprint_time[j] + autocvar_hud_panel_centerprint_time - time) / fade * alpha_factor;
+                       a = (centerprint_expire_time[j] - time) / fade * alpha_factor;
                        sz = 0.8 + a * (1 - 0.8);
                }
 
                drawfontscale = sz * '1 1 0';
-               n = tokenizebyseparator(centerprint_messages[j], "\n");
+               if (centerprint_countdown_num[j])
+                       n = tokenizebyseparator(sprintf(centerprint_messages[j], centerprint_countdown_num[j]), "\n");
+               else
+                       n = tokenizebyseparator(centerprint_messages[j], "\n");
                if (autocvar_hud_panel_centerprint_flip)
                {
                        // check if the message can be entirely shown
@@ -4514,12 +4527,12 @@ void HUD_CenterPrint (void)
                if (autocvar_hud_panel_centerprint_flip)
                {
                        pos_y = next_msg_pos_y;
-                       if (a < 1)
+                       if (a < 1 && centerprint_msgID[j] == 0) // messages with id can be replaced just after they are faded out, so never move over them the next messages
                                pos_y += 1.5 * fontsize_y * (1 - a*a);
                }
                else
                {
-                       if (a < 1)
+                       if (a < 1 && centerprint_msgID[j] == 0) // messages with id can be replaced just after they are faded out, so never move over them the next messages
                                pos_y -= 1.5 * fontsize_y * (1 - a*a);
                }
                drawfontscale = '1 1 0';
index af849e18c57c92dce1d1580b3342962b5b23403d..689722a1f6a9207e62d613b08546865bf8b9af79 100644 (file)
@@ -144,6 +144,7 @@ float camera_roll;
 vector camera_direction;
 
 void centerprint(string strMessage);
+void centerprint_generic(float new_id, string strMessage, float duration, float countdown_num);
 
 #define ALPHA_MIN_VISIBLE 0.003
 
index e47734cb3d240c58468c964b119b3fca5bf23a04..0ecb2b89a5aa7d0c2ea8517fc1a5a2fcb9376c1e 100644 (file)
@@ -20,7 +20,7 @@ void restartAnnouncer_Think() {
        countdown_rounded = floor(0.5 + countdown);
        if(countdown <= 0) {
                if (!spectatee_status) //do cprint only for players
-                       centerprint(strcat(CPID_GAME_STARTING, _("^1Begin!")));
+                       centerprint_generic(CPID_GAME_STARTING, _("^1Begin!"), 1, 0);
 
                sound(world, CHAN_AUTO, strcat("announcer/", autocvar_cl_announcer, "/begin.wav"), VOL_BASEVOICE, ATTN_NONE);
                //reset maptime announcers now as well
@@ -31,7 +31,7 @@ void restartAnnouncer_Think() {
        }
        else {
                if (!spectatee_status) //do cprint only for players
-                       centerprint(strcat(CPID_GAME_STARTING, sprintf(_("^1Game starts in %d seconds"), countdown_rounded)));
+                       centerprint_generic(CPID_GAME_STARTING, _("^1Game starts in %d seconds"), 1, countdown_rounded);
 
                if(countdown_rounded <= 3 && countdown_rounded >= 1) {
                        sound(world, CHAN_AUTO, strcat("announcer/", autocvar_cl_announcer, "/", ftos(countdown_rounded), ".wav"), VOL_BASEVOICE, ATTN_NONE);
index 31dcf71a946c90d0f41b7b122fd6f9b4f5c8fe66..ffabf0eb88cc12f8954af2d6842093e6b8c434b1 100644 (file)
@@ -82,6 +82,7 @@ const float RANKINGS_CNT = 15;
 
 const float CSQC_KILLNOTIFY = 0;
 const float CSQC_CENTERPRINT = 1;
+const float CSQC_CENTERPRINT_GENERIC = 2;
 
 const float ENT_CLIENT = 0;
 const float ENT_CLIENT_DEAD = 1;
@@ -581,15 +582,15 @@ float WATERLEVEL_SUBMERGED = 3;
 float MAX_SHOT_DISTANCE = 32768;
 
 //centerprint ID list
-#define CPID_TEAMCHANGE                        "\r1 "
-#define CPID_KILL                              "\r2 "
-#define CPID_MINSTA_FINDAMMO   "\r3 "
-#define CPID_NIX_WPNCHANGE             "\r4 "
-#define CPID_DISCONNECT_IDLING "\r5 "
-#define CPID_ROUND_STARTING            "\r6 "
-#define CPID_GAME_STARTING             "\r7 "
-#define CPID_TIMEOUT_COUNTDOWN "\r8 "
-#define CPID_MOTD                              "\r9 "
+float CPID_TEAMCHANGE = 1;
+float CPID_KILL = 2;
+float CPID_MINSTA_FINDAMMO = 3;
+float CPID_NIX_WPNCHANGE = 4;
+float CPID_DISCONNECT_IDLING = 5;
+float CPID_ROUND_STARTING = 6;
+float CPID_GAME_STARTING = 7;
+float CPID_TIMEOUT_COUNTDOWN = 8;
+float CPID_MOTD = 9;
 
 // CSQC centerprint/notify message types
 float MSG_SUICIDE = 0;
index 9ff080e97d0146d959bc3db699f05cba43e0cbcd..04b392c9401230086503a98c73362b60357f755b 100644 (file)
@@ -229,10 +229,13 @@ void Arena_Warmup()
                if (g_ca)
                        allowed_to_spawn = 1;
                if(champion && g_arena)
+               {
                        msg = strcat("The Champion is ", champion_name, "^7\n");
+                       FOR_EACH_PLAYER(e)
+                               centerprint(e, msg); // TODO: send this msg only once
+               }
 
                if(f != roundStartTime_prev) {
-                       msg = strcat(CPID_ROUND_STARTING, msg, "Round will start in ", ftos(f),"\n");
                        roundStartTime_prev = f;
                        if(f == 5)
                                Announce("prepareforbattle");
@@ -243,8 +246,8 @@ void Arena_Warmup()
                        else if(f == 1)
                                Announce("1");
 
-            FOR_EACH_PLAYER(e)
-                centerprint(e, msg);
+                       FOR_EACH_PLAYER(e)
+                               Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "Round will start in %d\n", 1, f); // TODO: send this msg only once
                }
 
                if (g_arena) {
@@ -261,7 +264,7 @@ void Arena_Warmup()
        {
                roundStartTime_prev = f;
                Announce("begin");
-               centerprint(self, strcat(CPID_ROUND_STARTING, "^1Begin!\n"));
+               Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "^1Begin!\n", 1, 0);
 
                if(g_ca) {
                        ca_players = 0;
index 6a0b0239e2db100fce6054fc3d9ac40591d2b1c3..3c61ba435a6e13b045409246e5f98e96455717c8 100644 (file)
@@ -614,6 +614,9 @@ void PutObserverInServer (void)
        DropAllRunes(self);
        MUTATOR_CALLHOOK(MakePlayerObserver);
 
+       if (g_minstagib)
+               minstagib_stop_countdown();
+
        Portal_ClearAll(self);
 
        if(self.alivetime)
@@ -1299,17 +1302,18 @@ void KillIndicator_Think()
                {
                        if(self.cnt <= 10)
                                AnnounceTo(self.owner, strcat(ftos(self.cnt), ""));
+                       // TODO: Send_CSQC_Centerprint_Generic only once
                        if(self.owner.killindicator_teamchange)
                        {
                                if(self.owner.killindicator_teamchange == -1)
-                                       centerprint(self.owner, strcat(CPID_TEAMCHANGE, "Changing team in ", ftos(self.cnt), " seconds"));
+                                       Send_CSQC_Centerprint_Generic(self.owner, CPID_TEAMCHANGE, "Changing team in %d seconds", 1, self.cnt);
                                else if(self.owner.killindicator_teamchange == -2)
-                                       centerprint(self.owner, strcat(CPID_TEAMCHANGE, "Spectating in ", ftos(self.cnt), " seconds"));
+                                       Send_CSQC_Centerprint_Generic(self.owner, CPID_TEAMCHANGE, "Spectating in %d seconds", 1, self.cnt);
                                else
-                                       centerprint(self.owner, strcat(CPID_TEAMCHANGE, "Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
+                                       Send_CSQC_Centerprint_Generic(self.owner, CPID_TEAMCHANGE, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in %d seconds"), 1, self.cnt);
                        }
                        else
-                               centerprint(self.owner, strcat(CPID_KILL, "^1Suicide in ", ftos(self.cnt), " seconds"));
+                               Send_CSQC_Centerprint_Generic(self.owner, CPID_KILL, "^1Suicide in %d seconds", 1, self.cnt);
                }
                self.nextthink = time + 1;
                self.cnt -= 1;
@@ -1658,8 +1662,6 @@ void ClientConnect (void)
 
        bprint("\n");
 
-       self.welcomemessage_time = 0;
-
        stuffcmd(self, strcat(clientstuff, "\n"));
        stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
        stuffcmd(self, "cl_particles_reloadeffects\n");
@@ -1773,6 +1775,9 @@ void ClientConnect (void)
                set_dom_state(self);
 
        CheatInitClient();
+
+       // FIXME: .BUTTON_INFO in PrintWelcomeMessage must be checked at every frame, not just here
+       PrintWelcomeMessage(self);
 }
 
 /*
@@ -1986,24 +1991,24 @@ string getTimeoutText(float addOneSecond) {
                else {
                        retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
                }
-               return strcat(CPID_TIMEOUT_COUNTDOWN, retStr);
+               return retStr;
        }
        else if (timeoutStatus == 2) {
                if (addOneSecond) {
                        retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
                        //don't show messages like "Timeout ends in 0 seconds"...
                        if ((remainingTimeoutTime + 1) > 0)
-                               return strcat(CPID_TIMEOUT_COUNTDOWN, retStr);
+                               return retStr;
                        else
-                               return strcat(CPID_TIMEOUT_COUNTDOWN, "");
+                               return "";
                }
                else {
                        retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
                        //don't show messages like "Timeout ends in 0 seconds"...
                        if ((remainingTimeoutTime) > 0)
-                               return strcat(CPID_TIMEOUT_COUNTDOWN, retStr);
+                               return retStr;
                        else
-                               return strcat(CPID_TIMEOUT_COUNTDOWN, "");
+                               return "";
                }
        }
        else return "";
@@ -2443,7 +2448,7 @@ void LeaveSpectatorMode()
                                bprint ("^4", self.netname, "^4 is playing now\n");
 
                        if(!autocvar_g_campaign)
-                               centerprint(self, CPID_MOTD); // clear MOTD
+                               Send_CSQC_Centerprint_Generic(self, CPID_MOTD, "", 1, 0); // clear MOTD
 
                        return;
                } else {
@@ -2528,7 +2533,6 @@ void ObserverThink()
                        }
                }
        }
-       PrintWelcomeMessage(self);
 }
 
 void SpectatorThink()
@@ -2568,7 +2572,6 @@ void SpectatorThink()
                }
        }
 
-       PrintWelcomeMessage(self);
        self.flags |= FL_CLIENT | FL_NOTARGET;
 }
 
@@ -2664,8 +2667,6 @@ void PlayerPreThink (void)
 
                CheckRules_Player();
 
-               PrintWelcomeMessage(self);
-
                if (intermission_running)
                {
                        IntermissionThink ();   // otherwise a button could be missed between
@@ -2876,12 +2877,12 @@ void PlayerPreThink (void)
                if(autocvar_g_balance_nex_charge_rot_rate && self.nex_charge > autocvar_g_balance_nex_charge_limit && self.nex_charge_rottime < time)
                        self.nex_charge = bound(autocvar_g_balance_nex_charge_limit, self.nex_charge - autocvar_g_balance_nex_charge_rot_rate * frametime / W_TICSPERFRAME, 1);
 
-               if(frametime)
-                       player_anim();
-
                if (g_minstagib)
                        minstagib_ammocheck();
 
+               if(frametime)
+                       player_anim();
+
                if(g_ctf)
                        ctf_setstatus();
 
@@ -3020,13 +3021,14 @@ void PlayerPostThink (void)
                {
                        if(timeleft != self.idlekick_lasttimeleft)
                        {
-                               centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat(CPID_DISCONNECT_IDLING, "^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
+                               // TODO: send this msg only once
+                               Send_CSQC_Centerprint_Generic(self, CPID_DISCONNECT_IDLING, "^3Stop idling!\n^3Disconnecting in %d seconds...", 1, timeleft);
                                AnnounceTo(self, strcat(ftos(timeleft), ""));
                        }
                }
                else
                {
-                       centerprint_expire(self, CENTERPRIO_IDLEKICK);
+                       Send_CSQC_Centerprint_Generic(self, CPID_DISCONNECT_IDLING, "", 1, timeleft);
                }
                self.idlekick_lasttimeleft = timeleft;
        }
index 043686bd898280058340d096618082ab3d15d676..072dfed8a6640d7159a52f640675f2d17d8c0eb2 100644 (file)
@@ -231,7 +231,7 @@ void weapon_defaultspawnfunc(float wpn);
 
 string w_deathtypestring;
 
-void(entity client, string s) centerprint_builtin = #73;
+// void(entity client, string s) centerprint_builtin = #73;
 .vector dest1, dest2;
 
 float gameover;
index 12a15f4f43a669cde751900ce7e464a9c10e9a72..1175494a7552ec055e2ce4353ef874f008e23c6a 100644 (file)
@@ -103,13 +103,15 @@ void fteqcc_testbugs()
 void timeoutHandler_Think() {
        local string timeStr;
        local entity plr;
+       // NOTE: the below Send_CSQC_Centerprint_Generic send msgs with countdown_num
+       // parameter set as 0, even if the msgs are part of a countdown
        if (timeoutStatus == 1) {
                if (remainingLeadTime > 0) {
                        //centerprint the information to every player
                        timeStr = getTimeoutText(0);
                        FOR_EACH_REALCLIENT(plr) {
                                if(plr.classname == "player") {
-                                       centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
+                                       Send_CSQC_Centerprint_Generic(plr, CPID_TIMEOUT_COUNTDOWN, timeStr, 1, 0);
                                }
                        }
                        remainingLeadTime -= 1;
@@ -136,7 +138,7 @@ void timeoutHandler_Think() {
                        timeStr = getTimeoutText(0);
                        FOR_EACH_REALCLIENT(plr) {
                                if(plr.classname == "player") {
-                                       centerprint_atprio(plr, CENTERPRIO_SPAM, timeStr);
+                                       Send_CSQC_Centerprint_Generic(plr, CPID_TIMEOUT_COUNTDOWN, timeStr, 1, 0);
                                }
                        }
                        if(remainingTimeoutTime == autocvar_sv_timeout_resumetime) { //play a warning sound when only <sv_timeout_resumetime> seconds are left
@@ -156,7 +158,7 @@ void timeoutHandler_Think() {
                        //get rid of the countdown message
                        FOR_EACH_REALCLIENT(plr) {
                                if(plr.classname == "player") {
-                                       centerprint_atprio(plr, CENTERPRIO_SPAM, "");
+                                       Send_CSQC_Centerprint_Generic(plr, CPID_TIMEOUT_COUNTDOWN, "", 1, 0);
                                }
                        }
                        remove(self);
@@ -167,7 +169,7 @@ void timeoutHandler_Think() {
        else if (timeoutStatus == 0) { //if a player called the resumegame command (which set timeoutStatus to 0 already)
                FOR_EACH_REALCLIENT(plr) {
                        if(plr.classname == "player") {
-                               centerprint_atprio(plr, CENTERPRIO_SPAM, "");
+                               Send_CSQC_Centerprint_Generic(plr, CPID_TIMEOUT_COUNTDOWN, "", 1, 0);
                        }
                }
                remove(self);
index 33fcebe10344ed272ea2465ce6f975f33384905c..4fc3b9c5cbaabdd0b03231b98b105b0256534651 100644 (file)
@@ -728,6 +728,7 @@ float NumberToTeamNumber(float number)
 #define CENTERPRIO_ADMIN 99
 .float centerprint_priority;
 .float centerprint_expires;
+void Send_CSQC_Centerprint_Generic(entity e, float id, string s1, float duration, float countdown_num);
 void centerprint_atprio(entity e, float prio, string s)
 {
     if (intermission_running)
@@ -742,7 +743,8 @@ void centerprint_atprio(entity e, float prio, string s)
             e.centerprint_expires = time + (e.cvar_hud_panel_centerprint_time * TIMEOUT_SLOWMO_VALUE);
         else
             e.centerprint_expires = time + e.cvar_hud_panel_centerprint_time;
-        centerprint_builtin(e, s);
+        // centerprint_builtin(e, s);
+        Send_CSQC_Centerprint_Generic(e, 0, s, 0, 0);
     }
 }
 void centerprint_expire(entity e, float prio)
@@ -750,7 +752,8 @@ void centerprint_expire(entity e, float prio)
     if (prio == e.centerprint_priority)
     {
         e.centerprint_priority = 0;
-        centerprint_builtin(e, "");
+        // centerprint_builtin(e, "");
+        Send_CSQC_Centerprint_Generic(e, 0, "", 0, 0);
     }
 }
 void centerprint(entity e, string s)
@@ -1689,6 +1692,26 @@ void precache()
 #define WRITESPECTATABLE_MSG_ONE(statement) WRITESPECTATABLE_MSG_ONE_VARNAME(oldmsg_entity, statement)
 #define WRITESPECTATABLE(msg,statement) if(msg == MSG_ONE) { WRITESPECTATABLE_MSG_ONE(statement); } else statement float WRITESPECTATABLE_workaround = 0
 
+
+void Send_CSQC_Centerprint_Generic(entity e, float id, string s1, float duration, float countdown_num)
+{
+       if (clienttype(e) == CLIENTTYPE_REAL)
+       {
+               msg_entity = e;
+               WRITESPECTATABLE_MSG_ONE({
+                       WriteByte(MSG_ONE, SVC_TEMPENTITY);
+                       WriteByte(MSG_ONE, TE_CSQC_NOTIFY);
+                       WriteByte(MSG_ONE, CSQC_CENTERPRINT_GENERIC);
+                       WriteByte(MSG_ONE, id);
+                       WriteString(MSG_ONE, s1);
+                       if (id != 0)
+                       {
+                               WriteByte(MSG_ONE, duration);
+                               WriteByte(MSG_ONE, countdown_num);
+                       }
+               });
+       }
+}
 // WARNING: this kills the trace globals
 #define EXACTTRIGGER_TOUCH if(WarpZoneLib_ExactTrigger_Touch()) return
 #define EXACTTRIGGER_INIT  WarpZoneLib_ExactTrigger_Init()
index b306b653cf8fae5fb5a0cad43688e4e5281719e1..bed98afba0c65e9c6b18013de507b8405f9ad988 100644 (file)
@@ -98,13 +98,13 @@ void NIX_GiveCurrentWeapon()
                if(dt >= 1 && dt <= 5)
                        self.nix_lastinfotime = -42;
                else
-                       centerprint(self, strcat(CPID_NIX_WPNCHANGE, "\n\n^2Active weapon: ^3", W_Name(nix_weapon)));
+                       Send_CSQC_Centerprint_Generic(self, CPID_NIX_WPNCHANGE, strcat("^2Active weapon: ^3", W_Name(nix_weapon)), 2, dt);
        }
        if(self.nix_lastinfotime != dt)
        {
                self.nix_lastinfotime = dt; // initial value 0 should count as "not seen"
                if(dt >= 1 && dt <= 5)
-                       centerprint(self, strcat(CPID_NIX_WPNCHANGE, "^3", ftos(dt), "^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nix_nextweapon), "\n"));
+                       Send_CSQC_Centerprint_Generic(self, CPID_NIX_WPNCHANGE, strcat("^3%d^2 seconds until weapon change...\n\nNext weapon: ^3", W_Name(nix_nextweapon), "\n"), 1, dt); // TODO: send this msg only once
        }
 
        if(!(self.items & IT_UNLIMITED_WEAPON_AMMO) && time > self.nix_nextincr)
index 0eea40b15c2d5a92ca120067185dbd5bf5d31394..d6e232286343c608a16c38f6049e09201cb6d8d7 100644 (file)
@@ -283,7 +283,6 @@ float Item_GiveTo(entity item, entity player)
                        {
                                pickedup = TRUE;
                                // play some cool sounds ;)
-                               centerprint(player, CPID_MINSTA_FINDAMMO); //clear countdown
                                if (clienttype(player) == CLIENTTYPE_REAL)
                                {
                                        if(player.health <= 5)
index 0acd63080878658a6f6ef43463e988a6bba7c9a8..6ef71b98afd7cfb335599863dd339187dc88abe7 100644 (file)
@@ -455,8 +455,6 @@ void PrintWelcomeMessage(entity pl)
 {
        string s, modifications, motd;
 
-       if(self.cvar_hud_panel_centerprint_time == 0) return;
-
        if(autocvar_g_campaign)
        {
                if(self.classname == "player" && !self.BUTTON_INFO)
@@ -468,11 +466,6 @@ void PrintWelcomeMessage(entity pl)
                        return;
        }
 
-       if( !(timeoutStatus >= 1) ) { //really print the WelcomeMessage to the player every frame when timeout-seconds are shown or the game is restarted, to make sure that the shown number is accurate
-               if(self.welcomemessage_time > time) return;
-               self.welcomemessage_time = time + max(0.5, self.cvar_hud_panel_centerprint_time * 0.6);
-       }
-
        if(autocvar_g_campaign)
        {
                centerprint(pl, campaign_message);
@@ -495,7 +488,7 @@ void PrintWelcomeMessage(entity pl)
                                return;
                        goto normal;
                }
-               return centerprint_atprio(self, CENTERPRIO_SPAM, specString);
+               return centerprint_atprio(self, CENTERPRIO_SPAM, specString); // TODO: convert to Send_CSQC_Centerprint_Generic(self, CPID_TIMEOUT_COUNTDOWN, ...
        }
 
 :normal
@@ -535,7 +528,7 @@ void PrintWelcomeMessage(entity pl)
        local string versionmessage;
        versionmessage = GetClientVersionMessage();
 
-       s = strcat(CPID_MOTD, "This is Xonotic ", autocvar_g_xonoticversion, "\n", versionmessage);
+       s = strcat("This is Xonotic ", autocvar_g_xonoticversion, "\n", versionmessage);
        s = strcat(s, "^8\n\nmatch type is ^1", gamemode_name, "^8\n");
 
        if(modifications != "")
@@ -567,7 +560,7 @@ void PrintWelcomeMessage(entity pl)
        }
        s = strcat(s, "\n");
 
-       centerprint(pl, s);
+       Send_CSQC_Centerprint_Generic(pl, CPID_MOTD, s, autocvar_welcome_message_time, 0);
 }
 
 
index 920d03f71be0f6e62ea8328cd0dd166539627b0a..95225be3aa09c8f1c131c9e312b5280d52943c95 100644 (file)
@@ -88,77 +88,80 @@ void W_MinstaNex_Attack (void)
 
 
 .float minstagib_nextthink;
-void minstagib_ammocheck (void)
+.float minstagib_needammo;
+void minstagib_stop_countdown(void)
 {
-       if (time < self.minstagib_nextthink || self.deadflag || gameover)
+       if (self.minstagib_needammo)
+       {
+               self.health = 100;
+               Send_CSQC_Centerprint_Generic(self, CPID_MINSTA_FINDAMMO, "", 1, 0);
+       }
+       self.minstagib_needammo = FALSE;
+}
+void minstagib_ammocheck(void)
+{
+       if (time < self.minstagib_nextthink)
                return;
 
-       if (self.ammo_cells <= 0)
-       if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
+       if (self.deadflag || gameover || self.ammo_cells > 0 || (self.items & IT_UNLIMITED_WEAPON_AMMO))
+               minstagib_stop_countdown();
+       else
        {
+               self.minstagib_needammo = TRUE;
                if (self.health == 5)
                {
-                       centerprint(self, strcat(CPID_MINSTA_FINDAMMO, "you're dead now...\n"));
                        Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
                        AnnounceTo(self, "terminated");
                }
                else if (self.health == 10)
                {
-                       centerprint(self, strcat(CPID_MINSTA_FINDAMMO, "^11^7 second left to find some ammo\n"));
                        Damage(self, self, self, 5, DEATH_NOAMMO, self.origin, '0 0 0');
                        AnnounceTo(self, "1");
                }
                else if (self.health == 20)
                {
-                       centerprint(self, strcat(CPID_MINSTA_FINDAMMO, "^12^7 seconds left to find some ammo\n"));
                        Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
                        AnnounceTo(self, "2");
                }
                else if (self.health == 30)
                {
-                       centerprint(self, strcat(CPID_MINSTA_FINDAMMO, "^13^7 seconds left to find some ammo\n"));
                        Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
                        AnnounceTo(self, "3");
                }
                else if (self.health == 40)
                {
-                       centerprint(self, strcat(CPID_MINSTA_FINDAMMO, "^14^7 seconds left to find some ammo\n"));
                        Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
                        AnnounceTo(self, "4");
                }
                else if (self.health == 50)
                {
-                       centerprint(self, strcat(CPID_MINSTA_FINDAMMO, "^15^7 seconds left to find some ammo\n"));
                        Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
                        AnnounceTo(self, "5");
                }
                else if (self.health == 60)
                {
-                       centerprint(self, strcat(CPID_MINSTA_FINDAMMO, "^36^7 seconds left to find some ammo\n"));
                        Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
                        AnnounceTo(self, "6");
                }
                else if (self.health == 70)
                {
-                       centerprint(self, strcat(CPID_MINSTA_FINDAMMO, "^37^7 seconds left to find some ammo\n"));
                        Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
                        AnnounceTo(self, "7");
                }
                else if (self.health == 80)
                {
-                       centerprint(self, strcat(CPID_MINSTA_FINDAMMO, "^38^7 seconds left to find some ammo\n"));
                        Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
                        AnnounceTo(self, "8");
                }
                else if (self.health == 90)
                {
-                       centerprint(self, strcat(CPID_MINSTA_FINDAMMO, "^39^7 seconds left to find some ammo\n"));
+                       Send_CSQC_Centerprint_Generic(self, CPID_MINSTA_FINDAMMO, "^1%d^7 second left to find some ammo", 1, 9);
                        Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
                        AnnounceTo(self, "9");
                }
                else if (self.health == 100)
                {
-                       centerprint(self, strcat(CPID_MINSTA_FINDAMMO, "get some ammo or\nyou'll be dead in ^310^7 seconds..."));
+                       Send_CSQC_Centerprint_Generic(self, CPID_MINSTA_FINDAMMO, "get some ammo or\nyou'll be dead in ^3%d^7 seconds...", 1, 10);
                        Damage(self, self, self, 10, DEATH_NOAMMO, self.origin, '0 0 0');
                        if not(self.flags & FL_GODMODE)
                                AnnounceTo(self, "10");