]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make some nice macros for team comparisons
authorSamual Lenks <samual@xonotic.org>
Sat, 14 Sep 2013 00:25:52 +0000 (20:25 -0400)
committerSamual Lenks <samual@xonotic.org>
Sat, 14 Sep 2013 00:25:52 +0000 (20:25 -0400)
14 files changed:
qcsrc/common/teams.qh
qcsrc/server/accuracy.qc
qcsrc/server/cheats.qc
qcsrc/server/cl_player.qc
qcsrc/server/g_damage.qc
qcsrc/server/mutators/gamemode_ca.qc
qcsrc/server/mutators/gamemode_ctf.qc
qcsrc/server/mutators/mutator_minstagib.qc
qcsrc/server/w_crylink.qc
qcsrc/server/w_electro.qc
qcsrc/server/w_fireball.qc
qcsrc/server/w_grenadelauncher.qc
qcsrc/server/w_minelayer.qc
qcsrc/server/w_rocketlauncher.qc

index cde71c7b3cfdcf8a428d1221170d66d99dda5d77..ade219a2459f9125677760a348a8895afc9712a7 100644 (file)
@@ -36,11 +36,6 @@ const string STATIC_NAME_TEAM_2 = "Blue";
 const string STATIC_NAME_TEAM_3 = "Yellow";
 const string STATIC_NAME_TEAM_4 = "Pink";
 
-#define APP_TEAM_NUM_2(num,prefix) ((num == NUM_TEAM_1) ? prefix##RED : prefix##BLUE)
-#define APP_TEAM_NUM_4(num,prefix) ((num == NUM_TEAM_1) ? prefix##RED : ((num == NUM_TEAM_2) ? prefix##BLUE : ((num == NUM_TEAM_3) ? prefix##YELLOW : prefix##PINK)))
-#define APP_TEAM_ENT_2(ent,prefix) ((ent.team == NUM_TEAM_1) ? prefix##RED : prefix##BLUE)
-#define APP_TEAM_ENT_4(ent,prefix) ((ent.team == NUM_TEAM_1) ? prefix##RED : ((ent.team == NUM_TEAM_2) ? prefix##BLUE : ((ent.team == NUM_TEAM_3) ? prefix##YELLOW : prefix##PINK)))
-
 #ifdef CSQC
 float teamplay;
 float myteam;
@@ -160,3 +155,13 @@ float Team_TeamToNumber(float teamid)
 
 // replace these flags in a string with the strings provided
 #define TCR(input,teamcolor,teamtext) strreplace("^TC", teamcolor, strreplace("^TT", teamtext, input))
+
+// safe team comparisons
+#define SAME_TEAM(a,b) (teamplay ? ((a.team == b.team) ? 1 : 0) : ((a == b) ? 1 : 0))
+#define DIFF_TEAM(a,b) (teamplay ? ((a.team != b.team) ? 1 : 0) : ((a != b) ? 1 : 0))
+
+// used for notification system multi-team identifiers
+#define APP_TEAM_NUM_2(num,prefix) ((num == NUM_TEAM_1) ? prefix##RED : prefix##BLUE)
+#define APP_TEAM_NUM_4(num,prefix) ((num == NUM_TEAM_1) ? prefix##RED : ((num == NUM_TEAM_2) ? prefix##BLUE : ((num == NUM_TEAM_3) ? prefix##YELLOW : prefix##PINK)))
+#define APP_TEAM_ENT_2(ent,prefix) ((ent.team == NUM_TEAM_1) ? prefix##RED : prefix##BLUE)
+#define APP_TEAM_ENT_4(ent,prefix) ((ent.team == NUM_TEAM_1) ? prefix##RED : ((ent.team == NUM_TEAM_2) ? prefix##BLUE : ((ent.team == NUM_TEAM_3) ? prefix##YELLOW : prefix##PINK)))
index b8b167beb37742ff79ca7c4b650cf4fcaf5e696c..dfc923b2bb7d573e5139dcf26390065b8f334170 100644 (file)
@@ -112,7 +112,7 @@ float accuracy_isgooddamage(entity attacker, entity targ)
        if(!warmup_stage)
        if(IS_CLIENT(targ))
        if(targ.deadflag == DEAD_NO)
