From 7bd09997998d81090b83aa741db168cfddee3be8 Mon Sep 17 00:00:00 2001 From: Samual Lenks Date: Fri, 13 Sep 2013 20:25:52 -0400 Subject: [PATCH] Make some nice macros for team comparisons --- qcsrc/common/teams.qh | 15 +++++++++----- qcsrc/server/accuracy.qc | 2 +- qcsrc/server/cheats.qc | 4 ++-- qcsrc/server/cl_player.qc | 2 +- qcsrc/server/g_damage.qc | 24 ++++------------------ qcsrc/server/mutators/gamemode_ca.qc | 2 +- qcsrc/server/mutators/gamemode_ctf.qc | 20 +++++++++--------- qcsrc/server/mutators/mutator_minstagib.qc | 4 ++-- qcsrc/server/w_crylink.qc | 6 +++--- qcsrc/server/w_electro.qc | 2 +- qcsrc/server/w_fireball.qc | 4 ++-- qcsrc/server/w_grenadelauncher.qc | 4 ++-- qcsrc/server/w_minelayer.qc | 6 +++--- qcsrc/server/w_rocketlauncher.qc | 2 +- 14 files changed, 43 insertions(+), 54 deletions(-) diff --git a/qcsrc/common/teams.qh b/qcsrc/common/teams.qh index cde71c7b3..ade219a24 100644 --- a/qcsrc/common/teams.qh +++ b/qcsrc/common/teams.qh @@ -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))) diff --git a/qcsrc/server/accuracy.qc b/qcsrc/server/accuracy.qc index b8b167beb..dfc923b2b 100644 --- a/qcsrc/server/accuracy.qc +++ b/qcsrc/server/accuracy.qc @@ -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; } diff --git a/qcsrc/server/cheats.qc b/qcsrc/server/cheats.qc index 5c08d7bbd..f04fc8472 100644 --- a/qcsrc/server/cheats.qc +++ b/qcsrc/server/cheats.qc @@ -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 diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index 1227a3e9d..e5e0c1dda 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -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; diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index 61bde55c7..8c2758224 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -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) { diff --git a/qcsrc/server/mutators/gamemode_ca.qc b/qcsrc/server/mutators/gamemode_ca.qc index fdbf1618b..f55c46e00 100644 --- a/qcsrc/server/mutators/gamemode_ca.qc +++ b/qcsrc/server/mutators/gamemode_ca.qc @@ -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; diff --git a/qcsrc/server/mutators/gamemode_ctf.qc b/qcsrc/server/mutators/gamemode_ctf.qc index 5a9dd79cf..f95d956c0 100644 --- a/qcsrc/server/mutators/gamemode_ctf.qc +++ b/qcsrc/server/mutators/gamemode_ctf.qc @@ -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) diff --git a/qcsrc/server/mutators/mutator_minstagib.qc b/qcsrc/server/mutators/mutator_minstagib.qc index f521e0f67..0d90ea362 100644 --- a/qcsrc/server/mutators/mutator_minstagib.qc +++ b/qcsrc/server/mutators/mutator_minstagib.qc @@ -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; diff --git a/qcsrc/server/w_crylink.qc b/qcsrc/server/w_crylink.qc index b24be5fc5..80af85acf 100644 --- a/qcsrc/server/w_crylink.qc +++ b/qcsrc/server/w_crylink.qc @@ -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; diff --git a/qcsrc/server/w_electro.qc b/qcsrc/server/w_electro.qc index 40fa490f8..dcf4e6563 100644 --- a/qcsrc/server/w_electro.qc +++ b/qcsrc/server/w_electro.qc @@ -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); diff --git a/qcsrc/server/w_fireball.qc b/qcsrc/server/w_fireball.qc index 78ee3009c..b019bcc31 100644 --- a/qcsrc/server/w_fireball.qc +++ b/qcsrc/server/w_fireball.qc @@ -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); diff --git a/qcsrc/server/w_grenadelauncher.qc b/qcsrc/server/w_grenadelauncher.qc index 6312de2fd..db8913b35 100644 --- a/qcsrc/server/w_grenadelauncher.qc +++ b/qcsrc/server/w_grenadelauncher.qc @@ -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); diff --git a/qcsrc/server/w_minelayer.qc b/qcsrc/server/w_minelayer.qc index 1557e9e5e..5d427a5a0 100644 --- a/qcsrc/server/w_minelayer.qc +++ b/qcsrc/server/w_minelayer.qc @@ -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); diff --git a/qcsrc/server/w_rocketlauncher.qc b/qcsrc/server/w_rocketlauncher.qc index 6700e26d2..6c5bae99c 100644 --- a/qcsrc/server/w_rocketlauncher.qc +++ b/qcsrc/server/w_rocketlauncher.qc @@ -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); -- 2.39.2