Example #1
0
/*! 
 Updates the race results based on the results of the race just completed
 Should be called before last_race_completed is updated.
 \author  jfpatry
 \date    Created:  2000-09-24
 \date    Modified: 2000-09-24
 */
static void update_race_results( void )
{
    char *event;
    char *cup;
    bool_t update_score = False;
    char *race_name;
    scalar_t time;
    int herring;
    int score;
    
    if ( g_game.practicing ) {
        open_course_data_t *data;
        data = (open_course_data_t*)get_list_elem_data( cur_elem );
        race_name = data->name;
    } else {
        race_data_t *data;
        data = (race_data_t*)get_list_elem_data( cur_elem );
        race_name = data->name;
    }
    
    event = g_game.current_event;
    cup = g_game.current_cup;
    
    if ( !get_saved_race_results( plyr->name,
                                 event,
                                 cup,
                                 race_name,
                                 g_game.difficulty,
                                 &time,
                                 &herring,
                                 &score ) )
    {
        update_score = True;
    } else if ( !g_game.practicing && !cup_complete ) {
        /* Scores are always overwritten if cup isn't complete */
        update_score = True;
    } else if ( plyr->score > score ) {
        update_score = True;
    } else {
        update_score = False;
    }
    
    if ( update_score ) {
        bool_t result;
        result = 
	    set_saved_race_results( plyr->name,
                               event,
                               cup,
                               race_name,
                               g_game.difficulty,
                               g_game.time,
                               plyr->herring,
                               plyr->score ); 
        if ( !result ) {
            print_warning( IMPORTANT_WARNING,
                          "Couldn't save race results" );
        }
    }
}
Example #2
0
void init_saved_games( void ) 
{
    char dir_name[BUFF_LEN];
    FILE* save_stream;
    save_info_t this_save;
    char player_name[BUFF_LEN];
    int sav_index;
    char file_name[BUFF_LEN];
    int i;
    char magic[4];
    list_t dir_file_list = NULL;
    list_elem_t cur_dir_file = NULL;
    char *cur_dir_filename = NULL;


    progress_save_table = create_hash_table();

    for (i=0; i<DIFFICULTY_NUM_LEVELS; i++) {
	results_save_table[i] = create_hash_table();
    }
 
    if (get_config_dir_name( dir_name, sizeof(dir_name) ) != 0) {
	return;
    }

    dir_file_list = get_dir_file_list(dir_name);
    if ( dir_file_list == NULL ) {
	/* Config dir doesn't exist.  Don't print warning since this is a
	   normal condition the first time the program is run. */
	return;
    }

    for ( cur_dir_file = get_list_head( dir_file_list );
	  cur_dir_file != NULL;
	  cur_dir_file = get_next_list_elem( dir_file_list, cur_dir_file ) )
    {
	cur_dir_filename = (char*) get_list_elem_data( cur_dir_file );

	if (get_sav_index(cur_dir_filename, &sav_index)) {

	    strncpy(player_name, cur_dir_filename, sav_index);
	    player_name[sav_index] = '\0';

	    sprintf( file_name, "%s" DIR_SEPARATOR "%s", 
		     dir_name,
		     cur_dir_filename );

	    save_stream = fopen( file_name, "r" );

	    if ( fread( magic, sizeof(magic), 1, save_stream ) != 1 ||
		 strncmp( magic, SAVE_MAGIC_V1, sizeof(magic) ) != 0 ) 
	    {
		print_warning( IMPORTANT_WARNING,
			       "`%s' is not a valid saved game file",
			       file_name );
		fclose( save_stream);
		continue;
	    }


	    if (save_stream != NULL) {
		while (fread( &this_save, sizeof(this_save), 1, save_stream)) {
		    switch ( this_save.data_type ) {
		    case EVENT_INFO:
			set_last_completed_cup( player_name, 
						this_save.data.event.event, 
						this_save.data.event.difficulty, 
						this_save.data.event.cup );
			print_debug( DEBUG_SAVE,
				     "Read completed from `%s': "
				     "name: %s, event: %s, difficulty: %d, cup: %s",
				     cur_dir_filename, 
				     player_name,
				     this_save.data.event.event,
				     this_save.data.event.difficulty,
				     this_save.data.event.cup );
			break;

		    case RACE_RESULTS:
			set_saved_race_results( player_name,
						this_save.data.results.event,
						this_save.data.results.cup,
						this_save.data.results.race,
						this_save.data.results.difficulty,
						this_save.data.results.time,
						this_save.data.results.herring,
						this_save.data.results.score );
			print_debug( DEBUG_SAVE,
				     "Read results from `%s': "
				     "name: %s, event: %s, cup: %s, "
				     "race: %s, difficulty: %d, time: %g, "
				     "herring: %d, score: %d",
				     cur_dir_filename, 
				     player_name,
				     this_save.data.results.event,
				     this_save.data.results.cup,
				     this_save.data.results.race,
				     this_save.data.results.difficulty,
				     this_save.data.results.time,
				     this_save.data.results.herring,
				     this_save.data.results.score );
			break;

		    default:
			print_warning( IMPORTANT_WARNING, 
				       "Unrecognized data type in save file." );

		    }
		}


		if ( fclose( save_stream ) != 0 ) {
		    perror( "fclose" );
		}
	    } else {
		print_warning( IMPORTANT_WARNING,
			       "Couldn't read file `%s': %s",
			       file_name, strerror( errno ) );
	    }
	}
    }

    free_dir_file_list( dir_file_list );
}
Example #3
0
/*! 
 Updates the race results based on the results of the race just completed
 Should be called before last_race_completed is updated.
 \author  jfpatry
 \date    Created:  2000-09-24
 \date    Modified: 2000-09-24
 */
