Ejemplo n.º 1
0
void pilotfile::plr_read_flags()
{
	// tips?
	p->tips = (int)cfread_ubyte(cfp);

	// saved flags
	p->save_flags = cfread_int(cfp);

	// listing mode (single or campaign missions
	p->readyroom_listing_mode = cfread_int(cfp);

	// briefing auto-play
	p->auto_advance = cfread_int(cfp);

	// special rank setting (to avoid having to read all stats on verify)
	// will be the multi rank
	// if there's a valid CSG, this will be overwritten
	p->stats.rank = cfread_int(cfp);

	if (version > 0) 
	{
		p->player_was_multi = cfread_int(cfp);
	} else 
	{
		p->player_was_multi = 0; // Default to single player
	}

	// which language was this pilot created with
	if (version > 1) {
		cfread_string_len(p->language, sizeof(p->language), cfp);
	} else {
		// if we don't know, default to the current language setting
		lcl_get_language_name(p->language);
	}
}
Ejemplo n.º 2
0
void pilotfile::plr_read_info()
{
    if ( !m_have_flags ) {
        throw "Info before Flags!";
    }

    // pilot image
    cfread_string_len(p->image_filename, MAX_FILENAME_LEN, cfp);

    // multi squad name
    cfread_string_len(p->m_squad_name, NAME_LENGTH, cfp);

    // squad image
    cfread_string_len(p->m_squad_filename, MAX_FILENAME_LEN, cfp);

    // active campaign
    cfread_string_len(p->current_campaign, MAX_FILENAME_LEN, cfp);
}
Ejemplo n.º 3
0
void pilotfile_convert::plr_import_red_alert()
{
	int idx, j;
	char name[35];

	if (fver >= 242) {
		return;
	}

	// have to read it, but don't need any of it ...

	int num_slots = cfread_int(cfp);

	if ( (num_slots < 0) || (num_slots >= 32) ) {
		throw "Data check failure in red-alert!";
	}

	if ( !num_slots ) {
		return;
	}

	for (idx = 0; idx < num_slots; idx++) {
		cfread_string(name, sizeof(name) - 1, cfp);
		cfread_float(cfp);

		cfread_string_len(name, sizeof(name), cfp);

		// subsystem hits
		for (j = 0; j < 64; j++) {
			cfread_float(cfp);
		}

		// aggregate hits
		for (j = 0; j < 12; j++) {
			cfread_float(cfp);
		}

		// weapons
		for (j = 0; j < 12; j++) {
			cfread_string_len(name, sizeof(name), cfp);
			cfread_int(cfp);
		}
	}
}
Ejemplo n.º 4
0
void pilotfile::csg_read_cutscenes() {
	size_t list_size = cfread_uint(cfp);

	for(size_t i = 0; i < list_size; i++) {
		char tempFilename[MAX_FILENAME_LEN];

		cfread_string_len(tempFilename, MAX_FILENAME_LEN, cfp);
		cutscene_mark_viewable(tempFilename);
	}
}
Ejemplo n.º 5
0
void pilotfile::csg_read_variables()
{
	int idx;

	Campaign.num_variables = cfread_int(cfp);

	if (Campaign.num_variables > 0) {
		Campaign.variables = (sexp_variable *) vm_malloc( Campaign.num_variables * sizeof(sexp_variable) );
		Verify( Campaign.variables != NULL );

		memset( Campaign.variables, 0, Campaign.num_variables * sizeof(sexp_variable) );

		for (idx = 0; idx < Campaign.num_variables; idx++) {
			Campaign.variables[idx].type = cfread_int(cfp);
			cfread_string_len(Campaign.variables[idx].text, TOKEN_LENGTH, cfp);
			cfread_string_len(Campaign.variables[idx].variable_name, TOKEN_LENGTH, cfp);
		}
	}

	if (csg_ver < 4) { // CSG files before version 4 don't have a Red Alert set of CPVs to load, so just copy the regular set.
		Campaign.redalert_num_variables = Campaign.num_variables;
		Campaign.redalert_variables = (sexp_variable *) vm_malloc( Campaign.redalert_num_variables * sizeof(sexp_variable) );
		Verify( Campaign.redalert_variables != NULL);

		memcpy( Campaign.redalert_variables, Campaign.variables, Campaign.num_variables * sizeof(sexp_variable));
	} else {
		Campaign.redalert_num_variables = cfread_int(cfp);

		if (Campaign.redalert_num_variables > 0) {
			Campaign.redalert_variables = (sexp_variable *) vm_malloc( Campaign.redalert_num_variables * sizeof(sexp_variable) );
			Verify( Campaign.redalert_variables != NULL );

			memset( Campaign.redalert_variables, 0, Campaign.redalert_num_variables * sizeof(sexp_variable) );

			for (idx = 0; idx < Campaign.redalert_num_variables; idx++) {
				Campaign.redalert_variables[idx].type = cfread_int(cfp);
				cfread_string_len(Campaign.redalert_variables[idx].text, TOKEN_LENGTH, cfp);
				cfread_string_len(Campaign.redalert_variables[idx].variable_name, TOKEN_LENGTH, cfp);
			}
		}
	}
}
Ejemplo n.º 6
0
void pilotfile_convert::plr_import_variables()
{
	int idx;
	sexp_variable nvar;

	int num_variables = cfread_int(cfp);

	if ( (num_variables < 0) || (num_variables >= 100) ) {
		throw "Data check failure in variables!";
	}

	plr->variables.reserve(num_variables);

	for (idx = 0; idx < num_variables; idx++) {
		nvar.type = cfread_int(cfp);
		cfread_string_len(nvar.text, sizeof(nvar.text), cfp);
		cfread_string_len(nvar.variable_name, sizeof(nvar.variable_name), cfp);

		plr->variables.push_back( nvar );
	}
}
Ejemplo n.º 7
0
void pilotfile_convert::csg_import_loadout()
{
	char t_string[50] = { '\0' };

	// mission name/status
	cfread_string_len(t_string, sizeof(t_string), cfp);
	csg->loadout.filename = t_string;

	cfread_string_len(t_string, sizeof(t_string), cfp);
	csg->loadout.last_modified = t_string;

	// ship pool
	size_t list_size = csg->ship_list.size();
	csg->loadout.ship_pool.reserve(list_size);

	for (size_t idx = 0; idx < list_size; idx++) {
		int count = cfread_int(cfp);
		csg->loadout.ship_pool.push_back( count );
	}

	// weapon pool
	list_size = csg->weapon_list.size();
	csg->loadout.weapon_pool.reserve(list_size);

	for (size_t idx = 0; idx < list_size; idx++) {
		int count = cfread_int(cfp);
		csg->loadout.weapon_pool.push_back( count );
	}

	// loadout info
	for (size_t idx = 0; idx < MAX_WSS_SLOTS_CONV; idx++) {
		csg->loadout.slot[idx].ship_index = cfread_int(cfp);

		for (size_t j = 0; j < MAX_SHIP_WEAPONS_CONV; j++) {
			csg->loadout.slot[idx].wep[j] = cfread_int(cfp);
			csg->loadout.slot[idx].wep_count[j] = cfread_int(cfp);
		}
	}
}
Ejemplo n.º 8
0
void pilotfile::plr_read_variables()
{
    int list_size = 0;
    int idx;
    sexp_variable n_var;

    list_size = cfread_int(cfp);

    if (list_size <= 0) {
        return;
    }

    p->variables.reserve(list_size);

    for (idx = 0; idx < list_size; idx++) {
        n_var.type = cfread_int(cfp);
        cfread_string_len(n_var.text, TOKEN_LENGTH, cfp);
        cfread_string_len(n_var.variable_name, TOKEN_LENGTH, cfp);

        p->variables.push_back( n_var );
    }
}
Ejemplo n.º 9
0
/*
 * Only used for quick start missions
 */
