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

Merge pull request #3970 from Laserlicht/extra

ExtraOptions improvements
This commit is contained in:
Ivan Savenko 2024-05-15 15:20:59 +03:00 committed by GitHub
commit 1b1f724de1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 69 additions and 5 deletions

View File

@ -77,6 +77,7 @@ AIGateway::AIGateway()
destinationTeleport = ObjectInstanceID();
destinationTeleportPos = int3(-1);
nullkiller.reset(new Nullkiller());
announcedCheatingProblem = false;
}
AIGateway::~AIGateway()
@ -828,7 +829,14 @@ void AIGateway::makeTurn()
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex);
setThreadName("AIGateway::makeTurn");
cb->sendMessage("vcmieagles");
if(cb->getStartInfo()->extraOptionsInfo.cheatsAllowed)
cb->sendMessage("vcmieagles");
else
{
if(!announcedCheatingProblem)
cb->sendMessage("Nullkiller AI currently requires the ability to cheat in order to function correctly! Please enable!");
announcedCheatingProblem = true;
}
retrieveVisitableObjs();

View File

@ -96,6 +96,7 @@ public:
std::unique_ptr<boost::thread> makingTurn;
private:
boost::mutex turnInterruptionMutex;
bool announcedCheatingProblem;
public:
ObjectInstanceID selectedObject;

View File

@ -63,7 +63,7 @@
"vcmi.mainMenu.serverClosing" : "Closing...",
"vcmi.mainMenu.hostTCP" : "Host TCP/IP game",
"vcmi.mainMenu.joinTCP" : "Join TCP/IP game",
"vcmi.lobby.filepath" : "File path",
"vcmi.lobby.creationDate" : "Creation date",
"vcmi.lobby.scenarioName" : "Scenario name",

View File

@ -63,7 +63,7 @@
"vcmi.mainMenu.serverClosing" : "Trenne...",
"vcmi.mainMenu.hostTCP" : "Hoste TCP/IP Spiel",
"vcmi.mainMenu.joinTCP" : "Trete TCP/IP Spiel bei",
"vcmi.lobby.filepath" : "Dateipfad",
"vcmi.lobby.creationDate" : "Erstellungsdatum",
"vcmi.lobby.scenarioName" : "Szenario-Name",

View File

