// Copyright (C) 1999-2000 Id Software, Inc.
//
/*
=======================================================================
 
INGAME MENU
 
=======================================================================
*/


/*
The work contained within this file is software written by various
copyright holders.  The initial contributor, Id Software holds all
copyright over their software.  However, software used and written by
and for UI Enhanced has copyrights held by the initial author of the
software.
 
The changes written by and for UI Enhanced are contained alongside the
original work from Id Software for convenience and ease of interoperability.
 
For the code contained herein that was written by Id Software, see
the license agreement on their original archive for restrictions and
limitations.
 
The UI Enhanced copyright owner permit free reuse of his code contained
herein, as long as the following terms are met:
 
----------------------------------------------------------------------
1) Credit is given in a place where users of the mod may read
   it. (Title screen, credit screen or README will do).  The
   recommended format is: "First, Last, alias, email"
 
2) There are no attempts to misrepresent the public as to who made the
   alterations.  The UI Enhanced copyright owner does not give permission
   for others to release software under the UI Enhanced name.
----------------------------------------------------------------------
 
Ian Jefferies   - HypoThermia ( uie@planetquake.com )
http://www.planetquake.com/uie
*/


#include "../q3_ui/q3ui_local.h"
#include "ui_dynamicmenu.h"
//#include "ui_modelist.h"


//#define INGAME_FRAME_TOP		"menu/art/ingamebgtop"
//#define INGAME_FRAME			"menu/art/ingamebg"
//#define	INGAME_FRAME_BOTTOM		"menu/art/ingamebgbot"

#define INGAME_SCROLL			"menu/art/separator"
//#define INGAME_FRAME					"menu/art/cut_frame"
#define INGAME_MENU_VERTICAL_SPACING	26

#define MAX_INGAME_SCROLLS 		6
#define SCROLL_HEIGHT			16

#define ID_TEAM					10
#define ID_ADDBOTS				11
#define ID_REMOVEBOTS			12
#define ID_SETUP				13
#define ID_SERVERINFO			14
#define ID_LEAVEARENA			15
#define ID_RESTART				16
#define ID_QUIT					17
#define ID_RESUME				18
#define ID_TEAMORDERS			19
#define ID_NEXTMAP				20
#define ID_ENABLEDITEMS			21
#define ID_CAMERACMDS			22
#define ID_FORCECOLOR			23
#define ID_SOUNDCMDS			24
#define ID_UNLAGGED				25
#define ID_PLAYERMODELS			26

static void IG_Camera_Commands_Submenu(void);
static void IG_Camera_Event( int index);
static void IG_ForceColor_Event(int index);
static void IG_EnemyColor_Event(int index);
static void IG_TeamColor_Event(int index);
static void Submenu_Team_Color_Choices(void);
static void Submenu_Enemy_Color_Choices(void);
static void DrawBG(void);


typedef struct {
    menuframework_s	menu;
    /*
    	menubitmap_s	frametop;
        menubitmap_s	frame;
    	menubitmap_s	framebot;
    */
    menutext_s		team;
    menutext_s		setup;
    menutext_s		server;
    menutext_s		leave;
    menutext_s		restart;
    menutext_s		addbots;
    menutext_s		removebots;
    menutext_s		teamorders;
    menutext_s		quit;
    menutext_s		resume;
    menutext_s		nextmap;
    menutext_s		enableditems;
    menutext_s		cameracmds;		//INCIN --- ZCAM camera commands menu
    menutext_s		soundcmds;		//INCIN -- added client sound commands, team audio etc.
    menutext_s		colorsoptions;
    menutext_s		unlagged;
	menutext_s		playermodels;

    int num_scrolls;
    int scroll_y[MAX_INGAME_SCROLLS];
}
ingamemenu_t;

static ingamemenu_t	s_ingame;

extern char *q3a_model_list[];
/*
static char *q3a_model_list[] = {"Anarki", "Biker", "Bitterman",
	"Bones","Crash", "Doom", "Grunt",
	"Hunter", "Keel", "Klesk", "Lucy", 
	"Mynx", "Orbb" , "Ranger", "Razor", 
	"Sarge", "Slash", "Sorlag", "Tankjr",
	"Uriel", "Visor", "Xaero"
};
*/
/*
typedef struct {
    menutext_s red;
    menutext_s blue;
    menutext_s green;
    menutext_s yellow;
    menutext_s orange;
    menutext_s aqua;
    menutext_s pink;
    menutext_s white;
    menutext_s black;
}
coloredmenus_t;
static coloredmenus_t ingamecolors;
*/

/*
=================
UI_CurrentPlayerTeam
=================
*/
int UI_CurrentPlayerTeam( void ) {
    static uiClientState_t	cs;
    static char	info[MAX_INFO_STRING];

    trap_GetClientState( &cs );
    trap_GetConfigString( CS_PLAYERS + cs.clientNum, info, MAX_INFO_STRING );
    return atoi(Info_ValueForKey(info, "t"));
}



/*
=================
InGame_RestartAction
=================
*/
static void InGame_RestartAction( qboolean result ) {
    if( !result ) {
        return;
    }

    UI_ForceMenuOff();
    trap_Cmd_ExecuteText( EXEC_APPEND, "map_restart 0\n" );
}


/*
=================
InGame_QuitAction
=================
*/
static void InGame_QuitAction( qboolean result ) {
    if( !result ) {
        return;
    }
    UI_ForceMenuOff();
    UI_CreditMenu();
}


/*
=================
InGame_NextMap
=================
*/
static void InGame_NextMap( qboolean result ) {
    int gametype;
    char	info[MAX_INFO_STRING];
    int i;
    int numPlayers;

    if( !result ) {
        return;
    }
    UI_ForceMenuOff();

    gametype = DynamicMenu_ServerGametype();
    if (gametype == GT_TOURNAMENT) {
        trap_Cmd_ExecuteText( EXEC_INSERT, "set activeAction \"");

        trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) );
        numPlayers = atoi( Info_ValueForKey( info, "sv_maxclients" ) );

        // try and move all bots to spectator mode
        for( i = 0; i < numPlayers; i++ ) {
            trap_GetConfigString( CS_PLAYERS + i, info, MAX_INFO_STRING );

            if (!atoi( Info_ValueForKey( info, "skill" ) ))
                continue;

            trap_Cmd_ExecuteText( EXEC_INSERT, va("forceteam %i spectator;", i));
        }
        trap_Cmd_ExecuteText( EXEC_INSERT, "\"\n");
    }
    trap_Cmd_ExecuteText( EXEC_APPEND, "vstr nextmap\n");
}



/*
=================
InGame_EventHandler
 
May be used by dynamic menu system also
=================
*/
// bk001205 - for LCC
//typedef void (*voidfunc_f)(void);
static void IG_SoundCmds_MenuInit(void);
static void IG_PlayerModels_MenuInit(void);

static void InGame_EventHandler(int id) {
    switch( id ) {
    case ID_TEAM:
        UI_TeamMainMenu();
        break;

    case ID_SETUP:
        UI_SetupMenu();
        break;

    case ID_LEAVEARENA:
        trap_Cmd_ExecuteText( EXEC_APPEND, "disconnect\n" );
#ifdef MISSIONPACK
		trap_Cvar_Set( "fs_game", "newexpertta");
#else
		trap_Cvar_Set( "fs_game", "newexpert");
#endif
        break;

    case ID_RESTART:
        UI_ConfirmMenu( "RESTART ARENA?", (voidfunc_f)0, InGame_RestartAction );
        break;

    case ID_QUIT:
        UI_ConfirmMenu( "EXIT GAME?", (voidfunc_f)0, InGame_QuitAction );
        break;

    case ID_SERVERINFO:
        UI_ServerInfoMenu();
        break;

    case ID_ADDBOTS:
        //UI_AddBotsMenu();
        break;

    case ID_REMOVEBOTS:
        //UI_RemoveBotsMenu(RBM_KICKBOT);
        break;

    case ID_TEAMORDERS:
        UI_BotCommandMenu_f();
        break;

    case ID_RESUME:
        UI_ForceMenuOff();
        break;

    case ID_NEXTMAP:
        UI_ConfirmMenu( "NEXT MAP?", (voidfunc_f)0, InGame_NextMap);
        break;

    case ID_ENABLEDITEMS:
        UIE_InGame_EnabledItems();
        break;

    case ID_CAMERACMDS:
        IG_Camera_Event(id);
        break;

    case ID_FORCECOLOR:
        IG_ForceColor_Event(id);
        break;

    case ID_SOUNDCMDS:
        IG_SoundCmds_MenuInit();
        break;

	case ID_PLAYERMODELS:
		IG_PlayerModels_MenuInit();
    default:

        break;
    }

}




/*
=================
InGame_Event
=================
*/
static void InGame_Event( void *ptr, int notification ) {
    if( notification != QM_ACTIVATED ) {
        return;
    }

    InGame_EventHandler(((menucommon_s*)ptr)->id );
}



/*
=================
InGame_MenuDraw
=================
*/
static void InGame_MenuDraw(void) {
    int i;

    for (i = 0; i < s_ingame.num_scrolls; i++) {
        UI_DrawNamedPic(320 - 64, s_ingame.scroll_y[i],  128, SCROLL_HEIGHT, INGAME_SCROLL);
    }

    // draw the controls
    Menu_Draw(&s_ingame.menu);
}


