/******************************************************************************************
	CRTEST PS   (c) 1999-2001 ISL

	credits.c:			Scrolling Credits 
******************************************************************************************/


#include "global.h"
#include "overlays.h"
#include "main.h"
#include "menu.h"
#include "gametext.h"
#include "map_draw.h"
#include "credits.h"
#include "menu.h"
#include "demo.h"
#include "sound.h"
#include "options.h"
#include "DC_TIM.h"

#define NUM_CREDITS 138
#define BLNK TEXTSTR_CREDITS_BLANK_LINE		// Saves me a bit of typing..

#undef NULL
#define NULL 0

struct {
	int state;	
	int drawposition;				// position to start drawing the list
	int listposition;				// position in the list
} credits;	


enum {
	CREDITS_STATE_SCROLLING,		// Scrolling text
	CREDITS_STATE_MODELS,			// Actors walking on/off
};


int creditscolours[] =
{
	0x808040,
	0,
	0,
	0,

	0x808040,
	0x808080,
	0,

	0x808040,
	0x808080,
	0,

	0x808040,
	0x808080,
	0,

	0x808040,		// Team leaders
	0x808080,
	0x808080,
	0,

	0x808040,		// Lead Prog
	0x808080,
	0,

	0x808040,		// Prog
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0,

	0x808040,		// Tools prog
	0x808080,
	0x808080,
	0,


	0x808040,		// Artists
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0,


	0x808040,		// Additional modelling
	0x808080,
	0,

	0x808040,		// Animation
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0,

	0x808040,	// Texture art
	0x808080,
	0,

	0x808040,	// concept
	0x808080,
	0,

	0x808040,		// Add prog
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0,

	0x808040,		// compression
	0x808080,
	0,


	0x808040,	// lighting
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0,

	0x808040,	// Music
	0x808080,
	0,

	0x808040,	// SFX
	0x808080,
	0,

	0x808040,	// MD
	0x808080,
	0,
	
	0x808040,	// TD
	0x808080,
	0,

	0x808040,	// Special thanks
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0x808080,
	0,

	0x808040,	// Eidos
	0,

	0x804080,	// chicken Pies
	0x804080,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,

	0x804080,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0,
	0
};

