Fix resource calculation in map generator

The editor's resource value calculation logic was fixed in #21820 to
match actual gameplay. The map generator logic originally copied the
editor logic from EditorResourceLayer rather than ResourceLayer and
associated game logic. As such, it inherited incorrect calculations.

This change updates the map generator logic to match the now
consistent logic in both ResourceLayer classes. Map generator resource
settings are also adjusted -25% to continue roughly matching the
previous resource output.
This commit is contained in:
Ashley Newson
2025-04-30 01:06:27 +01:00
committed by Gustas Kažukauskas
parent 965a490b70
commit 4a4217c3b3
3 changed files with 24 additions and 23 deletions

View File

@@ -1681,8 +1681,7 @@ namespace OpenRA.Mods.Common.Traits
map.Resources.Clear(); map.Resources.Clear();
// Return resource value of a given square. // Return resource value of a given square.
// See https://github.com/OpenRA/OpenRA/blob/9302bac6199fbc925a85fd7a08fc2ba4b9317d16/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs#L144-L166 // Matches the logic in ResourceLayer trait.
// https://github.com/OpenRA/OpenRA/blob/9302bac6199fbc925a85fd7a08fc2ba4b9317d16/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs#L175-L183
int CheckValue(CPos cpos) int CheckValue(CPos cpos)
{ {
if (!map.Resources.Contains(cpos)) if (!map.Resources.Contains(cpos))
@@ -1690,22 +1689,24 @@ namespace OpenRA.Mods.Common.Traits
var resource = map.Resources[cpos].Type; var resource = map.Resources[cpos].Type;
if (resource == 0) if (resource == 0)
return 0; return 0;
var adjacent = 0;
for (var y = -1; y <= 1; y++)
for (var x = -1; x <= 1; x++)
{
var offsetCpos = cpos + new CVec(x, y);
if (!map.Resources.Contains(offsetCpos))
continue;
if (map.Resources[offsetCpos].Type == resource)
adjacent++;
}
var resourceType = bestResource[cpos]; var resourceType = bestResource[cpos];
var density = Math.Max(resourceType.MaxDensity * adjacent / /*maxAdjacent=*/9, 1);
// density + 1 to mirror a bug that got ossified due to balancing. var adjacent = 0;
return param.ResourceValues[resourceType] * (density + 1); var directions = CVec.Directions;
for (var i = 0; i < directions.Length; i++)
{
var c = cpos + directions[i];
if (map.Resources.Contains(c) && map.Resources[c].Type == resource)
++adjacent;
}
// We need to have at least one resource in the cell.
// HACK: we should not be lerping to 9, as maximum adjacent resources is 8.
// HACK: it's too disruptive to fix.
var density = Math.Max(int2.Lerp(0, resourceType.MaxDensity, adjacent, 9), 1);
return param.ResourceValues[resourceType] * density;
} }
int CheckValue3By3(CPos cpos) int CheckValue3By3(CPos cpos)

View File

@@ -268,7 +268,7 @@
Label: label-cnc-map-generator-choice-resources-low Label: label-cnc-map-generator-choice-resources-low
Settings: Settings:
SpawnResourceSpawns: 1 SpawnResourceSpawns: 1
ResourcesPerPlayer: 25000 ResourcesPerPlayer: 18750
ResourceSpawnWeights: ResourceSpawnWeights:
split2: 1 split2: 1
split3: 1 split3: 1
@@ -278,7 +278,7 @@
Label: label-cnc-map-generator-choice-resources-medium Label: label-cnc-map-generator-choice-resources-medium
Settings: Settings:
SpawnResourceSpawns: 2 SpawnResourceSpawns: 2
ResourcesPerPlayer: 50000 ResourcesPerPlayer: 37500
ResourceSpawnWeights: ResourceSpawnWeights:
split2: 95 split2: 95
split3: 95 split3: 95
@@ -289,7 +289,7 @@
Label: label-cnc-map-generator-choice-resources-high Label: label-cnc-map-generator-choice-resources-high
Settings: Settings:
SpawnResourceSpawns: 3 SpawnResourceSpawns: 3
ResourcesPerPlayer: 75000 ResourcesPerPlayer: 56250
ResourceSpawnWeights: ResourceSpawnWeights:
split2: 9 split2: 9
split3: 9 split3: 9
@@ -300,7 +300,7 @@
Label: label-cnc-map-generator-choice-resources-very-high Label: label-cnc-map-generator-choice-resources-very-high
Settings: Settings:
SpawnResourceSpawns: 4 SpawnResourceSpawns: 4
ResourcesPerPlayer: 100000 ResourcesPerPlayer: 75000
ResourceSpawnWeights: ResourceSpawnWeights:
split2: 8 split2: 8
split3: 8 split3: 8

View File

@@ -295,7 +295,7 @@
Label: label-ra-map-generator-choice-resources-low Label: label-ra-map-generator-choice-resources-low
Settings: Settings:
SpawnResourceSpawns: 2 SpawnResourceSpawns: 2
ResourcesPerPlayer: 25000 ResourcesPerPlayer: 18750
ResourceSpawnWeights: ResourceSpawnWeights:
mine: 1 mine: 1
MaximumExpansionResourceSpawns: 3 MaximumExpansionResourceSpawns: 3
@@ -304,7 +304,7 @@
Label: label-ra-map-generator-choice-resources-medium Label: label-ra-map-generator-choice-resources-medium
Settings: Settings:
SpawnResourceSpawns: 3 SpawnResourceSpawns: 3
ResourcesPerPlayer: 50000 ResourcesPerPlayer: 37500
ResourceSpawnWeights: ResourceSpawnWeights:
mine: 95 mine: 95
gmine: 5 gmine: 5
@@ -314,7 +314,7 @@
Label: label-ra-map-generator-choice-resources-high Label: label-ra-map-generator-choice-resources-high
Settings: Settings:
SpawnResourceSpawns: 3 SpawnResourceSpawns: 3
ResourcesPerPlayer: 75000 ResourcesPerPlayer: 56250
ResourceSpawnWeights: ResourceSpawnWeights:
mine: 9 mine: 9
gmine: 1 gmine: 1
@@ -324,7 +324,7 @@
Label: label-ra-map-generator-choice-resources-very-high Label: label-ra-map-generator-choice-resources-very-high
Settings: Settings:
SpawnResourceSpawns: 4 SpawnResourceSpawns: 4
ResourcesPerPlayer: 100000 ResourcesPerPlayer: 75000
ResourceSpawnWeights: ResourceSpawnWeights:
mine: 8 mine: 8
gmine: 2 gmine: 2