void pilotfile::csg_read_lastmissions()
{
	int i;

	// restore list of most recently played missions
	Num_recent_missions = cfread_int( cfp );
	Assert(Num_recent_missions <= MAX_RECENT_MISSIONS);
	for ( i = 0; i < Num_recent_missions; i++ ) {
		char *cp;

		cfread_string_len( Recent_missions[i], MAX_FILENAME_LEN, cfp);
		// Remove the extension (safety check: shouldn't exist anyway)
		cp = strchr(Recent_missions[i], '.');
			if (cp)
				*cp = 0;
	}
}
Ejemplo n.º 10
0
void pilotfile_convert::plr_import_stats()
{
	int idx;
	char name[35];

	if (fver >= 242) {
		return;
	}

	// read everything, but we don't need any of it ...

	cfread_int(cfp);	// score
	cfread_int(cfp);	// rank
	cfread_int(cfp);	// assists

	// medals
	for (idx = 0; idx < 18; idx++) {
		cfread_int(cfp);
	}

	// kills per ship
	int count = cfread_int(cfp);

	for (idx = 0; idx < count; idx++) {
		cfread_ushort(cfp);
		cfread_string_len(name, sizeof(name), cfp);
	}

	cfread_int(cfp);	// kill_count
	cfread_int(cfp);	// kill_count_ok

	cfread_uint(cfp);	// p_shots_fired
	cfread_uint(cfp);	// s_shots_fired
	cfread_uint(cfp);	// p_shots_hit
	cfread_uint(cfp);	// s_shots_hit

	cfread_uint(cfp);	// p_bonehead_hits
	cfread_uint(cfp);	// s_bonehead_hits
	cfread_uint(cfp);	// bonehead_kills
}
Ejemplo n.º 11
0
void pilotfile_convert::plr_import_loadout()
{
	int idx, j;
	int s_count, w_count;
	char name[52];

	if (fver >= 242) {
		return;
	}

	// have to read it, but don't need any of it ...

	cfread_string_len(name, sizeof(name), cfp);	// filename
	cfread_string_len(name, sizeof(name), cfp);	// last_modified

	s_count = cfread_int(cfp);	// num ships
	w_count = cfread_int(cfp);	// num weapons

	// ships
	for (idx = 0; idx < s_count; idx++) {
		cfread_int(cfp);	// count
		cfread_string_len(name, sizeof(name), cfp);	// name
	}

	// weapons
	for (idx = 0; idx < w_count; idx++) {
		cfread_int(cfp);	// count
		cfread_string_len(name, sizeof(name), cfp);	// name
	}

	// loadout info
	for (idx = 0; idx < 12; idx++) {
		cfread_int(cfp);	// ship class
		cfread_string_len(name, sizeof(name), cfp);	// ship name

		for (j = 0; j < 12; j++) {
			cfread_int(cfp);	// weapon type
			cfread_int(cfp);	// weapon count
			cfread_string_len(name, sizeof(name), cfp);	// weapon name
		}
	}
}
Ejemplo n.º 12
0
void pilotfile_convert::csg_import_ships_weapons()
{
	index_list_t ilist;
	char name[35];
	int idx;
	int list_size = 0;

	int ship_count = cfread_int(cfp);
	int weap_count = cfread_int(cfp);

	for (idx = 0; idx < ship_count; idx++) {
		ubyte allowed = cfread_ubyte(cfp);
		csg->ships_allowed.push_back( (allowed != 0) );

		cfread_string_len(name, sizeof(name), cfp);

		ilist.name = name;
		ilist.index = ship_info_lookup(name);

		if (ilist.index < 0) {
			std::ostringstream error_msg;
			error_msg << "Data mismatch (ship lookup: " << ilist.name << ")!";
			throw std::runtime_error(error_msg.str().c_str());
		}

		csg->ship_list.push_back( ilist );
	}

	for (idx = 0; idx < weap_count; idx++) {
		ubyte allowed = cfread_ubyte(cfp);
		csg->weapons_allowed.push_back( allowed != 0 );

		cfread_string_len(name, sizeof(name), cfp);

		ilist.name = name;
		ilist.index = weapon_info_lookup(name);

		if (ilist.index < 0) {
			std::ostringstream error_msg;
			error_msg << "Data mismatch (weapon lookup: " << ilist.name << ")!";
			throw std::runtime_error(error_msg.str().c_str());
		}

		csg->weapon_list.push_back( ilist );
	}

	// get last ship flown index
	for (idx = 0; idx < ship_count; idx++) {
		if ( csg->ship_list[idx].name == plr->last_ship_flown ) {
			csg->last_ship_flown_index = idx;
			break;
		}
	}

	if (csg->last_ship_flown_index < 0) {
		std::ostringstream error_msg;
		error_msg << "Data mismatch (player ship: " << csg->last_ship_flown_index << ")!";
		throw std::runtime_error(error_msg.str().c_str());
	}

	// create list of medals (since it's missing from the old files)
	list_size = Num_medals;

	for (idx = 0; idx < list_size; idx++) {
		ilist.name = Medals[idx].name;
		ilist.index = idx;

		csg->medals_list.push_back( ilist );
	}

	// stuff intel list as well (present but burried in old files)
	list_size = Intel_info_size;

	for (idx = 0; idx < list_size; idx++) {
		ilist.name = Intel_info[idx].name;
		ilist.index = idx;

		csg->intel_list.push_back( ilist );
	}
}
Ejemplo n.º 13
0
void pilotfile::plr_read_stats_multi()
{
    int idx, j, list_size = 0;
    index_list_t ilist;
    char t_string[NAME_LENGTH+1];

    // global, all-time stats (used only until campaign stats are loaded)
    multi_stats.score = cfread_int(cfp);
    multi_stats.rank = cfread_int(cfp);
    multi_stats.assists = cfread_int(cfp);
    multi_stats.kill_count = cfread_int(cfp);
    multi_stats.kill_count_ok = cfread_int(cfp);
    multi_stats.bonehead_kills = cfread_int(cfp);

    multi_stats.p_shots_fired = cfread_uint(cfp);
    multi_stats.p_shots_hit = cfread_uint(cfp);
    multi_stats.p_bonehead_hits = cfread_uint(cfp);

    multi_stats.s_shots_fired = cfread_uint(cfp);
    multi_stats.s_shots_hit = cfread_uint(cfp);
    multi_stats.s_bonehead_hits = cfread_uint(cfp);

    multi_stats.flight_time = cfread_uint(cfp);
    multi_stats.missions_flown = cfread_uint(cfp);
    multi_stats.last_flown = (_fs_time_t)cfread_int(cfp);
    multi_stats.last_backup = (_fs_time_t)cfread_int(cfp);

    // ship kills (contains ships across all mods, not just current)
    list_size = cfread_int(cfp);
    multi_stats.ship_kills.reserve(list_size);

    for (idx = 0; idx < list_size; idx++) {
        cfread_string_len(t_string, NAME_LENGTH, cfp);

        ilist.name = t_string;
        ilist.index = ship_info_lookup(t_string);
        ilist.val = cfread_int(cfp);

        multi_stats.ship_kills.push_back(ilist);
    }

    // medals earned (contains medals across all mods, not just current)
    list_size = cfread_int(cfp);
    multi_stats.medals_earned.reserve(list_size);

    for (idx = 0; idx < list_size; idx++) {
        cfread_string_len(t_string, NAME_LENGTH,cfp);

        ilist.name = t_string;
        ilist.index = medals_info_lookup(t_string);
        ilist.val = cfread_int(cfp);

        multi_stats.medals_earned.push_back(ilist);
    }

    // if in multiplayer mode then set these stats as the player stats
    if (Game_mode & GM_MULTIPLAYER) {
        p->stats.score = multi_stats.score;
        p->stats.rank = multi_stats.rank;
        p->stats.assists = multi_stats.assists;
        p->stats.kill_count = multi_stats.kill_count;
        p->stats.kill_count_ok = multi_stats.kill_count_ok;
        p->stats.bonehead_kills = multi_stats.bonehead_kills;

        p->stats.p_shots_fired = multi_stats.p_shots_fired;
        p->stats.p_shots_hit = multi_stats.p_shots_hit;
        p->stats.p_bonehead_hits = multi_stats.p_bonehead_hits;

        p->stats.s_shots_fired = multi_stats.s_shots_fired;
        p->stats.s_shots_hit = multi_stats.s_shots_hit;
        p->stats.s_bonehead_hits = multi_stats.s_bonehead_hits;

        p->stats.flight_time = multi_stats.flight_time;
        p->stats.missions_flown = multi_stats.missions_flown;
        p->stats.last_flown = multi_stats.last_flown;
        p->stats.last_backup = multi_stats.last_backup;

        // ship kills (have to find ones that match content)
        list_size = (int)multi_stats.ship_kills.size();
        for (idx = 0; idx < list_size; idx++) {
            j = multi_stats.ship_kills[idx].index;

            if (j >= 0) {
                p->stats.kills[j] = multi_stats.ship_kills[idx].val;
            }
        }

        // medals earned (have to fine ones that match content)
        list_size = (int)multi_stats.medals_earned.size();
        for (idx = 0; idx < list_size; idx++) {
            j = multi_stats.medals_earned[idx].index;

            if (j >= 0) {
                p->stats.medals[j] = multi_stats.medals_earned[idx].val;
            }
        }
    }
}
Ejemplo n.º 14
0
void pilotfile::csg_read_redalert()
{
	int idx, i, j, list_size = 0;
	int count;
	char t_string[MAX_FILENAME_LEN+NAME_LENGTH+1] = { '\0' };
	float hit;
	wep_t weapons;

	if ( !m_have_info ) {
		throw "RedAlert before Info!";
	}

	list_size = cfread_int(cfp);

	if (list_size <= 0) {
		return;
	}

	cfread_string_len(t_string, MAX_FILENAME_LEN, cfp);

	Red_alert_precursor_mission = t_string;

	for (idx = 0; idx < list_size; idx++) {
		red_alert_ship_status ras;

		cfread_string_len(t_string, NAME_LENGTH, cfp);
		ras.name = t_string;

		ras.hull = cfread_float(cfp);

		// ship class, index into ship_list[]
		i = cfread_int(cfp);
		if ( (i >= (int)ship_list.size()) || (i < RED_ALERT_LOWEST_VALID_SHIP_CLASS) ) {
			mprintf(("CSG => Parse Warning: Invalid value for red alert ship index (%d), emptying slot.\n", i));
			ras.ship_class = RED_ALERT_DESTROYED_SHIP_CLASS;
		} else if ( (i < 0 ) && (i >= RED_ALERT_LOWEST_VALID_SHIP_CLASS) ) {  // ship destroyed/exited
			ras.ship_class = i;
		} else {
			ras.ship_class = ship_list[i].index;
		}

		// subsystem hits
		count = cfread_int(cfp);

		for (j = 0; j < count; j++) {
			hit = cfread_float(cfp);
			ras.subsys_current_hits.push_back( hit );
		}

		// subsystem aggregate hits
		count = cfread_int(cfp);

		for (j = 0; j < count; j++) {
			hit = cfread_float(cfp);
			ras.subsys_aggregate_current_hits.push_back( hit );
		}

		// primary weapon loadout and status
		count = cfread_int(cfp);

		for (j = 0; j < count; j++) {
			i = cfread_int(cfp);
			weapons.index = weapon_list[i].index;
			weapons.count = cfread_int(cfp);

			// triggering this means something is really fubar
			if (weapons.index < 0) {
				continue;
			}

			ras.primary_weapons.push_back( weapons );
		}

		// secondary weapon loadout and status
		count = cfread_int(cfp);

		for (j = 0; j < count; j++) {
			i = cfread_int(cfp);
			weapons.index = weapon_list[i].index;
			weapons.count = cfread_int(cfp);

			// triggering this means something is really fubar
			if (weapons.index < 0) {
				continue;
			}

			ras.secondary_weapons.push_back( weapons );
		}

		// this is quite likely a *bad* thing if it doesn't happen
		if (ras.ship_class >= RED_ALERT_LOWEST_VALID_SHIP_CLASS) {
			Red_alert_wingman_status.push_back( ras );
		}
	}
}
Ejemplo n.º 15
0
void pilotfile::csg_read_loadout()
{
	int j, count, ship_idx = -1, wep_idx = -1;
	size_t idx, list_size = 0;

	if ( !m_have_info ) {
		throw "Loadout before Info!";
	}

	// base info
	cfread_string_len(Player_loadout.filename, MAX_FILENAME_LEN, cfp);
	cfread_string_len(Player_loadout.last_modified, DATE_TIME_LENGTH, cfp);

	// ship pool
	list_size = ship_list.size();
	for (idx = 0; idx < list_size; idx++) {
		count = cfread_int(cfp);

		if (ship_list[idx].index >= 0) {
			Player_loadout.ship_pool[ship_list[idx].index] = count;
		}
	}

	// weapon pool
	list_size = weapon_list.size();
	for (idx = 0; idx < list_size; idx++) {
		count = cfread_int(cfp);

		if (weapon_list[idx].index >= 0) {
			Player_loadout.weapon_pool[weapon_list[idx].index] = count;
		}
	}

	// player ship loadout
	list_size = (uint)cfread_ushort(cfp);
	for (uint i = 0; i < list_size; i++) {
		wss_unit *slot = NULL;

		if (i < MAX_WSS_SLOTS) {
			slot = &Player_loadout.unit_data[i];
		}

		// ship
		ship_idx = cfread_int(cfp);

		if ( (ship_idx >= (int)ship_list.size()) || (ship_idx < -1) ) { // on the casts, assume that ship & weapon lists will never exceed ~2 billion
			mprintf(("CSG => Parse Warning: Invalid value for ship index (%d), emptying slot.\n", ship_idx));
			ship_idx = -1;
		}

		if (slot) {
			if (ship_idx == -1) { // -1 means no ship in this slot
				slot->ship_class = -1;
			} else {
				slot->ship_class = ship_list[ship_idx].index;
			}
		}

		// primary weapons
		count = cfread_int(cfp);

		for (j = 0; j < count; j++) {
			wep_idx = cfread_int(cfp);

			if ( (wep_idx >= (int)weapon_list.size()) || (wep_idx < -1) ) {
				mprintf(("CSG => Parse Warning: Invalid value for primary weapon index (%d), emptying slot.\n", wep_idx));
				wep_idx = -1;
			}


			if ( slot && (j < MAX_SHIP_PRIMARY_BANKS) ) {
				if (wep_idx == -1) { // -1 means no weapon in this slot
					slot->wep[j] = -1;
				} else {
					slot->wep[j] = weapon_list[wep_idx].index;
				}
			}

			int read_idx = cfread_int(cfp);

			if ( slot && (j < MAX_SHIP_PRIMARY_BANKS) ) {
				slot->wep_count[j] = read_idx;
			}
		}

		// secondary weapons
		count = cfread_int(cfp);

		for (j = 0; j < count; j++) {
			wep_idx = cfread_int(cfp);

			if ( (wep_idx >= (int)weapon_list.size()) || (wep_idx < -1) ) {
				mprintf(("CSG => Parse Warning: Invalid value for secondary weapon index (%d), emptying slot.\n", wep_idx));
				wep_idx = -1;
			}

			if ( slot && (j < MAX_SHIP_SECONDARY_BANKS) ) {
				if (wep_idx == -1) { // -1 means no weapon in this slot
					slot->wep[j+MAX_SHIP_PRIMARY_BANKS] = -1;
				} else {
					slot->wep[j+MAX_SHIP_PRIMARY_BANKS] = weapon_list[wep_idx].index;
				}
			}

			int read_idx = cfread_int(cfp);

			if ( slot && (j < MAX_SHIP_SECONDARY_BANKS) ) {
				slot->wep_count[j+MAX_SHIP_PRIMARY_BANKS] = read_idx;
			}
		}
	}	
}
Ejemplo n.º 16
0
void pilotfile::csg_read_info()
{
	char t_string[NAME_LENGTH+1] = { '\0' };
	index_list_t ilist;
	int idx, list_size = 0;
	ubyte allowed = 0;

	if ( !m_have_flags ) {
		throw "Info before Flags!";
	}

	//
	// NOTE: lists may contain missing/invalid entries for current data
	//       this is not necessarily fatal
	//

	// ship list (NOTE: may contain more than MAX_SHIP_CLASSES)
	list_size = cfread_int(cfp);

	for (idx = 0; idx < list_size; idx++) {
		cfread_string_len(t_string, NAME_LENGTH, cfp);

		ilist.name = t_string;
		ilist.index = ship_info_lookup(t_string);

		ship_list.push_back(ilist);
	}

	// weapon list (NOTE: may contain more than MAX_WEAPON_TYPES)
	list_size = cfread_int(cfp);

	for (idx = 0; idx < list_size; idx++) {
		cfread_string_len(t_string, NAME_LENGTH, cfp);

		ilist.name = t_string;
		ilist.index = weapon_info_lookup(t_string);

		weapon_list.push_back(ilist);
	}

	// intel list (NOTE: may contain more than MAX_INTEL_ENTRIES)
	list_size = cfread_int(cfp);

	for (idx = 0; idx < list_size; idx++) {
		cfread_string_len(t_string, NAME_LENGTH, cfp);

		ilist.name = t_string;
		ilist.index = intel_info_lookup(t_string);

		intel_list.push_back(ilist);
	}

	// medals list (NOTE: may contain more than Num_medals)
	list_size = cfread_int(cfp);

	for (idx = 0; idx < list_size; idx++) {
		cfread_string_len(t_string, NAME_LENGTH, cfp);

		ilist.name = t_string;
		ilist.index = medals_info_lookup(t_string);

		medals_list.push_back(ilist);
	}

	// last ship flown (index into ship_list)
	idx = cfread_int(cfp);

	// check the idx is within bounds
	Assertion ((idx < (int)ship_list.size()), "Campaign file contains an incorrect value for the last flown ship class. No data in ship_list for ship number %d.", idx); 
	if (idx >= (int)ship_list.size())
		idx = -1;
	else if (idx != -1)
		p->last_ship_flown_si_index = ship_list[idx].index;
	else
		p->last_ship_flown_si_index = -1;

	// progression state
	Campaign.prev_mission = cfread_int(cfp);
	Campaign.next_mission = cfread_int(cfp);

	// loop state
	Campaign.loop_reentry = cfread_int(cfp);
	Campaign.loop_enabled = cfread_int(cfp);

	// missions completed
	Campaign.num_missions_completed = cfread_int(cfp);

	// allowed ships
	list_size = (int)ship_list.size();
	for (idx = 0; idx < list_size; idx++) {
		allowed = cfread_ubyte(cfp);

		if (allowed) {
			if (ship_list[idx].index >= 0) {
				Campaign.ships_allowed[ship_list[idx].index] = 1;
			} else {
				m_data_invalid = true;
			}
		}
	}

	// allowed weapons
	list_size = (int)weapon_list.size();
	for (idx = 0; idx < list_size; idx++) {
		allowed = cfread_ubyte(cfp);

		if (allowed) {
			if (weapon_list[idx].index >= 0) {
				Campaign.weapons_allowed[weapon_list[idx].index] = 1;
			} else {
				m_data_invalid = true;
			}
		}
	}

	if (csg_ver >= 2) {
		// single/campaign squad name & image
		cfread_string_len(p->s_squad_name, NAME_LENGTH, cfp);
		cfread_string_len(p->s_squad_filename, MAX_FILENAME_LEN, cfp);
	}

	// if anything we need/use was missing then it should be considered fatal
	if (m_data_invalid) {
		throw "Invalid data for CSG!";
	}
}
Ejemplo n.º 17
0
void pilotfile::csg_read_missions()
{
	int i, j, idx, list_size;
	cmission *missionp;

	if ( !m_have_info ) {
		throw "Missions before Info!";
	}

	for (i = 0; i < Campaign.num_missions_completed; i++) {
		idx = cfread_int(cfp);
		missionp = &Campaign.missions[idx];

		missionp->completed = 1;

		// flags
		missionp->flags = cfread_int(cfp);

		// goals
		missionp->num_goals = cfread_int(cfp);

		if (missionp->num_goals > 0) {
			missionp->goals = (mgoal *) vm_malloc( missionp->num_goals * sizeof(mgoal) );
			Verify( missionp->goals != NULL );

			memset( missionp->goals, 0, missionp->num_goals * sizeof(mgoal) );

			for (j = 0; j < missionp->num_goals; j++) {
				cfread_string_len(missionp->goals[j].name, NAME_LENGTH, cfp);
				missionp->goals[j].status = cfread_char(cfp);
			}
		}

		// events
		missionp->num_events = cfread_int(cfp);

		if (missionp->num_events > 0) {
			missionp->events = (mevent *) vm_malloc( missionp->num_events * sizeof(mevent) );
			Verify( missionp->events != NULL );

			memset( missionp->events, 0, missionp->num_events * sizeof(mevent) );

			for (j = 0; j < missionp->num_events; j++) {
				cfread_string_len(missionp->events[j].name, NAME_LENGTH, cfp);
				missionp->events[j].status = cfread_char(cfp);
			}
		}

		// variables
		missionp->num_variables = cfread_int(cfp);

		if (missionp->num_variables > 0) {
			missionp->variables = (sexp_variable *) vm_malloc( missionp->num_variables * sizeof(sexp_variable) );
			Verify( missionp->variables != NULL );

			memset( missionp->variables, 0, missionp->num_variables * sizeof(sexp_variable) );

			for (j = 0; j < missionp->num_variables; j++) {
				missionp->variables[j].type = cfread_int(cfp);
				cfread_string_len(missionp->variables[j].text, TOKEN_LENGTH, cfp);
				cfread_string_len(missionp->variables[j].variable_name, TOKEN_LENGTH, cfp);
			}
		}

		// scoring stats
		missionp->stats.score = cfread_int(cfp);
		missionp->stats.rank = cfread_int(cfp);
		missionp->stats.assists = cfread_int(cfp);
		missionp->stats.kill_count = cfread_int(cfp);
		missionp->stats.kill_count_ok = cfread_int(cfp);
		missionp->stats.bonehead_kills = cfread_int(cfp);

		missionp->stats.p_shots_fired = cfread_uint(cfp);
		missionp->stats.p_shots_hit = cfread_uint(cfp);
		missionp->stats.p_bonehead_hits = cfread_uint(cfp);

		missionp->stats.s_shots_fired = cfread_uint(cfp);
		missionp->stats.s_shots_hit = cfread_uint(cfp);
		missionp->stats.s_bonehead_hits = cfread_uint(cfp);

		// ship kills (scoring)
		list_size = (int)ship_list.size();
		for (j = 0; j < list_size; j++) {
			idx = cfread_int(cfp);

			if (ship_list[j].index >= 0) {
				missionp->stats.kills[ship_list[j].index] = idx;
			}
		}

		// medals (scoring)
		list_size = (int)medals_list.size();
		for (j = 0; j < list_size; j++) {
			idx = cfread_int(cfp);

			if (medals_list[j].index >= 0) {
				missionp->stats.medal_counts[medals_list[j].index] = idx;
			}
		}
	}
}
SCP_string pilot::BinaryFileHandler::readString(const char*) {
	return cfread_string_len(_cfp);
}
Ejemplo n.º 19
0
void pilotfile_convert::csg_import(bool inferno)
{
	Assert( cfp != NULL );

	char name[35];

	unsigned int csg_id = cfread_uint(cfp);

	if (csg_id != 0xbeefcafe) {
		throw std::runtime_error("Invalid file signature!");
	}

	fver = cfread_uint(cfp);

	if (fver != 15) {
		throw std::runtime_error("Unsupported file version!");
	}

	// campaign type (single/multi)
	csg->sig = cfread_int(cfp);

	// trash
	cfread_string_len(name, sizeof(name), cfp);

	csg->prev_mission = cfread_int(cfp);
	csg->next_mission = cfread_int(cfp);
	csg->loop_reentry = cfread_int(cfp);
	csg->loop_enabled = cfread_int(cfp);

	csg_import_ships_weapons();

	csg_import_missions(inferno);

	csg->main_hall = cfread_ubyte(cfp);

	csg_import_red_alert();

	csg_import_techroom();

	csg_import_loadout();

	csg_import_stats();

	csg->cutscenes = cfread_int(cfp);

	// final data checks
	if ( csg->ship_list.size() != csg->ships_allowed.size() ) {
		throw std::runtime_error("Data check failure (ship size)!");
	} else if ( csg->ship_list.size() != csg->ships_techroom.size() ) {
		throw std::runtime_error("Data check failure (ship size)!");
	} else if ( csg->weapon_list.size() != csg->weapons_allowed.size() ) {
		throw std::runtime_error("Data check failure (weapon size)!");
	} else if ( csg->weapon_list.size() != csg->weapons_techroom.size() ) {
		throw std::runtime_error("Data check failure (weapon size)!");
	} else if ( csg->intel_list.size() != csg->intel_techroom.size() ) {
		throw std::runtime_error("Data check failure (intel size)!");
	}


	// and... we're done!
}
Ejemplo n.º 20
0
void pilotfile_convert::csg_import_missions(bool inferno)
{
	cmission_conv_t miss;
	int idx, j;
	int count;
	int list_size = 0, k;
	scoring_conv_t t_score;
	scoring_conv_INF_t t_inf_score;

	Assert( sizeof(scoring_conv_t) == SCORING_SIZE );
	Assert( sizeof(scoring_conv_INF_t) == SCORING_INF_SIZE );

	int ship_list_size = (int)csg->ship_list.size();

	int num_missions = cfread_int(cfp);

	csg->missions.reserve(num_missions);

	for (idx = 0; idx < num_missions; idx++) {
		miss.index = cfread_int(cfp);

		// goals
		count = cfread_int(cfp);

		if (count > 0) {
			mgoal n_goal;

			miss.goals.reserve(count);

			for (j = 0; j < count; j++) {
				memset(&n_goal, 0, sizeof(mgoal));

				cfread_string_len(n_goal.name, sizeof(n_goal.name), cfp);
				n_goal.status = cfread_char(cfp);

				miss.goals.push_back( n_goal );
			}
		}

		// events
		count = cfread_int(cfp);

		if (count > 0) {
			mevent n_event;

			miss.events.reserve(count);

			for (j = 0; j < count; j++) {
				memset(&n_event, 0, sizeof(mevent));

				cfread_string_len(n_event.name, sizeof(n_event.name), cfp);
				n_event.status = cfread_char(cfp);

				miss.events.push_back( n_event );
			}
		}

		// variables
		count = cfread_int(cfp);

		if (count > 0) {
			sexp_variable n_variable;

			miss.variables.reserve(count);

			for (j = 0; j < count; j++) {
				memset(&n_variable, 0, sizeof(sexp_variable));

				n_variable.type = cfread_int(cfp);
				cfread_string_len(n_variable.text, sizeof(n_variable.text), cfp);
				cfread_string_len(n_variable.variable_name, sizeof(n_variable.variable_name), cfp);

				miss.variables.push_back( n_variable );
			}
		}

		// stats
		miss.stats.ship_kills = csg->ship_list;
		miss.stats.medals_earned = csg->medals_list;

		if (inferno) {
			cfread(&t_inf_score, sizeof(scoring_conv_INF_t), 1, cfp);

			for (j = 0; j < ship_list_size; j++) {
				miss.stats.ship_kills[j].val = INTEL_INT(t_inf_score.kills[j]);
			}

			miss.stats.score = INTEL_INT(t_inf_score.score);
			miss.stats.rank = INTEL_INT(t_inf_score.rank);
			miss.stats.assists = INTEL_INT(t_inf_score.assists);
			miss.stats.kill_count = INTEL_INT(t_inf_score.kill_count);
			miss.stats.kill_count_ok = INTEL_INT(t_inf_score.kill_count_ok);
			miss.stats.p_shots_fired = INTEL_INT(t_inf_score.p_shots_fired);
			miss.stats.s_shots_fired = INTEL_INT(t_inf_score.s_shots_fired);
			miss.stats.p_shots_hit = INTEL_INT(t_inf_score.p_shots_hit);
			miss.stats.s_shots_hit = INTEL_INT(t_inf_score.s_shots_hit);
			miss.stats.p_bonehead_hits = INTEL_INT(t_inf_score.p_bonehead_hits);
			miss.stats.s_bonehead_hits = INTEL_INT(t_inf_score.s_bonehead_hits);
			miss.stats.bonehead_kills = INTEL_INT(t_inf_score.bonehead_kills);

			for (j = 0; j < 18; j++) {
				miss.stats.medals_earned[j].val = INTEL_INT(t_inf_score.medals[j]);
			}
		} else {
			cfread(&t_score, sizeof(scoring_conv_t), 1, cfp);

			for (j = 0; j < ship_list_size; j++) {
				miss.stats.ship_kills[j].val = INTEL_INT(t_score.kills[j]);
			}

			miss.stats.score = INTEL_INT(t_score.score);
			miss.stats.rank = INTEL_INT(t_score.rank);
			miss.stats.assists = INTEL_INT(t_score.assists);
			miss.stats.kill_count = INTEL_INT(t_score.kill_count);
			miss.stats.kill_count_ok = INTEL_INT(t_score.kill_count_ok);
			miss.stats.p_shots_fired = INTEL_INT(t_score.p_shots_fired);
			miss.stats.s_shots_fired = INTEL_INT(t_score.s_shots_fired);
			miss.stats.p_shots_hit = INTEL_INT(t_score.p_shots_hit);
			miss.stats.s_shots_hit = INTEL_INT(t_score.s_shots_hit);
			miss.stats.p_bonehead_hits = INTEL_INT(t_score.p_bonehead_hits);
			miss.stats.s_bonehead_hits = INTEL_INT(t_score.s_bonehead_hits);
			miss.stats.bonehead_kills = INTEL_INT(t_score.bonehead_kills);

			for (j = 0; j < 18; j++) {
				miss.stats.medals_earned[j].val = INTEL_INT(t_score.medals[j]);
			}
		}

		// flags
		miss.flags = cfread_int(cfp);


		// now add to list
		csg->missions.push_back( miss );
	}

	// finally, convert old mission variables to proper campaign variables
	for (idx = 0; idx < num_missions; idx++) {
		count = (int)csg->missions[idx].variables.size();

		for (j = 0; j < count; j++) {
			bool add_it = true;

			list_size = (int)csg->variables.size();

			for (k = 0; k < list_size; k++) {
				if ( !stricmp(csg->variables[k].variable_name, csg->missions[idx].variables[j].variable_name) ) {
					csg->variables[k] = csg->missions[idx].variables[j];
					add_it = false;
					break;
				}
			}

			if (add_it) {
				csg->variables.push_back( csg->missions[idx].variables[j] );
			}
		}
	}
}
Ejemplo n.º 21
0
void pilotfile_convert::plr_import()
{
	char name[35];
	int idx;

	unsigned int plr_id = cfread_uint(cfp);

	if (plr_id != 0x46505346) {
		throw "Invalid file signature!";
	}

	fver = cfread_uint(cfp);

	if ( (fver != 142) && (fver != 242) ) {
		throw "Unsupported file version!";
	}

	// multi flag
	plr->is_multi = (int)cfread_ubyte(cfp);

	// rank
	plr->rank = cfread_int(cfp);

	// mainhall, don't need it
	if (fver < 242) {
		cfread_ubyte(cfp);
	}

	plr->tips = cfread_int(cfp);

	if ( (plr->tips < 0) || (plr->tips > 1) ) {
		throw "Data check failure!";
	}

	cfread_string_len(plr->image_filename, sizeof(plr->image_filename), cfp);
	cfread_string_len(plr->squad_name, sizeof(plr->squad_name), cfp);
	cfread_string_len(plr->squad_filename, sizeof(plr->squad_filename), cfp);
	cfread_string_len(plr->current_campaign, sizeof(plr->current_campaign), cfp);
	cfread_string_len(plr->last_ship_flown, sizeof(plr->last_ship_flown), cfp);

	// controls
	plr_import_controls();

	// hud config
	plr_import_hud();

	// cutscenes, don't need it
	if (fver < 242) {
		cfread_int(cfp);
	}

	// volume stuff
	plr->sound_volume = cfread_float(cfp);
	plr->music_volume = cfread_float(cfp);
	plr->voice_volume = cfread_float(cfp);

	// detail settings
	plr_import_detail();

	// recent missions, don't need it
	int num_missions = cfread_int(cfp);

	for (idx = 0; idx < num_missions; idx++) {
		cfread_string_len(name, sizeof(name), cfp);
	}

	// stats, will skip if fver < 242
	plr_import_stats();

	plr->skill_level = cfread_int(cfp);

	if ( (plr->skill_level < 0) || (plr->skill_level > 4) ) {
		throw "Data check failure!";
	}

	// extra joystick stuff
	for (idx = 0; idx < 5; idx++) {
		plr->joy_axis_map_to[idx] = cfread_int(cfp);
		plr->joy_invert_axis[idx] = cfread_int(cfp);
	}

	// flags
	plr->save_flags = cfread_int(cfp);

	// loadout, will skip if fver < 242
	plr_import_loadout();

	// multiplayer
	plr_import_multiplayer();

	// two briefing related values
	plr->readyroom_listing_mode = cfread_int(cfp);
	Briefing_voice_enabled = cfread_int(cfp);

	plr->net_protocol = cfread_int(cfp);

	// protocol must be set to something
	if (plr->net_protocol == NET_NONE) {
		plr->net_protocol = NET_TCP;
	} else if ( (plr->net_protocol < 0) || (plr->net_protocol > NET_VMT) ) {
		throw "Data check failure!";
	}

	// red alert status, will skip if fver < 242 (and should be empty if multi)
	plr_import_red_alert();

	// briefing auto-advance
	plr->auto_advance = cfread_int(cfp);

	if ( (plr->auto_advance < 0) || (plr->auto_advance > 1) ) {
		throw "Data check failure!";
	}

	// some input options
	plr->Use_mouse_to_fly = cfread_int(cfp);
	plr->Mouse_sensitivity = cfread_int(cfp);
	plr->Joy_sensitivity = cfread_int(cfp);
	plr->Dead_zone_size = cfread_int(cfp);

	// variables
	plr_import_variables();


	// and... we're done! :)
}
void pilot::BinaryFileHandler::readString(const char*, char* dest, size_t max_size) {
	cfread_string_len(dest, (int) max_size, _cfp);
}