]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/domination.qc
make it compile
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / domination.qc
index 578a440990d25045755d6a4afe23fa723b9f5cd0..74c5edaddb188cbf12a1f63d7980fd4501b16862 100644 (file)
@@ -17,31 +17,37 @@ Note: The only teams who can use dom control points are identified by spawnfunc_
 
 #define DOMPOINTFRAGS frags
 
-float g_domination_point_amt;
-float g_domination_point_rate;
-
 .float enemy_playerid;
 .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)
+float dom_total_pps;
+float dom_pps_red;
+float dom_pps_blue;
+float dom_pps_yellow;
+float dom_pps_pink;
+void send_CSQC_dom_state()
+{
+       WriteByte(MSG_ALL, SVC_TEMPENTITY);
+       WriteByte(MSG_ALL, TE_CSQC_DOM);
+       WriteShort(MSG_ALL, dom_pps_red * 100.0);
+       WriteShort(MSG_ALL, dom_pps_blue * 100.0);
+       if (c3 >= 0) WriteShort(MSG_ALL, dom_pps_yellow * 100.0);
+       if (c4 >= 0) WriteShort(MSG_ALL, dom_pps_pink * 100.0);
+}
+//Must be called ONLY when a client connects to send total pps and state
+//If yellow/pink team doesn't exist sends a negative dom_pps_yellow/dom_pps_pink
+//to let know the client to not read these values anymore
+void send_CSQC_dom_all()
 {
-       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;
+       WriteByte(MSG_ALL, SVC_TEMPENTITY);
+       WriteByte(MSG_ALL, TE_CSQC_DOM);
+       WriteShort(MSG_ALL, dom_total_pps * 100.0);
+       WriteShort(MSG_ALL, dom_pps_red * 100.0);
+       WriteShort(MSG_ALL, dom_pps_blue * 100.0);
+       WriteShort(MSG_ALL, dom_pps_yellow * 100.0);
+       WriteShort(MSG_ALL, dom_pps_pink * 100.0);
 }
 
 void() dom_controlpoint_setup;
@@ -49,7 +55,7 @@ void() dom_controlpoint_setup;
 void LogDom(string mode, float team_before, entity actor)
 {
        string s;
-       if(!cvar("sv_eventlog"))
+       if(!autocvar_sv_eventlog)
                return;
        s = strcat(":dom:", mode);
        s = strcat(s, ":", ftos(team_before));
@@ -87,17 +93,20 @@ void dompoint_captured ()
        //bprint("\n");
 
        float points, wait_time;
-       if (g_domination_point_amt)
-               points = g_domination_point_amt;
+       if (autocvar_g_domination_point_amt)
+               points = autocvar_g_domination_point_amt;
        else
                points = self.frags;
-       if (g_domination_point_rate)
-               wait_time = g_domination_point_rate;
+       if (autocvar_g_domination_point_rate)
+               wait_time = autocvar_g_domination_point_rate;
        else
                wait_time = self.wait;
 
        bprint("^3", head.netname, "^3", self.message);
-       bprint(" ^7(", ftos(points), " points every ", ftos(wait_time), " seconds)\n");
+       if (points != 1)
+               bprint(" ^7(", ftos(points), " points every ", ftos(wait_time), " seconds)\n");
+       else
+               bprint(" ^7(", ftos(points), " point every ", ftos(wait_time), " seconds)\n");
 
        if(self.enemy.playerid == self.enemy_playerid)
                PlayerScore_Add(self.enemy, SP_DOM_TAKES, 1);
@@ -112,7 +121,7 @@ void dompoint_captured ()
        if (head.noise1 != "")
                play2all(head.noise1);
 
-       //self.nextthink = time + cvar("g_domination_point_rate");
+       //self.nextthink = time + autocvar_g_domination_point_rate;
        //self.think = dompointthink;
 
        self.delay = time + wait_time;
@@ -129,40 +138,49 @@ void dompoint_captured ()
 
        switch(self.team)
        {
+               // "fix" pps when slightly under 0 because of approximation errors
                case COLOR_TEAM1:
-                       pps_red -= (points/wait_time);
+                       dom_pps_red -= (points/wait_time);
+                       if (dom_pps_red < 0) dom_pps_red = 0;
                        break;
                case COLOR_TEAM2:
-                       pps_blue -= (points/wait_time);
+                       dom_pps_blue -= (points/wait_time);
+                       if (dom_pps_blue < 0) dom_pps_blue = 0;
                        break;
                case COLOR_TEAM3:
-                       pps_yellow -= (points/wait_time);
+                       dom_pps_yellow -= (points/wait_time);
+                       if (dom_pps_yellow < 0) dom_pps_yellow = 0;
                        break;
                case COLOR_TEAM4:
-                       pps_pink -= (points/wait_time);
+                       dom_pps_pink -= (points/wait_time);
+                       if (dom_pps_pink < 0) dom_pps_pink = 0;
        }
 
        switch(self.goalentity.team)
        {
+               // "fix" pps when slightly over dom_total_pps because of approximation errors
                case COLOR_TEAM1:
-                       pps_red += (points/wait_time);
+                       dom_pps_red += (points/wait_time);
+                       if (dom_pps_red > dom_total_pps) dom_pps_red = dom_total_pps;
                        WaypointSprite_UpdateSprites(self.sprite, "dom-red", "", "");
                        break;
                case COLOR_TEAM2:
-                       pps_blue += (points/wait_time);
+                       dom_pps_blue += (points/wait_time);
+                       if (dom_pps_blue > dom_total_pps) dom_pps_blue = dom_total_pps;
                        WaypointSprite_UpdateSprites(self.sprite, "dom-blue", "", "");
                        break;
                case COLOR_TEAM3:
-                       pps_yellow += (points/wait_time);
+                       dom_pps_yellow += (points/wait_time);
+                       if (dom_pps_yellow > dom_total_pps) dom_pps_yellow = dom_total_pps;
                        WaypointSprite_UpdateSprites(self.sprite, "dom-yellow", "", "");
                        break;
                case COLOR_TEAM4:
-                       pps_pink += (points/wait_time);
+                       dom_pps_pink += (points/wait_time);
+                       if (dom_pps_pink > dom_total_pps) dom_pps_pink = dom_total_pps;
                        WaypointSprite_UpdateSprites(self.sprite, "dom-pink", "", "");
        }
 
-       FOR_EACH_CLIENT(head)
-               set_dom_state(head, FALSE);
+       send_CSQC_dom_state();
 
        WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_DOMPOINT, colormapPaletteColor(self.goalentity.team - 1, 0));
        WaypointSprite_Ping(self.sprite);
