]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc
Create the g_race_targets, g_racecheckpoints and g_kaballs intrusive lists only when...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / ctf / sv_ctf.qc
index 03b2ec9d1d428a3c7dfce3b0d3cbcb2d5fe05bd1..904d26e8f817f7ebd34dde10ab7cf38fc4f9424d 100644 (file)
@@ -1,7 +1,17 @@
 #include "sv_ctf.qh"
 
 #include <common/effects/all.qh>
+#include <common/mapobjects/teleporters.qh>
+#include <common/mapobjects/triggers.qh>
 #include <common/vehicles/all.qh>
+#include <server/command/vote.qh>
+#include <server/client.qh>
+#include <server/gamelog.qh>
+#include <server/intermission.qh>
+#include <server/damage.qh>
+#include <server/world.qh>
+#include <server/items/items.qh>
+#include <server/race.qh>
 #include <server/teamplay.qh>
 
 #include <lib/warpzone/common.qh>
@@ -48,6 +58,8 @@ bool autocvar_g_ctf_flag_return_when_unreachable;
 float autocvar_g_ctf_flag_return_damage;
 float autocvar_g_ctf_flag_return_damage_delay;
 float autocvar_g_ctf_flag_return_dropped;
+bool autocvar_g_ctf_flag_waypoint = true;
+float autocvar_g_ctf_flag_waypoint_maxdistance;
 float autocvar_g_ctf_flagcarrier_auto_helpme_damage;
 float autocvar_g_ctf_flagcarrier_auto_helpme_time;
 float autocvar_g_ctf_flagcarrier_selfdamagefactor;
@@ -436,7 +448,19 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype)
        if(!flag) { return; }
        if((droptype == DROP_PASS) && !receiver) { return; }
 
-       if(flag.speedrunning) { ctf_RespawnFlag(flag); return; }
+       if(flag.speedrunning)
+       {
+               // ensure old waypoints are removed before resetting the flag
+               WaypointSprite_Kill(player.wps_flagcarrier);
+
+               if(player.wps_enemyflagcarrier)
+                       WaypointSprite_Kill(player.wps_enemyflagcarrier);
+
+               if(player.wps_flagreturn)
+                       WaypointSprite_Kill(player.wps_flagreturn);
+               ctf_RespawnFlag(flag);
+               return;
+       }
 
        // reset the flag
        setattachment(flag, NULL, "");
@@ -520,10 +544,12 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype)
        ctf_CaptureShield_Update(player, 0); // shield player from picking up flag
 }
 
+#if 0
 void shockwave_spawn(string m, vector org, float sz, float t1, float t2)
 {
        return modeleffect_spawn(m, 0, 0, org, '0 0 0', '0 0 0', '0 0 0', 0, sz, 1, t1, t2);
 }
+#endif
 
 // ==============
 // Event Handlers
@@ -587,7 +613,9 @@ void ctf_Handle_Capture(entity flag, entity toucher, int capturetype)
 
        // effects
        Send_Effect_(flag.capeffect, flag.origin, '0 0 0', 1);
-       //shockwave_spawn("models/ctf/shockwavetransring.md3", flag.origin - '0 0 15', -0.8, 0, 1);
+#if 0
+       shockwave_spawn("models/ctf/shockwavetransring.md3", flag.origin - '0 0 15', -0.8, 0, 1);
+#endif
 
        // other
        if(capturetype == CAPTURE_NORMAL)
@@ -1133,6 +1161,7 @@ METHOD(Flag, giveTo, bool(Flag this, entity flag, entity toucher))
 .float last_respawn;
 void ctf_RespawnFlag(entity flag)
 {
+       flag.watertype = CONTENT_EMPTY; // TODO: it is unclear why this workaround is needed, likely many other potential breakage points!!
        // check for flag respawn being called twice in a row
        if(flag.last_respawn > time - 0.5)
                { backtrace("flag respawn called twice quickly! please notify Samual about this..."); }
@@ -1224,10 +1253,14 @@ void ctf_DelayedFlagSetup(entity this) // called after a flag is placed on a map
                default: basename = WP_FlagBaseNeutral; break;
        }
 
