Merge branch 'master' into terencehill/newpanelhud-dom_points
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / domination.qc
index 3e5bed8b25f23c35247fa2cf1c50c14da053dc3c..17e2e5fe0bbaabfefd1f8dd4790129b5778a035e 100644 (file)
@@ -24,6 +24,26 @@ float g_domination_point_rate;
 .entity sprite;
 .float captime;
 
+// pps: points per second
+.float dom_total_pps;
+.float dom_pps_red;
+.float dom_pps_blue;
+.float dom_pps_yellow;
+.float dom_pps_pink;
+float total_pps;
+float pps_red;
+float pps_blue;
+float pps_yellow;
+float pps_pink;
+void set_dom_state(entity e, float connecting)
+{
+       if(connecting)  e.dom_total_pps = total_pps;
+                                       e.dom_pps_red = pps_red;
+                                       e.dom_pps_blue = pps_blue;
+       if(c3 >= 0)             e.dom_pps_yellow = pps_yellow;
+       if(c4 >= 0)             e.dom_pps_pink = pps_pink;
+}
+
 void() dom_controlpoint_setup;
 
 void LogDom(string mode, float team_before, entity actor)
@@ -110,21 +130,53 @@ void dompoint_captured ()
        self.delay = old_delay;
        self.team = old_team;
 
+       switch(self.team)
+       {
+               // "fix" pps when slightly under 0 because of approximation errors
+               case COLOR_TEAM1:
+                       pps_red -= (points/wait_time);
+                       if (pps_red < 0) pps_red = 0;
+                       break;
+               case COLOR_TEAM2:
+                       pps_blue -= (points/wait_time);
+                       if (pps_blue < 0) pps_blue = 0;
+                       break;
+               case COLOR_TEAM3:
+                       pps_yellow -= (points/wait_time);
+                       if (pps_yellow < 0) pps_yellow = 0;
+                       break;
+               case COLOR_TEAM4:
+                       pps_pink -= (points/wait_time);
+                       if (pps_pink < 0) pps_pink = 0;
+       }
+
        switch(self.goalentity.team)
        {
+               // "fix" pps when slightly over total_pps because of approximation errors
                case COLOR_TEAM1:
+                       pps_red += (points/wait_time);
+                       if (pps_red > total_pps) pps_red = total_pps;
                        WaypointSprite_UpdateSprites(self.sprite, "dom-red", "", "");
                        break;
                case COLOR_TEAM2:
+                       pps_blue += (points/wait_time);
+                       if (pps_blue > total_pps) pps_blue = total_pps;
                        WaypointSprite_UpdateSprites(self.sprite, "dom-blue", "", "");
                        break;
                case COLOR_TEAM3:
+                       pps_yellow += (points/wait_time);
+                       if (pps_yellow > total_pps) pps_yellow = total_pps;
                        WaypointSprite_UpdateSprites(self.sprite, "dom-yellow", "", "");
                        break;
                case COLOR_TEAM4:
+                       pps_pink += (points/wait_time);
+                       if (pps_pink > total_pps) pps_pink = total_pps;
                        WaypointSprite_UpdateSprites(self.sprite, "dom-pink", "", "");
-                       break;
        }
+
+       FOR_EACH_CLIENT(head)
+               set_dom_state(head, FALSE);
+
        WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_DOMPOINT, colormapPaletteColor(self.goalentity.team - 1, 0));
        WaypointSprite_Ping(self.sprite);
 
@@ -160,9 +212,6 @@ void dompointthink()
        if (gameover || self.delay > time || time < game_starttime)     // game has ended, don't keep giving points
                return;
 
-       g_domination_point_rate = cvar("g_domination_point_rate");
-       g_domination_point_amt = cvar("g_domination_point_amt");
-
        if(g_domination_point_rate)
                self.delay = time + g_domination_point_rate;
        else
@@ -549,6 +598,17 @@ void spawnfunc_dom_controlpoint()
        self.effects = self.effects | EF_LOWPRECISION;
        if (cvar("g_domination_point_fullbright"))
                self.effects |= EF_FULLBRIGHT;
+       
+       float points, waittime;
+       if (g_domination_point_rate)
+               points += g_domination_point_rate;
+       else
+               points += self.frags;
+       if (g_domination_point_amt)
+               waittime += g_domination_point_amt;
+       else
+               waittime += self.wait;
+       total_pps += points/waittime;
 };
 
 // code from here on is just to support maps that don't have control point and team entities
@@ -655,6 +715,15 @@ void dom_init()
        precache_sound("domination/claim.wav");
        InitializeEntity(world, dom_delayedinit, INITPRIO_GAMETYPE);
 
+       addstat(STAT_DOM_TOTAL_PPS, AS_FLOAT, dom_total_pps);
+       addstat(STAT_DOM_PPS_RED, AS_FLOAT, dom_pps_red);
+       addstat(STAT_DOM_PPS_BLUE, AS_FLOAT, dom_pps_blue);
+       if(c3 >= 0) addstat(STAT_DOM_PPS_YELLOW, AS_FLOAT, dom_pps_yellow);
+       if(c4 >= 0) addstat(STAT_DOM_PPS_PINK, AS_FLOAT, dom_pps_pink);
+
+       g_domination_point_rate = cvar("g_domination_point_rate");
+       g_domination_point_amt = cvar("g_domination_point_amt");
+
        // teamplay is always on in domination, defaults to hurt self but not teammates
        //if(!teams_matter)
        //      cvar_set("teamplay", "3");