int creditlist[] = 
{
	TEXTSTR_CREDITS_GAME,		//1
	BLNK,						//2
	BLNK,						//3
	BLNK,						//4
	
	TEXTSTR_CREDITS_DESIGNED,	//6
	TEXTSTR_CREDITS_BLITZ,		//7
	BLNK,						//8

	TEXTSTR_CREDITS_FOUNDED,	//10
	TEXTSTR_CREDITS_OLIVERS,	//11
	BLNK,						//12
	
	TEXTSTR_CREDITS_PROJECT_MANAGER,		//14
	TEXTSTR_CREDITS_NAMES_DWOOD,			//15
	BLNK,									//16
	
	TEXTSTR_CREDITS_TEAM_LEADER,			//18
	TEXTSTR_CREDITS_NAMES_DFLYNN,			//19
	TEXTSTR_CREDITS_NAMES_DMANUEL,			//20
	BLNK,									//21

	TEXTSTR_CREDITS_LEAD_PROGRAMMER,		//23
	TEXTSTR_CREDITS_NAMES_FWILLIAMS,		//24
	BLNK,									//25

	
	TEXTSTR_CREDITS_PROGRAMMERS,			//27
	TEXTSTR_CREDITS_NAMES_TDRUMMOND,		//28
	TEXTSTR_CREDITS_NAMES_DHARRIES,			//29
	TEXTSTR_CREDITS_NAMES_BPATERSON,		//30
	TEXTSTR_CREDITS_NAMES_CWILSON,			//31
	BLNK,									//32
									
	TEXTSTR_CREDITS_TOOLS_PROGRAMMERS,		//34
	TEXTSTR_CREDITS_NAMES_JSTEELE,			//35
	TEXTSTR_CREDITS_NAMES_CWILSON,			//36
	BLNK,									//37


	TEXTSTR_CREDITS_ARTISTS,				//51
	TEXTSTR_CREDITS_NAMES_MBEYNON,			//52
	TEXTSTR_CREDITS_NAMES_TCARTWRIGHT,		//53
	TEXTSTR_CREDITS_NAMES_DFLYNN,			//54
	TEXTSTR_CREDITS_NAMES_TKING,			//55
	TEXTSTR_CREDITS_NAMES_JWALSH,			//56
	TEXTSTR_CREDITS_NAMES_DWHITEHEAD,		//57
	BLNK,									//58
			
	TEXTSTR_CREDITS_ADDITIONAL_MODELLING,	//60
	TEXTSTR_CREDITS_NAMES_CSOUTHALL,		//61
	BLNK,									//62

	TEXTSTR_CREDITS_ANIMATION,				//64
	TEXTSTR_CREDITS_NAMES_NADAMS,			//65
	TEXTSTR_CREDITS_NAMES_TCARTWRIGHT,		//66
	TEXTSTR_CREDITS_NAMES_DMANUEL,			//67
	TEXTSTR_CREDITS_NAMES_NPETTIT,			//68
	BLNK,									//69
	
	TEXTSTR_CREDITS_TEXTURE_ART,			//71
	TEXTSTR_CREDITS_NAMES_RJONES,			//72
	BLNK,									//73

	TEXTSTR_CREDITS_ADDITIONAL_ART,			//75
	TEXTSTR_CREDITS_NAMES_SHAYES,			//76
	BLNK,									//77

	TEXTSTR_CREDITS_ADDITIONAL_PROGRAMMERS,	//39
	TEXTSTR_CREDITS_NAMES_IBIRD,			//40
	TEXTSTR_CREDITS_NAMES_SBOND,			//41
	TEXTSTR_CREDITS_NAMES_SLAMB,			//42
	TEXTSTR_CREDITS_NAMES_ASIDWELL,			//43
	TEXTSTR_CREDITS_NAMES_JWHIGHAM,			//44
	BLNK,									//46
							
	TEXTSTR_CREDITS_COMPRESSION,			//47
	TEXTSTR_CREDITS_NAMES_RHACKETT,			//48
	BLNK,									//49


	TEXTSTR_CREDITS_LIGHTING,				//79
	TEXTSTR_CREDITS_NAMES_MBEYNON,			//84
	TEXTSTR_CREDITS_NAMES_DFLYNN,			//85
	TEXTSTR_CREDITS_NAMES_SHAYES,			//86
	TEXTSTR_CREDITS_NAMES_NMATHIAS,			//80
	TEXTSTR_CREDITS_NAMES_TKING,			//87
	TEXTSTR_CREDITS_NAMES_JWALSH,			//88
	TEXTSTR_CREDITS_NAMES_DWHITEHEAD,		//89
	BLNK,									//91

	TEXTSTR_CREDITS_MUSIC,					//92
	TEXTSTR_CREDITS_NAMES_RLORD,			//93
	BLNK,

	TEXTSTR_CREDITS_SOUND_EFFECTS,
	TEXTSTR_CREDITS_NAMES_RLORD,
	BLNK,

	TEXTSTR_CREDITS_MANAGING_DIRECTOR,
	TEXTSTR_CREDITS_NAMES_POLIVER,
	BLNK,

	TEXTSTR_CREDITS_TECHNICAL_DIRECTOR,
	TEXTSTR_CREDITS_NAMES_AOLIVER,
	BLNK,

	TEXTSTR_CREDITS_THANKS_TO,
	TEXTSTR_CREDITS_NAMES_IWAKEFIELD,
	TEXTSTR_CREDITS_NAMES_CTHALMANN,		//110
	TEXTSTR_CREDITS_NAMES_JHINTON,
	TEXTSTR_CREDITS_NAMES_TSMALL,
	TEXTSTR_CREDITS_NAMES_DWILSONNUNN,
	TEXTSTR_CREDITS_NAMES_LPRICE,
	TEXTSTR_CREDITS_NAMES_NDAVIES,
	TEXTSTR_CREDITS_NAMES_STHORBURN,
	TEXTSTR_CREDITS_NAMES_RSMYTHE,
	TEXTSTR_CREDITS_NAMES_APARKER,
	TEXTSTR_CREDITS_NAMES_CHART,
	TEXTSTR_CREDITS_NAMES_JPINNOCK,
	TEXTSTR_CREDITS_NAMES_JLYONS,
	TEXTSTR_CREDITS_NAMES_GHERBERT,
	TEXTSTR_CREDITS_NAMES_NRANDALL,
	TEXTSTR_CREDITS_NAMES_LARD,
	TEXTSTR_CREDITS_NAMES_REDBULL,
	BLNK,

	TEXTSTR_CREDITS_NAMES_EIDOS,
	BLNK,

	TEXTSTR_CREDITS_PIES,
	TEXTSTR_CREDITS_PIES2,				
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,

	TEXTSTR_CREDITS_PIES3,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,
	BLNK,

	NULL
};

