コード例 #1
0
bool CPlayers::LoadPlayers () {
	if (FileExists (param.config_dir, "players") == false) {
		SetDefaultPlayers ();
		Message ("file 'players' does not exist, set default players");
		return false;
	}

	CSPList list(MAX_PLAYERS);
	if (list.Load (param.config_dir, "players") == false) {
		SetDefaultPlayers ();
		Message ("could not load players list, set default players");
		return false;
	}

	g_game.start_player = 0;
	g_game.start_character = 0;
	plyr.resize(list.Count());
	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		plyr[i].name = SPStrN (line, "name", "unknown");
		plyr[i].funlocked = SPStrN (line, "unlocked");
		plyr[i].avatar = FindAvatar(SPStrN(line, "avatar"));
		plyr[i].ctrl = NULL;
		int active = SPIntN (line, "active", 0);
		int ch = SPIntN(line, "character", 0);
		if (ch > 0) plyr[i].character = ch;
		if (active > 0) {
			g_game.start_player = i;
			if (ch > 0) g_game.start_character = ch;
		}
	}
	if (plyr.empty()) {
		SetDefaultPlayers ();
		Message ("player file doesn't contain a player, set default players");
		return false;
	}
	return true;
}
コード例 #2
0
ファイル: game_ctrl.cpp プロジェクト: RKSimon/extremetuxracer
bool CPlayers::LoadPlayers () {
	CSPList list(MAX_PLAYERS);
	string line;
	int active;

	if (FileExists (param.config_dir, "players") == false) {
		SetDefaultPlayers ();
		Message ("file 'players' does not exist, set default players");
		return false; 
	}

	if (list.Load (param.config_dir, "players") == false) {
		SetDefaultPlayers ();
		Message ("coule not load players list, set default players");
		return false; 
	}

	numPlayers = 0;
	g_game.start_player = 0;
	for (int i=0; i<list.Count(); i++) {
		line = list.Line(i);
		plyr[numPlayers].name = SPStrN (line, "name", "unknown");
		plyr[numPlayers].funlocked = SPStrN (line, "unlocked", "");
		plyr[numPlayers].avatar = SPStrN (line, "avatar", "");
		plyr[numPlayers].texid = SPIntN (AvatarIndex, plyr[numPlayers].avatar, 0);
		active = SPIntN (line, "active", 0);
		if (active > 0) g_game.start_player = numPlayers;
		numPlayers++;
	}
	if (numPlayers < 1) {
		SetDefaultPlayers ();
		Message ("player file doesn't contain a player, set default players");
		return false;
	}
	return true;
}