
#include "glover.h"

int cheatCompare();


// Alternatives for PSX
//		Win Level
//		Any Ball Powerwhacks
#ifdef MULTI_LANGUAGE
CHEAT_TYPE cheatInfo[NUM_CHEATS] = 
{
	{STR_CHT_CALLBALL,		{CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_UP   , CHT_RIGHT, CHT_LEFT , CHT_DOWN , CHT_UP   },TOGGLE},	//0 working
	{STR_CHT_CHECKPOINTS,	{CHT_DOWN , CHT_DOWN , CHT_RIGHT, CHT_LEFT , CHT_UP   , CHT_UP   , CHT_DOWN , CHT_LEFT },TOGGLE},	//1 working
//	{{"LEVEL SELECT"},			{CHT_UP	  , CHT_UP   , CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT},TOGGLE},	//23	TBD implement
	{STR_CHT_MENU,			{CHT_UP	  , CHT_UP   , CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT},TOGGLE},	//23	TBD implement

	{STR_CHT_INFYENERGY,	{CHT_RIGHT, CHT_RIGHT, CHT_DOWN , CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_UP   , CHT_LEFT },TOGGLE},	//6	TBD
	{STR_CHT_INFYLIVES,		{CHT_UP   , CHT_UP   , CHT_UP   , CHT_UP   , CHT_UP   , CHT_RIGHT, CHT_DOWN , CHT_RIGHT},TOGGLE},	//3 TBD

	{STR_CHT_ALLCHEATS,		{CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_RIGHT},REPEAT},	//22 working - cancel button. n64 was all downs


// Cheats above num_safe_cheats are only accessible via ISL memory-card dongle.

	{STR_CHT_WINLEVEL,		{CHT_DOWN , CHT_RIGHT, CHT_DOWN , CHT_UP   , CHT_RIGHT, CHT_DOWN , CHT_RIGHT, CHT_LEFT },TOGGLE},	//13 working

	{STR_CHT_FROGSPELL,		{CHT_DOWN , CHT_LEFT , CHT_DOWN , CHT_DOWN , CHT_LEFT , CHT_DOWN , CHT_UP   , CHT_LEFT },TOGGLE},	//15 working
	{STR_CHT_DEATHSPELL,	{CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_LEFT , CHT_LEFT , CHT_UP   , CHT_RIGHT, CHT_UP   },TOGGLE},	//14 working
	{STR_CHT_HERCULES,		{CHT_DOWN , CHT_DOWN , CHT_DOWN , CHT_LEFT , CHT_LEFT , CHT_DOWN , CHT_RIGHT, CHT_LEFT },TOGGLE},	//16 working
	{STR_CHT_SPEEDUP,		{CHT_LEFT , CHT_LEFT , CHT_RIGHT, CHT_UP   , CHT_RIGHT, CHT_LEFT , CHT_DOWN , CHT_DOWN },TOGGLE},	//17 working
	{STR_CHT_ROTORBLADES,	{CHT_UP	  , CHT_RIGHT, CHT_DOWN , CHT_RIGHT, CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_UP   },TOGGLE},	//20

	{STR_CHT_POWERBALL,		{CHT_UP   , CHT_DOWN , CHT_UP   , CHT_DOWN , CHT_UP   , CHT_DOWN , CHT_LEFT , CHT_UP   },TOGGLE},	//4 working
	{STR_CHT_BOOMERANG,		{CHT_RIGHT, CHT_UP   , CHT_UP   , CHT_UP   , CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_DOWN },TOGGLE},	//18 working
	{STR_CHT_BEACHBALL,		{CHT_DOWN , CHT_DOWN , CHT_UP   , CHT_DOWN , CHT_DOWN , CHT_LEFT , CHT_RIGHT, CHT_DOWN },TOGGLE},	//9 working
	


	{STR_CHT_LOWGRAVITY,			{CHT_LEFT , CHT_LEFT , CHT_UP   , CHT_LEFT , CHT_RIGHT, CHT_UP   , CHT_UP   , CHT_UP   },TOGGLE},	//8 working
	{STR_CHT_CINEMASCOPE,			{CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT},TOGGLE},	// 

	{STR_CHT_LOOKMODE,				{CHT_DOWN , CHT_UP   , CHT_RIGHT, CHT_RIGHT, CHT_DOWN , CHT_LEFT , CHT_RIGHT, CHT_RIGHT},TOGGLE},	//21
};
#else
CHEAT_TYPE cheatInfo[NUM_CHEATS] = 
{
	{{"CALL BALL"},				{CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_UP   , CHT_RIGHT, CHT_LEFT , CHT_DOWN , CHT_UP   },TOGGLE},	//0 working
	{{"CHECKPOINTS"},			{CHT_DOWN , CHT_DOWN , CHT_RIGHT, CHT_LEFT , CHT_UP   , CHT_UP   , CHT_DOWN , CHT_LEFT },TOGGLE},	//1 working
//	{{"LEVEL SELECT"},			{CHT_UP	  , CHT_UP   , CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT},TOGGLE},	//23	TBD implement
	{{"CHEATS MENU"},			{CHT_UP	  , CHT_UP   , CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT},TOGGLE},	//23	TBD implement

	{{"INFINITE ENERGY"},		{CHT_RIGHT, CHT_RIGHT, CHT_DOWN , CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_UP   , CHT_LEFT },TOGGLE},	//6	TBD
	{{"INFINITE LIVES"},		{CHT_UP   , CHT_UP   , CHT_UP   , CHT_UP   , CHT_UP   , CHT_RIGHT, CHT_DOWN , CHT_RIGHT},TOGGLE},	//3 TBD

	{{"ALL CHEATS"},			{CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_RIGHT, CHT_RIGHT},REPEAT},	//22 working - cancel button. n64 was all downs


// Cheats above num_safe_cheats are only accessible via ISL memory-card dongle.

	{{"WIN LEVEL"},				{CHT_DOWN , CHT_RIGHT, CHT_DOWN , CHT_UP   , CHT_RIGHT, CHT_DOWN , CHT_RIGHT, CHT_LEFT },TOGGLE},	//13 working

	{{"FROG SPELL"},			{CHT_DOWN , CHT_LEFT , CHT_DOWN , CHT_DOWN , CHT_LEFT , CHT_DOWN , CHT_UP   , CHT_LEFT },TOGGLE},	//15 working
	{{"DEATH SPELL"},			{CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_LEFT , CHT_LEFT , CHT_UP   , CHT_RIGHT, CHT_UP   },TOGGLE},	//14 working
	{{"HERCULES"},				{CHT_DOWN , CHT_DOWN , CHT_DOWN , CHT_LEFT , CHT_LEFT , CHT_DOWN , CHT_RIGHT, CHT_LEFT },TOGGLE},	//16 working
	{{"SPEEDUP"},				{CHT_LEFT , CHT_LEFT , CHT_RIGHT, CHT_UP   , CHT_RIGHT, CHT_LEFT , CHT_DOWN , CHT_DOWN },TOGGLE},	//17 working
	{{"ROTORBLADES"},			{CHT_UP	  , CHT_RIGHT, CHT_DOWN , CHT_RIGHT, CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_UP   },TOGGLE},	//20

	{{"POWERBALL"},				{CHT_UP   , CHT_DOWN , CHT_UP   , CHT_DOWN , CHT_UP   , CHT_DOWN , CHT_LEFT , CHT_UP   },TOGGLE},	//4 working
	{{"BOOMERANG BALL"},		{CHT_RIGHT, CHT_UP   , CHT_UP   , CHT_UP   , CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_DOWN },TOGGLE},	//18 working
	{{"BEACH BALL"},			{CHT_DOWN , CHT_DOWN , CHT_UP   , CHT_DOWN , CHT_DOWN , CHT_LEFT , CHT_RIGHT, CHT_DOWN },TOGGLE},	//9 working
	


	{{"LOW GRAVITY"},			{CHT_LEFT , CHT_LEFT , CHT_UP   , CHT_LEFT , CHT_RIGHT, CHT_UP   , CHT_UP   , CHT_UP   },TOGGLE},	//8 working
	{{"CINEMASCOPE"},			{CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT},TOGGLE},	// 

	{{"LOOK MODE"},				{CHT_DOWN , CHT_UP   , CHT_RIGHT, CHT_RIGHT, CHT_DOWN , CHT_LEFT , CHT_RIGHT, CHT_RIGHT},TOGGLE},	//21



/*
	{{"LOCATE GARIBS"},			{CHT_LEFT , CHT_UP   , CHT_RIGHT, CHT_DOWN , CHT_LEFT , CHT_UP   , CHT_LEFT , CHT_LEFT },TOGGLE},	//0
								                                                 
	{{"CONTROL BALL"},			{CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT, CHT_UP   , CHT_DOWN , CHT_RIGHT, CHT_RIGHT},TOGGLE},	//5
	{{"ENEMY BALL"},			{CHT_LEFT , CHT_DOWN , CHT_UP   , CHT_RIGHT, CHT_LEFT , CHT_LEFT , CHT_DOWN , CHT_DOWN },TOGGLE},	//7
								                                                 
	{{"FISH EYE"},				{CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT, CHT_LEFT , CHT_RIGHT},TOGGLE},	//10
	{{"CAMERA ROTATE R"},		{CHT_LEFT , CHT_RIGHT, CHT_UP   , CHT_UP   , CHT_DOWN , CHT_RIGHT, CHT_DOWN , CHT_RIGHT},REPEAT},	//11
	{{"CAMERA ROTATE L"},		{CHT_RIGHT, CHT_DOWN , CHT_RIGHT, CHT_DOWN , CHT_UP   , CHT_UP   , CHT_RIGHT, CHT_LEFT },REPEAT},	//12
	{{"MAD GARIBS"},			{CHT_DOWN , CHT_RIGHT, CHT_DOWN , CHT_UP   , CHT_LEFT , CHT_DOWN , CHT_LEFT , CHT_UP   },TOGGLE},	//13
	{{"VANISH BALL"},			{CHT_DOWN , CHT_DOWN , CHT_LEFT , CHT_LEFT , CHT_UP   , CHT_UP   , CHT_DOWN , CHT_UP   },TOGGLE},	//19

	{{"FROGGY"},				{CHT_UP	  , CHT_RIGHT, CHT_DOWN , CHT_RIGHT, CHT_UP   , CHT_LEFT , CHT_LEFT , CHT_UP   },TOGGLE},	//20
	{{"SECRET CHEAT"},			{CHT_DOWN , CHT_UP   , CHT_RIGHT, CHT_RIGHT, CHT_DOWN , CHT_LEFT , CHT_RIGHT, CHT_RIGHT},TOGGLE},	//21
	{{"OPEN PORTALS"},			{CHT_UP   , CHT_RIGHT, CHT_RIGHT, CHT_DOWN , CHT_LEFT , CHT_DOWN , CHT_UP   , CHT_RIGHT},TOGGLE},	//24

	{{"OPEN LEVELS"},			{CHT_DOWN , CHT_DOWN , CHT_LEFT , CHT_UP   , CHT_UP   , CHT_UP   , CHT_RIGHT, CHT_DOWN },TOGGLE},	//25
*/
};
#endif
char cheatInputString[8] = "\0";
char cheatInputPos = 0;

