Exemple #1
0
void CL_ParseMessageIDs (void)
{
	const char* type, *name, *text;

	numMsgIDs = 0;
	OBJZERO(msgIDHash);

	if (cl_msgidPool != nullptr) {
		Mem_FreePool(cl_msgidPool);
	} else {
		cl_msgidPool = Mem_CreatePool("msgids");
	}
	msgIDText = Mem_PoolAllocTypeN(char, MSGIDSIZE, cl_msgidPool);

	Com_Printf("\n----------- parse msgids -----------\n");

	Com_Printf("%i msgid files\n", FS_BuildFileList("ufos/msgid/*.ufo"));
	text = nullptr;

	FS_NextScriptHeader(nullptr, nullptr, nullptr);

	while ((type = FS_NextScriptHeader("ufos/msgid/*.ufo", &name, &text)) != nullptr) {
		if (Q_streq(type, "msgid"))
			CL_ParseMessageID(name, &text);
	}
}
Exemple #2
0
/**
 * @brief Read the data for campaigns
 * @sa SAV_GameLoad
 * @sa CP_ResetCampaignData
 */
void CP_ParseCampaignData (void)
{
	const char *type, *name, *text;
	int i;
	campaign_t *campaign;

	/* pre-stage parsing */
	FS_BuildFileList("ufos/*.ufo");
	FS_NextScriptHeader(NULL, NULL, NULL);
	text = NULL;

	while ((type = FS_NextScriptHeader("ufos/*.ufo", &name, &text)) != NULL)
		CP_ParseScriptFirst(type, name, &text);

	/* fill in IDXs for required research techs */
	RS_RequiredLinksAssign();

	/* stage two parsing */
	FS_NextScriptHeader(NULL, NULL, NULL);
	text = NULL;

	Com_DPrintf(DEBUG_CLIENT, "Second stage parsing started...\n");
	while ((type = FS_NextScriptHeader("ufos/*.ufo", &name, &text)) != NULL)
		CP_ParseScriptSecond(type, name, &text);
	INS_LinkTechnologies();

	for (i = 0; i < cgi->csi->numTeamDefs; i++) {
		const teamDef_t *teamDef = &cgi->csi->teamDef[i];
		if (!CHRSH_IsTeamDefAlien(teamDef))
			continue;

		ccs.teamDefTechs[teamDef->idx] = RS_GetTechByID(teamDef->tech);
		if (ccs.teamDefTechs[teamDef->idx] == NULL)
			cgi->Com_Error(ERR_DROP, "Could not find a tech for teamdef %s", teamDef->id);
	}

	for (i = 0, campaign = ccs.campaigns; i < ccs.numCampaigns; i++, campaign++) {
		/* find the relevant markets */
		campaign->marketDef = INV_GetEquipmentDefinitionByID(campaign->market);
		campaign->asymptoticMarketDef = INV_GetEquipmentDefinitionByID(campaign->asymptoticMarket);
	}

	Com_Printf("Campaign data loaded - size " UFO_SIZE_T " bytes\n", sizeof(ccs));
	Com_Printf("...techs: %i\n", ccs.numTechnologies);
	Com_Printf("...buildings: %i\n", ccs.numBuildingTemplates);
	Com_Printf("...ranks: %i\n", ccs.numRanks);
	Com_Printf("...nations: %i\n", ccs.numNations);
	Com_Printf("...cities: %i\n", ccs.numCities);
	Com_Printf("\n");
}
Exemple #3
0
/**
 * @brief Reloads the ui scripts and reinitializes the ui
 */