-       entity wp = WaypointSprite_SpawnFixed(basename, this.origin + FLAG_WAYPOINT_OFFSET, this, wps_flagbase, RADARICON_FLAG);
-       wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 1 1');
-       WaypointSprite_UpdateTeamRadar(this.wps_flagbase, RADARICON_FLAG, ((this.team) ? colormapPaletteColor(this.team - 1, false) : '1 1 1'));
-       setcefc(wp, ctf_FlagBase_Customize);
+       if(autocvar_g_ctf_flag_waypoint)
+       {
+               entity wp = WaypointSprite_SpawnFixed(basename, this.origin + FLAG_WAYPOINT_OFFSET, this, wps_flagbase, RADARICON_FLAG);
+               wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 1 1');
+               wp.fade_rate = autocvar_g_ctf_flag_waypoint_maxdistance;
+               WaypointSprite_UpdateTeamRadar(this.wps_flagbase, RADARICON_FLAG, ((this.team) ? colormapPaletteColor(this.team - 1, false) : '1 1 1'));
+               setcefc(wp, ctf_FlagBase_Customize);
+       }
 
        // captureshield setup
        ctf_CaptureShield_Spawn(this);
@@ -1235,7 +1268,7 @@ void ctf_DelayedFlagSetup(entity this) // called after a flag is placed on a map
 
 .bool pushable;
 