-       if(IsDifferentTeam(attacker, targ))
+       if(DIFF_TEAM(attacker, targ))
                return TRUE;
        return FALSE;
 }
index 5c08d7bbd0473c2a44ed533e764ae764a65c57a8..f04fc8472288e11ae3b9c6e3da1a0c47e4ed6e82 100644 (file)
@@ -252,7 +252,7 @@ float CheatImpulse(float i)
                        RandomSelection_Init();
                        FOR_EACH_PLAYER(e)
                                if(e.deadflag == DEAD_NO)
-                                       if(IsDifferentTeam(e, self))
+                                       if(DIFF_TEAM(e, self))
                                                RandomSelection_Add(e, 0, string_null, 1, 1);
                        if(RandomSelection_chosen_ent)
                                e = RandomSelection_chosen_ent;
@@ -771,7 +771,7 @@ float CheatFrame()
                                                                drag = TRUE;
                                                        break;
                                                case 2: // owner and team mates can grab
-                                                       if(!IsDifferentTeam(trace_ent.owner, self) || !IsDifferentTeam(trace_ent.realowner, self) || trace_ent.team == self.team)
+                                                       if(SAME_TEAM(trace_ent.owner, self) || SAME_TEAM(trace_ent.realowner, self) || trace_ent.team == self.team)
                                                                drag = TRUE;
                                                        break;
                                                case 3: // anyone can grab