static void UI_Restart_f (void)
{
	typedef std::vector<std::string> Names;
	Names names;
	for (int i = 0; i < ui_global.windowStackPos; i++) {
		names.push_back(std::string(ui_global.windowStack[i]->name));
	}

	UI_Shutdown();
	CLMN_Shutdown();
	R_FontShutdown();
	UI_Init();
	R_FontInit();
	Com_Printf("%i ui script files\n", FS_BuildFileList("ufos/ui/*.ufo"));
	FS_NextScriptHeader(nullptr, nullptr, nullptr);
	const char* type, *name, *text;
	text = nullptr;
	while ((type = FS_NextScriptHeader("ufos/*.ufo", &name, &text)) != nullptr) {
		if (Q_streq(type, "font"))
			UI_ParseFont(name, &text);
		else if (Q_streq(type, "menu_model"))
			UI_ParseUIModel(name, &text);
		else if (Q_streq(type, "sprite"))
			UI_ParseSprite(name, &text);
	}
	UI_Reinit();
	FS_NextScriptHeader(nullptr, nullptr, nullptr);
	text = nullptr;
	while ((type = FS_NextScriptHeader("ufos/ui/*.ufo", &name, &text)) != nullptr) {
		if (Q_streq(type, "window"))
			UI_ParseWindow(type, name, &text);
		else if (Q_streq(type, "component"))
			UI_ParseComponent(type, name, &text);
		else if (Q_streq(type, "menu_model"))
			UI_ParseUIModel(name, &text);
		else if (Q_streq(type, "sprite"))
			UI_ParseSprite(name, &text);
		else if (Q_streq(type, "lua"))
			UI_ParseAndLoadLuaScript(name, &text);
	}

	CLMN_Init();

	for (Names::iterator i = names.begin(); i != names.end(); ++i) {
		UI_PushWindow(i->c_str());
	}
}
Exemple #4
0
/**
 * @brief Autocomplete function for exec command
 * @note This function only lists all cfg files - but doesn't perform any
 * autocomplete step when hitting tab after "exec "
 * @sa Cmd_AddParamCompleteFunction
 */
static int Cmd_CompleteExecCommand (const char *partial, const char **match)
{
	const char *filename;
	size_t len;

	FS_BuildFileList("*.cfg");

	len = strlen(partial);
	if (!len) {
		while ((filename = FS_NextFileFromFileList("*.cfg")) != NULL) {
			Com_Printf("%s\n", filename);
		}
	}

	FS_NextFileFromFileList(NULL);
	return 0;
}
Exemple #5
0
/** @todo move it somewhere */
static void TEST_ParseScript (const char* scriptName)
{
	const char* type, *name, *text;
	int nbWrongScripts = 0;

	/* parse ui node script */
	Com_Printf("Load \"%s\": %i script file(s)\n", scriptName, FS_BuildFileList(scriptName));
	FS_NextScriptHeader(nullptr, nullptr, nullptr);
	text = nullptr;
	while ((type = FS_NextScriptHeader(scriptName, &name, &text)) != nullptr) {
		try {
			CL_ParseClientData(type, name, &text);
		} catch (const comDrop_t& e) {
			CU_assertImplementation(CU_FALSE, __LINE__, va("Failed to parse needed scripts for type: %s and id %s", type, name), __FILE__, "", CU_FALSE);
			nbWrongScripts++;
		}
	}
	CU_ASSERT_FATAL(nbWrongScripts == 0);
}
Exemple #6
0
static int S_CompleteSounds (const char *partial, const char **match)
{
    char const* const soundExtensions[] = SAMPLE_TYPES;

    int n = 0;
    for (char const* const* extension = soundExtensions; *extension; ++extension) {
        char pattern[MAX_OSPATH];
        Com_sprintf(pattern, sizeof(pattern), "sound/**.%s", *extension);
        FS_BuildFileList(pattern);
        while (char const* filename = FS_NextFileFromFileList(pattern)) {
            char const* const fileWithPath = filename + 6;
            if (Cmd_GenericCompleteFunction(fileWithPath, partial, match)) {
                Com_Printf("%s\n", fileWithPath);
                ++n;
            }
        }
        FS_NextFileFromFileList(0);
    }
    return n;
}
Exemple #7
0
static void testLoadAllAnimationFiles (void)
{
	const char *pattern = "models/**.anm";
	const char *filename;
	mAliasModel_t mod;

	FS_BuildFileList(pattern);

	OBJZERO(mod);
	/* set a very high value to work around the error check in the loading function */
	mod.num_frames = 100000;

	while ((filename = FS_NextFileFromFileList(pattern)) != NULL) {
		vid_modelPool = Mem_CreatePool("Vid Model Pool");
		Com_Printf("load anim file: %s\n", filename);
		R_ModLoadAnims(&mod, filename);
		Mem_DeletePool(vid_modelPool);
	}

	FS_NextFileFromFileList(NULL);
}
Exemple #8
0
/**
 * @brief Reads the comments from team files
 */