TIM_HEADER *creditsImg=NULL;


// Font is 12 pixels high


/*--------------------------------------------------------------------------
	   Function : void creditsDraw(void)
	Description : Draw the credits
	 Parameters :  
	    Returns :  
	       Info : 
--------------------------------------------------------------------------*/

void creditsDraw(void)
{
	int i;

	for(i=credits.listposition;i<credits.listposition+23;i++)
		fontPrintCentred(font,0,credits.drawposition+((i-credits.listposition)*18),TEXTSTR(creditlist[i]),(creditscolours[i]>>16) & 0xff,(creditscolours[i]>>8) & 0xff,creditscolours[i] & 0xff);

//	drawBGTim();

	dcTim_Draw(0, 0, 639, 479, creditsImg);
}





/*--------------------------------------------------------------------------
	   Function : void creditsCycle(void)
	Description : 
	 Parameters :  
	    Returns :  
	       Info : 
--------------------------------------------------------------------------*/

void creditsCycle(void)
{
	switch(credits.state)
	{
		case CREDITS_STATE_SCROLLING:
			credits.drawposition--;
	
			if(credits.drawposition<-273)
			{
				credits.drawposition=-256;
				credits.listposition++;
			}

			if(credits.listposition>=NUM_CREDITS)
				creditsEnd();
			break;
	}

	if(pReadPad->debounce[0] & (PAD_TRIANGLE + PAD_SQUARE + PAD_CROSS + PAD_CIRCLE + PAD_START))
		creditsEnd();
}





/*--------------------------------------------------------------------------
	   Function : void creditsStart(void)
	Description : 
	 Parameters :  
	    Returns :  
	       Info : 
--------------------------------------------------------------------------*/

void creditsStart(void)
{
 //	overlayLoadingBegin(1);
	creditsLoad();
//	overlayLoadingEnd();

	draw_routine = creditsDraw;
	cycle_routine = creditsCycle;

	credits.listposition = 0;					
	credits.drawposition = 150;
	credits.state = CREDITS_STATE_SCROLLING;
}






/*--------------------------------------------------------------------------
	   Function : void creditsLoad(void)
	Description : 
	 Parameters :  
	    Returns :  
	       Info : 
--------------------------------------------------------------------------*/

void creditsLoad(void)
{
	ULONG *tim;

  //	overlayLoadingBegin(1);
	sound_XA_PauseForLoading();

 //	tim=(ULONG *)fileLoad("FRONTEND\\SPLASH\\ACT1.TIM",0);

	dcTim_Load(&creditsImg, "FRONTEND\\SPLASH\\ACT1.TIM");



  //	overlayLoadingEnd();

	sound_XA_Resume(-1);

//	uploadTimToVRAM(tim);
	
	FREE(tim);
}





/*--------------------------------------------------------------------------
	   Function : void creditsEnd(void)
	Description : 
	 Parameters :  
	    Returns :  
	       Info : 
--------------------------------------------------------------------------*/

void creditsEnd(void)
{
	optionsStart(OPTIONS_DIARY_START);
	dcTim_Unload(&creditsImg);
}