static void update_race_results( void )
{
    char *event;
    char *cup;
    bool_t update_score = False;
    char *race_name;
    scalar_t time;
    int herring;
    int score;
	
    if ( g_game.practicing ) {
        open_course_data_t *data;
        data = (open_course_data_t*)get_list_elem_data( cur_elem );
        race_name = data->name;
    } else {
        race_data_t *data;
        data = (race_data_t*)get_list_elem_data( cur_elem );
        race_name = data->name;
    }
    
    event = g_game.current_event;
    cup = g_game.current_cup;
    
    if ( !get_saved_race_results( plyr->name,
                                 event,
                                 cup,
                                 race_name,
                                 g_game.difficulty,
                                 &time,
                                 &herring,
                                 &score ) )
    {
        update_score = True;
    } else if ( !g_game.practicing && !cup_complete ) {
        /* Scores are always overwritten if cup isn't complete */
        update_score = True;
    } else if ( (g_game.is_speed_only_mode && plyr->score < score) || (!g_game.is_speed_only_mode && plyr->score > score) ) {
        update_score = True;
    } else {
        update_score = False;
    }
    
    if ( update_score ) {
		//affiche le message facebook
		char score[BUFF_LEN];
		int minutes, seconds, hundredths;
		get_time_components( g_game.time, &minutes, &seconds, &hundredths );
		if (g_game.is_speed_only_mode) sprintf((char*)score, "%02d:%02d:%02d", minutes, seconds, hundredths );
		else sprintf((char*)score, "%d pts", plyr->score );
		
		char* mode = g_game.is_speed_only_mode?(char*)Localize("Time Trial","src/race_select.c"):(char*)Localize("classic","src/race_select.c");
		//message facebook publié
		//Si cette fonction est executée, elle bloque l'execution de la suivnte grace a une variable statique; voir dans TRFacebookController
		publishFirstScore(score,race_name,mode);
        bool_t result;
        result = 
	    set_saved_race_results( plyr->name,
                               event,
                               cup,
                               race_name,
                               g_game.difficulty,
                               g_game.time,
                               plyr->herring,
                               plyr->score ); 
        if ( !result ) {
            print_warning( IMPORTANT_WARNING,
                          "Couldn't save race results" );
        }
    }
}