void GAME_TeamSlotComments_f (void)
{
	UI_ExecuteConfunc("teamsaveslotsclear");

	char relSavePath[MAX_OSPATH];
	GAME_GetRelativeSavePath(relSavePath, sizeof(relSavePath));
	char pattern[MAX_OSPATH];
	Q_strncpyz(pattern, relSavePath, sizeof(pattern));
	Q_strcat(pattern, sizeof(pattern), "*.mpt");

	FS_BuildFileList(pattern);
	int i = 0;
	const char* filename;
	while ((filename = FS_NextFileFromFileList(pattern)) != nullptr) {
		ScopedFile f;
		const char* savePath = va("%s/%s", relSavePath, filename);
		FS_OpenFile(savePath, &f, FILE_READ);
		if (!f) {
			Com_Printf("Warning: Could not open '%s'\n", filename);
			continue;
		}
		teamSaveFileHeader_t header;
		const int clen = sizeof(header);
		if (FS_Read(&header, clen, &f) != clen) {
			Com_Printf("Warning: Could not read %i bytes from savefile\n", clen);
			continue;
		}
		if (LittleLong(header.version) != TEAM_SAVE_FILE_VERSION) {
			Com_Printf("Warning: Version mismatch in '%s'\n", filename);
			continue;
		}

		char absSavePath[MAX_OSPATH];
		GAME_GetAbsoluteSavePath(absSavePath, sizeof(absSavePath));
		const bool uploadable = FS_FileExists("%s/%s", absSavePath, filename);
		UI_ExecuteConfunc("teamsaveslotadd %i \"%s\" \"%s\" %i %i", i++, filename, header.name, LittleLong(header.soldiercount), uploadable ? 1 : 0);
	}
	FS_NextFileFromFileList(nullptr);
}
Exemple #9
0
/**
 * @brief Sets the music cvar to a random track
 */
