q2community / game-extensions

GNU General Public License v2.0
1 stars 1 forks source link

IS_ALIVE(ent) macro #3

Open darkshade9 opened 1 year ago

darkshade9 commented 1 year ago

Perhaps not necessarily an extension, but a potentially useful macro to reduce the toil of checking all of the constraints around whether a player is alive or not, sharing this to potentially incorporate into mods or extensions.

#define IS_ALIVE(ent) (((ent)->solid != SOLID_NOT && (ent)->deadflag == false) || (ent)->health > 0 || (ent)->client->pers.spectator == false)

This should check if entity:


We could remove some constraints here, and just go for simply (ent)-> solid != SOLID_NOT && (ent)->deadflag == false for simplicity's sake?

Paril commented 1 year ago

The latter condition may not work in some cases since I think there are cases in vanilla where spectators have 100 health... I think, at least. It's also going to be highly dependent on the mod in question.

Also, pers.spectator is their wanted spectator status, not their current spectator status.

The filter I used in Quake II re-release for the trigger_coop_relay is such:

inline bool trigger_coop_relay_filter(edict_t *player)
{
    return (player->health <= 0 || player->deadflag || player->movetype == MOVETYPE_NOCLIP ||
        player->client->resp.spectator || player->s.modelindex != MODELINDEX_PLAYER);
}
darkshade9 commented 1 year ago

Would this cover 99% of cases as a bit of a syntactic sugar shortener?

#define IS_ALIVE(ent) ((ent)->solid != SOLID_NOT && (ent)->deadflag == false)

!IS_ALIVE(ent) would mean they are both SOLID_NOT and deadflag is true

Paril commented 1 year ago

I think so but I can't say for sure; the modelindex one will also allow it to avoid catching gibs and spectators.