]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
notify messages MOSTLY work... some breakage here and there, please test :/
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index 2cdd8a9160c5fec30ffa0668dbe92e1ee763dfb1..6f4aadffd8f25ccb11ba21407208119394c9f8c6 100644 (file)
@@ -579,6 +579,7 @@ void HUD_Panel_ExportCfg(string cfgname)
                fputs(fh, strcat("seta hud_skin \"", cvar_string("hud_skin"), "\"", "\n"));
                fputs(fh, strcat("seta hud_bg \"", cvar_string("hud_bg"), "\"", "\n"));
                fputs(fh, strcat("seta hud_bg_color \"", cvar_string("hud_bg_color"), "\"", "\n"));
+               fputs(fh, strcat("seta hud_bg_color_team \"", cvar_string("hud_bg_color_team"), "\"", "\n"));
                fputs(fh, strcat("seta hud_bg_alpha \"", cvar_string("hud_bg_alpha"), "\"", "\n"));
                fputs(fh, strcat("seta hud_bg_border \"", cvar_string("hud_bg_border"), "\"", "\n"));
                fputs(fh, strcat("seta hud_bg_padding \"", cvar_string("hud_bg_padding"), "\"", "\n"));
@@ -587,6 +588,7 @@ void HUD_Panel_ExportCfg(string cfgname)
 
                fputs(fh, strcat("seta hud_dock \"", cvar_string("hud_dock"), "\"", "\n"));
                fputs(fh, strcat("seta hud_dock_color \"", cvar_string("hud_dock_color"), "\"", "\n"));
+               fputs(fh, strcat("seta hud_dock_color_team \"", cvar_string("hud_dock_color_team"), "\"", "\n"));
                fputs(fh, strcat("seta hud_dock_alpha \"", ftos(cvar("hud_dock_alpha")), "\"", "\n"));
                fputs(fh, "\n");
 
@@ -608,6 +610,7 @@ void HUD_Panel_ExportCfg(string cfgname)
                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_size \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_size")), "\"", "\n"));
                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg")), "\"", "\n"));
                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color")), "\"", "\n"));
+                       fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_color_team \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_color_team")), "\"", "\n"));
                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_alpha \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_alpha")), "\"", "\n"));
                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_border \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_border")), "\"", "\n"));
                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_padding \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_padding")), "\"", "\n"));
@@ -730,12 +733,24 @@ vector HUD_Panel_GetColor(float id)
        float f;
        vector color_vec;
        string color;
