/***************************************************************************
 *
 * screens.c
 *
 ***************************************************************************
 *
 * edit-player shell screens
 *
 ***************************************************************************/

/*
 * includes
 */

#include "generic.h"
#include "gameinc.h"
#include "teamdata.h"
#include "shellres.h"
#include "shell.h"
#include "stats.h"
#include "shellgfx.h"
#include "states.h"
#include "screenb.h"
#include "screeni.h"
#include "shadfont.h"
#include "fontcode.h"
//#include "../../bball/n64/shlplyr.h"
#include "config.h"
#include "popup.h"
#include "playgfx.h"
#include "help.h"

#define MJK_KLUDGE	0	// edited player is a long thread

#define TRUE_SHELL_PLAYER	0

extern 	Vp   vp;

 /*
 * defines
 */

#define TEAM_FREEAGENTS		34

#define FLG_CTR		1
#define FLG_HI		2
#define FLG_SHADOW	4
#define FLG_XR		8


#define MIN_HEIGHT			63
#define MAX_HEIGHT			94
#define MIN_AGE				17
#define MAX_AGE				39

#define MIN_WEIGHT			100
#define MAX_WEIGHT			350
#define NUM_CUSTOM_HEADS	20
#define NUM_CUSTOM_HAIR		(6*9)


#define ROOKIE_5_POSITIONS	1	// for conditional compiling


/*
 * typedefs
 */

/*
 * structures
 */

typedef struct stringXY {

	char *title;
	SW		x;
	SW		y;	
} 	stringXY_t;



/*
 * globals
 */

extern PlyrRomData_T ShellRomData;	// in min.c

unsigned char	headMapBuffer[(64*32)+(8*8)];
extern Gfx *PlayGfx_ShellDraw( Gfx *gp, s32 db, dyn *d );

int dataChanged;
int PoolPoints, MaxPoolPoints;

int pendingPopup=0;
static char releasePlayerWarningTitle[]="MINIMUM TEAM PLAYERS";
static char signedPlayerWarningTitle[]="SIGNED PLAYER";
static char releasePlayerWarningText[256];
static char okButtonText[]=
{
	"[FP" MPAL_YELLOW  "]"
	"[DEF]Continue[ESC]"
};
static char yesNoButtonText[]=
{
	"[FP" MPAL_YELLOW  "]"
	"[BTN]Yes[DEF]No[ESC]"
};

static char overwritePlayerWarningTitle[]="DELETE PLAYER";
static char overwritePlayerWarningText[]=
{
	"This will clear any existing\n"
	"player data in this slot.\n\n"
	"Proceed?"
	"[FP" MPAL_YELLOW  "]"
	"[BTN]Yes[DEF]No[ESC]"
};

static char overwriteCUTitle[]="CUSTOM USER";
static char overwriteCUWarningText[]=
{
	"Are you sure you want to\n"
	"delete this custom user?\n\n"
	"[FP" MPAL_YELLOW  "]"
	"[BTN]Yes[DEF]No[ESC]"
};

static char fullCUWarningText[]=
{
	"Custom users are full.\n"
	"You must delete an existing\n"
	"custom user in order to\n"
	"create a new custom user.\n\n"
	"[FP" MPAL_YELLOW  "]"
	"[DEF]Continue[ESC]"
};



//static char CareerPlayerTitle[]="CAREER PLAYER";
static char editPlayerTitle[]="EDIT PLAYER";
static char newPlayerTitle[]="NEW PLAYER";
static char keepPlayerText[]=
{
	"Keep changes?"
	"[FP" MPAL_YELLOW  "]"
	"[DEF]Yes[BTN]No[ESC]"
};
static char noNameText[]=
{
	"You must enter a valid\n"
	"First Name and Last Name\n"
	"for this player.\n"
	"[FP" MPAL_YELLOW  "]"
	"[DEF]Continue[ESC]"
};

/**********
static char RookieCreationText[]=
{
//	"Create a Career Mode Rookie\n"
	"or a Standard Player?\n"
	"[FP" MPAL_YELLOW  "]"
	"[BTN]Rookie[DEF]Standard[ESC]"
};
**********/

/**********
static char  NoModifyText [] =
{
	"You cannot modify a\n"
//	"career mode rookie.\n"
	"created rookie.\n"
	"[FP" MPAL_YELLOW  "]"
	"[DEF]Continue[ESC]"
};
*******/
static char  NoModifyText [] =
{
	"You cannot modify this\n"
//	"attribute of a created rookie.\n"
	"attribute of a Career Player.\n"
	"[FP" MPAL_YELLOW  "]"
	"[DEF]Continue[ESC]"
};


static char  NoModifyText1 [] =
{
	"You cannot modify any\n"
//	"abilities of a created rookie.\n"
	"abilities of a Career Player.\n"
	"[FP" MPAL_YELLOW  "]"
	"[DEF]Continue[ESC]"
};

static char  NotANameText [] =
{
	"This is not a real name.\n"
	"Please try again.\n"
	"[FP" MPAL_YELLOW  "]"
	"[DEF]Continue[ESC]"
};



#if ROOKIE_5_POSITIONS	//--------- conditional compile  ----------------------------

#define NUM_EDIT_POSITIONS	5



#define NUM_LR_CHOICES	4

static char *LRText[NUM_LR_CHOICES] = {"None", "Left", "Right", "Both"};


#define NUM_SOCK_CHOICES	2

static char *SockText[NUM_SOCK_CHOICES] = {"Low", "High"};


static int DefaultHeightByPosition[NUM_EDIT_POSITIONS] = { 	

	75-MIN_HEIGHT,	// p guard
	78-MIN_HEIGHT,	// s guard
	80-MIN_HEIGHT,	// s forward
	81-MIN_HEIGHT,	// p forward
	85-MIN_HEIGHT,	// center
};

static int DefaultWeightByPosition[NUM_EDIT_POSITIONS] = { 	
	200-MIN_WEIGHT,	// p guard
	215-MIN_WEIGHT,	// s guard
	225-MIN_WEIGHT,	// s forward
	240-MIN_WEIGHT,	// p forward
	260-MIN_WEIGHT,	// center
};


/********
static int DefaultHeightByPosition[NUM_EDIT_POSITIONS] = { 	

	75-MIN_HEIGHT,	// p guard
	79-MIN_HEIGHT,	// s guard
	81-MIN_HEIGHT,	// s forward
	81-MIN_HEIGHT,	// p forward
	85-MIN_HEIGHT,	// center
};

static int DefaultWeightByPosition[NUM_EDIT_POSITIONS] = { 	
	200-MIN_WEIGHT,	// p guard
	215-MIN_WEIGHT,	// s guard
	225-MIN_WEIGHT,	// s forward
	225-MIN_WEIGHT,	// p forward
	260-MIN_WEIGHT,	// center
};
********/


#else	//--------- conditional compile  ----------------------------

#define NUM_EDIT_POSITIONS	3

static	char *posNames[NUM_EDIT_POSITIONS] = { "Center","Forward","Guard"};


static int DefaultHeightByPosition[NUM_EDIT_POSITIONS] = { 	
	84-MIN_HEIGHT,	// center
	80-MIN_HEIGHT,	// forward
	74-MIN_HEIGHT,	// guard
};

static int DefaultWeightByPosition[NUM_EDIT_POSITIONS] = { 	
	280-MIN_WEIGHT,	// center
	250-MIN_WEIGHT,	// forward
	195-MIN_WEIGHT,	// guard
};

#endif	//--------- conditional compile  ----------------------------


static unsigned char		barCols[16]=
{
	0x80,	0x00,	0x00,	0xFF,
	0x80,	0x00,	0x00,	0xFF,
	0x80,	0x00,	0x00,	0xFF,
	0x80,	0x00,	0x00,	0xFF,
};

static int			clampSound;
static int			pendingLoadDelay;
static char			*editString;

static int			editGotData;
//static int			editNewCreation;

#define MAX_CHARS_IN_CUSTOM_NAME	10	//12		 - in both 1st and last (total = x2)
static signed char		editFirstName[16];
static signed char		editLastName[16];
static signed char		editAge;
static signed char		editYears;
static signed char    		editTeam;
static signed char		editNo;
static signed char		editPos;
static signed char		editHeight;
static signed int		editWeight;
static signed char		editHead;
static signed char		editHair;
static signed char		editRookieMode;
static int			editScale;
static signed char		editBodyType;
static signed char		editHeadType=3;
static signed char		editSkin;

static signed char		editWrist;
static signed char		editArms;
static signed char		editKnees;
static signed char		editSocks;

static signed char		editHairStyle;
static signed char		editHairColor;


#define	NUM_HAIR_STYLES		9
#define	NUM_HAIR_COLORS		6


global PlyrRomData_T * gCustomPlayerPtr;

global signed char		editAbilities[NUM_ABILITIES];
//static signed char		newAbilities[NUM_ABILITIES];	// for rookie RolePlay mode

static int		editNoModifyFlag;	// set if trying to re-edit a role-playing rookie
static int		editNewlyCreated;
global int		CreatePlayerMode;


static int			shellPlayerLoaded=0;
static int			shellPlayerTeam=-2;

static int			opt,selSlot=0,numSlots;
static int			s1Opt=0,s2Opt=0;
static int		editLastX,editLastY,editLastW,editLastH;
static int		editHiX,editHiY,editHiW,editHiH;

/*************
static unsigned char	greyBox[]=
{
	RGB_TRANS_DKGRY,RGB_TRANS_DKGRY,RGB_TRANS_DKGRY,RGB_TRANS_DKGRY,
	RGB_SOLID_YEL
};
static unsigned char	blackBox[]=
{
	RGB_SOLID_BLK,RGB_SOLID_BLK,RGB_SOLID_BLK,RGB_SOLID_BLK,
	RGB_SOLID_YEL
};
static unsigned char	blueBox[]=
{
	RGB_TRANS_BLU,RGB_TRANS_BLU,RGB_TRANS_BLU,RGB_TRANS_BLU,
	RGB_SOLID_YEL
};
***********/

