#include "cg_local.h"

/*
extern	vec4_t color_black	        = {0.00f, 0.00f, 0.00f, 1.00f};
extern	vec4_t color_white	        = {1.00f, 1.00f, 1.00f, 1.00f};
extern	vec4_t color_yellow	        = {1.00f, 1.00f, 0.00f, 1.00f};
extern	vec4_t color_blue	        = {0.00f, 0.00f, 1.00f, 1.00f};
extern	vec4_t color_lightOrange    = {1.00f, 0.68f, 0.00f, 1.00f};
extern	vec4_t color_orange	        = {1.00f, 0.43f, 0.00f, 1.00f};
extern	vec4_t color_red		    = {1.00f, 0.00f, 0.00f, 1.00f};
extern	vec4_t color_green			= {0.00f, 1.00f, 0.00f, 1.00f};
extern	vec4_t color_magenta		= {1.00f, 0.00f, 1.00f, 1.00f};
extern	vec4_t color_cyan			= {0.00f, 1.00f, 1.00f, 1.00f};
 
// current color scheme
vec4_t pulse_color          = {1.00f, 1.00f, 1.00f, 1.00f};
vec4_t text_color_disabled  = {0.50f, 0.50f, 0.50f, 1.00f};	// light gray
vec4_t text_color_normal	= {1.00f, 0.43f, 0.00f, 1.00f};	// light orange
vec4_t text_color_highlight = {1.00f, 1.00f, 0.00f, 1.00f};	// bright yellow
vec4_t listbar_color        = {1.00f, 0.43f, 0.00f, 0.30f};	// transluscent orange
vec4_t text_color_status    = {1.00f, 1.00f, 1.00f, 1.00f};	// bright white
*/

/*
extern	vec4_t		colorBlack;
extern	vec4_t		colorRed;
extern	vec4_t		colorGreen;
extern	vec4_t		colorBlue;
extern	vec4_t		colorYellow;
extern	vec4_t		colorMagenta;
extern	vec4_t		colorCyan;
extern	vec4_t		colorWhite;
extern	vec4_t		colorLtGrey;
extern	vec4_t		colorMdGrey;
extern	vec4_t		colorDkGrey;
 
 vec4_t		colorBlack	= {0, 0, 0, 1};
vec4_t		colorRed	= {1, 0, 0, 1};
vec4_t		colorGreen	= {0, 1, 0, 1};
vec4_t		colorBlue	= {0, 0, 1, 1};
vec4_t		colorYellow	= {1, 1, 0, 1};
vec4_t		colorMagenta= {1, 0, 1, 1};
vec4_t		colorCyan	= {0, 1, 1, 1};
vec4_t		colorWhite	= {1, 1, 1, 1};
vec4_t		colorLtGrey	= {0.75, 0.75, 0.75, 1};
vec4_t		colorMdGrey	= {0.5, 0.5, 0.5, 1};
vec4_t		colorDkGrey	= {0.25, 0.25, 0.25, 1};
 
*/

// Blue and red tints, used to tint things like sprites and trails red and
// blue (set shaderRGBA)
byte blueTint[] = { 87, 143, 248, 255 };
byte redTint[] = { 253, 64, 64, 255 };
/*
byte blueTint[] = { 87, 143, 248, 255 };
byte redTint[] = { 253, 64, 64, 255 };
byte blueTint[] = { 87, 143, 248, 255 };
byte redTint[] = { 253, 64, 64, 255 };
byte blueTint[] = { 87, 143, 248, 255 };
byte redTint[] = { 253, 64, 64, 255 };
byte blueTint[] = { 87, 143, 248, 255 };
*/

byte greyTint[] = { 190, 190, 190, 255 };
byte whiteTint[] = { 255, 255, 255, 255 };  // Joe

byte *teamTint[] = { whiteTint, redTint, blueTint };

typedef struct {
    char redShader[MAX_QPATH];
    char blueShader[MAX_QPATH];
    char orangeShader[MAX_QPATH];
    char greenShader[MAX_QPATH];
    char yellowShader[MAX_QPATH];
    char pinkShader[MAX_QPATH];
    char aquaShader[MAX_QPATH];
    char whiteShader[MAX_QPATH];
    char blackShader[MAX_QPATH];
}
battleShaders_t;

#define MAX_REMAP	10;
battleShaders_t shaderPath[10];
int maxShadersRemaps;

qboolean fileExists(const char *filename) {
    int len;
    fileHandle_t f;

    len = trap_FS_FOpenFile(filename, &f, FS_READ);

    if(len < 0) {
        //CG_Printf("%s does not exist\n", filename);
        return qfalse;
    } else {
        //CG_Printf("%s exists\n", filename);
        trap_FS_FCloseFile(f);
        return qtrue;
    }
}


void CG_FileExists_f( void ) {
    const char *filename;

    filename = CG_Argv(1);

    if(fileExists(filename)) {
        CG_Printf("%s exists\n", filename);
    } else {
        CG_Printf("%s does not exist\n", filename);
    }

}

int CG_OtherTeam(int team) {
    if (team==TEAM_RED)
        return TEAM_BLUE;
    else if (team==TEAM_BLUE)
        return TEAM_RED;
    return team;
}

