Game no longer crashes if no ResourceLayer is used.

This commit is contained in:
Andre Mohren
2017-09-29 14:22:27 +02:00
committed by reaperrr
parent d64a9e6afc
commit 4e45747b41
2 changed files with 4 additions and 4 deletions

View File

@@ -230,10 +230,10 @@ namespace OpenRA.Mods.Common.Orders
foreach (var r in previewRenderables)
yield return r;
var res = world.WorldActor.Trait<ResourceLayer>();
var res = world.WorldActor.TraitOrDefault<ResourceLayer>();
var isCloseEnough = buildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, building, topLeft);
foreach (var t in buildingInfo.Tiles(topLeft))
cells.Add(t, MakeCellType(isCloseEnough && world.IsCellBuildable(t, buildingInfo) && res.GetResource(t) == null));
cells.Add(t, MakeCellType(isCloseEnough && world.IsCellBuildable(t, buildingInfo) && (res == null || res.GetResource(t) == null)));
}
var cellPalette = wr.Palette(placeBuildingInfo.Palette);

View File

@@ -43,9 +43,9 @@ namespace OpenRA.Mods.Common.Traits
if (building.AllowInvalidPlacement)
return true;
var res = world.WorldActor.Trait<ResourceLayer>();
var res = world.WorldActor.TraitOrDefault<ResourceLayer>();
return building.Tiles(topLeft).All(
t => world.Map.Contains(t) && res.GetResource(t) == null &&
t => world.Map.Contains(t) && (res == null || res.GetResource(t) == null) &&
world.IsCellBuildable(t, building, toIgnore));
}