-void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag entity on the map as a spawnfunc
+void ctf_FlagSetup(int teamnum, entity flag) // called when spawning a flag entity on the map as a spawnfunc
 {
        // main setup
        flag.ctf_worldflagnext = ctf_worldflaglist; // link flag into ctf_worldflaglist
@@ -1243,8 +1276,8 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e
 
        setattachment(flag, NULL, "");
 
-       flag.netname = strzone(sprintf("%s%s^7 flag", Team_ColorCode(teamnumber), Team_ColorName_Upper(teamnumber)));
-       flag.team = teamnumber;
+       flag.netname = strzone(sprintf("%s%s^7 flag", Team_ColorCode(teamnum), Team_ColorName_Upper(teamnum)));
+       flag.team = teamnum;
        flag.classname = "item_flag_team";
        flag.target = "###item###"; // for finding the nearest item using findnearest
        flag.flags = FL_ITEM | FL_NOTARGET;
@@ -1274,24 +1307,24 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e
        if(autocvar_g_ctf_score_ignore_fields)
                flag.cnt = flag.score_assist = flag.score_team_capture = flag.score_capture = flag.score_drop = flag.score_pickup = flag.score_return = 0;
 
-       string teamname = Static_Team_ColorName_Lower(teamnumber);
+       string teamname = Static_Team_ColorName_Lower(teamnum);
        // appearence
        if(!flag.scale)                         { flag.scale = FLAG_SCALE; }
        if(flag.skin == 0)                      { flag.skin = cvar(sprintf("g_ctf_flag_%s_skin", teamname)); }
        if(flag.model == "")            { flag.model = cvar_string(sprintf("g_ctf_flag_%s_model", teamname)); }
-       if (flag.toucheffect == "") { flag.toucheffect = EFFECT_FLAG_TOUCH(teamnumber).eent_eff_name; }
-       if (flag.passeffect == "")      { flag.passeffect = EFFECT_PASS(teamnumber).eent_eff_name; }
-       if (flag.capeffect == "")       { flag.capeffect = EFFECT_CAP(teamnumber).eent_eff_name; }
+       if (flag.toucheffect == "") { flag.toucheffect = EFFECT_FLAG_TOUCH(teamnum).eent_eff_name; }
+       if (flag.passeffect == "")      { flag.passeffect = EFFECT_PASS(teamnum).eent_eff_name; }
+       if (flag.capeffect == "")       { flag.capeffect = EFFECT_CAP(teamnum).eent_eff_name; }
 
        // sounds
 #define X(s,b) \
                if(flag.s == "") flag.s = b; \
                precache_sound(flag.s);
 
-       X(snd_flag_taken,               strzone(SND(CTF_TAKEN(teamnumber))))
-       X(snd_flag_returned,    strzone(SND(CTF_RETURNED(teamnumber))))
-       X(snd_flag_capture,     strzone(SND(CTF_CAPTURE(teamnumber))))
-       X(snd_flag_dropped,     strzone(SND(CTF_DROPPED(teamnumber))))
+       X(snd_flag_taken,               strzone(SND(CTF_TAKEN(teamnum))))
+       X(snd_flag_returned,    strzone(SND(CTF_RETURNED(teamnum))))
+       X(snd_flag_capture,     strzone(SND(CTF_CAPTURE(teamnum))))
+       X(snd_flag_dropped,     strzone(SND(CTF_DROPPED(teamnum))))
        X(snd_flag_respawn,     strzone(SND(CTF_RESPAWN)))
        X(snd_flag_touch,               strzone(SND(CTF_TOUCH)))
        X(snd_flag_pass,                strzone(SND(CTF_PASS)))
@@ -1309,7 +1342,7 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e
 
        if(autocvar_g_ctf_flag_glowtrails)
        {
-               switch(teamnumber)
+               switch(teamnum)
                {
                        case NUM_TEAM_1: flag.glow_color = 251; break;
                        case NUM_TEAM_2: flag.glow_color = 210; break;
@@ -1325,7 +1358,7 @@ void ctf_FlagSetup(int teamnumber, entity flag) // called when spawning a flag e
        if(autocvar_g_ctf_fullbrightflags) { flag.effects |= EF_FULLBRIGHT; }
        if(autocvar_g_ctf_dynamiclights)
        {
-               switch(teamnumber)
+               switch(teamnum)
                {
                        case NUM_TEAM_1: flag.effects |= EF_RED; break;
                        case NUM_TEAM_2: flag.effects |= EF_BLUE; break;
@@ -1387,7 +1420,7 @@ void havocbot_ctf_calculate_middlepoint()
                // for symmetrical editing of waypoints
                entity f1 = ctf_worldflaglist;
                entity f2 = f1.ctf_worldflagnext;
-               float m = -(f1.origin.y - f2.origin.y) / (f1.origin.x - f2.origin.x);
+               float m = -(f1.origin.y - f2.origin.y) / (max(f1.origin.x - f2.origin.x, FLOAT_EPSILON));
                float q = havocbot_middlepoint.y - m * havocbot_middlepoint.x;
                havocbot_symmetry_axis_m = m;
                havocbot_symmetry_axis_q = q;
@@ -2173,7 +2206,7 @@ MUTATOR_HOOKFUNCTION(ctf, PlayerPreThink)
                WaypointSprite_UpdateHealth(player.wps_flagcarrier, healtharmor_maxdamage(GetResource(player, RES_HEALTH), GetResource(player, RES_ARMOR), autocvar_g_balance_armor_blockpercent, DEATH_WEAPON.m_id).x);
 }
 
-MUTATOR_HOOKFUNCTION(ctf, Damage_Calculate) // for changing damage and force values that are applied to players in g_damage.qc
+MUTATOR_HOOKFUNCTION(ctf, Damage_Calculate) // for changing damage and force values that are applied to players in damage.qc
 {
        entity frag_attacker = M_ARGV(1, entity);
        entity frag_target = M_ARGV(2, entity);
@@ -2267,15 +2300,7 @@ MUTATOR_HOOKFUNCTION(ctf, ClientConnect)
 
        entity player = M_ARGV(0, entity);
 
-       if(IS_REAL_CLIENT(player))
-       {
-               int m = min(RANKINGS_CNT, autocvar_g_cts_send_rankings_cnt);
-               race_send_rankings_cnt(MSG_ONE);
-               for (int i = 1; i <= m; ++i)
-               {
-                       race_SendRankings(i, 0, 0, MSG_ONE);
-               }
-       }
+       race_SendAll(player, true);
 }
 
 MUTATOR_HOOKFUNCTION(ctf, GetPressedKeys)
@@ -2285,16 +2310,7 @@ MUTATOR_HOOKFUNCTION(ctf, GetPressedKeys)
 
        entity player = M_ARGV(0, entity);
 
-       if(CS(player).cvar_cl_allow_uidtracking == 1 && CS(player).cvar_cl_allow_uid2name == 1)
-       {
-               if (!player.stored_netname)
-                       player.stored_netname = strzone(uid2name(player.crypto_idfp));
-               if(player.stored_netname != player.netname)
-               {
-                       db_put(ServerProgsDB, strcat("/uid2name/", player.crypto_idfp), player.netname);
-                       strcpy(player.stored_netname, player.netname);
-               }
-       }
+       race_checkAndWriteName(player);
 }
 
 MUTATOR_HOOKFUNCTION(ctf, PortalTeleport)
@@ -2326,7 +2342,7 @@ MUTATOR_HOOKFUNCTION(ctf, PlayerUseKey)
                                if(head != player && SAME_TEAM(head, player))
                                if(!head.speedrunning && !head.vehicle)
                                {
-                                       // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in g_damage.qc)
+                                       // if it's a player, use the view origin as reference (stolen from RadiusDamage functions in damage.qc)
                                        vector head_center = WarpZone_UnTransformOrigin(head, CENTER_OR_VIEWOFS(head));
                                        vector passer_center = CENTER_OR_VIEWOFS(player);
 
@@ -2707,7 +2723,6 @@ spawnfunc(ctf_team)
 {
        if(!g_ctf) { delete(this); return; }
 
-       this.classname = "ctf_team";
        this.team = this.cnt + 1;
 }
 
@@ -2811,6 +2826,8 @@ void ctf_DelayedInit(entity this) // Do this check with a delay so we can wait f
 
 void ctf_Initialize()
 {
+       CTF_FLAG = NEW(Flag);
+       record_type = CTF_RECORD;
        ctf_captimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
 
        ctf_captureshield_min_negscore = autocvar_g_ctf_shield_min_negscore;