From 66bcabf20e8f3847e6c697359b947e224db05cdd Mon Sep 17 00:00:00 2001 From: Samual Lenks Date: Thu, 21 Feb 2013 16:06:40 -0500 Subject: [PATCH] Do the same for checkargs-- also, add unified macro checks for some things --- qcsrc/common/notifications.qc | 27 +++++++++++++++++++++++---- qcsrc/server/miscfunctions.qc | 29 +++++++++++++++-------------- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/qcsrc/common/notifications.qc b/qcsrc/common/notifications.qc index e45360334..2f9d7f1e6 100644 --- a/qcsrc/common/notifications.qc +++ b/qcsrc/common/notifications.qc @@ -486,20 +486,39 @@ void Send_Notification(float broadcast, entity client, switch(broadcast) { case NOTIF_ONE: - case NOTIF_ONE_ONLY: { if(clienttype(client) == CLIENTTYPE_NOTACLIENT) { checkargs = sprintf("%sNo client provided!", checkargs); } break; } - case NOTIF_ANY_EXCEPT: { if(clienttype(client) == CLIENTTYPE_NOTACLIENT) { checkargs = sprintf("%sException can't be a non-client!", checkargs); } break; } - case NOTIF_ANY: { if(client) { checkargs = sprintf("%sEntity provided when world was required!", checkargs); } break; } + case NOTIF_ONE_ONLY: + { + if(IS_NOT_A_CLIENT(client)) + { checkargs = sprintf("%sNo client provided!", checkargs); } + break; + } + + case NOTIF_ANY_EXCEPT: + { + if(IS_NOT_A_CLIENT(client)) + { checkargs = sprintf("%sException can't be a non-client!", checkargs); } + break; + } + + case NOTIF_ANY: + { + if(client) + { checkargs = sprintf("%sEntity provided when world was required!", checkargs); } + break; + } + case NOTIF_TEAM: case NOTIF_TEAM_EXCEPT: { if not(teamplay) { checkargs = sprintf("%sTeamplay not active!", checkargs); } - else if(clienttype(client) == CLIENTTYPE_NOTACLIENT) + else if(IS_NOT_A_CLIENT(client)) { if(broadcast == NOTIF_TEAM) { checkargs = sprintf("%sNo client provided!", checkargs); } else { checkargs = sprintf("%sException can't be a non-client!", checkargs); } } break; } + default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; } } if(checkargs != "") { backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs)); return; } diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 921a2de85..2e7139269 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -79,26 +79,27 @@ float DistributeEvenly_GetRandomized(float weight) #define move_out_of_solid(e) WarpZoneLib_MoveOutOfSolid(e) - string STR_PLAYER = "player"; string STR_SPECTATOR = "spectator"; string STR_OBSERVER = "observer"; -#if 0 -#define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; ) -#define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL) -#define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; ) -#define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL) -#else +#define IS_PLAYER(v) (v.classname == STR_PLAYER) +#define IS_SPEC(v) (v.classname == STR_SPECTATOR) +#define IS_OBSERVER(v) (v.classname == STR_OBSERVER) +#define IS_CLIENT(v) (v.flags & FL_CLIENT) +#define IS_BOT_CLIENT(v) (clienttype(v) == CLIENTTYPE_BOT) +#define IS_REAL_CLIENT(v) (clienttype(v) == CLIENTTYPE_REAL) +#define IS_NOT_A_CLIENT(v) (clienttype(v) == CLIENTTYPE_NOTACLIENT) + #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(v.flags & FL_CLIENT) -#define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL) -#define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(v.classname == STR_PLAYER) -#define FOR_EACH_SPEC(v) FOR_EACH_CLIENT(v) if(v.classname != STR_PLAYER) -#define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(v.classname == STR_PLAYER) -#endif +#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)) + +#define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if(IS_PLAYER(v)) +#define FOR_EACH_SPEC(v) FOR_EACH_CLIENT(v) if not(IS_PLAYER(v)) // Samual: shouldn't this be IS_SPEC(v)? and rather create a separate macro to include observers too +#define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if(IS_PLAYER(v)) -#define CENTER_OR_VIEWOFS(ent) (ent.origin + ((ent.classname == STR_PLAYER) ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5))) +#define CENTER_OR_VIEWOFS(ent) (ent.origin + (IS_PLAYER(ent) ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5))) // copies a string to a tempstring (so one can strunzone it) string strcat1(string s) = #115; // FRIK_FILE -- 2.39.2