static char editValidLetters[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ'-. ";

/*
 * function prototypes
 */

void SetThinChap(void);


SB RookieBaseAbilities[NUM_ABILITIES][NUM_EDIT_POSITIONS] = {
	
	2*25,3*25,2*25,1*25,1*25,	// ABILITY_RANGE		0
	60,	60,	55,	55,	60,			// ABILITY_SHOOT		1
	35,	40,	25,	15,	10,			// ABILITY_3PT			2
	65,	65,	60,	60,	55,			// ABILITY_FT			3
	70,	60,	35,	30,	25,			// ABILITY_DRIB		4
	65,	45,	30,	25,	20,			// ABILITY_PASS		5
	70,	70,	60,	50,	40,			// ABILITY_SPEED		6
	60,	65,	70,	70,	75,			// ABILITY_JUMP		7
	15,	30,	45,	60,	70,			// ABILITY_REB			8
	25,	35,	55,	60,	70,			// ABILITY_STRENGTH	9
	30, 60,	70,	75,	65,			// ABILITY_DUNK		10
	50,	35,	15,	10,	10,			// ABILITY_STEAL		11
	15,	20,	55,	65,	70,			// ABILITY_BLOCK		12
	70,	50,	50,	45,	40,			// ABILITY_STAMINA		13
};


extern int PosIndexToTruePosition(int index);	//in subs.c	
extern int TranslatePositionToIndex(int p);					//in subs.c	


//  -----------------  stub functions  -------------------------------


int ShellPlayerLoadMain(int x,int y,int w,int h,int s)
{
	return(0);
}
void ShellPlayerFreeMain(void){};

int ShellPlayerLoadTeamTextures(int teamId)
{
	return(0);
}	
void ShellPlayerFreeTeamTextures(void) {};

Gfx *ShellPlayerRender(Gfx *gp,dyn *d,int draw_buffer)
{
	return(gp);
}

void ShellPlayerSetNumber(int num) {};
void ShellPlayerSetName(char *s) {};
void ShellPlayerSetBody(int scale,int body,int head) {};
void ShellPlayerSetFace(unsigned char *hair,unsigned char *face) {};

//  -----------------  end  stub functions  -------------------------------



/*------------------------------------------------------------------------------
 *								 code
------------------------------------------------------------------------------ */


void SetEditAbilitiesByPosition(int positionindex)
{
int i;

	if(CreatePlayerMode == CREATE_PLAYER_CAREER)	//editRookieMode)
	{
		for(i=0; i<NUM_ABILITIES; i++)
		{
#if defined(DEBUG)
			editAbilities[i] = 50;	// test only
			editAbilities[i] = RookieBaseAbilities[i][positionindex];
#else
			editAbilities[i] = RookieBaseAbilities[i][positionindex];
#endif
		}
	}
}





Gfx *RenderBAR(Gfx *gp,int x,int y,int w,int h,unsigned char *cols)
{
	int		z;
	extern Vtx	*pcl__gVtx;

	// Add window offset.
	x += si___gWindowX;
	y += si___gWindowY;

	// Draw box.
	z = 20;
	x = x - currentProcess->ScreenX/2;
	y = currentProcess->ScreenY/2 - y;

	pcl__gVtx[0].v.ob[0] = x;		// x
	pcl__gVtx[0].v.ob[1] = y;		// y
	pcl__gVtx[0].v.ob[2] = z;		// z
	pcl__gVtx[0].v.flag  = 0;		// flags
	pcl__gVtx[0].v.tc[0] = 0;		// tx
	pcl__gVtx[0].v.tc[1] = 0;		// ty
	pcl__gVtx[0].v.cn[0] = cols[0];
	pcl__gVtx[0].v.cn[1] = cols[1];
	pcl__gVtx[0].v.cn[2] = cols[2];
	pcl__gVtx[0].v.cn[3] = cols[3];

	pcl__gVtx[1].v.ob[0] = x+w;		// x
	pcl__gVtx[1].v.ob[1] = y;		// y
	pcl__gVtx[1].v.ob[2] = z;		// z
	pcl__gVtx[1].v.flag  = 0;		// flags
	pcl__gVtx[1].v.tc[0] = 0;		// tx
	pcl__gVtx[1].v.tc[1] = 0;		// ty
	pcl__gVtx[1].v.cn[0] = cols[4];
	pcl__gVtx[1].v.cn[1] = cols[5];
	pcl__gVtx[1].v.cn[2] = cols[6];
	pcl__gVtx[1].v.cn[3] = cols[7];

	pcl__gVtx[2].v.ob[0] = x+w;		// x
	pcl__gVtx[2].v.ob[1] = y-h;		// y
	pcl__gVtx[2].v.ob[2] = z;		// z
	pcl__gVtx[2].v.flag  = 0;		// flags
	pcl__gVtx[2].v.tc[0] = 0;		// tx
	pcl__gVtx[2].v.tc[1] = 0;		// ty
	pcl__gVtx[2].v.cn[0] = cols[8];
	pcl__gVtx[2].v.cn[1] = cols[9];
	pcl__gVtx[2].v.cn[2] = cols[10];
	pcl__gVtx[2].v.cn[3] = cols[11];

	pcl__gVtx[3].v.ob[0] = x;		// x
	pcl__gVtx[3].v.ob[1] = y-h;		// y
	pcl__gVtx[3].v.ob[2] = z;		// z
	pcl__gVtx[3].v.flag  = 0;		// flags
	pcl__gVtx[3].v.tc[0] = 0;		// tx
	pcl__gVtx[3].v.tc[1] = 0;		// ty
	pcl__gVtx[3].v.cn[0] = cols[12];
	pcl__gVtx[3].v.cn[1] = cols[13];
	pcl__gVtx[3].v.cn[2] = cols[14];
	pcl__gVtx[3].v.cn[3] = cols[15];

	//

	gDPPipeSync(gp++);

	gDPSetAlphaCompare(gp++,
			G_AC_NONE);
	gDPSetRenderMode(gp++,
			G_RM_XLU_SURF,
			G_RM_XLU_SURF2);
	gDPSetCombineMode(gp++,
			G_CC_SHADE,
			G_CC_SHADE);

	gSPSetGeometryMode(gp++,
		G_SHADE | G_SHADING_SMOOTH);

	gSPVertex(gp++,
		(Vtx *) pcl__gVtx, 4, 0);

	gSP2Triangles(gp++,
		0, 3, 2, 0, 2, 1, 0, 0);

	// Update the vertex pointer.

	pcl__gVtx += 4;

	// All Done.

	return (gp);
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int PlayerDefined(int slot)
{
	PlyrCustomInfo_T *c;

	c = (PlyrCustomInfo_T *)(&pacl_gCustom[slot].cl___pStatNBA);

	pacl_gCustom[slot].pcz__pSName = c->asb__pSName;
	pacl_gCustom[slot].pcz__pCName = c->asb__pCName;

	if(!pacl_gCustom[slot].pcz__pSName[0])
	{
		return(0);
	}
	
	return(1);
}



int GetCustomPlayerHead(int trueplyrindex)	//valid 1 to 384(si___gPlyrRomCnt) - #385 is 1st custom player
{
PlyrCustomInfo_T *c;

int	custompindex = trueplyrindex - si___gPlyrRomCnt - 1;
int head;

	if(custompindex < ZERO || custompindex >= CUSTOM_PLYRS)
	{	//error
		return(0);
	}
	
	if(ShellPlayerOnScreen)
	{
		c = (PlyrCustomInfo_T *)(&ShellRomData.cl___pStatNBA);
	}
	else
	{
		c = (PlyrCustomInfo_T *)(&pacl_gCustom[custompindex].cl___pStatNBA);
	}
		
	return(c->ub___pCustomHeadType);
//	head = (c->ub___pCustomHeadType & EDIT_HEAD_MASK) >> EDIT_HEAD_SHIFT ;
//	return(head);
}

int GetCustomPlayerHair(int trueplyrindex)	//valid 1 to 384(si___gPlyrRomCnt) - #385 is 1st custom player
{
PlyrCustomInfo_T *c;

int	custompindex = trueplyrindex - si___gPlyrRomCnt - 1;
int head;

	if(custompindex < ZERO || custompindex >= CUSTOM_PLYRS)
	{	//error
		return(0);
	}
	
	if(ShellPlayerOnScreen)
	{
		c = (PlyrCustomInfo_T *)(&ShellRomData.cl___pStatNBA);
	}
	else
	{
		c = (PlyrCustomInfo_T *)(&pacl_gCustom[custompindex].cl___pStatNBA);
	}
		
	return(c->ub___pCustomHairType);
//	head = (c->ub___pCustomHeadType & EDIT_HEAD_MASK) >> EDIT_HEAD_SHIFT ;
//	return(head);
}



/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

#if 0//phil
void UpdateHead(void)
{
#if TRUE_SHELL_PLAYER	
	LoadCustomPlyrTex(NULL,editHead,headMapBuffer);
	ShellPlayerSetFace(&headMapBuffer[64*32],headMapBuffer);
#endif
}
#endif

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

void ClearCustomPlayer(int slot)
{
	int		i;
	PlyrRomData_T	*rom;

	rom = &pacl_gCustom[slot];

	// if already on a team, remove!
	if(PlayerDefined(slot))
	{
		RosterMovePlyr(rom->ub___pTeam,
			       rom->uw___pIndx,
			       TEAM_XXX);		// put back on NOTHING team
	}

	// clear structure
	memset(rom,0,sizeof(PlyrRomData_T));

	ClearCustomPlayerStats(slot);
	
	// rebuild team info...
	LinkCustomPlyrs();
	FixPlyrRomTeams();
	sb___gRosterChanged=1;
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int GetEditAbilitiesAverage(void)
{
int t,i,aver;		// returns average of main abilities

	for(i=0,t=0; i<NUM_ABILITIES; i++)
	{
		t += editAbilities[i];
	}

	aver = t/NUM_ABILITIES;
	return(aver);	// return rating average

}




int MoveRomAbilitiesToEditAbilities(PlyrRomData_T * rom)
{
	editAbilities[ABILITY_RANGE]=	rom->ub___pAttrRange *25;
	editAbilities[ABILITY_SHOOT]=rom->ub___pAttrFG;
	editAbilities[ABILITY_3PT]=rom->ub___pAttr3P;
	editAbilities[ABILITY_FT]=rom->ub___pAttrFT;
	editAbilities[ABILITY_REB]=((int)rom->ub___pAttrRebOff+(int)rom->ub___pAttrRebDef)/2;
	editAbilities[ABILITY_STEAL]=rom->ub___pAttrSteal;
	editAbilities[ABILITY_PASS]=rom->ub___pAttrPass;
	editAbilities[ABILITY_BLOCK]=rom->ub___pAttrBlock;
	editAbilities[ABILITY_DRIB]=rom->ub___pAttrDribble;
	editAbilities[ABILITY_SPEED]=rom->ub___pAttrSpeed;
	editAbilities[ABILITY_JUMP]=rom->ub___pAttrJump;
	editAbilities[ABILITY_DUNK]=rom->ub___pAttrDunk;
	editAbilities[ABILITY_STRENGTH]=rom->ub___pAttrStrength;
	editAbilities[ABILITY_STAMINA]=rom->ub___pAttrStamina;

	return(GetEditAbilitiesAverage());	// return rating average

}





int MoveEditAbilitiesToRomAbilities(PlyrRomData_T * rom)
{

	rom->ub___pAttrRange =	editAbilities[ABILITY_RANGE] / 25;
	rom->ub___pAttrFG=		editAbilities[ABILITY_SHOOT];
	rom->ub___pAttr3P=		editAbilities[ABILITY_3PT];
	rom->ub___pAttrFT=		editAbilities[ABILITY_FT];
	rom->ub___pAttrRebOff=	editAbilities[ABILITY_REB];
		rom->ub___pAttrRebDef=	editAbilities[ABILITY_REB];

	rom->ub___pAttrSteal=editAbilities[ABILITY_STEAL];
	rom->ub___pAttrPass=editAbilities[ABILITY_PASS];
	rom->ub___pAttrBlock=editAbilities[ABILITY_BLOCK];
	rom->ub___pAttrDribble=editAbilities[ABILITY_DRIB];
	rom->ub___pAttrSpeed=editAbilities[ABILITY_SPEED];

	rom->ub___pAttrJump=editAbilities[ABILITY_JUMP];
	rom->ub___pAttrDunk=editAbilities[ABILITY_DUNK];
	rom->ub___pAttrStrength=editAbilities[ABILITY_STRENGTH];
	rom->ub___pAttrStamina=editAbilities[ABILITY_STAMINA];


	return(GetEditAbilitiesAverage());	// return rating average

}

//------------------------------------------------------
void  MoveRomDataToEditPlayerData(PlyrRomData_T *rom)
{
int i;

PlyrCustomInfo_T	*cplyr;

	// get following data directly from saved area
	cplyr = (PlyrCustomInfo_T *)(&rom->cl___pStatNBA);
	strcpy(editLastName, cplyr->asb__pSName);
	strcpy(editFirstName, cplyr->asb__pCName);
	editHead = cplyr->ub___pCustomHeadType;
	editHair = cplyr->ub___pCustomHairType;
	editHairStyle = editHair%NUM_HAIR_STYLES;
	editHairColor = editHair/NUM_HAIR_STYLES;


//	strcpy(editLastName,rom->pcz__pSName);
//	strcpy(editFirstName,rom->pcz__pCName);


	editTeam=(int)rom->ub___pTeam-1;
	editNo=rom->ub___pNum;
	
#if ROOKIE_5_POSITIONS
	i = (int)rom->ub___pPos;
	if(i<1)	i = POS_PG;	// it's ZERO on init
	editPos = TranslatePositionToIndex(i);
#else
	editPos = (int)rom->ub___pPos-1;
	if(editPos<0)
	{
		editPos=0;
	}
#endif	
	
	editHeight=(((int)rom->ub___pHgt>>4)*12 + ((int)rom->ub___pHgt&0xF))-MIN_HEIGHT;
	if(editHeight<0)
	{
		editHeight=0;
	}			
	
	editWeight=rom->ub___pWgt;

	editAge=rom->ub___pAge;

	if(editAge < MIN_AGE)
	{
		editAge = MIN_AGE;
	}
	else if(editAge > MAX_AGE)
	{
		editAge = MAX_AGE;
	}

	editYears=rom->ub___pExp;



//	rom->ub___pAcc0 = (editArms&3) + ((editWrist&3)<<2) + ((editKnee&3)<<4) + ((editSocks&1)<<6);
	editArms =  (rom->ub___pAcc0 >>0) & 3;
	editWrist = (rom->ub___pAcc0 >>2) & 3;
	editKnees = (rom->ub___pAcc0 >>4) & 3;
	editSocks = (rom->ub___pAcc0 >>6) & 1;
}

void SetTrueEditHair(void)
{

	editHair = editHairColor*NUM_HAIR_STYLES + editHairStyle;

}


void UpdateCustomPlayerRatings(PlyrRomData_T *rom)
{	// used when creating player and when rookie is improved
	//  allows "hidden" ratings to update based on averages of other ratings
int aver;

	// write edit attributes to Players final attribs
	aver = MoveEditAbilitiesToRomAbilities(rom);

	// figure "other" ratings
	rom->pAttrDefense = aver;

//	rom->ub___pAttrFoul=2;
//	rom->ub___pAttrGoto=1;
//	rom->ub___pPostUps=(MyRnd()%5)+1;	// 1-5


	if(aver >= 90)		rom->ub___pAttrGoto = 5;
	else if(aver >= 75)	rom->ub___pAttrGoto = 4;
	else if(aver >= 60)	rom->ub___pAttrGoto = 3;
	else if(aver >= 40)	rom->ub___pAttrGoto = 2;
	else rom->ub___pAttrGoto = 1;


	if(aver >= 78)		rom->ub___pAttrFoul = 1;
	else if(aver >= 45)	rom->ub___pAttrFoul = 2;
	else rom->ub___pAttrFoul = 3;

	if(aver >= 82)		rom->ub___pPostUps = 1;
	else if(aver >= 65)	rom->ub___pPostUps = 2;
	else if(aver >= 40)	rom->ub___pPostUps = 3;
	else rom->ub___pPostUps = 4;

	if(rom->ub___pAttrDunk >= 90)		rom->ub___pDunks=3;
	else if(rom->ub___pAttrDunk >= 65)	rom->ub___pDunks=2;
	else if(rom->ub___pAttrDunk >= 40)	rom->ub___pDunks=1;
	else					rom->ub___pDunks=0;


 // injury is now used in draft for best post players
//	rom->ub___pAttrInjury = aver;
	rom->ub___pAttrInjury = 
		(editAbilities[ABILITY_REB]+
		editAbilities[ABILITY_BLOCK]+
		editAbilities[ABILITY_JUMP]+
		editAbilities[ABILITY_DUNK]+
		editAbilities[ABILITY_STRENGTH]) /5;


/****
Post-Up -	1 = 400
		2 = 300
		3 = 200
		4 = 100


Foul -	1 = 150
		2 = 100
		3 = 50


Go To - 1 = 25
		2 = 75
		3 = 150
		4 = 250
		5 = 375
*******/


	rom->pAttrOverall = FigureOverallRating(rom);


}



void SaveEditAreaToCustomPlayerData(PlyrRomData_T *rom)
{
int aver;
PlyrCustomInfo_T	*c;

	// set thin data...
	SetThinChap();

	// clear out... nope... don't do that anymore - preserve index...
//	memset(rom,0,sizeof(PlyrRomData_T));

	// if this player was previously undefined, we need to add to the
	// new team... (probably free agent pool)
	if(!PlayerDefined(rom-pacl_gCustom))
	{
		RosterMovePlyr(TEAM_XXX,
			       rom->uw___pIndx,
		               editTeam+1);
	}


	// write name(s)
	c=(PlyrCustomInfo_T *)(&rom->cl___pStatNBA);
	strcpy(c->asb__pSName,editLastName);
	strcpy(c->asb__pCName,editFirstName);
	c->ub___pCustomHeadType =	 editHead;
	c->ub___pCustomHairType =	 editHair;
//	c->ub___pCustomHeadType =	 ((editHead << EDIT_HEAD_SHIFT) & EDIT_HEAD_MASK) 
//							   | ((editHair << EDIT_HAIR_SHIFT) & EDIT_HAIR_MASK) ;

	// set ptrs
	rom->pcz__pSName=c->asb__pSName;
	rom->pcz__pCName=c->asb__pCName;

	// write attributes
	UpdateCustomPlayerRatings(rom);

	// write other data
	rom->ub___pTeam=editTeam+1;
	rom->ub___pNum=editNo;

#if ROOKIE_5_POSITIONS
	rom->ub___pPos = PosIndexToTruePosition(editPos);	// in subs.c
#else
	rom->ub___pPos=editPos+1;
#endif	

	rom->ub___pHgt=(((editHeight+MIN_HEIGHT)/12)<<4) | ((editHeight+MIN_HEIGHT)%12);
	rom->ub___pWgt=editWeight;
	rom->ub___pAge=editAge;
	rom->ub___pExp=editYears;
	rom->ub___pSkin=aub__gCustomHeads[editHead][0];

	rom->ub___pAcc0 = (editArms&3) + ((editWrist&3)<<2) + ((editKnees&3)<<4) + ((editSocks&1)<<6);

	rom->ub___pAcc1=(aub__gCustomHeads[editHead][1]) | (editBodyType?64:0);

	// defaults

	// rebuild team info...
	LinkCustomPlyrs();
	FixPlyrRomTeams();

	// set flag
	sb___gRosterChanged=1;
}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/
#define START_ROOKIE_ATTR	25


void MoveCustomPlayerDataToEditArea(PlyrRomData_T *rom)	//ROMToMyStats(PlyrRomData_T *rom)
{
int		i;
int startvalue;

/******** following moved into "MoveRomDataToEditPlayerData(rom);"

PlyrCustomInfo_T	*cp;

	// read name(s)
	cp = (PlyrCustomInfo_T *)(&rom->cl___pStatNBA);
	strcpy(editLastName, cp->asb__pSName);
	strcpy(editFirstName, cp->asb__pCName);
//	editHead = (c->ub___pCustomHeadType & EDIT_HEAD_MASK) >> EDIT_HEAD_SHIFT;
//	editHair = (c->ub___pCustomHeadType & EDIT_HAIR_MASK) >> EDIT_HAIR_SHIFT;
	editHead = cp->ub___pCustomHeadType;
	editHair = cp->ub___pCustomHairType;
*****/
	// read attributes
	MoveRomAbilitiesToEditAbilities(rom);

	// read other data, weight, height, age, 
	 MoveRomDataToEditPlayerData(rom);

	editNoModifyFlag = 0;	// okay to modify 
	
	if( !(editFirstName[0] && editLastName[0]) )
	{	// player just created - start at "average" numbers, not at bottom
	
		// init height, weight based on position
		strcpy(editFirstName,"J");
		strcpy(editLastName,"Doe");

		editWeight	= DefaultWeightByPosition[editPos];
		editHeight	= DefaultHeightByPosition[editPos];
		editAge = 21;

		if(editRookieMode)
		{
			editYears=ROOKIE_MODE_EXP;
		}

//		editAbilities[ABILITY_RANGE]= 2;
//		startvalue = editRookieMode ? START_ROOKIE_ATTR : 50;	// MUST be multiple of 25 (due to [ABILITY_RANGE])
		startvalue = 50;	// MUST be multiple of 25 (due to [ABILITY_RANGE])
		for(i=0;i<NUM_ABILITIES;i++)
		{
			editAbilities[i] = startvalue;
		}
//		editAbilities[ABILITY_RANGE]= 50;	// UM wants more here

		/******
		editAbilities[ABILITY_SHOOT]=
		editAbilities[ABILITY_3PT]=
		editAbilities[ABILITY_FT]=
		editAbilities[ABILITY_REB]=
		editAbilities[ABILITY_STEAL]=
		editAbilities[ABILITY_PASS]=
		editAbilities[ABILITY_BLOCK]=
		editAbilities[ABILITY_DRIB]=
		editAbilities[ABILITY_SPEED]=
		editAbilities[ABILITY_JUMP]=
		editAbilities[ABILITY_DUNK]=
		editAbilities[ABILITY_STRENGTH]=
		editAbilities[ABILITY_STAMINA]=
						50;		**********/


	}
	else	// previously created player
	{
		editRookieMode = (editYears ==  ROOKIE_MODE_EXP ? 1:0);
//		editNoModifyFlag = editRookieMode; 
	}

	editNoModifyFlag = editRookieMode;	// can NEVER modifiy a rookie (even on init) 6/4/99 mjk

	// set thin data...
//	SetThinChap();			// moved outside of here
}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

static void SetBodyType()
{
	s32
		body,
		height,
		weight;

	height = MIN_HEIGHT + editHeight;
	height -= (5*12)+10;			// 5'10"
	if (height < 0) height = 0;
	height /= 3;
	if (height > 5) height = 5;

	weight = MIN_WEIGHT + editWeight;
	weight -= (height * 10);
	weight -= 160;

	if (weight < 0)
		body = 0;
	else
	{
		if (height < 2)
			body = 30;
		else
			body = 20;

		body += (height * 10);

		if (weight < body)
			body = 1;
		else
			body = 2;
	}

	PlayGfx_ShellBody( body );	// sets 	"player[0].plyrROM->ub___pAcc1 |= (body << 6);"

}


void SetThinChap(void)
{
	long	l,w;

	SetBodyType();

	l = (int)editHeight+MIN_HEIGHT;
	l = (long) (2.77 * l);
	w = (int)editWeight+MIN_WEIGHT;

	if (l > w)
	{
		editBodyType=1;
		editHeadType=(aub__gCustomHeads[editHead][1]>>3)*2+1;
	}
	else
	{
		editBodyType=0;
		editHeadType=(aub__gCustomHeads[editHead][1]>>3)*2;
	}

	editSkin=aub__gCustomHeads[editHead][0];
}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int isalpha(char a)
{
	if(a>='a' && a<='z') return(1);
	if(a>='A' && a<='Z') return(1);
	return(0);
}


void FixString2(char *s)
{
	int i,j;

	// strip leading and trailing spaces
	while(s[0]==' ') for(i=0;s[i];i++) s[i]=s[i+1];
	if(!s[0]) return;
	j=strlen(s)-1;
	while(s[j]==' ' && j>=0) { s[j]=0; s--; }
}

void FixString(char *ss,int macCheck)
{
	signed int	i,j;
	char	s[80];

	strcpy(&s[1],ss);
	s[0]=' ';

	s[1]=toupper(s[1]);
	for(i=2;i<strlen(s);i++)
	{
		j=toupper(s[i-1]);
		if(j>='A' && j<='Z') s[i]=tolower(s[i]);
		else s[i]=toupper(s[i]);
	}

	if(macCheck)
	{
		for(i=0;i<(signed)strlen(s)-3;i++)
			if(!isalpha(s[i]) && s[i+1]=='M' && s[i+2]=='c') s[i+3]=toupper(s[i+3]);
	}

	strcpy(ss,&s[1]);

}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

void UpdateJerseyString(void)
{

	char	tmp[20];
	int	i,j;

	if(shellPlayerTeam==-2) return;

	strcpy(tmp,editString);
	for(i=0;i<strlen(tmp);i++) if(tmp[i]!=' ') break;
	for(j=0;tmp[i+j];j++) tmp[j]=tmp[i+j];
	tmp[j]=0;

	for(i=0;tmp[i];i++) if(tmp[i]=='\'') tmp[i]='\\';
	for(i=0;tmp[i];i++) if(tmp[i]=='-') tmp[i]='[';

	for(i=strlen(tmp);i>=0;i--)
	{
		if(tmp[i]==' ')	tmp[i]=0;
		else		break;
	}
	PlayGfx_ShellName( tmp );

}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

char WrapLetter(char a,int dir)
{
	int		i,j;

	if(!a) a=' ';
	a=toupper(a);
	i=-1;
	for(j=0;editValidLetters[j];j++)
	{
		if(editValidLetters[j]==a) i=j;
	}
	if(i==-1) return('A');

	i=(i+j+dir)%j;
	return(editValidLetters[i]);
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/
#define SFX_ID_CHANGE	SFX_ID_SCROLL

int ClampAdd(int curval,int incval,int min,int max)
{
int oldval;

	oldval = curval;
	clampSound= SFX_ID_CHANGE;	// assume
	
	curval += incval;

	if(curval<min)
	{
		 curval=min;
		 clampSound= SFX_ID_CANTMOVE;
	}
	if(curval>max)
	{
		curval = max;
		clampSound=SFX_ID_CANTMOVE;
	}

	if(oldval != curval)
	{
		dataChanged=1;
	}
	
	return(curval);
}



int PoolClampAdd(int curval,int incval,int min,int max)
{
int oldval;

	oldval = curval;
//	clampSound=SFX_ID_CHANGE;	// assume
	clampSound=SFX_ID_CANTMOVE;	// assume

	if(PoolPoints + incval <= MaxPoolPoints)
	{
	//	PoolPoints += incval;
		curval += incval;
	
		if(curval<min)
		{
			 curval=min;
//			 clampSound=SFX_ID_CANTMOVE;
		}
		if(curval>max)
		{
			curval = max;
//			clampSound=SFX_ID_CANTMOVE;
		}

		if(oldval != curval)
		{
			dataChanged=1;
			clampSound=SFX_ID_CHANGE;
		}
	
	}
	
	return(curval);
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int WrapAdd(int a,int b,int min,int max)
{
	int i;

	i=a;
	clampSound= SFX_ID_CHANGE;
	a+=b;
	while(a<min) a+=(1+max-min);
	while(a>max) a-=(1+max-min);
	if(i!=a) dataChanged=1;
	return(a);
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/


void FetchSlotData(int slot)		// in InitScreenS1
{

	
	MoveCustomPlayerDataToEditArea(&pacl_gCustom[slot]);

//	// set thin data...
//	SetThinChap();	moved outside of routine

	if(!PlayerDefined(slot))
	{
		editTeam=-1;
//		editNewCreation = 1;
	}
	else
	{
//		editNewCreation = 0;	// previously created (Modify)
	}


}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

void EditRenderText(char *s,int x,int y,int font,int palette,int flg)
{
	TXTCEL_T	*tc;

	tc = InitTxtCel(NULL,0,font,palette,FFLG_YL | ((flg & FLG_SHADOW)?FFLG_SHADOW:0));
	ClearTxtCel(tc);
	WriteTxtCel(tc,s);
	
	if(flg & FLG_CTR)
	{
		x -= (tc->ui___tcW/2);
	}
	else if(flg & FLG_XR)
	{
		x -= (tc->ui___tcW);
	}
		
	DrawTxtCel(tc,x,y+tc->ui___tcH-1);

	editLastX = x; editLastY = y;
	editLastW = tc->ui___tcW;
	editLastH = tc->ui___tcH;

	if(flg & FLG_HI)
	{
		editHiX = x; editHiY = y;
		editHiW = tc->ui___tcW;
		editHiH = tc->ui___tcH;
	}

	FreeTxtCel(tc);
	MemFree(tc);
}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int EditGetWidth(char *s,int x,int y,int f,int c,int flg)
{
	TXTCEL_T	*tc;
	int		w;

	tc=InitTxtCel(NULL,0,f,c,FFLG_YL | ((flg & FLG_SHADOW)?FFLG_SHADOW:0));
	ClearTxtCel(tc);
	WriteTxtCel(tc,s);

	w=tc->ui___tcW;

	FreeTxtCel(tc);
	MemFree(tc);

	return(w);
}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

void RenderEditField(char *s,int x,int y,int f,int c,int flg,int editing,int cursorPos)
{
	char		tmp[80];
	char		tmp2[80];
	int		i,j,k,l,m;
//	extern int	frame;

	if(!editing) cursorPos=0;

	strcpy(tmp2,s);
	l = strlen(tmp2);
	
	k=0;
	m=0;
	if(editing < 2)
	{
	while(1)
	{
		i=EditGetWidth(tmp2,x,y,f,c,flg);
		if(i<100) break;

		if(!k)
		{
			if(cursorPos < 3)
			{
				k^=1;
			}
			else
			{
				if(!(m&1))
				{
					strcpy(tmp,"..");
					strcat(&tmp[strlen(tmp)],tmp2);
					strcpy(tmp2,tmp);
					m|=1;
				}
				for(j=2;tmp2[j];j++) tmp2[j]=tmp2[j+1];
				k^=1;
				l--; cursorPos--;
			}
		}
		else
		{
			if(cursorPos >= l-3)
			{
				k^=1;
			}
			else
			{
				if(m&1)
				{
					tmp2[l-1+2]=0;
					strcat(tmp2,"..");
				}
				else
				{
					tmp2[l-1]=0;
					strcat(tmp2,"..");
				}
				l--;
				k ^= 1;
			}
		}
	}

	
	}
	
	
	if( (!editing || ((frame%30)<10))
		&& 	(fl___gShellOverlay == 0)
	  )	// frame not inc'ed during PAUSE menu
	{
		EditRenderText(tmp2,x,y,f,c,flg);
	}
	else
	{
		if(m&1) cursorPos+=2;

		for(i=0;i<cursorPos && tmp2[i];i++) tmp[i]=tmp2[i];
		tmp[i]=0;
		if(tmp[0])
		{
			EditRenderText(tmp,x,y,f,c,flg);
			j=editLastW+2;
		}
		else
		{
			j=0;
		}
		EditRenderText("_",x+j,y+1,f,c,flg);
		strcpy(tmp,&tmp2[i]);
		if(tmp[0]) EditRenderText(tmp,x+j,y,f,c,flg);
	}
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

#if 0		// retired for 1999
/************
Gfx *RenderCurvyBox(Gfx *gp,int x,int y,int w,int h,unsigned char *boxCols)
{
	// adjust for inside of box...
	x+=4; w-=8;
	y+=2; h-=4;

	// render background areas...
	gp=RenderTBOX(gp,x,y,w-8,h,boxCols[0],boxCols[1],boxCols[2],boxCols[3]);
	gp=RenderTBOX(gp,x+w-8,y,8,h-7,boxCols[0],boxCols[1],boxCols[2],boxCols[3]);
	gp=RenderTBOX(gp,x+w-8,y+h-7,4,5,boxCols[0],boxCols[1],boxCols[2],boxCols[3]);

	// render shadows
	gp=RenderCSHD(gp,x,y,16,8);
	gp=RenderLSHD(gp,x,y+8,16,h-8);
	gp=RenderTSHD(gp,x+16,y,w-16,8);

	// restore dimensions
	x-=4; w+=8;
	y-=2; h+=4;

	// render border...
	gp=RenderTBOX(gp,x,y,w,2,boxCols[16],boxCols[17],boxCols[18],boxCols[19]);
	gp=RenderTBOX(gp,x,y,4,h,boxCols[16],boxCols[17],boxCols[18],boxCols[19]);
	gp=RenderTBOX(gp,x,y+h-2,w-32,2,boxCols[16],boxCols[17],boxCols[18],boxCols[19]);
	gp=RenderTBOX(gp,x+w-4,y,4,h-16,boxCols[16],boxCols[17],boxCols[18],boxCols[19]);

	// render curvy bit
	//gp = RenderSprBit(gp, SPR_PTR(SPR_LBITS),(UI)puw__gPalette,x+w-32,y+h-16,
	//		 0,  0, 32, 16);

	return(gp);
}
*******/
#endif

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

static	unsigned char                  sprScreenS [] =
{
	//SPR_STITLE,
	//SPR_LBITS,
	SPR_RED_TL,
	SPR_RED_TR,
	SPR_RED_BL,
	SPR_RED_BR,
//	SPR_TM_CRNR,

//	SPR_YEL_TL,
//	SPR_YEL_TR,
//	SPR_YEL_BL,
//	SPR_YEL_BR,

	0
};

int InitScreenS(int state)
{
	int		i,j,k;
	PlyrRamData_T *     pcl__PlyrRam;


//	editRookieMode = CreateRookieMode = 0;
	editRookieMode = 0;
	CreatePlayerMode = CREATE_PLAYER_EDIT;	// assume this

	// Load up the correct background image.
//	LoadShellBackgroundSpr(ID_SPR_BACK_KB1);
	BG_Load( BG_KOBE1, 0 );

	// Load up the sprites for this screen.
	LoadSpriteList(sprScreenS);

#if TRUE_SHELL_PLAYER	
	// ensure the shapes are loaded
	if(!shellPlayerLoaded)
	{
		ShellPlayerLoadMain(340,28,130,148,180);
		shellPlayerLoaded=1;
	}
#else
		shellPlayerLoaded=0;
#endif

	// get player names...
//	numSlots = configUseCtrlPak ? CUSTOM_PLYRS:4;
	numSlots = CUSTOM_PLYRS;
	selSlot %= numSlots;
	opt=selSlot;

	editGotData = editNewlyCreated = dataChanged=0;

	// All Done.
	return (state);
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ExitScreenS(int state)
{
	// Free up the sprites for this screen.
	FreeSpriteList(sprScreenS);


	// All Done.
	return (state);
}




/***************************************************************************
 *
 *			C R E A T E    R O O K I E
 *
 ***************************************************************************
 *
 *		The Create rookie mode bypasses ScreenS0(ScreenS) and goes thru here
 		and then into ScreenS1 (UNLESS all slots are full in which case it  
		will return)
 *
 ***************************************************************************/

//int GaveCareerInfo = 0;


int InitScreenCreateRookie(int state)
{
int i;

	InitScreenS(state);

	opt = -1;

	CreatePlayerMode = CREATE_PLAYER_CAREER;
//	CreateRookieMode = 1;
	
	for(i=0; i<numSlots; i++)	// find 1st available slot to insert rookie
	{
		if(!PlayerDefined(i))
		{
			opt = selSlot = i;
			break;
		}
	}

	if(opt < ZERO)
	{	// all slots full - stay in this state to display error message
//		state=asb__gStateNextRev[state];
	}
	else
	{
		editGotData = dataChanged=0;
		editNewlyCreated = 	editRookieMode = 1;	
/*****
		if (!GaveCareerInfo)
		{	// all slots full - stay in this state to display error message
//			state=asb__gStateNextRev[state];
			GaveCareerInfo = 1;	
		}
		else
		{
			state=asb__gStateNextFwd[state];
		}
*******/

	}

	// All Done.
	return (state);

}	

int InitScreenCreateNormalPlayer(int state)
{
int i;

	InitScreenS(state);

	opt = -1;
	CreatePlayerMode = CREATE_PLAYER_NORMAL;

	
	for(i=0; i<numSlots; i++)	// find 1st available slot to insert rookie
	{
		if(!PlayerDefined(i))
		{
			opt = selSlot = i;
			break;
		}
	}

	if(opt < ZERO)
	{	// all slots full - stay in this state to display error message
//		state=asb__gStateNextRev[state];
	}
	else
	{
		editGotData = dataChanged=0;

//		editNewlyCreated = 	editRookieMode = 1;	
		editNewlyCreated = 	1;	
		state=asb__gStateNextFwd[state];
	}

	// All Done.
	return (state);

}	


int ExitScreenCreateRookie(int state)
{
	// Free up the sprites for this screen.
	FreeSpriteList(sprScreenS);	// loaded indirectly by screens


	// All Done.
	return (state);
}


/************************************************************************************************

				  C R E A T E     R O O K I E


	

************************************************************************************************/



int ProcScreenCreateRookie(int oldState)
{
int sound = -1;


	if(opt < ZERO)
	{	// all slots are full 
		if (asi__gTeamBtn[EVERYBODY]& (CTRL_FIRE_A | CTRL_START | CTRL_FIRE_B) )
		{
			oldState = asb__gStateNextRev[oldState];
			sound = SFX_ID_BACK;
		}
	}
	else	// only here if Career(rookie) player
	{
		if (asi__gTeamBtn[EVERYBODY]& (CTRL_FIRE_B) )
		{
			oldState = asb__gStateNextRev[oldState];
			sound = SFX_ID_BACK;
		}
		else if (asi__gTeamBtn[EVERYBODY]& (CTRL_FIRE_A | CTRL_START ) )
		{
			editGotData = dataChanged=0;
			editNewlyCreated = 	editRookieMode = 1;	

			oldState = asb__gStateNextFwd[oldState];
			sound = SFX_FORWARD;
		}
	}

	
	
	if (sound >= 0)
	{
		AudioPlaySfx(sound, 11025, 255, 7);
	}

	return (oldState);
}

/*-------------------------------------------------------------------*/


#define CR_XC	300
#define CR_Y0	60
#define CR_Y0a	(60+2)
#define CR_Y1	(CR_Y0a + 12)
#define CR_LH	12


struct rcbox CRScreenBoxes[] = 
{	

	{0,   0,512,	 CR_Y0,   STAT_PAL1,0,0,0,0},
	HLINE(0,  CR_Y0,  512),

	{0, CR_Y0a,	512,	MENU_BOTTOM_LINE_Y - CR_Y0a,STAT_PAL2,NO_CORNERS},

	HLINE(0,  MENU_BOTTOM_LINE_Y,  512),
	{-1,0,0,0,0,NO_CORNERS}

};




Gfx *DrawScreenCreateRookie(int state,Gfx *gp)
{

	gp = DrawRCBoxes(gp, CRScreenBoxes);

	ShadFont_Color(SHADFNT_RGB_WHITE);	
	ShadFont_Set(TinyShadFont);


	if(opt < ZERO)
	{
		apcz_gStateHelpMsg[state] = acz__gHelpAllExit;

		gp = ShadFont_DrawCentered(gp,"ALL CREATED PLAYER SLOTS ARE FULL.",CR_XC,CR_Y0-15);
		gp = ShadFont_DrawCentered(gp,"YOU MUST GO TO EDIT PLAYER AND",CR_XC,CR_Y1+0*CR_LH);
		gp = ShadFont_DrawCentered(gp,"DELETE A CREATED PLAYER IN ORDER",CR_XC,CR_Y1+1*CR_LH);
//		gp = ShadFont_DrawCentered(gp,"TO CREATE A NEW ROOKIE PLAYER.",CR_XC,CR_Y1+2*CR_LH);
//		gp = ShadFont_DrawCentered(gp,"TO CREATE A NEW CAREER PLAYER.",CR_XC,CR_Y1+2*CR_LH);
		gp = ShadFont_DrawCentered(gp,"TO CREATE A NEW PLAYER.",CR_XC,CR_Y1+2*CR_LH);
	}
	else if (state == STATE_CREATE_ROOKIE)
	{
		apcz_gStateHelpMsg[state] = acz__gHelpAForwardBBack;

		gp = ShadFont_DrawCentered(gp,"A CAREER PLAYER WILL START AS AN",CR_XC,CR_Y1+0*CR_LH);
		gp = ShadFont_DrawCentered(gp,"INEXPERIENCED ROOKIE.  YOU CAN IMPROVE",CR_XC,CR_Y1+1*CR_LH);
		gp = ShadFont_DrawCentered(gp,"HIS ABILITIES BY PLAYING IN SEASON OR",CR_XC,CR_Y1+2*CR_LH);
		gp = ShadFont_DrawCentered(gp,"PLAYOFF GAMES.  IMPROVEMENT IS BASED ON",CR_XC,CR_Y1+3*CR_LH);
		gp = ShadFont_DrawCentered(gp,"GAME PLAY TENDENCIES AND ACHIEVEMENTS.",CR_XC,CR_Y1+4*CR_LH);

		gp = ShadFont_DrawCentered(gp,"A CAREER PLAYER IS INITIALLY PLACED",CR_XC,CR_Y1+6*CR_LH);
		gp = ShadFont_DrawCentered(gp,"IN THE FREE AGENT POOL, AND THEN",CR_XC,CR_Y1+7*CR_LH);
		gp = ShadFont_DrawCentered(gp,"YOU MAY SIGN HIM TO YOUR TEAM.",CR_XC,CR_Y1+8*CR_LH);
		gp = ShadFont_DrawCentered(gp,"ENTER SEASON PLAY TO BEGIN.",CR_XC,CR_Y1+9*CR_LH);
		gp = ShadFont_DrawCentered(gp,"GOOD LUCK.",CR_XC,CR_Y1+10*CR_LH + 6);

//		gp = ShadFont_DrawCentered(gp,"",CR_XC,CR_Y1+2*CR_LH);

		ShadFont_Set(LargeShadFont);
		gp = ShadFont_DrawCentered(gp,"CAREER  PLAYER",CR_XC,CR_Y0-15);

	}

	// Help message.
	gp = DrawHelpTeaser(gp, 290);

	// Finally draw characters.
	gp=DrawChrList(gp);


	// All done.
	return (gp);
}




/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ProcScreenS(int oldState)	// Select Player (or NEW) to eDIT
{
	// Local Variables.
	int                 newState = oldState;

#if MJK_KLUDGE

	if (asi__gTeamBtn[EVERYBODY]& (CTRL_FIRE_A | CTRL_START | CTRL_FIRE_B) )
	{
			newState = asb__gStateNextRev[newState];
	}

#else

int sound = -1;
int	btn;

/******  no more asking ROOKIE or STANDARD question
	if(pendingPopup == 3)
	{
		if (si___gPopupVal > 0)
		{
			editNewlyCreated = 1;
			if (si___gPopupVal == 1)
			{	// wants to create a rookie 
				editRookieMode = 1;	
				newState=asb__gStateNextFwd[newState];
			}
			else if (si___gPopupVal == 2)
			{	// wants to create a STANDARD player
				editRookieMode = 0;	
				newState=asb__gStateNextFwd[newState];
	
			}	// 3 is back up
		}

		si___gPopupVal = pendingPopup  =0;

		goto allDone;

	}

**********/
	// check popup window
	if(pendingPopup==1)
	{
	}
	else if(pendingPopup==2)	//Delete Player??
	{
		if(si___gPopupVal==1)	//"YES"
		{
			// clear slot!
			ClearCustomPlayer(selSlot);
			opt=selSlot;
		}
		else if(si___gPopupVal>=2)	//"NO" or backup
		{
			// return to selection
			opt=selSlot;
		}
	}
	pendingPopup=0;
	si___gPopupVal=0;

	btn=asi__gTeamBtn[EVERYBODY];

	if (btn & (CTRL_FIRE_A | CTRL_START))
	{
		if(opt < 20)	// cursor on 1 of the slots??
		{
			selSlot=opt;
			if(PlayerDefined(selSlot))
			{	// if already exists.....
				opt=20;	// .... change to "MODIFY"
			}
			else	// Create a New player from empty slot
			{
//				InitPopup(newPlayerTitle,RookieCreationText,NULL);
//				pendingPopup=3;
				CreatePlayerMode = CREATE_PLAYER_NORMAL;
				newState=asb__gStateNextFwd[newState];
			}
		}
		else
		{
			if(opt==21)	// "DELETE" option??
			{
				if(PlayerDefined(selSlot) && pacl_gCustom[selSlot].ub___pTeam!=TEAM_NONE)
				{
					if(TeamSlotsUsed(pacl_gCustom[selSlot].ub___pTeam)<=MIN_TEAM_PLYRS)
					{
						strcpy(releasePlayerWarningText,"Cannot be deleted until the\n");
						strcat(releasePlayerWarningText,pacl_gTeamRom[pacl_gCustom[selSlot].ub___pTeam].pcz__tCity);
						strcat(releasePlayerWarningText," ");
						strcat(releasePlayerWarningText,pacl_gTeamRom[pacl_gCustom[selSlot].ub___pTeam].pcz__tName);
						strcat(releasePlayerWarningText,"\nhave more than ");
						IntToStr(MIN_TEAM_PLYRS,&releasePlayerWarningText[strlen(releasePlayerWarningText)]);
						strcat(releasePlayerWarningText," players.\n");
						strcat(releasePlayerWarningText,okButtonText);
						InitPopup(releasePlayerWarningTitle,
					  		releasePlayerWarningText,
					  		NULL);
						pendingPopup=1;
						opt=selSlot;
					}
					else
					{
						strcpy(releasePlayerWarningText,"This player is currently signed to the\n");
						strcat(releasePlayerWarningText,pacl_gTeamRom[pacl_gCustom[selSlot].ub___pTeam].pcz__tCity);
						strcat(releasePlayerWarningText," ");
						strcat(releasePlayerWarningText,pacl_gTeamRom[pacl_gCustom[selSlot].ub___pTeam].pcz__tName);
						strcat(releasePlayerWarningText,".\nProceed?\n");
						strcat(releasePlayerWarningText,yesNoButtonText);
						InitPopup(signedPlayerWarningTitle,
					  		releasePlayerWarningText,
					  		NULL);
						pendingPopup=2;	// same as delete warning!
						opt=selSlot;
					}
				}
				else
				{
					InitPopup(overwritePlayerWarningTitle,
					  	overwritePlayerWarningText,
					  	NULL);
					pendingPopup=2;
				}
			}
			else	// we want to modify
			{
				newState = asb__gStateNextFwd[newState];
			}
		}
		sound    = SFX_SHELL_BTNA;
		goto allDone;
	}

	if (btn & (CTRL_FIRE_B))
	{
		if(opt>=20) opt=selSlot;
		else
		{
			newState = asb__gStateNextRev[newState];
			if(shellPlayerTeam!=-2)
			{
				shellPlayerTeam=-2;
//				ShellPlayerFreeTeamTextures();
			}
			if(shellPlayerLoaded)
			{
				shellPlayerLoaded=0;
//				ShellPlayerFreeMain();
			}
		}
		sound    = SFX_SHELL_BTNB;
		goto allDone;
	}

	if (btn & (CTRL_PAD_UP))
	{
		if(opt<20)
		{
			opt=(opt+numSlots-1)%numSlots;
			selSlot=opt;
			sound=SFX_ID_SCROLL;
		}
		else
		{
			opt^=1;
			sound=SFX_ID_SCROLL;
		}
		goto allDone;
	}

	if (btn & (CTRL_PAD_DOWN))
	{
		if(opt<20)
		{
			opt=(opt+1)%numSlots;
			selSlot=opt;
			sound= SFX_ID_SCROLL;
		}
		else
		{
			opt^=1;
			sound= SFX_ID_SCROLL;
		}
		goto allDone;
	}

	if (btn & (CTRL_PAD_LEFT | CTRL_PAD_RIGHT))
	{
		if(opt < CUSTOM_PLYRS)
		{
			if(numSlots == CUSTOM_PLYRS)
			{
				opt=(opt+CUSTOM_PLYRS/2)%CUSTOM_PLYRS;
				sound=SFX_ID_SCROLL;
			}
			else
			{
				sound= SFX_ID_CANTMOVE;
			}
			selSlot=opt;
		}
		else
		{
			opt^=1;
			sound= SFX_ID_SCROLL;
		}
		goto allDone;
	}

	// Anything else ?

	if (btn & (
			CTRL_PAD_UP | CTRL_PAD_DOWN | CTRL_PAD_LEFT | CTRL_PAD_RIGHT |
			CTRL_C_UP | CTRL_C_DOWN | CTRL_C_LEFT | CTRL_C_RIGHT))
	{
		sound = SFX_SHELL_NOMV;
	}

	// All done.

	allDone:

	if (sound >= 0)
	{
		AudioPlaySfx(sound, 11025, 255, 7);
	}

#endif	// mjk

	return (newState);
}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

/************
struct rcbox TestScreenBoxes[] = 
{
	//{120, 15,	350,195,	RGB_SOLID_YEL,0,0,0,0},
	

	{350, 60,	80,50,	RGB_TRANS_YEL,
				SPR_YEL_TL,
				SPR_YEL_TR,
				SPR_YEL_BL,
				SPR_YEL_BR},


	{200, 60,	80,50,	RGB_TRANS_RED,
				SPR_RED_TL,
				SPR_RED_TR,
				SPR_RED_BL,
				SPR_RED_BR},

	{150, 60,	0,0,	RGB_TRANS_RED,
				SPR_RED_TL,
				SPR_RED_TR,
				SPR_RED_BL,
				SPR_RED_BR},

	{130, 90,	16,10,	RGB_TRANS_RED,
				0,SPR_SMALLCRV,	0,0},

	{130, 120,	16,10,	RGB_TRANS_YEL,
				0,SPR_SMALLCRV,	0,0},

	
	
	{320,150, 2,2,	RGB_TRANS_RED,
				0,SPR_MBARSHAD,0,0},

	{350,150, 2,2,	RGB_TRANS_YEL,
				0,SPR_MBARSHAD,0,0},


	{130,150, 8,5,	RGB_TRANS_YEL,
				0,SPR_TM_CRNR,0,0},

	{180,150, 8,5,	RGB_TRANS_RED,
				0,SPR_TM_CRNR,0,0},


	{130, 20,	16,10,	RGB_TRANS_YEL,
				0,SPR_AT_BOX,0,0},


	{230, 20,	16,10,	RGB_TRANS_RED,
				0,SPR_AT_BOX,0,0},


	HLINE(0,  MENU_BOTTOM_LINE_Y,  512),
	{-1,0,0,0,0,NO_CORNERS}
};

*********/

#define S0_Y1	16
#define S0_Y1a	(S0_Y1+MENU_LINE_H)
#define S0_Y2	(178-4)
#define S0_Y2a	(S0_Y2+MENU_LINE_H)
#define S0_Y2c	((S0_Y2+MENU_BOTTOM_LINE_Y)/2)

#define S0_X1	(282+6)
#define S0_X1a	(S0_X1+MENU_LINE_W)



struct rcbox S0ScreenBoxes[] = 
{
	{0, 0,512,S0_Y1, RGB_TRANS_YEL,NO_CORNERS},

//	HLINE(0, SO_Y1, 512),
//	{0, 79+MENU_LINE_H,	512,MENU_BOTTOM_LINE_Y-(79+MENU_LINE_H),	RGB_TRANS_RED,NO_CORNERS},
	{0, S0_Y1a,	S0_X1, S0_Y2-(S0_Y1a),	RGB_TRANS_RED,0,SPR_RED_TR,0,SPR_RED_BR},
//	VLINE(288, 79+MENU_LINE_H, MENU_BOTTOM_LINE_Y-(79+MENU_LINE_H)),

	{0, S0_Y2a,	512, MENU_BOTTOM_LINE_Y-(S0_Y2a),	RGB_TRANS_PURPLE,0,0,0,0},

	HLINE(0,  MENU_BOTTOM_LINE_Y,  512),
	{-1,0,0,0,0,NO_CORNERS}
};



stringXY_t EditPlayerModes[2] = {
	"MODIFY",	S0_X1-80,	S0_Y2c-1,	
	"DELETE",	S0_X1+80,	S0_Y2c-1,	
};



Gfx *DrawScreenS(int state,Gfx *gp)
{

int         i,j,k,l,m;
//TXTCEL_T *  pcl__Txt;
char		tmp[80];
int			x,y;
int		cpcount = 0;

	gp = DrawRCBoxes(gp,S0ScreenBoxes);	// lay the graphical foundation 
	gp = DrawBlankBox(gp, S0_X1, 513, S0_Y1a, S0_Y2,BB_LEFT_BOX);

//	gp = DrawRCVLineRight(gp, 288, MENU_TOP_KEY_Y+MENU_LINE_H, MENU_BOTTOM_LINE_Y,1);
	DRAW_MENU_HLINE(S0_Y1);
	DRAW_MENU_HLINE(S0_Y2);


	// Help message.

//	gp = DrawHelpTeaser(gp, 290);

	// draw the main body of the screen
	editHiX=-1;
	for(i=0; i < numSlots; i++)
	{
//		j=(i/10)*172 + 130;
		j= (i/10) ?  S0_X1+20 : 132;
		k=(i%10)*14 + 28;
		if(opt<20)
		{
//			if(selSlot==i) l=FPAL_RED;
//			else 
			l=FPAL_WHITE;
		}
		else
		{
			if(selSlot==i) l=FPAL_WHITE;
			else l=FPAL_BLUE;
		}

		if(PlayerDefined(i))
		{
			strcpy(tmp,pacl_gCustom[i].pcz__pSName);
			strcat(tmp,", ");
			m=strlen(tmp);
			tmp[m]=pacl_gCustom[i].pcz__pCName[0];
			tmp[m+1]=0;
			if(pacl_gCustom[i].ub___pExp == ROOKIE_MODE_EXP)
			{
//				strcat(tmp,"(CP)");
				strcat(tmp," *");
				cpcount++;
			}
		}
		else
		{
			strcpy(tmp,"-Empty Slot-");
		}
		EditRenderText(tmp,j,k,FONT_BLKCN18,l,(opt<20 && selSlot==i)?FLG_HI:0);
	}

	if(editHiX!=-1)
	{
		editHiX -= 4; editHiY -= 2; editHiW += 8; editHiH += 4;

		editHiX = (selSlot<10) ? 114+2+2+2 : S0_X1a+2+3;
		editHiW = (selSlot<10) ? (168-2) : (168);
//		editHiW = (172-4);

		gp = DrawOvalCursorHilite(gp, editHiX+editHiW/2,editHiY+5,editHiW);

//		gp=RenderTBOX(gp,editHiX,editHiY,editHiW,editHiH,RGB_SOLID_WHT);
//		gp=RenderTSHD(gp,editHiX,editHiY+editHiH,editHiW,3);
		editHiX=-1;
	}


	ShadFont_Set(TinyShadFont);

	if(PlayerDefined(selSlot))
	{

		if(opt >= 20)	
		{	// hilighted
			ShadFont_Color(SHADFNT_RGB_WHITE);
		}	
		else
		{
			ShadFont_Color(SHADFNT_RGB_GRAY);
		}	

		for(i=0; i < 2; i++)
		{
			x = EditPlayerModes[i].x;
			y = EditPlayerModes[i].y;

			if(opt == i+20)
			{
				gp = DrawOvalCursor(gp, x,y,80);
			}
		
			gp = ShadFont_DrawCentered(gp,EditPlayerModes[i].title,x,y);
		}
	}
	else	// empty slot
	{	
		x = S0_X1;
		y = S0_Y2c-1;
	
		gp = DrawOvalCursor(gp, x,y,80);
		ShadFont_Color(SHADFNT_RGB_WHITE);
		gp = ShadFont_DrawCentered(gp,"CREATE",x,y);

	}
	
	if(cpcount) 
	{
		EditRenderText("* = Career Player",220,S0_Y2c+8,FONT_BLKCN18,FPAL_WHITE,FLG_HI | FLG_SHADOW);
	}


/************

	k = (opt==20) ? FPAL_RED:((opt==21) ? FPAL_WHITE : FPAL_BLUE);
	EditRenderText("Modify",200,190,FONT_BLKBT18,k,FLG_CTR | (opt==20?FLG_HI:0));

	k=(opt==21)?FPAL_RED:((opt==20)?FPAL_WHITE:FPAL_BLUE);
	EditRenderText("Delete",372,190,FONT_BLKBT18,k,FLG_CTR | (opt==21?FLG_HI:0));

	if(editHiX!=-1)
	{
		editHiX-=4; editHiY-=2; editHiW+=8; editHiH+=4;
		
		editHiW+=12;	gp = DrawOvalCursor(gp, editHiX-4+editHiW/2,editHiY+5,editHiW);
//		gp=RenderTBOX(gp,editHiX,editHiY,editHiW,editHiH,RGB_SOLID_WHT);
//		gp=RenderTSHD(gp,editHiX,editHiY+editHiH,editHiW,3);
		editHiX=-1;
	}
*************/

	// Help message.

	gp = DrawHelpTeaser(gp, 290);

	// Finally draw characters.
	gp=DrawChrList(gp);


	// All done.
	return (gp);
}



/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

static	unsigned char                  sprScreenS1 [] =
{
	SPR_RED_TL,SPR_RED_TR,SPR_RED_BL,SPR_RED_BR,
	//SPR_STITLE1,
	//SPR_LBITS,
	0
};


#define INFO_FIRSTNAME		0
#define INFO_LASTNAME		1
#define INFO_AGE			2
#define INFO_YEARS			3
#define INFO_NO				4
#define INFO_POS			5
#define INFO_HEIGHT			6
#define INFO_WEIGHT			7
#define INFO_HEAD			8
#define INFO_HAIR_STYLE		9
#define INFO_HAIR_COLOR		10
#define INFO_ARMS			11
#define INFO_WRIST			12
#define INFO_KNEES			13
#define INFO_SOCKS			14

#define INFO_ABILITIES		15
#define NUM_INFO_FIELDS		16
//#define INFO_ROOKIE_MODE	10
//#define INFO_HAIR			9



static	char *infoFields[NUM_INFO_FIELDS]=
{
	"First Name",
	"Last Name",
	"Age",
	"Years Pro",
	"Jersey #",
	"Position",
	"Height",
	"Weight",
	"Head",
//	"Hair",
	"Hair Style",
	"Hair Type",

	"Arm Bands",
	"Wrist Bands",
	"Knee Pads",
	"Socks",

	"Abilities..."
};


static	char RookieNotModifable[NUM_INFO_FIELDS]=
{	// 0 means can modify a created rookie after initial creation
	1,	//	"First Name",
	1,	//	"Last Name",
	1,	//	"Age",
	1,	//	"Years Pro",
	0,	//	"Jersey #",
	1,	//	"Position",
	1,	//	"Height",
	0,	//	"Weight",	so, he gains a few pounds
	1,	//	"Head",
	0,	//	"Hair 1,
	0,	//	"Hair 2",

	0,	//	"Arm Bands",
	0,	//	"Wrist Bands",
	0,	//	"Knee Pads",
	0,	//	"Socks",

	0,	//	"Abilities..."
};




#define INIT_DELAY	10
static int reptDelay[2];
static int NeedNewBody;


static void SetCamMode( int mode )
{
	switch (opt)
	{
		case INFO_LASTNAME:
		case INFO_NO:
			PlayGfx_ShellFocus( PG_FOCUS_BACK );
			break;

		case INFO_HEIGHT:
		case INFO_WEIGHT:
		case INFO_ARMS:
		case INFO_WRIST:
		case INFO_KNEES:
		case INFO_SOCKS:
			PlayGfx_ShellFocus( PG_FOCUS_ALL );
			break;

		case INFO_HEAD:
//		case INFO_HAIR:
		case INFO_HAIR_COLOR:
		case INFO_HAIR_STYLE:
			PlayGfx_ShellFocus( PG_FOCUS_FACE );
			break;
	}
}


void DoBodyTypeChange(void)
{
	editScale = editHeight;
	editScale += MIN_HEIGHT;
	editScale = (editScale*256)/MAX_HEIGHT;
	PlayGfx_ShellScale( editScale );

	SetThinChap();
//phil	PlayGfx_ShellHead( editHead, editHair );//ShellPlayerSetBody(256,editBodyType,editHeadType);
}


void InitShellPlayer(void)
{

	ShellPlayerOnScreen = 1;	// global so Z-buffer doesn't get wiped out

	PlayGfx_ShellName( editLastName );
	PlayGfx_ShellInit();		// moved to bottom

	// load the correct team!
//	if(shellPlayerTeam!=editTeam)
//	{
//		pendingLoadDelay=4;
//	}
//	else
	{
		// set data now!
		PlayGfx_ShellNumber( editNo );
		PlayGfx_ShellHead( editHead, editHair );
		PlayGfx_ShellWrists( editWrist );
		PlayGfx_ShellArms( editArms );
		PlayGfx_ShellKnees( editKnees );
		PlayGfx_ShellSocks( editSocks );


		DoBodyTypeChange();	

//		NeedNewBody = 1;

	}
}



void SetEditPlayerTitles(int state)
{
	if(CreatePlayerMode == CREATE_PLAYER_CAREER)
	{
		gStateTitleText2[state] = "CAREER";
		gStateTitleText[state] = "PLAYER";
	}
	else if(CreatePlayerMode == CREATE_PLAYER_NORMAL)
	{
		gStateTitleText2[state] = "CREATE";
		gStateTitleText[state] = "PLAYER";
	}
	else if(state == STATE_S2)	// normal edit
	{
		gStateTitleText2[state] = "EDIT PLAYER";
		gStateTitleText[state] = "ABILITIES";
	}
	else 
	{
		gStateTitleText2[state] = "";
		gStateTitleText[state] = "EDIT PLAYER";
	}

}

static int editing, cursorPos;

//--------------------------------------------------------------------------

int InitScreenS1(int state)
{

int		i,j,k;


	// Load up the correct background image.
//	LoadShellBackgroundSpr(ID_SPR_BACK_KB2);
	BG_Load( BG_KOBE2, 0 );

	giraffeMode = 0;	// 

	// Load up the sprites for this screen.
	LoadSpriteList(sprScreenS1);

	// init option
	opt = s1Opt;
	editing =  cursorPos=0;

	// set autorepeat for L and R
	reptDelay[0] = reptDelay[1]=INIT_DELAY;

	
	gCustomPlayerPtr = &pacl_gCustom[selSlot];		// needed for shell player body/acc/head etc.

#if 1	// order of routines changed 7/122/99 - mjk	
	
	// fetch data...
	if(!editGotData)
	{	// first time in ??? - then load
		editGotData=1;

//		FetchSlotData(selSlot);
		MoveCustomPlayerDataToEditArea(&pacl_gCustom[selSlot]);
		if(!PlayerDefined(selSlot))
		{
			editTeam=-1;
		}

	}
//	else
//	{
//		SetEditAbilitiesByPosition(editPos);	// will do only if create rookie mode
//	}

	SetEditAbilitiesByPosition(editPos);	// will do only if create rookie mode

	InitShellPlayer();

//	SetThinChap();	 this was done in InitShellPlayer()


#else
	InitShellPlayer();	// must be before FetchSlotData()!!!

	// fetch data...
	if(!editGotData)
	{
		FetchSlotData(selSlot);
		editGotData=1;
	}
#endif
	
	pendingPopup=0;


	SetEditPlayerTitles(STATE_S1);

	SetCamMode( opt );	// fixes bug # 882



	// All Done.
	return (state);
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ExitScreenS1(int state)
{
	PlayGfx_ShellDeinit();
	ShellPlayerOnScreen = 0;

	// Free up the sprites for this screen.
	FreeSpriteList(sprScreenS1);


	// remember opt
	s1Opt=opt;


//  N.B.  changing STATE in any ExitScreen does NOTHING!!!!
/****
//	if(CreateRookieMode && fl___gReverse)
	{
		state = STATE_P;	// skip ScreenS0 - goto Rosters
	}
******/


	// All Done.
	return (state);	// calling code ignores this value!!!
}




void CheckForPositionChange(int btn)
{
int i;

	i=editPos;
	if(btn&CTRL_PAD_LEFT)
	{
		editPos=WrapAdd(editPos,-1,0,NUM_EDIT_POSITIONS-1);
	}

	if(btn&CTRL_PAD_RIGHT)
	{
		editPos=WrapAdd(editPos,1,0,NUM_EDIT_POSITIONS-1);
	}
			
	if(i!= editPos)
	{	// if position changed....
		editHeight = DefaultHeightByPosition[editPos];	// change H/W
		editWeight = DefaultWeightByPosition[editPos];	

		DoBodyTypeChange();

//				NeedNewBody = 1;
			SetEditAbilitiesByPosition(editPos);
	}
}



/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ProcScreenS1(int oldState)
{
	int		newState = oldState;

	int		sound = -1;
	int		btn;
	int		i,j,k;
	int		ch,wcount;

	fl___gReverse = 0;

	// check popup
	if(pendingPopup==3 && si___gPopupVal > 0)		// "continue" is  only option
	{
		pendingPopup =
			si___gPopupVal = 0;
		goto allDone;
	}



	if(pendingPopup==1)		// "keep changes?"
	{
		pendingPopup=0;
		if(si___gPopupVal==1)	//"YES"
		{
			if(editFirstName[0] && editLastName[0])
			{
				// SAVE SLOT!!!
				SaveEditAreaToCustomPlayerData(&pacl_gCustom[selSlot]);
				fl___gReverse = 1;
				newState = asb__gStateNextRev[newState];
				si___gPopupVal=0;
				goto allDone;
			}
			else
			{
				InitPopup(newPlayerTitle,
					  noNameText,
					  NULL);
				si___gPopupVal=0;
				goto allDone;
			}
		}
		else if(si___gPopupVal==2)	// "NO"
		{	// keep the same (don't clear!!)
			newState=asb__gStateNextRev[newState];
			fl___gReverse = 1;
			si___gPopupVal=0;
			goto allDone;
		}
	}
//	else if(pendingPopup==10)		// Mr. W
//	{
//
//	}

	si___gPopupVal=0;
	pendingPopup=0;


	apcz_gStateHelpMsg[oldState] = acz__gHelpScreenS1;	// assume - could change below if name input

	btn=asi__gTeamBtn[EVERYBODY];

	// process repeat...
	if(opt==INFO_AGE ||
	   opt==INFO_NO ||
	   opt==INFO_HEIGHT ||
	   opt==INFO_WEIGHT)
	{
		if(!(asi__gTeamPad[EVERYBODY] & CTRL_PAD_LEFT))		reptDelay[0]=INIT_DELAY;
		else if(reptDelay[0]) reptDelay[0]--;
		if(!reptDelay[0]) btn |= CTRL_PAD_LEFT;
		if(!(asi__gTeamPad[EVERYBODY] & CTRL_PAD_RIGHT))	reptDelay[1]=INIT_DELAY;
		else if(reptDelay[1]) reptDelay[1]--;
		if(!reptDelay[1]) btn |= CTRL_PAD_RIGHT;
	}
	else

	{
		reptDelay[0]=INIT_DELAY;
		reptDelay[1]=INIT_DELAY;
	}
	if(btn & (CTRL_PAD_UP | CTRL_PAD_DOWN))
	{
		reptDelay[0]=INIT_DELAY;
		reptDelay[1]=INIT_DELAY;
	}

	// load team textures?
	if(!(asi__gTeamPad[EVERYBODY] & (CTRL_PAD_LEFT|CTRL_PAD_RIGHT)))
	{
		if((editTeam!=shellPlayerTeam) && (!pendingLoadDelay))
		{
			pendingLoadDelay=4;
		}
	}

	if(pendingLoadDelay)
	{
		pendingLoadDelay--;
		if(!pendingLoadDelay)
		{
			if(shellPlayerTeam!=-2) ShellPlayerFreeTeamTextures();

			shellPlayerTeam=editTeam;
			ShellPlayerLoadTeamTextures(shellPlayerTeam==-1?TEAM_FREEAGENTS:shellPlayerTeam);

			PlayGfx_ShellNumber( editNo );
			ShellPlayerSetName(editLastName);

			DoBodyTypeChange();
		}
	}

	// Exit button ?
	if ((btn & (CTRL_START)) && !pendingLoadDelay && !editing)
	{
		newState = asb__gStateNextFwd[newState];
		sound    = SFX_SHELL_STRT;
		goto allDone;
	}

	if ((btn & (CTRL_PAD_UP)) && !editing)
	{
		opt=(opt+(NUM_INFO_FIELDS-1))%NUM_INFO_FIELDS;
		sound= SFX_ID_SCROLL;
		SetCamMode( opt );
		goto allDone;
	}

	if ((btn & (CTRL_PAD_DOWN)) && !editing)
	{
		opt=(opt+1)%NUM_INFO_FIELDS;
		sound= SFX_ID_SCROLL;
		SetCamMode( opt );
		goto allDone;
	}

	if (((btn & (CTRL_FIRE_B)) && !editing) && !pendingLoadDelay)
	{
		if(dataChanged)
		{
			InitPopup(newPlayerTitle,
			  	keepPlayerText,
			  	NULL);
			pendingPopup=1;
			sound= SFX_ID_BACK;
			goto allDone;
		}
		else
		{
			newState=asb__gStateNextRev[newState];
			fl___gReverse = 1;
			sound=SFX_ID_BACK;
			goto allDone;
		}
	}

	clampSound=-1;

	if(editNoModifyFlag &&   !editNewlyCreated)
	{
		if(  ( (btn & CTRL_FIRE_A) && (opt <= INFO_LASTNAME)  )

		  || ( (btn & (CTRL_PAD_LEFT | CTRL_PAD_RIGHT))
			    && (RookieNotModifable[opt])
		     )	
		   )
		{
			InitPopup(editPlayerTitle,NoModifyText,NULL);
			pendingPopup=3;
			goto allDone;
		}


	}



	switch(opt)
	{
		case INFO_FIRSTNAME:
		case INFO_LASTNAME:
			if(editing)
			{
				apcz_gStateHelpMsg[oldState] = acz__gHelpScreenNameInput;

				if(btn&(CTRL_FIRE_B))
				{
					FixString(editString,(opt==INFO_LASTNAME?1:0));
					FixString2(editString);
					if(opt==INFO_LASTNAME) UpdateJerseyString();
//phil					ShellPlayerSetCamMode(0);

					wcount = 0;
					for(i=0; i<10; i++)
					{
						ch = tolower(editString[i]);
						if(ch == 'w'  || ch == 'm')
							wcount++;
						  
					}
					if(wcount > 7)
					{
						InitPopup(editPlayerTitle,NotANameText,NULL);
						pendingPopup = 10;		// Mr. W
//						editing=1;
						sound=SFX_ERROR;

					}
					else
					{
						editing=0;
						sound=SFX_ID_BACK;

					}
				}
				else if(btn&(CTRL_PAD_RIGHT | CTRL_FIRE_A))
				{
					if(!strlen(editString)) sound= SFX_ID_CANTMOVE;
					else cursorPos+=1;

					if(cursorPos >= MAX_CHARS_IN_CUSTOM_NAME) { sound= SFX_ID_CANTMOVE; cursorPos--; }
					if(cursorPos>(strlen(editString)))
					{
						strcat(editString," ");
					}
					if(sound!= SFX_ID_CANTMOVE)
						sound= SFX_ID_SCROLL;
				}
				else if(btn&CTRL_PAD_LEFT)
				{
					if(cursorPos>0)
					{
						cursorPos--;
						sound=SFX_ID_SCROLL;
					}
					else sound= SFX_ID_CANTMOVE;
				}
				else if(btn&CTRL_TRIGGER)
				{
					if(!strlen(editString)) sound= SFX_ID_CANTMOVE;
					else if(cursorPos==0)
					{
						for(i=0;editString[i];i++) editString[i]=editString[i+1];
						sound=SFX_ID_CHANGE;
					}
					else
					{
//						cursorPos--;
						for(i=cursorPos;editString[i];i++) editString[i]=editString[i+1];
						cursorPos--;
						sound=SFX_ID_CHANGE;
					}
					FixString(editString,(opt==INFO_LASTNAME?1:0));
					if(opt==INFO_LASTNAME) UpdateJerseyString();
				}
				else if(btn&CTRL_PAD_UP)
				{
					if(cursorPos>=strlen(editString))	strcat(editString," ");
					editString[cursorPos]=WrapLetter(editString[cursorPos],-1);
					sound= SFX_ID_CHANGE;
					FixString(editString,(opt==INFO_LASTNAME?1:0));
					if(opt==INFO_LASTNAME) UpdateJerseyString();
				}
				else if(btn&CTRL_PAD_DOWN)
				{
					if(cursorPos>=strlen(editString))	strcat(editString," ");
					editString[cursorPos]=WrapLetter(editString[cursorPos],1);
					FixString(editString,(opt==INFO_LASTNAME?1:0));
					if(opt==INFO_LASTNAME) UpdateJerseyString();
					sound=SFX_ID_CHANGE;
				}
			}
			else
			{
				if(btn&CTRL_FIRE_A)
				{
					editString=(opt==INFO_FIRSTNAME?editFirstName:editLastName);
					editing=1;
					cursorPos=0;
					sound= SFX_ID_OK;
					FixString(editString,(opt==INFO_LASTNAME?1:0));
					if(opt==INFO_LASTNAME)
					{
						UpdateJerseyString();
//phil						ShellPlayerSetCamMode(1);
					}
					dataChanged=1;
				}
				else if(btn&(CTRL_PAD_LEFT | CTRL_PAD_RIGHT))
				{
					sound= SFX_ID_CANTMOVE;
				}
			}
			break;
		
		case INFO_AGE:
			if(!editRookieMode)
			{
				if(btn&CTRL_PAD_LEFT)	editAge=ClampAdd(editAge,-1,MIN_AGE+editYears,MAX_AGE);
				if(btn&CTRL_PAD_RIGHT)	editAge=ClampAdd(editAge,1,MIN_AGE+editYears,MAX_AGE);
			}
			else
			{
				if(btn&CTRL_PAD_LEFT)	editAge=ClampAdd(editAge,-1,MIN_AGE,MAX_AGE);
				if(btn&CTRL_PAD_RIGHT)	editAge=ClampAdd(editAge,1,MIN_AGE,MAX_AGE);
			}


//			if(btn&CTRL_PAD_LEFT)	editAge=ClampAdd(editAge,-1,0,99);
//			if(btn&CTRL_PAD_RIGHT)	editAge=ClampAdd(editAge,1,0,99);
			break;

		case INFO_YEARS:
			if(!editRookieMode)
			{
				if(btn&CTRL_PAD_LEFT)	editYears=ClampAdd(editYears,-1,0,editAge-MIN_AGE);
				if(btn&CTRL_PAD_RIGHT)	editYears=ClampAdd(editYears,1,0,editAge-MIN_AGE);
//				if(btn&CTRL_PAD_LEFT)	editYears=ClampAdd(editYears,-1,0,20);
//				if(btn&CTRL_PAD_RIGHT)	editYears=ClampAdd(editYears,1,0,20);
			}
			break;

		case INFO_NO:
			if(btn&CTRL_PAD_LEFT)
			{
				editNo=(editNo+100)%101;
				clampSound= SFX_ID_CHANGE;
				dataChanged=1;
			}
			if(btn&CTRL_PAD_RIGHT)
			{
				editNo=(editNo+1)%101;
				clampSound= SFX_ID_CHANGE;
				dataChanged=1;
			}
			if(clampSound==SFX_ID_CHANGE && shellPlayerTeam==editTeam) PlayGfx_ShellNumber( editNo );
			break;

		case INFO_POS:

			CheckForPositionChange(btn);

/******			
			i=editPos;
			if(btn&CTRL_PAD_LEFT)
			{
				editPos=WrapAdd(editPos,-1,0,NUM_EDIT_POSITIONS-1);
			}

			if(btn&CTRL_PAD_RIGHT)
			{
				editPos=WrapAdd(editPos,1,0,NUM_EDIT_POSITIONS-1);
			}
			
			if(i!= editPos)
			{	// if position changed....
				editHeight = DefaultHeightByPosition[editPos];	// change H/W
				editWeight = DefaultWeightByPosition[editPos];	

				NeedNewBody = 1;
				SetEditAbilitiesByPosition(editPos);
			}
******/
			break;

		case INFO_HEIGHT:
			
			i = editHeight;

			if(btn&CTRL_PAD_LEFT)	editHeight=ClampAdd(editHeight,-1,0,MAX_HEIGHT-MIN_HEIGHT);
			if(btn&CTRL_PAD_RIGHT)	editHeight=ClampAdd(editHeight,1,0,MAX_HEIGHT-MIN_HEIGHT);
			if(i != editHeight)
			{
				NeedNewBody = 1;
			}				
			break;

		case INFO_WEIGHT:
			i = editWeight;
			if(btn&CTRL_PAD_LEFT)	editWeight=ClampAdd(editWeight,-1,0,MAX_WEIGHT-MIN_WEIGHT);
			if(btn&CTRL_PAD_RIGHT)	editWeight=ClampAdd(editWeight,1,0,MAX_WEIGHT-MIN_WEIGHT);
			if(i != editWeight)
			{
				NeedNewBody = 1;
			}				
//			SetThinChap();
//			ShellPlayerSetBody(256,editBodyType,editHeadType);
			break;

		case INFO_HEAD:
			i=editHead;
//			if(btn&CTRL_PAD_LEFT)	editHead=ClampAdd(editHead,-1,0,19);
//			if(btn&CTRL_PAD_RIGHT)	editHead=ClampAdd(editHead,1,0,19);
			if(btn&CTRL_PAD_LEFT)	editHead = (editHead+NUM_CUSTOM_HEADS-1)%NUM_CUSTOM_HEADS;
			if(btn&CTRL_PAD_RIGHT)	editHead = (editHead+1)%NUM_CUSTOM_HEADS;
			if(i!=editHead)
			{
//phil				SetThinChap();
//phil				ShellPlayerSetCamMode(2);
				PlayGfx_ShellHead( editHead, editHair );
				clampSound= SFX_ID_CHANGE;
				dataChanged=1;
			}
			break;
/*****
		case INFO_HAIR:
			i=editHair;
			if(btn&CTRL_PAD_LEFT)	editHair = (editHair+NUM_CUSTOM_HAIR-1)%NUM_CUSTOM_HAIR;
			if(btn&CTRL_PAD_RIGHT)	editHair = (editHair+1)%NUM_CUSTOM_HAIR;
			if(i!=editHair)
			{
//				SetThinChap();
//				ShellPlayerSetCamMode(2);
				PlayGfx_ShellHead( editHead, editHair );
				dataChanged=1;
				clampSound= SFX_ID_CHANGE;
			}
			break;
*****/

		case INFO_HAIR_STYLE:
			i=editHairStyle;
			if(btn&CTRL_PAD_LEFT)	editHairStyle = (editHairStyle + NUM_HAIR_STYLES-1) % NUM_HAIR_STYLES;
			if(btn&CTRL_PAD_RIGHT)	editHairStyle = (editHairStyle + 1) % NUM_HAIR_STYLES;
			if(i!=editHairStyle)
			{
//				SetThinChap();
//				ShellPlayerSetCamMode(2);
				SetTrueEditHair();
				PlayGfx_ShellHead( editHead, editHair );
				dataChanged=1;
				clampSound= SFX_ID_CHANGE;
			}
			break;

		case INFO_HAIR_COLOR:
			i=editHairColor;
			if(btn&CTRL_PAD_LEFT)	editHairColor = (editHairColor + NUM_HAIR_COLORS-1) % NUM_HAIR_COLORS;
			if(btn&CTRL_PAD_RIGHT)	editHairColor = (editHairColor + 1) % NUM_HAIR_COLORS;
			if(i!=editHairColor)
			{
//				SetThinChap();
//				ShellPlayerSetCamMode(2);
				SetTrueEditHair();
				PlayGfx_ShellHead( editHead, editHair );
				dataChanged=1;
				clampSound= SFX_ID_CHANGE;
			}
			break;

		case INFO_WRIST:
			if(btn&CTRL_PAD_LEFT)
			{
				editWrist = (editWrist+NUM_LR_CHOICES-1)%NUM_LR_CHOICES;
				clampSound= SFX_ID_CHANGE;
				dataChanged=1;
				PlayGfx_ShellWrists( editWrist );
			}
			if(btn&CTRL_PAD_RIGHT)
			{
				editWrist = (editWrist+1)%NUM_LR_CHOICES;
				clampSound= SFX_ID_CHANGE;
				dataChanged=1;
				PlayGfx_ShellWrists( editWrist );
			}

			break;

		case INFO_ARMS:
			if(btn&CTRL_PAD_LEFT)
			{
				editArms = (editArms+NUM_LR_CHOICES-1)%NUM_LR_CHOICES;
				clampSound=SFX_ID_CHANGE;
				dataChanged=1;
				PlayGfx_ShellArms( editArms );
			}

			if(btn&CTRL_PAD_RIGHT)
			{
				editArms = (editArms+1)%NUM_LR_CHOICES;
				clampSound= SFX_ID_CHANGE;
				dataChanged=1;
				PlayGfx_ShellArms( editArms );
			}

			break;

		case INFO_KNEES:
			if(btn&CTRL_PAD_LEFT)
			{
				editKnees = (editKnees + NUM_LR_CHOICES-1)%NUM_LR_CHOICES;
				clampSound= SFX_ID_CHANGE;
				dataChanged=1;
				PlayGfx_ShellKnees( editKnees );
			}

			if(btn&CTRL_PAD_RIGHT)
			{
				editKnees = (editKnees+1)%NUM_LR_CHOICES;
				clampSound= SFX_ID_CHANGE;
				dataChanged=1;
				PlayGfx_ShellKnees( editKnees );
			}

			break;

		case INFO_SOCKS:
			if(btn & (CTRL_PAD_LEFT | CTRL_PAD_RIGHT))
			{
				editSocks ^= 1;
				clampSound= SFX_ID_CHANGE;
				dataChanged=1;
				PlayGfx_ShellSocks( editSocks );
			}
			break;



/***
		case INFO_ROOKIE_MODE:
			if(btn&CTRL_PAD_LEFT)
			{	
				editRookieMode = 0;
				if(editYears == ROOKIE_MODE_EXP)
				{
					editYears = ZERO;
				}				
			}

			if(btn&CTRL_PAD_RIGHT)
			{
				editRookieMode = 1;
				editYears=ROOKIE_MODE_EXP;
			}
			
			break;
*****/
		case INFO_ABILITIES:
			if((btn&CTRL_FIRE_A) && !(pendingLoadDelay))
			{
				newState=asb__gStateNextFwd[newState];
				sound=SFX_ID_OK;
			}
			break;
	}

/******
	if(editRookieMode)
	{
		editYears=ROOKIE_MODE_EXP;
		MaxPoolPoints = NUM_ABILITIES*START_ROOKIE_ATTR + 50;	// 50 extra to allocate as necessary
	}
	else
	{
		MaxPoolPoints = NUM_ABILITIES*100;	// unlimited
	}
***/
	MaxPoolPoints = NUM_ABILITIES*100;	// unlimited

	// if hit end of range, stop auto repeat
	if(clampSound!=-1) sound=clampSound;
	if(clampSound== SFX_ID_CANTMOVE)
	{
		reptDelay[0]=reptDelay[1]=INIT_DELAY;
	}

	// All done.

	allDone:

	if(NeedNewBody)
	{
		NeedNewBody = 0;
		DoBodyTypeChange();
	}
	
	if (sound >= 0)
	{
		AudioPlaySfx(sound, 11025, 255, 7);
	}

/***
//	if(CreateRookieMode && fl___gReverse)
	{
		newState = asb__gStateNextRev[STATE_CREATE_ROOKIE];	// skip ScreenS0  - must be here, can't be in ExitScreenS1
	}
***/

	return (newState);
}

/**************************************************************************

	Used in custom user

	editString MUST be set up !!!!

	returns 0 if done

**************************************************************************/

int InputName(int btn, int *sound, int maxlen)
{
int stillinputting = 1;
int i;

				if(btn & (CTRL_FIRE_B) )
				{
					stillinputting = ZERO;
					*sound = SFX_ID_BACK;
					FixString(editString,0);
					FixString2(editString);
				}
				else if(btn & (CTRL_PAD_RIGHT | CTRL_FIRE_A))
				{
					if(!strlen(editString))
					{
						*sound=SFX_ID_CANTMOVE;
					}
					else
					{
						cursorPos+=1;
					}
					
					if(cursorPos >= maxlen)
					{ 
						*sound=SFX_ID_CANTMOVE;
						cursorPos--;
					}
					if(cursorPos > (strlen(editString)))
					{
						strcat(editString," ");
					}
					if(*sound != SFX_ID_CANTMOVE)
						*sound= SFX_ID_SCROLL;
				}
				else if(btn & CTRL_PAD_LEFT)
				{
					if(cursorPos > 0)
					{
						cursorPos--; *sound= SFX_ID_SCROLL;
					}
					else *sound= SFX_ID_CANTMOVE;
				}
				else if(btn & CTRL_TRIGGER)
				{		// erase char
					if(!strlen(editString)) *sound= SFX_ID_CANTMOVE;
					else if(cursorPos==0)
					{
						for(i=0;editString[i];i++) editString[i]=editString[i+1];
						*sound= SFX_ID_CHANGE;
					}
					else
					{
//						cursorPos--;
						for(i=cursorPos;editString[i];i++) editString[i]=editString[i+1];
						cursorPos--;
						*sound= SFX_ID_CHANGE;
					}
					FixString(editString,0);
				}
				else if(btn & CTRL_PAD_UP)
				{
					if(cursorPos >= strlen(editString))
					{
						strcat(editString," ");
					}
					editString[cursorPos] = WrapLetter(editString[cursorPos],-1);
					*sound = SFX_ID_CHANGE;
					FixString(editString,0);
				}
				else if(btn & CTRL_PAD_DOWN)
				{
					if(cursorPos >= strlen(editString))
					{
						strcat(editString," ");
					}
					editString[cursorPos] = WrapLetter(editString[cursorPos],1);
					FixString(editString,0);
					*sound= SFX_ID_CHANGE;
				}


	return(stillinputting);
}




/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

#define S1_X1	208
#define S1_X1a	(S1_X1+MENU_LINE_W)
#define S1_X2	330
#define S1_Y1	16
#define S1_Y1a	(S1_Y1+MENU_LINE_H)


struct rcbox S1ScreenBoxes[] = 
{
	{0, 0,512,S1_Y1, RGB_TRANS_YEL,NO_CORNERS},


	{S1_X1a,S1_Y1a,S1_X2-S1_X1a,MENU_BOTTOM_LINE_Y-S1_Y1a,
				RGB_TRANS_RED,SPR_RED_TL,SPR_RED_TR,SPR_RED_BL,SPR_RED_BR},

	{-1,0,0,0,0,NO_CORNERS}
};


Gfx *DrawShellPlayer(Gfx *gp)	// called at least 3 places
{
extern dyn	*dynamicp;
extern int	dbuf;

	if(pendingLoadDelay>4 || !pendingLoadDelay)
	{
		gp=ShellPlayerRender(gp,dynamicp,dbuf);
gDPPipeSync( gp++ );
gDPSetScissor(gp++,
	G_SC_NON_INTERLACE,
	0,
	0,
	currentProcess->ScreenX,
	currentProcess->ScreenY);
gp = PlayGfx_ShellDraw( gp, dbuf, dynamicp );
	}

	// restore shell matrices!
	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(dynamicp->shellOrtho)),
		G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(dynamicp->identity)),
		G_MTX_MODELVIEW  | G_MTX_LOAD | G_MTX_NOPUSH);
	gDPSetScissor(gp++,
		G_SC_NON_INTERLACE,
		0,
		0,
		currentProcess->ScreenX,
		currentProcess->ScreenY);
	vp.vp.vscale[0] = currentProcess->ScreenX*2;
	vp.vp.vscale[1] = currentProcess->ScreenY*2;
	vp.vp.vtrans[0] = currentProcess->ScreenX*2;
	vp.vp.vtrans[1] = currentProcess->ScreenY*2;
	gSPViewport(gp++, &vp);

	return(gp);
}

//----------------------------------------------------------------

#define S1_TEXT_START	(40-6)		// 42
#define S1_LINE_HEIGHT	11		// 14

//#define S1_NUM_PAL	FPAL_WHITE
#define S1_NUM_PAL_OFF	FPAL_WHITE
#define S1_NUM_PAL_ON	FPAL_YELLOW	//red is too dark

#define S1_NUM_PAL	opt == ((k-S1_TEXT_START)/S1_LINE_HEIGHT) ? S1_NUM_PAL_ON: S1_NUM_PAL_OFF

Gfx *DrawScreenS1(int state,Gfx *gp)
{

int		i,j,k,l;
TXTCEL_T	*pcl__Txt;
char		tmp[80];
//	extern dyn	*dynamicp;
//	extern int	dbuf;




#if 1
	gp =DrawRCBoxes(gp, S1ScreenBoxes);	// transparent BG boxes

	gp = DrawBlankBox(gp, S1_X2, 513, S1_Y1a, MENU_BOTTOM_LINE_Y,BB_LEFT_BOX);
	gp = DrawBlankBox(gp, -1, S1_X1,  S1_Y1a, MENU_BOTTOM_LINE_Y,BB_RIGHT_BOX);

	DRAW_MENU_HLINE(S1_Y1);		// must be drawn after lines/blank boxes to cover up anti-aliasing
	DRAW_MENU_HLINE(MENU_BOTTOM_LINE_Y);

#else

	// render boxes
	gp=RenderShadedBox(gp,110,16,102,180,greyBox);
	gp=RenderShadedBox(gp,208,16,126,180,blueBox);
	gp=RenderCurvyBox(gp,330,16,150,180,blackBox);
	gp=RenderTBOX(gp,110,18+172,4,208-172,RGB_SOLID_YEL);

	// render side bar
	//gp=RenderSprite(gp,SPR_PTR(SPR_STITLE1),(UI)puw__gPalette,46,16);

#endif

	// Help message.

	gp = DrawHelpTeaser(gp, 290);

	// render list of fields...
	EditRenderText("Team",161,S1_TEXT_START-S1_LINE_HEIGHT,FONT_BLKCN18,FPAL_WHITE,FLG_CTR);
	strcpy(tmp,pacl_gTeamRom[editTeam+1].pcz__tCityName);
	EditRenderText(tmp,221,S1_TEXT_START-S1_LINE_HEIGHT,FONT_BLKCN18,S1_NUM_PAL_OFF,0);

	editHiX=-1;
	for(i=0;i<NUM_INFO_FIELDS;i++)
	{

#if 0	// space between "abilities" and others	
		if(i==NUM_INFO_FIELDS-1)
		{
			j=(i+1)*S1_LINE_HEIGHT + S1_TEXT_START;
		}
		else
		{
			j=i*S1_LINE_HEIGHT + S1_TEXT_START;
		}
#else
		j = i*S1_LINE_HEIGHT + S1_TEXT_START;
#endif
		EditRenderText(infoFields[i],
			       161,
			       j,
		               FONT_BLKCN18,
//			       (opt==i)?FPAL_RED:FPAL_WHITE,
			       FPAL_WHITE,
			       ((opt==i)?FLG_HI:0) | FLG_CTR);
	}
	if(editHiX!=-1)
	{
//		editHiX-=4; 
		editHiY-=2;
//		editHiW+=8;
//		editHiH+=4;
		editHiW = S1_X1 - MENU_LEFT_KEYX - 6;	//102-8;
		if(opt == NUM_INFO_FIELDS-1)
			editHiW -= 6;

		editHiX = MENU_LEFT_KEYX+2;	//114;
		gp = DrawOvalCursorHilite(gp, editHiX+editHiW/2,editHiY+5,editHiW);

//		gp=RenderTBOX(gp,editHiX,editHiY,editHiW,editHiH,RGB_SOLID_WHT);
//		gp=RenderTSHD(gp,editHiX,editHiY+editHiH,editHiW,3);
		editHiX=-1;
	}

	// render data...
	k = S1_TEXT_START; l = S1_LINE_HEIGHT;
	
	RenderEditField(editFirstName,221,k,FONT_BLKCN18,S1_NUM_PAL,0,(opt==INFO_FIRSTNAME?editing:0),cursorPos);
	
	k+=l;
	RenderEditField(editLastName,221,k,FONT_BLKCN18,S1_NUM_PAL,0,(opt==INFO_LASTNAME?editing:0),cursorPos);
	
	k+=l;
	IntToStr(editAge,tmp);
	EditRenderText(tmp,221,k,FONT_BLKCN18,S1_NUM_PAL,0);
	
	k+=l;
	if(editYears ==  ROOKIE_MODE_EXP)
	{
//		strcpy(tmp,"Always Rookie");
		strcpy(tmp,"Career Player");
	}
	else if(editYears)	//  && editYears !=  ROOKIE_MODE_EXP)
	{
		IntToStr(editYears,tmp);
	}
	else
	{
		strcpy(tmp,"Rookie");
	}
	EditRenderText(tmp,221,k,FONT_BLKCN18,S1_NUM_PAL,0);
	
	k+=l;
	if(editNo==100)	strcpy(tmp,"00");
	else		IntToStr(editNo,tmp);
	EditRenderText(tmp,221,k,FONT_BLKCN18,S1_NUM_PAL,0);
	
	k+=l;
	EditRenderText(positionNames[editPos],221,k,FONT_BLKCN18,S1_NUM_PAL,0);
	
	k+=l;
	IntToStr((((int)editHeight)+MIN_HEIGHT)/12,tmp);
	strcat(tmp,"'");
	IntToStr((((int)editHeight)+MIN_HEIGHT)%12,&tmp[strlen(tmp)]);
	strcat(tmp,"\"");
	EditRenderText(tmp,221,k,FONT_BLKCN18,S1_NUM_PAL,0);
	
	k+=l;
	IntToStr(((int)editWeight)+MIN_WEIGHT,tmp);
	EditRenderText(tmp,221,k,FONT_BLKCN18,S1_NUM_PAL,0);
	
	k+=l;
	IntToStr(editHead+1,tmp);	// heads = 1-20  for consumers  (not 0-19 for programmers)
	EditRenderText(tmp,221,k,FONT_BLKCN18,S1_NUM_PAL,0);

	k+=l;
//	IntToStr(editHair+1,tmp);	// hair = 1-20  for consumers  (not 0-19 for programmers)
//	EditRenderText(tmp,221,k,FONT_BLKCN18,S1_NUM_PAL,0);

	IntToStr(editHairStyle+1,tmp);	// hair = 1-20  for consumers  (not 0-19 for programmers)
	EditRenderText(tmp,221,k,FONT_BLKCN18,S1_NUM_PAL,0);

	k+=l;
	IntToStr(editHairColor+1,tmp);	// hair = 1-20  for consumers  (not 0-19 for programmers)
	EditRenderText(tmp,221,k,FONT_BLKCN18,S1_NUM_PAL,0);

	k+=l;
	EditRenderText(LRText[editArms],221,k,FONT_BLKCN18,S1_NUM_PAL,0);

	k+=l;
	EditRenderText(LRText[editWrist],221,k,FONT_BLKCN18,S1_NUM_PAL,0);

	k+=l;
	EditRenderText(LRText[editKnees],221,k,FONT_BLKCN18,S1_NUM_PAL,0);

	k+=l;
	EditRenderText(SockText[editSocks],221,k,FONT_BLKCN18,S1_NUM_PAL,0);

//	k+=l;
//	EditRenderText(editRookieMode ? "On": "Off",221,k,FONT_BLKCN18,S1_NUM_PAL,0);

	// Finally draw characters.
	gp=DrawChrList(gp);

	// render shell player!
	
	gp = DrawShellPlayer(gp);
/********	
	if(pendingLoadDelay>4 || !pendingLoadDelay)
	{
		gp=ShellPlayerRender(gp,dynamicp,dbuf);
gDPPipeSync( gp++ );
gDPSetScissor(gp++,
	G_SC_NON_INTERLACE,
	0,
	0,
	currentProcess->ScreenX,
	currentProcess->ScreenY);
gp = PlayGfx_ShellDraw( gp, dbuf, dynamicp );
	}

	// restore shell matrices!
	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(dynamicp->shellOrtho)),
		G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(dynamicp->identity)),
		G_MTX_MODELVIEW  | G_MTX_LOAD | G_MTX_NOPUSH);
	gDPSetScissor(gp++,
		G_SC_NON_INTERLACE,
		0,
		0,
		currentProcess->ScreenX,
		currentProcess->ScreenY);
	vp.vp.vscale[0] = currentProcess->ScreenX*2;
	vp.vp.vscale[1] = currentProcess->ScreenY*2;
	vp.vp.vtrans[0] = currentProcess->ScreenX*2;
	vp.vp.vtrans[1] = currentProcess->ScreenY*2;
	gSPViewport(gp++, &vp);
************/

	// All done.
	return (gp);
}




/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

static	unsigned char                  sprScreenS2 [] =
{
	SPR_RED_TL,SPR_RED_TR,SPR_RED_BL,SPR_RED_BR,
//	SPR_PUR_BR,	// need if switch to view player
//	SPR_PUR_TR,
//	SPR_PUR_BL,
//	SPR_PUR_TL,

	//SPR_STITLE2,
	//SPR_LBITS,
	SPR_LEVBORD,
	0
};

static	char *abilityFields[NUM_ABILITIES]=
{
	"Shot Range",
	"Shooting",
	"3-Pointers",
	"Free Throws",
	"Dribbling",
	"Passing",
	"Speed",
	"Jumping",
	"Rebounding",
	"Strength",
	"Dunking",
	"Stealing",
	"Blocking",
	"Stamina"
};

int InitScreenS2(int state)
{
	int		i,j,k;

	// Load up the correct background image.
//	LoadShellBackgroundSpr(ID_SPR_BACK_KB3);
	BG_Load( BG_KOBE3, 0 );

	// Load up the sprites for this screen.
	LoadSpriteList(sprScreenS2);

	// init option
	opt=s2Opt;

	// set autorepeat for L and R
	reptDelay[0] = reptDelay[1] = INIT_DELAY;

	InitShellPlayer();


	SetEditPlayerTitles(STATE_S2);


	// All Done.
	return (state);
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ExitScreenS2(int state)
{

	PlayGfx_ShellDeinit();
	ShellPlayerOnScreen = 0;

	// Free up the sprites for this screen.
	FreeSpriteList(sprScreenS2);

	// remember option
	s2Opt=opt;


	ShellPlayerOnScreen = 0;

	// All Done.
	return (state);
}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ProcScreenS2(int oldState)		// editing attributes (ratings) of a created player
{
	int		newState = oldState;
	int		sound = -1;
	int		btn;
	int		i,j,k;

	btn=asi__gTeamBtn[EVERYBODY];


	if(editNoModifyFlag)
	{
		apcz_gStateHelpMsg[oldState] =  acz__gHelpScreenS2NoModify;
	}
	else
	{
		apcz_gStateHelpMsg[oldState] =  acz__gHelpScreenS2;	// assume
	}
		
	PoolPoints = ZERO;
	for(i = 0; i< NUM_ABILITIES; i++)
	{
		PoolPoints += editAbilities[i];
	}

	fl___gReverse = 0;

	// Are we displaying a popup ?

	if (si___gPopupVal < 0)
	{
		goto allDone;
	}
	
	// React to the results of a popup.

	if (si___gPopupVal > 0)		// "continue" is  only option
	{
		si___gPopupVal = 0;
		goto allDone;
	}


	if ((btn & (CTRL_FIRE_B)))
	{
		newState=asb__gStateNextRev[newState];
		fl___gReverse = 1;
		sound= SFX_ID_BACK;
		goto allDone;
	}
	if ((btn & (CTRL_FIRE_A)))
	{
		sound= SFX_ID_CANTMOVE;
		goto allDone;
	}

	// Exit button ?
	if (btn & (CTRL_START))
	{
		newState = asb__gStateNextFwd[newState];
		sound    = SFX_SHELL_STRT;
		goto allDone;
	}


	if(CreatePlayerMode == CREATE_PLAYER_CAREER)	// can only change position in rookie mode
	{
		CheckForPositionChange(btn);
		apcz_gStateHelpMsg[oldState] =  acz__gHelpScreenS2Rookie;

		goto allDone;
	}

	// process repeat...
	if(opt!=ABILITY_RANGE)
	{
		if(!(asi__gTeamPad[EVERYBODY] & CTRL_PAD_LEFT))		reptDelay[0]=INIT_DELAY;
		else if(reptDelay[0]) reptDelay[0]--;
		if(!reptDelay[0]) btn |= CTRL_PAD_LEFT;
		if(!(asi__gTeamPad[EVERYBODY] & CTRL_PAD_RIGHT))	reptDelay[1]=INIT_DELAY;
		else if(reptDelay[1]) reptDelay[1]--;
		if(!reptDelay[1]) btn |= CTRL_PAD_RIGHT;
	}
	else
	{
		reptDelay[0]=INIT_DELAY;
		reptDelay[1]=INIT_DELAY;
	}
	if(btn & (CTRL_PAD_UP | CTRL_PAD_DOWN))
	{
		reptDelay[0]=INIT_DELAY;
		reptDelay[1]=INIT_DELAY;
		sound= SFX_ID_SCROLL;
	}

	if ((btn & (CTRL_PAD_UP)))
	{
		opt=(opt+(NUM_ABILITIES-1))%NUM_ABILITIES;
		goto allDone;
	}

	if ((btn & (CTRL_PAD_DOWN)))
	{
		opt=(opt+1)%NUM_ABILITIES;
		goto allDone;
	}

	clampSound=-1;

	if(btn & (CTRL_PAD_LEFT | CTRL_PAD_RIGHT | CTRL_C_LEFT | CTRL_C_RIGHT) )
	{
		if(editNoModifyFlag)
		{
			InitPopup(editPlayerTitle,NoModifyText1,NULL);
			sound= SFX_ID_CANTMOVE;
			goto allDone;
		}
	}

	if(opt==ABILITY_RANGE)
	{
	// 5/11/99 - keep all [edit] abilities in range 0-100 mjk
	// ABILITY_RANGE is scaled 0-4 when STORED in ROM
//		if(btn & CTRL_PAD_LEFT)	editAbilities[opt]=ClampAdd(editAbilities[opt],-1,0,4);
//		if(btn & CTRL_PAD_RIGHT)editAbilities[opt]=ClampAdd(editAbilities[opt],1,0,4);
		if(btn & ( CTRL_PAD_LEFT | CTRL_C_LEFT))
		{
			editAbilities[opt] = PoolClampAdd(editAbilities[opt],-25,0,100);
		}
		if(btn & (CTRL_PAD_RIGHT | CTRL_C_RIGHT))
		{
			editAbilities[opt] = PoolClampAdd(editAbilities[opt],25,0,100);
		}
//		if(btn & (CTRL_C_LEFT | CTRL_C_RIGHT))
//		{
//			sound= SFX_ID_CANTMOVE;
//		}
	}
	else
	{
		if(btn & CTRL_PAD_LEFT)
		{
			editAbilities[opt]=PoolClampAdd(editAbilities[opt],-1,0,100);
		}
		if(btn & CTRL_PAD_RIGHT)
		{
			editAbilities[opt]=PoolClampAdd(editAbilities[opt],1,0,100);
		}
		if(btn & CTRL_C_LEFT)
		{
			editAbilities[opt]=PoolClampAdd(editAbilities[opt],-10,0,100);
		}
		if(btn & CTRL_C_RIGHT)
		{
			editAbilities[opt]=PoolClampAdd(editAbilities[opt],10,0,100);
		}

	}

	// if hit end of range, stop auto repeat
	if(clampSound!=-1) sound=clampSound;

	if(clampSound ==  SFX_ID_CANTMOVE)
	{
		reptDelay[0]=reptDelay[1]=INIT_DELAY;
	}

	// All done.

	allDone:

	if (sound >= 0)
	{
		AudioPlaySfx(sound, 11025, 255, 7);
	}

	return (newState);
}


void SetAbilityRangeString(int num, char *tmp)
{
	IntToStr((((int)num/25)*17/4) + 8,tmp);
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

Gfx *DrawScreenS2(int state,Gfx *gp)
{

int		i,j,k,l;
int hilite;
TXTCEL_T	*pcl__Txt;
char		tmp[80];
//	extern dyn	*dynamicp;
//	extern int	dbuf;


#if 1
	gp =DrawRCBoxes(gp, S1ScreenBoxes);	// transparent BG boxes

	gp = DrawBlankBox(gp, S1_X2, 513, S1_Y1a, MENU_BOTTOM_LINE_Y,BB_LEFT_BOX);
	gp = DrawBlankBox(gp, -1, S1_X1,  S1_Y1a, MENU_BOTTOM_LINE_Y,BB_RIGHT_BOX);

	DRAW_MENU_HLINE(S1_Y1);		// must be drawn after lines/blank boxes to cover up anti-aliasing
	DRAW_MENU_HLINE(MENU_BOTTOM_LINE_Y);

#else

	// render boxes
	gp=RenderShadedBox(gp,110,16,102,192,greyBox);
	gp=RenderShadedBox(gp,208,16,126,192,blueBox);
	gp=RenderCurvyBox(gp,330,16,150,192,blackBox);
	gp=RenderTBOX(gp,110,18+172,4,208-172,RGB_SOLID_YEL);

	// render side bar
	//gp=RenderSprite(gp,SPR_PTR(SPR_STITLE2),(UI)puw__gPalette,46,16);
#endif

	// Help message.

	gp = DrawHelpTeaser(gp, 290);

	// render list of fields...
	editHiX=-1;
	for(i=0;i<NUM_ABILITIES;i++)
	{
		j=i*13+25;

		hilite = (opt==i && !editRookieMode);
		EditRenderText(abilityFields[i], 161, j,
		               FONT_BLKCN18,
//			       (hilite)?FPAL_RED:FPAL_WHITE,
			       FPAL_WHITE,
			       ((hilite)?FLG_HI:0) | FLG_CTR);
	}

	if(editHiX != -1)
	{
//		editHiX-=4;
		editHiY-=2;
//		editHiW+=8;
//		editHiH+=4;
		editHiW = S1_X1 - MENU_LEFT_KEYX - 4;	//102-8;

		editHiX = MENU_LEFT_KEYX+2;	//114;
		gp = DrawOvalCursorHilite(gp, editHiX+editHiW/2,editHiY+5,editHiW);

//		editHiW=102-8;
//		editHiX=114;
//		gp=RenderTBOX(gp,editHiX,editHiY,editHiW,editHiH,RGB_SOLID_WHT);
//		gp=RenderTSHD(gp,editHiX,editHiY+editHiH,editHiW,3);
		editHiX=-1;
	}

	// render bar-graph style abilities...
	for(i=0;i<NUM_ABILITIES;i++)
	{
		int		q;
		j=i*13+25;

		// get percentage
/***	if(i==ABILITY_RANGE)
		{	
			k=((int)editAbilities[i])*100/4;
		}
		else	***/
		{
			k=((int)editAbilities[i]);
		}


		// set col
		barCols[4]=(100-k)*128/100;
		barCols[5]=k*128/100;
		barCols[6]=0;
		barCols[7]=255;
		memcpy(&barCols[8],&barCols[4],4);

		// render box
		gp=RenderBAR(gp,221,j-1,100*k/100,11,barCols);
		gp=RenderTSHD(gp,221,j+9,100*k/100,3);

		// render text
		if(i==ABILITY_RANGE)
		{
//			IntToStr(((int)editAbilities[i]*17/4) + 8,tmp);
//			IntToStr((((int)editAbilities[i]/25)*17/4) + 8,tmp);
			SetAbilityRangeString(editAbilities[i], tmp);
			strcat(tmp," feet");
		}
		else
		{
			IntToStr(editAbilities[i],tmp);
//			strcat(tmp,"%");
		}
		EditRenderText(tmp,	271,j,
		        FONT_BLKCN18,
//			(i==opt) || editRookieMode ? FPAL_WHITE:FPAL_GREY,
//			(i==opt) || editRookieMode ? FPAL_WHITE:FPAL_YELLOW,
			(i==opt) || editRookieMode ? FPAL_YELLOW:FPAL_WHITE,
			FLG_CTR | FLG_SHADOW);
	}

/*******
	if(editRookieMode)
	{
		char string[32];
		strcpy(string,"Remaining Points:");
		EditRenderText(string,400,25,FONT_BLKCN18,FPAL_WHITE,FLG_CTR);
		int2str(string,MaxPoolPoints - PoolPoints);
		EditRenderText(string,400,35,FONT_BLKCN18,FPAL_WHITE,FLG_CTR);
	}
*****/

	// Finally draw characters.
	gp=DrawChrList(gp);

	// render shell player!

	gp = DrawShellPlayer(gp);

#if 0
	if(pendingLoadDelay>4 || !pendingLoadDelay)
	{
		gp=ShellPlayerRender(gp,dynamicp,dbuf);
/*****
	gDPPipeSync( gp++ );
	gDPSetScissor(gp++,
		G_SC_NON_INTERLACE,
		0,
		0,
		currentProcess->ScreenX,
		currentProcess->ScreenY);
		gp = PlayGfx_ShellDraw( gp, dbuf, dynamicp );
**********/
	}

	
	// restore shell matrices!
	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(dynamicp->shellOrtho)),
		G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
	gSPMatrix(gp++,
		OS_K0_TO_PHYSICAL(&(dynamicp->identity)),
		G_MTX_MODELVIEW  | G_MTX_LOAD | G_MTX_NOPUSH);
	gDPSetScissor(gp++,
		G_SC_NON_INTERLACE,
		0,
		0,
		currentProcess->ScreenX,
		currentProcess->ScreenY);
	vp.vp.vscale[0] = currentProcess->ScreenX*2;
	vp.vp.vscale[1] = currentProcess->ScreenY*2;
	vp.vp.vtrans[0] = currentProcess->ScreenX*2;
	vp.vp.vtrans[1] = currentProcess->ScreenY*2;
	gSPViewport(gp++, &vp);
#endif


	ShadFont_Color(SHADFNT_RGB_WHITE);	
	ShadFont_Set(TinyShadFont);


	gp =  DrawPlyrShadow2NamesCentered(gp,
					editFirstName,editLastName,
					410,30,512-30-S1_X2);

/***
	strcpy(tmp,editFirstName);
	strcat(tmp," ");
	strcat(tmp,editLastName);
	StrToUprCase(tmp);
	gp = ShadFont_DrawCentered(gp,tmp,410,30);	**/
	
	if(CreatePlayerMode == CREATE_PLAYER_ROOKIE)
	{
		gp = DrawOvalCursor(gp, 410,42,150);
//		gp=RenderTBOX(gp,S1_X2+10,42-5,170,11,RGB_TRANS_WHT);
	}
	gp = ShadFont_DrawCentered(gp,positionNames[editPos],410,42);


	// All done.
	return (gp);
}






/***************************************************************************
 *
 *				 R O L E    P L A Y I N G    R O O K I E
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/


playerRPstatdata_t  CustomPlyrStatsData[CUSTOM_PLYRS];	//112 x 20 = 2240 bytes



void ClearCustomPlayerStats(int cplyrindex)
{

	if(cplyrindex >= ZERO && cplyrindex < CUSTOM_PLYRS)
	{	//index is valid
		memset(&CustomPlyrStatsData[cplyrindex], ZERO, sizeof(playerRPstatdata_t));
	}

}


//   global vars used in Rookie Role Play Mode  ---------------

int		gNumGameRPPlayers;
int		RPIndex=0;

PlyrRamData_T *     GameRPPlyrRamPtrs[CUSTOM_PLYRS];
global PlyrRamData_T *		gRPlyrRamPtr;

//struct PlayerRPStatData CustomPlayerRPStats[CUSTOM_PLYRS];	


/*--------------------------------------------------*/


void BuildGameRPPlayerData(void)
{
int t,numplayers;
PlyrRamData_T *     pcl__PlyrRam;
PlyrRomData_T *     pcl__PlyrRom;


	gNumGameRPPlayers=0;

// test only
/******	
	pcl__PlyrRom = &pacl_gPlyrRom[38];
	pcl__PlyrRom->ub___pExp = ROOKIE_MODE_EXP;	// kobe


	pcl__PlyrRom = &pacl_gPlyrRom[98];
	pcl__PlyrRom->ub___pExp = ROOKIE_MODE_EXP;		// fisher
******/

// test only - force 3 players as rookies
#if 0	// defined(DEBUG)
	pcl__PlyrRam	= pcl__gMatch->apcl_mTeamRam[0]->pcl__tPlyrRam;
	pcl__PlyrRom = pcl__PlyrRam->pcl__pPlyrRom;
	pcl__PlyrRom->ub___pExp = ROOKIE_MODE_EXP;


	pcl__PlyrRam = pcl__gMatch->apcl_mTeamRam[1]->pcl__tPlyrRam;
	pcl__PlyrRom = pcl__PlyrRam->pcl__pPlyrRom;
	pcl__PlyrRom->ub___pExp = ROOKIE_MODE_EXP;
#endif

	for (t = 0; t < 2; t++)
	{
		pcl__PlyrRam	= pcl__gMatch->apcl_mTeamRam[t]->pcl__tPlyrRam;
		numplayers		= pcl__gMatch->apcl_mTeamRam[t]->sb___tPlayers;

		while (numplayers--)
		{
			pcl__PlyrRom = pcl__PlyrRam->pcl__pPlyrRom;

			if (pcl__PlyrRom->ub___pExp == ROOKIE_MODE_EXP 
#if defined(DEBUG)
//				|| pcl__PlyrRom->ub___pExp == ZERO		// test only - true rookie
#endif
			   )
			{		// save these for futire reference
				GameRPPlyrRamPtrs[gNumGameRPPlayers] = pcl__PlyrRam;
				gNumGameRPPlayers++;
			}

			pcl__PlyrRam += 1;
		}
	}
}


void SetValidRPIndex(int incvalue)	
{
	RPIndex += incvalue;

	if(RPIndex < ZERO)
	{
		RPIndex = gNumGameRPPlayers-1;
	}
	else if(RPIndex >= gNumGameRPPlayers)
	{
		RPIndex = ZERO;
	}
}


/************

void	EvaluateRPPlayerForImprovement(void)
{
PlyrRamStat_T	*PlyrGameStats;
int		i,r;
int		pct,rebs,minutes,abil;


	PlyrGameStats = &(gRPlyrRamPtr->cl___pStatGame);

	for(i=0; i < NUM_ABILITIES; i++)
	{
		
		r = 0;	// assume

		if(PlyrGameStats->ub___pGP)
		{

		  rebs = PlyrGameStats->uw___pOFF + PlyrGameStats->uw___pDEF;	
		  minutes = PlyrGameStats->uw___pMIN/4;	// pMIN is 15 sec increments

  		  switch (i)
		  {
			case ABILITY_RANGE:
				break;
			
			case ABILITY_SHOOT:
				if(PlyrGameStats->uw___pFGM > 4)
				{
					r = 1;
				}
				break;

			case ABILITY_3PT:
				if(PlyrGameStats->uw___p3PM > 1)
				{
					r = 1;
				}
				break;

			case ABILITY_FT:
				if(PlyrGameStats->uw___pFTA > 0)
				{
					pct = (PlyrGameStats->uw___pFTM*100) / PlyrGameStats->uw___pFTA;
					if(pct >= gRPlyrRamPtr->pcl__pPlyrRom->ub___pAttrFT)
					{
						r = 1;
					}
					else
					{
						r = -1;
					}
				
				}
				break;

			case ABILITY_DRIB:
				if(PlyrGameStats->uw___pTO < 2 && minutes > 10)
				{
					r = 1;
				}
				break;

			case ABILITY_PASS:
				if(PlyrGameStats->uw___pAST > 3)
				{
					r = 1;
				}
				break;

			case ABILITY_SPEED:
				if(ReadRandomByte() < 15)
				{
					r = 1;
				}
				break;

			case ABILITY_JUMP:
				if(PlyrGameStats->uw___pBLK + rebs/2 > 4)
				{
					r = 1;
				}
				break;

			case ABILITY_REB:
				if(rebs > 4)
				{
					r = 1;
				}
				break;

			case ABILITY_STRENGTH:
				if(ReadRandomByte() < 10)
				{
					r = 1;
				}
				break;

			case ABILITY_DUNK:
				break;

			case ABILITY_STEAL:
				if(PlyrGameStats->uw___pSTL > 2)
				{
					r = 1;
				}
				break;

			case ABILITY_BLOCK:
				if(PlyrGameStats->uw___pBLK > 2)
				{
					r = 1;
				}
				break;

			case ABILITY_STAMINA:
				if(minutes  > 24)	// pMIN is 15 sec increments
				{
					r = 1;
				}
				break;

		  }	// end switch
		}
		
		abil = editAbilities[i] + r;	// assume

		if(abil > 100)
			abil = 100;
		else if(abil < 1)
			abil = 1;

		newAbilities[i] = abil;
	}
}

*********/


/*********

void UpdateRookieAbilities(void)	// only call once per season or playoff game!!!!!
{
int i,p;
PlyrRamData_T *     PlyrRamPtr;
PlyrRomData_T *     PlyrRomPtr;

	BuildGameRPPlayerData();

	for(p=0; p< gNumGameRPPlayers; p++)		
	{
	
		PlyrRamPtr = GameRPPlyrRamPtrs[p];
		PlyrRomPtr = PlyrRamPtr->pcl__pPlyrRom;


		SetEditAbilitiesToRomAbilities(PlyrRomPtr);
	
		EvaluateRPPlayerForImprovement();

		for(i=0; i < NUM_ABILITIES; i++)
		{
			editAbilities[i] = newAbilities[i];
		}
	
		SetRomAbilitiesToEditAbilities(PlyrRomPtr);


	}
}

*******/

/*------------------------------------------------------------------------*/


int InitScreenRPPostGame(int state)	// shows all rookie players of this game
{
PlyrRamData_T *     PlyrRamPtr;
PlyrRomData_T *     PlyrRomPtr;

	BuildGameRPPlayerData();

	SetValidRPIndex(0);	// keep it valid

	// Load up the correct background image.
	if(gNumGameRPPlayers)
	{		// show team BG of the selected rookie
		PlyrRamPtr = GameRPPlyrRamPtrs[RPIndex];
		PlyrRomPtr = PlyrRamPtr->pcl__pPlyrRom;
//		LoadShellBackgroundSpr(*(apul_gTeamBackground[PlyrRomPtr->ub___pTeam]));
		BG_Load( PlyrRomPtr->ub___pTeam-1, 0 );
	}
	else
	{
//		LoadShellBackgroundSpr(ID_SPR_BACK_KB4);
		BG_Load( BG_KOBE4, 0 );
	}
	
	// All Done.
	return (state);
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ExitScreenRPPostGame(int state)	// menu
{


	// Free up the sprites for this screen.
//	FreeSpriteList(sprScreenS);


	// All Done.
	return (state);
}




/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ProcScreenRPPostGame(int oldState)	// Select Player (or NEW) to edit
{
int oldteam, newteam;
PlyrRamData_T *     PlyrRamPtr;
PlyrRomData_T *     PlyrRomPtr;
int sound = -1;

	// Local Variables.

/********
	if (asi__gTeamBtn[EVERYBODY]& (CTRL_START | CTRL_TRIGGER ) )
	{
		if(gNumGameRPPlayers)
		{
			oldState = STATE_RP_ABILITIES;
			gRPlyrRamPtr = GameRPPlyrRamPtrs[RPIndex];	// this is used in the next screen
		}
	}

	if (asi__gTeamBtn[EVERYBODY]& (CTRL_FIRE_A) )
	{
			oldState = asb__gStateNextFwd[oldState];
	}
********/

	if (asi__gTeamBtn[EVERYBODY]& (CTRL_FIRE_B) )
	{
		oldState = asb__gStateNextRev[oldState];
		sound = SFX_ID_BACK;
		goto allDone;
	}

	if (asi__gTeamBtn[EVERYBODY] &
			( CTRL_C_UP | CTRL_C_DOWN | CTRL_C_LEFT | CTRL_C_RIGHT| CTRL_PAD_LEFT | CTRL_PAD_RIGHT))
	{	// ignore these
			sound = SFX_SHELL_NOMV;
			goto allDone;
	}


	if(gNumGameRPPlayers)	
	{	// there are rookie players

		apcz_gStateHelpMsg[oldState] = acz__gHelpRookieMenu;	// 78 Rookie Role Play Mode after game screen

		if (asi__gTeamBtn[EVERYBODY]& (CTRL_FIRE_A) )
		{
			oldState = STATE_RP_ABILITIES;
			gRPlyrRamPtr = GameRPPlyrRamPtrs[RPIndex];	// this is used in the next screen
			sound = SFX_ID_OK;
		}
		else if(gNumGameRPPlayers > 1)	
		{	// choose between all rookie players

			if (asi__gTeamBtn[EVERYBODY]& (CTRL_PAD_UP | CTRL_PAD_DOWN) )
			{
				sound = SFX_ID_SCROLL;

				PlyrRamPtr = GameRPPlyrRamPtrs[RPIndex];
				PlyrRomPtr = PlyrRamPtr->pcl__pPlyrRom;
				oldteam = PlyrRomPtr->ub___pTeam;

				if (asi__gTeamBtn[EVERYBODY]& (CTRL_PAD_UP) )
				{
					SetValidRPIndex(-1);
				}
				else
//				if (asi__gTeamBtn[EVERYBODY]& (CTRL_PAD_DOWN) )
				{
					SetValidRPIndex(1);
				}

				PlyrRamPtr = GameRPPlyrRamPtrs[RPIndex];
				PlyrRomPtr = PlyrRamPtr->pcl__pPlyrRom;
				newteam = PlyrRomPtr->ub___pTeam;
				if(oldteam != newteam)
				{
//					LoadShellBackgroundSpr(*(apul_gTeamBackground[newteam]));
					BG_Load( newteam-1, 0 );
				}			
			}
		}
		else
		{
			apcz_gStateHelpMsg[oldState] = acz__gHelpRookieMenu1Rookie;	// 78 Rookie Role Play Mode after game screen

		}
	}
	else	// no rookie players
	{

		apcz_gStateHelpMsg[oldState] = acz__gHelpRookieMenuNoRookies;	// 78 Rookie Role Play Mode after game screen

		if (asi__gTeamBtn[EVERYBODY]& (CTRL_FIRE_A) )
		{
			oldState = asb__gStateNextFwd[oldState];
			sound = SFX_ID_OK;
		}
		else if (asi__gTeamBtn[EVERYBODY] & (CTRL_PAD_UP | CTRL_PAD_DOWN))
		{	// ignore these
			sound = SFX_SHELL_NOMV;
			goto allDone;
		}
	}



	allDone:

	if (sound >= 0)
	{
		AudioPlaySfx(sound, 11025, 255, 7);
	}

	return (oldState);
}


/*****************************************************************************/

#define RRP_Y1		40
#define RRP_Y1a		(RRP_Y1+MENU_LINE_H)

struct rcbox BasicScreenBoxes1[] = 
{	

	{0,   0,512,	 RRP_Y1,   RGB_TRANS_YEL,0,0,0,0},
	HLINE(0,  RRP_Y1,  512),

	{0, RRP_Y1a,	512,MENU_BOTTOM_LINE_Y-(RRP_Y1a),RGB_TRANS_RED,NO_CORNERS},

	HLINE(0,  MENU_BOTTOM_LINE_Y,  512),
	{-1,0,0,0,0,NO_CORNERS}

};


Gfx *DrawScreenRPPostGame(int state,Gfx *gp)
{
PlyrRamData_T *     PlyrRamPtr;
PlyrRomData_T *     PlyrRomPtr;
TeamRomData_T *     pcl__Team;
char  text[32];
int y,p;

	gp = DrawRCBoxes(gp, BasicScreenBoxes1);


	ShadFont_Color(SHADFNT_RGB_WHITE);	
	ShadFont_Set(SmallShadFont);

//	gp = ShadFont_DrawCentered(gp,"ROOKIE SKILL PLAYERS",286,RRP_Y1 - 12);
	gp = ShadFont_DrawCentered(gp,"CAREER PLAYERS",286,RRP_Y1 - 12);
	ShadFont_Set(TinyShadFont);


	if(gNumGameRPPlayers)
	{
		y = RRP_Y1a + 8;
		
		for(p=0; p< gNumGameRPPlayers; p++)		
		{
			if(p == RPIndex)
			{
				gp = DrawOvalCursorHilite(gp, 140+310/2,y+3,310);
//				gp=RenderTBOX(gp,,11,RGB_SOLID_YEL);
			}
			
			PlyrRamPtr = GameRPPlyrRamPtrs[p];
			PlyrRomPtr = PlyrRamPtr->pcl__pPlyrRom;
			gp =DrawPlyrShadowName(gp,PlyrRomPtr,150,y,320-150-5);

			pcl__Team = &pacl_gTeamRom[PlyrRomPtr->ub___pTeam];
			strcpy(text, pcl__Team->pcz__tCityName);
			StrToUprCase(text);
			gp = ShadFont_Draw(gp,text,320,y);

			y += 11;
		}
	}
	else
	{
//		gp = ShadFont_DrawCentered(gp,"NO ROOKIE SKILL PLAYERS",286,	RRP_Y1a + 15);
		gp = ShadFont_DrawCentered(gp,"NO CAREER PLAYERS",286,	RRP_Y1a + 15);
		gp = ShadFont_DrawCentered(gp,"COMPETED IN THIS GAME.",286,	RRP_Y1a + 25);
	}


	// Help message.
	gp = DrawHelpTeaser(gp, 290);

	// Finally draw characters.
	gp=DrawChrList(gp);


	// All done.
	return (gp);
}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/



int InitScreenRPAbilities(int state)	// @ Post Game
{

PlyrRomData_T *     rom;
int slot;

	rom  = gRPlyrRamPtr->pcl__pPlyrRom;	// this isn't correct yet...

	slot = rom->uw___pIndx - si___gPlyrRomCnt - 1;		//... but use it to get correct

	if(slot < 0 || slot >= CUSTOM_PLYRS)
	{
		slot = 0;
	}
	
	rom = &pacl_gCustom[slot];
	
	gCustomPlayerPtr = &pacl_gCustom[slot];		// needed for shell player body/acc/head etc.

	// Load up the correct background image of players team.
//	LoadShellBackgroundSpr(*(apul_gTeamBackground[rom->ub___pTeam]));
	BG_Load( rom->ub___pTeam-1, 0 );

	MoveRomAbilitiesToEditAbilities(rom);	// for display purposes

	 MoveRomDataToEditPlayerData(rom);	// sets height, weight, etc. for player render

//	EvaluateRPPlayerForImprovement();

//	MoveCustomPlayerDataToEditArea(gRPlyrRomPtr);	// set info for display - this was too much

	LoadSpriteList(sprScreenS2);

	sb___gSubShown = 0;	// will be 1 if showing player stats

	// set up in case switch to player stats
	InitializeLogos(rom->ub___pTeam, -1);
	LoadTeamLogo(rom->ub___pTeam, 1);

	puw__gPhoto0 = DecodePlyrImg(gRPlyrRamPtr, puw__gPhoto0);


	pcl__gITeam = gRPlyrRamPtr->pcl__pTeamRam;


	InitShellPlayer();

	// All Done.
	return (state);
}

/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ExitScreenRPAbilities(int state)
{

	PlayGfx_ShellDeinit();
	ShellPlayerOnScreen = 0;

	FreeTeamLogos();
	FreegPhotos();
	pcl__gITeam = NULL;	// fixes bug 401??

	// Free up the sprites for this screen.
	FreeSpriteList(sprScreenS2);


	// All Done.
	return (state);
}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ProcScreenRPAbilities(int oldState)	// Select Player (or NEW) to edit
{
	// Local Variables.
int sound = -1;


	apcz_gStateHelpMsg[oldState] = acz__gHelpRookieAbilities;	// assume

	if(sb___gSubShown)
	{	// player stats screen is up

		apcz_gStateHelpMsg[oldState] = acz__gHelpScreenFULLTIME ;	//acz__gXxxHelpScreenI3;	//acz__gHelpScreenI6;

		if (asi__gTeamBtn[EVERYBODY] & (CTRL_START | CTRL_FIRE_A | CTRL_TRIGGER | CTRL_FIRE_B) ) 
		{	// remove stats screen			
			sb___gSubShown = 0;
			sound = SFX_ID_BACK;
//			FreeTeamLogo(asb__sRTeam[DraftSide]);
		}

		if (asi__gTeamBtn[EVERYBODY] &
			(	 CTRL_PAD_UP | CTRL_PAD_DOWN | CTRL_PAD_LEFT | CTRL_PAD_RIGHT))
		{	// ignore these
			sound = SFX_SHELL_NOMV;
			goto allDone;
		}
		else
		{
			// Restrict the input that we send.

			asi__gTeamBtn[EVERYBODY] &= (CTRL_C_UP | CTRL_C_DOWN | CTRL_C_LEFT | CTRL_C_RIGHT);
	
			// Let the stats screen process whats left.

			ProcScreenI3(STATE_I3a);
		}

		goto allDone;
	}
	

/***
	if (asi__gTeamBtn[EVERYBODY]& (CTRL_FIRE_A | CTRL_START) )
	{
			oldState = asb__gStateNextFwd[oldState];
	}

*/
	if (asi__gTeamBtn[EVERYBODY]& (CTRL_FIRE_B) )
	{
		oldState = asb__gStateNextRev[oldState];
		sound = SFX_ID_BACK;
	}

	if (asi__gTeamBtn[EVERYBODY] & (CTRL_TRIGGER | CTRL_FIRE_A | CTRL_START))
	{	// switch to view player stats
		sound = SFX_FORWARD;
		sb___gSubShown = 1;	
/***
		si___gIPlyr = asb__sRPlyr[DraftSide];
		pcl__gITeam = apcl_sRTeam[DraftSide];

		InitializeLogos(asb__sRTeam[DraftSide], -1);
		LoadTeamLogo(asb__sRTeam[DraftSide], 1);

		puw__gPhoto0 = DecodePlyrImg(pcl__gITeam->ppcl_tPlyrLst[si___gIPlyr], puw__gPhoto0);
****/
//		si___Sound = SFX_SHELL_CHNG;
		goto allDone;
	}

	
	if (asi__gTeamBtn[EVERYBODY] &
			(	 CTRL_PAD_UP | CTRL_PAD_DOWN | CTRL_PAD_LEFT | CTRL_PAD_RIGHT | CTRL_C_UP | CTRL_C_DOWN | CTRL_C_LEFT | CTRL_C_RIGHT ) )
	{	// ignore these
		sound = SFX_SHELL_NOMV;
		goto allDone;
	}

	allDone:

	if (sound >= 0)
	{
		AudioPlaySfx(sound, 11025, 255, 7);
	}
	return (oldState);
}




Gfx *DrawBoxGraph(Gfx *gp,int x, int y, int length,int pregame)
{	// box is 100w x 7h (int) -  box is 104w x 9h (exterior)

	
	if(pregame)
	{	
//		gp = RenderTBOX(gp,x-2,y-1,MAX_RP_BAR_LENGTH+4,1,RGB_SOLID_WHITE);	// top
//		gp = RenderTBOX(gp,x-2,y+7,MAX_RP_BAR_LENGTH+4,1,RGB_SOLID_WHITE);	// bottom
//		gp = RenderTBOX(gp,x-2,y-1,2,9,RGB_SOLID_WHITE);					// left
//		gp = RenderTBOX(gp,x+MAX_RP_BAR_LENGTH,y-1,2,9,RGB_SOLID_WHITE);	// right
		gp=RenderSprite(gp,SPR_PTR(SPR_LEVBORD),(UI)puw__gMainPalH,x-2,y-1);

		if(length > ZERO)
		{
			gp = RenderTBOX(gp,x,y,length,7,RGB_SOLID_YEL);	// inside (on top of green)
		}
	}
	else if(length >= MAX_RP_BAR_LENGTH)
	{
		length = MAX_RP_BAR_LENGTH;		// 100 pixels
		gp = RenderTBOX(gp,x,y,length,7,RGB_SOLID_GREEN);	// inside
	}
	else
	{
		if(length > ZERO)
		{
			gp = RenderTBOX(gp,x,y,length,7,RGB_SOLID_LT_GREEN);	// inside
		}
	}


	return(gp);
}






#define RPA_Y1	34
#define RPA_Y1a	(RPA_Y1+MENU_LINE_H)


struct rcbox RPAScreenBoxes[] = 
{
	{0, 0,512,RPA_Y1, RGB_TRANS_YEL,NO_CORNERS},


	{S1_X1a,RPA_Y1a,S1_X2-S1_X1a,MENU_BOTTOM_LINE_Y-RPA_Y1a,
				RGB_TRANS_RED,SPR_RED_TL,SPR_RED_TR,SPR_RED_BL,SPR_RED_BR},

	{-1,0,0,0,0,NO_CORNERS}
};


int rppal = FPAL_WHITE;


Gfx *DrawScreenRPAbilities(int state,Gfx *gp)		// sorta like ScreenS2 (@ Post Game)
{

int		i,y,color;	//k,l;
int		cplyrindex;
int len;
TXTCEL_T	*pcl__Txt;
char		tmp[80];
char		tmp1[32];

extern dyn	*dynamicp;
extern int	dbuf;
PlyrRomData_T *     rom;
RPstatdata_t *rpstats;
struct _rookiebars  * rpdisplay;
SW	improvement;



	if (sb___gSubShown)
	{
		// Display the stats screen instead of the normal screen.

		return (DrawScreenI3(STATE_I3a, gp));
	}



	rom  = gRPlyrRamPtr->pcl__pPlyrRom;

	cplyrindex = rom->uw___pIndx - si___gPlyrRomCnt - 1;	// custom player index	
	rpstats = &CustomPlyrStatsData[cplyrindex].RolePlayerAbilities[0];


	gp =DrawRCBoxes(gp, RPAScreenBoxes);	// transparent BG boxes

	gp = DrawBlankBox(gp, S1_X2, 513, RPA_Y1a, MENU_BOTTOM_LINE_Y,BB_LEFT_BOX);
	gp = DrawBlankBox(gp, -1, S1_X1,  RPA_Y1a, MENU_BOTTOM_LINE_Y,BB_RIGHT_BOX);

	DRAW_MENU_HLINE(RPA_Y1);	// must be drawn after lines/blank boxes to cover up anti-aliasing
	DRAW_MENU_HLINE(MENU_BOTTOM_LINE_Y);


	// render shell player!
	gp = DrawShellPlayer(gp);


	// render list of fields...
	editHiX=-1;


	for(i=0;i<NUM_ABILITIES;i++)
	{

		rpdisplay = &RookieBarDisplay[cplyrindex][i];

//		y=i*13+25;
//		y=i*12+42;
		y=i*12 + RPA_Y1+8;

		EditRenderText(abilityFields[i],  161,y,
					FONT_BLKCN18,FPAL_WHITE, FLG_CTR);

		// "was"
		if(i==ABILITY_RANGE)
		{
//			IntToStr(((int)editAbilities[i]*17/4) + 8,tmp);
//			IntToStr((((int)editAbilities[i]/25)*17/4) + 8,tmp);
			SetAbilityRangeString(editAbilities[i], tmp);
			strcat(tmp," ft");
		}
		else
		{
			IntToStr(editAbilities[i],tmp);
		}
//		strcat(tmp,"%");

		EditRenderText(tmp,	271-20,y,
//		EditRenderText(tmp,	271,y,
		        FONT_BLKCN18,FPAL_WHITE,
				FLG_CTR | FLG_SHADOW);
	
// improvement
		improvement = rpdisplay->improvement;
		if(improvement)
		{
			color = rppal;	// realtime debugging tweak to find best color

			if(improvement > ZERO)
			{
				color = FPAL_BRIGHT_WHITE;
				strcpy(tmp,"+");
			}
			else
			{
				color = FPAL_YELLOW;
				improvement = -improvement;
				strcpy(tmp,"-");
			}

			IntToStr(improvement,tmp1);
			strcat(tmp,tmp1);

			EditRenderText(tmp,	271+20,y,FONT_BLKCN18,color,FLG_CTR | FLG_SHADOW);

		}
/********
		// "now"
		IntToStr(newAbilities[i],tmp);
		strcat(tmp,"%");

		if(newAbilities[i] > editAbilities[i])
			color = FPAL_GREEN;
		else if(newAbilities[i] < editAbilities[i])
			color = FPAL_RED;
		else
			color = FPAL_WHITE;

		EditRenderText(tmp,	271+20,y,
		        FONT_BLKCN18,color,
				FLG_CTR | FLG_SHADOW);
****/

/********
		IntToStr(newAbilities[i],tmp);
		strcat(tmp,"%");

		if(newAbilities[i] > editAbilities[i])
			color = FPAL_GREEN;
		else if(newAbilities[i] < editAbilities[i])
			color = FPAL_RED;
		else
			color = FPAL_WHITE;

		EditRenderText(tmp,	271+20,y,
		        FONT_BLKCN18,color,
				FLG_CTR | FLG_SHADOW);
****/
	

//		len = editAbilities[i]/2;
//		len = rpstats[i].StatTotal *2;
//		len = rpstats[i].StatPerGame[NUM_GAMES_RP_STATS-1];
		len = rpdisplay->postgamebar;
//		len = (i+1)*5;	//test only
		gp = DrawBoxGraph(gp,S1_X2+25, y, len,0);

	// draw pregame bar on top of postgame bar
		len = rpdisplay->pregamebar;
//		len = (i+1)*3;//test only
		gp = DrawBoxGraph(gp,S1_X2+25, y, len,1);

	}

	ShadFont_Color(SHADFNT_RGB_WHITE);	
//	ShadFont_Set(TinyShadFont);
	ShadFont_Set(SmallShadFont);

	gp =DrawPlyrShadowNameCentered(gp,rom,271,RPA_Y1-9,(271-MENU_LEFT_KEYX-10)*2);
//	gp =DrawPlyrShadowNameCentered(gp,rom,410,30,512-30-S1_X2);
//	gp = ShadFont_DrawCentered(gp,"WAS",271-20,30);
//	gp = ShadFont_DrawCentered(gp,"NOW",271+20,30);


	// Help message.
	gp = DrawHelpTeaser(gp, 290);

	// Finally draw characters.
	gp=DrawChrList(gp);

	
	// All done.
	return (gp);
}




/***************************************************************************
 *
 *			 C  U S T O M    U S E R     T E A M S   
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

enum CUmodes_enums {
	CU_CREATE,
	CU_VIEW,
	CU_SELECT,
	CU_MODIFY,
	CU_DELETE,

	CU_MAX_MODES
};


enum CUsortmethod_enums {
	CU_SORT_PCT,
	CU_SORT_WINS,
	CU_SORT_LOSSES,
	CU_SORT_GP,
	
	CU_MAX_SORT_METHODS
};

char * SortMethodStrings[CU_MAX_SORT_METHODS] = {
//	"Best %",
//	"Most Wins",
//	"Most Losses",
//	"Most G.P."
	"BEST WINNING %",
	"MOST WINS",
	"MOST LOSSES",
	"MOST GAMES PLAYED"

};

static int		CUMode, CULastMode;

static int		InputtingName; 
static int		CUSortMethod = CU_SORT_PCT;				

global int	SelectedCustomUserSlot;
global int	CUCurSlot = 0;
global int	NumCustomUsers;


int UserTeamDefined(int slot)
{

	return(UserTeams[slot].UserName[0]);

}


static	unsigned char	sprScreenUserTeams [] =		//
{
	SPR_RED_TL,
	SPR_RED_TR,
	SPR_RED_BL,
	SPR_RED_BR,
//	SPR_TM_CRNR,

	SPR_YEL_TL,
	SPR_YEL_TR,
	SPR_YEL_BL,
	SPR_YEL_BR,

	0
};




 

orderedlist_t OrderedCustomUsersTable[MAX_CUSTOM_USERS];



int	AllocNewCustomUser(void)
{
int i;

	for(i=0; i<MAX_CUSTOM_USERS; i++)
	{	
		if(!UserTeamDefined(i))
			break;
	}

	return(i);
}


void OrderCustomUsers(void)
{
int i,limit;
int	gp,wins,losses,pct;
int swap, needswap,nexti;
orderedlist_t temp;

	NumCustomUsers = ZERO;
	for(i=0; i<MAX_CUSTOM_USERS; i++)	// clear everything
	{	
		if(UserTeamDefined(i))
		{
			OrderedCustomUsersTable[NumCustomUsers].user = i;
			gp = UserTeams[i].UserTeamStats.uw___tGP;
			wins = UserTeams[i].UserTeamStats.uw___tGW;
			losses = UserTeams[i].UserTeamStats.uw___tGP - UserTeams[i].UserTeamStats.uw___tGW;
			if(gp)
			{	// no divide by zero
				if(wins)
				{
					pct = (wins * 1000)/gp;
				}
				else
				{		// make so 0-3 is worst than 0-1
					pct = -gp-1;
				}
			}
			else
			{							
				pct = -1;			
			}				


			switch(CUSortMethod)
			{
				case CU_SORT_PCT:
					OrderedCustomUsersTable[NumCustomUsers].sortdata = pct;
					OrderedCustomUsersTable[NumCustomUsers].sortdata2 = gp;
					break;

				case CU_SORT_WINS:
					OrderedCustomUsersTable[NumCustomUsers].sortdata = wins;
					OrderedCustomUsersTable[NumCustomUsers].sortdata2 = pct;
				break;

				case CU_SORT_LOSSES:
					OrderedCustomUsersTable[NumCustomUsers].sortdata = losses;
					// use wins, not pct in case of 3-0, 2-0, etc 
					OrderedCustomUsersTable[NumCustomUsers].sortdata2 = 30000-wins;
					break;

				case CU_SORT_GP:
					OrderedCustomUsersTable[NumCustomUsers].sortdata = gp;
					OrderedCustomUsersTable[NumCustomUsers].sortdata2 = wins;
					break;
			}
			NumCustomUsers++;
		}
	}

	for(i = NumCustomUsers; i<MAX_CUSTOM_USERS; i++)	// clear unused slots
	{
		OrderedCustomUsersTable[i].user = 
			OrderedCustomUsersTable[i].sortdata = -1;
	}


	limit = NumCustomUsers-1;
	do		// bubble sort
	{
		swap = FALSE;
		
		for(i=0; i< limit; i++)
		{
			nexti = i+1;
			needswap = 0;

			if(OrderedCustomUsersTable[i].sortdata < OrderedCustomUsersTable[nexti].sortdata)
			{	// swap
			
				needswap = 1;
			}
			else if(OrderedCustomUsersTable[i].sortdata == OrderedCustomUsersTable[nexti].sortdata)
			{	// swap
				if(OrderedCustomUsersTable[i].sortdata2 < OrderedCustomUsersTable[nexti].sortdata2)
				{	
					needswap = 1;
				}
			}

	
			if(needswap)
			{
				memcpy(&temp,&OrderedCustomUsersTable[nexti],sizeof(orderedlist_t));
				memcpy(&OrderedCustomUsersTable[nexti],&OrderedCustomUsersTable[i],sizeof(orderedlist_t));
				memcpy(&OrderedCustomUsersTable[i],&temp,sizeof(orderedlist_t));

/**				temp = 	OrderedCustomUsersTable[nexti].sortdata;
				OrderedCustomUsersTable[nexti].sortdata = OrderedCustomUsersTable[i].sortdata;
				OrderedCustomUsersTable[i].sortdata = temp;

				temp = 	OrderedCustomUsersTable[nexti].user;
				OrderedCustomUsersTable[nexti].user = OrderedCustomUsersTable[i].user;
				OrderedCustomUsersTable[i].user = temp;
**/
				swap = TRUE;
			}
		}
		limit--;

	}while(swap);


	CUMode = NumCustomUsers ? CULastMode : CU_CREATE;

	if(NumCustomUsers)
	{
		CUCurSlot %= NumCustomUsers;	// keep CUCurSlot in range in case of delete
	}
}



int FindCustomUserSortedIndex(int trueslot)
{
int i;

	for(i=0; i< NumCustomUsers; i++)
	{
		if(OrderedCustomUsersTable[i].user == trueslot)
			break;

	}
	return (i);
}


#define CUSTOM_TITLE_Y	190
#define CU_TW	70

stringXY_t CustomUserTitles[CU_MAX_MODES] = {
	"Create",	160+(0*CU_TW),		CUSTOM_TITLE_Y,	
	"View",		160+(1*CU_TW),	CUSTOM_TITLE_Y,	
	"Select",	160+(2*CU_TW),	CUSTOM_TITLE_Y,	
	"Modify",	160+(3*CU_TW),	CUSTOM_TITLE_Y,	
	"Delete",	160+(4*CU_TW),	CUSTOM_TITLE_Y,
};
		


int	NeedCustomUserSave = 0;


int InitScreenUserTeams(int state)
{
int		i,j,k;
PlyrRamData_T *     pcl__PlyrRam;


	// Load up the correct background image.
	if (fl___gShellOverlay == 0)
	{
//		LoadShellBackgroundSpr(START_BG_CYCLING);
		BG_Load(BG_CYCLING, 0 );
	}
	else
	{
//		ShellFromGameInitMenu();	// this fixes palette corruption 

		//(fixed later by FreeSpriteList not freeing everything if paused

//		LoadShellBackgroundSpr(*(apul_gTeamBackground[(pcl__gMatch->asb__mTeam[HOME_TEAM])]));
//		LoadShellBackgroundSpr(*(apul_gTeamBackground[pcl__gMatch->apcl_mTeamRom[pauseTeam]->ub___tTeam]));

	}

	// Load up the sprites for this screen.
	LoadSpriteList(sprScreenUserTeams);

	CULastMode = CU_SELECT;

//	if(!fl___gReverse)
	{	// load first time in - quick fix of bug
		LoadCustomUsers();
	}
	
	OrderCustomUsers();

	SelectedCustomUserSlot = -1;

	InputtingName = 0;

	// All Done.
	return (state);
}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ExitScreenUserTeams(int state)
{
	// Free up the sprites for this screen.
	FreeSpriteList(sprScreenUserTeams);


	SaveCustomUserData();	// will save only if modify

	// All Done.
	return (state);
}



void DeleteCustomUser(int trueslot)
{
int pad;

		// clear slot!

	for(pad = 0; pad < MAX_CONTROLLERS; pad++)
	{
		if(CurGameUserTeams[pad] == trueslot)
		{	// if deleted user is linked to controller pad..
			CurGameUserTeams[pad] = -1;	// .. then break the link
		}
	}

	memset(&UserTeams[trueslot],0,sizeof(UserTeamInfo_T));
	OrderCustomUsers();

}


/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

int ProcScreenUserTeams(int oldState)	// Select Player (or NEW) to eDIT
{
	// Local Variables.
int		newState = oldState;
int		sound = -1;
int		btn;
int		pad;

UserTeamInfo_T *user; 
int 	trueslot = OrderedCustomUsersTable[CUCurSlot].user;

	if(trueslot >= ZERO)
	{
		user = &UserTeams[trueslot];
	}
	// check popup window
	if(pendingPopup == 1)			//Delete Player??
	{
		if(si___gPopupVal==1)	//"YES"
		{
			DeleteCustomUser(trueslot);
			NeedCustomUserSave = 1;
		}
		else if(si___gPopupVal>=2)	//"NO" or backup
		{
			
			// return to selection
//			opt = selSlot;
		}
	}
	else if(pendingPopup == 2)	//Slots full?
	{
		if(si___gPopupVal>=1)	//"continue"
		{
			CUMode = CU_DELETE;	//is this a bit too user friendly???
		}
	}

	pendingPopup=0;
	si___gPopupVal=0;

//	btn = asi__gTeamBtn[EVERYBODY];
	btn = asi__gJoyBtn[CUControlPad];

	if(NumCustomUsers)
	{
		apcz_gStateHelpMsg[oldState] = acz__gHelpCustomUser;
	}
	else
	{
		apcz_gStateHelpMsg[oldState] = acz__gHelpCustomUserNoUsers;	//bug #550
	}

	if(InputtingName)
	{
		apcz_gStateHelpMsg[oldState] = acz__gHelpScreenNameInput;
		 
//		InputtingName = InputName(btn, &sound, USER_NAME_MAX_LEN-1);
//		InputtingName = InputName(btn, &sound, 10);	//bug#281 - name too long in controller config oval
		InputtingName = InputName(btn, &sound, 12);	//bug#281 - now we put in (...) if name too long

		if(!InputtingName)
		{
			if(user->UserName[0] == 0)
			{	// backup from input w/o doing anything
				DeleteCustomUser(trueslot);
			}
			else	// done with a valid name
			{
				NeedCustomUserSave = 1;
				// save current control mode (rookie/pro) mode
				UserTeams[trueslot].PadMode = ControllerGameMode[CUControlPad];

				if(CUMode == CU_CREATE)
				{	// don't reorder if modifing
//					OrderCustomUsers();
					CUMode = CULastMode = CU_SELECT;
				}
			}
		}		
		goto allDone;
	}
	
	if (btn & (CTRL_FIRE_A | CTRL_START))
	{

		switch(CUMode)
		{
			case CU_CREATE:
				// clear slot!
				trueslot = AllocNewCustomUser();
				if(trueslot >= MAX_CUSTOM_USERS)
				{	// soory - must delete somebody
					InitPopup(overwriteCUTitle,fullCUWarningText,NULL);
					pendingPopup = 2;
					goto allDone;
				}
				else
				{	
					user = &UserTeams[trueslot];

					memset(user,0,sizeof(UserTeamInfo_T));
					strcpy(user->UserName, " ");
#if	1	//def DEBUG
					if (btn & (CTRL_TRIGGER))
//						strcpy(user->UserName,"Wmwmwmwmwmwmwmw");
						strcpy(user->UserName,"Andy Knauer");
					if (btn & (CTRL_SHOULDER_L))
						strcpy(user->UserName,"Jack Knauer");
#endif
					OrderCustomUsers();
					CUCurSlot = FindCustomUserSortedIndex(trueslot);
					CUMode = CU_CREATE;

				}	
			// fall thru to MODIFY - no break

			case CU_MODIFY:
				InputtingName = 1;
				cursorPos = 0;				
				editString = user->UserName;
				break;
			
			case CU_SELECT:

				// check for already in use
				for(pad = 0; pad < MAX_CONTROLLERS; pad++)
				{
					if(CurGameUserTeams[pad] == trueslot)
					{	// if new user is currently linked to controller pad..
						CurGameUserTeams[pad] = -1;	// .. then break the old link
					}
				}

				SelectedCustomUserSlot = trueslot;
//				newState = asb__gStateNextRev[newState];
				CurGameUserTeams[CUControlPad] = trueslot;
				
				// restore rookie/pro control mode
				ControllerGameMode[CUControlPad] = UserTeams[trueslot].PadMode;


				newState = CUFromState;
				break;

			case CU_VIEW:

				newState = STATE_VIEW_CUSTOM_USER;


				break;

//			case CU_MODIFY:
//				strcpy(UserTeams[CUCurSlot].UserName,"Rick Head");
//				break;

			case CU_DELETE:
				InitPopup(overwriteCUTitle,overwriteCUWarningText,NULL);
				pendingPopup = 1;
				break;	
		}

		sound    = SFX_SHELL_BTNA;
		goto allDone;

	}		
	
	if (btn & (CTRL_FIRE_B))
	{
//		newState = asb__gStateNextRev[newState];

		CurGameUserTeams[CUControlPad] = -1;	// deselect

		newState = CUFromState;
		sound    = SFX_SHELL_BTNB;
		goto allDone;
	}

	if(NumCustomUsers)	// if nobody there - must create
	{
		if (btn & (CTRL_PAD_UP))
		{
			CUCurSlot = (CUCurSlot + NumCustomUsers-1) % NumCustomUsers;
			sound= SFX_ID_SCROLL;
			goto allDone;
		}

		if (btn & (CTRL_PAD_DOWN))
		{
			CUCurSlot = (CUCurSlot+1) % NumCustomUsers;
			sound= SFX_ID_SCROLL;
			goto allDone;
		}

		if (btn & (CTRL_PAD_LEFT) )
		{
			if(--CUMode < 0)
			{
				CUMode = CU_MAX_MODES-1;				
			}
			CULastMode = CUMode;	
			sound= SFX_ID_SCROLL;
			goto allDone;
		}	


		if (btn & (CTRL_PAD_RIGHT ))
		{
			if(++CUMode >= CU_MAX_MODES)
			{
				CUMode = 0;				
			}
			CULastMode = CUMode;	
			sound= SFX_ID_SCROLL;
			goto allDone;
		}	

		if (btn & (CTRL_C_LEFT) )
		{
			if(--CUSortMethod < 0)
			{
				CUSortMethod = CU_MAX_SORT_METHODS-1;				
			}
			OrderCustomUsers();
			sound= SFX_ID_SCROLL;
			goto allDone;
		}	


		if (btn & (CTRL_C_RIGHT))
		{
			if(++CUSortMethod >= CU_MAX_SORT_METHODS)
			{
				CUSortMethod = 0;				
			}
			OrderCustomUsers();
			sound= SFX_ID_SCROLL;
			goto allDone;
		}	

#ifdef DEBUG
		if (btn & (CTRL_C_UP))
		{
				// test only
					user->UserTeamStats.uw___tGW = ReadRandomByte()&3 ;
					
					user->UserTeamStats.uw___tGP  =
						user->UserTeamStats.uw___tGW + (ReadRandomByte()&3);
					OrderCustomUsers();
					NeedCustomUserSave = 1;
			goto allDone;

		}


		if (btn & (CTRL_C_DOWN))
		{
				// test only
			LoadCustomUsers();
			goto allDone;

		}
#endif

	}	


	// Anything else ?

	if (btn & (CTRL_PAD_UP | CTRL_PAD_DOWN | CTRL_PAD_LEFT | CTRL_PAD_RIGHT |
			CTRL_C_UP | CTRL_C_DOWN))
	{
		sound = SFX_SHELL_NOMV;
	}

	// All done.

	allDone:

	if (sound >= 0)
	{
		AudioPlaySfx(sound, 11025, 255, 7);
	}

	return (newState);
}


/***************************************************************************
 *
 *			 D R A W    C U S T O M   U S E R   S C R E E N
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/

#define NUM_DISPLAYED_CU	9	// best if odd number

#define CU_Y1	40
#define CU_Y1a	(CU_Y1+MENU_LINE_H)
#define CU_Y2	178
#define CU_Y2a	(CU_Y2+MENU_LINE_H)

#define	CU_W	(260+44)
#define CU_X0	140		// left side
#define CU_X1	(CU_X0+CU_W)		// right side (of text)
#define CU_Xc	((CU_X1+CU_X0)/2)	// center

#define CU_CONT_X	(CU_X1-8)

struct rcbox CustomerUserScreenBoxes[] = 
{
	{0, 0,512,CU_Y1, RGB_TRANS_YEL,NO_CORNERS},

	HLINE(0, CU_Y1, 512),
	{0, CU_Y1a,	512, CU_Y2-(CU_Y1a),	RGB_TRANS_RED,NO_CORNERS},

	HLINE(0,  CU_Y2,  512),

	{0, CU_Y2a,	512, MENU_BOTTOM_LINE_Y-(CU_Y2a),	RGB_TRANS_PURPLE,0,0,0,0},

	HLINE(0,  MENU_BOTTOM_LINE_Y,  512),
	{-1,0,0,0,0,NO_CORNERS}
};




void BuildRecordString(char *string, TeamRamStat_T * teamstatsPtr)
{
char numstring[16];
	
	int2str(numstring,teamstatsPtr->uw___tGW);
	strcpy(string,numstring);
	strcat(string,"-");
	int2str(numstring,teamstatsPtr->uw___tGP - teamstatsPtr->uw___tGW);
	strcat(string,numstring);
}




/*--------------------------------------------------------------------------*/

Gfx *DrawScreenUserTeams(int state,Gfx *gp)
{

int			i,p;
int			x,y;
int			low,high,top;
TXTCEL_T *          pcl__Txt;
char			tmp[80];
char			string[64];
int trueslot,end;
UserTeamInfo_T * user;

	gp = DrawRCBoxes(gp,CustomerUserScreenBoxes);	// lay the graphical foundation 

	// Help message.

	gp = DrawHelpTeaser(gp, 290);

	// draw the main body of the screen

	int2str(string,CUControlPad+1);
	strcpy(tmp,"CUSTOM USER FOR CONTROLLER ");
	strcat(tmp,string);	

	ShadFont_Color(SHADFNT_RGB_WHITE);	
	ShadFont_Set(TinyShadFont);
	gp = ShadFont_DrawCentered( gp, tmp, ((512-40) + MENU_LEFT_KEYX)/2,CU_Y1-10);


	end = NUM_DISPLAYED_CU;
	y = (CU_Y1 + CU_Y2)/2 - (NUM_DISPLAYED_CU*6);
	if(NumCustomUsers <= NUM_DISPLAYED_CU)
	{
		top = 0;
		end = NumCustomUsers;
		y = (CU_Y1 + CU_Y2)/2 - (NumCustomUsers*6);
	}
	else if(CUCurSlot  < NUM_DISPLAYED_CU/2)		//"middle" scrolling technique 
	{							// with NUM_DISPLAYED_CU on screen at once
		top = ZERO;
	}
	else if(CUCurSlot  >=  NumCustomUsers-5)
	{	
		top = NumCustomUsers-NUM_DISPLAYED_CU;
	}
	else
	{
		top = CUCurSlot - (NUM_DISPLAYED_CU/2);	// keep selected slot in middle
	}
		


	for(i = top; i < top+end; i++)
	{

		if(i== 0)
		{				// put in headings

			gp = ShadFont_DrawCenteredX( gp, SortMethodStrings[CUSortMethod], CU_Xc,y-11);
//			gp = ShadFont_DrawCenteredX( gp, "CONTROLLER", CU_CONT_X,y-11);
			gp = ShadFont_DrawCenteredX( gp, "CTRL.", CU_CONT_X,y-11);

		}
		
		trueslot = OrderedCustomUsersTable[i].user;
		user = &UserTeams[trueslot];
		
		if(i == CUCurSlot)
		{
			gp = DrawOvalCursorHilite(gp, CU_Xc,y+3,CU_W+24);
		}

		int2str(tmp,i+1);
		strcat(tmp," - ");
		EditRenderText(tmp,CU_X0+22,y, FONT_BLKCN18,FPAL_WHITE,FLG_XR);

		BuildRecordString(string, &user->UserTeamStats);
		EditRenderText(string,CU_X1-40,y, FONT_BLKCN18,FPAL_WHITE,FLG_XR);


		for(p=0; p<4; p++)
		{
			if(CurGameUserTeams[p] == trueslot)
				break;
		}
		if(p == 4)
		{
			strcpy(string,"None");
		}
		else
		{
			int2str(string,p+1);
		}
		EditRenderText(string,CU_CONT_X,y, FONT_BLKCN18,FPAL_WHITE,FFLG_XC);
		
		
		if(i == CUCurSlot && InputtingName)
		{ 
			strcpy(tmp,user->UserName);

			RenderEditField(tmp, CU_X0+25, y,FONT_BLKCN18,FPAL_WHITE,0,2,cursorPos);

		}
		else if(UserTeamDefined(trueslot))
		{
			strcpy(tmp,user->UserName);
			EditRenderText(tmp,CU_X0+25,y, FONT_BLKCN18,FPAL_WHITE,0);

//			BuildRecordString(string, &UserTeams[trueslot].UserTeamStats);
//			EditRenderText(string,CU_X1,y, FONT_BLKCN18,FPAL_WHITE,FLG_XR);

		}
		else	// catch any errors here
		{
			strcpy(tmp,"--- Available ---");
			EditRenderText(tmp,CU_X0+25,y, FONT_BLKCN18,FPAL_WHITE,0);
		}

		y += 13;
	}




//  put in titles/modes
	if(CUMode)
	{
		low = 1; high = CU_MAX_MODES;
	}
	else
	{
		low = 0; high = 1;
	}
	low = 0; high = CU_MAX_MODES;
	
	for(i = low; i < high; i++)
	{
		x = CustomUserTitles[i].x;
		y = CustomUserTitles[i].y;

		if(i == CUMode)
		{
			gp = DrawOvalCursor(gp, x,y+3,72);
		}
		
		EditRenderText(	CustomUserTitles[i].title,x,y,FONT_BLKBT18,FPAL_WHITE,FLG_CTR);
	
	}

//void EditRenderText(char *s,int x,int y,int font,int palette,int flg)


	// All done.
	return (gp);
}






/***************************************************************************
 *
 *
 *
 ***************************************************************************
 *
 *
 *
 ***************************************************************************/



/***************************************************************************
 *
 *				End of file:  ScreenS.c
 *
 ***************************************************************************/

