Code: Select all
/**
@brief Load teams and remove gaps in the team numbering.
@pre numTeams, hostDemo initialized
@post teams loaded
@todo don't store in global variables directly
*/
void CGameSetup::LoadTeams(const TdfParser& file)
{
// i = team index in game (no gaps), a = team index in script
int i = 0;
for (int a = 0; a < MAX_TEAMS; ++a) {
char section[50];
sprintf(section, "GAME\\TEAM%i\\", a);
string s(section);
if (!file.SectionExist(s.substr(0, s.length() - 1)))
continue;
// Get default color from palette (based on "color" tag)
int colorNum = atoi(file.SGetValueDef("0", s + "color").c_str());
colorNum %= palette.NumTeamColors();
float3 defaultCol(palette.teamColor[colorNum][0] / 255.0f, palette.teamColor[colorNum][1] / 255.0f, palette.teamColor[colorNum][2] / 255.0f);
// Read RGBColor, this overrides color if both had been set.
float3 color = file.GetFloat3(defaultCol, s + "rgbcolor");
for (int b = 0; b < 3; ++b) {
gs->Team(i)->color[b] = int(color[b] * 255);
}
gs->Team(i)->color[3] = 255;
gs->Team(i)->handicap = atof(file.SGetValueDef("0", s + "handicap").c_str()) / 100 + 1;
// leader field is relocated in RemapPlayers
gs->Team(i)->leader = atoi(file.SGetValueDef("0", s + "teamleader").c_str());
gs->Team(i)->side = StringToLower(file.SGetValueDef("arm", s + "side").c_str());
// allyteam field is relocated in RemapAllyteams
gs->SetAllyTeam(i, atoi(file.SGetValueDef("0", s + "allyteam").c_str()));
// Is this team (Lua) AI controlled?
// If this is a demo replay, non-Lua AIs aren't loaded.
const string aiDll = file.SGetValueDef("", s + "aidll");
if (aiDll.substr(0, 6) == "LuaAI:") {
gs->Team(i)->luaAI = aiDll.substr(6);
} else {
if (hostDemo) {
aiDlls[i] = "";
} else {
aiDlls[i] = aiDll;
}
}
teamRemap[a] = i;
++i;
}
if (teamRemap.size() != numTeams)
throw content_error("incorrect number of teams in GameSetup script");
}