From 1c8fb57ff990c69a8d100281f0259f39fa4a7951 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:51:27 -0500 Subject: [PATCH] Fix: Do not split departing player research centers with team in non-shared research mode --- src/multijoin.cpp | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/multijoin.cpp b/src/multijoin.cpp index c2eb3c1a434..1da76892e2c 100644 --- a/src/multijoin.cpp +++ b/src/multijoin.cpp @@ -169,6 +169,33 @@ void destroyPlayerResources(UDWORD player, bool quietly) return; } +static bool destroyMatchingStructs(UDWORD player, std::function cmp, bool quietly) +{ + bool destroyedAnyStructs = false; + STRUCTURE *psStruct = apsStructLists[player]; + while (psStruct) + { + STRUCTURE * psNext = psStruct->psNext; + + if (cmp(psStruct)) + { + // FIXME: look why destroyStruct() doesn't put back the feature like removeStruct() does + if (quietly || psStruct->pStructureType->type == REF_RESOURCE_EXTRACTOR) // don't show effects + { + removeStruct(psStruct, true); + } + else // show effects + { + destroyStruct(psStruct, gameTime); + } + destroyedAnyStructs = true; + } + + psStruct = psNext; + } + return destroyedAnyStructs; +} + bool splitResourcesAmongTeam(UDWORD player) { auto team = NetPlay.players[player].team; @@ -288,7 +315,15 @@ bool splitResourcesAmongTeam(UDWORD player) // Distribute key structures distributeMatchingStructs([](STRUCTURE *psStruct) { return psStruct->pStructureType->type == REF_RESOURCE_EXTRACTOR; }); distributeMatchingStructs([](STRUCTURE *psStruct) { return psStruct->pStructureType->type == REF_POWER_GEN; }); - distributeMatchingStructs([](STRUCTURE *psStruct) { return psStruct->pStructureType->type == REF_RESEARCH; }); + if (alliancesSharedResearch(game.alliance)) + { + distributeMatchingStructs([](STRUCTURE *psStruct) { return psStruct->pStructureType->type == REF_RESEARCH; }); + } + else + { + // destroy the research centers in unshared research mode + destroyMatchingStructs(player, [](STRUCTURE *psStruct) { return psStruct->pStructureType->type == REF_RESEARCH; }, false); + } distributeMatchingStructs([](STRUCTURE *psStruct) { return psStruct->pStructureType->type == REF_COMMAND_CONTROL; }); distributeMatchingStructs([](STRUCTURE *psStruct) { return StructIsFactory(psStruct); });