@ -230,6 +230,16 @@ void CLobbyScreen::toggleChat()
void CLobbyScreen::updateAfterStateChange()
{
if(CSH->isHost() && screenType == ESelectionScreen::newGame)
{
bool isMultiplayer = CSH->loadMode == ELoadMode::MULTI;
ExtraOptionsInfo info = SEL->getStartInfo()->extraOptionsInfo;
info.cheatsAllowed = isMultiplayer ? persistentStorage["startExtraOptions"]["multiPlayer"]["cheatsAllowed"].Bool() : !persistentStorage["startExtraOptions"]["singlePlayer"]["cheatsNotAllowed"].Bool();
info.unlimitedReplay = persistentStorage["startExtraOptions"][isMultiplayer ? "multiPlayer" : "singlePlayer"]["unlimitedReplay"].Bool();
if(info.cheatsAllowed != CSH->si->extraOptionsInfo.cheatsAllowed || info.unlimitedReplay != CSH->si->extraOptionsInfo.unlimitedReplay)
CSH->setExtraOptionsInfo(info);
}
if(CSH->mi)
{
if (tabOpt)

View File

@ -22,6 +22,7 @@
#include "../../lib/Languages.h"
#include "../../lib/MetaString.h"
#include "../../lib/CGeneralTextHandler.h"
#include "../../lib/CConfigHandler.h"
static std::string timeToString(int time)
{
@ -100,12 +101,18 @@ OptionsTabBase::OptionsTabBase(const JsonPath & configPath)
});
addCallback("setCheatAllowed", [&](int index){
bool isMultiplayer = CSH->loadMode == ELoadMode::MULTI;
Settings entry = persistentStorage.write["startExtraOptions"][isMultiplayer ? "multiPlayer" : "singlePlayer"][isMultiplayer ? "cheatsAllowed" : "cheatsNotAllowed"];
entry->Bool() = isMultiplayer ? index : !index;
ExtraOptionsInfo info = SEL->getStartInfo()->extraOptionsInfo;
info.cheatsAllowed = index;
CSH->setExtraOptionsInfo(info);
});
addCallback("setUnlimitedReplay", [&](int index){
bool isMultiplayer = CSH->loadMode == ELoadMode::MULTI;
Settings entry = persistentStorage.write["startExtraOptions"][isMultiplayer ? "multiPlayer" : "singlePlayer"]["unlimitedReplay"];
entry->Bool() = index;
ExtraOptionsInfo info = SEL->getStartInfo()->extraOptionsInfo;
info.unlimitedReplay = index;
CSH->setExtraOptionsInfo(info);
@ -410,13 +417,13 @@ void OptionsTabBase::recreate(bool campaign)
if(auto buttonCheatAllowed = widget<CToggleButton>("buttonCheatAllowed"))
{
buttonCheatAllowed->setSelectedSilent(SEL->getStartInfo()->extraOptionsInfo.cheatsAllowed);
buttonCheatAllowed->block(SEL->screenType == ESelectionScreen::loadGame);
buttonCheatAllowed->block(CSH->isGuest());
}
if(auto buttonUnlimitedReplay = widget<CToggleButton>("buttonUnlimitedReplay"))
{
buttonUnlimitedReplay->setSelectedSilent(SEL->getStartInfo()->extraOptionsInfo.unlimitedReplay);
buttonUnlimitedReplay->block(SEL->screenType == ESelectionScreen::loadGame);
buttonUnlimitedReplay->block(CSH->isGuest());
}
if(auto textureCampaignOverdraw = widget<CFilledTexture>("textureCampaignOverdraw"))

View File

@ -294,6 +294,7 @@ void CGameState::updateOnLoad(StartInfo * si)
scenarioOps->playerInfos = si->playerInfos;
for(auto & i : si->playerInfos)
gs->players[i.first].human = i.second.isControlledByHuman();
scenarioOps->extraOptionsInfo = si->extraOptionsInfo;
}
void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRandomMap, Load::ProgressAccumulator & progressTracking)

View File

@ -16,6 +16,7 @@
#include "processors/PlayerMessageProcessor.h"
#include "../lib/CHeroHandler.h"
#include "../lib/CPlayerState.h"
#include "../lib/MetaString.h"
#include "../lib/registerTypes/RegisterTypesLobbyPacks.h"
#include "../lib/serializer/CMemorySerializer.h"
@ -332,6 +333,8 @@ void CVCMIServer::startGameImmediately()
setState(EServerState::GAMEPLAY);
lastTimerUpdateTime = gameplayStartTime = std::chrono::steady_clock::now();
onTimer();
multiplayerWelcomeMessage();
}
void CVCMIServer::onDisconnected(const std::shared_ptr<INetworkConnection> & connection, const std::string & errorMessage)
@ -979,6 +982,38 @@ ui8 CVCMIServer::getIdOfFirstUnallocatedPlayer() const
return 0;
}
void CVCMIServer::multiplayerWelcomeMessage()
{
int humanPlayer = 0;
for (auto & pi : si->playerInfos)
if(gh->getPlayerState(pi.first)->isHuman())
humanPlayer++;
if(humanPlayer < 2) // Singleplayer
return;
std::vector<std::string> optionIds;
if(si->extraOptionsInfo.cheatsAllowed)
optionIds.push_back("vcmi.optionsTab.cheatAllowed.hover");
if(si->extraOptionsInfo.unlimitedReplay)
optionIds.push_back("vcmi.optionsTab.unlimitedReplay.hover");
if(!optionIds.size()) // No settings to publish
return;
MetaString str;
str.appendTextID("vcmi.optionsTab.extraOptions.hover");
str.appendRawString(": ");
for(int i = 0; i < optionIds.size(); i++)
{
str.appendTextID(optionIds[i]);
if(i < optionIds.size() - 1)
str.appendRawString(", ");
}
gh->playerMessages->broadcastSystemMessage(str);
}
INetworkHandler & CVCMIServer::getNetworkHandler()
{
return *networkHandler;

View File

@ -130,4 +130,6 @@ public:
void setCampaignBonus(int bonusId);
ui8 getIdOfFirstUnallocatedPlayer() const;
void multiplayerWelcomeMessage();
};