// Joe dynamic team audio
void soundtypeForModel(char *soundtype, int soundtypeSize, char *model) {
    // 23 models

    if (Q_stricmpn(model, "anarki", sizeof("anarki") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "male");
    else if (Q_stricmpn(model, "biker", sizeof("biker") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "male");
    else if (Q_stricmpn(model, "bitterman", sizeof("bitterman") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "male");
    else if (Q_stricmpn(model, "bones", sizeof("bones") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "demon");
    else if (Q_stricmpn(model, "crash", sizeof("crash") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "mech");
    else if (Q_stricmpn(model, "doom", sizeof("doom") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "male");
    else if (Q_stricmpn(model, "grunt", sizeof("grunt") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "male");
    else if (Q_stricmpn(model, "hunter", sizeof("hunter") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "female");
    else if (Q_stricmpn(model, "keel", sizeof("keel") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "male");
    else if (Q_stricmpn(model, "klesk", sizeof("klesk") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "monster");
    else if (Q_stricmpn(model, "lucy", sizeof("lucy") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "female");
    else if (Q_stricmpn(model, "major", sizeof("major") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "female");
    else if (Q_stricmpn(model, "mynx", sizeof("mynx") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "female");
    else if (Q_stricmpn(model, "orbb", sizeof("orbb") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "mech");
    else if (Q_stricmpn(model, "ranger", sizeof("ranger") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "male");
    else if (Q_stricmpn(model, "razor", sizeof("razor") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "male");
    else if (Q_stricmpn(model, "sarge", sizeof("sarge") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "male");
    else if (Q_stricmpn(model, "slash", sizeof("slash") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "female");
    else if (Q_stricmpn(model, "sorlag", sizeof("sorlag") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "monster");
    else if (Q_stricmpn(model, "tankjr", sizeof("tankjr") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "monster");
    else if (Q_stricmpn(model, "uriel", sizeof("uriel") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "demon");
    else if (Q_stricmpn(model, "visor", sizeof("visor") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "male");
    else if (Q_stricmpn(model, "xaero", sizeof("xaero") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "demon");
    //banshee added soundtype for new LOBO model as DEMON
    else if (Q_stricmpn(model, "lobo", sizeof("lobo") - 1) == 0)
        Com_sprintf(soundtype, soundtypeSize, "%s", "demon");
    else
        Com_sprintf(soundtype, soundtypeSize, "%s", "male");

} // end soundtypeForModel()
// end Joe dynamic team audio

// Joe lastweap
void CG_LastWeap_f( void ) {
    int		num;

    if ( !cg.snap ) {
        return;
    }
    if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) {
        return;
    }

    num = cg.lastWeap;

    if ( num < 1 || num > 15 ) {
        return;
    }

    cg.weaponSelectTime = cg.time;

    if ( ! ( cg.snap->ps.stats[STAT_WEAPONS] & ( 1 << num ) ) ) {
        return;		// don't have the weapon
    }

    cg.lastWeap = cg.weaponSelect;
    cg.weaponSelect = num;
}
// end Joe


// Joe new grapples

// helper for CG_GrappleCapEffectTrail()
void CG_SparkleBubbleTrail( vec3_t start, vec3_t end, float spacing ) {
    vec3_t		move;
    vec3_t		vec;
    float		len;
    int			i;

    VectorCopy (start, move);
    VectorSubtract (end, start, vec);
    len = VectorNormalize (vec);

    // advance a random amount first
    i = rand() % (int)spacing;
    VectorMA( move, i, vec, move );

    VectorScale (vec, spacing, vec);

    for ( ; i < len; i += spacing ) {
        localEntity_t	*le;
        refEntity_t		*re;

        le = CG_AllocLocalEntity();
        le->leFlags = LEF_PUFF_DONT_SCALE;
        le->leType = LE_MOVE_SCALE_FADE;
        le->startTime = cg.time;
        le->endTime = cg.time + 1000 + random() * 250;
        le->lifeRate = 1.0 / ( le->endTime - le->startTime );

        re = &le->refEntity;
        re->shaderTime = cg.time / 1000.0f;

        re->reType = RT_SPRITE;
        re->rotation = 0;
        //Crock - Make the trail radius less
        re->radius = 1.5;  //was 3
        //Crock - end
        //re->customShader = cgs.media.combatRedExplosionShader;

        re->shaderRGBA[0] = 0xff;
        re->shaderRGBA[1] = 0xff;
        re->shaderRGBA[2] = 0xff;
        re->shaderRGBA[3] = 0xff;
		

		//re->customShader = cgs.media.bulletSpark_red;
		re->customShader = cgs.media.bulletSpark_blue;
		
		//re->customShader = cgs.media.ringFlashModel;
		//re->customShader = cgs.media.lightningShader;
		//re->customShader = cgs.media.teleportEffectShader;

        le->color[3] = 1.0;

        le->color[0] = 1.0;

        le->pos.trType = TR_LINEAR;
        le->pos.trTime = cg.time;
        VectorCopy( move, le->pos.trBase );
        le->pos.trDelta[0] = crandom()*5;
        le->pos.trDelta[1] = crandom()*5;
        le->pos.trDelta[2] = crandom()*5 + 6;

        VectorAdd (move, vec, move);
    }
}  // end CG_SparkleBubbleTrail()


void CG_GrappleCapEffectTrail( centity_t *ent, const weaponInfo_t *wi ) {
    int		step;
    vec3_t	origin, lastPos;
    int		t;
    int		startTime, contents;
    int		lastContents;
    entityState_t	*es;
    vec3_t	up;

    up[0] = 0;
    up[1] = 0;
    up[2] = 0;

    step = 50;

    es = &ent->currentState;
    startTime = ent->trailTime;
    t = step * ( (startTime + step) / step );

    BG_EvaluateTrajectory( &es->pos, cg.time, origin );
    contents = CG_PointContents( origin, -1 );

    // if object (e.g. grenade) is stationary, don't toss up smoke
    if ( es->pos.trType == TR_STATIONARY ) {
        ent->trailTime = cg.time;
        return;
    }

    BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos );
    lastContents = CG_PointContents( lastPos, -1 );

    ent->trailTime = cg.time;

    CG_SparkleBubbleTrail( lastPos, origin, 8);

}  // end CG_GrappleCapEffectTrail()


// bubble trail for hook using custom shader - Joe
// choice grapple type 3 for combat
static void CG_AllianceBubbleTrail( vec3_t start, vec3_t end, float spacing,
                                    int team ) {
    vec3_t		move;
    vec3_t		vec;
    float		len;
    int			i;

    VectorCopy (start, move);
    VectorSubtract (end, start, vec);
    len = VectorNormalize (vec);

    // advance a random amount first
    i = rand() % (int)spacing;
    VectorMA( move, i, vec, move );

    VectorScale (vec, spacing, vec);

    for ( ; i < len; i += spacing ) {
        localEntity_t	*le;
        refEntity_t		*re;

        le = CG_AllocLocalEntity();
        le->leFlags = LEF_PUFF_DONT_SCALE;
        le->leType = LE_MOVE_SCALE_FADE;
        le->startTime = cg.time;
        le->endTime = cg.time + 1000 + random() * 250;
        le->lifeRate = 1.0 / ( le->endTime - le->startTime );

        re = &le->refEntity;
        re->shaderTime = cg.time / 1000.0f;

        re->reType = RT_SPRITE;
        re->rotation = 0;
        //Crock - More visibility while hooking
        if (BG_gamemode() == GM_BATTLE) {
            re->radius = 2;  //Was 3
        }
        else

            re->radius = 3;

        //Crock - end

        re->shaderRGBA[0] = greyTint[0];  // same
        re->shaderRGBA[1] = greyTint[1];
        re->shaderRGBA[2] = greyTint[2];
        re->shaderRGBA[3] = greyTint[3];

        re->customShader = cgs.media.combatTrailShader; // being consistent

        le->color[3] = 1.0;

        le->pos.trType = TR_LINEAR;
        le->pos.trTime = cg.time;
        VectorCopy( move, le->pos.trBase );
        le->pos.trDelta[0] = crandom()*5;
        le->pos.trDelta[1] = crandom()*5;
        le->pos.trDelta[2] = crandom()*5 + 6;

        VectorAdd (move, vec, move);
    }
}


// part of CG_RocketTrail()
void CG_GrappleBubbleTrail( centity_t *ent, const weaponInfo_t *wi ) {
    int		step;
    vec3_t	origin, lastPos;
    int		t;
    int		startTime, contents;
    int		lastContents;
    entityState_t	*es;
    vec3_t	up;

    // Joe grapple color coding
    int myTeam, grappleOwnerTeam;
    //    qboolean isFriend;

    if ( cg_noProjectileTrail.integer ) {
        return;
    }

    up[0] = 0;
    up[1] = 0;
    up[2] = 0;

    step = 50;

    es = &ent->currentState;
    startTime = ent->trailTime;
    t = step * ( (startTime + step) / step );

    BG_EvaluateTrajectory( &es->pos, cg.time, origin );
    contents = CG_PointContents( origin, -1 );

    // if object (e.g. grenade) is stationary, don't toss up smoke
    if ( es->pos.trType == TR_STATIONARY ) {
        ent->trailTime = cg.time;
        return;
    }

    BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos );
    lastContents = CG_PointContents( lastPos, -1 );

    ent->trailTime = cg.time;

    // Joe color coded trail
    // Publius smuggled the hook owner clientnum in s.otherEntityNum

    grappleOwnerTeam = cgs.clientinfo[es->otherEntityNum].team;

    myTeam = cg.snap->ps.persistant[PERS_TEAM];
    CG_AllianceBubbleTrail( lastPos, origin, 8, grappleOwnerTeam );

}

// combination of CG_RocketTrail() and CG_BloodTrail()
void CG_GrappleBloodTrail( centity_t *ent, const weaponInfo_t *wi ) {
    int		step;
    vec3_t	origin, lastPos;
    int		t;
    // int             t2;    // CG_BloodTrail() var
    int		startTime, contents;
    int		lastContents;
    entityState_t	*es;
    vec3_t	up;

    localEntity_t	*blood;

    if ( cg_noProjectileTrail.integer ) {
        return;
    }

    up[0] = 0;
    up[1] = 0;
    up[2] = 0;

    step = 50;

    es = &ent->currentState;
    startTime = ent->trailTime;
    t = step * ( (startTime + step) / step );


    BG_EvaluateTrajectory( &es->pos, cg.time, origin );
    contents = CG_PointContents( origin, -1 );

    // if object (e.g. grenade) is stationary, don't toss up smoke
    if ( es->pos.trType == TR_STATIONARY ) {
        ent->trailTime = cg.time;
        return;
    }
	
	BG_EvaluateTrajectory( &es->pos, ent->trailTime, lastPos );
    lastContents = CG_PointContents( lastPos, -1 );

    ent->trailTime = cg.time;

    if ( contents & ( CONTENTS_WATER | CONTENTS_SLIME | CONTENTS_LAVA ) ) {
        if ( contents & lastContents & CONTENTS_WATER ) {
            CG_BubbleTrail( lastPos, origin, 8 );
        }
        return;
    }


    // slower blood loop
    //	for ( ; t <= t2 ; t += step ) {

    // rocket trail loop
    for ( ; t <= ent->trailTime ; t += step ) {
        BG_EvaluateTrajectory( &es->pos, t, lastPos );

        // from CG_BloodTrail
        blood = CG_SmokePuff( lastPos, up,
                              20,
                              1, 1, 1, 1,
                              2000,
                              t,
                              0,
                              0,
                              cgs.media.bloodTrailShader );
        // use the optimized local entity add
        blood->leType = LE_FALL_SCALE_FADE;
        // drop a total of 40 units over its lifetime
        blood->pos.trDelta[2] = 40;
    }
}

// end Joe new grapples

// Joe - tint missile trails
// almost identical to CG_SmokePuff()
localEntity_t *CG_TeamSmokePuff( const vec3_t p, const vec3_t vel,
                                 float radius,
                                 float r, float g, float b, float a,
                                 float duration,
                                 int startTime,
                                 int leFlags,
                                 qhandle_t hShader, int team ) {
    static int      seed = 0x92;
    localEntity_t   *le;
    refEntity_t             *re;
    vec3_t color; //, out;

    color[0] = r;
    color[1] = g;
    color[2] = b;

    GetTeamColorsVEC3(color, color, team);

    le = CG_AllocLocalEntity();
    le->leFlags = leFlags;
    le->radius = radius;

    re = &le->refEntity;
    re->rotation = Q_random( &seed ) * 360;
    re->radius = radius;
    re->shaderTime = startTime / 1000.0f;

    le->leType = LE_MOVE_SCALE_FADE;
    le->startTime = startTime;
    le->endTime = startTime + duration;
    le->lifeRate = 1.0 / ( le->endTime - le->startTime );

    le->color[0] = color[0];
    le->color[1] = color[1];
    le->color[2] = color[2];
    le->color[3] = a;


    le->pos.trType = TR_LINEAR;
    le->pos.trTime = startTime;
    VectorCopy( vel, le->pos.trDelta );
    VectorCopy( p, le->pos.trBase );

    VectorCopy( p, re->origin );
    re->customShader = hShader;

    // rage pro can't alpha fade, so use a different shader
    if ( cgs.glconfig.hardwareType == GLHW_RAGEPRO ) {
        int i;

        re->customShader = cgs.media.smokePuffRageProShader;

        for (i = 0; i < 4; i++)
            re->shaderRGBA[i] = color[i] * 255;  // Joe  same either way?
    }
    else // not ATI
    {
        int i;

        for (i = 0; i < 4; i++)
            re->shaderRGBA[i] = color[i] * 255;
        // CG_Printf("team is %d\n", team);

    }

    re->reType = RT_SPRITE;
    re->radius = le->radius;

    return le;
}

// Myrkul Combat CTF Scoring strings for messages

typedef enum {
    BONUS_STRING,
    PENALTY_STRING,
    ASSIST_STRING
} bonusClass_t;

#define BONUS_STRING         S_COLOR_CYAN "BONUS" S_COLOR_WHITE
#define PENALTY_STRING       S_COLOR_CYAN "PENALTY" S_COLOR_WHITE
//#define BONUS_STRING         "BONUS"
//#define PENALTY_STRING       "PENALTY"

// Indexed by scoringBonus_t in bg_alliance.h
char *CTFBonus[CTF_TOTAL_BONUSES] = {
                                        "CARRIER KILL",
                                        "CARRIER DEFENSE",
                                        "CARRIER SAVE",
                                        "BASE DEFENSE",
                                        "FLAG DEFENSE",
                                        "DEFENDER KILL",
                                        "FLAG HOLDING"
                                    };

char *CTFPenalty[CTF_TOTAL_BONUSES] = {
                                          "CARRIER MURDER", // kill your carrier (ouch)
                                          "ENEMY CARRIER DEFENSE", // kill your teammates who are attacking the
                                          "ENEMY CARRIER SAVE",    // enemy carrier
                                          "ENEMY BASE DEFENSE", // kill your teammates in enemy base
                                          "ENEMY FLAG DEFENSE", // kill your teammates who are trying to get enemy flag
                                          "FLAG ENDANGERMENT", // kill a teammate covering your own flag
                                          "FLAG DROPPING" // actually impossible, since attacker would need to be
                                          // enemy carrier
                                      };

// Whether the teamname in eg "Red Carrier Kill" is the same as the attacker's
// team
qboolean teamFlip[CTF_TOTAL_BONUSES] = {
                                           qfalse,
                                           qtrue,
                                           qtrue,
                                           qtrue,
                                           qtrue,
                                           qfalse,
                                           qfalse
                                       };


// Alliance: Myrkul
// Returns a colored version of a team name.
/*
char *coloredTeamName(team_t team) {
 
	switch (team) {
	case TEAM_RED: return S_COLOR_RED "Red" S_COLOR_WHITE;
	case TEAM_BLUE: return S_COLOR_BLUE "Blue" S_COLOR_WHITE;
	case TEAM_SPECTATOR: return S_COLOR_GREEN "Spectator" S_COLOR_WHITE;
    default: return "";
	}
}
*/

const char *TeamName(int team)  {
    if (team==TEAM_RED)
        return "RED";
    else if (team==TEAM_BLUE)
        return "BLUE";
    else if (team==TEAM_SPECTATOR)
        return "SPECTATOR";
    // BB
    else if (team==TEAM_SPECTATOR_RED)
        return "RED SPECTATOR";
    else if (team==TEAM_SPECTATOR_BLUE)
        return "BLUE SPECTATOR";
    // BB
    return "FREE";
}

const char *OtherTeamName(int team) {

    if (team==TEAM_RED)
        return "BLUE";
    else if (team==TEAM_BLUE)
        return "RED";
    else if (team==TEAM_SPECTATOR)
        return "SPECTATOR";
    // BB
    else if (team==TEAM_SPECTATOR_RED)
        return "BLUE SPECTATOR";
    else if (team==TEAM_SPECTATOR_BLUE)
        return "RED SPECTATOR";
    // BB
    return "FREE";
}


void showBattleCTFBonus(int receiverNum, int bonusType,
                        int points, int param) {
    const char *receiverInfo;
    char receiverName[32];
    int messageTeam;
    char *paramString = "";
    char *team = "";

    // whether this is a penalty
    qboolean penalty = bonusType & SCORE_FLAG_PENALTY;
    bonusType &= ~SCORE_FLAG_PENALTY;

    // except for carrier kills, only show bonuses the local player recieved

    if (receiverNum != cg.snap->ps.clientNum
            //&& bonusType != SCORE_CARRIER_KILL
       ) {
        return;
    }

    // get the name of the receiver of the bonus from his userinfo
    receiverInfo = CG_ConfigString( CS_PLAYERS + receiverNum);
    if (!receiverInfo) {
        return;
    }
    Q_strncpyz( receiverName, Info_ValueForKey( receiverInfo, "n" ),
                sizeof(receiverName) - 2);

    // team of the receiver
    messageTeam = cgs.clientinfo[receiverNum].team;

    // special case: display time carrier lived or location of carrier death on
    // carrier kill
    if (bonusType == SCORE_CARRIER_KILL) {
        if (param & FL_DISTANCE) {
            // bonus awarded based on distance from enemy base; report how far
            // carrier made it
            int distance = param & ~FL_DISTANCE;

            // did the carrier make it past the middle (with respect to enemy base)
            int carrierTeam = penalty ? messageTeam : CG_OtherTeam(messageTeam);
            int teamGround = distance > LOC_MIDDLE ?
                             carrierTeam : CG_OtherTeam(carrierTeam);

            switch (distance) {
            case POS_NEUTRAL:
                paramString = " on neutral ground";
                break;
            case POS_ENEMY_BASE:
            case POS_HOME_BASE:
                paramString = va(" in %s base", TeamName(teamGround));
                break;
            case POS_ENEMY_TERRITORY:
            case POS_HOME_TERRITORY:
                paramString = va(" in %s territory", TeamName(teamGround));
                break;
            }
        } else {
            // bonus awarded based on how long carrier survived
            paramString = va(" after %d seconds", param);
        }
    }

    if (!teamFlip[bonusType]) {
        // color in the message refers to the opposite team
        messageTeam = CG_OtherTeam(messageTeam);
    }

    // no colorized team name on penalties, too confusing
    if (penalty) {
        team = "";
    } else {
        team = va("%s ", TeamName(messageTeam));
    }

    CG_Printf("(%s %s" S_COLOR_WHITE "): %s%s%s: %d %s\n",
              penalty ? PENALTY_STRING : BONUS_STRING,
              receiverName,
              team,
              penalty ? CTFPenalty[bonusType] : CTFBonus[bonusType],
              paramString,
              points,
              points > 1 ? "points" : "point");
}


// Joe - support for team audio
// this may err if 2 clients have the same name
// these are probably better:

// BW_FindClient() - bloodwolf.c
// ClientForString() - g_cvcmds.c

int clientNumForName(char *name) {
    int clientNum;
    clientInfo_t *ci;
    char tempname[MAX_TOKEN_CHARS];

    for(clientNum = 0; clientNum < cgs.maxclients; clientNum++) {
        ci = &cgs.clientinfo[clientNum];
        // keep it case sensitive?
        strcpy( tempname, ci->name );
        Q_CleanStr( tempname );
        if (strcmp(name, tempname) == 0)
            break;
    }

    if (clientNum < cgs.maxclients)
        return(clientNum);
    else
        return(-1);

}

// just getting rid of beep now
qboolean A_dynamicTeamRadio(void) {
    char soundfilepath[MAX_TOKEN_CHARS];
    //char soundtype[MAX_TOKEN_CHARS];
    char *soundtype;
    int clientNum;

    char message[MAX_TOKEN_CHARS];

    const char *configstring;

    Com_sprintf(message, sizeof(message), "%s", Q_strrchr(CG_Argv(1),
                COLOR_CYAN)+1);
    clientNum = atoi(CG_Argv(2));

    configstring = CG_ConfigString(clientNum + CS_PLAYERS);
    //Com_sprintf(soundtype, sizeof(soundtype), "%s", Info_ValueForKey(configstring, "s"));
    soundtype = va("%s", Info_ValueForKey(configstring, "s"));
    // if unset, map according to current model, includes bots
    if (! soundtype[0]) {
        clientInfo_t *ci = &cgs.clientinfo[clientNum];
        char *model;

        // watch out this returns local static var
        // should be model of the sender
        // get rid of /skinname from the model
        model = ci->modelName;
        soundtypeForModel(soundtype, sizeof(soundtype), model);
    }

    Com_sprintf(soundfilepath, sizeof(soundfilepath),
                "sound/radio/%s/%s.wav", soundtype, message);
    if(fileExists(soundfilepath) && ! cg_noTeamAudio.integer) {
        //alliance - banshee- added spectatorcheck
        if (cg.snap->ps.pm_type == PM_SPECTATOR) {
            return qfalse;
        } else { //end of spec check
            return qtrue;
        } //part of spec check
    }
    else
        return qfalse;

} // end A_dynamicTeamAudio()

qboolean A_dynamicVoice(void) {
    char soundfilepath[MAX_TOKEN_CHARS];
    //char soundtype[MAX_TOKEN_CHARS];
    char *soundtype;
    char message[MAX_TOKEN_CHARS];
    int clientNum;

    const char *configstring;

    //Alliance - Banshee - Remove audio messages for SPECTATING players.
    if (cg.snap->ps.pm_type == PM_SPECTATOR)
        return qfalse;
    //End

    Com_sprintf(message, sizeof(message), "%s",
                Q_strrchr(CG_Argv(1), COLOR_GREEN) + 1);

    clientNum = atoi(CG_Argv(2));

    configstring = CG_ConfigString(clientNum + CS_PLAYERS);
    //Com_sprintf(soundtype, sizeof(soundtype), "%s",Info_ValueForKey(configstring, "s"));
    soundtype = va("%s",Info_ValueForKey(configstring, "s"));
    // if unset, map according to current model, includes bots
    if (!soundtype[0]) {
        clientInfo_t *ci = &cgs.clientinfo[clientNum];
        char *model;

        // watch out this returns local static var
        // should be model of the sender
        // get rid of /skinname from the model
        model = ci->modelName;
        soundtypeForModel(soundtype, sizeof(soundtype), model);
    }

    Com_sprintf(soundfilepath, sizeof(soundfilepath),
                "sound/voice/%s/%s.wav", soundtype, message);

    if(fileExists(soundfilepath) && ! cg_noVoiceAudio.integer) {
        return qtrue;
    } else
        return qfalse;

} // end A_dynamicVoice()

// Joe
void CG_Svcmd_Stuff_f(void) {
    trap_SendConsoleCommand( va("%s\n", CG_Argv(1) ));
}


// Joe
char * configName(int num) {

    if ( num == CS_MUSIC ) {
        return "CS_MUSIC";
    } else if ( num == CS_SERVERINFO ) {
        return "CS_SERVERINFO";
    } else if ( num == CS_SYSTEMINFO ) {
        return "CS_SYSTEMINFO";
    } else if ( num == CS_WARMUP ) {
        return "CS_WARMUP";
    } else if ( num == CS_SCORES1 ) {
        return "CS_SCORES1";
    } else if ( num == CS_SCORES2 ) {
        return "CS_SCORES2";
    } else if ( num == CS_WARMUP ) {
        return "CS_WARMUP";
    } else if ( num == CS_LEVEL_START_TIME ) {
        return "CS_LEVEL_START_TIME";
    } else if ( num == CS_VOTE_TIME ) {
        return "CS_VOTE_TIME";
    } else if ( num == CS_VOTE_YES ) {
        return "CS_VOTE_YES";
    } else if ( num == CS_VOTE_NO ) {
        return "CS_VOTE_NO";
    } else if ( num == CS_VOTE_STRING ) {
        return "CS_VOTE_STRING";
    } else if ( num == CS_INTERMISSION ) {
        return "CS_INTERMISSION";
    } else if ( num >= CS_MODELS && num < CS_MODELS+MAX_MODELS ) {
        return "CS_MODELS";
    } else if ( num >= CS_SOUNDS && num < CS_SOUNDS+MAX_MODELS ) {
        return "CS_SOUNDS";
    } else if ( num >= CS_PLAYERS && num < CS_PLAYERS+MAX_CLIENTS ) {
        return "CS_PLAYERS";
    } else if ( num == CS_FLAGSTATUS ) {
        return "CS_FLAGSTATUS";
    } else
        return "CS_UNKNOWN";

}


// Joe - use this in cgame too, the traps are exactly the same
char	*ConcatArgs( int start ) {
    int		i, c, tlen;
    static char	line[MAX_STRING_CHARS];
    int		len;
    char	arg[MAX_STRING_CHARS];

    len = 0;
    c = trap_Argc();
    for ( i = start ; i < c ; i++ ) {
        trap_Argv( i, arg, sizeof( arg ) );
        tlen = strlen( arg );
        if ( len + tlen >= MAX_STRING_CHARS - 1 ) {
            break;
        }
        memcpy( line + len, arg, tlen );
        len += tlen;
        if ( i != c - 1 ) {
            line[len] = ' ';
            len++;
        }
    }

    line[len] = 0;

    return line;
}

// Joe - a_serverinfo command
void CG_Serverinfo_f(void) {
    CG_Printf("%s\n", CG_ConfigString( CS_SERVERINFO ));
}

// Joe - a_systeminfo command
void CG_Systeminfo_f(void) {
    CG_Printf("%s\n", CG_ConfigString( CS_SYSTEMINFO ));
}

// Joe - moved Pub's func to this file
// this is getting big
// we could use configstrings instead, but it wouldn't show in gamespy then
// Alliance: Update Alliance-specific server configuration
void updateServerConfig(const char *info) {
    //char str[10];
    //char str[10];
    //	char shader[1024];

    // these cvars MUST be CVAR_SERVERINFO in game/g_main.c
    // should check if Info_ValueForKey() comes up empty

    //CG_Printf("updateServerConfig()\n");

    cg_serverConfig.grappletype = atoi( Info_ValueForKey( info, "g_grappleType" ) );

    cg_grapple.pullSpeed = atoi(Info_ValueForKey(info, "g_grapplePullSpeed"));
    //	CG_Printf("cg_grapple.pullSpeed is now %d\n", cg_grapple.pullSpeed);


    // weapons stay
    cg_serverConfig.weaponsStay = atoi(Info_ValueForKey(info, "g_weaponsStay"));

    // combat weapons
    cg_serverConfig.battleWeapons = atoi(Info_ValueForKey(info, "g_battleWeapons"));

    // Myrkul: Movement options
    cg_serverConfig.rampJump = atoi(Info_ValueForKey(info, "g_rampJump"));
    cg_serverConfig.strafeJump = atoi(Info_ValueForKey(info, "g_strafeJump"));
    cg_serverConfig.airMove = atoi(Info_ValueForKey(info, "g_airMove"));
    cg_serverConfig.airSpeed = atoi(Info_ValueForKey(info, "g_airSpeed"));
    cg_serverConfig.grafting= atoi(Info_ValueForKey(info, "g_grafting"));

    cg_serverConfig.ammoRestore = atoi(Info_ValueForKey(info, "g_ammoRestore"));

    // begin Joe triple rail
    cg_serverConfig.tripleRail = atoi(Info_ValueForKey(info,"g_tripleRail"));
    // end Joe triple rail
    cg_serverConfig.gamemode = atoi(Info_ValueForKey(info, "g_gamemode"));
    //Com_sprintf(str, sizeof(str), "%s", Info_ValueForKey(info, "g_gamemode"));
    //if(cg_serverConfig.gamemode != 0 || cg_serverConfig.gamemode != 1)
    //   CG_Printf(S_COLOR_RED "updateServerConfig(): can't get value "
    //              "for ac_battle\n");
    cg_serverConfig.grappleGlobal = atoi(Info_ValueForKey(info, "g_grappleGlobal"));
    //Com_sprintf(str, sizeof(str), "%s", Info_ValueForKey(info, "g_grappleGlobal"));
    //if(cg_serverConfig.grappleGlobal != 0 || cg_serverConfig.grappleGlobal != 1)
    //    CG_Printf(S_COLOR_RED "updateServerConfig(): can't get value for g_grappleGlobal\n");

    cg_serverConfig.grapple_onhand = atoi(Info_ValueForKey(info, "g_grappleOnHand"));
    //Com_sprintf(str, sizeof(str), "%s", Info_ValueForKey(info, "g_grappleOnHand"));
    //if(cg_serverConfig.grapple_onhand != 0 || cg_serverConfig.grapple_onhand != 1)
    //    CG_Printf(S_COLOR_RED "updateServerConfig(): can't get value for g_grappleOnHand\n");

    //Com_sprintf(str, sizeof(str), "%s", Info_ValueForKey(info, "g_skyHook"));
    cg_serverConfig.SkyHook = atoi(Info_ValueForKey(info, "g_skyHook"));
    //if(cg_serverConfig.SkyHook != 0 || cg_serverConfig.SkyHook != 1)
    //    CG_Printf(S_COLOR_RED "updateServerConfig(): can't get value for g_SkyHook\n");

    //Com_sprintf(str, sizeof(str), "%s", Info_ValueForKey(info, "g_grappleHookSpeed"));
    cg_grapple.hookSpeed = atoi(Info_ValueForKey(info, "g_grappleHookSpeed"));
    //if(!cg_grapple.hookSpeed)
    //    CG_Printf(S_COLOR_RED "updateServerConfig(): can't get value for g_grappleHookSpeed\n");

    //Com_sprintf(str, sizeof(str), "%s", Info_ValueForKey(info, "g_superShotgun"));
    cg_serverConfig.superShotgun = atoi(Info_ValueForKey(info, "g_superShotgun"));
    //if(cg_serverConfig.superShotgun != 0 || cg_serverConfig.superShotgun  != 1)
    //   CG_Printf(S_COLOR_RED "updateServerConfig(): can't get value for g_superShotgun\n");

    //Com_sprintf(str, sizeof(str), "%s", Info_ValueForKey(info, "g_battlePowerups"));
    cg_serverConfig.battlePowerups = atoi(Info_ValueForKey(info, "g_battlePowerups"));
    // if(cg_serverConfig.battlePowerups != 0 || cg_serverConfig.battlePowerups != 1)
    //     CG_Printf(S_COLOR_RED "updateServerConfig(): can't get value for g_battlePowerups\n");
	cg_serverConfig.dm_flags = atoi(Info_ValueForKey(info, "dmflags"));
}

void getStatusIcons(void ) {
    //char shader[MAX_QPATH];
    char *shader;
    int i, index;

    i = 1;

    //Com_Printf( "^2Team : %d)\n", cg.team);

    if (cg_forceColor.integer == 2) {

        for (i = 1; i < 5; i++) {

            index = i - 1;

            if (cg.team == TEAM_BLUE) {
                //Com_sprintf( shader, sizeof(shader), "icons/iconf_%s%d", cg_teamColor.string, i );
                shader = va("icons/iconf_%s%d", cg_teamColor.string, i );
                cgs.media.blueFlagShader[i - 1] = trap_R_RegisterShader( shader );
                //Com_Printf( "^2Blue : %s\n", shader);

                //Com_sprintf( shader, sizeof(shader), "icons/iconf_%s%d", cg_enemyColor.string, i );
                shader = va("icons/iconf_%s%d", cg_enemyColor.string, i);
                cgs.media.redFlagShader[i - 1] = trap_R_RegisterShader( shader );
                //Com_Printf( "^2Red : %s\n", shader);

            }
            else {

                //Com_sprintf( shader, sizeof(shader), "icons/iconf_%s%d", cg_teamColor.string, i );
                shader = va("icons/iconf_%s%d", cg_teamColor.string, i);
                cgs.media.redFlagShader[i - 1] = trap_R_RegisterShader( shader );
                //Com_Printf( "^2Red : %s\n", shader);

                //Com_sprintf( shader, sizeof(shader), "icons/iconf_%s%d", cg_enemyColor.string, i );
                shader = va("icons/iconf_%s%d", cg_enemyColor.string, i);

                cgs.media.blueFlagShader[i - 1] = trap_R_RegisterShader( shader );
                //Com_Printf( "^2Blue : %s\n", shader);

            }

        }
        cgs.media.redBlueFlagShader = trap_R_RegisterShaderNoMip( "icons/iconf_redblu" );
    } else {

        cgs.media.redFlagShader[0] = trap_R_RegisterShaderNoMip( "icons/iconf_red1" );
        cgs.media.redFlagShader[1] = trap_R_RegisterShaderNoMip( "icons/iconf_red2" );
        cgs.media.redFlagShader[2] = trap_R_RegisterShaderNoMip( "icons/iconf_red3" );

        cgs.media.blueFlagShader[0] = trap_R_RegisterShaderNoMip( "icons/iconf_blue1" );
        cgs.media.blueFlagShader[1] = trap_R_RegisterShaderNoMip( "icons/iconf_blue2" );
        cgs.media.blueFlagShader[2] = trap_R_RegisterShaderNoMip( "icons/iconf_blue3" );
        //RTF
        cgs.media.redFlagShader[3] = trap_R_RegisterShaderNoMip( "icons/iconf_red4" );
        cgs.media.blueFlagShader[3] = trap_R_RegisterShaderNoMip( "icons/iconf_blue4" );
        cgs.media.redBlueFlagShader = trap_R_RegisterShaderNoMip( "icons/iconf_redblu" );

    }
}

/*
void changeItemIcons(void) {
 
    
    gitem_t	*item;
    itemInfo_t info;
 
 
    item = BG_FindItemForPowerup( PW_BLUEFLAG );
    info = cg_items[ITEM_INDEX(item)];
    info.icon = trap_R_RegisterShader( getItemIcon("icons/iconf_blue1") );
 
    item = BG_FindItemForPowerup( PW_REDFLAG );
    info = cg_items[ITEM_INDEX(item)];
    info.icon = trap_R_RegisterShader( getItemIcon("icons/iconf_red1") );
    
 
}
*/

char *getItemIcon(char *iconShader ) {
    //char originalShader[MAX_QPATH];
    //char newShader[MAX_QPATH];
    //char shader[MAX_QPATH]; //some things are larger then 64 characters apparently
    char *shader=NULL;
    //char shader[96]; //some things are larger then 64 characters apparently
    //Com_Printf( "^2Team : %d)\n", cg.team);

    if (cg_forceColor.integer == 2) {

        if (Q_stricmpn(iconShader, "icons/iconf_red1",
                       sizeof("icons/iconf_red1")) == 0) {
            switch(cg.team) {
            case TEAM_BLUE:

                //Com_sprintf( shader, sizeof(shader), "icons/iconf_%s1", cg_enemyColor.string );
                shader = va("icons/iconf_%s1", cg_enemyColor.string);
                //Com_Printf( "^2 remap file: %s \n", shader );

            default:

                //Com_sprintf( shader, sizeof(shader), "icons/iconf_%s1", cg_teamColor.string );
                shader = va("icons/iconf_%s1", cg_teamColor.string);

                //Com_Printf( "^2 remap file: %s \n", shader );

            }
        }
        else if (Q_stricmpn(iconShader, "icons/iconf_blue1",  sizeof("icons/iconf_blue1")) == 0) {

            switch(cg.team) {
            case TEAM_BLUE:

                //Com_sprintf( shader, sizeof(shader), "icons/iconf_%s1", cg_teamColor.string );
                shader = va("icons/iconf_%s1", cg_teamColor.string);
                //Com_Printf( "^2 remap file: %s \n", shader );

            default:
                //Com_sprintf( shader, sizeof(shader), "icons/iconf_%s1", cg_enemyColor.string );
                shader = va("icons/iconf_%s1", cg_enemyColor.string);
                //Com_Printf( "^2 remap file: %s \n", shader );
            }
        }
        else if(Q_stricmpn(iconShader,"icons/iconw",11) == 0)//INCIN  --- some icons don't have iconf_
            //Com_sprintf( shader, sizeof(shader), "icons/iconw_%s1", cg_enemyColor.string );
            shader = va("icons/iconw_%s1", cg_enemyColor.string);

        Q_strncpyz(iconShader, shader, sizeof(shader));
    }
    return iconShader;
}

/*
char *getFlagShaders(char *shaderFile ) {
    //char originalShader[MAX_QPATH];
    //char newShader[MAX_QPATH];
    char shader[MAX_QPATH];
 
    //Com_Printf( "^2 before: %s \n", shaderFile );
 
    //Com_Printf( "^2 Entered Flag Shader Swap \n" );
 
    //Com_Printf( "^2Team : %d)\n", cg.team);
 
    //BB
    //Battle Flag Shaders
    if (cg_forceColor.integer) {
 
        switch(cg.team) {
        case TEAM_BLUE:
 
            if (Q_stricmpn(shaderFile, "textures/ctf/ctf_redflag",
                           sizeof("textures/ctf/ctf_redflag")) == 0) {
 
                if (cg_forceColor.integer == 2)
                    Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_%sflag_%s_%s",
                                 cg_enemyColor.string, cg_enemyFlagstyle.string, cg_enemyLogo.string );
                else
                    Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_redflag_%s_%s",
                                 cg_enemyFlagstyle.string, cg_enemyLogo.string );
 
                cgs.media.redFlagBanner = trap_R_RegisterShader( shader );
                strncpy(shaderFile, shader, sizeof(shader));
 
            } else if (Q_stricmpn(shaderFile, "textures/ctf/ctf_blueflag",
                                  sizeof("textures/ctf/ctf_redflag")) == 0) {
 
                if (cg_forceColor.integer == 2)
                    Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_%sflag_%s_%s",
                                 cg_teamColor.string, cg_teamFlagstyle.string, cg_teamLogo.string );
                else
                    Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_blueflag_%s_%s",
                                 cg_teamFlagstyle.string, cg_teamLogo.string );
 
                cgs.media.blueFlagBanner = trap_R_RegisterShader( shader );
                strncpy(shaderFile, shader, sizeof(shader));
 
            } else if (Q_stricmpn(shaderFile, "models/flags/r_flag2",
                                  sizeof("models/flags/r_flag2")) == 0) {
 
                if (cg_forceColor.integer == 2)
                    Com_sprintf( shader, sizeof(shader), "models/flags/%s_flag2_%s",
                                 cg_enemyColor.string, cg_enemyLogo.string );
                else
                    Com_sprintf( shader, sizeof(shader), "models/flags/red_flag2_%s",
                                 cg_enemyLogo.string );
 
                strncpy(shaderFile, shader, sizeof(shader));
 
            } else if (Q_stricmpn(shaderFile, "models/flags/b_flag2",
                                  sizeof("models/flags/b_flag2")) == 0) {
 
                if (cg_forceColor.integer == 2)
                    Com_sprintf( shader, sizeof(shader), "models/flags/%s_flag2_%s",
                                 cg_teamColor.string, cg_teamLogo.string );
                else
                    Com_sprintf( shader, sizeof(shader), "models/flags/blue_flag2_%s",
                                 cg_teamLogo.string );
 
                strncpy(shaderFile, shader, sizeof(shader));
 
            }
 
        default:
 
            if (Q_stricmpn(shaderFile, "textures/ctf/ctf_redflag",
                           sizeof("textures/ctf/ctf_redflag")) == 0) {
 
                if (cg_forceColor.integer == 2)
                    Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_%sflag_%s_%s",
                                 cg_teamColor.string, cg_teamFlagstyle.string, cg_teamLogo.string );
                else
                    Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_redflag_%s_%s",
                                 cg_teamFlagstyle.string, cg_teamLogo.string );
 
                cgs.media.redFlagBanner = trap_R_RegisterShader( shader );
                strncpy(shaderFile, shader, sizeof(shader));
 
            } else if (Q_stricmpn(shaderFile, "textures/ctf/ctf_blueflag",
                                  sizeof("textures/ctf/ctf_redflag")) == 0) {
 
                if (cg_forceColor.integer == 2)
                    Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_%sflag_%s_%s",
                                 cg_enemyColor.string, cg_enemyFlagstyle.string, cg_enemyLogo.string );
                else
                    Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_blueflag_%s_%s",
                                 cg_enemyFlagstyle.string, cg_enemyLogo.string );
 
                cgs.media.blueFlagBanner = trap_R_RegisterShader( shader );
                strncpy(shaderFile, shader, sizeof(shader));
 
            } else if (Q_stricmpn(shaderFile, "models/flags/r_flag2",
                                  sizeof("models/flags/r_flag2")) == 0) {
 
                if (cg_forceColor.integer == 2)
                    Com_sprintf( shader, sizeof(shader), "models/flags/%s_flag2_%s",
                                 cg_teamColor.string, cg_teamLogo.string );
 
                else
                    Com_sprintf( shader, sizeof(shader), "models/flags/red_flag2_%s",
                                 cg_teamLogo.string );
 
                strncpy(shaderFile, shader, sizeof(shader));
 
            } else if (Q_stricmpn(shaderFile, "models/flags/b_flag2",
                                  sizeof("models/flags/b_flag2")) == 0) {
 
                if (cg_forceColor.integer == 2)
                    Com_sprintf( shader, sizeof(shader), "models/flags/%s_flag2_%s",
                                 cg_enemyColor.string, cg_enemyLogo.string );
                else
                    Com_sprintf( shader, sizeof(shader), "models/flags/blue_flag2_%s",
                                 cg_enemyLogo.string );
 
                strncpy(shaderFile, shader, sizeof(shader));
 
            }
        }
    }
    return shaderFile;
 
}
*/

int getColorFromString(char *color) {


    if (Q_stricmp(color, "red") == 0) {
        return BC_RED;
    } else if (Q_stricmp(color, "blue") == 0) {
        return BC_BLUE;
    } else if (Q_stricmp(color, "yellow") == 0) {
        return BC_YELLOW;
    } else if (Q_stricmp(color, "orange") == 0) {
        return BC_ORANGE;
    } else if (Q_stricmp(color, "green") == 0) {
        return BC_GREEN;
    } else if (Q_stricmp(color, "pink") == 0) {
        return BC_PINK;
    } else if (Q_stricmp(color, "aqua") == 0) {
        return BC_AQUA;
    } else if (Q_stricmp(color, "white") == 0) {
        return BC_WHITE;
    } else if (Q_stricmp(color, "black") == 0) {
        return BC_BLACK;
    } else
        return -1;

}

char *getStringFromColor(int color) {


    if (color == BC_RED) {
        return "red";
    } else if (color == BC_BLUE) {
        return "blue";
    } else if (color == BC_YELLOW) {
        return "yellow";
    } else if (color == BC_PINK) {
        return "pink";
    } else if (color == BC_ORANGE) {
        return "orange";
    } else if (color == BC_AQUA) {
        return "aqua";
    } else if (color == BC_GREEN) {
        return "green";
    } else if (color == BC_WHITE) {
        return "white";
    } else if (color == BC_BLACK) {
        return "black";
    }

    return "white";
}

void changeFlagShaders(void) {
    //char originalShader[MAX_QPATH];
    //char newShader[MAX_QPATH];
    //char shader[MAX_QPATH];
    char *shader=NULL;
    char f;
    char timeOffset[10];//incin MAY NOT BE LARGE ENOUGH

    //timeOffset = "0.00";

    f = cg.time * 0.001;
    Com_sprintf(timeOffset, sizeof(timeOffset), "%5.2f", f);

    //Com_Printf( "^4Time : %s\n", timeOffset);

    //Com_Printf( "^2 Entered Flag Shader Swap \n" );

    //Battle Flag Shaders
    if (cg.team == TEAM_BLUE) {

        if (cg_forceColor.integer == 2) {

            //Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_%sflag_%s_%s", cg_enemyColor.string, cg_enemyFlagstyle.string, cg_enemyLogo.string );
            shader = va("textures/ctf/ctf_%sflag_%s_%s", cg_enemyColor.string, cg_enemyFlagstyle.string, cg_enemyLogo.string );
            cgs.media.redFlagBanner = trap_R_RegisterShader( shader );
            trap_R_RemapShader( "textures/ctf/ctf_redflag", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (textures/ctf/ctf_redflag) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_%sflag_%s_%s", cg_teamColor.string, cg_teamFlagstyle.string, cg_teamLogo.string );
            shader = va("textures/ctf/ctf_%sflag_%s_%s", cg_teamColor.string, cg_teamFlagstyle.string, cg_teamLogo.string );
            cgs.media.blueFlagBanner = trap_R_RegisterShader( shader );
            trap_R_RemapShader( "textures/ctf/ctf_blueflag", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (textures/ctf/ctf_blueflag) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "models/flags/%s_flag2_%s", cg_enemyColor.string, cg_enemyLogo.string );
            shader = va("models/flags/%s_flag2_%s", cg_enemyColor.string, cg_enemyLogo.string);
            trap_R_RegisterShader( shader );
            trap_R_RemapShader( "models/flags/r_flag2", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (models/flags/r_flag2) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "models/flags/%s_flag2_%s", cg_teamColor.string, cg_teamLogo.string );
            shader = va("models/flags/%s_flag2_%s", cg_teamColor.string, cg_teamLogo.string);
            trap_R_RegisterShader( shader );
            trap_R_RemapShader( "models/flags/b_flag2", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (models/flags/b_flag2) -> (%s)\n", shader );


        } else if (cg_forceColor.integer == 1) {

            //Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_redflag_%s_%s", cg_enemyFlagstyle.string, cg_enemyLogo.string );
            shader = va("textures/ctf/ctf_redflag_%s_%s", cg_enemyFlagstyle.string, cg_enemyLogo.string);
            cgs.media.redFlagBanner = trap_R_RegisterShader( shader );
            trap_R_RemapShader( "textures/ctf/ctf_redflag", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (textures/ctf/ctf_redflag) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_blueflag_%s_%s", cg_teamFlagstyle.string, cg_teamLogo.string );
            shader = va("textures/ctf/ctf_blueflag_%s_%s", cg_teamFlagstyle.string, cg_teamLogo.string);
            cgs.media.blueFlagBanner = trap_R_RegisterShader( shader );
            trap_R_RemapShader( "textures/ctf/ctf_blueflag", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (textures/ctf/ctf_blueflag) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "models/flags/red_flag2_%s", cg_enemyLogo.string );
            shader = va("models/flags/red_flag2_%s", cg_enemyLogo.string);
            trap_R_RegisterShader( shader );
            trap_R_RemapShader( "models/flags/r_flag2", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (models/flags/r_flag2) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "models/flags/blue_flag2_%s", cg_teamLogo.string );
            shader = va("models/flags/blue_flag2_%s", cg_teamLogo.string);
            trap_R_RegisterShader( shader );
            trap_R_RemapShader( "models/flags/b_flag2", shader, timeOffset );
 //           if (cg_debugRemap.integer)
 //               Com_Printf( "^2Remap (models/flags/b_flag2) -> (%s)\n", shader );


        } else {

            cgs.media.redFlagBanner = trap_R_RegisterShader( "textures/ctf/ctf_redflag" );
            trap_R_RemapShader( "textures/ctf/ctf_redflag", "textures/ctf/ctf_redflag", timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (textures/ctf/ctf_redflag) -> (textures/ctf/ctf_redflag)\n", shader );

            cgs.media.blueFlagBanner = trap_R_RegisterShader( "textures/ctf/ctf_blueflag" );
            trap_R_RemapShader( "textures/ctf/ctf_blueflag", "textures/ctf/ctf_blueflag", timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (textures/ctf/ctf_blueflag) -> (textures/ctf/ctf_blueflag)\n", shader );

            trap_R_RegisterShader( "models/flags/r_flag2" );
            trap_R_RemapShader( "models/flags/r_flag2", "models/flags/r_flag2", timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (models/flags/r_flag2) -> (models/flags/r_flag2)\n", shader );

            trap_R_RegisterShader( "models/flags/b_flag2" );
            trap_R_RemapShader( "models/flags/b_flag2", "models/flags/b_flag2", timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (models/flags/b_flag2) -> (models/flags/b_flag2)\n", shader );

        }

    } else {

        if (cg_forceColor.integer == 2) {

            //Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_%sflag_%s_%s", cg_enemyColor.string, cg_enemyFlagstyle.string, cg_enemyLogo.string );
            shader = va("textures/ctf/ctf_%sflag_%s_%s", cg_enemyColor.string, cg_enemyFlagstyle.string, cg_enemyLogo.string);
            cgs.media.redFlagBanner = trap_R_RegisterShader( shader );
            trap_R_RemapShader( "textures/ctf/ctf_blueflag", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (textures/ctf/ctf_blueflag) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_%sflag_%s_%s", cg_teamColor.string, cg_teamFlagstyle.string, cg_teamLogo.string );
            shader = va("textures/ctf/ctf_%sflag_%s_%s", cg_teamColor.string, cg_teamFlagstyle.string, cg_teamLogo.string);
            cgs.media.blueFlagBanner = trap_R_RegisterShader( shader );
            trap_R_RemapShader( "textures/ctf/ctf_redflag", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (textures/ctf/ctf_redflag) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "models/flags/%s_flag2_%s", cg_enemyColor.string, cg_enemyLogo.string );
            shader = va("models/flags/%s_flag2_%s", cg_enemyColor.string, cg_enemyLogo.string);
            trap_R_RegisterShader( shader );
            trap_R_RemapShader( "models/flags/b_flag2", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (models/flags/b_flag2) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "models/flags/%s_flag2_%s", cg_teamColor.string, cg_teamLogo.string );
            shader = va("models/flags/%s_flag2_%s", cg_teamColor.string, cg_teamLogo.string);
            trap_R_RegisterShader( shader );
            trap_R_RemapShader( "models/flags/r_flag2", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (models/flags/r_flag2) -> (%s)\n", shader );


        } else if (cg_forceColor.integer == 1) {

            //Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_blueflag_%s_%s", cg_enemyFlagstyle.string, cg_enemyLogo.string );
            shader = va("textures/ctf/ctf_blueflag_%s_%s", cg_enemyFlagstyle.string, cg_enemyLogo.string);
            cgs.media.redFlagBanner = trap_R_RegisterShader( shader );
            trap_R_RemapShader( "textures/ctf/ctf_blueflag", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (textures/ctf/ctf_blueflag) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "textures/ctf/ctf_redflag_%s_%s", cg_teamFlagstyle.string, cg_teamLogo.string );
            shader = va("textures/ctf/ctf_redflag_%s_%s", cg_teamFlagstyle.string, cg_teamLogo.string);
            cgs.media.blueFlagBanner = trap_R_RegisterShader( shader );
            trap_R_RemapShader( "textures/ctf/ctf_redflag", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (textures/ctf/ctf_redflag) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "models/flags/blue_flag2_%s", cg_enemyLogo.string );
            shader = va("models/flags/blue_flag2_%s", cg_enemyLogo.string);
            trap_R_RegisterShader( shader );
            trap_R_RemapShader( "models/flags/b_flag2", shader, timeOffset );
 //           if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (models/flags/b_flag2) -> (%s)\n", shader );

            //Com_sprintf( shader, sizeof(shader), "models/flags/red_flag2_%s", cg_teamLogo.string );
            shader = va("models/flags/red_flag2_%s", cg_teamLogo.string);
            trap_R_RegisterShader( shader );
            trap_R_RemapShader( "models/flags/r_flag2", shader, timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (models/flags/r_flag2) -> (%s)\n", shader );


        } else {

            cgs.media.redFlagBanner = trap_R_RegisterShader( "textures/ctf/ctf_redflag" );
            trap_R_RemapShader( "textures/ctf/ctf_redflag", "textures/ctf/ctf_redflag", timeOffset );
//            if (cg_debugRemap.integer)
 //               Com_Printf( "^2Remap (textures/ctf/ctf_redflag) -> (textures/ctf/ctf_redflag)\n", shader );

            cgs.media.blueFlagBanner = trap_R_RegisterShader( "textures/ctf/ctf_blueflag" );
            trap_R_RemapShader( "textures/ctf/ctf_blueflag", "textures/ctf/ctf_blueflag", timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (textures/ctf/ctf_blueflag) -> (textures/ctf/ctf_blueflag)\n", shader );

            trap_R_RegisterShader( "models/flags/r_flag2" );
            trap_R_RemapShader( "models/flags/r_flag2", "models/flags/r_flag2", timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (models/flags/r_flag2) -> (models/flags/r_flag2)\n");

            trap_R_RegisterShader( "models/flags/b_flag2" );
            trap_R_RemapShader( "models/flags/b_flag2", "models/flags/b_flag2", timeOffset );
//            if (cg_debugRemap.integer)
//                Com_Printf( "^2Remap (models/flags/b_flag2) -> (models/flags/b_flag2)\n");

        }
    }

}

void parseRemapFileNew(void) {

    int	len;
    //    int i;
    fileHandle_t f;
    char buf[16384];
    char **p, *ptr;
    char *token;
    //char filename[MAX_OSPATH] = {0};
    char *filename;
    int basecolor;
    //int newcolor;
    char originalShader[MAX_QPATH];
    //char newShader[MAX_QPATH];
    int tempColor;
    float tme;
    char timeOffset[10];

    if (cgs.gametype  < GT_CTF)
        return;

    //timeOffset = "0.00";
    basecolor = -1;
    tempColor = -1;

    tme = cg.time * 0.001;
    Com_sprintf(timeOffset, sizeof(timeOffset), "%5.2f", tme);


    // Com_sprintf( filename, sizeof(filename), "maps/%s.remap", Info_ValueForKey(CG_ConfigString(CS_SERVERINFO), "mapname") );
    filename = va("maps/%s.remap", Info_ValueForKey(CG_ConfigString(CS_SERVERINFO), "mapname"));
    //Com_Printf( "^2 remap file: %s \n", filename );

    len = trap_FS_FOpenFile( filename, &f, FS_READ );
    if ( !f ) {
        //trap_Print( va( S_COLOR_RED "remap file was not found: %s\n", filename ) );
        return;
    }

    if ( len >= 16384 ) {
        //trap_Print( va( S_COLOR_RED "remap file too large: %s is %i, max allowed is %i", filename, len, 16384 ) );
        trap_FS_FCloseFile( f );
        return ;
    }

    trap_FS_Read( buf, len, f );
    buf[len] = 0;
    trap_FS_FCloseFile( f );

    ptr = buf;
    p = &ptr;

    //loop file
    while ( 1 ) {

        token = COM_ParseExt(p, qtrue);
        if (!token || token[0] == 0) {
            return;
        }

        if (!Q_stricmp(token, "}"))
            break;

        if (Q_stricmp(token, "{")) {

            basecolor = getColorFromString(token);

            //trap_Print( va( S_COLOR_RED "remap: %d\n",
            //basecolor ) );
        }

        if (!Q_stricmp(token, "{")) {

            //loop original shader
            while(1) {

                token = COM_ParseExt(p, qtrue);
                if (!token || token[0] == 0) {
                    return;
                }

                if (!Q_stricmp(token, "}"))
                    break;

                if (Q_stricmp(token, "{")) {
                    Com_sprintf(originalShader,
                                sizeof(originalShader), token);

                    //trap_Print( va( S_COLOR_RED "remap: %s\n",
                    //originalShader ) );

                }

                if (!Q_stricmp(token, "{")) {

                    //loop new shader
                    while(1) {

                        token = COM_ParseExt(p, qtrue);
                        if (!token || token[0] == 0) {
                            return;
                        }

                        if (!Q_stricmp(token, "}"))
                            break;

                        //trap_Print( va( S_COLOR_RED "color:%s\n",
                        //token ) );


                        //remap shaders according to team
                        if (Q_stricmpn(token, "=", sizeof("=")) != 0) {

                            if (getColorFromString(token) != -1) {

                                tempColor = getColorFromString(token);

                                //trap_Print( va( S_COLOR_RED "color:%s\n",
                                //token ) );

                            }
                            else {

                                //Com_Printf( "^2Remap (%d)\n", basecolor );

                                if (cg.team == TEAM_BLUE) {

                                    if (basecolor == BC_BLUE) {

                                        if (cg_forceColor.integer == 2) {

                                            if (getColorFromString(cg_teamColor.string) == tempColor) {

//                                                if (cg_debugRemap.integer)
//                                                    Com_Printf( "^2Remap (%s) -> (%s)\n",
//                                                                originalShader, token );

                                                if (cg_registerRemap.integer){
//													trap_R_ClearScene();
                                                    trap_R_RegisterShader( token );
												}
//												trap_R_ClearScene();
												trap_R_RemapShader( originalShader, token, timeOffset );

                                            }
                                        } else {

                                            if (tempColor == BC_BLUE) {

//                                                if (cg_debugRemap.integer)
//                                                    Com_Printf( "^2Remap (%s) -> (%s)\n",
//                                                                originalShader, token );
                                                if (cg_registerRemap.integer){
//													trap_R_ClearScene();
                                                    trap_R_RegisterShader( token );
												}
//												trap_R_ClearScene();
												trap_R_RemapShader( originalShader, token, timeOffset );
                                            }

                                        }
                                    } else if (basecolor == BC_RED) {

                                        if (cg_forceColor.integer == 2) {

                                            if (getColorFromString(cg_enemyColor.string) == tempColor) {

//                                                if (cg_debugRemap.integer)
//                                                    Com_Printf( "^2Remap (%s) -> (%s)\n",
//                                                                originalShader, token );
                                               if (cg_registerRemap.integer){
//													trap_R_ClearScene();
                                                    trap_R_RegisterShader( token );
												}
//												trap_R_ClearScene();
												trap_R_RemapShader( originalShader, token, timeOffset );
                                            }

                                        } else {

                                            if (tempColor == BC_RED) {

//                                                if (cg_debugRemap.integer)
//                                                    Com_Printf( "^2Remap (%s) -> (%s)\n",
//                                                                originalShader, token );

                                                if (cg_registerRemap.integer){
//													trap_R_ClearScene();
                                                    trap_R_RegisterShader( token );
												}
//												trap_R_ClearScene();
												trap_R_RemapShader( originalShader, token, timeOffset );
                                            }

                                        }
                                    }

                                } else {

                                    if (basecolor == BC_BLUE) {

                                        if (cg_forceColor.integer == 2) {

                                            if (getColorFromString(cg_enemyColor.string) == tempColor) {

//                                                if (cg_debugRemap.integer)
//                                                   Com_Printf( "^2Remap (%s) -> (%s)\n",
//                                                                originalShader, token );
                                                if (cg_registerRemap.integer){
//													trap_R_ClearScene();
                                                    trap_R_RegisterShader( token );
												}
//												trap_R_ClearScene();
												trap_R_RemapShader( originalShader, token, timeOffset );

                                            }
                                        } else {

                                            if (tempColor == BC_BLUE) {

//                                                if (cg_debugRemap.integer)
 //                                                   Com_Printf( "^2Remap (%s) -> (%s)\n",
 //                                                               originalShader, token );

                                                if (cg_registerRemap.integer){
//													trap_R_ClearScene();
                                                    trap_R_RegisterShader( token );
												}
//												trap_R_ClearScene();
												trap_R_RemapShader( originalShader, token, timeOffset );

                                            }

                                        }
                                    } else if (basecolor == BC_RED) {

                                        if (cg_forceColor.integer == 2) {

                                            if (getColorFromString(cg_teamColor.string) == tempColor) {

//                                                if (cg_debugRemap.integer)
//                                                    Com_Printf( "^2Remap (%s) -> (%s)\n",
//                                                                originalShader, token );

                                                if (cg_registerRemap.integer){
//													trap_R_ClearScene();
                                                    trap_R_RegisterShader( token );
												}
//												trap_R_ClearScene();
												trap_R_RemapShader( originalShader, token, timeOffset );
                                            }
                                        } else {

                                            if (tempColor == BC_RED) {

//                                                if (cg_debugRemap.integer)
//                                                    Com_Printf( "^2Remap (%s) -> (%s)\n",
//                                                                originalShader, token );

                                                if (cg_registerRemap.integer){
//													trap_R_ClearScene();
                                                    trap_R_RegisterShader( token );
												}
//												trap_R_ClearScene();
												trap_R_RemapShader( originalShader, token, timeOffset );
                                            }

                                        }
                                    }
                                }
                            }
                        }
                        //remap shaders according to team

                    }
                    //loop new shader
                }
            }
            //loop original shader
        }
        //if a color
    }
    //loop file
}

char *StringReplace(char *Str, size_t BufSiz, char *OldStr, char *NewStr) {

    int OldLen, NewLen;
    char *p, *q;

    if(NULL == (p = strstr(Str, OldStr)))
        return Str;

    OldLen = strlen(OldStr);
    NewLen = strlen(NewStr);
    if ((strlen(Str) + NewLen - OldLen + 1) > BufSiz)
        return Str;

    memmove(q = p+NewLen, p+OldLen, strlen(p+OldLen)+1);
    memcpy(p, NewStr, NewLen);
    return q;

}

char *FindColoredName(char *strText) {

    int tColor, eColor;
    char		text[1024];

    strcpy(text, strText);

    //BB begin COLORS
    //StringReplace(text, sizeof(text), " RED ", " test ");
    if (cg_forceColor.integer == 2
            && cgs.gametype >= GT_TEAM) {

        tColor = getColorFromString(cg_teamColor.string);
        eColor = getColorFromString(cg_enemyColor.string);

        if (cg.team == TEAM_BLUE) {

            if (tColor == BC_AQUA) {
                StringReplace(strText, sizeof(strText), "BLUE", "^5AQUA^7");
            } else if (tColor == BC_BLACK) {
                StringReplace(strText, sizeof(strText), "BLUE", "^0BLACK^7");
            } else if (tColor == BC_BLUE) {
                StringReplace(strText, sizeof(strText), "BLUE", "^4BLUE^7");
            } else if (tColor == BC_GREEN) {
                StringReplace(strText, sizeof(strText), "BLUE", "^2GREEN^7");
            } else if (tColor == BC_ORANGE) {
					StringReplace(strText, sizeof(strText), "BLUE", "^8ORANGE^7");
            } else if (tColor == BC_RED) {
                StringReplace(strText, sizeof(strText), "BLUE", "^1RED^7");
            } else if (tColor == BC_PINK) {
                StringReplace(strText, sizeof(strText), "BLUE", "^6PINK^7");
            } else if (tColor == BC_WHITE) {
                StringReplace(strText, sizeof(strText), "BLUE", "^7WHITE^7");
            } else if (tColor == BC_YELLOW) {
                StringReplace(strText, sizeof(strText), "BLUE", "^3YELLOW^7");
            }

            if (eColor == BC_AQUA) {
                StringReplace(strText, sizeof(strText), "RED", "^5AQUA^7");
            } else if (eColor == BC_BLACK) {
                StringReplace(strText, sizeof(strText), "RED", "^0BLACK^7");
            } else if (eColor == BC_BLUE) {
                StringReplace(strText, sizeof(strText), "RED", "^4BLUE^7");
            } else if (eColor == BC_GREEN) {
                StringReplace(strText, sizeof(strText), "RED", "^2GREEN^7");
            } else if (eColor == BC_ORANGE) {
					StringReplace(strText, sizeof(strText), "RED", "^8ORANGE^7");
            } else if (eColor == BC_RED) {
                StringReplace(strText, sizeof(strText), "RED", "^1RED^7");
            } else if (eColor == BC_PINK) {
                StringReplace(strText, sizeof(strText), "RED", "^6PINK^7");
            } else if (eColor == BC_WHITE) {
                StringReplace(strText, sizeof(strText), "RED", "^7WHITE^7");
            } else if (eColor == BC_YELLOW) {
                StringReplace(strText, sizeof(strText), "RED", "^3YELLOW^7");
            }
        } else {

            if (eColor == BC_AQUA) {
                StringReplace(strText, sizeof(strText), "BLUE", "^5AQUA^7");
            } else if (eColor == BC_BLACK) {
                StringReplace(strText, sizeof(strText), "BLUE", "^0BLACK^7");
            } else if (eColor == BC_BLUE) {
                StringReplace(strText, sizeof(strText), "BLUE", "^4BLUE^7");
            } else if (eColor == BC_GREEN) {
                StringReplace(strText, sizeof(strText), "BLUE", "^2GREEN^7");
            } else if (eColor == BC_ORANGE) {
					StringReplace(strText, sizeof(strText), "BLUE", "^8ORANGE^7");
            } else if (eColor == BC_RED) {
                StringReplace(strText, sizeof(strText), "BLUE", "^1RED^7");
            } else if (eColor == BC_PINK) {
                StringReplace(strText, sizeof(strText), "BLUE", "^6PINK^7");
            } else if (eColor == BC_WHITE) {
                StringReplace(strText, sizeof(strText), "BLUE", "^7WHITE^7");
            } else if (eColor == BC_YELLOW) {
                StringReplace(strText, sizeof(strText), "BLUE", "^3YELLOW^7");
            }

            if (tColor == BC_AQUA) {
                StringReplace(strText, sizeof(strText), "RED", "^5AQUA^7");
            } else if (tColor == BC_BLACK) {
                StringReplace(strText, sizeof(strText), "RED", "^0BLACK^7");
            } else if (tColor == BC_BLUE) {
                StringReplace(strText, sizeof(strText), "RED", "^4BLUE^7");
            } else if (tColor == BC_GREEN) {
                StringReplace(strText, sizeof(strText), "RED", "^2GREEN^7");
            } else if (tColor == BC_ORANGE) {
					StringReplace(strText, sizeof(strText), "RED", "^8ORANGE^7");
            } else if (tColor == BC_RED) {
                StringReplace(strText, sizeof(strText), "RED", "^1RED^7");
            } else if (tColor == BC_PINK) {
                StringReplace(strText, sizeof(strText), "RED", "^6PINK^7");
            } else if (tColor == BC_WHITE) {
                StringReplace(strText, sizeof(strText), "RED", "^7WHITE^7");
            } else if (tColor == BC_YELLOW) {
                StringReplace(strText, sizeof(strText), "RED", "^3YELLOW^7");
            }

        }

    } else if(cgs.gametype >= GT_TEAM) {

        StringReplace(strText, sizeof(strText), "BLUE", "^4BLUE^7");
        StringReplace(strText, sizeof(strText), "RED", "^1RED^7");


    }
    strcpy(strText, text);
    return strText;

}

void BB_LightningTeamEffects(int team, int bccolor) {
    char lshader[128];
    char sshader[128];
    char fshader[128];
	char eshader[128];

    Com_sprintf( lshader, sizeof(lshader), "lightningBolt_%s", getStringFromColor(bccolor) );
    Com_sprintf( sshader, sizeof(sshader), "models/weapons2/lightning/lightning_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( fshader, sizeof(fshader), "models/weapons2/lightning/f_lightning_%s.skin", getStringFromColor(bccolor) );
	Com_sprintf( eshader, sizeof(eshader), "models/weaphits/crackle_%s.md3", getStringFromColor(bccolor) );

    if (team == TEAM_BLUE) {

        cgs.media.lightningShader_blue = trap_R_RegisterShader(lshader);
        cgs.media.lightninggunSkin_blue = trap_R_RegisterSkin(sshader);
        cgs.media.lightningFlashSkin_blue = trap_R_RegisterSkin(fshader);
		cgs.media.lightningExplosionModel_blue = trap_R_RegisterModel( eshader );

    } else {

        cgs.media.lightningShader_red = trap_R_RegisterShader(lshader);
        cgs.media.lightninggunSkin_red = trap_R_RegisterSkin(sshader);
        cgs.media.lightningFlashSkin_red = trap_R_RegisterSkin(fshader);
		cgs.media.lightningExplosionModel_red = trap_R_RegisterModel(eshader);


    }
}

void BB_RocketTeamEffects(int team, int bccolor) {
    char eshader[128];
    char sshader[128];
    char gshader[128];
    char fshader[128];

    Com_sprintf( eshader, sizeof(eshader), "rocketExplosion_%s", getStringFromColor(bccolor) );
    Com_sprintf( sshader, sizeof(sshader), "models/ammo/rocket/rocket_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( gshader, sizeof(gshader), "models/weapons2/rocketl/rocketl_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( fshader, sizeof(fshader), "models/weapons2/rocketl/f_rocketl_%s.skin", getStringFromColor(bccolor) );


    if (team == TEAM_BLUE) {

        cgs.media.rocketExplosionShader_blue = trap_R_RegisterShader(eshader);
        cgs.media.rocketSkin_blue = trap_R_RegisterSkin(sshader);
        cgs.media.rocketgunSkin_blue = trap_R_RegisterSkin(gshader);
        cgs.media.rocketgunFlashSkin_blue = trap_R_RegisterSkin(fshader);

    } else {

        cgs.media.rocketExplosionShader_red = trap_R_RegisterShader(eshader);
        cgs.media.rocketSkin_red = trap_R_RegisterSkin(sshader);
        cgs.media.rocketgunSkin_red = trap_R_RegisterSkin(gshader);
        cgs.media.rocketgunFlashSkin_red = trap_R_RegisterSkin(fshader);

    }
}

void BB_PlasmaTeamEffects(int team, int bccolor) {
    char eshader[128];
    char sshader[128];
    char fshader[128];
    char bshader[128];

    Com_sprintf( eshader, sizeof(eshader), "plasmaExplosion_%s", getStringFromColor(bccolor) );
    Com_sprintf( sshader, sizeof(sshader), "models/weapons2/plasma/plasma_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( fshader, sizeof(fshader), "models/weapons2/plasma/f_plasma_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( bshader, sizeof(bshader), "sprites/plasmaa_%s", getStringFromColor(bccolor) );

    if (team == TEAM_BLUE) {

        cgs.media.plasmaExplosionShader_blue = trap_R_RegisterShader(eshader);
        cgs.media.plasmagunSkin_blue = trap_R_RegisterSkin(sshader);
        cgs.media.plasmaBallShader_blue = trap_R_RegisterShader(bshader);
        cgs.media.plasmagunFlashSkin_blue = trap_R_RegisterSkin(fshader);


    } else {

        cgs.media.plasmaExplosionShader_red = trap_R_RegisterShader(eshader);
        cgs.media.plasmagunSkin_red = trap_R_RegisterSkin(sshader);
        cgs.media.plasmaBallShader_red = trap_R_RegisterShader(bshader);
        cgs.media.plasmagunFlashSkin_red = trap_R_RegisterSkin(fshader);

    }
}

void BB_HGTeamEffects(int team, int bccolor) {
    char sshader[128];


    Com_sprintf( sshader, sizeof(sshader), "models/weapons2/handgr/handgr_%s.skin", getStringFromColor(bccolor) );


    if (team == TEAM_BLUE) {

        cgs.media.handgrenadeSkin_blue = trap_R_RegisterSkin(sshader);

    } else {

        cgs.media.handgrenadeSkin_red = trap_R_RegisterSkin(sshader);

    }


}

void BB_BFGTeamEffects(int team, int bccolor) {
    char eshader[128];
    char sshader[128];
    char fshader[128];
    char bshader[128];

    Com_sprintf( eshader, sizeof(eshader), "bfgExplosion_%s", getStringFromColor(bccolor) );
    Com_sprintf( sshader, sizeof(sshader), "models/weapons2/bfg/bfg_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( fshader, sizeof(fshader), "models/weapons2/bfg/f_bfg_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( bshader, sizeof(bshader), "models/weaphits/bfg_%s.skin", getStringFromColor(bccolor) );

    if (team == TEAM_BLUE) {

        cgs.media.bfgExplosionShader_blue = trap_R_RegisterShader( eshader );
        cgs.media.bfgSkin_blue = trap_R_RegisterSkin(sshader);
        cgs.media.bfgMissleSkin_blue = trap_R_RegisterSkin(bshader);
        cgs.media.bfgFlashSkin_blue = trap_R_RegisterSkin(fshader);

    } else {

        cgs.media.bfgExplosionShader_red = trap_R_RegisterShader( eshader );
        cgs.media.bfgSkin_red = trap_R_RegisterSkin(sshader);
        cgs.media.bfgMissleSkin_red = trap_R_RegisterSkin(bshader);
        cgs.media.bfgFlashSkin_red = trap_R_RegisterSkin(fshader);

    }
}


void BB_FlagBaseTeamEffects(int team, int bccolor) {
    char sshader[128];


    Com_sprintf( sshader, sizeof(sshader), "models/mapobjects/flagbase/base_%s.skin", getStringFromColor(bccolor) );


    if (team == TEAM_BLUE) {

        cgs.media.flagbaseSkin_blue = trap_R_RegisterSkin(sshader);

    } else {

        cgs.media.flagbaseSkin_red = trap_R_RegisterSkin(sshader);

    }


}

void BB_MachineTeamEffects(int team, int bccolor) {
    char eshader[128];
    char sshader[128];
    char fshader[128];
    char bshader[128];

    Com_sprintf( eshader, sizeof(eshader), "bulletExplosion_%s", getStringFromColor(bccolor) );
    Com_sprintf( sshader, sizeof(sshader), "models/weapons2/machinegun/machinegun_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( fshader, sizeof(fshader), "models/weapons2/machinegun/f_machinegun_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( bshader, sizeof(bshader), "gfx/misc/tracer_%s", getStringFromColor(bccolor) );

    if (team == TEAM_BLUE) {

        cgs.media.bulletExplosionShader_blue = trap_R_RegisterShader(eshader);
        cgs.media.machinegunSkin_blue = trap_R_RegisterSkin(sshader);
        cgs.media.bulletSpark_blue = trap_R_RegisterShader(bshader);
        cgs.media.machinegunFlashSkin_blue = trap_R_RegisterSkin(fshader);


    } else {

        cgs.media.bulletExplosionShader_red = trap_R_RegisterShader(eshader);
        cgs.media.machinegunSkin_red = trap_R_RegisterSkin(sshader);
        cgs.media.bulletSpark_red = trap_R_RegisterShader(bshader);
        cgs.media.machinegunFlashSkin_red = trap_R_RegisterSkin(fshader);

    }


}

void BB_ShotTeamEffects(int team, int bccolor) {
    //char eshader[128];
    char sshader[128];
    char fshader[128];
    //char bshader[128];

    //Com_sprintf( eshader, sizeof(eshader), "plasmaExplosion_%s", getStringFromColor(bccolor) );
    Com_sprintf( sshader, sizeof(sshader), "models/weapons2/shotgun/shotgun_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( fshader, sizeof(fshader), "models/weapons2/shotgun/f_shotgun_%s.skin", getStringFromColor(bccolor) );
    //Com_sprintf( bshader, sizeof(bshader), "sprites/plasmaa_%s", getStringFromColor(bccolor) );

    if (team == TEAM_BLUE) {

        //cgs.media.plasmaExplosionShader_blue = trap_R_RegisterShader(eshader);
        cgs.media.shotgunSkin_blue = trap_R_RegisterSkin(sshader);
        //cgs.media.plasmaBallShader_blue = trap_R_RegisterShader(bshader);
        cgs.media.shotgunFlashSkin_blue = trap_R_RegisterSkin(fshader);


    } else {

        //cgs.media.plasmaExplosionShader_red = trap_R_RegisterShader(eshader);
        cgs.media.shotgunSkin_red = trap_R_RegisterSkin(sshader);
        //cgs.media.plasmaBallShader_red = trap_R_RegisterShader(bshader);
        cgs.media.shotgunFlashSkin_red = trap_R_RegisterSkin(fshader);

    }


}


void BB_RailTeamEffects(int team, int bccolor) {
    //char eshader[128];
    char sshader[128];
    char fshader[128];
    //char bshader[128];

    //Com_sprintf( eshader, sizeof(eshader), "plasmaExplosion_%s", getStringFromColor(bccolor) );
    Com_sprintf( sshader, sizeof(sshader), "models/weapons2/railgun/railgun_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( fshader, sizeof(fshader), "models/weapons2/railgun/f_railgun_%s.skin", getStringFromColor(bccolor) );
    //Com_sprintf( bshader, sizeof(bshader), "sprites/plasmaa_%s", getStringFromColor(bccolor) );

    if (team == TEAM_BLUE) {

        //cgs.media.plasmaExplosionShader_blue = trap_R_RegisterShader(eshader);
        cgs.media.railgunSkin_blue = trap_R_RegisterSkin(sshader);
        //cgs.media.plasmaBallShader_blue = trap_R_RegisterShader(bshader);
        cgs.media.railgunFlashSkin_blue = trap_R_RegisterSkin(fshader);


    } else {

        //cgs.media.plasmaExplosionShader_red = trap_R_RegisterShader(eshader);
        cgs.media.railgunSkin_red = trap_R_RegisterSkin(sshader);
        //cgs.media.plasmaBallShader_red = trap_R_RegisterShader(bshader);
        cgs.media.railgunFlashSkin_red = trap_R_RegisterSkin(fshader);

	}


    }
	
void BB_GrenadelTeamEffects(int team, int bccolor) {
    //char eshader[128];
    char sshader[128];
    char fshader[128];
    char bshader[128];

    //Com_sprintf( eshader, sizeof(eshader), "plasmaExplosion_%s", getStringFromColor(bccolor) );
    Com_sprintf( sshader, sizeof(sshader), "models/weapons2/grenadel/grenadel_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( fshader, sizeof(fshader), "models/weapons2/grenadel/f_grenadel_%s.skin", getStringFromColor(bccolor) );
    Com_sprintf( bshader, sizeof(bshader), "models/ammo/grenade_%s.skin", getStringFromColor(bccolor) );

    if (team == TEAM_BLUE) {

        //cgs.media.plasmaExplosionShader_blue = trap_R_RegisterShader(eshader);
        cgs.media.grenadelSkin_blue = trap_R_RegisterSkin(sshader);
        //cgs.media.plasmaBallShader_blue = trap_R_RegisterShader(bshader);
        cgs.media.grenadelFlashSkin_blue = trap_R_RegisterSkin(fshader);
		cgs.media.grenadeSkin_blue = trap_R_RegisterSkin(bshader);


    } else {

        //cgs.media.plasmaExplosionShader_red = trap_R_RegisterShader(eshader);
        cgs.media.grenadelSkin_red = trap_R_RegisterSkin(sshader);
        //cgs.media.plasmaBallShader_red = trap_R_RegisterShader(bshader);
        cgs.media.grenadelFlashSkin_red = trap_R_RegisterSkin(fshader);
		cgs.media.grenadeSkin_red = trap_R_RegisterSkin(bshader);

	}


    }

void BB_RegisterWeaponTeamEffects(void) {

    int team, enemy;

    team = getColorFromString(cg_teamColor.string);
    enemy = getColorFromString(cg_enemyColor.string);

    if (cg_forceColor.integer == 2 ) {

        if (cg.team == TEAM_BLUE) {

            // BB COLORS: team
            BB_FlagBaseTeamEffects(TEAM_BLUE, team);
            BB_RocketTeamEffects(TEAM_BLUE, team);
            BB_HGTeamEffects(TEAM_BLUE, team);
            BB_PlasmaTeamEffects(TEAM_BLUE, team);
            BB_LightningTeamEffects(TEAM_BLUE, team);
            BB_BFGTeamEffects(TEAM_BLUE, team);
            BB_MachineTeamEffects(TEAM_BLUE, team);
            BB_ShotTeamEffects(TEAM_BLUE, team);
			BB_RailTeamEffects(TEAM_BLUE, team);
			BB_GrenadelTeamEffects(TEAM_BLUE, team);

            // BB COLORS: enemy
            BB_FlagBaseTeamEffects(TEAM_RED, enemy);
            BB_RocketTeamEffects(TEAM_RED, enemy);
            BB_HGTeamEffects(TEAM_RED, enemy);
            BB_PlasmaTeamEffects(TEAM_RED, enemy);
            BB_LightningTeamEffects(TEAM_RED, enemy);
            BB_BFGTeamEffects(TEAM_RED, enemy);
            BB_MachineTeamEffects(TEAM_RED, enemy);
            BB_ShotTeamEffects(TEAM_RED, enemy);
			BB_RailTeamEffects(TEAM_RED, enemy);
			BB_GrenadelTeamEffects(TEAM_RED, enemy);

        } else {

            // BB COLORS: team
            BB_FlagBaseTeamEffects(TEAM_RED, team);
            BB_RocketTeamEffects(TEAM_RED, team);
            BB_HGTeamEffects(TEAM_RED, team);
            BB_PlasmaTeamEffects(TEAM_RED, team);
            BB_LightningTeamEffects(TEAM_RED, team);
            BB_BFGTeamEffects(TEAM_RED, team);
            BB_MachineTeamEffects(TEAM_RED, team);
            BB_ShotTeamEffects(TEAM_RED, team);
			BB_RailTeamEffects(TEAM_RED, team);
			BB_GrenadelTeamEffects(TEAM_RED, team);

            // BB COLORS: enemy
            BB_FlagBaseTeamEffects(TEAM_BLUE, enemy);
            BB_RocketTeamEffects(TEAM_BLUE, enemy);
            BB_HGTeamEffects(TEAM_BLUE, enemy);
            BB_PlasmaTeamEffects(TEAM_BLUE, enemy);
            BB_LightningTeamEffects(TEAM_BLUE, enemy);
            BB_BFGTeamEffects(TEAM_BLUE, enemy);
            BB_MachineTeamEffects(TEAM_BLUE, enemy);
            BB_ShotTeamEffects(TEAM_BLUE, enemy);
			BB_RailTeamEffects(TEAM_BLUE, enemy);
			BB_GrenadelTeamEffects(TEAM_BLUE, enemy);

        }

    } else {

        // BB COLORS: blue
        BB_FlagBaseTeamEffects(TEAM_BLUE, BC_BLUE);
        BB_RocketTeamEffects(TEAM_BLUE, BC_BLUE);
        BB_HGTeamEffects(TEAM_BLUE, BC_BLUE);
        BB_PlasmaTeamEffects(TEAM_BLUE, BC_BLUE);
        BB_LightningTeamEffects(TEAM_BLUE, BC_BLUE);
        BB_BFGTeamEffects(TEAM_BLUE, BC_BLUE);
        BB_MachineTeamEffects(TEAM_BLUE, BC_BLUE);
        BB_ShotTeamEffects(TEAM_BLUE, BC_BLUE);
		BB_RailTeamEffects(TEAM_BLUE, BC_BLUE);
		BB_GrenadelTeamEffects(TEAM_BLUE, BC_BLUE);

        // BB COLORS: red
        BB_FlagBaseTeamEffects(TEAM_RED, BC_RED);
        BB_RocketTeamEffects(TEAM_RED, BC_RED);
        BB_HGTeamEffects(TEAM_RED, BC_RED);
        BB_PlasmaTeamEffects(TEAM_RED, BC_RED);
        BB_LightningTeamEffects(TEAM_RED, BC_RED);
        BB_BFGTeamEffects(TEAM_RED, BC_RED);
        BB_MachineTeamEffects(TEAM_RED, BC_RED);
        BB_ShotTeamEffects(TEAM_RED, BC_RED);
		BB_RailTeamEffects(TEAM_RED, BC_RED);
		BB_GrenadelTeamEffects(TEAM_RED, BC_RED);

    }

}

void GetTeamColorsVEC3(vec3_t in, vec3_t out, int team) {

    int teamcolor, enemycolor;
    //vec3_t color;

    VectorCopy(in, out);

    teamcolor = getColorFromString(cg_teamColor.string);
    enemycolor = getColorFromString(cg_enemyColor.string);

    if (cg_forceColor.integer == 2) {

        if (team == TEAM_BLUE) {

            if (cg.team == TEAM_BLUE) {

                if (teamcolor == BC_BLUE) {
                    out[0] = 0;
                    out[1] = 0;
                    out[2] = 1;
                } else if (teamcolor == BC_RED) {
                    out[0] = 1;
                    out[1] = 0;
                    out[2] = 0;
                } else if (teamcolor == BC_GREEN) {
                    out[0] = 0;
                    out[1] = 1;
                    out[2] = 0;
                    //CG_Printf("GetTeamColorsVEC3\n");
                }
                else if (teamcolor == BC_YELLOW) {
                    out[0] = 1;
                    out[1] = 1;
                    out[2] = 0;
                } else if (teamcolor == BC_ORANGE) {
                    out[0] = 1;
                    out[1] = 0.43f;
                    out[2] = 0;

                } else if (teamcolor == BC_PINK) {
                    out[0] = 1;
                    out[1] = 0;
                    out[2] = 1;
                } else if (teamcolor == BC_AQUA) {
                    out[0] = 0;
                    out[1] = 1;
                    out[2] = 1;
                } else if (teamcolor == BC_WHITE) {
                    out[0] = 1;
                    out[1] = 1;
                    out[2] = 1;
                } else if (teamcolor == BC_BLACK) {
                    out[0] = 0.25f;
                    out[1] = 0.25f;
                    out[2] = 0.25f;
                }
            } else {

                if (enemycolor == BC_BLUE) {
                    out[0] = 0;
                    out[1] = 0;
                    out[2] = 1;
                } else if (enemycolor == BC_RED) {
                    out[0] = 1;
                    out[1] = 0;
                    out[2] = 0;
                } else if (enemycolor == BC_GREEN) {
                    out[0] = 0;
                    out[1] = 1;
                    out[2] = 0;
                } else if (enemycolor == BC_YELLOW) {
                    out[0] = 1;
                    out[1] = 1;
                    out[2] = 0;
                } else if (enemycolor == BC_ORANGE) {
                    out[0] = 1;
                    out[1] = 0.43f;
                    out[2] = 0;
                } else if (enemycolor == BC_PINK) {
                    out[0] = 1;
                    out[1] = 0;
                    out[2] = 1;
                } else if (enemycolor == BC_AQUA) {
                    out[0] = 0;
                    out[1] = 1;
                    out[2] = 1;
                } else if (enemycolor == BC_WHITE) {
                    out[0] = 1;
                    out[1] = 1;
                    out[2] = 1;
                } else if (enemycolor == BC_BLACK) {
                    out[0] = 0.25f;
                    out[1] = 0.25f;
                    out[2] = 0.25f;
                }
            }
        } else {

            if (cg.team == TEAM_BLUE) {

                if (enemycolor == BC_BLUE) {
                    out[0] = 0;
                    out[1] = 0;
                    out[2] = 1;
                } else if (enemycolor == BC_RED) {
                    out[0] = 1;
                    out[1] = 0;
                    out[2] = 0;
                } else if (enemycolor == BC_GREEN) {
                    out[0] = 0;
                    out[1] = 1;
                    out[2] = 0;
                } else if (enemycolor == BC_YELLOW) {
                    out[0] = 1;
                    out[1] = 1;
                    out[2] = 0;
                } else if (enemycolor == BC_ORANGE) {
                    out[0] = 1;
                    out[1] = 0.43f;
                    out[2] = 0;
                } else if (enemycolor == BC_PINK) {
                    out[0] = 1;
                    out[1] = 0;
                    out[2] = 1;
                } else if (enemycolor == BC_AQUA) {
                    out[0] = 0;
                    out[1] = 1;
                    out[2] = 1;
                } else if (enemycolor == BC_WHITE) {
                    out[0] = 1;
                    out[1] = 1;
                    out[2] = 1;
                } else if (enemycolor == BC_BLACK) {
                    out[0] = 0.25f;
                    out[1] = 0.25f;
                    out[2] = 0.25f;
                }
            } else {

                if (teamcolor == BC_BLUE) {
                    out[0] = 0;
                    out[1] = 0;
                    out[2] = 1;
                } else if (teamcolor == BC_RED) {
                    out[0] = 1;
                    out[1] = 0;
                    out[2] = 0;
                } else if (teamcolor == BC_GREEN) {
                    out[0] = 0;
                    out[1] = 1;
                    out[2] = 0;
                } else if (teamcolor == BC_YELLOW) {
                    out[0] = 1;
                    out[1] = 1;
                    out[2] = 0;
                } else if (teamcolor == BC_ORANGE) {
                    out[0] = 1;
                    out[1] = 0.43f;
                    out[2] = 0;
                } else if (teamcolor == BC_PINK) {
                    out[0] = 1;
                    out[1] = 0;
                    out[2] = 1;
                } else if (teamcolor == BC_AQUA) {
                    out[0] = 0;
                    out[1] = 1;
                    out[2] = 1;
                } else if (teamcolor == BC_WHITE) {
                    out[0] = 1;
                    out[1] = 1;
                    out[2] = 1;
                } else if (teamcolor == BC_BLACK) {
                    out[0] = 0.25f;
                    out[1] = 0.25f;
                    out[2] = 0.25f;
                }
            }
        }
    } else {

		if (team == TEAM_BLUE) {
            out[0] = 0;
            out[1] = 0;
            out[2] = 1;
        } else {
            out[0] = 1;
            out[1] = 0;
            out[2] = 0;
        }
    }
}
