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

@@ -24,6 +24,8 @@ namespace OpenRA.GameRules
public readonly Dictionary<string, float> Versus; public readonly Dictionary<string, float> Versus;
[Desc("Can this damage resource patches?")] [Desc("Can this damage resource patches?")]
public readonly bool DestroyResources = false; public readonly bool DestroyResources = false;
[Desc("Will this splatter resources and which?")]
public readonly string AddsResourceType = null;
[Desc("Explosion effect to use.")] [Desc("Explosion effect to use.")]
public readonly string Explosion = null; public readonly string Explosion = null;
[Desc("Palette to use for explosion effect.")] [Desc("Palette to use for explosion effect.")]

View File

@@ -153,6 +153,13 @@ namespace OpenRA.Traits
return true; return true;
} }
public bool CanSpawnResourceAt(ResourceType newResourceType, CPos cell)
{
var currentResourceType = GetResource(cell);
return currentResourceType == newResourceType
|| (currentResourceType == null && AllowResourceAt(newResourceType, cell));
}
CellContents CreateResourceCell(ResourceType t, CPos p) CellContents CreateResourceCell(ResourceType t, CPos p)
{ {
world.Map.CustomTerrain[p.X, p.Y] = world.TileSet.GetTerrainIndex(t.Info.TerrainType); world.Map.CustomTerrain[p.X, p.Y] = world.TileSet.GetTerrainIndex(t.Info.TerrainType);

View File

@@ -18,7 +18,8 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA 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) static string GetImpactSound(WarheadInfo warhead, bool isWater)
{ {
@@ -49,10 +50,10 @@ namespace OpenRA.Mods.RA
Sound.Play(GetImpactSound(warhead, isWater), pos); Sound.Play(GetImpactSound(warhead, isWater), pos);
var smudgeLayers = world.WorldActor.TraitsImplementing<SmudgeLayer>().ToDictionary(x => x.Info.Type); 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) if (warhead.Size[0] > 0)
{ {
var resLayer = world.WorldActor.Trait<ResourceLayer>();
var allCells = world.Map.FindTilesInCircle(targetTile, warhead.Size[0]).ToList(); var allCells = world.Map.FindTilesInCircle(targetTile, warhead.Size[0]).ToList();
// `smudgeCells` might want to just be an outer shell of the cells: // `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: // Destroy all resources in range, not just the outer shell:
foreach (var cell in allCells) if (warhead.DestroyResources)
{ foreach (var cell in allCells)
if (warhead.DestroyResources)
resLayer.Destroy(cell); 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 else
@@ -202,6 +222,7 @@ namespace OpenRA.Mods.RA
var falloff = (float)GetDamageFalloff(distance * 1f / warhead.Spread.Range); var falloff = (float)GetDamageFalloff(distance * 1f / warhead.Spread.Range);
rawDamage = (float)(falloff * rawDamage); rawDamage = (float)(falloff * rawDamage);
} }
return (float)(rawDamage * modifier * (float)warhead.EffectivenessAgainst(target.Info)); 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)) .SkipWhile(p => resLayer.GetResource(p) == resourceType && resLayer.IsFull(p.X, p.Y))
.Cast<CPos?>().FirstOrDefault(); .Cast<CPos?>().FirstOrDefault();
if (cell != null && self.World.Map.IsInMap(cell.Value) && if (cell != null && resLayer.CanSpawnResourceAt(resourceType, cell.Value))
(resLayer.GetResource(cell.Value) == resourceType
|| (resLayer.GetResource(cell.Value) == null && resLayer.AllowResourceAt(resourceType, cell.Value))))
resLayer.AddResource(resourceType, cell.Value, 1); resLayer.AddResource(resourceType, cell.Value, 1);
} }
static IEnumerable<CPos> RandomWalk(CPos p, MersenneTwister r) static IEnumerable<CPos> RandomWalk(CPos p, MersenneTwister r)
{ {
for (; ; ) for (;;)
{ {
var dx = r.Next(-1, 2); var dx = r.Next(-1, 2);
var dy = r.Next(-1, 2); var dy = r.Next(-1, 2);

View File

@@ -71,6 +71,8 @@ HARV:
HuskActor: HARV.Husk HuskActor: HARV.Husk
-GainsExperience: -GainsExperience:
RenderHarvester: RenderHarvester:
Explodes:
Weapon: TiberiumExplosion
APC: APC:
Inherits: ^Tank Inherits: ^Tank

View File

@@ -877,6 +877,21 @@ Tiberium:
Damage: 2 Damage: 2
PreventProne: yes PreventProne: yes
TiberiumExplosion:
Warhead:
Damage: 10
Spread: 9
Size: 1,1
Versus:
None: 90%
Wood: 75%
Light: 60%
Heavy: 25%
Explosion: chemball
InfDeath: 3
ImpactSound: xplosml2.aud
AddsResourceType: Tiberium
Heal: Heal:
ROF: 4 ROF: 4
Warhead: Warhead:

View File

@@ -77,7 +77,7 @@ HARVESTER:
RevealsShroud: RevealsShroud:
Range: 4c0 Range: 4c0
Explodes: Explodes:
Weapon: UnitExplodeScale Weapon: SpiceExplosion
EmptyWeapon: UnitExplodeScale EmptyWeapon: UnitExplodeScale
LeavesHusk: LeavesHusk:
HuskActor: Harvester.Husk HuskActor: Harvester.Husk

View File

@@ -649,3 +649,18 @@ Shrapnel:
Damage: 60 Damage: 60
ImpactSound: EXPLLG5.WAV ImpactSound: EXPLLG5.WAV
SpiceExplosion:
Warhead:
Damage: 10
Spread: 9
Size: 2,2
Versus:
None: 90%
Wood: 75%
Light: 60%
Heavy: 25%
Explosion: med_explosion
InfDeath: 3
ImpactSound: EXPLLG5.WAV
AddsResourceType: Spice

View File

@@ -285,7 +285,7 @@ HARV:
FullHuskActor: HARV.FullHusk FullHuskActor: HARV.FullHusk
FullnessThreshold: 50 FullnessThreshold: 50
Explodes: Explodes:
Weapon: UnitExplodeSmall Weapon: OreExplosion
EmptyWeapon: UnitExplodeSmall EmptyWeapon: UnitExplodeSmall
MCV: MCV:

View File

@@ -1360,3 +1360,18 @@ MADTankDetonate:
ImpactSound: mineblo1.aud ImpactSound: mineblo1.aud
SmudgeType: Crater SmudgeType: Crater
OreExplosion:
Warhead:
Damage: 10
Spread: 9
Size: 1,1
Versus:
None: 90%
Wood: 75%
Light: 60%
Heavy: 25%
Explosion: med_explosion
InfDeath: 3
ImpactSound: kaboom25.aud
AddsResourceType: Ore