Skip to content

Commit

Permalink
Merge pull request #4019 from IvanSavenko/simturn_tweaks
Browse files Browse the repository at this point in the history
[1.5.2] Simturn tweaks
  • Loading branch information
IvanSavenko committed May 21, 2024
2 parents e5322ea + 215b279 commit c85ea98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/StartInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ struct DLL_LINKAGE SimturnsInfo
int optionalTurns = 0;
/// If set to true, human and 1 AI can act at the same time
bool allowHumanWithAI = false;
/// If set to true, allied players can play simultaneously even after contacting each other
bool ignoreAlliedContacts = true;

bool operator == (const SimturnsInfo & other) const
{
return requiredTurns == other.requiredTurns &&
optionalTurns == other.optionalTurns &&
ignoreAlliedContacts == other.ignoreAlliedContacts &&
allowHumanWithAI == other.allowHumanWithAI;
}

Expand All @@ -46,6 +49,10 @@ struct DLL_LINKAGE SimturnsInfo
h & requiredTurns;
h & optionalTurns;
h & allowHumanWithAI;

static_assert(Handler::Version::RELEASE_143 < Handler::Version::CURRENT, "Please add ignoreAlliedContacts to serialization for 1.6");
// disabled to allow multiplayer compatibility between 1.5.2 and 1.5.1
// h & ignoreAlliedContacts
}
};

Expand Down
18 changes: 18 additions & 0 deletions server/processors/TurnOrderProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include "../CVCMIServer.h"

#include "../../lib/CPlayerState.h"
#include "../../lib/mapping/CMap.h"
#include "../../lib/mapObjects/CGObjectInstance.h"
#include "../../lib/gameState/CGameState.h"
#include "../../lib/pathfinder/CPathfinder.h"
#include "../../lib/pathfinder/PathfinderOptions.h"

Expand Down Expand Up @@ -102,6 +105,18 @@ bool TurnOrderProcessor::playersInContact(PlayerColor left, PlayerColor right) c
const auto * leftInfo = gameHandler->getPlayerState(left, false);
const auto * rightInfo = gameHandler->getPlayerState(right, false);

for (auto obj : gameHandler->gameState()->map->objects)
{
if (obj && obj->isVisitable())
{
int3 pos = obj->visitablePos();
if (obj->tempOwner == left)
leftReachability[pos.z][pos.x][pos.y] = true;
if (obj->tempOwner == right)
rightReachability[pos.z][pos.x][pos.y] = true;
}
}

for(const auto & hero : leftInfo->heroes)
{
CPathsInfo out(mapSize, hero);
Expand Down Expand Up @@ -174,6 +189,9 @@ bool TurnOrderProcessor::computeCanActSimultaneously(PlayerColor active, PlayerC
if (gameHandler->getDate(Date::DAY) > simturnsTurnsMaxLimit())
return false;

if (gameHandler->getStartInfo()->simturnsInfo.ignoreAlliedContacts && activeInfo->team == waitingInfo->team)
return true;

if (playersInContact(active, waiting))
return false;

Expand Down

0 comments on commit c85ea98

Please sign in to comment.