/*
=================
InGame_MenuInit
=================
*/
void InGame_MenuInit( void ) {
    int		y;
    int gametype;
    memset( &s_ingame, 0 ,sizeof(ingamemenu_t) );

    InGame_Cache();

    gametype = DynamicMenu_ServerGametype();
    s_ingame.menu.wrapAround = qtrue;
    s_ingame.menu.fullscreen = qfalse;
    s_ingame.menu.draw = InGame_MenuDraw;
    
	y = 30;
    s_ingame.team.generic.type			= MTYPE_PTEXT;
    s_ingame.team.generic.flags			= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.team.generic.x				= 320;
    s_ingame.team.generic.y				= y;
    s_ingame.team.generic.id			= ID_TEAM;
    s_ingame.team.generic.callback		= InGame_Event;
    s_ingame.team.string				= "START";
    s_ingame.team.color					= color_green;
    s_ingame.team.style					= UI_CENTER|UI_SMALLFONT;


    //INCIN -- zcam menu integration
    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.cameracmds.generic.type	= MTYPE_PTEXT;
    s_ingame.cameracmds.generic.flags	= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.cameracmds.generic.x		= 320;
    s_ingame.cameracmds.generic.y		= y;
    s_ingame.cameracmds.generic.id		= ID_CAMERACMDS;
    s_ingame.cameracmds.generic.callback= InGame_Event;
    s_ingame.cameracmds.string			= "CAMERA";
    s_ingame.cameracmds.color			= color_green;
    s_ingame.cameracmds.style			= UI_CENTER|UI_SMALLFONT;
    //INCIN -- zcam menu integration



    //INCIN -- sound file integration
    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.soundcmds.generic.type	= MTYPE_PTEXT;
    s_ingame.soundcmds.generic.flags	= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.soundcmds.generic.x		= 320;
    s_ingame.soundcmds.generic.y		= y;
    s_ingame.soundcmds.generic.id		= ID_SOUNDCMDS;
    s_ingame.soundcmds.generic.callback= InGame_Event;
    s_ingame.soundcmds.string			= "SOUNDS";
    s_ingame.soundcmds.color			= color_green;
    s_ingame.soundcmds.style			= UI_CENTER|UI_SMALLFONT;
    //INCIN -- sound file integration

	y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.playermodels.generic.type		= MTYPE_PTEXT;
    s_ingame.playermodels.generic.flags	= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.playermodels.generic.x		= 320;
    s_ingame.playermodels.generic.y		= y;
    s_ingame.playermodels.generic.id		= ID_PLAYERMODELS;
    s_ingame.playermodels.generic.callback	= InGame_Event;
    s_ingame.playermodels.string			= "MODELS";
    s_ingame.playermodels.color			= color_green;
    s_ingame.playermodels.style			= UI_CENTER|UI_SMALLFONT;
	
    //INCIN --/cg_forcecolor settings
    if(gametype >= GT_TEAM) {
        y += INGAME_MENU_VERTICAL_SPACING;
        s_ingame.colorsoptions.generic.type		= MTYPE_PTEXT;
        s_ingame.colorsoptions.generic.flags	= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
        s_ingame.colorsoptions.generic.x		= 320;
        s_ingame.colorsoptions.generic.y		= y;
        s_ingame.colorsoptions.generic.id		= ID_FORCECOLOR;
        s_ingame.colorsoptions.generic.callback	= InGame_Event;
        s_ingame.colorsoptions.string			= "TEAM COLORS";
        s_ingame.colorsoptions.color			= color_green;
        s_ingame.colorsoptions.style			= UI_CENTER|UI_SMALLFONT;
    }

    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.unlagged.generic.type			= MTYPE_PTEXT;
    s_ingame.unlagged.generic.flags			= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.unlagged.generic.x				= 320;
    s_ingame.unlagged.generic.y				= y;
    s_ingame.unlagged.generic.id			= ID_UNLAGGED;
    s_ingame.unlagged.generic.callback		= InGame_Event;
    s_ingame.unlagged.string				= "UNLAGGED";
    s_ingame.unlagged.color					= color_green;
    s_ingame.unlagged.style					= UI_CENTER|UI_SMALLFONT;

    /*
    y += INGAME_MENU_VERTICAL_SPACING;
       s_ingame.addbots.generic.type		= MTYPE_PTEXT;
       s_ingame.addbots.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
       s_ingame.addbots.generic.x			= 320;
       s_ingame.addbots.generic.y			= y;
       s_ingame.addbots.generic.id			= ID_ADDBOTS;
       s_ingame.addbots.generic.callback	= InGame_Event;
       s_ingame.addbots.string				= "ADD BOTS";
       s_ingame.addbots.color				= color_green;
       s_ingame.addbots.style				= UI_CENTER|UI_SMALLFONT;
       if( !trap_Cvar_VariableValue( "sv_running" ) || !trap_Cvar_VariableValue( "bot_enable" ) || (gametype == GT_SINGLE_PLAYER)) {
           s_ingame.addbots.generic.flags |= QMF_GRAYED;
       }

       y += INGAME_MENU_VERTICAL_SPACING;
       s_ingame.removebots.generic.type		= MTYPE_PTEXT;
       s_ingame.removebots.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
       s_ingame.removebots.generic.x			= 320;
       s_ingame.removebots.generic.y			= y;
       s_ingame.removebots.generic.id			= ID_REMOVEBOTS;
       s_ingame.removebots.generic.callback	= InGame_Event;
       s_ingame.removebots.string				= "REMOVE BOTS";
       s_ingame.removebots.color				= color_green;
       s_ingame.removebots.style				= UI_CENTER|UI_SMALLFONT;
       if( !trap_Cvar_VariableValue( "sv_running" ) || !trap_Cvar_VariableValue( "bot_enable" ) || (gametype == GT_SINGLE_PLAYER)) {
           s_ingame.removebots.generic.flags |= QMF_GRAYED;
       }

    */
    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.teamorders.generic.type		= MTYPE_PTEXT;
    s_ingame.teamorders.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.teamorders.generic.x			= 320;
    s_ingame.teamorders.generic.y			= y;
    s_ingame.teamorders.generic.id			= ID_TEAMORDERS;
    s_ingame.teamorders.generic.callback	= InGame_Event;
    s_ingame.teamorders.string				= "TEAM ORDERS";
    s_ingame.teamorders.color				= color_green;
    s_ingame.teamorders.style				= UI_CENTER|UI_SMALLFONT;
    if( !(gametype >= GT_TEAM) ) {
        s_ingame.teamorders.generic.flags |= QMF_GRAYED;
    } else if( UI_CurrentPlayerTeam() == TEAM_SPECTATOR		||
               UI_CurrentPlayerTeam() == TEAM_SPECTATOR_RED ||
               UI_CurrentPlayerTeam() == TEAM_SPECTATOR_BLUE ) {
        s_ingame.teamorders.generic.flags |= QMF_GRAYED;
    }

    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.scroll_y[ s_ingame.num_scrolls++ ] = y;

    y += SCROLL_HEIGHT + 2;
    s_ingame.setup.generic.type			= MTYPE_PTEXT;
    s_ingame.setup.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.setup.generic.x			= 320;
    s_ingame.setup.generic.y			= y;
    s_ingame.setup.generic.id			= ID_SETUP;
    s_ingame.setup.generic.callback		= InGame_Event;
    s_ingame.setup.string				= "SETUP";
    s_ingame.setup.color				= color_green;
    s_ingame.setup.style				= UI_CENTER|UI_SMALLFONT;

    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.server.generic.type		= MTYPE_PTEXT;
    s_ingame.server.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.server.generic.x			= 320;
    s_ingame.server.generic.y			= y;
    s_ingame.server.generic.id			= ID_SERVERINFO;
    s_ingame.server.generic.callback	= InGame_Event;
    s_ingame.server.string				= "SERVER INFO";
    s_ingame.server.color				= color_green;
    s_ingame.server.style				= UI_CENTER|UI_SMALLFONT;

    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.scroll_y[ s_ingame.num_scrolls++ ] = y;

    y += SCROLL_HEIGHT + 2;
    s_ingame.enableditems.generic.type			= MTYPE_PTEXT;
    s_ingame.enableditems.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.enableditems.generic.x			= 320;
    s_ingame.enableditems.generic.y			= y;
    s_ingame.enableditems.generic.id			= ID_ENABLEDITEMS;
    s_ingame.enableditems.generic.callback		= InGame_Event;
    s_ingame.enableditems.string				= "DISABLE ITEMS";
    s_ingame.enableditems.color				= color_green;
    s_ingame.enableditems.style				= UI_CENTER|UI_SMALLFONT;
    if( !trap_Cvar_VariableValue( "sv_running" ) || gametype == GT_SINGLE_PLAYER) {
        s_ingame.enableditems.generic.flags |= QMF_GRAYED;
    }

    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.restart.generic.type		= MTYPE_PTEXT;
    s_ingame.restart.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.restart.generic.x			= 320;
    s_ingame.restart.generic.y			= y;
    s_ingame.restart.generic.id			= ID_RESTART;
    s_ingame.restart.generic.callback	= InGame_Event;
    s_ingame.restart.string				= "RESTART ARENA";
    s_ingame.restart.color				= color_green;
    s_ingame.restart.style				= UI_CENTER|UI_SMALLFONT;
    if( !trap_Cvar_VariableValue( "sv_running" ) ) {
        s_ingame.restart.generic.flags |= QMF_GRAYED;
    }

    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.nextmap.generic.type		= MTYPE_PTEXT;
    s_ingame.nextmap.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.nextmap.generic.x			= 320;
    s_ingame.nextmap.generic.y			= y;
    s_ingame.nextmap.generic.id			= ID_NEXTMAP;
    s_ingame.nextmap.generic.callback	= InGame_Event;
    s_ingame.nextmap.string				= "NEXT MAP";
    s_ingame.nextmap.color				= color_green;
    s_ingame.nextmap.style				= UI_CENTER|UI_SMALLFONT;
    if( !trap_Cvar_VariableValue( "sv_running" ) ) {
        s_ingame.nextmap.generic.flags |= QMF_GRAYED;
    }
    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.resume.generic.type			= MTYPE_PTEXT;
    s_ingame.resume.generic.flags			= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.resume.generic.x				= 320;
    s_ingame.resume.generic.y				= y;
    s_ingame.resume.generic.id				= ID_RESUME;
    s_ingame.resume.generic.callback		= InGame_Event;
    s_ingame.resume.string					= "RESUME GAME";
    s_ingame.resume.color					= color_green;
    s_ingame.resume.style					= UI_CENTER|UI_SMALLFONT;

    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.scroll_y[ s_ingame.num_scrolls++ ] = y;

    y += SCROLL_HEIGHT + 2;
    s_ingame.leave.generic.type			= MTYPE_PTEXT;
    s_ingame.leave.generic.flags		= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.leave.generic.x			= 320;
    s_ingame.leave.generic.y			= y;
    s_ingame.leave.generic.id			= ID_LEAVEARENA;
    s_ingame.leave.generic.callback		= InGame_Event;
    s_ingame.leave.string				= "LEAVE ARENA";
    s_ingame.leave.color				= color_green;
    s_ingame.leave.style				= UI_CENTER|UI_SMALLFONT;

    y += INGAME_MENU_VERTICAL_SPACING;
    s_ingame.quit.generic.type			= MTYPE_PTEXT;
    s_ingame.quit.generic.flags			= QMF_CENTER_JUSTIFY|QMF_PULSEIFFOCUS;
    s_ingame.quit.generic.x				= 320;
    s_ingame.quit.generic.y				= y;
    s_ingame.quit.generic.id			= ID_QUIT;
    s_ingame.quit.generic.callback		= InGame_Event;
    s_ingame.quit.string				= "EXIT GAME";
    s_ingame.quit.color					= color_green;
    s_ingame.quit.style					= UI_CENTER|UI_SMALLFONT;
    /*
    	Menu_AddItem( &s_ingame.menu, &s_ingame.frametop );
        Menu_AddItem( &s_ingame.menu, &s_ingame.frame );
    	Menu_AddItem( &s_ingame.menu, &s_ingame.framebot );
    */
    Menu_AddItem( &s_ingame.menu, &s_ingame.team );
    Menu_AddItem( &s_ingame.menu, &s_ingame.cameracmds);//INCIN -- added ZCAM menuitem
	Menu_AddItem( &s_ingame.menu, &s_ingame.playermodels);
    if(gametype >= GT_TEAM) {
        Menu_AddItem( &s_ingame.menu, &s_ingame.colorsoptions);//INCIN -- added cg_forcolor menuitem
        Menu_AddItem( &s_ingame.menu, &s_ingame.soundcmds );
    }
    Menu_AddItem( &s_ingame.menu, &s_ingame.unlagged );
    //Menu_AddItem( &s_ingame.menu, &s_ingame.addbots );
    //Menu_AddItem( &s_ingame.menu, &s_ingame.removebots );
    Menu_AddItem( &s_ingame.menu, &s_ingame.teamorders );
    Menu_AddItem( &s_ingame.menu, &s_ingame.setup );
    Menu_AddItem( &s_ingame.menu, &s_ingame.server );
    Menu_AddItem( &s_ingame.menu, &s_ingame.enableditems );
    Menu_AddItem( &s_ingame.menu, &s_ingame.restart );
    Menu_AddItem( &s_ingame.menu, &s_ingame.nextmap );
    Menu_AddItem( &s_ingame.menu, &s_ingame.resume );
    Menu_AddItem( &s_ingame.menu, &s_ingame.leave );
    Menu_AddItem( &s_ingame.menu, &s_ingame.quit );
}


/*
=================
InGame_Cache
=================
*/
void InGame_Cache( void ) {
    trap_R_RegisterShaderNoMip( INGAME_FRAME_TOP );//INCIN ADDED
    trap_R_RegisterShaderNoMip( INGAME_FRAME );
    trap_R_RegisterShaderNoMip( INGAME_FRAME_BOTTOM );//INCIN ADDED
    trap_R_RegisterShaderNoMip( INGAME_FRAME_SINGLE );//INCIN ADDED
}



/*
=======================================================================
 
INGAME ESCAPE MENU, USING DYNAMIC MENU SYSTEM
 
=======================================================================
*/


typedef struct {
    int 	gametype;
    char* 	menu;
}
gametypeMenu;



static gametypeMenu gametypeMenu_data[] = {
            { GT_FFA, "DeathMatch"},
            { GT_TOURNAMENT, "Tournament"},
            { GT_TEAM, "Team DM"},
            { GT_CTF, "CTF"},
            { GT_RTF, "RTF"}
#ifdef MISSIONPACK
			,//incin added
			{ GT_1FCTF, "One Flag CTF" },
			{ GT_OBELISK, "Overload" },
			{ GT_HARVESTER, "Harvester"}
#endif
        };


static int gametypeMenu_size = sizeof(gametypeMenu_data)/sizeof(gametypeMenu_data[0]);



// main dynamic in game menu
enum {
    IGM_CLOSE,
    IGM_START,
    IGM_CAMERA, //INCIN zcam addin
    IGM_COLORS, //INCIN added for cgforcecolor options
    IGM_SOUNDS,	//INCIN client sound commands
	IGM_PLAYERMODELS,
    IGM_UNLAGGED,	//INCIN --Unlagged UI support commandlines --  fresh!!!
    IGM_BOTS,
    IGM_TEAMORDERS,
    IGM_SETUP,
    IGM_MAP,
    IGM_VOTE,
    IGM_CALLVOTE,
    IGM_EXIT
};



// callvote misc options
enum {
    CVM_NEXTMAP,
    CVM_MAPRESTART
};


// callvote options
enum {
    IGCV_KICK,
    IGCV_MAP,
    IGCV_LEADER,
    IGCV_GAMETYPE,
    IGCV_MISC
};


// vote options
enum {
    IGV_YES,
    IGV_NO,
    IGV_TEAMYES,
    IGV_TEAMNO
};


// setup options
enum {
    IGS_PLAYER,
    IGS_MODEL,
    IGS_CONTROLS,
    IGS_OPTIONS,
    IGS_GRAPHICS,
    IGS_DISPLAY,
    IGS_SOUND,
    IGS_NETWORK,
    IGS_SKIRMISH
};


// join team options
enum {
    DM_START_SPECTATOR,
    DM_START_GAME,
    DM_START_RED,
    DM_START_BLUE,
    DM_START_AUTO,
    DM_START_SPECTATOR_RED,
    DM_START_SPECTATOR_BLUE,
    DM_START_FOLLOW1,
    DM_START_FOLLOW2,
    DM_START_FOLLOW_NAMED,
    DM_START_MAX
};
/*INCIN -- ZCAM enumerated menuitems*/
enum{
    CAMERANEXT,
    CAMERAPREV,
    CAMERAFLIC,
    CAMERASWING,
    CAMERAOFF,
    CAMERAON
};

static char* jointeam_cmd[DM_START_MAX] = {
            "spectator",	// DM_START_SPECTATOR
            "free",			// DM_START_GAME
            "red",			// DM_START_RED
            "blue",			// DM_START_BLUE
            "auto",			// DM_START_AUTO
            "",				//observe red
            "",				//observe blue
            "follow1",		// DM_START_FOLLOW1
            "follow2"		// DM_START_FOLLOW2
        };

enum
{
    COLOR0,
    COLOR1,
    COLOR2,
    COLOR3,
    COLOR4,
    COLOR5,
    COLOR6,
    COLOR7,
    COLOR8,
    COLOR9,
    COLOR10,
    COLOR11
};

enum
{
	MODEL1,
	MODEL2,
	MODEL3,
	MODEL4,
	MODEL5,
	MODEL6
};

/*
=================
InGameDynamic_Close
=================
*/
static void InGameDynamic_Close( void ) {
    //	UI_PopMenu();
}





/*
=================
IG_FragLimit_Event
=================
*/
static void IG_FragLimit_Event( int index ) {
    int id;

    id = DynamicMenu_IdAtIndex(index);
    UI_ForceMenuOff();

    trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote fraglimit %i\n",id));
}


/*
=================
IG_TimeLimit_Event
=================
*/
static void IG_TimeLimit_Event( int index ) {
    int id;

    id = DynamicMenu_IdAtIndex(index);
    UI_ForceMenuOff();

    trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote timelimit %i\n",id));
}



/*
=================
IG_DoWarmup_Event
=================
*/
static void IG_DoWarmup_Event( int index ) {
    int id;

    id = DynamicMenu_IdAtIndex(index);
    UI_ForceMenuOff();

    trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote g_doWarmup %i\n",id));
}



/*
=================
IG_UseOldInGame_Event
=================
*/
static void IG_UseOldInGame_Event( int index ) {
    int id;
    //	char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();

    switch (id) {
    case ID_ADDBOTS:
    case ID_REMOVEBOTS:
    case ID_RESTART:
    case ID_LEAVEARENA:
    case ID_QUIT:
    case ID_ENABLEDITEMS:
    case ID_NEXTMAP:
        break;
    default:
        Com_Printf("IG_UseOldInGame_Event: unknown id (%i)", id);
        return;
    }

    InGame_EventHandler(id);
}