-       color = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color"));
+
+       // fetch per-panel color
+       if(teamplay && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")) != "") {
+               f = stof(getplayerkey(self.sv_entnum, "colors"));
+               color = vtos(colormapPaletteColor(mod(f, 16), 1) * cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")));
+       }
+       else
+               color = cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color"));
        color_vec = stov(color);
-       if(color == "") {
+
+       if(color == "") { // fetch default color
                color = cvar_string("hud_bg_color");
                color_vec = stov(color);
-               if(color == "shirt") {
+               if(teamplay && cvar(strcat("hud_bg_color_team"))) {
+                       f = stof(getplayerkey(self.sv_entnum, "colors"));
+                       color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_bg_color_team");
+               }
+               else if(color == "shirt") {
                        f = stof(getplayerkey(self.sv_entnum, "colors"));
                        color_vec = colormapPaletteColor(floor(f / 16), 0);
                }
@@ -762,7 +777,11 @@ vector HUD_Panel_Dock_GetColor(void)
        string color;
        color = cvar_string("hud_dock_color");
        color_vec = stov(color);
-       if(color == "shirt") {
+       if(teamplay && cvar(strcat("hud_dock_color_team"))) {
+               f = stof(getplayerkey(self.sv_entnum, "colors"));
+               color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_dock_color_team");
+       }
+       else if(color == "shirt") {
                f = stof(getplayerkey(self.sv_entnum, "colors"));
                color_vec = colormapPaletteColor(floor(f / 16), 0);
        }
@@ -1980,9 +1999,12 @@ void HUD_HealthArmor(void)
 // Notification area (#4)
 //
 
-string Weapon_SuicideMessage(float id)
+string Weapon_SuicideMessage(float deathtype)
 {
-       switch (id)
+       float w;
+       w = DEATH_WEAPONOF(deathtype);
+
+       switch (w)
        {
                case 1:
                        return "lasered himself to hell";
@@ -1991,45 +2013,76 @@ string Weapon_SuicideMessage(float id)
                case 3:
                        return "did the impossible";
                case 4:
-                       if(id & HITTYPE_SECONDARY)
+                       if(deathtype & HITTYPE_SECONDARY)
                                return "tried out his own grenade";
                        return "detonated";
        }
        // TODO: was blasted by?
-       return strcat("[no kill message for weapon ", ftos(id), "!]");
+       return strcat("[no kill message for weapon ", ftos(w), "!]");
 }
 
-string Weapon_KillMessage(float id)
+string Weapon_KillMessage(float deathtype)
 {
-       switch (id)
+       float w;
+       w = DEATH_WEAPONOF(deathtype);
+
+       switch (w)
        {
                case 1:
                        return "was lasered to death by";
                case 2:
                        return "was gunned by";
                case 3:
-                       if(id & HITTYPE_SECONDARY)
+                       if(deathtype & HITTYPE_SECONDARY)
                                return "was sniped by";
                        return "was riddled full of holes by";
                case 4:
-                       if(id & HITTYPE_BOUNCE)
+                       if(deathtype & HITTYPE_BOUNCE)
                                return "didn't see #'s grenade";
                        return "almost dodged #'s grenade";
        }
-       return strcat("[no suicide message for weapon ", ftos(id), "!]");
+       return strcat("[no suicide message for weapon ", ftos(w), "!]");
+}
+
+float killnotify_times[10];
+float killnotify_deathtype[10];
+string killnotify_attackers[10];
+string killnotify_victims[10];
+void HUD_KillNotify_Push(string attacker, string victim, float wpn)
+{
+       float i;
+       for (i = 9; i > 0; --i) {
+               killnotify_times[i] = killnotify_times[i-1];
+               killnotify_deathtype[i] = killnotify_deathtype[i-1];
+               if(killnotify_attackers[i])
+                       strunzone(killnotify_attackers[i]);
+               killnotify_attackers[i] = strzone(killnotify_attackers[i-1]);
+               if(killnotify_victims[i])
+                       strunzone(killnotify_victims[i]);
+               killnotify_victims[i] = strzone(killnotify_victims[i-1]);
+       }
+       killnotify_times[0] = time;
+       killnotify_deathtype[0] = wpn;
+       if(killnotify_attackers[0])
+               strunzone(killnotify_attackers[0]);
+       killnotify_attackers[0] = strzone(attacker);
+       if(killnotify_victims[0])
+               strunzone(killnotify_victims[0]);
+       killnotify_victims[0] = strzone(victim);
 }
 
 void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
 {
+       float w;
        if(msg == MSG_SUICIDE) {
-               float w;
-               string w_typestring;
+               HUD_KillNotify_Push(s1, "", DEATH_KILL);
 
-               w = DEATH_WEAPONOF(type);
                // TODO: cl_gentle
-               // TODO: way of finding out secondary?
-               if(type == DEATH_WEAPON)
-                       print("^1", s1, "^1 ", Weapon_SuicideMessage(stof(s3)), "\n");
+               w = DEATH_WEAPONOF(type);
+               if(WEP_VALID(w)) {
+                       if (!HUD_Panel_CheckActive(4) || cvar("hud_notify_print"))
+                               print("^1", s1, "^1 ", Weapon_SuicideMessage(type), "\n");
+               }
                else if (type == DEATH_KILL)
                        print ("^1",s1, "^1 couldn't take it anymore\n");
                else if (type == DEATH_ROT)
@@ -2049,7 +2102,13 @@ void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
                if (stof(s2) > 2) // killcount > 2
                        print ("^1",s1,"^1 ended it all after a ",s2," kill spree\n");
        } else if(msg == MSG_KILL) {
-               if(type == KILL_TEAM || type == KILL_TEAM_SPREE) {
+               w = DEATH_WEAPONOF(type);
+               if(WEP_VALID(w)) {
+                       HUD_KillNotify_Push(s2, s1, w);
+                       if (!HUD_Panel_CheckActive(4) || cvar("hud_notify_print"))
+                               print("^1", s1, "^1 ", Weapon_KillMessage(type), "\n");
+               }
+               else if(type == KILL_TEAM || type == KILL_TEAM_SPREE) {
                                if(cvar("cl_gentle")) {
                                        print ("^1", s1, "^1 took action against a team mate\n");
                                } else {
@@ -2070,27 +2129,41 @@ void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
                }
                else if(type == KILL_FIRST_BLOOD)
                        print("^1",s1, "^1 drew first blood", "\n");
-               else if (type == DEATH_WEAPON)
-                       print("^1", s1, "^1 ", Weapon_KillMessage(stof(s3)), "\n");
                else if (type == DEATH_TELEFRAG)
                        print ("^1",s1, "^1 was telefragged by ", s2, "\n");
-               else if (type == DEATH_DROWN)
+               else if (type == DEATH_DROWN) {
+                       HUD_KillNotify_Push(s2, s1, DEATH_FALL);
                        print ("^1",s1, "^1 was drowned by ", s2, "\n");
-               else if (type == DEATH_SLIME)
+               }
+               else if (type == DEATH_SLIME) {
+                       HUD_KillNotify_Push(s2, s1, DEATH_FALL);
                        print ("^1",s1, "^1 was slimed by ", s2, "\n");
-               else if (type == DEATH_LAVA)
+               }
+               else if (type == DEATH_LAVA) {
+                       HUD_KillNotify_Push(s2, s1, DEATH_FALL);
                        print ("^1",s1, "^1 was cooked by ", s2, "\n");
-               else if (type == DEATH_FALL)
+               }
+               else if (type == DEATH_FALL) {
+                       HUD_KillNotify_Push(s2, s1, DEATH_FALL);
                        print ("^1",s1, "^1 was grounded by ", s2, "\n");
-               else if (type == DEATH_SHOOTING_STAR)
+               }
+               else if (type == DEATH_SHOOTING_STAR) {
+                       HUD_KillNotify_Push(s2, s1, DEATH_FALL);
                        print ("^1",s1, "^1 was shot into space by ", s2, "\n");
-               else if (type == DEATH_SWAMP)
+               }
+               else if (type == DEATH_SWAMP) {
+                       HUD_KillNotify_Push(s2, s1, DEATH_FALL);
                        print ("^1",s1, "^1 was conserved by ", s2, "\n");
-               // TODO
-               /*else if (type == DEATH_HURTTRIGGER && inflictor.msg2 != "")
+               }
+               else if (type == DEATH_HURTTRIGGER && s3 != "")
                {
-                       print("^1", s1, "^1 ", s2, "^1", s3, "\n");
-               }*/
+                       HUD_KillNotify_Push(s2, s1, DEATH_FALL);
+                       // p ?!?! :o
+                       //if(p < 0)
+                               print("^1", s1, "^1 ", s3, " ", s2, "\n");
+                       //else
+                       //      bprint("^1", s1, "^1 ", substring(s3, 0, p), s2, "^1", substring(s3, p+1, strlen(s3) - (p+1)), "\n");
+               }
                else if(type == DEATH_SBCRUSH)
                        print ("^1",s1, "^1 was crushed by ^1", s2, "\n");
                else if(type == DEATH_SBMINIGUN)
@@ -2167,6 +2240,7 @@ void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
                                print (s1,"^7 unleashes ^1ARMAGEDDON!\n");
                }
        } else if(msg == MSG_KILL_ACTION) { // wtf is this? isnt it basically the same as MSG_SUICIDE?
+               HUD_KillNotify_Push(s1, "", DEATH_KILL);
                if (type == DEATH_DROWN) {
                        if(cvar("cl_gentle"))
                                print ("^1",s1, "^1 was in the water for too long\n");
@@ -2214,8 +2288,9 @@ void HUD_KillNotify(string s1, string s2, string s3, float type, float msg)
                                print ("^1",s1, "^1 needs a restart\n");
                        else
                                print ("^1",s1, "^1 died\n");
-               }
+       }
        } else if(msg == MSG_KILL_ACTION_SPREE) {
+               HUD_KillNotify_Push(s1, "", DEATH_KILL);
                if(cvar("cl_gentle"))
                        print ("^1",s1,"^1 needs a restart after a ",s2," scoring spree\n");
                else
@@ -2283,6 +2358,40 @@ void HUD_Notify (void)
                mySize -= '2 2 0' * padding;
        }
 
+       float entries, height;
+       entries = 8 * mySize_y/mySize_x;
+       height = mySize_y/entries;
+       
+       vector fontsize;
+       fontsize = '0.33 0.33 0' * height;
+
+       float a;
+       float when;
+       when = 5;
+       float fadetime;
+       fadetime = 2;
+
+       float i;
+       for(i = 0; i <= entries; ++i)
+       {
+               a = bound(0, when + (fadetime - (time - killnotify_times[i]))/fadetime, 1);
+               drawcolorcodedstring(pos + eY * 0.33 * height + eY * i * height, textShortenToWidth(killnotify_attackers[i], 0.5 * mySize_x - height, fontsize, stringwidth_colors), fontsize, hud_alpha_fg * a, DRAWFLAG_NORMAL);
+               drawcolorcodedstring(pos + eY * 0.33 * height + eX * 0.5 * mySize_x + eX * height + eY * i * height, textShortenToWidth(killnotify_victims[i], 0.5 * mySize_x - height, fontsize, stringwidth_colors), fontsize, hud_alpha_fg * a, DRAWFLAG_NORMAL);
+               
+               if(WEP_VALID(killnotify_deathtype[i]))
+               {
+                       self = get_weaponinfo(killnotify_deathtype[i]);
+                       drawpic_skin(pos + eX * 0.5 * mySize_x - eX * (mySize_y/entries) + eY * i * (mySize_y/entries), strcat("weapon", self.netname), '2 1 0' * (mySize_y/entries), '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);
+               }
+               else if(killnotify_deathtype[i] == DEATH_KILL)
+               {
+                       drawpic_skin(pos + eX * 0.5 * mySize_x - eX * (mySize_y/entries) + eY * i * (mySize_y/entries), "notify_selfkill", '2 1 0' * (mySize_y/entries), '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);   
+               }
+               else if(killnotify_deathtype[i] == DEATH_FALL)
+               {
+                       drawpic_skin(pos + eX * 0.5 * mySize_x - eX * (mySize_y/entries) + eY * i * (mySize_y/entries), "notify_pushoffedge", '2 1 0' * (mySize_y/entries), '1 1 1', hud_alpha_fg * a, DRAWFLAG_NORMAL);        
+               }
+       }
        /* This will come later.
        string s;
        entity tm;
@@ -3547,6 +3656,23 @@ void HUD_Main (void)
        hud_configure = cvar("_hud_configure");
 
        // Drawing stuff
+
+       // HUD configure visible grid
+       if(hud_configure && cvar("hud_configure_grid") && cvar("hud_configure_grid_alpha"))
+       {
+               float i;
+               // x-axis
+               for(i = 0; i < vid_conwidth/cvar("hud_configure_grid_x"); ++i)
+               {
+                       drawfill(eX * i * cvar("hud_configure_grid_x"), eX + eY * vid_conheight, '0.5 0.5 0.5', cvar("hud_configure_grid_alpha"), DRAWFLAG_NORMAL);
+               }
+               // y-axis
+               for(i = 0; i < vid_conheight/cvar("hud_configure_grid_y"); ++i)
+               {
+                       drawfill(eY * i * cvar("hud_configure_grid_y"), eY + eX * vid_conwidth, '0.5 0.5 0.5', cvar("hud_configure_grid_alpha"), DRAWFLAG_NORMAL);
+               }
+       }
+
        if(cvar_string("hud_dock") != "")
                drawpic_skin('0 0 0', cvar_string("hud_dock"), eX * vid_conwidth + eY * vid_conheight, HUD_Panel_Dock_GetColor(), cvar("hud_dock_alpha"), DRAWFLAG_NORMAL);