D:\cygwin\wf_fusion_src_r8\CVSROOT\WeaponsFactory\wf_id.c

/*
==============================================================================
The Weapons Factory - 
  
Modified code by Keith Pase

Copyright (C) 1997-2003 Weapons Factory Software

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  Modified code by Keith Pase

  wf_id.c -- Player Identification Code
  

==============================================================================
*/
#include "../game/g_local.h"


void WFSetIDView(edict_t *ent)
{
    vec3_t start,end,endp,offset;
    vec3_t forward,right,up;
    trace_t tr;
    int i,j,k,l;
    char idstring[1024];
    char *enemytype[2] = {"Friendly","Enemy"};
    char *colors[2] = {"^1","^5"};
    qboolean tagged = qfalse;
    edict_t *who, *best, *target,*id;

    best = NULL;

    if (level.time - ent->r.client->resp.lastidtime < 0.33)
        return;
    ent->r.client->resp.lastidtime = level.time + (random()*.1);
    ent->r.client->ps.stats[STAT_CTF_ID_VIEW] = 0;
    ent->r.client->ps.stats[STAT_CTF_ID_VIEW_COLOR] = 0;

    AngleVectors (ent->r.client->v_angle, forward, right, NULL);
    VectorSet(end,100 , 0, 0);
    G_ProjectSource (ent->s.origin, end, forward, right, start);
    id = G_Spawn ();
    id->r.owner = ent;
    id->movetype = MOVETYPE_NOCLIP;
    id->r.solid = SOLID_NOT;
    id->classname = "id";

    AngleVectors (id->r.owner->r.client->v_angle, forward, right, up);
    VectorSet(offset,24 , 6, id->r.owner->viewheight-7);
    G_ProjectSource (id->r.owner->s.origin, offset, forward, right, start);
    VectorMA(start,8192,forward,end);
    trap_Trace (&tr,start,NULL,NULL, end,id->r.owner,CONTENTS_SOLID|CONTENTS_BODY|CONTENTS_CORPSE);

    if (tr.fraction != 1)
    {
        VectorMA(tr.endpos,-4,forward,endp);
        VectorCopy(endp,tr.endpos);
    }

    target = &game.edicts[tr.ent];


    if (target->wf_team)
    {
        j=abs(target->wf_team - ent->wf_team);
        if (ent->wf_team == 1)
            if (j==0)
                k=0;
            else
                k=1;
        else
            if (j==0)
                k=1;
            else
                k=0;
    }
    if (strcmp(target->classname, "decoy") == 0)
    {
        if (j==0)
            Com_sprintf (idstring, sizeof(idstring), "[%s%s^7]\n%s's ^7Decoy",
            colors[k],
            enemytype[j],
            target->creator->r.client->pers.netname);
        else
            Com_sprintf (idstring, sizeof(idstring), "[%s%s^7]\n%s",
            colors[k],
            enemytype[j],
            target->creator->r.client->pers.netname);

        tagged = qtrue;
    }
    if (strcmp(target->classname, "SentryGun") == 0)
    {
        Com_sprintf (idstring, sizeof(idstring), "[%s%s^7]\n%s^7's SentryGun\nLevel:%i/Armor:%i/Ammo:%i",
        colors[k],
        enemytype[j],
        target->creator->r.client->pers.netname,
        target->count,
        target->health,
        target->light_level);

        tagged = qtrue;
    }
    if (strcmp(target->classname, "depot") == 0)
    {
        G_Printf("DEBUG: yay\n");
        Com_sprintf (idstring, sizeof(idstring), "[%s%s^7]\n%s's ^7SupplyDepot",
        colors[k],
        enemytype[j],
        target->creator->r.client->pers.netname);

        tagged = qtrue;
    }
    if (target->r.client)
        if (!target->r.client->pers.feign)
        {
            if (target->disguised)
            {
                if (target->r.client->pers.player_class == 9 &&
                    ent->r.client->pers.player_class == 9)
                {
                    Com_sprintf (idstring, sizeof(idstring), "[%s%s^7]\n%s",
                        colors[k],
                        enemytype[j],
                        target->r.client->pers.netname);
                    tagged = qtrue;
                }
                else
                {       
                    for (i = 1; i <= maxclients->value; i++) 
                    {
                        who = game.edicts + i;
                        if (who->r.client->pers.player_class == target->disguised)
                        {
                            best = who;
                            break;
                        }
                        if (who->wf_team == ent->wf_team)
                        {
                            best = who;
                            continue;
                        }
                        best = who;
                        continue;
                    }
                    Com_sprintf (idstring, sizeof(idstring), "[%s%s^7]\n%s",
                        colors[k],
                        enemytype[j],
                        best->r.client->pers.netname);
                    tagged = qtrue;
                }
            }
            else
            {
                if (ent->r.client->pers.player_class < 4 && ent->r.client->pers.player_class > 1)
                {
                    l = ArmorIndex (&game.edicts[tr.ent]);
                    Com_sprintf (idstring, sizeof(idstring), "[%s%s^7]\n%s\nHealth:%i/Armor:%i",
                        colors[k],
                        enemytype[j],
                        target->r.client->pers.netname,
                        target->health,
                        target->r.client->pers.inventory[l]);
                    tagged = qtrue;
                }
                else
                {
                    Com_sprintf (idstring, sizeof(idstring), "[%s%s^7]\n%s",
                        colors[k],
                        enemytype[j],
                        target->r.client->pers.netname);
                    tagged = qtrue;
                }
            }
        }

    if (tagged)
        G_CenterPrintMsg (ent,idstring);

    VecToAngles(tr.plane.normal,id->s.angles);
    VectorCopy(tr.endpos,id->s.origin);
    trap_LinkEntity (id);
    G_FreeEdict (id);
    id = NULL;
}