Example #1
0
/*
-----------------------------------------------------------------------------
 Function: 
 
 Parameters:
 
 Returns:
 
 Notes: 

-----------------------------------------------------------------------------
*/
PUBLIC void PL_Init(void)
{
	PL_Reset();
	PL_NewGame( &Player );

	Cmd_AddCommand( "god", Cmd_God_f );
	Cmd_AddCommand( "notarget", PL_notarget_f );
	Cmd_AddCommand( "give", Cmd_Give_f );
}
Example #2
0
//==========================================
//  iphoneSelectMapMenu()
//  A doom classic style map selector
//==========================================
void iphoneSelectMapMenu()
{
	int		s;			//skill
	char	str[64];
	
	// highlight the current skill selection
	int skillValue = (int)skill->value;
	if (skillValue < 0)
		skillValue = 0;
	if (skillValue > 3)
		skillValue = 3;
	
	int skillSides = 80;
	
	int	e = 0;		//episode
	
	int m, map;			//mission/map
	int height = 48;
	int spacing = 10;
	int y = 0;
	
	char strMission[80];
	strMission[79] = '\0';
	
	int		numMaps = 60;
	if (g_version->value == SPEAROFDESTINY)
		numMaps = 60 + 21;
	
	iphoneDrawPic(0, 0, 480, 320, "iphone/submenus_background_image.tga");
	
	//check for BackButton touches
	if ( BackButton() ) {
		menuState = IPM_MAIN;
		return;
	}
	
	//we want to use the menu selector bar
	my_snprintf( str, sizeof( str ), "iphone/menu_bar.tga" );
	
	//iterate through the maps... drawing only the visible maps
	for (m = 0; m < numMaps; m++)
	{
		
		//Draws the spacing between each episode
		e = m/10;
		if (e < 6)
		{
			y = dragPosition + ((height + spacing) * e*11);// + ((height + spacing) * (e+1));
			if ( y >= -height && y < 320 )
			{
				my_snprintf( str, sizeof( str ), "iphone/button_ep%i.tga", e+1 );
				iphoneDrawPic( 0, y, 480-80, height, str);
			}
				
			y = dragPosition + ((height + spacing) * m) + ((height + spacing) * (e+1));
		}
		else
		{
			y = dragPosition + ((height + spacing) * 6*11);
			if ( y >= -height && y < 320 )
			{
				my_snprintf( str, sizeof( str ), "iphone/button_epSOD.tga");
				iphoneDrawPic( 0, y, 480-80, height, str);
			}
			y = dragPosition + ((height + spacing) * m) + ((height + spacing) * 7);
		}
		
		//we want to use the menu selector bar
		my_snprintf( str, sizeof( str ), "iphone/menu_bar.tga" );
		
		//only draw the maps that are currently viewable
		if ( y >= -height && y < 320 )
		{
			e = m/10;
			map = m%10;
			
			//color maps
			int ch = currentMap.mapFlags[skillValue][m];
			
			int alpha = 128;
			colour4_t colorSecret = { 80, 0, 0, alpha };
			colour4_t colorNoTry = { 0, 0, 0, alpha };
			colour4_t colorTried = { 80, 80, 0, alpha };
			colour4_t colorCompleted = { 0, 80, 0, alpha };
			colour4_t colorBlink = { 80, 80, 80, alpha };
			
			unsigned char *color = colorNoTry;
			bool isSecretAvailable = true;
			
			if ( map == 9  && !( ch & MF_TRIED ) && e < 6)  //if it's the 9th and not SOD
			{
				color = colorSecret;
				isSecretAvailable = false;
			}
			else if ( (m == 79 || m == 78) && !(ch & MF_TRIED) ) //if it's the secret SOD levels
			{
				color = colorSecret;
				isSecretAvailable = false;
			} else if ( ch & MF_COMPLETED ) {
				color = colorCompleted;
			} else if ( ch & MF_TRIED ) {
				color = colorTried;
			} else {
				color = colorNoTry;
			}
			
			//blink the level you're currently on
			if ( ( iphoneFrameNum & 8 ) && map == currentMap.map && e == currentMap.episode )
				color = colorBlink;
			
			//draw maps and touch
			if ( iphoneDrawPicWithTouchAndColor( 0, y, 480-80, height, str, color) && dragVelocity == 0 && isSecretAvailable )
			{
				//reset the player to new
				PL_NewGame( &Player );
				
				//set episode and map numbers and load map
				Cvar_SetValue( episode->name, e );
				iphonePreloadBeforePlay();				//This prevents crashes when loading SOD maps
				iphoneStartMap( e, map, skillValue );
			}
			
			//draw the rewards
			iphoneDrawRewards(m, skillValue, 0, y);
			
			//draw the episode and map over the selection bar
			my_snprintf( strMission, sizeof( strMission ), "%s", levelNames[m] );
			iphoneDrawText( 100, y + 16, 16, 16, strMission );
//			iphoneCenterText( 160, y + 16, strMission );
		}
	}
	
	int numUserMaps = 0;
	
#if 0
	//buy more episodes button
	if (g_version->value != SPEAROFDESTINY) 
		GetSpearOfDestiny( 0, dragPosition + (height + spacing) * (m+6) );
#endif
	//TODO: Draw user maps
	numUserMaps = iphoneDrawUserMaps(y, height, spacing, skillValue);	
	
	//Update the scrolling drags
	iphoneUpdateDrags(numMaps, skillSides, height, spacing, numUserMaps);

	
	//Draw/choose the skills on the right side of the screen
	for ( s = 0 ; s < 4 ; s++ )
	{
		my_snprintf( str, sizeof( str ), "iphone/button_skill%i.tga", s+1 );
		
		if ( s != (int)skill->value ) {
			pfglColor3f( 0.5, 0.5, 0.5 );
		}
		if ( iphoneDrawPicWithTouch( 480 - skillSides, skillSides*s, skillSides, skillSides, str ) ) {	
			Cvar_SetValue( skill->name, s );
			skillValue = s;
			break;
		}
		pfglColor3f( 1, 1, 1 );
	}
	

	
	//Draw a bar that covers empty space
	iphoneDrawPic(0, 0, 480-80, 32, "iphone/menu_bar.tga");
	
	//levels header
	iphoneDrawPic(240-64, 0, 128, 32, "iphone/header_levels.tga");
	
	BackButton();  //this is kinda cheap...
	//we want the back button to render on top
	//but we also want it to check for touches before the maps
	//so we call this function twice
	//(at the beginning for touches; the end for rendering)
}
Example #3
0
//==========================================
//  iphoneDrawUserMaps()
//  This function scans through the custom maps
//  and displays the ones on screen
//==========================================
int iphoneDrawUserMaps(int Yoffset, int height, int spacing, int skillValue)
{	
	int numMaps = 0;
	
	DIR *dp;
	struct dirent *ep;
	char mapBuffer[1024];
	
	int length = strlen(iphoneDocDirectory);
	strcpy(mapBuffer, iphoneDocDirectory);
	strcpy(mapBuffer + length, "/usermaps/");
	
	dp = opendir (mapBuffer);
	
	if (dp != NULL)
	{
		int y = Yoffset;
		if (g_version->value != SPEAROFDESTINY)  //make space for the purchase SOD button
			y += height + spacing + spacing;
		
		//draw the custom map spacing
		y += height + spacing;
		iphoneDrawPic( 0, y, 480-80, height, "iphone/button_epSOD.tga");
		
			
		while ( ( ep = readdir (dp) ) )
		{
			++numMaps;
			if (numMaps < 3)  //skip the '.' and '..'
				continue;
			
			y += height + spacing;
			Com_Printf("value y:  %i\n", y);

			//TODO: draw the names!
			if ( y >= -height && y < 320 )
			{
			
				//draw maps and touch
				int alpha = 128;
				//colour4_t colorSecret = { 80, 0, 0, alpha };
				colour4_t colorNoTry = { 0, 0, 0, alpha };
			
				if ( iphoneDrawPicWithTouchAndColor( 0, y, 480-80, height, "iphone/menu_bar.tga", colorNoTry) && dragVelocity == 0 )//&& isSecretAvailable )
				{
					//reset the player to new
					PL_NewGame( &Player );
				
					//set episode and map numbers and load map
					int e = 9; //9 will be used to show a custom map
					Cvar_SetValue( episode->name, e );
					iphonePreloadBeforePlay();				//This prevents crashes when loading SOD maps
					iphoneStartUserMap( e, numMaps - 3, skillValue, ep->d_name );
				}
				
				iphoneDrawText( 100, y + 16, 16, 16, ep->d_name );
				//iphoneCenterText( 160, y + 16, ep->d_name );
				
				//draw the rewards
				iphoneDrawRewards(numMaps-2+90, skillValue, 0, y);
			}
		}
		closedir (dp);
		
		--numMaps;
		--numMaps;
	}
	
	Com_Printf("numMaps: %i\n", numMaps);
	
	return numMaps;
}
/**
 * \brief Load game state from file
 * \param[in] name Name of save game file to load.  
 * \return 1 on success, otherwise 0
 */