/*
=================
IG_Setup_Event
=================
*/
static void IG_Setup_Event( int index ) {
    int id;
    //	char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();

    switch (id) {
    case IGS_PLAYER:
        UI_PlayerSettingsMenu();
        break;
    case IGS_MODEL:
        UI_PlayerModelMenu();
        break;
    case IGS_CONTROLS:
        UI_ControlsMenu();
        break;
    case IGS_OPTIONS:
        UI_PreferencesMenu();
        break;
    case IGS_GRAPHICS:
        UI_GraphicsOptionsMenu();
        break;
    case IGS_DISPLAY:
        UI_DisplayOptionsMenu();
        break;
    case IGS_SOUND:
        UI_SoundOptionsMenu();
        break;
    case IGS_NETWORK:
        UI_NetworkOptionsMenu();
        break;
    case IGS_SKIRMISH:
        UI_StartServerMenu(qfalse);
        break;
    default:
        Com_Printf("IG_Setup_Event: unknown id (%i)", id);
        return;
    }
}




/*
=================
IG_CallVoteGameType_Event
=================
*/
static void IG_CallVoteGameType_Event( int index ) {
    int id;

    id = DynamicMenu_IdAtIndex(index);
    UI_ForceMenuOff();

    switch (id) {
    case GT_FFA:
    case GT_TOURNAMENT:
    case GT_TEAM:
    case GT_CTF:
    case GT_RTF://incin added
#ifdef MISSIONPACK
	case GT_1FCTF:
	case GT_OBELISK:
	case GT_HARVESTER:
#endif
        break;

    default:
        Com_Printf("IG_CallVoteGameType_Event: unknown game-id (%i)", id);
        return;
    }

    trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote g_gametype %i\n",id));
}



/*
=================
IG_CallVoteMisc_Event
=================
*/
static void IG_CallVoteMisc_Event( int index ) {
    int id;
    char* s;

    id = DynamicMenu_IdAtIndex(index);
    UI_ForceMenuOff();

    switch (id) {
    case CVM_NEXTMAP:
        s = "nextmap";
        break;
    case CVM_MAPRESTART:
        s = "map_restart";
        break;
    default:
        Com_Printf("IG_CallVote_Event: unknown id (%i)", id);
        return;
    }

    trap_Cmd_ExecuteText( EXEC_APPEND, va("callvote %s\n",s));
}




/*
=================
IG_CallVote_Event
=================
*/
static void IG_CallVote_Event( int index ) {
    int id;
    //	char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();

    switch (id) {
    case IGCV_KICK:
        //UI_RemoveBotsMenu(RBM_CALLVOTEKICK);
        break;
    case IGCV_MAP:
        UI_MapCallVote();
        break;
    case IGCV_LEADER:
        //UI_RemoveBotsMenu(RBM_CALLVOTELEADER);
        break;
    default:
        Com_Printf("IG_CallVote_Event: unknown id (%i)", id);
        return;
    }
}




/*
=================
IG_Vote_Event
=================
*/
static void IG_Vote_Event( int index ) {
    int id;
    char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();

    switch (id) {
    case IGV_YES:
        s = "vote yes\n";
        break;
    case IGV_NO:
        s = "vote no\n";
        break;
    case IGV_TEAMYES:
        s = "teamvote yes\n";
        break;
    case IGV_TEAMNO:
        s = "teamvote yes\n";
        break;
    default:
        Com_Printf("IG_Vote_Event: unknown id (%i)", id);
        return;
    }

    trap_Cmd_ExecuteText( EXEC_APPEND, s);
}



/*
=================
IG_TeamOrders_Event
=================
*/
static void IG_TeamOrders_Event( int index ) {
    UI_PopMenu();
    UI_BotCommandMenu_f();
}


/*
=================
IG_Start_Event
=================
*/
static void IG_Start_Event( int index ) {
    int id;
    char * s;

    id = DynamicMenu_IdAtIndex(index);
    UI_ForceMenuOff();

    if (id < 0 || id >= DM_START_MAX) {
        Com_Printf("IG_Start_Event: unknown id (%i)", id);
        return;
    }

    switch(id) {
    case DM_START_SPECTATOR:

        //trap_Cmd_ExecuteText( EXEC_APPEND, va("team %s; camera off\n", jointeam_cmd[id]));
		trap_Cmd_ExecuteText( EXEC_APPEND, va("team %s", jointeam_cmd[id]));
        return;
    case DM_START_SPECTATOR_RED:
        s = "observe_red\n";
        trap_Cmd_ExecuteText( EXEC_APPEND, va("%s\n",s));
        return;

    case DM_START_SPECTATOR_BLUE:
        s = "observe_blue\n";
        trap_Cmd_ExecuteText( EXEC_APPEND, va("%s\n",s));
        return;

    default:
        break;
    }

    trap_Cmd_ExecuteText( EXEC_APPEND, va("team %s\n", jointeam_cmd[id]));
}

static void IG_Camera_Event( int index) {
    int id;
    char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();
    UI_ForceMenuOff();
    switch (id) {
    case CAMERANEXT:
        s = "camera next\n";
        break;
    case CAMERAPREV:
        s = "camera prev\n";
        break;
    case CAMERAFLIC:
        s = "camera flic\n";
        break;
    case CAMERASWING:
        s = "camera swing\n";
        break;
    case CAMERAOFF:
        s = "camera off\n";
        break;
    case CAMERAON:
        s = "camera on\n";
        break;
    default:
        Com_Printf("IG_Vote_Event: unknown id (%i)\n", id);
        return;
    }

    trap_Cmd_ExecuteText( EXEC_APPEND, s);
    //Com_Printf("%s \n",s);
}


static void DrawBG(void) {

    DynamicMenu_AddBackground(INGAME_FRAME_TOP);
    //	DynamicMenu_AddBackground(INGAME_FRAME);		//no need to send all to it
    //	DynamicMenu_AddBackground(INGAME_FRAME_BOTTOM);
}

// ZCAM camera submenus

static void IG_Camera_Commands_Submenu(void) {
    int team;
    int depth;
    //	int gametype;

    team = UI_CurrentPlayerTeam();
    //gametype = DynamicMenu_ServerGametype();

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Next", CAMERANEXT, (voidfunc_f)0, IG_Camera_Event);
    DynamicMenu_AddItem("Prev",CAMERAPREV, (voidfunc_f)0, IG_Camera_Event);
    DynamicMenu_AddItem("Flic", CAMERAFLIC, (voidfunc_f)0, IG_Camera_Event);
    DynamicMenu_AddItem("Swing", CAMERASWING, (voidfunc_f)0, IG_Camera_Event);
    DynamicMenu_AddItem("Off", CAMERAOFF, (voidfunc_f)0, IG_Camera_Event);
    DynamicMenu_AddItem("On", CAMERAON, (voidfunc_f)0, IG_Camera_Event);
    //IG_Camera_Commands_Submenu
    //gametype = trap_Cvar_VariableValue("g_gametype");
    depth = DynamicMenu_Depth();

    if (team != TEAM_SPECTATOR || team != TEAM_SPECTATOR_RED || team != TEAM_SPECTATOR_BLUE ) {
        DynamicMenu_SetFlags(depth, CAMERANEXT, QMF_GRAYED);
        //	DynamicMenu_SetFlags(depth, CAMERAPREV, QMF_GRAYED);
    }
    depth = DynamicMenu_Depth();

    if (team != TEAM_SPECTATOR || team != TEAM_SPECTATOR_RED || team != TEAM_SPECTATOR_BLUE ) {
        //	DynamicMenu_SetFlags(depth, CAMERANEXT, QMF_GRAYED);
        DynamicMenu_SetFlags(depth, CAMERAPREV, QMF_GRAYED);
    }

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}



static void IG_SoundTeam_Event(int index) {
    int id;
    char* s;
    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();
    UI_ForceMenuOff();
    switch(id) {
        //cg_noTeamAudio; (0 - 1)
    case COLOR0://generic enum type
        s = "cg_noTeamAudio 1\n";
        break;
    case COLOR1:
        s = "cg_noTeamAudio 0\n";
        break;
    default:
        Com_Printf("IG_SoundTeam_Event: unknown id (%i)\n", id);
        return;
    }
    trap_Cmd_ExecuteText( EXEC_APPEND,s);


}


