Replace ResourceType with strings in interfaces/public methods.

This commit is contained in:
Paul Chote
2021-01-25 22:21:48 +00:00
committed by reaperrr
parent dcd8eccee4
commit 80e92849da
21 changed files with 226 additions and 186 deletions

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Warheads
{
public class CreateResourceWarhead : Warhead, IRulesetLoaded<WeaponInfo>
public class CreateResourceWarhead : Warhead
{
[Desc("Size of the area. The resources are seeded within this area.", "Provide 2 values for a ring effect (outer/inner).")]
public readonly int[] Size = { 0, 0 };
@@ -25,16 +25,6 @@ namespace OpenRA.Mods.Common.Warheads
[FieldLoader.Require]
public readonly string AddsResourceType = null;
void IRulesetLoaded<WeaponInfo>.RulesetLoaded(Ruleset rules, WeaponInfo info)
{
var world = rules.Actors["world"];
var resourceType = world.TraitInfos<ResourceTypeInfo>()
.FirstOrDefault(t => t.Type == AddsResourceType);
if (resourceType == null)
throw new YamlException("CreateResourceWarhead defines an invalid resource type '{0}'".F(AddsResourceType));
}
// TODO: Allow maximum resource splatter to be defined. (Per tile, and in total).
public override void DoImpact(in Target target, WarheadArgs args)
{
@@ -53,17 +43,15 @@ namespace OpenRA.Mods.Common.Warheads
var minRange = (Size.Length > 1 && Size[1] > 0) ? Size[1] : 0;
var allCells = world.Map.FindTilesInAnnulus(targetTile, minRange, Size[0]);
var resourceType = world.WorldActor.TraitsImplementing<ResourceType>()
.First(t => t.Info.Type == AddsResourceType);
var resourceLayer = world.WorldActor.Trait<IResourceLayer>();
var maxDensity = resourceLayer.GetMaxDensity(AddsResourceType);
foreach (var cell in allCells)
{
if (!resourceLayer.CanAddResource(resourceType, cell))
if (!resourceLayer.CanAddResource(AddsResourceType, cell))
continue;
var splash = world.SharedRandom.Next(1, resourceType.Info.MaxDensity - resourceLayer.GetResource(cell).Density);
resourceLayer.AddResource(resourceType, cell, splash);
var splash = world.SharedRandom.Next(1, maxDensity - resourceLayer.GetResource(cell).Density);
resourceLayer.AddResource(AddsResourceType, cell, splash);
}
}
}