Skip to content

Commit

Permalink
Merge branch 'master' into pre-improvecarriercost-dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
wichern authored Jan 20, 2025
2 parents 725fbc1 + bd3a2ab commit 7843b3c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
Binary file modified data/RTTR/assets/base/fonts.lst
Binary file not shown.
1 change: 1 addition & 0 deletions data/RTTR/assets/base/languages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Norwegian Bokmal=nb
Slovenian=sl
Latin=la
Portuguese=pt
Chinese=zh_CN
2 changes: 1 addition & 1 deletion external/languages
Submodule languages updated 29 files
+3 −3 .github/workflows/sanity_check.yml
+25 −20 .github/workflows/synchronize-launchpad.yml
+623 −427 rttr-cs.po
+623 −424 rttr-de.po
+623 −427 rttr-en_GB.po
+619 −423 rttr-es.po
+619 −423 rttr-et.po
+619 −423 rttr-fi.po
+623 −424 rttr-fr.po
+613 −423 rttr-he.po
+619 −423 rttr-hu.po
+616 −423 rttr-it.po
+610 −423 rttr-ko.po
+613 −423 rttr-la.po
+616 −423 rttr-lt.po
+617 −424 rttr-nb.po
+616 −423 rttr-nds.po
+623 −427 rttr-nl.po
+623 −427 rttr-pl.po
+619 −423 rttr-pt.po
+619 −423 rttr-pt_BR.po
+645 −446 rttr-ru.po
+610 −423 rttr-rw.po
+616 −423 rttr-sk.po
+620 −424 rttr-sl.po
+619 −423 rttr-sv.po
+610 −423 rttr-tr.po
+1,394 −1,170 rttr-zh_CN.po
+660 −454 rttr.pot
2 changes: 1 addition & 1 deletion external/s25update
Submodule s25update updated 1 files
+7 −3 src/s25update.cpp
30 changes: 16 additions & 14 deletions libs/s25main/world/GameWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,30 +574,32 @@ void GameWorld::CleanTerritoryRegion(TerritoryRegion& region, TerritoryChangeRea
{
if(GetGGS().isEnabled(AddonId::NO_ALLIED_PUSH))
{
const unsigned char ownerOfTriggerBld = GetNode(triggerBld.GetPos()).owner;
const unsigned char newOwnerOfTriggerBld = region.GetOwner(region.GetPosFromMapPos(triggerBld.GetPos()));
const bool isHq = triggerBld.GetBuildingType() == BuildingType::Headquarters;
const auto newOwnerOfTriggerBld = region.GetOwner(region.GetPosFromMapPos(triggerBld.GetPos()));
// An HQ can be placed independently of the current owner.
// So ensure the HQ position is always considered to belong to the HQ owner
const auto ownerOfTriggerBld = isHq ? newOwnerOfTriggerBld : GetNode(triggerBld.GetPos()).owner;

RTTR_FOREACH_PT(Position, region.size)
{
const MapPoint curMapPt = MakeMapPoint(pt + region.startPt);
const unsigned char oldOwner = GetNode(curMapPt).owner;
const unsigned char newOwner = region.GetOwner(pt);
const auto oldOwner = GetNode(curMapPt).owner;
const auto newOwner = region.GetOwner(pt);

// If nothing changed, there is nothing to do (ownerChanged was already initialized)
if(oldOwner == newOwner)
continue;

// rule 1: only take territory from an ally if that ally loses a building - special case: headquarter can
// take territory
const bool ownersAllied = oldOwner > 0 && newOwner > 0 && GetPlayer(oldOwner - 1).IsAlly(newOwner - 1);
if((ownersAllied && (ownerOfTriggerBld != oldOwner || reason == TerritoryChangeReason::Build)
&& triggerBld.GetBuildingType() != BuildingType::Headquarters)
||
// rule 2: do not gain territory when you lose a building (captured or destroyed)
(ownerOfTriggerBld == newOwner && reason != TerritoryChangeReason::Build) ||
// rule 3: do not lose territory when you gain a building (newBuilt or capture)
((ownerOfTriggerBld == oldOwner && oldOwner > 0 && reason == TerritoryChangeReason::Build)
|| (newOwnerOfTriggerBld == oldOwner && reason == TerritoryChangeReason::Captured)))
if(
// rule 1: only take territory from an ally if that ally loses a building
// special case: headquarter can take territory
(ownersAllied && (ownerOfTriggerBld != oldOwner || reason == TerritoryChangeReason::Build) && !isHq) ||
// rule 2: do not gain territory when you lose a building (captured or destroyed)
(ownerOfTriggerBld == newOwner && reason != TerritoryChangeReason::Build) ||
// rule 3: do not lose territory when you gain a building (newBuilt or capture)
((ownerOfTriggerBld == oldOwner && oldOwner > 0 && reason == TerritoryChangeReason::Build)
|| (newOwnerOfTriggerBld == oldOwner && reason == TerritoryChangeReason::Captured)))
{
region.SetOwner(pt, oldOwner);
}
Expand Down
28 changes: 28 additions & 0 deletions tests/s25Main/integration/testTerritoryRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "GamePlayer.h"
#include "PointOutput.h"
#include "RttrForeachPt.h"
#include "buildings/nobHQ.h"
#include "buildings/nobMilitary.h"
#include "factories/BuildingFactory.h"
#include "figures/nofPassiveSoldier.h"
Expand Down Expand Up @@ -310,4 +311,31 @@ BOOST_FIXTURE_TEST_CASE(CreateTerritoryRegion, WorldFixtureEmpty2P)
}
}

BOOST_FIXTURE_TEST_CASE(CreateTerritoryRegionForHQs, WorldFixtureEmpty2P)
{
// All points should belong to the HQ closest with and without improved alliances

const MapPoint hq0Pos = world.GetPlayer(0).GetHQPos();
const MapPoint hq1Pos = world.GetPlayer(1).GetHQPos();
auto distance = hq1Pos.x - hq0Pos.x;

for(const MapPoint pt : world.GetPointsInRadiusWithCenter(hq0Pos, distance / 2))
BOOST_TEST_CONTEXT("pt: " << pt) { BOOST_TEST(world.GetNode(pt).owner == 1); }
for(const MapPoint pt : world.GetPointsInRadiusWithCenter(hq1Pos, distance / 2))
BOOST_TEST_CONTEXT("pt: " << pt) { BOOST_TEST(world.GetNode(pt).owner == 2); }

// Remove HQ 1 and its fire to place it closer to HQ 0
world.DestroyNO(hq1Pos);
world.DestroyNO(hq1Pos);

this->ggs.setSelection(AddonId::NO_ALLIED_PUSH, true);
distance = 7; // Odd number such that there is no point in the same distance to both HQs
const MapPoint newHq1Pos = hq0Pos + MapPoint(distance, 0);
BuildingFactory::CreateBuilding(world, BuildingType::Headquarters, newHq1Pos, 1, Nation::Africans);
for(const MapPoint pt : world.GetPointsInRadiusWithCenter(hq0Pos, distance / 2))
BOOST_TEST_CONTEXT("pt: " << pt) { BOOST_TEST(world.GetNode(pt).owner == 1); }
for(const MapPoint pt : world.GetPointsInRadiusWithCenter(newHq1Pos, distance / 2))
BOOST_TEST_CONTEXT("pt: " << pt) { BOOST_TEST(world.GetNode(pt).owner == 2); }
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 7843b3c

Please sign in to comment.