static void Submenu_Team_Audio( void) {
    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Off",  COLOR0, (voidfunc_f)0, IG_SoundTeam_Event);
    DynamicMenu_AddItem("On", COLOR1, (voidfunc_f)0, IG_SoundTeam_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}

static void IG_SoundVoice_Event(int index) {
    int id;
    char* s;
    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();
    UI_ForceMenuOff();
    switch(id) {
        //cg_noVoiceAudio; (0 - 1)

    case COLOR0://generic enum type
        s = "cg_noVoiceAudio 1\n";
        break;
    case COLOR1:
        s = "cg_noVoiceAudio 0\n";
        break;
    default:
        Com_Printf("IG_SoundVoice_Event: unknown id (%i)\n", id);
        return;
    }
    trap_Cmd_ExecuteText( EXEC_APPEND,s);


}

static void Submenu_VoiceAudio( void) {
    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Off", COLOR0, (voidfunc_f)0, IG_SoundVoice_Event);
    DynamicMenu_AddItem("On", COLOR1, (voidfunc_f)0, IG_SoundVoice_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}

static void IG_SoundTypes_Event(int index) {
    int id;
    char* s;
    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();
    UI_ForceMenuOff();
    switch(id) {
        //"male" , "female", "demon", "mech", "monster"
    case COLOR0://generic enum type
        s = "soundtype male\n";
        break;
    case COLOR1:
        s = "soundtype female\n";
        break;
    case COLOR2:
        s = "soundtype demon\n";
        break;
    case COLOR3:
        s = "soundtype mech\n";
        break;
    case COLOR4:
        s = "soundtype monster\n";
        break;
    default:
        Com_Printf("IG_SoundTypes_Event: unknown id (%i)\n", id);
        return;
    }
    trap_Cmd_ExecuteText( EXEC_APPEND,s);

}

static void SubMenu_SoundType(void) {
    //cg_soundType; ("male" , "female", "demon", "mech", "monster")
    //"male" , "female", "demon", "mech", "monster"
    DynamicMenu_SubMenuInit();
    DynamicMenu_AddItem("male",		COLOR0,	(voidfunc_f)0,	IG_SoundTypes_Event);
    DynamicMenu_AddItem("female",	COLOR1,	(voidfunc_f)0,	IG_SoundTypes_Event);
    DynamicMenu_AddItem("demon",	COLOR2,	(voidfunc_f)0,	IG_SoundTypes_Event);
    DynamicMenu_AddItem("mech",		COLOR3,	(voidfunc_f)0,	IG_SoundTypes_Event);
    DynamicMenu_AddItem("monster",	COLOR4, (voidfunc_f)0,	IG_SoundTypes_Event);
    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}

static void IG_SoundCmds_MenuInit(void) {

    DynamicMenu_SubMenuInit();

    //cg_noTeamAudio; (0 - 1)
    //cg_noVoiceAudio; (0 - 1)
    //cg_debugSounds; (0 - 1)
    DynamicMenu_AddItem("Team Audio",  COLOR0, Submenu_Team_Audio, 0);
    DynamicMenu_AddItem("Model Sound", COLOR2, SubMenu_SoundType,  0);
    DynamicMenu_AddItem("Voice Audio", COLOR1, Submenu_VoiceAudio, 0);
    DrawBG();
    DynamicMenu_FinishSubMenuInit();

}

static void IG_ModelSelect2(int index)
{	
	const char *s;
	const char *t;
	int cmd;
	int depth;

	//UI_DrawString(0, 128 + SMALLCHAR_HEIGHT, va("active: %i %i %i", s_dynamic.active[0], s_dynamic.active[1], s_dynamic.active[2] ), UI_SMALLFONT, color_white);
	
	depth = DynamicMenu_DepthOfIndex(index);
	//Com_Printf("IG_ModelSelect: Depth: %i DynamicMenu_Depth: %i\n", depth, DynamicMenu_Depth());
    
	if (depth != DynamicMenu_Depth())
	{
		//|| depth < 3) {
        Com_Printf("IG_ModelSelect: index %i at wrong depth (%i)\n", index, depth);
        return;
    }
    cmd = Dynamic_Menuparentid(depth-2);
	s =	DynamicMenu_StringAtIndex(cmd);
	
	
	cmd = Dynamic_Menuparentid(depth);
	t =	DynamicMenu_StringAtIndex(cmd);

	Com_Printf("%s set to: %s\n", s, t);

	if(Q_stricmp(s,"MODEL") == 0){
		s = "model";
	}
	else if(Q_stricmp(s,"Head Model") == 0){
		s = "headmodel";
	}
	else if(Q_stricmp(s,"Team Model") == 0){
		s = "team_model";
	}
	else if(Q_stricmp(s,"Team Head Model") == 0){
		s = "team_headmodel";
	}
	else if(Q_stricmp(s,"Enemy Model") == 0){
		s = "cg_enemyModel";
	}
	else if(Q_stricmp(s,"Enemy Head Model") == 0){
		s = "cg_enemyHeadmodel";
	}
	else
	{
		Com_Printf("IG_ModelSelect: Bad option\n");
	}
	//Com_Printf("Command selected: %s %s\n", s, t);
	trap_Cvar_Set(s, t);
	//trap_Cmd_ExecuteText( EXEC_APPEND,va("%s %s\n" ,s ,t));
	InGameDynamic_Close();
    UI_ForceMenuOff();

}


static void IG_ModelSelect(int index)
{	
	const char *s;
	const char *t;
	int cmd;
	int depth;

	//UI_DrawString(0, 128 + SMALLCHAR_HEIGHT, va("active: %i %i %i", s_dynamic.active[0], s_dynamic.active[1], s_dynamic.active[2] ), UI_SMALLFONT, color_white);
	
	depth = DynamicMenu_DepthOfIndex(index);
	//Com_Printf("IG_ModelSelect: Depth: %i DynamicMenu_Depth: %i\n", depth, DynamicMenu_Depth());
    
	if (depth != DynamicMenu_Depth())
	{
		//|| depth < 3) {
        Com_Printf("IG_ModelSelect: index %i at wrong depth (%i)\n", index, depth);
        return;
    }
    cmd = Dynamic_Menuparentid(depth-1);
	s =	DynamicMenu_StringAtIndex(cmd);
	
	
	cmd = Dynamic_Menuparentid(depth);
	t =	DynamicMenu_StringAtIndex(cmd);
	
	Com_Printf("%s set to: %s\n", s, t);
	if(Q_stricmp(s,"MODEL") == 0){
		s = "model";
	}
	else if(Q_stricmp(s,"Head Model") == 0){
		s = "headmodel";
	}
	else if(Q_stricmp(s,"Team Model") == 0){
		s = "team_model";
	}
	else if(Q_stricmp(s,"Team Head Model") == 0){
		s = "team_headmodel";
	}
	else if(Q_stricmp(s,"Enemy Model") == 0){
		s = "cg_enemyModel";
	}
	else if(Q_stricmp(s,"Enemy Head Model") == 0){
		s = "cg_enemyHeadmodel";
	}
	else
	{
		Com_Printf("IG_ModelSelect: Bad option\n");
	}
	
	trap_Cvar_Set(s, t);
	//trap_Cmd_ExecuteText( EXEC_APPEND,va("%s %s\n" ,s ,t));
	InGameDynamic_Close();
    UI_ForceMenuOff();
}

static void IG_ModelChoice_Event2(void){
	int i;
	DynamicMenu_SubMenuInit();
	for(i = 11; i < 22; i++)
	{
		DynamicMenu_AddItem(q3a_model_list[i], i ,(voidfunc_f)0,IG_ModelSelect2);
	}
	DrawBG();
	DynamicMenu_FinishSubMenuInit();
}

static void IG_ModelChoice_Event(void){
	int i;
	DynamicMenu_SubMenuInit();
	for(i = 0; i <= 10; i++)
	{
		DynamicMenu_AddItem(q3a_model_list[i], i ,(voidfunc_f)0,IG_ModelSelect);
	}
	DynamicMenu_AddItem("MORE..", 24 ,IG_ModelChoice_Event2,0);
	DrawBG();
	DynamicMenu_FinishSubMenuInit();
}

static void IG_PlayerModels_MenuInit(void){
	int depth;
	DynamicMenu_SubMenuInit();
	
	DynamicMenu_AddItem("Model",MODEL1,IG_ModelChoice_Event,0);
	DynamicMenu_AddItem("Head Model",MODEL2,IG_ModelChoice_Event, 0);
	DynamicMenu_AddItem("Team Model",MODEL3,IG_ModelChoice_Event, 0);
	DynamicMenu_AddItem("Team Head Model",MODEL4,IG_ModelChoice_Event, 0);
	DynamicMenu_AddItem("Enemy Model",MODEL5,IG_ModelChoice_Event, 0);
	DynamicMenu_AddItem("Enemy Head Model", MODEL6,IG_ModelChoice_Event, 0);
	
	depth = DynamicMenu_Depth();
	if (DynamicMenu_ServerGametype() >= GT_TEAM) {
        DynamicMenu_SetFlags(depth, MODEL1, QMF_GRAYED);
        DynamicMenu_SetFlags(depth, MODEL2, QMF_GRAYED);
    }
	if (DynamicMenu_ServerGametype() < GT_TEAM) {
        DynamicMenu_SetFlags(depth, MODEL3, QMF_GRAYED);
        DynamicMenu_SetFlags(depth, MODEL4, QMF_GRAYED);
		DynamicMenu_SetFlags(depth, MODEL5, QMF_GRAYED);
        DynamicMenu_SetFlags(depth, MODEL6, QMF_GRAYED);
    }

	DrawBG();
    DynamicMenu_FinishSubMenuInit();
}


static void IG_EnemyColor_Event(int index) {
    int id;
    char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();
    UI_ForceMenuOff();

    switch (id) {
    case COLOR0:
        s = "cg_enemyColor red\n";
        break;
    case COLOR1:
        s = "cg_enemyColor blue\n";
        break;
    case COLOR2:
        s = "cg_enemyColor green\n";
        break;
    case COLOR3:
        s = "cg_enemyColor yellow\n";
        break;
    case COLOR4:
        s = "cg_enemyColor orange\n";
        break;
    case COLOR5:
        s = "cg_enemyColor aqua\n";
        break;
    case COLOR6:
        s = "cg_enemyColor pink\n";
        break;
    case COLOR7:
        s = "cg_enemyColor white\n";
        break;
    case COLOR8:
        s = "cg_enemyColor black\n";
        break;
    default:
        Com_Printf("IG_EnemyColor_Event: unknown id (%i)\n", id);
        return;

    }
    //trap_Cmd_ExecuteText( EXEC_APPEND, va("%s ;+scores;-scores\n",s));
    trap_Cmd_ExecuteText( EXEC_APPEND,s);
}

static void Submenu_Enemy_Color_Choices(void) {

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("red",		COLOR0,	(voidfunc_f)0,	IG_EnemyColor_Event);
    DynamicMenu_AddItem("blue",		COLOR1,	(voidfunc_f)0,	IG_EnemyColor_Event);
    DynamicMenu_AddItem("green",	COLOR2,	(voidfunc_f)0,	IG_EnemyColor_Event);
    DynamicMenu_AddItem("yellow",	COLOR3,	(voidfunc_f)0,	IG_EnemyColor_Event);
    DynamicMenu_AddItem("orange",	COLOR4,	(voidfunc_f)0,	IG_EnemyColor_Event);
    DynamicMenu_AddItem("aqua",		COLOR5,	(voidfunc_f)0,	IG_EnemyColor_Event);
    DynamicMenu_AddItem("pink",		COLOR6,	(voidfunc_f)0,	IG_EnemyColor_Event);
    DynamicMenu_AddItem("white",	COLOR7,	(voidfunc_f)0,	IG_EnemyColor_Event);
    DynamicMenu_AddItem("black",	COLOR8,	(voidfunc_f)0,	IG_EnemyColor_Event);
    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}


static void IG_TeamColor_Event(int index) {
    int id;
    char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();
    UI_ForceMenuOff();

    switch (id) {
    case COLOR0:
        s = "cg_teamColor red\n";
        break;
    case COLOR1:
        s = "cg_teamColor blue\n";
        break;
    case COLOR2:
        s = "cg_teamColor green\n";
        break;
    case COLOR3:
        s = "cg_teamColor yellow\n";
        break;
    case COLOR4:
        s = "cg_teamColor orange\n";
        break;
    case COLOR5:
        s = "cg_teamColor aqua\n";
        break;
    case COLOR6:
        s = "cg_teamColor pink\n";
        break;
    case COLOR7:
        s = "cg_teamColor white\n";
        break;
    case COLOR8:
        s = "cg_teamColor black\n";
        break;
    default:
        Com_Printf("IG_TeamColor_Event: unknown id (%i)\n", id);
        return;

    }
    trap_Cmd_ExecuteText( EXEC_APPEND, s);
}


static void Submenu_Team_Color_Choices(void) {

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("red",		COLOR0,	(voidfunc_f)0,	IG_TeamColor_Event);
    DynamicMenu_AddItem("blue",		COLOR1,	(voidfunc_f)0,	IG_TeamColor_Event);
    DynamicMenu_AddItem("green",	COLOR2,	(voidfunc_f)0,	IG_TeamColor_Event);
    DynamicMenu_AddItem("yellow",	COLOR3,	(voidfunc_f)0,	IG_TeamColor_Event);
    DynamicMenu_AddItem("orange",	COLOR4,	(voidfunc_f)0,	IG_TeamColor_Event);
    DynamicMenu_AddItem("aqua",		COLOR5,	(voidfunc_f)0,	IG_TeamColor_Event);
    DynamicMenu_AddItem("pink",		COLOR6,	(voidfunc_f)0,	IG_TeamColor_Event);
    DynamicMenu_AddItem("white",	COLOR7,	(voidfunc_f)0,	IG_TeamColor_Event);
    DynamicMenu_AddItem("black",	COLOR8,	(voidfunc_f)0,	IG_TeamColor_Event);
    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}

static void IG_Team_HeadColors_Event(int index) {
    int id;
    char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();
    UI_ForceMenuOff();

    switch (id) {
    case COLOR0:
        s = "cg_teamHeadcolor red\n";
        break;
    case COLOR1:
        s = "cg_teamHeadcolor blue\n";
        break;
    case COLOR2:
        s = "cg_teamHeadcolor green\n";
        break;
    case COLOR3:
        s = "cg_teamHeadcolor yellow\n";
        break;
    case COLOR4:
        s = "cg_teamHeadcolor orange\n";
        break;
    case COLOR5:
        s = "cg_teamHeadcolor aqua\n";
        break;
    case COLOR6:
        s = "cg_teamHeadcolor pink\n";
        break;
    case COLOR7:
        s = "cg_teamHeadcolor white\n";
        break;
    case COLOR8:
        s = "cg_teamHeadcolor black\n";
        break;
    default:
        Com_Printf("IG_Team_HeadColors_Event: unknown id (%i)\n", id);
        return;
    }
    trap_Cmd_ExecuteText( EXEC_APPEND, s);
}


static void Submenu_Team_HeadColors(void) {

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("red",		COLOR0,	(voidfunc_f)0,	IG_Team_HeadColors_Event);
    DynamicMenu_AddItem("blue",		COLOR1,	(voidfunc_f)0,	IG_Team_HeadColors_Event);
    DynamicMenu_AddItem("green",	COLOR2,	(voidfunc_f)0,	IG_Team_HeadColors_Event);
    DynamicMenu_AddItem("yellow",	COLOR3,	(voidfunc_f)0,	IG_Team_HeadColors_Event);
    DynamicMenu_AddItem("orange",	COLOR4,	(voidfunc_f)0,	IG_Team_HeadColors_Event);
    DynamicMenu_AddItem("aqua",		COLOR5,	(voidfunc_f)0,	IG_Team_HeadColors_Event);
    DynamicMenu_AddItem("pink",		COLOR6,	(voidfunc_f)0,	IG_Team_HeadColors_Event);
    DynamicMenu_AddItem("white",	COLOR7,	(voidfunc_f)0,	IG_Team_HeadColors_Event);
    DynamicMenu_AddItem("black",	COLOR8,	(voidfunc_f)0,	IG_Team_HeadColors_Event);
    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}

static void IG_Enemy_HeadColors_Event(int index) {
    int id;
    char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();
    UI_ForceMenuOff();

    switch (id) {
    case COLOR0:
        s = "cg_enemyHeadcolor red\n";
        break;
    case COLOR1:
        s = "cg_enemyHeadcolor blue\n";
        break;
    case COLOR2:
        s = "cg_enemyHeadcolor green\n";
        break;
    case COLOR3:
        s = "cg_enemyHeadcolor yellow\n";
        break;
    case COLOR4:
        s = "cg_enemyHeadcolor orange\n";
        break;
    case COLOR5:
        s = "cg_enemyHeadcolor aqua\n";
        break;
    case COLOR6:
        s = "cg_enemyHeadcolor pink\n";
        break;
    case COLOR7:
        s = "cg_enemyHeadcolor white\n";
        break;
    case COLOR8:
        s = "cg_enemyHeadcolor black\n";
        break;
    default:
        Com_Printf("IG_Enemy_HeadColors_Event: unknown id (%i)\n", id);
        return;
    }

    trap_Cmd_ExecuteText( EXEC_APPEND, s);
}

static void Submenu_Enemy_HeadColors(void) {

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("red",		COLOR0,	(voidfunc_f)0,	IG_Enemy_HeadColors_Event);
    DynamicMenu_AddItem("blue",		COLOR1,	(voidfunc_f)0,	IG_Enemy_HeadColors_Event);
    DynamicMenu_AddItem("green",	COLOR2,	(voidfunc_f)0,	IG_Enemy_HeadColors_Event);
    DynamicMenu_AddItem("yellow",	COLOR3,	(voidfunc_f)0,	IG_Enemy_HeadColors_Event);
    DynamicMenu_AddItem("orange",	COLOR4,	(voidfunc_f)0,	IG_Enemy_HeadColors_Event);
    DynamicMenu_AddItem("aqua",		COLOR5,	(voidfunc_f)0,	IG_Enemy_HeadColors_Event);
    DynamicMenu_AddItem("pink",		COLOR6,	(voidfunc_f)0,	IG_Enemy_HeadColors_Event);
    DynamicMenu_AddItem("white",	COLOR7,	(voidfunc_f)0,	IG_Enemy_HeadColors_Event);
    DynamicMenu_AddItem("black",	COLOR8,	(voidfunc_f)0,	IG_Enemy_HeadColors_Event);
    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}


static void IG_Team_LogoColors_Event(int index) {

    int id;
    char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();
    UI_ForceMenuOff();

    switch (id) {
    case COLOR0:
        s = "cg_teamLogo red\n";
        break;
    case COLOR1:
        s = "cg_teamLogo blue\n";
        break;
    case COLOR2:
        s = "cg_teamLogo green\n";
        break;
    case COLOR3:
        s = "cg_teamLogo yellow\n";
        break;
    case COLOR4:
        s = "cg_teamLogo orange\n";
        break;
    case COLOR5:
        s = "cg_teamLogo aqua\n";
        break;
    case COLOR6:
        s = "cg_teamLogo pink\n";
        break;
    case COLOR7:
        s = "cg_teamLogo white\n";
        break;
    case COLOR8:
        s = "cg_teamLogo black\n";
        break;
    default:
        Com_Printf("IG_Team_LogoColors_Event: unknown id (%i)\n", id);
        return;
    }
    trap_Cmd_ExecuteText( EXEC_APPEND, s);
}

static void Submenu_Team_LogoColors(void) {

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("red",		COLOR0,	(voidfunc_f)0,	IG_Team_LogoColors_Event);
    DynamicMenu_AddItem("blue",		COLOR1,	(voidfunc_f)0,	IG_Team_LogoColors_Event);
    DynamicMenu_AddItem("green",	COLOR2,	(voidfunc_f)0,	IG_Team_LogoColors_Event);
    DynamicMenu_AddItem("yellow",	COLOR3,	(voidfunc_f)0,	IG_Team_LogoColors_Event);
    DynamicMenu_AddItem("orange",	COLOR4,	(voidfunc_f)0,	IG_Team_LogoColors_Event);
    DynamicMenu_AddItem("aqua",		COLOR5,	(voidfunc_f)0,	IG_Team_LogoColors_Event);
    DynamicMenu_AddItem("pink",		COLOR6,	(voidfunc_f)0,	IG_Team_LogoColors_Event);
    DynamicMenu_AddItem("white",	COLOR7,	(voidfunc_f)0,	IG_Team_LogoColors_Event);
    DynamicMenu_AddItem("black",	COLOR8,	(voidfunc_f)0,	IG_Team_LogoColors_Event);
    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}

static void IG_Enemy_Logo_Event(int index) {

    int id;
    char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();
    UI_ForceMenuOff();

    switch (id) {

    case COLOR0:
        s = "cg_enemyLogo red\n";
        break;
    case COLOR1:
        s = "cg_enemyLogo blue\n";
        break;
    case COLOR2:
        s = "cg_enemyLogo green\n";
        break;
    case COLOR3:
        s = "cg_enemyLogo yellow\n";
        break;
    case COLOR4:
        s = "cg_enemyLogo orange\n";
        break;
    case COLOR5:
        s = "cg_enemyLogo aqua\n";
        break;
    case COLOR6:
        s = "cg_enemyLogo pink\n";
        break;
    case COLOR7:
        s = "cg_enemyLogo white\n";
        break;
    case COLOR8:
        s = "cg_enemyLogo black\n";
        break;
    default:
        Com_Printf("IG_Enemy_Logo_Event: unknown id (%i)\n", id);
        return;
    }
    trap_Cmd_ExecuteText( EXEC_APPEND, s);

}

static void Submenu_Enemy_LogoColors(void) {

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("red",		COLOR0,	(voidfunc_f)0,	IG_Enemy_Logo_Event);
    DynamicMenu_AddItem("blue",		COLOR1,	(voidfunc_f)0,	IG_Enemy_Logo_Event);
    DynamicMenu_AddItem("green",	COLOR2,	(voidfunc_f)0,	IG_Enemy_Logo_Event);
    DynamicMenu_AddItem("yellow",	COLOR3,	(voidfunc_f)0,	IG_Enemy_Logo_Event);
    DynamicMenu_AddItem("orange",	COLOR4,	(voidfunc_f)0,	IG_Enemy_Logo_Event);
    DynamicMenu_AddItem("aqua",		COLOR5,	(voidfunc_f)0,	IG_Enemy_Logo_Event);
    DynamicMenu_AddItem("pink",		COLOR6,	(voidfunc_f)0,	IG_Enemy_Logo_Event);
    DynamicMenu_AddItem("white",	COLOR7,	(voidfunc_f)0,	IG_Enemy_Logo_Event);
    DynamicMenu_AddItem("black",	COLOR8,	(voidfunc_f)0,	IG_Enemy_Logo_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}
/*
static void IG_Team_Flagstyles_Event(int index) {

    int id;
    char* s;

    id = DynamicMenu_IdAtIndex(index);
    InGameDynamic_Close();
    UI_ForceMenuOff();

    switch (id) {
    case COLOR0:
        s = "cg_teamFlagstyle silk\n";
        break;
    case COLOR1:
        //Diordna
        s = "cg_teamLogo \"nologo\"; cg_teamFlagstyle \"ta\"\n";
        //s = "cg_teamLogo nologo; cg_teamFlagstyle ta\n";
        break;
    case COLOR3:
        s = "cg_enemyFlagstyle silk\n";
        break;
    case COLOR4:
        //Diordna
        s = "cg_enemyLogo \"nologo\"; cg_enemyFlagstyle \"ta\"\n";
        //s = "cg_teamLogo nologo; cg_enemyFlagstyle ta\n";
        break;
    default:
        Com_Printf("IG_Team_Flagstyles_Event: unknown id (%i)\n", id);
        return;

    }
    trap_Cmd_ExecuteText( EXEC_APPEND, s);

}
*/
/*
static void Submenu_Team_Flagstyles(void) {

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("silk",		COLOR0,	(voidfunc_f)0,	IG_Team_Flagstyles_Event);
    //	DynamicMenu_AddItem("TA",		COLOR1,	(voidfunc_f)0,	IG_Team_Flagstyles_Event);
    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}
*/
/*
static void Submenu_Enemy_Flagstyles(void){
	
	DynamicMenu_SubMenuInit();
 
	DynamicMenu_AddItem("silk",		COLOR3,	(voidfunc_f)0,	IG_Team_Flagstyles_Event);
//	DynamicMenu_AddItem("TA",		COLOR4,	(voidfunc_f)0,	IG_Team_Flagstyles_Event);
 
	DrawBG();
	DynamicMenu_FinishSubMenuInit();
}
*/
static void IG_ForceColor_Event(int index) {
    int id;
    char* s;

    id = DynamicMenu_IdAtIndex(index);

    switch (id) {
    case COLOR0:
        InGameDynamic_Close();
        UI_ForceMenuOff();
        s = "cg_forceColor 0\n";
        //Com_Printf("cg_forceColor turned off, using defaults\n");
        break;
    case COLOR1:
        InGameDynamic_Close();
        UI_ForceMenuOff();
        s = "cg_forceColor 1\n";
        Com_Printf("cg_forceColor set to 1\n");
        break;
    case COLOR2:
        InGameDynamic_Close();
        UI_ForceMenuOff();
        s = "cg_forceColor 2\n";
        Com_Printf("cg_forceColor set to 2\n");
        break;
    case COLOR3:
        return;
    case COLOR4:
        return;
        //	case COLOR11:
        //		InGameDynamic_Close();
        //		UI_ForceMenuOff();
        //		s = "cg_forcecolor 0; cg_enemyColor \"green\"; cg_teamColor \"yellow\"; cg_teamFlagstyle \"silk\"; cg_enemyFlagstyle \"silk\"; 23 \"yellow\"; cg_enemyHeadcolor \"pink\"\n";
        //Com_Printf("Reset to Defaults not enabled yet: id (%i)\n", id);
        //		break;
    default:
        Com_Printf("IG_ForceColor_Event: unknown id (%i)\n", id);
        return;
    }
    trap_Cmd_ExecuteText( EXEC_APPEND, s);

}


//CG_forcecolor menuitcommands submenu
static void IG_Forcecolor_SubMenuInit(void) {
    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Off",			COLOR0,	(voidfunc_f)0,	IG_ForceColor_Event);
    DynamicMenu_AddItem("Mode 1",		COLOR1,	(voidfunc_f)0,	IG_ForceColor_Event);
    DynamicMenu_AddItem("Mode 2",		COLOR2,	(voidfunc_f)0,	IG_ForceColor_Event);
    DynamicMenu_AddItem("Team Color",	COLOR3,	Submenu_Team_Color_Choices, 0);
    DynamicMenu_AddItem("Enemy Color",	COLOR4,	Submenu_Enemy_Color_Choices,	0);
    DynamicMenu_AddItem("Team HeadColor", COLOR5, Submenu_Team_HeadColors, 0);
    DynamicMenu_AddItem("Enemy HeadColor", COLOR6, Submenu_Enemy_HeadColors, 0);
    DynamicMenu_AddItem("Team LogoColor", COLOR7, Submenu_Team_LogoColors, 0);
    DynamicMenu_AddItem("Enemy LogoColor", COLOR8, Submenu_Enemy_LogoColors, 0);
    // DynamicMenu_AddItem("Flag Styles", COLOR9, Submenu_Team_Flagstyles, 0);

    //	DynamicMenu_AddItem("Team Flag Style", COLOR9, Submenu_Team_Flagstyles, 0);
    //	DynamicMenu_AddItem("Enemy Flag Style", COLOR10, Submenu_Team_Flagstyles, 0);
    //	DynamicMenu_AddItem("Defaults",		COLOR11,	(voidfunc_f)0,	IG_ForceColor_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();

}

/*
=================
IG_TimeLimit_SubMenu
=================
*/
static void IG_TimeLimit_SubMenu( void ) {
    //	int depth;

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Unlimited", 0, (voidfunc_f)0, IG_TimeLimit_Event);
    DynamicMenu_AddItem("5", 5, (voidfunc_f)0, IG_TimeLimit_Event);
    DynamicMenu_AddItem("10", 10, (voidfunc_f)0, IG_TimeLimit_Event);
    DynamicMenu_AddItem("15", 15, (voidfunc_f)0, IG_TimeLimit_Event);
    DynamicMenu_AddItem("20", 20, (voidfunc_f)0, IG_TimeLimit_Event);
    DynamicMenu_AddItem("25", 25, (voidfunc_f)0, IG_TimeLimit_Event);
    DynamicMenu_AddItem("30", 30, (voidfunc_f)0, IG_TimeLimit_Event);
    DynamicMenu_AddItem("45", 45, (voidfunc_f)0, IG_TimeLimit_Event);
    DynamicMenu_AddItem("60", 60, (voidfunc_f)0, IG_TimeLimit_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}



/*
=================
IG_FragLimit_SubMenu
=================
*/
static void IG_FragLimit_SubMenu( void ) {
    //	int depth;

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Unlimited", 0, (voidfunc_f)0, IG_FragLimit_Event);
    DynamicMenu_AddItem("10", 10, (voidfunc_f)0, IG_FragLimit_Event);
    DynamicMenu_AddItem("15", 15, (voidfunc_f)0, IG_FragLimit_Event);
    DynamicMenu_AddItem("20", 20, (voidfunc_f)0, IG_FragLimit_Event);
    DynamicMenu_AddItem("30", 30, (voidfunc_f)0, IG_FragLimit_Event);
    DynamicMenu_AddItem("40", 40, (voidfunc_f)0, IG_FragLimit_Event);
    DynamicMenu_AddItem("50", 50, (voidfunc_f)0, IG_FragLimit_Event);
    DynamicMenu_AddItem("75", 75, (voidfunc_f)0, IG_FragLimit_Event);
    DynamicMenu_AddItem("100", 100, (voidfunc_f)0, IG_FragLimit_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}


/*
=================
IG_DoWarmup_SubMenu
=================
*/
static void IG_DoWarmup_SubMenu( void ) {
    //	int depth;

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Enable", 1, (voidfunc_f)0, IG_DoWarmup_Event);
    DynamicMenu_AddItem("Disable", 0, (voidfunc_f)0, IG_DoWarmup_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}



/*
=================
IG_Map_SubMenu
=================
*/
static void IG_Map_SubMenu( void ) {
    int depth;

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Restart map...", ID_RESTART, (voidfunc_f)0, IG_UseOldInGame_Event);
    DynamicMenu_AddItem("Disable Items...", ID_ENABLEDITEMS, (voidfunc_f)0, IG_UseOldInGame_Event);
    DynamicMenu_AddItem("Next map...", ID_NEXTMAP, (voidfunc_f)0, IG_UseOldInGame_Event);

    depth = DynamicMenu_Depth();
    if (DynamicMenu_ServerGametype() == GT_SINGLE_PLAYER) {
        DynamicMenu_SetFlags(depth, ID_NEXTMAP, QMF_GRAYED);
        DynamicMenu_SetFlags(depth, ID_ENABLEDITEMS, QMF_GRAYED);
    }

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}



/*
=================
IG_CallVoteMisc_SubMenu
=================
*/
static void IG_CallVoteMisc_SubMenu( void ) {
    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Next map", CVM_NEXTMAP, (voidfunc_f)0, IG_CallVoteMisc_Event);
    DynamicMenu_AddItem("Map restart", CVM_MAPRESTART, (voidfunc_f)0, IG_CallVoteMisc_Event);
    DynamicMenu_AddItem("Warmup", 0, IG_DoWarmup_SubMenu, 0);
    DynamicMenu_AddItem("Timelimit", 0, IG_TimeLimit_SubMenu, 0);
    //Incin added rtf mode
    if (DynamicMenu_ServerGametype() == GT_CTF || DynamicMenu_ServerGametype() == GT_RTF) {
        // No CTF caplimit, callvote doesn't support it
    }
    else {
        DynamicMenu_AddItem("FragLimit", 0, IG_FragLimit_SubMenu, 0);
    }

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}



/*
=================
IG_CallVoteMisc_SubMenu
=================
*/
static void IG_CallVoteGameType_SubMenu( void ) {
    int gametype;
    int i;
    int depth;
    const char* icon;

    gametype = DynamicMenu_ServerGametype();

    DynamicMenu_SubMenuInit();

    depth = DynamicMenu_Depth();
    for (i = 0; i < gametypeMenu_size; i++) {
        icon = UIE_DefaultIconFromGameType(gametypeMenu_data[i].gametype);

        DynamicMenu_AddIconItem(gametypeMenu_data[i].menu, gametypeMenu_data[i].gametype,
                                icon, (voidfunc_f)0, IG_CallVoteGameType_Event);

        if (gametypeMenu_data[i].gametype == gametype)
            DynamicMenu_SetFlags(depth, gametype, QMF_GRAYED);
    }

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}



/*
=================
IG_CallVote_SubMenu
=================
*/
static void IG_CallVote_SubMenu( void ) {
    int team;
    int depth;

    team = UI_CurrentPlayerTeam();

    DynamicMenu_SubMenuInit();

    depth = DynamicMenu_Depth();
    DynamicMenu_AddItem("Kick...", IGCV_KICK, (voidfunc_f)0, IG_CallVote_Event);
    DynamicMenu_AddItem("Map...", IGCV_MAP, (voidfunc_f)0, IG_CallVote_Event);
    DynamicMenu_AddItem("Leader...", IGCV_LEADER, (voidfunc_f)0, IG_CallVote_Event);
    DynamicMenu_AddItem("Gametype", IGCV_GAMETYPE, IG_CallVoteGameType_SubMenu, 0);
    //DynamicMenu_AddItem("Gamemode", IGCV_GAMEMODE, IG_CallVoteGameMode_SubMenu, 0);//INCIN enable at a later date
    DynamicMenu_AddItem("Misc", 0, IG_CallVoteMisc_SubMenu, 0);

    if (team == TEAM_SPECTATOR || team == TEAM_SPECTATOR_RED || team == TEAM_SPECTATOR_BLUE || team == TEAM_FREE) {
        DynamicMenu_SetFlags(depth, IGCV_LEADER, QMF_GRAYED);
    }

    DrawBG();

    DynamicMenu_FinishSubMenuInit();
}



/*
=================
IG_Vote_SubMenu
=================
*/
static void IG_Vote_SubMenu( void ) {
    char buf[MAX_INFO_STRING];

    DynamicMenu_SubMenuInit();

    trap_GetConfigString(CS_VOTE_TIME, buf, MAX_INFO_STRING);
    if (atoi(buf) != 0) {
        DynamicMenu_AddItem("Yes", IGV_YES, (voidfunc_f)0, IG_Vote_Event);
        DynamicMenu_AddItem("No", IGV_NO, (voidfunc_f)0, IG_Vote_Event);
    }

    trap_GetConfigString(CS_TEAMVOTE_TIME, buf, MAX_INFO_STRING);
    if (atoi(buf) != 0) {
        DynamicMenu_AddItem("Team Yes", IGV_TEAMYES, (voidfunc_f)0, IG_Vote_Event);
        DynamicMenu_AddItem("Team No", IGV_TEAMNO, (voidfunc_f)0, IG_Vote_Event);
    }

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}



/*
=================
IG_Setup_SubMenu
=================
*/
static void IG_Setup_SubMenu( void ) {
    qboolean localserver;

    localserver = trap_Cvar_VariableValue( "sv_running" );

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Player...", IGS_PLAYER, (voidfunc_f)0, IG_Setup_Event);
    DynamicMenu_AddItem("Model...", IGS_MODEL, (voidfunc_f)0, IG_Setup_Event);
    DynamicMenu_AddItem("Controls...", IGS_CONTROLS, (voidfunc_f)0, IG_Setup_Event);
    DynamicMenu_AddItem("Preferences...", IGS_OPTIONS, (voidfunc_f)0, IG_Setup_Event);
    DynamicMenu_AddItem("Graphics...", IGS_GRAPHICS, (voidfunc_f)0, IG_Setup_Event);
    DynamicMenu_AddItem("Display...", IGS_DISPLAY, (voidfunc_f)0, IG_Setup_Event);
    DynamicMenu_AddItem("Sound...", IGS_SOUND, (voidfunc_f)0, IG_Setup_Event);
    DynamicMenu_AddItem("Network...", IGS_NETWORK, (voidfunc_f)0, IG_Setup_Event);
    if(localserver) {
        DynamicMenu_AddItem("Battle...", IGS_SKIRMISH, (voidfunc_f)0, IG_Setup_Event);
    }

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}



/*
=================
IG_AddBot_SubMenu
=================
 
static void IG_AddBot_SubMenu( void ) {
    DynamicMenu_SubMenuInit();
 
    DynamicMenu_AddItem("Add bot...", ID_ADDBOTS, (voidfunc_f)0, IG_UseOldInGame_Event);
    DynamicMenu_AddItem("Remove bot...", ID_REMOVEBOTS, (voidfunc_f)0, IG_UseOldInGame_Event);
 
	DrawBG();
    DynamicMenu_FinishSubMenuInit();
}
*/




/*
=================
IG_Exit_SubMenu
=================
*/
static void IG_Exit_SubMenu( void ) {
    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Quit...", ID_QUIT, (voidfunc_f)0, IG_UseOldInGame_Event);
    //INCIN -- grrrrr stupid thing screwing up debugging
    DynamicMenu_AddItem("Main Menu", ID_LEAVEARENA, (voidfunc_f)0, IG_UseOldInGame_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}


static void IG_Follow_Event(int index) {
    const char *s;
    //int id;
    //id = DynamicMenu_IdAtIndex(index);
    s = DynamicMenu_StringAtIndex(index);
    trap_Cmd_ExecuteText( EXEC_APPEND, va("follow %s\n", s));
    InGameDynamic_Close();
    UI_ForceMenuOff();
}


/*
=================
IG_Add_Players
=================
*/

static void IG_Add_Players( void) {
    uiClientState_t	cs;
    int		numPlayers;
    //    int		isBot;
    int		n;
    char	info[MAX_INFO_STRING];
    //    char	boticon[MAX_BOT_ICON];
    char 	name[64];
    int 	playerTeam, team;
    //int 	depth;

    DynamicMenu_SubMenuInit();

    trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) );
    numPlayers = atoi( Info_ValueForKey( info, "sv_maxclients" ) );

    trap_GetClientState( &cs );
    trap_GetConfigString( CS_PLAYERS + cs.clientNum, info, MAX_INFO_STRING );
    playerTeam = atoi(Info_ValueForKey(info, "t"));

    for( n = 0; n < numPlayers; n++ ) {

        trap_GetConfigString( CS_PLAYERS + n, info, MAX_INFO_STRING );

        if (n == cs.clientNum) //self
            continue;
        team = atoi(Info_ValueForKey(info, "t"));

        if( team == TEAM_SPECTATOR) {
            continue;
        } else if( team == TEAM_SPECTATOR_RED) {
            continue;
        } else if( team == TEAM_SPECTATOR_BLUE) {
            continue;
        }
        Q_strncpyz(name, Info_ValueForKey(info, "n"), 64);
        //Q_CleanStr(name);

        if (!name[0])
            continue;
        DynamicMenu_AddItem( name, n , (voidfunc_f)0, IG_Follow_Event);
    }

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}




/*
=================
IG_Start_SubMenu
=================
*/
static void IG_Start_SubMenu( void ) {
    int depth;
    int gametype;
    int team;
    //Incin added to test for player count
    //uiClientState_t cs;
    int n;
    int j;
    char info[MAX_INFO_STRING];
    int numPlayers;
    j = 0;

    gametype = DynamicMenu_ServerGametype();
    DynamicMenu_SubMenuInit();
    depth = DynamicMenu_Depth();

    if (gametype < GT_TEAM) {
        DynamicMenu_AddIconItem("Join Game", DM_START_GAME, "menu/medals/medal_gauntlet", (voidfunc_f)0, IG_Start_Event);
    } else {
        DynamicMenu_AddIconItem("Auto Join", DM_START_AUTO, "menu/medals/medal_capture", (voidfunc_f)0, IG_Start_Event);
        DynamicMenu_AddIconItem("Join Red", DM_START_RED, "uie_icons/iconf_red", (voidfunc_f)0, IG_Start_Event);
        DynamicMenu_AddIconItem("Join Blue", DM_START_BLUE, "uie_icons/iconf_blu", (voidfunc_f)0, IG_Start_Event);

    }

    DynamicMenu_AddItem("Spectate", DM_START_SPECTATOR, (voidfunc_f)0, IG_Start_Event);


    if(gametype >= GT_TEAM) {
        DynamicMenu_AddIconItem("Observe Red", DM_START_SPECTATOR_RED,"uie_icons/iconf_red",	(voidfunc_f)0, IG_Start_Event);
        DynamicMenu_AddIconItem("Observe Blue", DM_START_SPECTATOR_BLUE, "uie_icons/iconf_blu", (voidfunc_f)0, IG_Start_Event);
        DynamicMenu_AddIconItem("Follow #1", DM_START_FOLLOW1, "uie_icons/iconf_red", (voidfunc_f)0, IG_Start_Event);//red team
        DynamicMenu_AddIconItem("Follow #2", DM_START_FOLLOW2, "uie_icons/iconf_blu", (voidfunc_f)0, IG_Start_Event);//blue team


        if(UI_CurrentPlayerTeam() == TEAM_SPECTATOR_RED ) {
            DynamicMenu_SetFlags(depth, DM_START_SPECTATOR_RED, QMF_GRAYED);
        }

        if(UI_CurrentPlayerTeam() == TEAM_SPECTATOR_BLUE) {
            DynamicMenu_SetFlags(depth, DM_START_SPECTATOR_BLUE, QMF_GRAYED);
        }


    } else {
        DynamicMenu_AddItem("Follow", DM_START_FOLLOW1, (voidfunc_f)0, IG_Start_Event);//red team
    }




    if (UI_CurrentPlayerTeam() == TEAM_SPECTATOR && gametype >= GT_TEAM) {
        DynamicMenu_SetFlags(depth, DM_START_SPECTATOR, QMF_GRAYED);
    } else if (UI_CurrentPlayerTeam() == TEAM_SPECTATOR && gametype < GT_TEAM) {
        DynamicMenu_SetFlags(depth, DM_START_SPECTATOR, QMF_GRAYED);
    }

    //INCIN - fixed
    //trap_GetClientState( &cs );

    //if(gametype >= GT_TEAM)
    //{
    trap_GetConfigString( CS_SERVERINFO, info, sizeof(info) );
    numPlayers = atoi( Info_ValueForKey( info, "sv_maxclients" ) );
    for( n = 0; n < numPlayers; n++ ) {
        //trap_GetConfigString( CS_PLAYERS + n, info, MAX_INFO_STRING );
        trap_GetConfigString( CS_PLAYERS + n, info, MAX_INFO_STRING );//cs.clientNum
        team = atoi( Info_ValueForKey( info, "t" ) );
        //Com_Printf("%i\n",cs.clientNum);
        if (info[0] == '\0')
            continue;

        if( team == TEAM_SPECTATOR) {
            continue;
        } else if( team == TEAM_SPECTATOR_RED) {
            continue;
        } else if( team == TEAM_SPECTATOR_BLUE) {
            continue;
        }
        j++;
    }
    //incin if your the only player on disable follow team choices

    if(j > 1)
        DynamicMenu_AddItem("Follow...", DM_START_FOLLOW_NAMED, IG_Add_Players,0);

    if(j < 2 ) {
        if((!UI_CurrentPlayerTeam() == TEAM_SPECTATOR) || (UI_CurrentPlayerTeam() == TEAM_SPECTATOR)) {
            if (gametype > GT_TEAM) {
                DynamicMenu_SetFlags(depth, DM_START_FOLLOW1, QMF_GRAYED);
                DynamicMenu_SetFlags(depth, DM_START_FOLLOW2, QMF_GRAYED);
            } else if(gametype < GT_TEAM) {
                DynamicMenu_SetFlags(depth, DM_START_FOLLOW1, QMF_GRAYED);
            }
        }

        if((UI_CurrentPlayerTeam() == TEAM_SPECTATOR_RED) && gametype >= GT_TEAM) {
            DynamicMenu_SetFlags(depth, DM_START_SPECTATOR_RED, QMF_GRAYED);
        }

        if((UI_CurrentPlayerTeam() == TEAM_SPECTATOR_BLUE) && gametype >= GT_TEAM) {
            DynamicMenu_SetFlags(depth, DM_START_SPECTATOR_BLUE, QMF_GRAYED);
        }
    }

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}




static void IG_OptimizePrediction_Event(int index) {
    int i;
    i = DynamicMenu_IdAtIndex(index);
    trap_Cmd_ExecuteText( EXEC_APPEND, va("cg_optimizePrediction %i\n", i ));
    InGameDynamic_Close();
    UI_ForceMenuOff();
}

static void IG_OptimizePredictionMenu(void) {
    //int depth;
    DynamicMenu_SubMenuInit();
    //depth = DynamicMenu_Depth();

    DynamicMenu_AddItem("Off", 0, (voidfunc_f)0, IG_OptimizePrediction_Event);
    DynamicMenu_AddItem("On", 1, (voidfunc_f)0, IG_OptimizePrediction_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();

}

static void IG_DelagOnOff_Event(int index) {
    int i;
    i = DynamicMenu_IdAtIndex(index);
    trap_Cmd_ExecuteText( EXEC_APPEND, va("cg_delag %i\n", i));
    InGameDynamic_Close();
    UI_ForceMenuOff();
}

static void IG_DelagOnOffMenu(void) {
    //int depth;
    DynamicMenu_SubMenuInit();
    //depth = DynamicMenu_Depth();

    DynamicMenu_AddItem("Off", 0, (voidfunc_f)0, IG_DelagOnOff_Event);
    DynamicMenu_AddItem("On", 1, (voidfunc_f)0, IG_DelagOnOff_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();

}

static void IG_CmdTimeNuge_Event(int index) {
    const char *s;
    //int id;
    //id = DynamicMenu_IdAtIndex(index);
    s = DynamicMenu_StringAtIndex(index);
    trap_Cmd_ExecuteText( EXEC_APPEND, va("cg_cmdTimeNudge %s\n", s));
    Com_Printf("cg_cmdTimeNudge set to %s\n", s);
    InGameDynamic_Close();
    UI_ForceMenuOff();
}

static void IG_CmdTimeNugeMenu(void) {	//int depth,
    int j;
    int i;
    const char *s[] = {
                          "0","10","20","30","40","50" ,
                          "100", "125","150","200","300","400","500","800","999"
                      };

    DynamicMenu_SubMenuInit();
    //depth = DynamicMenu_Depth();
    for (i = 0, j = 5 ; i < 15; i++, j+= 5) {
        //strcpy(s[i],(char *)i-30);
        //s = //va("%s",i - 30);
        DynamicMenu_AddItem( s[i] , j, (voidfunc_f)0, IG_CmdTimeNuge_Event);
    }
    DrawBG();
    DynamicMenu_FinishSubMenuInit();


}

static void IG_ProjNudge_Event(int index) {
    const char *s;
    //int id;
    //id = DynamicMenu_IdAtIndex(index);
    s = DynamicMenu_StringAtIndex(index);
    trap_Cmd_ExecuteText( EXEC_APPEND, va("cg_projectileNudge %s\n", s));
    Com_Printf("cg_projectileNudge set to %s\n", s);
    InGameDynamic_Close();
    UI_ForceMenuOff();
}

static void IG_ProjNudgeMenu(void) {	//int depth,
    int j;
    int i;
    const char *s[] = {
                          "-30","-25","-20","-15","-10","-5" ,
                          "0",
                          "5","10","15","20","25","30"
                      };

    DynamicMenu_SubMenuInit();
    //depth = DynamicMenu_Depth();
    for (i = 0, j = 5 ; i < 13; i++, j+= 5) {
        //strcpy(s[i],(char *)i-30);
        //s = //va("%s",i - 30);
        DynamicMenu_AddItem( s[i] , j, (voidfunc_f)0, IG_ProjNudge_Event);
    }
    DrawBG();
    DynamicMenu_FinishSubMenuInit();

}

static void IG_TimeNudge_Event(int index) {
    const char *s;
    s = DynamicMenu_StringAtIndex(index);
    UI_ForceMenuOff();

    trap_Cmd_ExecuteText( EXEC_APPEND, va("cl_timeNudge %s\n",s));
    InGameDynamic_Close();
    Com_Printf("cl_timeNudge set to %s\n", s);
}
static void IG_TimeNudgeMenu(void) {
    //int depth,
    int j;
    int i;
    const char *s[] = {
                          "-30","-25","-20","-15","-10","-5" ,
                          "0",
                          "5","10","15","20","25","30"
                      };

    DynamicMenu_SubMenuInit();
    //depth = DynamicMenu_Depth();
    for (i = 0, j = 5 ; i < 13; i++, j+= 5) {
        //strcpy(s[i],(char *)i-30);
        //s = //va("%s",i - 30);
        DynamicMenu_AddItem( s[i] , j, (voidfunc_f)0, IG_TimeNudge_Event);
    }
    DrawBG();
    DynamicMenu_FinishSubMenuInit();


}
/*
extern	vmCvar_t		cg_delag;
extern	vmCvar_t		cg_debugDelag;
extern	vmCvar_t		cg_drawBBox;
extern	vmCvar_t		cg_cmdTimeNudge;
extern	vmCvar_t		sv_fps;
extern	vmCvar_t		cg_projectileNudge;
extern	vmCvar_t		cg_optimizePrediction;
extern	vmCvar_t		cl_timeNudge;
extern	vmCvar_t		cg_latentSnaps;
extern	vmCvar_t		cg_latentCmds;
extern	vmCvar_t		cg_plOut;
//unlagged - client options
	{ &cg_delag, "cg_delag", "1", CVAR_ARCHIVE | CVAR_USERINFO },
	
 
	{ &cg_cmdTimeNudge, "cg_cmdTimeNudge", "0", CVAR_ARCHIVE | CVAR_USERINFO },
	
	{ &cg_projectileNudge, "cg_projectileNudge", "0", CVAR_ARCHIVE },
	{ &cg_optimizePrediction, "cg_optimizePrediction", "1", CVAR_ARCHIVE },
	{ &cl_timeNudge, "cl_timeNudge", "0", CVAR_ARCHIVE },
	
	{ &cg_drawBBox, "cg_drawBBox", "0", CVAR_CHEAT },
	{ &cg_latentSnaps, "cg_latentSnaps", "0", CVAR_USERINFO | CVAR_CHEAT },
	{ &cg_latentCmds, "cg_latentCmds", "0", CVAR_USERINFO | CVAR_CHEAT },
	{ &cg_plOut, "cg_plOut", "0", CVAR_USERINFO | CVAR_CHEAT },
	{ &cg_debugDelag, "cg_debugDelag", "0", CVAR_USERINFO | CVAR_CHEAT },
//unlagged - client options
*/
static void IG_DrawBbox_Event(int index) {
    int i;
    i = DynamicMenu_IdAtIndex(index);
    trap_Cmd_ExecuteText( EXEC_APPEND, va("cg_drawBBox %i\n", i));
    InGameDynamic_Close();
    UI_ForceMenuOff();
}


static void IG_DrawBbox(void) {
    //int depth;
    DynamicMenu_SubMenuInit();
    //depth = DynamicMenu_Depth();

    DynamicMenu_AddItem("Off", 0, (voidfunc_f)0, IG_DrawBbox_Event);
    DynamicMenu_AddItem("On", 1, (voidfunc_f)0, IG_DrawBbox_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();

}
static void IG_LatentSnaps_Event(int index) {
    int i;
    i = DynamicMenu_IdAtIndex(index);
    trap_Cmd_ExecuteText( EXEC_APPEND, va("cg_latentSnaps %i\n", i));
    InGameDynamic_Close();
    UI_ForceMenuOff();
}

static void IG_LatentSnaps(void) {
    //int depth;
    DynamicMenu_SubMenuInit();
    //depth = DynamicMenu_Depth();

    DynamicMenu_AddItem("Off", 0, (voidfunc_f)0, IG_LatentSnaps_Event);
    DynamicMenu_AddItem("On", 1, (voidfunc_f)0, IG_LatentSnaps_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();

}
static void IG_LatentCmds_Event(int index) {
    int i;
    i = DynamicMenu_IdAtIndex(index);
    trap_Cmd_ExecuteText( EXEC_APPEND, va("cg_latentCmds %i\n", i));
    InGameDynamic_Close();
    UI_ForceMenuOff();
}


static void IG_LatentCmds(void) {
    //int depth;
    DynamicMenu_SubMenuInit();
    //depth = DynamicMenu_Depth();

    DynamicMenu_AddItem("Off", 0, (voidfunc_f)0, IG_LatentCmds_Event);
    DynamicMenu_AddItem("On", 1, (voidfunc_f)0, IG_LatentCmds_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();

}

static void IG_PlOut_Event(int index) {
    int i;
    i = DynamicMenu_IdAtIndex(index);
    trap_Cmd_ExecuteText( EXEC_APPEND, va("cg_plOut %i\n", i));
    InGameDynamic_Close();
    UI_ForceMenuOff();
}


static void IG_PlOut(void) {
    //int depth;
    DynamicMenu_SubMenuInit();
    //depth = DynamicMenu_Depth();

    DynamicMenu_AddItem("Off", 0, (voidfunc_f)0, IG_PlOut_Event);
    DynamicMenu_AddItem("On", 1, (voidfunc_f)0, IG_PlOut_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();

}
static void IG_DebugLag_Event(int index) {
    int i;
    i = DynamicMenu_IdAtIndex(index);
    trap_Cmd_ExecuteText( EXEC_APPEND, va("cg_debugDelag %i\n", i));
    InGameDynamic_Close();
    UI_ForceMenuOff();
}



static void IG_DebugLag(void) {
    //int depth;
    DynamicMenu_SubMenuInit();
    //depth = DynamicMenu_Depth();

    DynamicMenu_AddItem("Off", 0, (voidfunc_f)0, IG_DebugLag_Event);
    DynamicMenu_AddItem("On", 1, (voidfunc_f)0, IG_DebugLag_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}

enum
{
    IG_PREDCTN,
    IG_DELAG,
    IG_CMDTIMENUDGE,
    IG_PROJNUDGE,
    IG_TIMENUDGE,
    IG_DRAWBBOX,
    IG_LATENTSNAPS,
    IG_LATENTCMDS,
    IG_PLOUT,
    IG_DEBUGLAG
};

static void IG_Unlagged_SubmenuInit(void) {
    int depth;
    qboolean cheats;

    cheats = (int)trap_Cvar_VariableValue("sv_cheats");

    DynamicMenu_SubMenuInit();
    depth = DynamicMenu_Depth();

    DynamicMenu_AddItem("Optimize Prediction", IG_PREDCTN , IG_OptimizePredictionMenu,0);//(voidfunc_f)0, );
    DynamicMenu_AddItem("Delag", IG_DELAG,IG_DelagOnOffMenu,0);//(voidfunc_f)0, );
    DynamicMenu_AddItem("Cmd Time Nudge", IG_CMDTIMENUDGE , IG_CmdTimeNugeMenu, 0 );//(voidfunc_f)0

    DynamicMenu_AddItem("Projectile Nudge", IG_PROJNUDGE ,IG_ProjNudgeMenu , 0 );//(voidfunc_f)0

    DynamicMenu_AddItem("Time Nudge", IG_TIMENUDGE , IG_TimeNudgeMenu, 0 );//(voidfunc_f)0

    if(cheats) {
        DynamicMenu_AddItem("DrawBBox", IG_DRAWBBOX, IG_DrawBbox, 0);
        DynamicMenu_AddItem("LatentSnaps", IG_LATENTSNAPS, IG_LatentSnaps, 0);
        DynamicMenu_AddItem("LatentCmds", IG_LATENTCMDS, IG_LatentCmds, 0);
        DynamicMenu_AddItem("Cg_PlOut", IG_PLOUT, IG_PlOut, 0);
        DynamicMenu_AddItem("DebugLag", IG_DEBUGLAG, IG_DebugLag, 0);

    }

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}

/*
=================
IG_Close_Event
=================
*/
static void IG_Close_Event( int index ) {
    UI_ForceMenuOff();
}



/*
=================
InGameDynamic_InitPrimaryMenu
=================
*/
static void InGameDynamic_InitPrimaryMenu( void ) {
    int depth;
    int gametype;
    int team;
    qboolean localserver;
    qboolean voting;
    char buf[MAX_INFO_STRING];

    team = UI_CurrentPlayerTeam();
    gametype = DynamicMenu_ServerGametype();

    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Close!", IGM_CLOSE, (voidfunc_f)0, IG_Close_Event);
    DynamicMenu_AddItem("Start", IGM_START, IG_Start_SubMenu, 0);

    /*if((team == TEAM_SPECTATOR)|| (team == TEAM_SPECTATOR_RED)
    	|| (team == TEAM_SPECTATOR_BLUE) || (team == TEAM_FREE))*/
    DynamicMenu_AddItem("Camera", IGM_CAMERA, IG_Camera_Commands_Submenu, 0);//INCIN
	
	depth = DynamicMenu_Depth();
	if( (UI_CurrentPlayerTeam() != TEAM_SPECTATOR) &&
		(UI_CurrentPlayerTeam() != TEAM_SPECTATOR_RED) &&
		(UI_CurrentPlayerTeam() != TEAM_SPECTATOR_BLUE)) {
		DynamicMenu_SetFlags(depth, IGM_CAMERA, QMF_GRAYED);
	}

    if(gametype >= GT_TEAM) {
        DynamicMenu_AddItem("Teams Colors", IGM_COLORS, IG_Forcecolor_SubMenuInit, 0);//INCIN
        DynamicMenu_AddItem("Sounds", IGM_SOUNDS, IG_SoundCmds_MenuInit, 0);//INCIN
    }
	DynamicMenu_AddItem("Models", IGM_PLAYERMODELS,IG_PlayerModels_MenuInit, 0);
    DynamicMenu_AddItem("Unlagged", IGM_UNLAGGED, IG_Unlagged_SubmenuInit, 0);

    //DynamicMenu_AddItem("Bots", IGM_BOTS, IG_AddBot_SubMenu, 0);
    if(gametype >= GT_TEAM) {
        DynamicMenu_AddItem("Team Orders...", IGM_TEAMORDERS, (voidfunc_f)0, IG_TeamOrders_Event);
    }
    DynamicMenu_AddItem("Setup", IGM_SETUP, IG_Setup_SubMenu, 0);
    DynamicMenu_AddItem("Map", IGM_MAP, IG_Map_SubMenu, 0);
    DynamicMenu_AddItem("Vote", IGM_VOTE, IG_Vote_SubMenu, 0);
    DynamicMenu_AddItem("Call Vote", IGM_CALLVOTE, IG_CallVote_SubMenu, 0);
    DynamicMenu_AddItem("Exit!", IGM_EXIT, IG_Exit_SubMenu, 0);

    
    gametype = trap_Cvar_VariableValue("g_gametype");

    if (gametype < GT_TEAM || team == TEAM_SPECTATOR ||
            team == TEAM_SPECTATOR_RED || team == TEAM_SPECTATOR_BLUE) {
        DynamicMenu_SetFlags(depth, IGM_TEAMORDERS, QMF_GRAYED);
    }

    // disable map commands if non-local server
    localserver = trap_Cvar_VariableValue( "sv_running" );
    if( !localserver) {
        DynamicMenu_SetFlags(depth, IGM_MAP, QMF_GRAYED);
    }

    // singleplayer/spec protects voting menu (otherwise it could be used to cheat)
    if (gametype == GT_SINGLE_PLAYER || team == TEAM_SPECTATOR ||
            team == TEAM_SPECTATOR_RED || team == TEAM_SPECTATOR_BLUE) {
        DynamicMenu_SetFlags(depth, IGM_CALLVOTE, QMF_GRAYED);
        DynamicMenu_SetFlags(depth, IGM_VOTE, QMF_GRAYED);
    }

    // bot manipulation
    if (!localserver || !trap_Cvar_VariableValue( "bot_enable" ) || (gametype == GT_SINGLE_PLAYER)) {
        DynamicMenu_SetFlags(depth, IGM_BOTS, QMF_GRAYED);
    }

    // disable vote menu if no voting
    voting = qfalse;
    trap_GetConfigString(CS_VOTE_TIME, buf, MAX_INFO_STRING);
    if (atoi(buf) != 0) {
        voting = qtrue;
    }
    trap_GetConfigString(CS_TEAMVOTE_TIME, buf, MAX_INFO_STRING);
    if (atoi(buf) != 0) {
        voting = qtrue;
    }

    if (!voting) {
        DynamicMenu_SetFlags(depth, IGM_VOTE, QMF_GRAYED);
    }

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}




/*
=================
UI_InGameDynamic
=================
*/
void UI_InGameDynamic( void ) {
    DynamicMenu_MenuInit(qfalse, qtrue);
    InGameDynamic_InitPrimaryMenu();
}




/*
=================
UI_InGameMenu
=================
*/
void UI_InGameMenu( void ) {
    if (uie_ingame_dynamicmenu.integer) {
        UI_InGameDynamic();
    } else {
        // force as top level menu
        uis.menusp = 0;

        // set menu cursor to a nice location
        uis.cursorx = 319;
        uis.cursory = 80;

        InGame_MenuInit();
        UI_PushMenu( &s_ingame.menu );
    }
}






/*
=======================================================================
 
INGAME DYNAMIC BOT COMMAND MENU
 
=======================================================================
*/


// stores current gametype for fast access by menus
static int botcommandmenu_gametype = 0;



enum {
    COM_WHOLEADER,
    COM_IAMLEADER,
    COM_QUITLEADER,
    COM_MYTASK
} commandId;


static char* commandString[] = {
                                   "Who is the leader", // COM_WHOLEADER
                                   "I am the leader",	// COM_IAMLEADER
                                   "I quit being the leader",	// COM_QUITLEADER
                                   "What is my job",	// COM_MYTASK
                                   0
                               };


enum {
    BC_NULL,
    BC_FOLLOW,
    BC_HELP,
    BC_GET,
    BC_PATROL,
    BC_CAMP,
    BC_HUNT,
    BC_DISMISS,
    BC_REPORT,
    BC_POINT,
    BC_GETFLAG,
    BC_DEFENDBASE
} botCommandId;


static char* botCommandStrings[] = {
                                       "", // BC_NULL
                                       "%s follow %s", // BC_FOLLOW
                                       "%s help %s", // BC_HELP
                                       "%s get %s", // BC_GET
                                       "%s patrol from %s to %s", // BC_PATROL
                                       "%s camp %s", // BC_CAMP
                                       "%s kill %s", // BC_HUNT
                                       "%s dismissed", // BC_DISMISS
                                       "%s report", // BC_REPORT
                                       "%s lead the way", // BC_POINT
                                       "%s get the flag",	// BC_GETFLAG
                                       "%s defend the base",	// BC_DEFENDBASE
                                       0
                                   };







/*
=================
BotCommand_MenuClose
=================
*/
void BotCommand_MenuClose( void ) {
    if (uie_autoclosebotmenu.integer)
        UI_PopMenu();
}





/*
=================
DM_BotPlayerTarget_Event
 
Issues a command to a bot that needs a target
Assumes index is the object, parent is the command,
and parent of parent is the bot
=================
*/
static void DM_BotPlayerTarget_Event( int index) {
    int depth;
    int bot, cmd;
    const char* s;

    depth = DynamicMenu_DepthOfIndex(index);

    if (depth != DynamicMenu_Depth() || depth < 3) {
        Com_Printf("BotPlayerTarget_Event: index %i at wrong depth (%i)\n", index, depth);
        BotCommand_MenuClose();
        return;
    }

    // validate command
    cmd = DynamicMenu_ActiveIdAtDepth(depth - 1);
    switch (cmd) {
    case BC_FOLLOW:
    case BC_HELP:
    case BC_HUNT:
        break;
    default:
        Com_Printf("BotPlayerTarget_Event: unknown command id %i\n", cmd);
        BotCommand_MenuClose();
        return;
    };

    // get the parent bot, insert it and item into command string
    bot = DynamicMenu_ActiveIndexAtDepth(depth - 2);
    s = va(botCommandStrings[cmd], DynamicMenu_StringAtIndex(bot),
           DynamicMenu_StringAtIndex(index));

    // issue the command
    BotCommand_MenuClose();
    trap_Cmd_ExecuteText( EXEC_APPEND, va("say_team \"%s\"\n", s));
}





/*
=================
DM_BotItemItemTarget_Event
 
Issues a command to a bot that needs two targets
Assumes index and parent are the objects, grandparent
is the command, and great-grandparent is the bot
=================
*/
static void DM_BotItemItemTarget_Event( int index) {
    int depth;
    int bot, cmd, item, item2;
    const char* s;

    depth = DynamicMenu_DepthOfIndex(index);

    if (depth != DynamicMenu_Depth() || depth < 4) {
        Com_Printf("BotItemItemTarget_Event: index %i at wrong depth (%i)\n", index, depth);
        BotCommand_MenuClose();
        return;
    }

    // validate command
    cmd = DynamicMenu_ActiveIdAtDepth(depth - 2);
    switch (cmd) {
    case BC_PATROL:
        break;
    default:
        Com_Printf("BotItemItemTarget_Event: unknown command id %i\n", cmd);
        BotCommand_MenuClose();
        return;
    };

    // get the parent bot, insert it and item into command string
    bot = DynamicMenu_ActiveIndexAtDepth( depth - 3 );
    item = DynamicMenu_ActiveIdAtDepth(depth - 1);
    item2 = DynamicMenu_IdAtIndex(index);

    s = va(botCommandStrings[cmd], DynamicMenu_StringAtIndex(bot),
           DynamicMenu_ItemShortname(item), DynamicMenu_ItemShortname(item2));

    // issue the command
    BotCommand_MenuClose();
    trap_Cmd_ExecuteText( EXEC_APPEND, va("say_team \"%s\"\n", s));
}




/*
=================
DM_BotItemTarget_Event
 
Issues a command to a bot that needs a target
Assumes index is the object, parent is the command,
and parent of parent is the bot
=================
*/
static void DM_BotItemTarget_Event( int index) {
    int depth;
    int bot, cmd, item;
    const char* s;
    const char* item_str;

    depth = DynamicMenu_DepthOfIndex(index);

    if (depth != DynamicMenu_Depth() || depth < 3) {
        Com_Printf("BotItemTarget_Event: index %i at wrong depth (%i)\n", index, depth);
        BotCommand_MenuClose();
        return;
    }

    // validate command
    cmd = DynamicMenu_ActiveIdAtDepth(depth - 1);
    switch (cmd) {
    case BC_GET:
    case BC_CAMP:
        break;
    default:
        Com_Printf("BotItemTarget_Event: unknown command id %i\n", cmd);
        BotCommand_MenuClose();
        return;
    };

    // get the parent bot, insert it and item into command string
    bot = DynamicMenu_ActiveIndexAtDepth(depth - 2);
    item = DynamicMenu_IdAtIndex(index);
    if (item < 0)
        item_str = DynamicMenu_StringAtIndex(index);
    else
        item_str = DynamicMenu_ItemShortname(item);

    s = va(botCommandStrings[cmd], DynamicMenu_StringAtIndex(bot), item_str);

    // issue the command
    BotCommand_MenuClose();
    trap_Cmd_ExecuteText( EXEC_APPEND, va("say_team \"%s\"\n", s));
}



/*
=================
DM_BotCommand_Event
 
Issues a command to a bot
=================
*/
static void DM_BotCommand_Event( int index ) {
    int depth;
    int bot, cmd;
    const char* s;

    depth = DynamicMenu_DepthOfIndex(index);

    if (depth != DynamicMenu_Depth() || depth < 2) {
        Com_Printf("BotCommand_Event: index %i at wrong depth (%i)\n", index, depth);
        BotCommand_MenuClose();
        return;
    }

    // validate command
    cmd = DynamicMenu_IdAtIndex(index);
    switch (cmd) {
    case BC_DISMISS:
    case BC_REPORT:
    case BC_POINT:
    case BC_GETFLAG:
    case BC_DEFENDBASE:
        break;
    default:
        Com_Printf("BotCommand_Event: unknown command (%i)\n", cmd);
        BotCommand_MenuClose();
        return;
    };

    // get the parent bot name, insert into command string
    bot = DynamicMenu_ActiveIndexAtDepth(depth - 1);
    s = va(botCommandStrings[cmd], DynamicMenu_StringAtIndex(bot));

    // issue the command
    BotCommand_MenuClose();
    trap_Cmd_ExecuteText( EXEC_APPEND, va("say_team \"%s\"\n", s));
}





/*
=================
DM_Command_Event
 
Issues a command without target
=================
*/
static void DM_Command_Event( int index ) {
    int depth;
    int cmd;
    //	const char* s;

    depth = DynamicMenu_DepthOfIndex(index);

    if (depth != DynamicMenu_Depth()) {
        Com_Printf("Command_Event: index %i at wrong depth (%i)\n", index, depth);
        BotCommand_MenuClose();
        return;
    }

    // validate command
    cmd = DynamicMenu_IdAtIndex(index);
    switch (cmd) {
    case COM_WHOLEADER:
    case COM_IAMLEADER:
    case COM_QUITLEADER:
    case COM_MYTASK:
        break;
    default:
        Com_Printf("Command_Event: unknown command (%i)\n", cmd);
        BotCommand_MenuClose();
        return;
    };

    // issue the command
    BotCommand_MenuClose();
    trap_Cmd_ExecuteText( EXEC_APPEND, va("say_team \"%s\"\n", commandString[cmd]));
}



/*
=================
DM_Close_Event
=================
*/
static void DM_Close_Event( int index ) {
    UI_PopMenu();
}





/*
=================
DM_TeamList_SubMenu
=================
*/
static void DM_TeamList_SubMenu( void ) {
    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("me", 0, (voidfunc_f)0, DM_BotPlayerTarget_Event);
    DynamicMenu_AddListOfPlayers(PT_FRIENDLY|PT_EXCLUDEGRANDPARENT, (voidfunc_f)0, DM_BotPlayerTarget_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}




/*
=================
DM_ItemPatrol2_SubMenu
=================
*/
static void DM_ItemPatrol2_SubMenu( void ) {
    int exclude;
    //	int index;
    int depth;

    DynamicMenu_SubMenuInit();

    depth = DynamicMenu_Depth() - 1;
    exclude = DynamicMenu_ActiveIdAtDepth(depth);
    //	index = s_dynamic.active[depth - 1];	// previous menu level
    //	exclude = s_dynamic.data[index].id;
    DynamicMenu_AddListOfItems(exclude, (voidfunc_f)0, DM_BotItemItemTarget_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}





/*
=================
DM_ItemPatrol_SubMenu
=================
*/
static void DM_ItemPatrol_SubMenu( void ) {
    DynamicMenu_SubMenuInit();
    DynamicMenu_AddListOfItems(-1, DM_ItemPatrol2_SubMenu, 0);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}





/*
=================
DM_CampItemList_SubMenu
=================
*/
static void DM_CampItemList_SubMenu( void ) {
    DynamicMenu_SubMenuInit();
    DynamicMenu_AddItem("here", -1, (voidfunc_f)0, DM_BotItemTarget_Event);
    DynamicMenu_AddItem("there", -1, (voidfunc_f)0, DM_BotItemTarget_Event);
    DynamicMenu_AddListOfItems(-1, (voidfunc_f)0, DM_BotItemTarget_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}







/*
=================
DM_ItemList_SubMenu
=================
*/
static void DM_ItemList_SubMenu( void ) {
    DynamicMenu_SubMenuInit();
    DynamicMenu_AddListOfItems(-1, (voidfunc_f)0, DM_BotItemTarget_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}





/*
=================
DM_EnemyList_SubMenu
=================
*/
static void DM_EnemyList_SubMenu( void ) {
    DynamicMenu_SubMenuInit();
    DynamicMenu_AddListOfPlayers(PT_ENEMY, (voidfunc_f)0, DM_BotPlayerTarget_Event);

    DrawBG();

    DynamicMenu_FinishSubMenuInit();
}



/*
=================
DM_CommandList_SubMenu
=================
*/
static void DM_CommandList_SubMenu( void ) {
    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Report", BC_REPORT, (voidfunc_f)0, DM_BotCommand_Event);
    DynamicMenu_AddItem("Help", BC_HELP, DM_TeamList_SubMenu, 0);
    //incin added rtf mode
    if (botcommandmenu_gametype == GT_CTF) {
        DynamicMenu_AddItem("Capture Flag", BC_GETFLAG, (voidfunc_f)0, DM_BotCommand_Event);
        DynamicMenu_AddItem("Defend Base", BC_DEFENDBASE, (voidfunc_f)0, DM_BotCommand_Event);
    } else if(botcommandmenu_gametype == GT_RTF) {
        DynamicMenu_AddItem("Capture Flag", BC_GETFLAG, (voidfunc_f)0, DM_BotCommand_Event);
        DynamicMenu_AddItem("Defend Base", BC_DEFENDBASE, (voidfunc_f)0, DM_BotCommand_Event);
    }

    DynamicMenu_AddItem("Follow", BC_FOLLOW, DM_TeamList_SubMenu, 0);
    DynamicMenu_AddItem("Get", BC_GET, DM_ItemList_SubMenu, 0);
    DynamicMenu_AddItem("Patrol", BC_PATROL, DM_ItemPatrol_SubMenu, 0);
    DynamicMenu_AddItem("Camp", BC_CAMP, DM_CampItemList_SubMenu, 0);
    DynamicMenu_AddItem("Hunt", BC_HUNT, DM_EnemyList_SubMenu, 0);
    DynamicMenu_AddItem("Point+", BC_POINT, (voidfunc_f)0, DM_BotCommand_Event);
    DynamicMenu_AddItem("Dismiss", BC_DISMISS, (voidfunc_f)0, DM_BotCommand_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}


/*
=================
BotCommand_InitPrimaryMenu
=================
*/
static void BotCommand_InitPrimaryMenu( void ) {
    DynamicMenu_SubMenuInit();

    DynamicMenu_AddItem("Close!", 0, (voidfunc_f)0, DM_Close_Event);
    DynamicMenu_AddItem("Everyone", 0, DM_CommandList_SubMenu, 0);
    DynamicMenu_AddListOfPlayers(PT_FRIENDLY|PT_BOTONLY, DM_CommandList_SubMenu, 0);
    DynamicMenu_AddItem("Leader?", COM_WHOLEADER, (voidfunc_f)0, DM_Command_Event);
    //incin added rtf mode
    if (botcommandmenu_gametype == GT_CTF || botcommandmenu_gametype == GT_RTF) {
        DynamicMenu_AddItem("My task?", COM_MYTASK, (voidfunc_f)0, DM_Command_Event);
    }

    DynamicMenu_AddItem("Lead", COM_IAMLEADER, (createHandler)0, DM_Command_Event);
    DynamicMenu_AddItem("Resign", COM_QUITLEADER, (createHandler)0, DM_Command_Event);

    DrawBG();
    DynamicMenu_FinishSubMenuInit();
}







/*
=================
UI_BotCommand_Cache
=================
*/
void UI_BotCommand_Cache( void ) {}




/*
=================
UI_BotCommandMenu
=================
*/
void UI_BotCommandMenu( void ) {
    if (UI_CurrentPlayerTeam() == TEAM_SPECTATOR)
        return;

    if (UI_CurrentPlayerTeam() == TEAM_SPECTATOR_RED)
        return;

    if (UI_CurrentPlayerTeam() == TEAM_SPECTATOR_BLUE)
        return;

    botcommandmenu_gametype = DynamicMenu_ServerGametype();
    if ( botcommandmenu_gametype< GT_TEAM)
        return;

    DynamicMenu_MenuInit(qfalse, qtrue);
    BotCommand_InitPrimaryMenu();
}



/*
=================
UI_BotCommandMenu_f
=================
*/
void UI_BotCommandMenu_f( void ) {
    UI_BotCommandMenu();
}






