let harvester splatter resources when exploding

closes #2346
This commit is contained in:
Matthias Mailänder
2014-05-13 18:52:30 +02:00
parent 3e627d2eba
commit e607c04cce
10 changed files with 86 additions and 12 deletions

View File

@@ -18,7 +18,8 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public static class Combat /* some utility bits that are shared between various things */
// some utility bits that are shared between various things
public static class Combat
{
static string GetImpactSound(WarheadInfo warhead, bool isWater)
{
@@ -49,10 +50,10 @@ namespace OpenRA.Mods.RA
Sound.Play(GetImpactSound(warhead, isWater), pos);
var smudgeLayers = world.WorldActor.TraitsImplementing<SmudgeLayer>().ToDictionary(x => x.Info.Type);
var resLayer = warhead.DestroyResources || !string.IsNullOrEmpty(warhead.AddsResourceType) ? world.WorldActor.Trait<ResourceLayer>() : null;
if (warhead.Size[0] > 0)
{
var resLayer = world.WorldActor.Trait<ResourceLayer>();
var allCells = world.Map.FindTilesInCircle(targetTile, warhead.Size[0]).ToList();
// `smudgeCells` might want to just be an outer shell of the cells:
@@ -76,10 +77,29 @@ namespace OpenRA.Mods.RA
}
// Destroy all resources in range, not just the outer shell:
foreach (var cell in allCells)
{
if (warhead.DestroyResources)
if (warhead.DestroyResources)
foreach (var cell in allCells)
resLayer.Destroy(cell);
// Splatter resources:
if (!string.IsNullOrEmpty(warhead.AddsResourceType))
{
var resourceType = world.WorldActor.TraitsImplementing<ResourceType>()
.FirstOrDefault(t => t.Info.Name == warhead.AddsResourceType);
if (resourceType == null)
Log.Write("debug", "Warhead defines an invalid resource type '{0}'".F(warhead.AddsResourceType));
else
{
foreach (var cell in allCells)
{
if (!resLayer.CanSpawnResourceAt(resourceType, cell))
continue;
var splash = world.SharedRandom.Next(1, resourceType.Info.MaxDensity - resLayer.GetResourceDensity(cell));
resLayer.AddResource(resourceType, cell, splash);
}
}
}
}
else
@@ -202,6 +222,7 @@ namespace OpenRA.Mods.RA
var falloff = (float)GetDamageFalloff(distance * 1f / warhead.Spread.Range);
rawDamage = (float)(falloff * rawDamage);
}
return (float)(rawDamage * modifier * (float)warhead.EffectivenessAgainst(target.Info));
}
}

View File

@@ -63,16 +63,13 @@ namespace OpenRA.Mods.RA
.SkipWhile(p => resLayer.GetResource(p) == resourceType && resLayer.IsFull(p.X, p.Y))
.Cast<CPos?>().FirstOrDefault();
if (cell != null && self.World.Map.IsInMap(cell.Value) &&
(resLayer.GetResource(cell.Value) == resourceType
|| (resLayer.GetResource(cell.Value) == null && resLayer.AllowResourceAt(resourceType, cell.Value))))
if (cell != null && resLayer.CanSpawnResourceAt(resourceType, cell.Value))
resLayer.AddResource(resourceType, cell.Value, 1);
}
static IEnumerable<CPos> RandomWalk(CPos p, MersenneTwister r)
{
for (; ; )
for (;;)
{
var dx = r.Next(-1, 2);
var dy = r.Next(-1, 2);