Example #1
0
bool CEvents::LoadEventList () {
	CSPList list(256);
	int i, ii, type;
	string line, item, race, cup;
	int num;

	if (!list.Load (param.common_course_dir, "events.lst")) {
		Message ("could not load events.lst");
		return false;
	}

	// pass 1: races
	for (i=0; i<list.Count(); i++) {
		line = list.Line (i);
		type = SPIntN (line, "struct", -1);
		if (type == 0) {
			if (numRaces < MAX_RACES2) {
				RaceList[numRaces].race = SPStrN (line, "race", "error");
				item = SPStrN (line, "course", "");
				RaceList[numRaces].course = Course.GetCourseIdx (item);
				item = SPStrN (line, "light", "");
				RaceList[numRaces].light = Env.GetLightIdx (item);
				RaceList[numRaces].snow = SPIntN (line, "snow", 0);
				RaceList[numRaces].wind = SPIntN (line, "wind", 0);
				RaceList[numRaces].time = SPVector3N (line, "time", MakeVector (0, 0, 0));
				RaceList[numRaces].herrings = SPIndex3N (line, "herring", MakeIndex3 (0, 0, 0));
				RaceList[numRaces].music_theme = Music.GetThemeIdx (SPStrN (line, "theme", "normal"));
				numRaces++;
			}
		}
	}
	list.MakeIndex (RaceIndex, "race");

	// pass 2: cups
	for (i=0; i<list.Count(); i++) {
		line = list.Line (i);
		type = SPIntN (line, "struct", -1);
		if (type == 1) {
			if (numCups < MAX_CUPS2) {
				CupList[numCups].cup = SPStrN (line, "cup", "error");
				CupList[numCups].name = SPStrN (line, "name", "unknown");
				CupList[numCups].desc = SPStrN (line, "desc", "unknown");
				num = SPIntN (line, "num", 0);
				CupList[numCups].num_races = num;
				for (ii=0; ii<num; ii++) {
					race = SPStrN (line, Int_StrN (ii+1), "");
					CupList[numCups].races[ii] = GetRaceIdx (race);
				}
				numCups++;
			}
		}
	}
	list.MakeIndex (CupIndex, "cup");

	// pass 3: events
	for (i=0; i<list.Count(); i++) {
		line = list.Line (i);
		type = SPIntN (line, "struct", -1);
		if (type == 2) {
			if (numEvents < MAX_EVENTS2) {
				EventList[numEvents].name = SPStrN (line, "name", "unknown");
				num = SPIntN (line, "num", 0);
				EventList[numEvents].num_cups = num;
				for (ii=0; ii<num; ii++) {
					cup = SPStrN (line, Int_StrN (ii+1), "");
					EventList[numEvents].cups[ii] = GetCupIdx (cup);
				}
				numEvents++;
			}
		}
	}
	list.MakeIndex (EventIndex, "event");

	return true;
}
bool CEvents::LoadEventList () {
	CSPList list(256);

	if (!list.Load (param.common_course_dir, "events.lst")) {
		Message ("could not load events.lst");
		return false;
	}

	// pass 1: races
	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		int type = SPIntN (line, "struct", -1);
		if (type == 0) {
			RaceList.push_back(TRace(
			                       Course.GetCourse(SPStrN(line, "course")),
			                       Env.GetLightIdx(SPStrN(line, "light")),
			                       SPIntN(line, "snow", 0),
			                       SPIntN(line, "wind", 0),
			                       SPVector3i(line, "herring"),
			                       SPVector3d(line, "time"),
			                       Music.GetThemeIdx(SPStrN(line, "theme", "normal"))));
		}
	}
	list.MakeIndex (RaceIndex, "race");

	// pass 2: cups
	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		int type = SPIntN (line, "struct", -1);
		if (type == 1) {
			CupList.push_back(TCup(
			                      SPStrN(line, "cup", errorString),
			                      SPStrN(line, "name", "unknown"),
			                      SPStrN(line, "desc", "unknown")));
			int num = SPIntN (line, "num", 0);
			CupList.back().races.resize(num);
			for (int ii=0; ii<num; ii++) {
				string race = SPStrN (line, Int_StrN (ii+1));
				CupList.back().races[ii] = &RaceList[GetRaceIdx(race)];
			}
		}
	}
	list.MakeIndex (CupIndex, "cup");

	// pass 3: events
	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		int type = SPIntN (line, "struct", -1);
		if (type == 2) {
			EventList.push_back(TEvent(SPStrN(line, "name", "unknown")));
			int num = SPIntN (line, "num", 0);
			EventList.back().cups.resize(num);
			for (int ii=0; ii<num; ii++) {
				string cup = SPStrN (line, Int_StrN (ii+1));
				EventList.back().cups[ii] = &CupList[GetCupIdx(cup)];
			}
		}
	}
	list.MakeIndex (EventIndex, "event");

	return true;
}