int cheatActivated = 0;

char cheatNeedsDraw = 0;
char isl_dongle_used = 0;

int cheatNameNumber = 0;
int cheatNameTicker = 0;
char cheatMessage[64];


//unsigned long sfxPlay(int vab,int sfxNum);

TEXT *cheatText = NULL;

char cheatSFX[4] =
{
	SFX_GE_KEG_CALL,
	SFX_GE_CHICKEN_BELCH,
	SFX_GE_CHICKEN_FART,
	SFX_GE_CHICKEN_CLUCKMAD
};


char cheatCheck()
{
	int i;

	cheatNeedsDraw = 2;

	if(debounce[0] & (PAD_L1 + PAD_L2 + PAD_R1 + PAD_R2))
	{
		int c = CHT_LEFT;
//		if(debounce[0] & PAD_L1) c = CHT_LEFT;
		if(debounce[0] & PAD_L2) c = CHT_RIGHT;
		if(debounce[0] & PAD_R1) c = CHT_UP;
		if(debounce[0] & PAD_R2) c = CHT_DOWN;

		cheatInputString[(int)cheatInputPos++] = c;

		sfxPlay(globalFX,cheatSFX[c-1]);

		i = cheatCompare();
		if(i != -1)
		{
			cheatInputPos = 0;
			memset(cheatInputString, CHT_DUMMY, CHEAT_STRING_LENGTH);
			cheatActivate(i,YES);
			return TRUE;
		}

	}
	if((cheatInputPos == CHEAT_STRING_LENGTH) || (debounce[0] & (PAD_UP | PAD_DOWN | PAD_LEFT | PAD_RIGHT)))
	{
		cheatInputPos = 0;
		memset(cheatInputString, CHT_DUMMY, CHEAT_STRING_LENGTH);
	}
	return FALSE;
}

