1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Implemented "Allied Adventure Map AI" option

This commit is contained in:
Ivan Savenko 2023-06-29 19:09:47 +03:00
parent 21c45bd84f
commit 8efa7911b7
8 changed files with 22 additions and 41 deletions

View File

@ -430,18 +430,23 @@ void CClient::initPlayerEnvironments()
void CClient::initPlayerInterfaces()
{
for(auto & elem : gs->scenarioOps->playerInfos)
for(auto & playerInfo : gs->scenarioOps->playerInfos)
{
PlayerColor color = elem.first;
PlayerColor color = playerInfo.first;
if(!vstd::contains(CSH->getAllClientPlayers(CSH->c->connectionID), color))
continue;
if(!vstd::contains(playerint, color))
{
logNetwork->info("Preparing interface for player %s", color.getStr());
if(elem.second.isControlledByAI())
if(playerInfo.second.isControlledByAI())
{
auto AiToGive = aiNameForPlayer(elem.second, false);
bool alliedToHuman = false;
for(auto & allyInfo : gs->scenarioOps->playerInfos)
if (gs->getPlayerTeam(allyInfo.first) == gs->getPlayerTeam(playerInfo.first) && allyInfo.second.isControlledByHuman())
alliedToHuman = true;
auto AiToGive = aiNameForPlayer(playerInfo.second, false, alliedToHuman);
logNetwork->info("Player %s will be lead by %s", color.getStr(), AiToGive);
installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), color);
}
@ -464,7 +469,7 @@ void CClient::initPlayerInterfaces()
logNetwork->trace("Initialized player interfaces %d ms", CSH->th->getDiff());
}
std::string CClient::aiNameForPlayer(const PlayerSettings & ps, bool battleAI)
std::string CClient::aiNameForPlayer(const PlayerSettings & ps, bool battleAI, bool alliedToHuman)
{
if(ps.name.size())
{
@ -473,13 +478,15 @@ std::string CClient::aiNameForPlayer(const PlayerSettings & ps, bool battleAI)
return ps.name;
}
return aiNameForPlayer(battleAI);
return aiNameForPlayer(battleAI, alliedToHuman);
}
std::string CClient::aiNameForPlayer(bool battleAI)
std::string CClient::aiNameForPlayer(bool battleAI, bool alliedToHuman)
{
const int sensibleAILimit = settings["session"]["oneGoodAI"].Bool() ? 1 : PlayerColor::PLAYER_LIMIT_I;
std::string goodAI = battleAI ? settings["server"]["neutralAI"].String() : settings["server"]["playerAI"].String();
std::string goodAdventureAI = alliedToHuman ? settings["server"]["alliedAI"].String() : settings["server"]["playerAI"].String();
std::string goodBattleAI = settings["server"]["neutralAI"].String();
std::string goodAI = battleAI ? goodBattleAI : goodAdventureAI;
std::string badAI = battleAI ? "StupidAI" : "EmptyAI";
//TODO what about human players

View File

@ -161,8 +161,8 @@ public:
void initMapHandler();
void initPlayerEnvironments();
void initPlayerInterfaces();
std::string aiNameForPlayer(const PlayerSettings & ps, bool battleAI); //empty means no AI -> human
std::string aiNameForPlayer(bool battleAI);
std::string aiNameForPlayer(const PlayerSettings & ps, bool battleAI, bool alliedToHuman); //empty means no AI -> human
std::string aiNameForPlayer(bool battleAI, bool alliedToHuman);
void installNewPlayerInterface(std::shared_ptr<CGameInterface> gameInterface, PlayerColor color, bool battlecb = false);
void installNewBattleInterface(std::shared_ptr<CBattleGameInterface> battleInterface, PlayerColor color, bool needCallback = true);

View File

@ -94,7 +94,7 @@ void ClientCommandManager::handleGoSoloCommand()
{
if(elem.second.human)
{
auto AiToGive = CSH->client->aiNameForPlayer(*CSH->client->getPlayerSettings(elem.first), false);
auto AiToGive = CSH->client->aiNameForPlayer(*CSH->client->getPlayerSettings(elem.first), false, false);
printCommandMessage("Player " + elem.first.getStr() + " will be lead by " + AiToGive, ELogLevel::INFO);
CSH->client->installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), elem.first);
}

View File

@ -107,13 +107,9 @@ void FirstLaunchView::enterSetup()
void FirstLaunchView::setSetupProgress(int progress)
{
int value = std::max(progress, ui->setupProgressBar->value());
ui->setupProgressBar->setValue(value);
ui->buttonTabLanguage->setDisabled(value < 1);
ui->buttonTabHeroesData->setDisabled(value < 2);
ui->buttonTabModPreset->setDisabled(value < 3);
ui->buttonTabLanguage->setDisabled(progress < 1);
ui->buttonTabHeroesData->setDisabled(progress < 2);
ui->buttonTabModPreset->setDisabled(progress < 3);
}
void FirstLaunchView::activateTabLanguage()

View File

@ -93,25 +93,6 @@
</item>
</layout>
</item>
<item>
<widget class="QProgressBar" name="setupProgressBar">
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>3</number>
</property>
<property name="value">
<number>0</number>
</property>
<property name="textVisible">
<bool>true</bool>
</property>
<property name="format">
<string>Step %v out of %m</string>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="installerTabs">
<property name="currentIndex">

View File

@ -22,7 +22,7 @@
VCMI_LIB_NAMESPACE_BEGIN
PlayerSettings::PlayerSettings()
: bonus(RANDOM), castle(NONE), hero(RANDOM), heroPortrait(RANDOM), color(0), handicap(NO_HANDICAP), team(0), compOnly(false)
: bonus(RANDOM), castle(NONE), hero(RANDOM), heroPortrait(RANDOM), color(0), handicap(NO_HANDICAP), compOnly(false)
{
}

View File

@ -43,7 +43,6 @@ struct DLL_LINKAGE PlayerSettings
PlayerColor color; //from 0 -
enum EHandicap {NO_HANDICAP, MILD, SEVERE};
EHandicap handicap;//0-no, 1-mild, 2-severe
TeamID team;
std::string name;
std::set<ui8> connectedPlayerIDs; //Empty - AI, or connectrd player ids
@ -60,7 +59,6 @@ struct DLL_LINKAGE PlayerSettings
h & handicap;
h & name;
h & connectedPlayerIDs;
h & team;
h & compOnly;
}

View File

@ -658,7 +658,6 @@ void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRan
{
PlayerSettings & playerSettings = scenarioOps->playerInfos[PlayerColor(i)];
playerSettings.compOnly = !playerInfo.canHumanPlay;
playerSettings.team = playerInfo.team;
playerSettings.castle = playerInfo.defaultCastle();
if(playerSettings.isControlledByAI() && playerSettings.name.empty())
{