Example #1
0
void CTeamHandler::LoadFromSetup(const CGameSetup* setup)
{
	assert(!setup->teamStartingData.empty());
	assert(setup->teamStartingData.size() <= MAX_TEAMS);
	assert(setup->allyStartingData.size() <= MAX_TEAMS);

	teams.reserve(setup->teamStartingData.size() + 1); // +1 for Gaia
	teams.resize(setup->teamStartingData.size());
	allyTeams = setup->allyStartingData;

	for (size_t i = 0; i < teams.size(); ++i) {
		// TODO: this loop body could use some more refactoring
		CTeam* team = new CTeam(i);
		teams[i] = team;
		*team = setup->teamStartingData[i];

		// all non-Gaia teams (within one allyteam) get and maintain the same unit-limit
		// (because of this it would be better treated as a pool owned by class AllyTeam)
		team->SetMaxUnits(std::min(setup->maxUnitsPerTeam, int(MAX_UNITS / teams.size())));

		assert(team->teamAllyteam >=                0);
		assert(team->teamAllyteam <  allyTeams.size());
	}

	if (gs->useLuaGaia) {
		// Gaia adjustments
		gaiaTeamID = static_cast<int>(teams.size());
		gaiaAllyTeamID = static_cast<int>(allyTeams.size());

		// Setup the gaia team
		CTeam* gaia = new CTeam(gaiaTeamID);
		gaia->color[0] = 255;
		gaia->color[1] = 255;
		gaia->color[2] = 255;
		gaia->color[3] = 255;
		gaia->gaia = true;
		gaia->SetMaxUnits(MAX_UNITS - (teams.size() * teams[0]->GetMaxUnits()));
		gaia->StartposMessage(ZeroVector);
		gaia->teamAllyteam = gaiaAllyTeamID;
		teams.push_back(gaia);

		assert((((teams.size() - 1) * teams[0]->GetMaxUnits()) + gaia->GetMaxUnits()) == MAX_UNITS);

		for (std::vector< ::AllyTeam >::iterator it = allyTeams.begin(); it != allyTeams.end(); ++it) {
			it->allies.push_back(false); // enemy to everyone
		}

		::AllyTeam allyteam;
		allyteam.allies.resize(allyTeams.size() + 1, false); // everyones enemy
		allyteam.allies[gaiaAllyTeamID] = true; // peace with itself
		allyTeams.push_back(allyteam);
	}
}
Example #2
0
void CTeamHandler::LoadFromSetup(const CGameSetup* setup)
{
	const bool useLuaGaia  = CLuaGaia::SetConfigString(setup->luaGaiaStr);

	activeTeams = setup->numTeams;
	activeAllyTeams = setup->numAllyTeams;

	assert(activeTeams <= MAX_TEAMS);
	assert(activeAllyTeams <= MAX_TEAMS);

	for (int i = 0; i < activeTeams; ++i) {
		// TODO: this loop body could use some more refactoring
		CTeam* team = Team(i);
		const CGameSetup::TeamData& teamStartingData = setup->teamStartingData[i];

		team->metal = setup->startMetal;
		team->metalIncome = setup->startMetal; // for the endgame statistics

		team->energy = setup->startEnergy;
		team->energyIncome = setup->startEnergy;

		float3 start(teamStartingData.startPos.x, teamStartingData.startPos.y, teamStartingData.startPos.z);
		team->StartposMessage(start, (setup->startPosType != CGameSetup::StartPos_ChooseInGame));
		std::memcpy(team->color, teamStartingData.color, 4);
		team->handicap = teamStartingData.handicap;
		team->leader = teamStartingData.leader;
		team->side = teamStartingData.side;
		SetAllyTeam(i, teamStartingData.teamAllyteam);

		if (!teamStartingData.aiDll.empty()) {
			if (teamStartingData.aiDll.substr(0, 6) == "LuaAI:") { // its a LuaAI
				team->luaAI = teamStartingData.aiDll.substr(6);
				team->isAI = true;
			}
			else { // no LuaAI
				if (setup->hostDemo) // in demo replay, we don't need AI's to load again
					team->dllAI = "";
				else {
					team->dllAI = teamStartingData.aiDll;
					team->isAI = true;
				}
			}
		}
	}

	for (int allyTeam1 = 0; allyTeam1 < activeAllyTeams; ++allyTeam1)
	{
		for (int allyTeam2 = 0; allyTeam2 < activeAllyTeams; ++allyTeam2)
			allies[allyTeam1][allyTeam2] = setup->allyStartingData[allyTeam1].allies[allyTeam2];
	}

	if (useLuaGaia) {
		// Gaia adjustments
		gaiaTeamID = activeTeams;
		gaiaAllyTeamID = activeAllyTeams;
		activeTeams++;
		activeAllyTeams++;

		// Setup the gaia team
		CTeam* team = Team(gaiaTeamID);
		team->color[0] = 255;
		team->color[1] = 255;
		team->color[2] = 255;
		team->color[3] = 255;
		team->gaia = true;
		team->StartposMessage(float3(0.0, 0.0, 0.0), true);
		//players[setup->numPlayers]->team = gaiaTeamID;
		SetAllyTeam(gaiaTeamID, gaiaAllyTeamID);
	}
}
void CGlobalSyncedStuff::LoadFromSetup(const CGameSetup* setup)
{
	gameMode = setup->gameMode;
	noHelperAIs = !!setup->noHelperAIs;

	useLuaGaia  = CLuaGaia::SetConfigString(setup->luaGaiaStr);
	useLuaRules = CLuaRules::SetConfigString(setup->luaRulesStr);

	activePlayers = setup->numPlayers;
	activeTeams = setup->numTeams;
	activeAllyTeams = setup->numAllyTeams;
	
	assert(activeTeams <= MAX_TEAMS);
	assert(activeAllyTeams <= MAX_TEAMS);

	for (int i = 0; i < activePlayers; ++i)
	{
		// TODO: refactor
		*static_cast<PlayerBase*>(players[i]) = setup->playerStartingData[i];
	}

	for (int i = 0; i < activeTeams; ++i)
	{
		teams[i]->metal = setup->startMetal;
		teams[i]->metalIncome = setup->startMetal; // for the endgame statistics

		teams[i]->energy = setup->startEnergy;
		teams[i]->energyIncome = setup->startEnergy;

		float3 start(setup->teamStartingData[i].startPos.x, setup->teamStartingData[i].startPos.y, setup->teamStartingData[i].startPos.z);
		teams[i]->StartposMessage(start, (setup->startPosType != CGameSetup::StartPos_ChooseInGame));
		std::memcpy(teams[i]->color, setup->teamStartingData[i].color, 4);
		teams[i]->handicap = setup->teamStartingData[i].handicap;
		teams[i]->leader = setup->teamStartingData[i].leader;
		teams[i]->side = setup->teamStartingData[i].side;
		SetAllyTeam(i, setup->teamStartingData[i].teamAllyteam);
		if (!setup->teamStartingData[i].aiDll.empty())
		{
			if (setup->teamStartingData[i].aiDll.substr(0, 6) == "LuaAI:") // its a LuaAI
			{
				teams[i]->luaAI = setup->teamStartingData[i].aiDll.substr(6);
				teams[i]->isAI = true;
			}
			else // no LuaAI
			{
				if (setup->hostDemo) // in demo replay, we don't need AI's to load again
					teams[i]->dllAI = "";
				else
				{
					teams[i]->dllAI = setup->teamStartingData[i].aiDll;
					teams[i]->isAI = true;
				}
			}
		}
	}

	for (int allyTeam1 = 0; allyTeam1 < activeAllyTeams; ++allyTeam1)
	{
		for (int allyTeam2 = 0; allyTeam2 < activeAllyTeams; ++allyTeam2)
			allies[allyTeam1][allyTeam2] = setup->allyStartingData[allyTeam1].allies[allyTeam2];
	}

	if (useLuaGaia) {
		//TODO duplicated in SpringApp::CreateGameSetup()
		// Gaia adjustments
		gaiaTeamID = activeTeams;
		gaiaAllyTeamID = activeAllyTeams;
		activeTeams++;
		activeAllyTeams++;

		// Setup the gaia team
		CTeam* team = gs->Team(gs->gaiaTeamID);
		team->color[0] = 255;
		team->color[1] = 255;
		team->color[2] = 255;
		team->color[3] = 255;
		team->gaia = true;
		team->StartposMessage(float3(0.0, 0.0, 0.0), true);
		//players[setup->numPlayers]->team = gaiaTeamID;
		SetAllyTeam(gaiaTeamID, gaiaAllyTeamID);
	}
}
Example #4
0
void CTeamHandler::LoadFromSetup(const CGameSetup* setup)
{
	const bool useLuaGaia = CLuaGaia::SetConfigString(setup->luaGaiaStr);

	const size_t activeTeams = setup->numTeams;
	assert(activeTeams <= MAX_TEAMS);
	teams.resize(activeTeams);
	team2allyteam.resize(activeTeams);

	const size_t activeAllyTeams = setup->numAllyTeams;
	assert(activeAllyTeams <= MAX_TEAMS);

	for (size_t i = 0; i < activeTeams; ++i) {
		// TODO: this loop body could use some more refactoring
		CTeam* team = Team(i);
		const CGameSetup::TeamData& teamStartingData = setup->teamStartingData[i];
		team->teamNum = i;
		team->metal = setup->startMetal;
		team->metalIncome = setup->startMetal; // for the endgame statistics

		team->energy = setup->startEnergy;
		team->energyIncome = setup->startEnergy;

		float3 start(teamStartingData.startPos.x, teamStartingData.startPos.y, teamStartingData.startPos.z);
		team->StartposMessage(start, (setup->startPosType != CGameSetup::StartPos_ChooseInGame));
		std::memcpy(team->color, teamStartingData.color, 4);
		team->handicap = teamStartingData.handicap;
		team->leader = teamStartingData.leader;
		team->side = teamStartingData.side;
		SetAllyTeam(i, teamStartingData.teamAllyteam);

		const SkirmishAIData* skirmishAIData =
				setup->GetSkirmishAIDataForTeam(i);

		if (skirmishAIData != NULL) {
			if (skirmishAIData->isLuaAI) {
				team->luaAI = skirmishAIData->shortName;
				team->isAI = true;
			} else {
				if (setup->hostDemo) {
					team->skirmishAIKey = SkirmishAIKey(); // unspecifyed AI Key
				} else {
					const char* sn = skirmishAIData->shortName.c_str();
					const char* v = skirmishAIData->version.c_str();
					SkirmishAIKey spec = SkirmishAIKey(sn, v);
					SkirmishAIKey fittingKey =
							IAILibraryManager::GetInstance()->ResolveSkirmishAIKey(spec);
					if (!fittingKey.IsUnspecified()) {
						team->skirmishAIKey = fittingKey;
						team->skirmishAIOptions = skirmishAIData->options;
						team->isAI = true;
					} else {
						const int MAX_MSG_LENGTH = 511;
						char s_msg[MAX_MSG_LENGTH + 1];
						SNPRINTF(s_msg, MAX_MSG_LENGTH,
								"Specifyed Skirmish AI could not be found: %s (version: %s)",
								spec.GetShortName().c_str(), spec.GetVersion() != "" ? spec.GetVersion().c_str() : "<not specifyed>");
						handleerror(NULL, s_msg, "Team Handler Error", MBF_OK | MBF_EXCL);
					}
				}
			}
		}
	}

	for (size_t allyTeam1 = 0; allyTeam1 < activeAllyTeams; ++allyTeam1)
	{
		allies.push_back(setup->allyStartingData[allyTeam1].allies);
	}

	if (useLuaGaia) {
		// Gaia adjustments
		gaiaTeamID = static_cast<int>(activeTeams);
		gaiaAllyTeamID = static_cast<int>(activeAllyTeams);

		// Setup the gaia team
		CTeam team;
		team.color[0] = 255;
		team.color[1] = 255;
		team.color[2] = 255;
		team.color[3] = 255;
		team.gaia = true;
		team.teamNum = gaiaTeamID;
		team.StartposMessage(float3(0.0, 0.0, 0.0), true);
		teams.push_back(team);
		team2allyteam.push_back(gaiaAllyTeamID);
		for (size_t allyTeam1 = 0; allyTeam1 < activeAllyTeams; ++allyTeam1)
		{
			allies[allyTeam1].push_back(false); // enemy to everyone
		}
		allies.push_back(std::vector<bool>(activeAllyTeams+1,false)); // everyones enemy
		allies[activeAllyTeams][activeAllyTeams] = true; // peace with itself
	}
	assert(team2allyteam.size() == teams.size());
	assert(teams.size() <= MAX_TEAMS);
}
Example #5
0
void CTeamHandler::LoadFromSetup(const CGameSetup* setup)
{
	const bool useLuaGaia = CLuaGaia::SetConfigString(setup->luaGaiaStr);

	assert(setup->numTeams <= MAX_TEAMS);
	teams.resize(setup->numTeams);

	for (size_t i = 0; i < teams.size(); ++i) {
		// TODO: this loop body could use some more refactoring
		CTeam* team = Team(i);
		*team = setup->teamStartingData[i];
		team->teamNum = i;
		team->metalIncome = team->metal; // for the endgame statistics

		team->energyIncome = setup->startEnergy;

		SetAllyTeam(i, team->teamAllyteam);

		const SkirmishAIData* skirmishAIData = setup->GetSkirmishAIDataForTeam(i);

		if (skirmishAIData != NULL) {
			bool isLuaAI = true;
			const IAILibraryManager::T_skirmishAIKeys& skirmishAIKeys = IAILibraryManager::GetInstance()->GetSkirmishAIKeys();
			IAILibraryManager::T_skirmishAIKeys::const_iterator skirmAiImpl;

			for (skirmAiImpl = skirmishAIKeys.begin();
				skirmAiImpl != skirmishAIKeys.end(); ++skirmAiImpl) {
				if (skirmishAIData->shortName == skirmAiImpl->GetShortName()) {
					isLuaAI = false;
					logOutput.Print("Skirmish AI (%s) for team %i is no Lua AI", skirmishAIData->shortName.c_str(), skirmishAIData->team);
					break;
				}
			}

			if (isLuaAI) {
				team->luaAI = skirmishAIData->shortName;
				team->isAI = true;
			} else {
				if (setup->hostDemo) {
					// CPreGame always adds the name of the demo
					// file to the internal setup script before
					// CGameSetup is inited, therefore hostDemo
					// tells us if we're watching a replay
					// if so, then we do NOT want to load any AI
					// libs, and therefore we must make sure each
					// team's skirmishAIKey is left "unspecified"
					//
					// however, flag this team as an AI anyway so
					// the original AI team's orders are not seen
					// as invalid and we don't desync the demo
					team->skirmishAIKey = SkirmishAIKey(); // unspecified AI Key
					team->isAI = true;
				} else {
					const char* sn = skirmishAIData->shortName.c_str();
					const char* v = skirmishAIData->version.c_str();

					SkirmishAIKey spec = SkirmishAIKey(sn, v);
					SkirmishAIKey fittingKey =
							IAILibraryManager::GetInstance()->ResolveSkirmishAIKey(spec);

					if (!fittingKey.IsUnspecified()) {
						team->skirmishAIKey = fittingKey;
						team->skirmishAIOptions = skirmishAIData->options;
						team->isAI = true;
					} else {
						// a missing AI lib is only a problem for
						// the player who is supposed to load it
						if (gu->myPlayerNum == skirmishAIData->hostPlayerNum) {
							const int MAX_MSG_LENGTH = 511;
							char s_msg[MAX_MSG_LENGTH + 1];
							SNPRINTF(s_msg, MAX_MSG_LENGTH,
									"Specified Skirmish AI could not be found: %s (version: %s)",
									spec.GetShortName().c_str(), spec.GetVersion() != "" ? spec.GetVersion().c_str() : "<not specified>");
							handleerror(NULL, s_msg, "Team Handler Error", MBF_OK | MBF_EXCL);
						}
					}
				}
			}
		}
	}

	allyTeams = setup->allyStartingData;
	assert(setup->numAllyTeams <= MAX_TEAMS);
	if (useLuaGaia) {
		// Gaia adjustments
		gaiaTeamID = static_cast<int>(teams.size());
		gaiaAllyTeamID = static_cast<int>(allyTeams.size());

		// Setup the gaia team
		CTeam team;
		team.color[0] = 255;
		team.color[1] = 255;
		team.color[2] = 255;
		team.color[3] = 255;
		team.gaia = true;
		team.teamNum = gaiaTeamID;
		team.StartposMessage(float3(0.0, 0.0, 0.0), true);
		team.teamAllyteam = gaiaAllyTeamID;
		teams.push_back(team);

		for (std::vector< ::AllyTeam >::iterator it = allyTeams.begin(); it != allyTeams.end(); ++it)
		{
			it->allies.push_back(false); // enemy to everyone
		}
		::AllyTeam allyteam;
		allyteam.allies.resize(allyTeams.size()+1,false); // everyones enemy
		allyteam.allies[gaiaTeamID] = true; // peace with itself
		allyTeams.push_back(allyteam);
	}
}
void CTeamHandler::LoadFromSetup(const CGameSetup* setup)
{
    const bool useLuaGaia  = CLuaGaia::SetConfigString(setup->luaGaiaStr);

    activeTeams = setup->numTeams;
    activeAllyTeams = setup->numAllyTeams;

    assert(activeTeams <= MAX_TEAMS);
    assert(activeAllyTeams <= MAX_TEAMS);

    for (int i = 0; i < activeTeams; ++i) {
        // TODO: this loop body could use some more refactoring
        CTeam* team = Team(i);
        const CGameSetup::TeamData& teamStartingData = setup->teamStartingData[i];

        team->metal = setup->startMetal;
        team->metalIncome = setup->startMetal; // for the endgame statistics

        team->energy = setup->startEnergy;
        team->energyIncome = setup->startEnergy;

        float3 start(teamStartingData.startPos.x, teamStartingData.startPos.y, teamStartingData.startPos.z);
        team->StartposMessage(start, (setup->startPosType != CGameSetup::StartPos_ChooseInGame));
        std::memcpy(team->color, teamStartingData.color, 4);
        team->handicap = teamStartingData.handicap;
        team->leader = teamStartingData.leader;
        team->side = teamStartingData.side;
        SetAllyTeam(i, teamStartingData.teamAllyteam);

        if (!teamStartingData.luaAI.empty()) {
            team->luaAI = teamStartingData.luaAI;
            team->isAI = true;
        } else if (!(teamStartingData.skirmishAIShortName.empty())) {
            if (setup->hostDemo) {
                team->skirmishAIKey = SkirmishAIKey(); // unspecifyed AI Key
            } else {
                const char* sn = teamStartingData.skirmishAIShortName.c_str();
                const char* v = teamStartingData.skirmishAIVersion.empty()
                                ? NULL : teamStartingData.skirmishAIVersion.c_str();
                SkirmishAIKey spec = SkirmishAIKey(sn, v);
                SkirmishAIKey fittingKey =
                    IAILibraryManager::GetInstance()->ResolveSkirmishAIKey(spec);
                if (!fittingKey.IsUnspecified()) {
                    team->skirmishAIKey = fittingKey;
                    team->skirmishAIOptions = teamStartingData.skirmishAIOptions;
                    team->isAI = true;
                } else {
                    const int MAX_MSG_LENGTH = 511;
                    char s_msg[MAX_MSG_LENGTH + 1];
                    SNPRINTF(s_msg, MAX_MSG_LENGTH,
                             "Specifyed Skirmish AI could not be found: %s (version: %s)",
                             spec.GetShortName().c_str(), spec.GetVersion() != "" ? spec.GetVersion().c_str() : "<not specifyed>");
                    handleerror(NULL, s_msg, "Team Handler Error", MBF_OK | MBF_EXCL);
                }
            }
        }
    }

    for (int allyTeam1 = 0; allyTeam1 < activeAllyTeams; ++allyTeam1)
    {
        for (int allyTeam2 = 0; allyTeam2 < activeAllyTeams; ++allyTeam2)
            allies[allyTeam1][allyTeam2] = setup->allyStartingData[allyTeam1].allies[allyTeam2];
    }

    if (useLuaGaia) {
        // Gaia adjustments
        gaiaTeamID = activeTeams;
        gaiaAllyTeamID = activeAllyTeams;
        activeTeams++;
        activeAllyTeams++;

        // Setup the gaia team
        CTeam* team = Team(gaiaTeamID);
        team->color[0] = 255;
        team->color[1] = 255;
        team->color[2] = 255;
        team->color[3] = 255;
        team->gaia = true;
        team->StartposMessage(float3(0.0, 0.0, 0.0), true);
        //players[setup->numPlayers]->team = gaiaTeamID;
        SetAllyTeam(gaiaTeamID, gaiaAllyTeamID);
    }
}