PUBLIC int LoadTheGame( const char *name ) 
{
	FILE	*f;
	char	path[1024];
	int		version;
	int		i;
	int		oldCompleted;
	
	com_snprintf( path, sizeof( path ), "%s%c%s.bin", FS_Userdir(), PATH_SEP, name );
	f = fopen( path, "rb" );
	if( ! f ) {
		Com_Printf( "Could not open %s.\n", path );
		return 0;
	}
	
	fread( &currentMap, 1,sizeof(currentMap) , f);
	
	if ( currentMap.version != SAVEGAME_VERSION ) {
		Com_Printf( "Savegame header version mismatch: %i != %i\n", currentMap.version, SAVEGAME_VERSION );
		fclose( f );
		return 0;
	}
	
	
	Com_Printf("episode: %i\nmap: %i\n", currentMap.episode, currentMap.map);
	
	// load the huds
	//fread( &huds, 1,sizeof(huds), f);
	
	// do a normal map start
	Cvar_SetValue( skill->name, (float)currentMap.skill );
	PL_NewGame( &Player );
	
	oldCompleted = currentMap.levelCompleted;
	StartGame( currentMap.episode, currentMap.map, currentMap.skill );
	Cbuf_Execute();
	
	currentMap.levelCompleted = oldCompleted;
	
	// load modifications on top
	fread( &levelData, 1,sizeof(levelData), f);
	fread( &LevelRatios, 1,sizeof(LRstruct), f );
	fread( &levelstate, 1,sizeof(levelstate), f );
	fread( Guards, 1,sizeof(Guards), f );
	fread( areaconnect, 1,sizeof(areaconnect), f );
	fread( areabyplayer, 1,sizeof(areabyplayer), f );
	fread( &PWall, 1,sizeof(PWall), f );
	fread( &Player, 1,sizeof(Player), f );
	fread( &version, 1,sizeof(version), f );
	
	fclose( f );

	ClientState.viewangles[ YAW ] = RAD2FINE(Player.position.angle);
	ClientState.viewangles[ PITCH ] = RAD2FINE(Player.position.pitch);

	if ( version != SAVEGAME_VERSION ) {
		Com_Printf( "Savegame trailer version mismatch: %i != %i\n", version, SAVEGAME_VERSION );
		return 0;
	}
	
	// turn the r_world->Doors.doors back to pointers
	for ( i = 0 ; i < r_world->Doors.doornum ; i++ ) 
    {
		int	index = (int)r_world->Doors.Doors[i];
		assert( index >= 0 && index < 4096 );
		r_world->Doors.Doors[i] = &r_world->Doors.DoorMap[0][0] + index;
	}

	return 1;
}