void campaign_filelist_box::initialize()
{
	int i, z, num_files;
	char *mission_filenames[2000];
	char mission_filenames_arr[2000][MAX_FILENAME_LEN];
	mission a_mission;

	ResetContent();

	extern int Skip_packfile_search;
	Skip_packfile_search = 1;
	num_files = cf_get_file_list_preallocated(2000, mission_filenames_arr, mission_filenames, CF_TYPE_MISSIONS, "*.fs2");
	Skip_packfile_search = 0;

	i=0;

	while (i < num_files)
	{
		// make a call to get the mission info for this mission.  Passing a misison as the second
		// parameter will prevent The_mission from getting overwritten.
		get_mission_info( mission_filenames[i] , &a_mission );
		strcat(mission_filenames[i],".fs2");

		// only add missions of the appropriate type to the file listbox
		if ( (Campaign.type == CAMPAIGN_TYPE_SINGLE) && (a_mission.game_type & (MISSION_TYPE_SINGLE|MISSION_TYPE_TRAINING)) )
			AddString(mission_filenames[i]);
		else if ( (Campaign.type == CAMPAIGN_TYPE_MULTI_COOP) && (a_mission.game_type & MISSION_TYPE_MULTI_COOP) )
			AddString(mission_filenames[i]);
		else if ( (Campaign.type == CAMPAIGN_TYPE_MULTI_TEAMS) && (a_mission.game_type & MISSION_TYPE_MULTI_TEAMS) )
			AddString(mission_filenames[i]);

		i++;
	} 
	

	for (i=0; i<Campaign.num_missions; i++) {
		z = FindString(-1, Campaign.missions[i].name);
		if (z != LB_ERR) {
			DeleteString(z);  // take out all missions already in the campaign
			i--;  // recheck for name just in case there are two (should be impossible but can't be sure)
		}
	}
	
}
void campaign_editor::update()
{
	char buf[MISSION_DESC_LENGTH];

	// get data from dlog box
	UpdateData(TRUE);

	// update campaign name
	string_copy(Campaign.name, m_name, NAME_LENGTH);
	Campaign.type = m_type;

	// update campaign desc
	deconvert_multiline_string(buf, m_desc, MISSION_DESC_LENGTH);
	if (Campaign.desc) {
		free(Campaign.desc);
	}

	Campaign.desc = NULL;
	if (strlen(buf)) {
		Campaign.desc = strdup(buf);
	}

	// update flags
	Campaign.flags = CF_DEFAULT_VALUE;
	if (m_custom_tech_db)
		Campaign.flags |= CF_CUSTOM_TECH_DATABASE;

	// maybe update mission loop text
	save_loop_desc_window();

	// set the number of players in a multiplayer mission equal to the number of players in the first mission
	if ( Campaign.type != CAMPAIGN_TYPE_SINGLE ) {
		if ( Campaign.num_missions == 0 ) {
			Campaign.num_players = 0;
		} else {
			mission a_mission;

			get_mission_info(Campaign.missions[0].name, &a_mission);
			Campaign.num_players = a_mission.num_players;
		}
	}
}
Exemplo n.º 3
0
void campaign_tree_view::drop_mission(int m, CPoint point)
{
	char name[MAX_FILENAME_LEN + 1];
	int i, item, level, pos;
	cmission *cm;
	mission a_mission;
	CListBox *listbox;

	level = query_level(point);
	pos = query_pos(point);
	Assert((level >= 0) && (pos >= 0));  // this should be impossible

	listbox = (CListBox *) &Campaign_tree_formp->m_filelist;
	item = listbox->GetCurSel();
	if (item == LB_ERR) {
		MessageBox("Select a mission from listbox to add.", "Error");
		return;
	}

	if (listbox->GetTextLen(item) > MAX_FILENAME_LEN) {
		char buf[256];

		sprintf(buf, "Filename is too long.  Must be %d or less characters.", MAX_FILENAME_LEN);
		MessageBox(buf, "Error");
		return;  // filename is too long.  Would overflow our buffer
	}

	// grab the filename selected from the listbox
	listbox->GetText(item, name);

	if (Campaign.num_missions >= MAX_CAMPAIGN_MISSIONS) {  // Can't add any more
		MessageBox("Too many missions.  Can't add more to Campaign.", "Error");
		return;
	}

	if (!level && (get_root_mission() >= 0)) {
		MessageBox("Only 1 mission may be in the top level");
		return;
	}

	// check the number of players in a multiplayer campaign against the number of players
	// in the mission that was just dropped
	if ( Campaign.type != CAMPAIGN_TYPE_SINGLE ) {
		get_mission_info(name, &a_mission);
		if ( !(a_mission.game_type & MISSION_TYPE_MULTI) ) {
			char buf[256];

			sprintf(buf, "Mission \"%s\" is not a multiplayer mission", name);
			MessageBox(buf, "Error");
			return;
		}

		if (Campaign.num_players != 0) {
			if (Campaign.num_players != a_mission.num_players) {
				char buf[512];

				sprintf(buf, "Mission \"%s\" has %d players.  Campaign has %d players.  Campaign will not play properly in FreeSpace", name, a_mission.num_players, Campaign.num_players );
				MessageBox(buf, "Warning");
			}

		} else {
			Campaign.num_players = a_mission.num_players;
		}
	}

	Elements[Campaign.num_missions].from_links = Elements[Campaign.num_missions].to_links = 0;
	cm = &(Campaign.missions[Campaign.num_missions++]);
	cm->name = strdup(name);
	cm->formula = Locked_sexp_true;
	cm->num_goals = -1;
	cm->notes = NULL;
	cm->briefing_cutscene[0] = 0;
	for (i=0; i<Campaign.num_missions - 1; i++)
		if ((Campaign.missions[i].level == level) && (Campaign.missions[i].pos + 1 == pos)) {
			pos = query_alternate_pos(point);
			break;
		}

	cm->level = level;
	cm->pos = pos - 1;
	correct_position(Campaign.num_missions - 1);
	sort_links();
	SetScrollSizes(MM_TEXT, CSize(total_width * CELL_WIDTH, total_levels * LEVEL_HEIGHT));
	Invalidate();

	// update and reinitialize dialog items
	if ( Campaign.type != CAMPAIGN_TYPE_SINGLE ) {
		Campaign_tree_formp->update();
		Campaign_tree_formp->initialize(0);
	}

	listbox->DeleteString(item);
	Campaign_modified = 1;
	return;
}