void cheatDisplay()
{
	int i;

	if(cheatNeedsDraw)
		cheatNeedsDraw--;

	sprctrl.scalex = sprctrl.scaley = 4096;
	SETRGBC(sprctrl.r, 128,128,128,0);

	for(i = 0; i < CHEAT_STRING_LENGTH; i++)
	{
		if(cheatInputString[i] != CHT_DUMMY)
		{
//			spritePrint(SPR_cheatbase + (cheatInputString[i] - CHT_DUMMY - 1), resolution/2 + (i-4) * 32,100,10);


//			spritePrint(SPR_cheatbase + (cheatInputString[i] - CHT_DUMMY - 1), (i-4) * 32,80,10);

			spritePrint(SPR_cheats[(cheatInputString[i] - CHT_DUMMY - 1)], (i-4) * 32,80,10);
		}
	}
	if(cheatNameTicker)
	{
		cheatNeedsDraw = 2;

		cheatNameTicker--;
		if(!cheatNameTicker)
		{
			SubText(cheatText);
			cheatText = NULL;

		}
	}
}

int cheatCompare()
{
	int i, j;
	char match = 0;
	int max;

	if(isl_dongle_used)
	{
		max = NUM_CHEATS;
	}
	else
	{
		max = CHEAT_ALL_OFF+1;
	}


	for(i = 0; i < max; i++)
	{
		match = 0;
		for(j = 0; j < CHEAT_STRING_LENGTH; j++)
		{
			if(cheatInputString[j] == cheatInfo[i].string[j])
			{
				match++;
			}
			else
				continue;
		}
		if(match == CHEAT_STRING_LENGTH)
		{
			return i;
		}

	}
	return -1;
}