@@ -199,8 +217,8 @@ void dompointthink()
        if (gameover || self.delay > time || time < game_starttime)     // game has ended, don't keep giving points
                return;
 
-       if(g_domination_point_rate)
-               self.delay = time + g_domination_point_rate;
+       if(autocvar_g_domination_point_rate)
+               self.delay = time + autocvar_g_domination_point_rate;
        else
                self.delay = time + self.wait;
 
@@ -208,8 +226,8 @@ void dompointthink()
        // NOTE: this defaults to 0
        if (self.goalentity.netname != "")
        {
-               if(g_domination_point_amt)
-                       fragamt = g_domination_point_amt;
+               if(autocvar_g_domination_point_amt)
+                       fragamt = autocvar_g_domination_point_amt;
                else
                        fragamt = self.DOMPOINTFRAGS;
                TeamScore_AddToTeam(self.goalentity.team, ST_SCORE, fragamt);
@@ -306,7 +324,7 @@ Keys:
 
 void spawnfunc_dom_team()
 {
-       if(!g_domination || cvar("g_domination_teams_override") >= 2)
+       if(!g_domination || autocvar_g_domination_teams_override >= 2)
        {
                remove(self);
                return;
@@ -347,11 +365,23 @@ void dom_controlpoint_setup()
        if(!self.message)
                self.message = " has captured a control point";
 
-       if(!self.DOMPOINTFRAGS)
+       if(self.DOMPOINTFRAGS <= 0)
                self.DOMPOINTFRAGS = 1;
-       if(!self.wait)
+       if(self.wait <= 0)
                self.wait = 5;
 
+       float points, waittime;
+       if (autocvar_g_domination_point_rate)
+               points = autocvar_g_domination_point_rate;
+       else
+               points = self.frags;
+       if (autocvar_g_domination_point_amt)
+               waittime = autocvar_g_domination_point_amt;
+       else
+               waittime = self.wait;
+
+       dom_total_pps += points/waittime;
+
        if(!self.t_width)
                self.t_width = 0.02; // frame animation rate
        if(!self.t_length)
@@ -381,8 +411,8 @@ void dom_controlpoint_setup()
        float c1, c2, c3, c4, totalteams, smallestteam, smallestteam_count, selectedteam;
        float balance_teams, force_balance, balance_type;
 
-       balance_teams = cvar("g_balance_teams");
-       balance_teams = cvar("g_balance_teams_force");
+       balance_teams = autocvar_g_balance_teams;
+       balance_teams = autocvar_g_balance_teams_force;
 
        c1 = c2 = c3 = c4 = -1;
        totalteams = 0;
@@ -583,19 +613,8 @@ void spawnfunc_dom_controlpoint()
        //if(!self.glow_size)
        //      self.glow_size = cvar("g_domination_point_glow");
        self.effects = self.effects | EF_LOWPRECISION;
-       if (cvar("g_domination_point_fullbright"))
+       if (autocvar_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
@@ -643,10 +662,10 @@ void dom_spawnpoint(vector org)
 void dom_spawnteams()
 {
        float numteams;
-       if(cvar("g_domination_teams_override") < 2)
-               numteams = cvar("g_domination_default_teams");
+       if(autocvar_g_domination_teams_override < 2)
+               numteams = autocvar_g_domination_default_teams;
        else
-               numteams = cvar("g_domination_teams_override");
+               numteams = autocvar_g_domination_teams_override;
        // LordHavoc: edit this if you want to change defaults
        dom_spawnteam("Red", COLOR_TEAM1-1, "models/domination/dom_red.md3", 0, "domination/claim.wav", "", "Red team has captured a control point");
        dom_spawnteam("Blue", COLOR_TEAM2-1, "models/domination/dom_blue.md3", 0, "domination/claim.wav", "", "Blue team has captured a control point");
@@ -662,7 +681,7 @@ void dom_delayedinit()
        local entity head;
 
        // if no teams are found, spawn defaults, if custom teams are set, use them
-       if (find(world, classname, "dom_team") == world || cvar("g_domination_teams_override") >= 2)
+       if (find(world, classname, "dom_team") == world || autocvar_g_domination_teams_override >= 2)
                dom_spawnteams();
        // if no control points are found, spawn defaults
        if (find(world, classname, "dom_controlpoint") == world)
@@ -685,6 +704,8 @@ void dom_delayedinit()
                        }
                }
        }
+       if (c3 == -1) dom_pps_yellow = -1;
+       if (c4 == -1) dom_pps_pink = -1;
 
        ScoreRules_dom();
 };
@@ -701,18 +722,5 @@ void dom_init()
        precache_model("models/domination/dom_unclaimed.md3");
        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");
 };