static void M_RandomTrack_f (void)
{
	if (!s_env.initialized || !music.playing)
		return;

	const int musicTrackCount = FS_BuildFileList("music/*.ogg");
	if (musicTrackCount) {
		int randomID = rand() % musicTrackCount;
		Com_DPrintf(DEBUG_SOUND, "M_RandomTrack_f: random track id: %i/%i\n", randomID, musicTrackCount);

		const char* filename;
		while ((filename = FS_NextFileFromFileList("music/*.ogg")) != nullptr) {
			if (!randomID) {
				const char* musicTrack = Com_SkipPath(filename);
				Com_Printf("..playing next music track: '%s'\n", musicTrack);
				Cvar_Set("snd_music", "%s", musicTrack);
			}
			randomID--;
		}
		FS_NextFileFromFileList(nullptr);
	} else {
		Com_DPrintf(DEBUG_SOUND, "M_RandomTrack_f: No music found!\n");
	}
}
Exemple #10
0
static int S_CompleteSounds (const char *partial, const char **match)
{
	const char *filename;
	int matches = 0;
	char *localMatch[MAX_COMPLETE];
	size_t len = strlen(partial);
	const char *soundExtensions[] = SAMPLE_TYPES;
	const char **extension = soundExtensions;
	int returnValue;

	/* check for partial matches */
	while (*extension) {
		char pattern[MAX_OSPATH];
		Com_sprintf(pattern, sizeof(pattern), "sound/**.%s", *extension);
		FS_BuildFileList(pattern);
		while ((filename = FS_NextFileFromFileList(pattern)) != NULL) {
			char fileWithPath[MAX_OSPATH];
			Com_sprintf(fileWithPath, sizeof(fileWithPath), "%s", filename + 6);
			if (!len) {
				Com_Printf("%s\n", fileWithPath);
			} else if (!strncmp(partial, fileWithPath, len)) {
				Com_Printf("%s\n", fileWithPath);
				localMatch[matches++] = strdup(fileWithPath);
				if (matches >= MAX_COMPLETE)
					break;
			}
		}
		FS_NextFileFromFileList(NULL);
		extension++;
	}

	returnValue = Cmd_GenericCompleteFunction(len, match, matches, (const char **)localMatch);
	while (--matches >= 0)
		free(localMatch[matches]);
	return returnValue;
}
Exemple #11
0
TEST_F(RendererTest, CharacterAnimationFiles)
{
	const char* pattern = "models/**.anm";
	const char* filename;
	mAliasModel_t mod;
	const char* bloodspider[] = { "death1", "death2", "death3", "dead1",
			"dead2", "dead3", "stand0", "stand1", "stand2", "stand3", "walk0",
			"walk1", "walk2", "walk3", "cstand0", "cstand1", "cstand2",
			"cstand3", "cwalk0", "cwalk1", "cwalk2", "cwalk3", "stand_menu",
			"panic0", nullptr };
	const char* hovernet[] = { "death1", "dead1", "death2","dead2", "death3",
			"dead3", "stand0", "walk0", "cstand0", "cwalk0", "stand1", "walk1",
			"cstand1", "cwalk1", "stand2", "walk2", "cstand2", "cwalk2",
			"stand3", "walk3", "cstand3", "cwalk3", "move_rifle", "shoot_rifle",
			"cmove_rifle", "cshoot_rifle", "stand_menu", "panic0", nullptr };
	const char* soldiers[] = { "death1", "death2", "death3", "dead1", "dead2",
			"dead3", "stand0", "stand1", "stand2", "stand3", "walk0", "walk1",
			"walk2", "walk3", "cstand0", "cstand1", "cstand2", "cstand3",
			"cwalk0", "cwalk1", "cwalk2", "cwalk3", "stand_menu", "panic0",
			"move_rifle", "shoot_rifle", "cmove_rifle", "cshoot_rifle",
			"move_biggun", "shoot_biggun", "cmove_biggun", "cshoot_biggun",
			"move_melee", "shoot_melee", "cmove_melee", "cshoot_melee",
			"stand_still", "move_pistol", "shoot_pistol", "cmove_pistol",
			"cshoot_pistol", "move_pistol_d", "shoot_pistol_d",
			"cmove_pistol_d", "cshoot_pistol_d", "move_grenade",
			"shoot_grenade", "cmove_grenade", "cshoot_grenade", "move_item",
			"shoot_item", "cmove_item", "cshoot_item", "move_rpg", "shoot_rpg",
			"cmove_rpg", "cshoot_rpg", nullptr };
	const char* civilians[] = { "death1", "dead1", "death2", "dead2", "death3",
			"dead3", "stand0", "walk0", "panic0", "stand1", "stand2",
			"stand_menu", "stand_still", nullptr };

	FS_BuildFileList(pattern);

	vid_modelPool = Mem_CreatePool("Vid Model Pool");

	while ((filename = FS_NextFileFromFileList(pattern)) != nullptr) {
		const char** animList;
		if (Q_strstart(filename, "models/soldiers/"))
			animList = soldiers;
		else if (Q_strstart(filename, "models/civilians/"))
			animList = civilians;
		else if (Q_strstart(filename, "models/aliens/bloodspider"))
			animList = bloodspider;
		else if (Q_strstart(filename, "models/aliens/hovernet"))
			animList = hovernet;
		else if (Q_strstart(filename, "models/aliens/"))
			animList = soldiers;
		else
			animList = nullptr;

		/** @todo remove this hack - but ugvs are just not ready yet */
		if (Q_strstart(filename, "models/soldiers/ugv_"))
			continue;
		/** @todo remove this hack - alientank is just not ready yet */
		if (Q_strstart(filename, "models/aliens/alientank/"))
			continue;

		if (animList != nullptr) {
			OBJZERO(mod);
			/* set a very high value to work around the error check in the loading function */
			mod.num_frames = 100000;

			Com_Printf("load character anim file: %s\n", filename);
			R_ModLoadAnims(&mod, filename);

			while (*animList != nullptr) {
				int i;
				for (i = 0; i < mod.num_anims; i++) {
					const mAliasAnim_t* a = &mod.animdata[i];
					if (Q_streq(a->name, *animList))
						break;
				}
				ASSERT_FALSE(i == mod.num_anims) << "anm file " << filename << " does not contain the needed animation definition " << *animList;

				animList++;
			}
		}
	}

	Mem_DeletePool(vid_modelPool);

	FS_NextFileFromFileList(nullptr);
}