{"record":{"id":"24b72e7cad55c784","repo":"OpenRA/OpenRA","slug":"buildingweights-must-be-0","errorCode":null,"errorMessage":"BuildingWeights.* must be >= 0","messagePattern":"BuildingWeights\\.\\* must be >= 0","errorType":"exception","errorClass":"MapGenerationException","httpStatus":null,"severity":"error","filePath":"OpenRA.Mods.Common/Traits/World/ClassicMapGenerator.cs","lineNumber":408,"sourceCode":"\t\t\t\tif (MinimumBuildings > MaximumBuildings)\n\t\t\t\t\tthrow new MapGenerationException(\"MinimumBuildings must be <= maximumBuildings\");\n\t\t\t\tif (CivilianBuildings < 0 || CivilianBuildings > FractionMax)\n\t\t\t\t\tthrow new MapGenerationException($\"CivilianBuildings must be between 0 and {FractionMax} inclusive\");\n\t\t\t\tif (CivilianBuildingDensity < 0 || CivilianBuildingDensity > FractionMax)\n\t\t\t\t\tthrow new MapGenerationException($\"CivilianBuildingDensity must be between 0 and {FractionMax} inclusive\");\n\t\t\t\tif (MinimumCivilianBuildingDensity < 0 || MinimumCivilianBuildingDensity > FractionMax)\n\t\t\t\t\tthrow new MapGenerationException($\"MinimumCivilianBuildingDensity must be between 0 and {FractionMax} inclusive\");\n\t\t\t\tif (CivilianBuildingDensityRadius < 0)\n\t\t\t\t\tthrow new MapGenerationException(\"CivilianBuildingDensityRadius must be >= 0\");\n\t\t\t\tif (ResourcesPerPlayer < 0)\n\t\t\t\t\tthrow new MapGenerationException(\"ResourcesPerPlayer must be >= 0\");\n\t\t\t\tif (OreUniformity < 0)\n\t\t\t\t\tthrow new MapGenerationException(\"OreUniformity must be >= 0\");\n\t\t\t\tif (OreClumpiness < 0)\n\t\t\t\t\tthrow new MapGenerationException(\"OreClumpiness must be >= 0\");\n\t\t\t\tforeach (var kv in BuildingWeights)\n\t\t\t\t\tif (kv.Value < 0)\n\t\t\t\t\t\tthrow new MapGenerationException(\"BuildingWeights.* must be >= 0\");\n\t\t\t\tforeach (var kv in ResourceSpawnWeights)\n\t\t\t\t\tif (kv.Value < 0)\n\t\t\t\t\t\tthrow new MapGenerationException(\"ResourceSpawnWeights.* must be >= 0\");\n\t\t\t\tforeach (var kv in ResourceSpawnWeights)\n\t\t\t\t\tif (!ResourceSpawnSeeds.ContainsKey(kv.Key))\n\t\t\t\t\t\tthrow new MapGenerationException($\"ResourceSpawnSeeds does not contain possible resource spawn `{kv.Key}`\");\n\n\t\t\t\tif (!(terrainInfo.Templates.TryGetValue(LandTile, out var landTemplate) && landTemplate.Contains(0)))\n\t\t\t\t\tthrow new MapGenerationException(\"LandTile is not valid\");\n\t\t\t\tif (!(terrainInfo.Templates.TryGetValue(LandTile, out var waterTemplate) && waterTemplate.Contains(0)))\n\t\t\t\t\tthrow new MapGenerationException(\"WaterTile is not valid\");\n\n\t\t\t\tif (Players > 32)\n\t\t\t\t\tthrow new MapGenerationException(\"Total number of players must not exceed 32\");\n\n\t\t\t\tvar symmetryCount = Symmetry.RotateAndMirrorProjectionCount(Rotations, Mirror);\n\t\t\t\tif (Players % symmetryCount != 0)\n\t\t\t\t\tthrow new MapGenerationException($\"Total number of players must be a multiple of {symmetryCount}\");","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/OpenRA/OpenRA/blob/a520984d91eda9de48a62b1d15c1e3bad0d4fb1a/OpenRA.Mods.Common/Traits/World/ClassicMapGenerator.cs#L390-L426","documentation":"Thrown when any value in the BuildingWeights dictionary is negative. BuildingWeights maps civilian building actor/obstacle keys to integer selection weights; a negative weight is invalid for the weighted-random placement. The '*' in the message denotes 'any key'.","triggerScenarios":"Map generation with a BuildingWeights yaml sub-node containing an entry whose integer value is negative, e.g. 'BuildingWeights: { Tower: -2 }'.","commonSituations":"Hand-editing the weights to suppress a building and using a negative number instead of 0; or a stray minus sign in the yaml.","solutions":["Set every BuildingWeights entry to 0 or a positive integer (use 0 to effectively exclude a building).","Remove entries you do not want rather than negating them."],"exampleFix":"# before\nBuildingWeights:\n  HOUSE: 10\n  TOWER: -2\n# after\nBuildingWeights:\n  HOUSE: 10\n  TOWER: 0","handlingStrategy":"validation","validationCode":"foreach (var kv in param.BuildingWeights)\n    if (kv.Value < 0)\n        throw new InvalidOperationException($\"BuildingWeights[{kv.Key}] must be >= 0\");","typeGuard":"static bool BuildingWeightsOk(ClassicMapGeneratorInfo.Parameters p) => p.BuildingWeights.All(kv => kv.Value >= 0);","tryCatchPattern":"try { mapGenerator.Generate(modData, args); }\ncatch (MapGenerationException ex) when (ex.Message.Contains(\"BuildingWeights.*\"))\n{ /* set every weight to 0 or positive; 0 excludes a building */ }","preventionTips":["Use 0 to exclude a building, never a negative weight.","Remove unwanted entries entirely rather than negating them."],"tags":["openra","map-generation","yaml-config","validation","dictionary","weights"],"backgroundTag":null,"analyzedSha":"a520984d91eda9de48a62b1d15c1e3bad0d4fb1a","analyzedAt":"2026-08-13T15:30:14.787Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}