Skip to content

Commit af28636

Browse files
ottmlFlamefire
authored andcommitted
Return-To-The-Roots#1781 Check if hq is build to work correct with the NO_ALLIED_PUSH addon
1 parent a8dc3da commit af28636

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

libs/s25main/world/GameWorld.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,9 @@ void GameWorld::CleanTerritoryRegion(TerritoryRegion& region, TerritoryChangeRea
578578
const auto newOwnerOfTriggerBld = region.GetOwner(region.GetPosFromMapPos(triggerBld.GetPos()));
579579
// An HQ can be placed independently of the current owner.
580580
// So ensure the HQ position is always considered to belong to the HQ owner
581-
const auto ownerOfTriggerBld = isHq ? newOwnerOfTriggerBld : GetNode(triggerBld.GetPos()).owner;
581+
// if the TerritoryChangeReason is Build
582+
const auto ownerOfTriggerBld =
583+
isHq && reason == TerritoryChangeReason::Build ? newOwnerOfTriggerBld : GetNode(triggerBld.GetPos()).owner;
582584

583585
RTTR_FOREACH_PT(Position, region.size)
584586
{

tests/s25Main/integration/testTerritoryRegion.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,30 @@ BOOST_FIXTURE_TEST_CASE(CreateTerritoryRegionForHQs, WorldFixtureEmpty2P)
338338
BOOST_TEST_CONTEXT("pt: " << pt) { BOOST_TEST(world.GetNode(pt).owner == 2); }
339339
}
340340

341+
// HQ radius = 9
342+
BOOST_FIXTURE_TEST_CASE(CreateTerritoryRegionForDestroyedHQ, WorldFixtureEmpty2P)
343+
{
344+
const MapPoint hq0Pos = world.GetPlayer(0).GetHQPos();
345+
const MapPoint hq1Pos = world.GetPlayer(1).GetHQPos();
346+
auto distance = hq1Pos.x - hq0Pos.x;
347+
348+
for(const MapPoint pt : world.GetPointsInRadiusWithCenter(hq0Pos, distance / 2))
349+
BOOST_TEST_CONTEXT("pt: " << pt) { BOOST_TEST(world.GetNode(pt).owner == 1); }
350+
for(const MapPoint pt : world.GetPointsInRadiusWithCenter(hq1Pos, distance / 2))
351+
BOOST_TEST_CONTEXT("pt: " << pt) { BOOST_TEST(world.GetNode(pt).owner == 2); }
352+
353+
this->ggs.setSelection(AddonId::NO_ALLIED_PUSH, true);
354+
355+
// Remove HQ 1 and its fire
356+
world.DestroyNO(hq1Pos);
357+
world.DestroyNO(hq1Pos);
358+
359+
auto hq0Region = world.GetPointsInRadiusWithCenter(hq0Pos, 9);
360+
RTTR_FOREACH_PT(MapPoint, world.GetSize())
361+
{
362+
auto owner = std::find(std::begin(hq0Region), std::end(hq0Region), pt) != std::end(hq0Region) ? 1 : 0;
363+
BOOST_TEST_CONTEXT("pt: " << pt) { BOOST_TEST(world.GetNode(pt).owner == owner); }
364+
}
365+
}
366+
341367
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)