void cheatActivate(char num,char disp)
{
	char cheatOn = FALSE;
/*
	int j;
	int x, y;
	TEXTURE *tex;
	char *temp;
	USHORT col;
	GARIBGROUP *garibGroup;
	GARIB *garib;
*/
	//toggle cheat switches


	if(cheatInfo[(int)num].type == TOGGLE)
	{
		if(cheatActivated & (1 << num))
			cheatActivated &= -1 - (1 << num);
		else
		{
			cheatActivated |= (1 << num);
			cheatOn = TRUE;
		}
	}


//	cheatCount = 0;

	switch(num)
	{
		case CHEAT_SUMMON_BALL:
			if(cheatOn)
				cheatDoCallBall();	// and subsequently, it adds a menu item.
			break;

		case CHEAT_WIN_LEVEL:

//			if(cheatOn)
//				cheatDoWinLevel();	// and subsequently, it adds a menu item.
			break;

		case CHEAT_DEATH_SPELL:
//			if(player.pickupTimer[DEATH])
			if(handpower_timer && handpower_type == SPELL_DEATH)
			{
				cheatOn = FALSE;
				handpower_timer = 0;
				handpower_type = 0;
			}
			else
			{
				cheatOn = TRUE;
				handGivePlayerPower(SPELL_DEATH,1000);
			}
			break;
		
		case CHEAT_FROG_SPELL:
			if(handpower_timer && handpower_type == SPELL_FROGGY)
			{
				cheatOn = FALSE;
				handpower_timer = 0;
				handpower_type = 0;
			}
			else
			{
				cheatOn = TRUE;
				handGivePlayerPower(SPELL_FROGGY,1000);
			}
			break;

		case CHEAT_HERCULES:
			if(handpower_timer && handpower_type == SPELL_HERCULES)
			{
				cheatOn = FALSE;
				handpower_timer = 0;
				handpower_type = 0;
			}
			else
			{
				cheatOn = TRUE;
				handGivePlayerPower(SPELL_HERCULES,1000);
			}
			break;

		case CHEAT_SPEEDUP:
			if(handpower_timer && handpower_type == SPELL_SPEEDUP)
			{
				cheatOn = FALSE;
				handpower_timer = 0;
				handpower_type = 0;
			}
			else
			{
				cheatOn = TRUE;
				handGivePlayerPower(SPELL_SPEEDUP,1000);
			}
			break;

		case CHEAT_ROTOR:
			if(handpower_timer && handpower_type == SPELL_ROTORBLADES)
			{
				cheatOn = FALSE;
				handpower_timer = 0;
				handpower_type = 0;
			}
			else
			{
				cheatOn = TRUE;
				handGivePlayerPower(SPELL_ROTORBLADES,1000);
			}
			break;


		case CHEAT_POWERBALL:
			if(cheatOn)
				ballHitBySpell(SPELL_BALL_POWER,1000);
			else
				ballHitBySpell(SPELL_BALL_NORMAL,1000);
			break;

		case CHEAT_BIGBALL:
			if(cheatOn)
				ballHitBySpell(SPELL_BALL_BEACH,1000);
			else
				ballHitBySpell(SPELL_BALL_NORMAL,1000);
			break;

		case CHEAT_BOOMERANGBALL:
			ballHitBySpell(SPELL_BOOMERANG,300);

// tbd - timer
/*
			if(player.pickupTimer[BOOMERANGBALL])
			{
				cheatOn = FALSE;
				DeactivateCollectable(BOOMERANGBALL);
			}
			else
			{
				cheatOn = TRUE;
				ActivateCollectable(BOOMERANGBALL,1000);
			}
*/
			break;

		case CHEAT_LO_GRAVITY:
			if(cheatOn)
				gravity /= 2;
			else
				gravity *= 2;
			break;

		case CHEAT_CINEMASCOPE:
			if(cheatOn)
				cinemascopeToggle=2;
			else
				cinemascopeToggle=1;

			break;

		case CHEAT_LEVEL_SELECT:
			cheatMenuOn=1;
			break;

/*

		case CHEAT_CONTROLBALL:
			if(cheatOn)
			{
				ballStatic = 0;
				ball.flags = defaultBehaviour[ballControl.ballType].flags;
				SetVector(&ball.pos, &hand.pos);
			}
			else
				SetControlToHand();
 			break;

		case CHEAT_BALL_TO_ENEMY:
			if(cheatOn)
			{
				switch(gameInfo.world)
				{
					case ATLANTIS:
						ballEnemyType = MALLET;
						break;
					case CARNIVAL:
						ballEnemyType = BUGLE;
						break;
					case PIRATES:
						ballEnemyType = CANNONBALL;
						break;
					case PREHISTORIC:
						ballEnemyType = BOVVA;
						break;
					case FEAR:
						ballEnemyType = DIBBER;
						break;
					case SPACE:
						ballEnemyType = OPEC;
						break;
					case HUB:
						ballEnemyType = CANNONBALL;
						break;
				}
				DeactivateCollectable(CRYSTALBALL);
				DeactivateCollectable(SNOWBALL);
				FindObject(&ball.objectController, UpdateCRC(nmeObjectName[ballEnemyType]), nmeObjectName[ballEnemyType],YES);
				AddObjectsSpritesToSpriteList(ball.objectController->object);
				ball.scale.v[X] = ball.scale.v[Y] = ball.scale.v[Z] = (ball.collision->sphere[0].radius*enemyStats[ballEnemyType].scale)/defaultBehaviour[ballEnemyType].radius;
				ball.collision->sphere[0].radiusAim = defaultBehaviour[ballEnemyType].radius;
				for(j = 0;j < MAX_PLASTERS;j++)
					plaster[j].xluOverride = 0;
			}
			else
			{
				RemoveObjectSprites(ball.objectController->object,YES);
				FindObject(&ball.objectController, UpdateCRC("gball.ndo"), "gball.ndo",YES);
				ball.scale.v[X] = ball.scale.v[Y] = ball.scale.v[Z] = (ball.collision->sphere[0].radius*HAND_NORMAL_SCALE)/BALL_NORMAL_RADIUS;
				ball.collision->sphere[0].radiusAim = defaultBehaviour[ballControl.ballType].radius;
				for(j = 0;j < MAX_PLASTERS;j++)
					plaster[j].xluOverride = 100;
			}
			break;



		case CHEAT_FISHEYE:
			if(cheatOn)
				fieldOfViewAim = 120;
			else
				fieldOfViewAim = 45;
			break;

		case CHEAT_ROTATE_CAM_LEFT:
			RotateVector2DXYZ(&cameraUpVectAim,&cameraUpVectAim,-PI/4,Z);
			break;

		case CHEAT_ROTATE_CAM_RIGHT:
			RotateVector2DXYZ(&cameraUpVectAim,&cameraUpVectAim,PI/4,Z);
			break;

		case CHEAT_REAL_GARIB:
			for(garibGroup = garibGroupList.head.next;garibGroup != &garibGroupList.head;garibGroup = garibGroup->next)
			{
				for(garib = garibGroup->garibList.head.next;garib != &garibGroup->garibList.head;garib = garib->next)
				{
					if(garib->type == NORMAL_GARIB)
					{
						if(cheatOn)
							InitSpriteAnimation(&garib->sprite,&garibAnimation[REAL_GARIB],0);
						else
							InitSpriteAnimation(&garib->sprite,&garibAnimation[NORMAL_GARIB],0);
					}
				}
			}
			break;




		case CHEAT_VANISHBALL:
			if(player.pickupTimer[VANISHBALL])
			{
				cheatOn = FALSE;
				DeactivateCollectable(VANISHBALL);
			}
			else
			{
				cheatOn = TRUE;
				ActivateCollectable(VANISHBALL,1000);
			}
			break;

		case CHEAT_HAND_TO_FROG:
			if(handControl.spellCount[FROGGY] > 50)
			{
				cheatOn = FALSE;
				handControl.spellCount[FROGGY] = 50;
			}
			else
			{
				cheatOn = TRUE;
				ActivateSpellHand(FROGGY);
				handControl.spellCount[FROGGY] = 1000;
			}
			break;
*/

		case CHEAT_ALL_OFF:
		{
			int j;
			for(j = 0;j < NUM_CHEATS;j++)
			{
				if((cheatActivated & (1<<j)) && (cheatInfo[j].type == TOGGLE))
					cheatActivate(j,NO);
					
			}
//			LOAD_VECTOR(cameraUpVectAim,0,1,0);
			break;
		}

		default:
			break;
 
 	}

	effectsStartOverlay(10,0xffffff);


	if(disp)
	{
		cheatNameTicker = 50;

//		NEW_TEXT(256, 68, 128,128,0,255, 4096,4096, TRUE, "", TRUE);



		if(cheatText)
			SubText(cheatText);
		NEW_TEXT(256, 60, 128,128,0,255, 4096,4096, TRUE, "", TRUE);
		cheatText = mtext;
		cheatText->flags=TEXT_SHADED|TEXT_ANIMATED;

			SETRGBC(cheatText->r, 128,128,0,255);
			SETRGBC(cheatText->r1, 128,40,8,255);
#ifdef MULTI_LANGUAGE
		{
			int sub;
			sub = 0;
			if(language == 3)
			{
				switch(num)
				{
				case CHEAT_ALL_OFF:
				case CHEAT_ACCESS_ALL_RESTARTS:
					sub = 1;
					break;
				case CHEAT_INFINITE_ENERGY:
					sub = 2;
					break;
				case CHEAT_INFINITE_LIVES:
					sub = 3;
					break;
				}
			}
		if(cheatOn)
			sprintf(cheatText->message,"%s %s",
				fontFindLangString(cheatInfo[(int)num].name_id),
				fontFindLangString(STR_CHEAT_ON+sub)
				);
		else
			sprintf(cheatText->message,"%s %s",
				fontFindLangString(cheatInfo[(int)num].name_id),
				fontFindLangString(STR_CHEAT_OFF+sub)
				);
		}
#else
		if(cheatOn)
			sprintf(cheatText->message,"%s ON!",cheatInfo[(int)num].name);
		else
			sprintf(cheatText->message,"%s OFF!",cheatInfo[(int)num].name);
#endif
		if(strlen(cheatText->message) > 16)
		{
			cheatText->scaleX = 4096 * 16 / strlen(cheatText->message);
		}
		else
		{
			cheatText->scaleX = 4096;
		}
		cheatText->font=fontList[0];

		sfxPlay(globalFX,SFX_COLLECT_BONUS_2);


	}
}


