当前位置: 首页>>代码示例>>C++>>正文


C++ CFileHandler::FileExists方法代码示例

本文整理汇总了C++中CFileHandler::FileExists方法的典型用法代码示例。如果您正苦于以下问题:C++ CFileHandler::FileExists方法的具体用法?C++ CFileHandler::FileExists怎么用?C++ CFileHandler::FileExists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CFileHandler的用法示例。


在下文中一共展示了CFileHandler::FileExists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BuildFromFileNames

bool CMouseCursor::BuildFromFileNames(const string& name, int lastFrame)
{
	// find the image file type to use
	const char* ext = "";
	const char* exts[] = { "png", "tga", "bmp" };
	const int extCount = sizeof(exts) / sizeof(exts[0]);
	for (int e = 0; e < extCount; e++) {
		ext = exts[e];
		std::ostringstream namebuf;
		namebuf << "anims/" << name << "_0." << ext;
		CFileHandler* f = new CFileHandler(namebuf.str());
		if (f->FileExists()) {
			delete f;
			break;
		}
		delete f;
	}

	while (int(frames.size()) < lastFrame) {
		std::ostringstream namebuf;
		namebuf << "anims/" << name << "_" << frames.size() << "." << ext;
		ImageData image;
		if (!LoadCursorImage(namebuf.str(), image))
			break;
		images.push_back(image);
		FrameData frame(image, defFrameLength);
		frames.push_back(frame);
	}

	hwCursor->Finish();

	return true;
}
开发者ID:DoctorEmmettBrown,项目名称:spring,代码行数:33,代码来源:MouseCursor.cpp

示例2: SelectMap

