From: Mario Date: Tue, 18 Aug 2015 23:42:25 +0000 (+1000) Subject: Add IS_MONSTER, IS_TURRET & IS_VEHICLE macros X-Git-Tag: xonotic-v0.8.2~2064^2~3 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b60641e56c648beebc66d628305fb652dc6db571;p=xonotic%2Fxonotic-data.pk3dir.git Add IS_MONSTER, IS_TURRET & IS_VEHICLE macros --- diff --git a/qcsrc/common/monsters/monster/mage.qc b/qcsrc/common/monsters/monster/mage.qc index ec1e4be31..c531fe025 100644 --- a/qcsrc/common/monsters/monster/mage.qc +++ b/qcsrc/common/monsters/monster/mage.qc @@ -67,7 +67,7 @@ float friend_needshelp(entity e) if(e.frozen) return false; if(!IS_PLAYER(e)) - return ((e.flags & FL_MONSTER) && e.health < e.max_health); + return (IS_MONSTER(e) && e.health < e.max_health); if(e.items & IT_INVINCIBLE) return false; diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index 239f8fe9a..720b9561c 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -81,7 +81,7 @@ float monster_isvalidtarget (entity targ, entity ent) //if(trace_ent != targ) //return false; - if(targ.vehicle_flags & VHF_ISVEHICLE) + if(IS_VEHICLE(targ)) if(!((get_monsterinfo(ent.monsterid)).spawnflags & MON_FLAG_RANGED)) return false; // melee attacks are useless against vehicles @@ -100,7 +100,7 @@ float monster_isvalidtarget (entity targ, entity ent) if(IS_SPEC(targ) || IS_OBSERVER(targ)) return false; // enemy is a spectator - if(!(targ.vehicle_flags & VHF_ISVEHICLE)) + if(!IS_VEHICLE(targ)) if(targ.deadflag != DEAD_NO || ent.deadflag != DEAD_NO || targ.health <= 0 || ent.health <= 0) return false; // enemy/self is dead @@ -110,7 +110,7 @@ float monster_isvalidtarget (entity targ, entity ent) if(targ.monster_owner == ent) return false; // don't attack our pet - if(!(targ.vehicle_flags & VHF_ISVEHICLE)) + if(!IS_VEHICLE(targ)) if(targ.flags & FL_NOTARGET) return false; // enemy can't be targeted @@ -182,7 +182,7 @@ void MonsterTouch () return; if(self.enemy != other) - if(!(other.flags & FL_MONSTER)) + if(!IS_MONSTER(other)) if(monster_isvalidtarget(other, self)) self.enemy = other; } diff --git a/qcsrc/common/triggers/func/ladder.qc b/qcsrc/common/triggers/func/ladder.qc index f0216ccd1..5a96b9bb6 100644 --- a/qcsrc/common/triggers/func/ladder.qc +++ b/qcsrc/common/triggers/func/ladder.qc @@ -3,7 +3,7 @@ void func_ladder_touch() #ifdef SVQC if (!other.iscreature) return; - if (other.vehicle_flags & VHF_ISVEHICLE) + if(IS_VEHICLE(other)) return; #endif #ifdef CSQC diff --git a/qcsrc/common/triggers/trigger/teleport.qc b/qcsrc/common/triggers/trigger/teleport.qc index 5ff5fcf33..d983cf3ae 100644 --- a/qcsrc/common/triggers/trigger/teleport.qc +++ b/qcsrc/common/triggers/trigger/teleport.qc @@ -23,7 +23,7 @@ void Teleport_Touch (void) if(!other.vehicle.teleportable) return; - if(other.turrcaps_flags & TFL_TURRCAPS_ISTURRET) + if(IS_TURRET(other)) return; if(other.deadflag != DEAD_NO) diff --git a/qcsrc/common/weapons/w_arc.qc b/qcsrc/common/weapons/w_arc.qc index 79d4dc7c7..83fff0cdc 100644 --- a/qcsrc/common/weapons/w_arc.qc +++ b/qcsrc/common/weapons/w_arc.qc @@ -449,11 +449,11 @@ void W_Arc_Beam_Think(void) new_dir = WarpZone_TransformVelocity(WarpZone_trace_transform, new_dir); float is_player = ( - trace_ent.classname == "player" + IS_PLAYER(trace_ent) || trace_ent.classname == "body" || - (trace_ent.flags & FL_MONSTER) + IS_MONSTER(trace_ent) ); if(trace_ent && trace_ent.takedamage && (is_player || WEP_CVAR(arc, beam_nonplayerdamage))) diff --git a/qcsrc/common/weapons/w_shockwave.qc b/qcsrc/common/weapons/w_shockwave.qc index d23ce753a..17189bd4a 100644 --- a/qcsrc/common/weapons/w_shockwave.qc +++ b/qcsrc/common/weapons/w_shockwave.qc @@ -158,7 +158,7 @@ void W_Shockwave_Melee_Think(void) te_customflash(targpos, 40, 2, '1 1 1'); #endif - is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || (trace_ent.flags & FL_MONSTER)); + is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || IS_MONSTER(trace_ent)); if((trace_fraction < 1) // if trace is good, apply the damage and remove self if necessary && (trace_ent.takedamage == DAMAGE_AIM) diff --git a/qcsrc/common/weapons/w_shotgun.qc b/qcsrc/common/weapons/w_shotgun.qc index 5415b4a6f..16195e00a 100644 --- a/qcsrc/common/weapons/w_shotgun.qc +++ b/qcsrc/common/weapons/w_shotgun.qc @@ -125,7 +125,7 @@ void W_Shotgun_Melee_Think(void) //te_lightning2(world, targpos, self.realowner.origin + self.realowner.view_ofs + v_forward * 5 - v_up * 5); //te_customflash(targpos, 40, 2, '1 1 1'); - is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || (trace_ent.flags & FL_MONSTER)); + is_player = (IS_PLAYER(trace_ent) || trace_ent.classname == "body" || IS_MONSTER(trace_ent)); if((trace_fraction < 1) // if trace is good, apply the damage and remove self && (trace_ent.takedamage == DAMAGE_AIM) diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index eec507f07..113967b2c 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -232,7 +232,7 @@ void ClientCommand_mobedit(float request, float argc) WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * 100, MOVE_NORMAL, self); if(!autocvar_g_monsters_edit) { sprint(self, "Monster property editing is not enabled.\n"); return; } - if(trace_ent.flags & FL_MONSTER) + if(IS_MONSTER(trace_ent)) { if(trace_ent.realowner != self) { sprint(self, "That monster does not belong to you.\n"); return; } switch(argv(1)) @@ -273,7 +273,7 @@ void ClientCommand_mobkill(float request) makevectors(self.v_angle); WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * 100, MOVE_NORMAL, self); - if(trace_ent.flags & FL_MONSTER) + if(IS_MONSTER(trace_ent)) { if(trace_ent.realowner != self) { diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index c5bbfcab5..b6f6fc8c7 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -557,13 +557,13 @@ void Ice_Think() void Freeze (entity targ, float freeze_time, float frozen_type, float show_waypoint) { - if(!IS_PLAYER(targ) && !(targ.flags & FL_MONSTER)) // only specified entities can be freezed + if(!IS_PLAYER(targ) && !IS_MONSTER(targ)) // only specified entities can be freezed return; if(targ.frozen) return; - float targ_maxhealth = ((targ.flags & FL_MONSTER) ? targ.max_health : start_health); + float targ_maxhealth = ((IS_MONSTER(targ)) ? targ.max_health : start_health); targ.frozen = frozen_type; targ.revive_progress = ((frozen_type == 3) ? 1 : 0); @@ -849,12 +849,12 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, int d if(targ != attacker) { entity victim; - if((targ.vehicle_flags & VHF_ISVEHICLE) && targ.owner) + if(IS_VEHICLE(targ) && targ.owner) victim = targ.owner; else victim = targ; - if(IS_PLAYER(victim) || (victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET) || (victim.flags & FL_MONSTER)) + if(IS_PLAYER(victim) || IS_TURRET(victim) || IS_MONSTER(victim)) { if(DIFF_TEAM(victim, attacker) && !victim.frozen) { diff --git a/qcsrc/server/miscfunctions.qh b/qcsrc/server/miscfunctions.qh index 12dbe3a2c..a3c0d78d3 100644 --- a/qcsrc/server/miscfunctions.qh +++ b/qcsrc/server/miscfunctions.qh @@ -158,6 +158,10 @@ const string STR_OBSERVER = "observer"; #define IS_REAL_CLIENT(v) (clienttype(v) == CLIENTTYPE_REAL) #define IS_NOT_A_CLIENT(v) (clienttype(v) == CLIENTTYPE_NOTACLIENT) +#define IS_MONSTER(v) (v.flags & FL_MONSTER) +#define IS_VEHICLE(v) (v.vehicle_flags & VHF_ISVEHICLE) +#define IS_TURRET(v) (v.turrcaps_flags & TFL_TURRCAPS_ISTURRET) + #define FOR_EACH_CLIENTSLOT(v) for(v = world; (v = nextent(v)) && (num_for_edict(v) <= maxclients); ) #define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if(IS_CLIENT(v)) #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(IS_REAL_CLIENT(v)) diff --git a/qcsrc/server/mutators/gamemode_ctf.qc b/qcsrc/server/mutators/gamemode_ctf.qc index d17dc86a1..3861c8b03 100644 --- a/qcsrc/server/mutators/gamemode_ctf.qc +++ b/qcsrc/server/mutators/gamemode_ctf.qc @@ -475,7 +475,7 @@ void ctf_Handle_Capture(entity flag, entity toucher, int capturetype) void ctf_Handle_Return(entity flag, entity player) { // messages and sounds - if(player.flags & FL_MONSTER) + if(IS_MONSTER(player)) { Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT_4(flag, INFO_CTF_RETURN_MONSTER_), player.monster_name); } @@ -906,7 +906,7 @@ void ctf_FlagTouch() if(trace_dphitcontents & (DPCONTENTS_PLAYERCLIP | DPCONTENTS_MONSTERCLIP)) { return; } entity toucher = other, tmp_entity; - bool is_not_monster = (!(toucher.flags & FL_MONSTER)), num_perteam = 0; + bool is_not_monster = (!IS_MONSTER(toucher)), num_perteam = 0; // automatically kill the flag and return it if it touched lava/slime/nodrop surfaces if(ITEM_TOUCH_NEEDKILL()) @@ -923,14 +923,14 @@ void ctf_FlagTouch() // special touch behaviors if(toucher.frozen) { return; } - else if(toucher.vehicle_flags & VHF_ISVEHICLE) + else if(IS_VEHICLE(toucher)) { if(autocvar_g_ctf_allow_vehicle_touch && toucher.owner) toucher = toucher.owner; // the player is actually the vehicle owner, not other else return; // do nothing } - else if(toucher.flags & FL_MONSTER) + else if(IS_MONSTER(toucher)) { if(!autocvar_g_ctf_allow_monster_touch) return; // do nothing diff --git a/qcsrc/server/mutators/gamemode_invasion.qc b/qcsrc/server/mutators/gamemode_invasion.qc index 34abc6c82..33966bbe7 100644 --- a/qcsrc/server/mutators/gamemode_invasion.qc +++ b/qcsrc/server/mutators/gamemode_invasion.qc @@ -366,7 +366,7 @@ MUTATOR_HOOKFUNCTION(invasion_PlayerCommand) MUTATOR_HOOKFUNCTION(invasion_BotShouldAttack) { - if(!(checkentity.flags & FL_MONSTER)) + if(!IS_MONSTER(checkentity)) return true; return false; @@ -382,7 +382,7 @@ MUTATOR_HOOKFUNCTION(invasion_SetStartItems) MUTATOR_HOOKFUNCTION(invasion_AccuracyTargetValid) { - if(frag_target.flags & FL_MONSTER) + if(IS_MONSTER(frag_target)) return MUT_ACCADD_INVALID; return MUT_ACCADD_INDIFFERENT; } diff --git a/qcsrc/server/mutators/mutator_buffs.qc b/qcsrc/server/mutators/mutator_buffs.qc index 170f59874..b46c4de9e 100644 --- a/qcsrc/server/mutators/mutator_buffs.qc +++ b/qcsrc/server/mutators/mutator_buffs.qc @@ -496,7 +496,7 @@ MUTATOR_HOOKFUNCTION(buffs_PlayerDamage_Calculate) if(DEATH_WEAPONOF(frag_deathtype) != WEP_ARC) if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype)) if(frag_target.deadflag == DEAD_NO) - if(IS_PLAYER(frag_target) || (frag_target.flags & FL_MONSTER)) + if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target)) if(frag_attacker != frag_target) if(!frag_target.frozen) if(frag_target.takedamage) diff --git a/qcsrc/server/mutators/mutator_nades.qc b/qcsrc/server/mutators/mutator_nades.qc index f4267716e..585cab836 100644 --- a/qcsrc/server/mutators/mutator_nades.qc +++ b/qcsrc/server/mutators/mutator_nades.qc @@ -412,7 +412,7 @@ void nade_heal_touch() { float maxhealth; float health_factor; - if(IS_PLAYER(other) || (other.flags & FL_MONSTER)) + if(IS_PLAYER(other) || IS_MONSTER(other)) if(other.deadflag == DEAD_NO) if(!other.frozen) { @@ -426,7 +426,7 @@ void nade_heal_touch() } if ( health_factor > 0 ) { - maxhealth = (other.flags & FL_MONSTER) ? other.max_health : g_pickup_healthmega_max; + maxhealth = (IS_MONSTER(other)) ? other.max_health : g_pickup_healthmega_max; if ( other.health < maxhealth ) { if ( self.nade_show_particles ) @@ -442,9 +442,9 @@ void nade_heal_touch() } - if ( IS_REAL_CLIENT(other) || (other.vehicle_flags & VHF_ISVEHICLE) ) + if ( IS_REAL_CLIENT(other) || IS_VEHICLE(other) ) { - entity show_red = (other.vehicle_flags & VHF_ISVEHICLE) ? other.owner : other; + entity show_red = (IS_VEHICLE(other)) ? other.owner : other; show_red.stat_healing_orb = time+0.1; show_red.stat_healing_orb_alpha = 0.75 * (self.ltime - time) / self.healer_lifetime; } diff --git a/qcsrc/server/mutators/mutator_overkill.qc b/qcsrc/server/mutators/mutator_overkill.qc index 39b244a72..a82465a7e 100644 --- a/qcsrc/server/mutators/mutator_overkill.qc +++ b/qcsrc/server/mutators/mutator_overkill.qc @@ -75,7 +75,7 @@ MUTATOR_HOOKFUNCTION(ok_PlayerDies) entity oldself = self; entity targ = ((frag_attacker) ? frag_attacker : frag_target); - if(self.flags & FL_MONSTER) + if(IS_MONSTER(self)) { remove(other); // remove default item other = world; diff --git a/qcsrc/server/sv_main.qc b/qcsrc/server/sv_main.qc index 48cd05361..9d83b00ab 100644 --- a/qcsrc/server/sv_main.qc +++ b/qcsrc/server/sv_main.qc @@ -37,9 +37,9 @@ void CreatureFrame (void) { if (self.movetype == MOVETYPE_NOCLIP) { continue; } - float vehic = (self.vehicle_flags & VHF_ISVEHICLE); + float vehic = IS_VEHICLE(self); float projectile = (self.flags & FL_PROJECTILE); - float monster = (self.flags & FL_MONSTER); + float monster = IS_MONSTER(self); if (self.watertype <= CONTENT_WATER && self.waterlevel > 0) // workaround a retarded bug made by id software :P (yes, it's that old of a bug) { diff --git a/qcsrc/server/tturrets/system/system_main.qc b/qcsrc/server/tturrets/system/system_main.qc index 694ff5d45..1862bcb1d 100644 --- a/qcsrc/server/tturrets/system/system_main.qc +++ b/qcsrc/server/tturrets/system/system_main.qc @@ -601,7 +601,7 @@ float turret_validate_target(entity e_turret, entity e_target, float validate_fl return -5; // Cant touch this - if(e_target.vehicle_flags & VHF_ISVEHICLE) + if(IS_VEHICLE(e_target)) { if (e_target.vehicle_health <= 0) return -6; @@ -1001,7 +1001,7 @@ void turrets_manager_think() e = nextent(world); while (e) { - if (e.turrcaps_flags & TFL_TURRCAPS_ISTURRET) + if(IS_TURRET(e)) { load_unit_settings(e,e.cvar_basename,1); if(e.turret_postthink) diff --git a/qcsrc/server/vehicles/bumblebee.qc b/qcsrc/server/vehicles/bumblebee.qc index 79eac74bb..956b2443e 100644 --- a/qcsrc/server/vehicles/bumblebee.qc +++ b/qcsrc/server/vehicles/bumblebee.qc @@ -474,7 +474,7 @@ float bumb_pilot_frame() if((teamplay && trace_ent.team == pilot.team) || !teamplay) { - if(trace_ent.vehicle_flags & VHF_ISVEHICLE) + if(IS_VEHICLE(trace_ent)) { if(autocvar_g_vehicle_bumblebee_healgun_sps && trace_ent.vehicle_health <= trace_ent.tur_health) trace_ent.vehicle_shield = min(trace_ent.vehicle_shield + autocvar_g_vehicle_bumblebee_healgun_sps * frametime, trace_ent.tur_head.tur_health); @@ -492,7 +492,7 @@ float bumb_pilot_frame() trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, autocvar_g_vehicle_bumblebee_healgun_hmax); } - else if(trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET) + else if(IS_TURRET(trace_ent)) { if(trace_ent.health <= trace_ent.tur_health && autocvar_g_vehicle_bumblebee_healgun_hps) trace_ent.health = min(trace_ent.health + autocvar_g_vehicle_bumblebee_healgun_hps * frametime, trace_ent.tur_health); diff --git a/qcsrc/server/vehicles/vehicle.qc b/qcsrc/server/vehicles/vehicle.qc index e6a0f9c0e..b6bbae8ae 100644 --- a/qcsrc/server/vehicles/vehicle.qc +++ b/qcsrc/server/vehicles/vehicle.qc @@ -267,8 +267,8 @@ void vehicles_locktarget(float incr, float decr, float _lock_time) if(trace_ent.deadflag != DEAD_NO) trace_ent = world; if(!( - (trace_ent.vehicle_flags & VHF_ISVEHICLE) || - (trace_ent.turrcaps_flags & TFL_TURRCAPS_ISTURRET) || + IS_VEHICLE(trace_ent) || + IS_TURRET(trace_ent) || (trace_ent.takedamage == DAMAGE_TARGETDRONE) )) { trace_ent = world; } } @@ -520,7 +520,7 @@ float vehicles_crushable(entity e) if(IS_PLAYER(e)) return true; - if(e.flags & FL_MONSTER) + if(IS_MONSTER(e)) return true; return false; diff --git a/qcsrc/server/weapons/hitplot.qc b/qcsrc/server/weapons/hitplot.qc index 0564bdc76..065edf1b1 100644 --- a/qcsrc/server/weapons/hitplot.qc +++ b/qcsrc/server/weapons/hitplot.qc @@ -66,7 +66,7 @@ void W_HitPlotAnalysis(entity player, vector screenforward, vector screenright, org = player.origin + player.view_ofs; traceline_antilag_force(player, org, org + screenforward * MAX_SHOT_DISTANCE, MOVE_NORMAL, player, lag); - if(IS_CLIENT(trace_ent) || (trace_ent.flags & FL_MONSTER)) + if(IS_CLIENT(trace_ent) || IS_MONSTER(trace_ent)) { antilag_takeback(trace_ent, time - lag); hitplot = W_HitPlotNormalizedUntransform(org, trace_ent, screenforward, screenright, screenup, trace_endpos);