SkirmishAIKey CSkirmishAILibraryInfo::GetKey() const {

	const std::string& sn = GetInfo(SKIRMISH_AI_PROPERTY_SHORT_NAME);
	const std::string& v = GetInfo(SKIRMISH_AI_PROPERTY_VERSION);
	SkirmishAIKey key = SkirmishAIKey(sn, v);

	return key;
}
SkirmishAIKey CSkirmishAILibraryInfo::GetKey() const {

	const std::string& sn = GetShortName();
	const std::string& v = GetVersion();
	SkirmishAIKey key = SkirmishAIKey(sn, v);

	return key;
}
Exemple #3
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);
}
Exemple #4
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);
	}
}
Exemple #5
0
void CAILibraryManager::GetAllInfosFromCache() {

	ClearAllInfos();

	typedef std::vector<std::string> T_dirs;

	// cause we use CFileHandler for searching files,
	// we are automatically searching in all data-dirs

	// Read from AI Interface info files
	// we are looking for:
	// {AI_INTERFACES_DATA_DIR}/{*}/{*}/InterfaceInfo.lua
	T_dirs aiInterfaceDataDirs =
			filesystem.FindDirsInDirectSubDirs(AI_INTERFACES_DATA_DIR);
	typedef std::map<const AIInterfaceKey, std::set<std::string> > T_dupInt;
	T_dupInt duplicateInterfaceInfoCheck;
	for (T_dirs::iterator dir = aiInterfaceDataDirs.begin();
			dir != aiInterfaceDataDirs.end(); ++dir) {
		const std::string& possibleDataDir = *dir;
		T_dirs infoFile =
				CFileHandler::FindFiles(possibleDataDir, "InterfaceInfo.lua");
		if (infoFile.size() > 0) { // interface info is available

			// generate and store the interface info
			CAIInterfaceLibraryInfo* interfaceInfo =
					new CAIInterfaceLibraryInfo(infoFile.at(0));

			interfaceInfo->SetDataDir(noSlashAtEnd(possibleDataDir));
			interfaceInfo->SetDataDirCommon(
					removeLastPathPart(possibleDataDir) + "common");

			AIInterfaceKey interfaceKey = interfaceInfo->GetKey();

			interfaceKeys.insert(interfaceKey);
			interfaceInfos[interfaceKey] = interfaceInfo;

			// so we can check if one interface is specified multiple times
			duplicateInterfaceInfoCheck[interfaceKey].insert(infoFile.at(0));
		}
	}

	// filter out interfaces that are specified multiple times
	for (T_dupInt::const_iterator info = duplicateInterfaceInfoCheck.begin();
			info != duplicateInterfaceInfoCheck.end(); ++info) {
		if (info->second.size() >= 2) {
			duplicateInterfaceInfos[info->first] = info->second;

			logOutput.Print("WARNING: Duplicate AI Interface Info found:");
			logOutput.Print("\tfor interface: %s %s", info->first.GetShortName().c_str(),
					info->first.GetVersion().c_str());
			logOutput.Print("\tin files:");
			const std::string* lastDir = NULL;
			std::set<std::string>::const_iterator dir;
			for (dir = info->second.begin(); dir != info->second.end(); ++dir) {
				logOutput.Print("\t%s", dir->c_str());
				lastDir = &(*dir);
			}
			logOutput.Print("\tusing: %s", lastDir->c_str());
		}
	}

	// Read from Skirmish AI info and option files
	// we are looking for:
	// {SKIRMISH_AI_DATA_DIR}/{*}/{*}/AIInfo.lua
	T_dirs skirmishAIDataDirs = filesystem.FindDirsInDirectSubDirs(SKIRMISH_AI_DATA_DIR);
	T_dupSkirm duplicateSkirmishAIInfoCheck;
	for (T_dirs::iterator dir = skirmishAIDataDirs.begin();
			dir != skirmishAIDataDirs.end(); ++dir) {
		const std::string& possibleDataDir = *dir;
		T_dirs infoFile = CFileHandler::FindFiles(possibleDataDir,
				"AIInfo.lua");
		if (infoFile.size() > 0) { // skirmish AI info is available
			std::string optionFileName = "";
			T_dirs optionFile = CFileHandler::FindFiles(possibleDataDir,
					"AIOptions.lua");
			if (optionFile.size() > 0) {
				optionFileName = optionFile.at(0);
			}
			// generate and store the ai info
			CSkirmishAILibraryInfo* skirmishAIInfo =
					new CSkirmishAILibraryInfo(infoFile.at(0), optionFileName);

			skirmishAIInfo->SetDataDir(noSlashAtEnd(possibleDataDir));
			skirmishAIInfo->SetDataDirCommon(
					removeLastPathPart(possibleDataDir) + "common");
			skirmishAIInfo->SetLuaAI(false);

			SkirmishAIKey aiKey = skirmishAIInfo->GetKey();
			AIInterfaceKey interfaceKey =
					FindFittingInterfaceSpecifier(
							skirmishAIInfo->GetInterfaceShortName(),
							skirmishAIInfo->GetInterfaceVersion(),
							interfaceKeys);
			if (!interfaceKey.IsUnspecified()) {
				SkirmishAIKey skirmishAIKey = SkirmishAIKey(aiKey, interfaceKey);
				skirmishAIKeys.insert(skirmishAIKey);
				skirmishAIInfos[skirmishAIKey] = skirmishAIInfo;

				// so we can check if one skirmish AI is specified multiple times
				duplicateSkirmishAIInfoCheck[skirmishAIKey].insert(infoFile.at(0));
			}
		}
	}

	// filter out skirmish AIs that are specified multiple times
	for (T_dupSkirm::const_iterator info = duplicateSkirmishAIInfoCheck.begin();
			info != duplicateSkirmishAIInfoCheck.end(); ++info) {
		if (info->second.size() >= 2) {
			duplicateSkirmishAIInfos[info->first] = info->second;

			logOutput.Print("WARNING: Duplicate Skirmish AI Info found:");
			logOutput.Print("\tfor Skirmish AI: %s %s", info->first.GetShortName().c_str(),
					info->first.GetVersion().c_str());
			logOutput.Print("\tin files:");
			const std::string* lastDir = NULL;
			std::set<std::string>::const_iterator dir;
			for (dir = info->second.begin(); dir != info->second.end(); ++dir) {
				logOutput.Print("\t%s", dir->c_str());
				lastDir = &(*dir);
			}
			logOutput.Print("\tusing: %s", lastDir->c_str());
		}
	}
}
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);
    }
}