/** Called by the map-selecting CglList. */
void CPreGame::SelectMap(std::string s)
{
    if (s == "Random map") {
        s = pregame->showList->items[1 + gu->usRandInt() % (pregame->showList->items.size() - 1)];
    }
    stupidGlobalMapname = pregame->mapName = s;
    delete pregame->showList;
    pregame->showList = 0;
    logOutput << "Map: " << s.c_str() << "\n";

    // Determine if the map is inside an archive, and possibly map needed archives
    CFileHandler* f = SAFE_NEW CFileHandler("maps/" + s);
    if (!f->FileExists()) {
        vector<string> ars = archiveScanner->GetArchivesForMap(s);
        if (ars.empty())
            throw content_error("Couldn't find any archives for map '" + s + "'.");
        for (vector<string>::iterator i = ars.begin(); i != ars.end(); ++i) {
            if (!hpiHandler->AddArchive(*i, false))
                throw content_error("Couldn't load archive '" + *i + "' for map '" + s + "'.");
        }
    }
    delete f;

    if (net && net->GetDemoRecorder())
        net->GetDemoRecorder()->SetName(s);
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:27,代码来源:PreGame.cpp

示例3: GetFileSize

int CAICallback::GetFileSize (const char *name)
{
	CFileHandler fh (name);

	if (!fh.FileExists ())
		return -1;

	return fh.FileSize();
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:9,代码来源:AICallback.cpp

示例4: GetFileSize

int CAICallback::GetFileSize (const char *filename, const char* modes)
{
	CFileHandler fh (filename, modes);

	if (!fh.FileExists ())
		return -1;

	return fh.FileSize();
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:9,代码来源:AICallback.cpp

示例5: ReadFile

bool CAICallback::ReadFile (const char *name, void *buffer, int bufferLength)
{
	CFileHandler fh (name);
	int fs;
	if (!fh.FileExists() || bufferLength < (fs = fh.FileSize()))
		return false;

	fh.Read (buffer, fs);
	return true;
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:10,代码来源:AICallback.cpp

示例6: OpenFile

int CArchiveDir::OpenFile(const std::string& fileName)
{
	CFileHandler* f = SAFE_NEW CFileHandler(archiveName + lcNameToOrigName[StringToLower(fileName)]);

	if (!f || !f->FileExists())
		return 0;

	++curFileHandle;
	fileHandles[curFileHandle] = f;
	return curFileHandle;
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:11,代码来源:ArchiveDir.cpp

示例7: LoadCursorImage

bool CMouseCursor::LoadCursorImage(const string& name, ImageData& image)
{
	CFileHandler* f = new CFileHandler(name);
	if (!f->FileExists()) {
		return false;
	}

	CBitmap b;
	if (!b.Load(name)) {
		logOutput.Print("CMouseCursor: Bad image file: %s", name.c_str());
		return false;
	}

	b.ReverseYAxis();

	CBitmap* final = getAlignedBitmap(b);
	
	// coded bmp transparency mask
	if ((name.size() >= 3) &&
	    (StringToLower(name.substr(name.size() - 3)) == "bmp")) {
		setBitmapTransparency(*final, 84, 84, 252);
	}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:22,代码来源:MouseCursor.cpp

示例8: LoadMap

void CPreGame::LoadMap(const std::string& mapName, const bool forceReload)
{
	static bool alreadyLoaded = false;

	if (!alreadyLoaded || forceReload)
	{
		CFileHandler* f = new CFileHandler("maps/" + mapName);
		if (!f->FileExists()) {
			vector<string> ars = archiveScanner->GetArchivesForMap(mapName);
			if (ars.empty()) {
				throw content_error("Couldn't find any archives for map '" + mapName + "'.");
			}
			for (vector<string>::iterator i = ars.begin(); i != ars.end(); ++i) {
				if (!vfsHandler->AddArchive(*i, false)) {
					throw content_error("Couldn't load archive '" + *i + "' for map '" + mapName + "'.");
				}
			}
		}
		delete f;
		alreadyLoaded = true;
	}
}
开发者ID:Dmytry,项目名称:spring,代码行数:22,代码来源:PreGame.cpp

示例9: BuildFromFileNames

bool CMouseCursor::BuildFromFileNames(const string& name, int lastFrame)
{
	char namebuf[128];
	if (name.size() > (sizeof(namebuf) - 20)) {
		logOutput.Print("CMouseCursor: Long name %s", name.c_str());
		return false;
	}
	
	// find the image file type to use
	const char* ext = "";
	const char* exts[] = { "png", "tga", "bmp" };
	const int extCount = sizeof(exts) / sizeof(exts[0]);
	for (int e = 0; e < extCount; e++) {
		ext = exts[e];
		SNPRINTF(namebuf, sizeof(namebuf), "anims/%s_%d.%s",
		         name.c_str(), 0, ext);
		CFileHandler* f = new CFileHandler(namebuf);
		if (f->FileExists()) {
			delete f;
			break;
		}
		delete f;
	}

	while (frames.size() < lastFrame) {
		SNPRINTF(namebuf, sizeof(namebuf), "anims/%s_%d.%s",
		         name.c_str(), frames.size(), ext);
		ImageData image;
		if (!LoadCursorImage(namebuf, image)) {
			break;
		}
		images.push_back(image);
		FrameData frame(image, defFrameLength);
		frames.push_back(frame);
	}

	return true;	
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:38,代码来源:MouseCursor.cpp

示例10: Update

bool CPreGame::Update(void)
{
	if(waitOnAddress && !userWriting){
		waitOnAddress=false;
		if (saveAddress)
			configHandler.SetString("address",userInput);
		if(net->InitClient(userInput.c_str(),8452,0)==-1){
			info->AddLine("Client couldnt connect");
			return false;
		}
		userWriting=false;
	}

	if(!server && !waitOnAddress){
		net->Update();
		UpdateClientNet();
	}

	if(waitOnScript && !showList){
		waitOnScript=false;

		mapName=CScriptHandler::Instance().chosenScript->GetMapName();

		if(mapName==""){
			ShowMapList();
			waitOnMap=true;
		} else {
			allReady=true;
		}
	}

	if(allReady){
		ENTER_MIXED;

		// Map all required archives depending on selected mod(s)
		stupidGlobalModName = MOD_FILE;
		if (gameSetup)
			stupidGlobalModName = gameSetup->baseMod;
		vector<string> ars = archiveScanner->GetArchives(stupidGlobalModName);
		for (vector<string>::iterator i = ars.begin(); i != ars.end(); ++i) {
			hpiHandler->AddArchive(*i, false);
		}

		// Determine if the map is inside an archive, and possibly map needed archives
		CFileHandler* f = new CFileHandler("maps/" + mapName);
		if (!f->FileExists()) {
			vector<string> ars = archiveScanner->GetArchivesForMap(mapName);
			for (vector<string>::iterator i = ars.begin(); i != ars.end(); ++i) {
				hpiHandler->AddArchive(*i, false);
			}
		}
		delete f;

		LoadStartPicture();

		game=new CGame(server,mapName);
		ENTER_UNSYNCED;
		game->Update();
		pregame=0;
		delete this;
		return true;
	}
	return true;
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:64,代码来源:PreGame.cpp

示例11: Init

bool CGameSetup::Init(char* buf, int size)
{
	for(int a=0;a<MAX_PLAYERS;a++){
		gs->players[a]->team=0;					//needed in case one tries to spec a game with only one team
	}

	gameSetupText=SAFE_NEW char[size];
	memcpy(gameSetupText,buf,size);
	gameSetupTextLength=size;

	file.LoadBuffer(buf,size);

	if(!file.SectionExist("GAME"))
		return false;

	mapname=file.SGetValueDef("","GAME\\mapname");
	scriptName=file.SGetValueDef("Commanders","GAME\\scriptname");
	baseMod=archiveScanner->ModArchiveToModName(file.SGetValueDef(MOD_FILE,"GAME\\Gametype"));
	file.GetDef(hostip,"0","GAME\\HostIP");
	file.GetDef(hostport,"0","GAME\\HostPort");
	file.GetDef(maxUnits,"500","GAME\\MaxUnits");
	file.GetDef(gs->gameMode,"0","GAME\\GameMode");
	file.GetDef(sourceport,"0","GAME\\SourcePort");
	file.GetDef(limitDgun,"0","GAME\\LimitDgun");
	file.GetDef(diminishingMMs,"0","GAME\\DiminishingMMs");
	file.GetDef(disableMapDamage,"0","GAME\\DisableMapDamage");
	demoName=file.SGetValueDef("","GAME\\Demofile");
	if(!demoName.empty())
		hostDemo=true;
	file.GetDef(ghostedBuildings,"1","GAME\\GhostedBuildings");

	file.GetDef(maxSpeed, "3", "GAME\\MaxSpeed");
	file.GetDef(minSpeed, "0.3", "GAME\\MinSpeed");

	// Determine if the map is inside an archive, and possibly map needed archives
	CFileHandler* f = SAFE_NEW CFileHandler("maps/" + mapname);
	if (!f->FileExists()) {
		vector<string> ars = archiveScanner->GetArchivesForMap(mapname);
		for (vector<string>::iterator i = ars.begin(); i != ars.end(); ++i) {
			if (!hpiHandler->AddArchive(*i, false))
				logOutput.Print("Warning: Couldn't load archive '%s'.", i->c_str());
		}
	}
	delete f;

	file.GetDef(myPlayer,"0","GAME\\MyPlayerNum");
	gu->myPlayerNum=myPlayer;
	file.GetDef(numPlayers,"2","GAME\\NumPlayers");
	file.GetDef(gs->activeTeams,"2","GAME\\NumTeams");
	file.GetDef(gs->activeAllyTeams,"2","GAME\\NumAllyTeams");

	file.GetDef(startPosType,"0","GAME\\StartPosType");
	if(startPosType==2){
		for(int a=0;a<gs->activeTeams;++a)
			readyTeams[a]=false;
		for(int a=0;a<gs->activeTeams;++a)
			teamStartNum[a]=a;
		SAFE_NEW CStartPosSelecter();
	} else {
		for(int a=0;a<gs->activeTeams;++a)
			readyTeams[a]=true;
		if(startPosType==0){		//in order
			for(int a=0;a<gs->activeTeams;++a)
				teamStartNum[a]=a;
		} else {								//random order
			std::multimap<int,int> startNums;
			for(int a=0;a<gs->activeTeams;++a)
				startNums.insert(pair<int,int>(gu->usRandInt(),a));	//server syncs these later
			int b=0;
			for(std::multimap<int,int>::iterator si=startNums.begin();si!=startNums.end();++si){
				teamStartNum[si->second]=b;
				++b;
			}
		}
	}
	for(int a=0;a<numPlayers;++a){
		char section[50];
		sprintf(section,"GAME\\PLAYER%i\\",a);
		string s(section);

		gs->players[a]->team=atoi(file.SGetValueDef("0",s+"team").c_str());
		gs->players[a]->spectator=!!atoi(file.SGetValueDef("0",s+"spectator").c_str());
		gs->players[a]->playerName=file.SGetValueDef("0",s+"name");

		int fromDemo;
		file.GetDef(fromDemo,"0",s+"IsFromDemo");
		if(fromDemo)
			numDemoPlayers++;
	}
	gu->spectating = gs->players[myPlayer]->spectator;
	gu->spectatingFullView = gu->spectating;

	TdfParser p2;
	CReadMap::OpenTDF (mapname, p2);

	for(int a=0;a<gs->activeTeams;++a){
		char section[50];
		sprintf(section,"GAME\\TEAM%i\\",a);
		string s(section);

//.........这里部分代码省略.........
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,代码来源:GameSetup.cpp

示例12: Update

bool CPreGame::Update()
{
	assert(good_fpu_control_registers("CPreGame::Update"));

	switch (state) {

		case UNKNOWN:
			logOutput.Print("Internal error in CPreGame");
			return false;

		case WAIT_ON_ADDRESS:
			if (userWriting)
				break;

			if (saveAddress)
				configHandler.SetString("address",userInput);
			if(net->InitClient(userInput.c_str(),8452,0)==-1){
				logOutput.Print("Client couldn't connect");
				return false;
			}

			// State is never WAIT_ON_ADDRESS if gameSetup was true in our constructor,
			// so if it's true here, it means net->InitClient() just loaded a demo
			// with gameSetup.
			// If so, don't wait indefinitely on a script/map/mod name, but load
			// everything from gameSetup and switch to ALL_READY state.
			if(gameSetup) {
				CScriptHandler::SelectScript("Commanders");
				SelectMap(gameSetup->mapname);
				SelectMod(gameSetup->baseMod);
				state = ALL_READY;
				break;
			} else {
				state = WAIT_ON_SCRIPT;
				// fall trough
			}

		case WAIT_ON_SCRIPT:
			if (showList || !server)
				break;

			mapName = CScriptHandler::Instance().chosenScript->GetMapName();
			if (mapName == "")
				ShowMapList();
			state = WAIT_ON_MAP;
			// fall through

		case WAIT_ON_MAP:
			if (showList || !server)
				break;

			modName = CScriptHandler::Instance().chosenScript->GetModName();
			if (modName == "")
				ShowModList();
			state = WAIT_ON_MOD;
			// fall through

		case WAIT_ON_MOD:
			if (showList || !server)
				break;

			state = ALL_READY;
			// fall through

		case ALL_READY:
			ENTER_MIXED;

			// Map all required archives depending on selected mod(s)
			vector<string> ars = archiveScanner->GetArchives(modName);
			if (ars.empty())
				logOutput.Print("Warning: mod archive \"%s\" is missing?\n", modName.c_str());
			for (vector<string>::iterator i = ars.begin(); i != ars.end(); ++i)
				if (!hpiHandler->AddArchive(*i, false))
					logOutput.Print("Warning: Couldn't load archive '%s'.", i->c_str());

			// Determine if the map is inside an archive, and possibly map needed archives
			CFileHandler* f = SAFE_NEW CFileHandler("maps/" + mapName);
			if (!f->FileExists()) {
				vector<string> ars = archiveScanner->GetArchivesForMap(mapName);
				if (ars.empty())
					logOutput.Print("Warning: map archive \"%s\" is missing?\n", mapName.c_str());
				for (vector<string>::iterator i = ars.begin(); i != ars.end(); ++i) {
					if (!hpiHandler->AddArchive(*i, false))
						logOutput.Print("Warning: Couldn't load archive '%s'.", i->c_str());
				}
			}
			delete f;

			// always load springcontent.sdz
			hpiHandler->AddArchive("base/springcontent.sdz", false);

			LoadStartPicture();

			game = SAFE_NEW CGame(server, mapName, modName, infoConsole);

			infoConsole = 0;

			ENTER_UNSYNCED;
			pregame=0;
			delete this;
//.........这里部分代码省略.........
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,代码来源:PreGame.cpp

示例13: main

int main(int argc, char *argv[])
{
#ifdef _WIN32
	try {
#endif
	std::cout << "If you find any errors, report them to mantis or the forums." << std::endl << std::endl;
	ConfigHandler::Instantiate("");
	FileSystemHandler::Cleanup();
	FileSystemHandler::Initialize(false);
	CGameServer* server = 0;
	CGameSetup* gameSetup = 0;

	if (argc > 1)
	{
		const std::string script(argv[1]);
		std::cout << "Loading script from file: " << script << std::endl;

		ClientSetup settings;
		CFileHandler fh(argv[1]);
		if (!fh.FileExists())
			throw content_error("Setupscript doesn't exists in given location: "+script);

		std::string buf;
		if (!fh.LoadStringData(buf))
			throw content_error("Setupscript cannot be read: "+script);
		settings.Init(buf);

		gameSetup = new CGameSetup();	// to store the gamedata inside
		if (!gameSetup->Init(buf))	// read the script provided by cmdline
		{
			std::cout << "Failed to load script" << std::endl;
			return 1;
		}

		std::cout << "Starting server..." << std::endl;
		// Create the server, it will run in a separate thread
		GameData* data = new GameData();
		UnsyncedRNG rng;
		rng.Seed(gameSetup->gameSetupText.length());
		rng.Seed(script.length());
		data->SetRandomSeed(rng.RandInt());

		//  Use script provided hashes if they exist
		if (gameSetup->mapHash != 0)
		{
			data->SetMapChecksum(gameSetup->mapHash);
			gameSetup->LoadStartPositions(false); // reduced mode
		}
		else
		{
			data->SetMapChecksum(archiveScanner->GetMapChecksum(gameSetup->mapName));

			CFileHandler* f = new CFileHandler("maps/" + gameSetup->mapName);
			if (!f->FileExists()) {
				std::vector<std::string> ars = archiveScanner->GetArchivesForMap(gameSetup->mapName);
				if (ars.empty()) {
					throw content_error("Couldn't find any archives for map '" + gameSetup->mapName + "'.");
				}
				for (std::vector<std::string>::iterator i = ars.begin(); i != ars.end(); ++i) {
					if (!vfsHandler->AddArchive(*i, false)) {
						throw content_error("Couldn't load archive '" + *i + "' for map '" + gameSetup->mapName + "'.");
					}
				}
			}
			delete f;
			gameSetup->LoadStartPositions(); // full mode
		}

		if (gameSetup->modHash != 0) {
			data->SetModChecksum(gameSetup->modHash);
		} else {
			const std::string modArchive = archiveScanner->ModNameToModArchive(gameSetup->modName);
			data->SetModChecksum(archiveScanner->GetModChecksum(modArchive));
		}

		data->SetSetup(gameSetup->gameSetupText);
		server = new CGameServer(&settings, false, data, gameSetup);

		while (!server->HasFinished()) // check if still running
#ifdef _WIN32
			Sleep(1000);
#else
			sleep(1);	// if so, wait 1  second
#endif
		delete server;	// delete the server after usage
	}
	else
	{
		std::cout << "usage: spring-dedicated <full_path_to_script>" << std::endl;
	}

	FileSystemHandler::Cleanup();

#ifdef _WIN32
	}
	catch (const std::exception& err)
	{
		std::cout << "Exception raised: " << err.what() << std::endl;
		return 1;
	}
//.........这里部分代码省略.........
开发者ID:javaphoon,项目名称:spring,代码行数:101,代码来源:main.cpp

示例14: runtime_error

CglFont::CglFont(const std::string& fontfile, int size, int _outlinewidth, float _outlineweight):
	fontSize(size),
	fontPath(fontfile),
	outlineWidth(_outlinewidth),
	outlineWeight(_outlineweight),
	inBeginEnd(false)
{
	if (size<=0)
		size = 14;

	const float invSize = 1.0f / size;
	const float normScale = invSize / 64.0f;

	FT_Library library;
	FT_Face face;

	//! initialize Freetype2 library
	FT_Error error = FT_Init_FreeType(&library);
	if (error) {
		string msg = "FT_Init_FreeType failed:";
		msg += GetFTError(error);
		throw std::runtime_error(msg);
	}

	//! load font via VFS
	CFileHandler* f = new CFileHandler(fontPath);
	if (!f->FileExists()) {
		//! check in 'fonts/', too
		if (fontPath.substr(0, 6) != "fonts/") {
			delete f;
			fontPath = "fonts/" + fontPath;
			f = new CFileHandler(fontPath);
		}

		if (!f->FileExists()) {
			delete f;
			FT_Done_FreeType(library);
			throw content_error("Couldn't find font '" + fontfile + "'.");
		}
	}
	int filesize = f->FileSize();
	FT_Byte* buf = new FT_Byte[filesize];
	f->Read(buf,filesize);
	delete f;

	//! create face
	error = FT_New_Memory_Face(library, buf, filesize, 0, &face);
	if (error) {
		FT_Done_FreeType(library);
		delete[] buf;
		string msg = fontfile + ": FT_New_Face failed: ";
		msg += GetFTError(error);
		throw content_error(msg);
	}

	//! set render size
	error = FT_Set_Pixel_Sizes(face, 0, size);
	if (error) {
		FT_Done_Face(face);
		FT_Done_FreeType(library);
		delete[] buf;
		string msg = fontfile + ": FT_Set_Pixel_Sizes failed: ";
		msg += GetFTError(error);
		throw content_error(msg);
	}

	//! setup character range
	charstart = 32;
	charend   = 254; //! char 255 = colorcode
	chars     = (charend - charstart) + 1;

	//! get font information
	fontFamily = face->family_name;
	fontStyle  = face->style_name;

	//! font's descender & height (in pixels)
	fontDescender = normScale * FT_MulFix(face->descender, face->size->metrics.y_scale);
	//lineHeight    = invSize * (FT_MulFix(face->height, face->size->metrics.y_scale) / 64.0f);
	//lineHeight    = invSize * math::ceil(FT_MulFix(face->height, face->size->metrics.y_scale) / 64.0f);
	lineHeight = face->height / face->units_per_EM;
	//lineHeight = invSize * face->size->metrics.height / 64.0f;

	if (lineHeight<=0.0f) {
		lineHeight = 1.25 * invSize * (face->bbox.yMax - face->bbox.yMin);
	}

	//! used to create the glyph textureatlas
	CFontTextureRenderer texRenderer(outlineWidth, outlineWeight);

	for (unsigned int i = charstart; i <= charend; i++) {
		GlyphInfo* g = &glyphs[i];

		//! translate WinLatin (codepage-1252) to Unicode (used by freetype)
		int unicode = WinLatinToUnicode(i);

		//! convert to an anti-aliased bitmap
		error = FT_Load_Char(face, unicode, FT_LOAD_RENDER);
		if ( error ) {
			continue;
		}
//.........这里部分代码省略.........
开发者ID:tranchis,项目名称:spring,代码行数:101,代码来源:glFont.cpp

示例15: Init

bool CGameSetup::Init(char* buf, int size)
{
	for(int a=0;a<gs->activePlayers;a++){
		gs->players[a]->team=0;					//needed in case one tries to spec a game with only one team
	}
	palette.Init();

	gameSetupText=new char[size];
	memcpy(gameSetupText,buf,size);
	gameSetupTextLength=size;

	file=new CSunParser;
	file->LoadBuffer(buf,size);

	if(!file->SectionExist("GAME"))
		return false;

	mapname=file->SGetValueDef("","GAME\\mapname");
	baseMod=file->SGetValueDef("xta_se_060.sdz","GAME\\Gametype");
	file->GetDef(hostip,"0","GAME\\HostIP");
	file->GetDef(hostport,"0","GAME\\HostPort");
	file->GetDef(maxUnits,"500","GAME\\MaxUnits");
	file->GetDef(gs->gameMode,"0","GAME\\GameMode");
	file->GetDef(sourceport,"0","GAME\\SourcePort");
	file->GetDef(limitDgun,"0","GAME\\LimitDgun");
	file->GetDef(diminishingMMs,"0","GAME\\DiminishingMMs");
	demoName=file->SGetValueDef("","GAME\\Demofile");

	// Determine if the map is inside an archive, and possibly map needed archives
	CFileHandler* f = new CFileHandler("maps\\" + mapname);
	if (!f->FileExists()) {
		vector<string> ars = archiveScanner->GetArchivesForMap(mapname);
		for (vector<string>::iterator i = ars.begin(); i != ars.end(); ++i) {
			hpiHandler->AddArchive(*i, false);
		}
	}
	delete f;

	file->GetDef(myPlayer,"0","GAME\\MyPlayerNum");
	gu->myPlayerNum=myPlayer;
	file->GetDef(numPlayers,"2","GAME\\NumPlayers");
	gs->activePlayers=numPlayers;
	file->GetDef(gs->activeTeams,"2","GAME\\NumTeams");
	file->GetDef(gs->activeAllyTeams,"2","GAME\\NumAllyTeams");

	file->GetDef(startPosType,"0","GAME\\StartPosType");
	if(startPosType==2){
		for(int a=0;a<gs->activeTeams;++a)
			readyTeams[a]=false;
		for(int a=0;a<gs->activeTeams;++a)
			teamStartNum[a]=a;
		new CStartPosSelecter();
	} else {
		for(int a=0;a<gs->activeTeams;++a)
			readyTeams[a]=true;
		if(startPosType==0){		//in order
			for(int a=0;a<gs->activeTeams;++a)
				teamStartNum[a]=a;
		} else {								//random order
			std::multimap<int,int> startNums;
			for(int a=0;a<gs->activeTeams;++a)
				startNums.insert(pair<int,int>(gu->usRandInt(),a));	//server syncs these later
			int b=0;
			for(std::multimap<int,int>::iterator si=startNums.begin();si!=startNums.end();++si){
				teamStartNum[si->second]=b;
				++b;
			}
		}
	}
	for(int a=0;a<numPlayers;++a){
		char section[50];
		sprintf(section,"GAME\\PLAYER%i\\",a);
		string s(section);

		gs->players[a]->team=atoi(file->SGetValueDef("0",s+"team").c_str());
		gs->players[a]->spectator=!!atoi(file->SGetValueDef("0",s+"spectator").c_str());
		gs->players[a]->playerName=file->SGetValueDef("0",s+"name");

		int fromDemo;
		file->GetDef(fromDemo,"0",s+"IsFromDemo");
		if(fromDemo)
			numDemoPlayers++;
	}
	if(!demoName.empty() && myPlayer==numDemoPlayers){
		hostDemo=true;
	}

	gu->spectating=gs->players[myPlayer]->spectator;

	CSunParser p2;
	p2.LoadFile(string("maps\\")+mapname.substr(0,mapname.find_last_of('.'))+".smd");

	for(int a=0;a<gs->activeTeams;++a){
		char section[50];
		sprintf(section,"GAME\\TEAM%i\\",a);
		string s(section);

		gs->teams[a]->colorNum=atoi(file->SGetValueDef("0",s+"color").c_str());
		for(int b=0;b<4;++b)
			gs->teams[a]->color[b]=palette.teamColor[gs->teams[a]->colorNum][b];
//.........这里部分代码省略.........
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:101,代码来源:GameSetup.cpp


注:本文中的CFileHandler::FileExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。