void cheatSetText(char *string)
{
	if(cheatText)
		SubText(cheatText);
	NEW_TEXT(256, 60, 128,128,0,255, 4096,4096, TRUE, "", TRUE);
	cheatText = mtext;
	cheatText->flags=TEXT_SHADED|TEXT_ANIMATED;

	if(strlen(string) > 16)
	{
		cheatText->scaleX = 4096 * 16 / strlen(string);
	}
	else
	{
		cheatText->scaleX = 4096;
	}
	cheatText->font=fontList[0];


	SETRGBC(cheatText->r, 128,128,0,255);
	SETRGBC(cheatText->r1, 128,40,8,255);
	strcpy(&cheatText->message[0],string);
	cheatNameTicker = 50;
	cheatNeedsDraw = 2;

}



void cheatDoCallBall()
{
	VECTOR pos;
	pos = glovePos;
	pos.vy -= 50<<12;
	ballPlaceAt(&pos);
}



void cheatDoWinLevel()
{

	if( world == HUB)
	{
		if(!GameState.levels_open[0] & LEVOPEN_L1_OPEN)
		{
			GameState.levels_open[0] |= LEVOPEN_L1_OPEN;
		}
		else
		{
			int i;

			for(i = 0; i < 6; i++)
			{
				if(!(GameState.levels_open[i] & LEVOPEN_CRYSTAL_DELIVERED))	// Have we returned that level's Xtal ?
				{
					GameState.levels_open[i] |= LEVOPEN_L1_OPEN | LEVOPEN_L2_OPEN | LEVOPEN_L3_OPEN
						| LEVOPEN_BOSS_OPEN | LEVOPEN_BONUS_OPEN
						| LEVOPEN_BOSS_BEATEN;	// | LEVOPEN_CRYSTAL_DELIVERED;

// Frig the "level we're coming from" to be a boss level with no hard-coded platforms in "bosses.c"
// (actually, say we're coming from the wayroom having carted the ball around for a bit)

					gameCtrl.wayroom_world = (i + ATLANTIS);
					level = WAYROOM;
//					level = ATLANTISBOSS;

/*
					if(i == 6)
						level = SPACEBOSS2;
					else
						level = i * 5 + ATLANTISBOSS;
*/
					break;
				}
			}
		}

		gameCtrl.port_with_ball = TRUE;
		GloveCtrl.ballWithHand = TRUE;

		CaveHubDecide();

	}

	NextLevelBasics();
	gameCtrl.dropOutFlag=GAME_COMPLETED;


	MenuFadeOut();
//	gameCtrl.state = TRUE;
//	gameCtrl.gameActive=TRUE;
	gameCtrl.fadeIn=0;
	gameCtrl.fadeOut=0;
}