index 1227a3e9da8329e3982224836710f5d0f4c3b85c..e5e0c1dda5516b22ce098311cdc239db3369899f 100644 (file)
@@ -495,7 +495,7 @@ void PlayerDamage (entity inflictor, entity attacker, float damage, float deatht
        if(vbot || IS_REAL_CLIENT(self))
        if(abot || IS_REAL_CLIENT(attacker))
        if(attacker && self != attacker)
-       if(IsDifferentTeam(self, attacker))
+       if(DIFF_TEAM(self, attacker))
        {
                if(DEATH_ISSPECIAL(deathtype))
                        awep = attacker.weapon;
index 61bde55c7fabaa952ceeb9dccae6881c5b226b64..8c275822481d1a30ad13ac8020de9921389398c3 100644 (file)
@@ -56,22 +56,6 @@ float damage_gooddamage;
 .float istypefrag;
 .float taunt_soundtime;
 
-
-float IsDifferentTeam(entity a, entity b)
-{
-       if(teamplay)
-       {
-               if(a.team == b.team)
-                       return 0;
-       }
-       else
-       {
-               if(a == b)
-                       return 0;
-       }
-       return 1;
-}
-
 float IsFlying(entity a)
 {
        if(a.flags & FL_ONGROUND)
@@ -409,7 +393,7 @@ void Obituary(entity attacker, entity inflictor, entity targ, float deathtype)
        // ======
        else if(IS_PLAYER(attacker))
        {
-               if(!IsDifferentTeam(attacker, targ))
+               if(SAME_TEAM(attacker, targ))
                {
                        LogDeath("tk", deathtype, attacker, targ);
                        GiveFrags(attacker, targ, -1, deathtype);
@@ -600,7 +584,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
        if(DEATH_ISWEAPON(deathtype, WEP_HOOK) || DEATH_ISWEAPON(deathtype, WEP_TUBA))
        {
                if(IS_PLAYER(targ))
-                       if not(IsDifferentTeam(targ, attacker))
+                       if(SAME_TEAM(targ, attacker))
                        {
                                self = oldself;
                                return;
@@ -633,7 +617,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                                damage = 0;
                                force = '0 0 0';
                        }
-                       else if(!IsDifferentTeam(attacker, targ))
+                       else if(SAME_TEAM(attacker, targ))
                        {
                                if(autocvar_teamplay_mode == 1)
                                        damage = 0;
@@ -746,7 +730,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
 
                        if(IS_PLAYER(victim) || victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET)
                        {
-                               if(IsDifferentTeam(victim, attacker))
+                               if(DIFF_TEAM(victim, attacker))
                                {
                                        if(damage > 0)
                                        {
index fdbf1618bfc26397b8391c2383d981ee256ae169..f55c46e00ad5e34468bdfaae2e614227e7702aba 100644 (file)
@@ -242,7 +242,7 @@ MUTATOR_HOOKFUNCTION(ca_PlayerDamage)
 {
        if(IS_PLAYER(frag_target))
        if(frag_target.deadflag == DEAD_NO)
-       if(frag_target == frag_attacker || !IsDifferentTeam(frag_target, frag_attacker) || frag_deathtype == DEATH_FALL)
+       if(frag_target == frag_attacker || SAME_TEAM(frag_target, frag_attacker) || frag_deathtype == DEATH_FALL)
                frag_damage = 0;
                
        frag_mirrordamage = 0;
index 5a9dd79cf721ec30d8f0cb5639f10317a8854b20..f95d956c0f671ca0efe6b642b7ee596978044e5e 100644 (file)
@@ -132,7 +132,7 @@ float ctf_CaptureShield_CheckStatus(entity p)
        players_total = players_worseeq = 0;
        FOR_EACH_PLAYER(e)
        {
-               if(IsDifferentTeam(e, p))
+               if(DIFF_TEAM(e, p))
                        continue;
                se = PlayerScore_Add(e, SP_SCORE, 0);
                if(se <= s)
@@ -162,7 +162,7 @@ void ctf_CaptureShield_Update(entity player, float wanted_status)
 float ctf_CaptureShield_Customize()
 {
        if(!other.ctf_captureshielded) { return FALSE; }
-       if(!IsDifferentTeam(self, other)) { return FALSE; }
+       if(SAME_TEAM(self, other)) { return FALSE; }
        
        return TRUE;
 }
@@ -170,7 +170,7 @@ float ctf_CaptureShield_Customize()
 void ctf_CaptureShield_Touch()
 {
        if(!other.ctf_captureshielded) { return; }
-       if(!IsDifferentTeam(self, other)) { return; }
+       if(SAME_TEAM(self, other)) { return; }
        
        vector mymid = (self.absmin + self.absmax) * 0.5;
        vector othermid = (other.absmin + other.absmax) * 0.5;
@@ -275,7 +275,7 @@ void ctf_Handle_Retrieve(entity flag, entity player)
                        Send_Notification(NOTIF_ONE, tmp_player, MSG_CENTER, APP_TEAM_ENT_2(flag, CENTER_CTF_PASS_SENT_), player.netname);
                else if(tmp_player == player)
                        Send_Notification(NOTIF_ONE, tmp_player, MSG_CENTER, APP_TEAM_ENT_2(flag, CENTER_CTF_PASS_RECEIVED_), sender.netname);
-               else if(!IsDifferentTeam(tmp_player, sender))
+               else if(SAME_TEAM(tmp_player, sender))
                        Send_Notification(NOTIF_ONE, tmp_player, MSG_CENTER, APP_TEAM_ENT_2(flag, CENTER_CTF_PASS_OTHER_), sender.netname, player.netname);
        }
        
@@ -803,16 +803,16 @@ void ctf_FlagTouch()
        {       
                case FLAG_BASE:
                {
-                       if(!IsDifferentTeam(toucher, self) && (toucher.flagcarried) && IsDifferentTeam(toucher.flagcarried, self))
+                       if(SAME_TEAM(toucher, self) && (toucher.flagcarried) && DIFF_TEAM(toucher.flagcarried, self))
                                ctf_Handle_Capture(self, toucher, CAPTURE_NORMAL); // toucher just captured the enemies flag to his base
-                       else if(IsDifferentTeam(toucher, self) && (!toucher.flagcarried) && (!toucher.ctf_captureshielded) && (time > toucher.next_take_time))
+                       else if(DIFF_TEAM(toucher, self) && (!toucher.flagcarried) && (!toucher.ctf_captureshielded) && (time > toucher.next_take_time))
                                ctf_Handle_Pickup(self, toucher, PICKUP_BASE); // toucher just stole the enemies flag
                        break;
                }
                
                case FLAG_DROPPED:
                {
-                       if(!IsDifferentTeam(toucher, self))
+                       if(SAME_TEAM(toucher, self))
                                ctf_Handle_Return(self, toucher); // toucher just returned his own flag
                        else if((!toucher.flagcarried) && ((toucher != self.ctf_dropper) || (time > self.ctf_droptime + autocvar_g_ctf_flag_collect_delay)))
                                ctf_Handle_Pickup(self, toucher, PICKUP_DROPPED); // toucher just picked up a dropped enemy flag
@@ -829,7 +829,7 @@ void ctf_FlagTouch()
                {
                        if((IS_PLAYER(toucher)) && (toucher.deadflag == DEAD_NO) && (toucher != self.pass_sender))
                        {
-                               if(IsDifferentTeam(toucher, self.pass_sender))
+                               if(DIFF_TEAM(toucher, self.pass_sender))
                                        ctf_Handle_Return(self, toucher);
                                else
                                        ctf_Handle_Retrieve(self, toucher);
@@ -1728,7 +1728,7 @@ MUTATOR_HOOKFUNCTION(ctf_PlayerDamage) // for changing damage and force values t
                        frag_force *= autocvar_g_ctf_flagcarrier_forcefactor;
                }
        }
-       else if(frag_target.flagcarried && (frag_target.deadflag == DEAD_NO) && IsDifferentTeam(frag_target, frag_attacker)) // if the target is a flagcarrier
+       else if(frag_target.flagcarried && (frag_target.deadflag == DEAD_NO) && DIFF_TEAM(frag_target, frag_attacker)) // if the target is a flagcarrier
        {
                if(autocvar_g_ctf_flagcarrier_auto_helpme_damage > ('1 0 0' * healtharmor_maxdamage(frag_target.health, frag_target.armorvalue, autocvar_g_balance_armor_blockpercent)))
                if(time > frag_target.wps_helpme_time + autocvar_g_ctf_flagcarrier_auto_helpme_time)
@@ -1804,7 +1804,7 @@ MUTATOR_HOOKFUNCTION(ctf_PlayerUseKey)
                        while(head) // find the closest acceptable target to pass to
                        {
                                if(IS_PLAYER(head) && head.deadflag == DEAD_NO)
-                               if(head != player && !IsDifferentTeam(head, player))
+                               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) 
index f521e0f67b427ff5efdaafbd145f6366afd8f5ed..0d90ea36219510db62e2ff2308d4bd6fff283054 100644 (file)
@@ -210,7 +210,7 @@ MUTATOR_HOOKFUNCTION(minstagib_ForbidThrowing)
 
 MUTATOR_HOOKFUNCTION(minstagib_PlayerDamage)
 {
-       if(autocvar_g_friendlyfire == 0 && !IsDifferentTeam(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
+       if(autocvar_g_friendlyfire == 0 && SAME_TEAM(frag_target, frag_attacker) && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
                frag_damage = 0;
                
        if(IS_PLAYER(frag_target))
@@ -324,7 +324,7 @@ MUTATOR_HOOKFUNCTION(minstagib_CustomizeWaypoint)
        // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
        // but only apply this to real players, not to spectators
        if((self.owner.flags & FL_CLIENT) && (self.owner.items & IT_STRENGTH) && (e == other))
-       if(IsDifferentTeam(self.owner, e))
+       if(DIFF_TEAM(self.owner, e))
                return TRUE;
        
        return FALSE;
index b24be5fc56bebd5f9d57421f4c92799f1500f4cc..80af85acf34a3af5a65c631803aec4e2174aa70f 100644 (file)
@@ -236,10 +236,10 @@ float W_Crylink_Touch_WouldHitFriendly(entity projectile, float rad)
        {
                if((head.takedamage != DAMAGE_NO) && (head.deadflag == DEAD_NO))
                {
-                       if(IsDifferentTeam(head, projectile.realowner))
-                               ++hit_enemy;
-                       else
+                       if(SAME_TEAM(head, projectile.realowner))
                                ++hit_friendly;
+                       else
+                               ++hit_enemy;
                }
                        
                head = head.chain;
index 40fa490f8498b97494b58d0efc4df1cf56ab2744..dcf4e6563344547210e5c847e8842e9e11dece03 100644 (file)
@@ -40,7 +40,7 @@ void W_Plasma_Explode (void)
 {
        if(other.takedamage == DAMAGE_AIM)
                if(IS_PLAYER(other))
-                       if(IsDifferentTeam(self.realowner, other))
+                       if(DIFF_TEAM(self.realowner, other))
                                if(other.deadflag == DEAD_NO)
                                        if(IsFlying(other))
                                                Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_ELECTROBITCH);
index 78ee3009cee1e784e8c7ceb199635230a213701f..b019bcc3163c7cd0e0661b18f8e5c042f17153aa 100644 (file)
@@ -38,7 +38,7 @@ void W_Fireball_Explode (void)
                // 2. bfg effect
                // NOTE: this cannot be made warpzone aware by design. So, better intentionally ignore warpzones here.
                for(e = findradius(self.origin, autocvar_g_balance_fireball_primary_bfgradius); e; e = e.chain)
-               if(e != self.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !self.realowner || IsDifferentTeam(e, self))
+               if(e != self.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
                {
                        // can we see fireball?
                        traceline(e.origin + e.view_ofs, self.origin, MOVE_NORMAL, e);
@@ -83,7 +83,7 @@ void W_Fireball_LaserPlay(float dt, float dist, float damage, float edgedamage,
 
        RandomSelection_Init();
        for(e = WarpZone_FindRadius(self.origin, dist, TRUE); e; e = e.chain)
-       if(e != self.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !self.realowner || IsDifferentTeam(e, self))
+       if(e != self.realowner) if(e.takedamage == DAMAGE_AIM) if(!IS_PLAYER(e) || !self.realowner || DIFF_TEAM(e, self))
        {
                p = e.origin;
                p_x += e.mins_x + random() * (e.maxs_x - e.mins_x);
index 6312de2fd8bddcf644d3cfbc291323f38420a41d..db8913b351ccb3f1acb37e2c649edb4491bf353f 100644 (file)
@@ -19,7 +19,7 @@ void W_Grenade_Explode (void)
 {
        if(other.takedamage == DAMAGE_AIM)
                if(IS_PLAYER(other))
-                       if(IsDifferentTeam(self.realowner, other))
+                       if(DIFF_TEAM(self.realowner, other))
                                if(other.deadflag == DEAD_NO)
                                        if(IsFlying(other))
                                                Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
@@ -39,7 +39,7 @@ void W_Grenade_Explode2 (void)
 {
        if(other.takedamage == DAMAGE_AIM)
                if(IS_PLAYER(other))
-                       if(IsDifferentTeam(self.realowner, other))
+                       if(DIFF_TEAM(self.realowner, other))
                                if(other.deadflag == DEAD_NO)
                                        if(IsFlying(other))
                                                Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
index 1557e9e5ee4e9ef7d1607c2595ac48fff24a6070..5d427a5a0f1b02b9745e857c2b4b16679fa1b2fb 100644 (file)
@@ -73,7 +73,7 @@ void W_Mine_Explode ()
 {
        if(other.takedamage == DAMAGE_AIM)
                if(IS_PLAYER(other))
-                       if(IsDifferentTeam(self.realowner, other))
+                       if(DIFF_TEAM(self.realowner, other))
                                if(other.deadflag == DEAD_NO)
                                        if(IsFlying(other))
                                                Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);
@@ -148,7 +148,7 @@ void W_Mine_ProximityExplode ()
                head = findradius(self.origin, autocvar_g_balance_minelayer_radius);
                while(head)
                {
-                       if(head == self.realowner || !IsDifferentTeam(head, self.realowner))
+                       if(head == self.realowner || SAME_TEAM(head, self.realowner))
                                return;
                        head = head.chain;
                }
@@ -208,7 +208,7 @@ void W_Mine_Think (void)
        while(head)
        {
                if(IS_PLAYER(head) && head.deadflag == DEAD_NO)
-               if(head != self.realowner && IsDifferentTeam(head, self.realowner)) // don't trigger for team mates
+               if(head != self.realowner && DIFF_TEAM(head, self.realowner)) // don't trigger for team mates
                if(!self.mine_time)
                {
                        spamsound (self, CH_SHOTS, "weapons/mine_trigger.wav", VOL_BASE, ATTEN_NORM);
index 6700e26d20c0d5c43e6bab112b27d7c4933f9513..6c5bae99c13f13683ac0c7ebee3eb3c92c582a55 100644 (file)
@@ -30,7 +30,7 @@ void W_Rocket_Explode ()
 
        if(other.takedamage == DAMAGE_AIM)
                if(IS_PLAYER(other))
-                       if(IsDifferentTeam(self.realowner, other))
+                       if(DIFF_TEAM(self.realowner, other))
                                if(other.deadflag == DEAD_NO)
                                        if(IsFlying(other))
                                                Send_Notification(NOTIF_ONE, self.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT);