Change DamagedByTerrain to apply the damage directly.

Instead of relying on a weapon.
This commit is contained in:
Zimmermann Gyula
2016-07-11 13:43:39 +02:00
parent e13fa2d474
commit 4812bc2997
2 changed files with 20 additions and 14 deletions

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2016 The OpenRA Developers (see AUTHORS) * Copyright 2007-2016 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Traits; using OpenRA.Traits;
@@ -16,10 +17,16 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("This actor receives damage from the given weapon when on the specified terrain type.")] [Desc("This actor receives damage from the given weapon when on the specified terrain type.")]
class DamagedByTerrainInfo : UpgradableTraitInfo, IRulesetLoaded, Requires<HealthInfo> class DamagedByTerrainInfo : UpgradableTraitInfo, Requires<HealthInfo>
{ {
[Desc("The weapon which is used to damage the actor.")] [Desc("Amount of damage received per DamageInterval ticks.")]
[WeaponReference, FieldLoader.Require] public readonly string Weapon; [FieldLoader.Require] public readonly int Damage = 0;
[Desc("Delay between receiving damage.")]
public readonly int DamageInterval = 0;
[Desc("Apply the damage using these damagetypes.")]
public readonly HashSet<string> DamageTypes = new HashSet<string>();
[Desc("Terrain types where the actor will take damage.")] [Desc("Terrain types where the actor will take damage.")]
[FieldLoader.Require] public readonly string[] Terrain = { }; [FieldLoader.Require] public readonly string[] Terrain = { };
@@ -30,10 +37,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Inflict damage down to the DamageThreshold when the actor gets created on damaging terrain.")] [Desc("Inflict damage down to the DamageThreshold when the actor gets created on damaging terrain.")]
public readonly bool StartOnThreshold = false; public readonly bool StartOnThreshold = false;
public WeaponInfo WeaponInfo { get; private set; }
public override object Create(ActorInitializer init) { return new DamagedByTerrain(init.Self, this); } public override object Create(ActorInitializer init) { return new DamagedByTerrain(init.Self, this); }
public void RulesetLoaded(Ruleset rules, ActorInfo ai) { WeaponInfo = rules.Weapons[Weapon.ToLowerInvariant()]; }
} }
class DamagedByTerrain : UpgradableTrait<DamagedByTerrainInfo>, ITick, ISync, INotifyAddedToWorld class DamagedByTerrain : UpgradableTrait<DamagedByTerrainInfo>, ITick, ISync, INotifyAddedToWorld
@@ -70,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
// Actors start with maximum damage applied // Actors start with maximum damage applied
var delta = health.HP - damageThreshold; var delta = health.HP - damageThreshold;
if (delta > 0) if (delta > 0)
health.InflictDamage(self, self.World.WorldActor, new Damage(delta), false); self.InflictDamage(self.World.WorldActor, new Damage(delta, Info.DamageTypes));
} }
public void Tick(Actor self) public void Tick(Actor self)
@@ -86,8 +90,8 @@ namespace OpenRA.Mods.Common.Traits
if (!Info.Terrain.Contains(t.Type)) if (!Info.Terrain.Contains(t.Type))
return; return;
Info.WeaponInfo.Impact(Target.FromActor(self), self.World.WorldActor, Enumerable.Empty<int>()); self.InflictDamage(self.World.WorldActor, new Damage(Info.Damage, Info.DamageTypes));
damageTicks = Info.WeaponInfo.ReloadDelay; damageTicks = Info.DamageInterval;
} }
} }
} }

View File

@@ -234,8 +234,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
else else
node.Value.Nodes.Add(new MiniYamlNode("Terrain", new MiniYaml("Tiberium, BlueTiberium"))); node.Value.Nodes.Add(new MiniYamlNode("Terrain", new MiniYaml("Tiberium, BlueTiberium")));
if (!node.Value.Nodes.Any(a => a.Key == "Weapon")) Console.WriteLine("PoisonedByTiberium: Weapon isn't converted. Copy out the appropriate");
node.Value.Nodes.Add(new MiniYamlNode("Weapon", new MiniYaml("Tiberium"))); Console.WriteLine("weapon's Damage, ReloadDelay and DamageTypes to DamagedByTerrain's Damage,");
Console.WriteLine("DamageInterval and DamageTypes, respectively, then remove the Weapon tag.");
} }
} }
@@ -244,8 +245,9 @@ namespace OpenRA.Mods.Common.UtilityCommands
node.Key = node.Key.Replace("DamagedWithoutFoundation", "DamagedByTerrain"); node.Key = node.Key.Replace("DamagedWithoutFoundation", "DamagedByTerrain");
if (!node.Key.StartsWith("-")) if (!node.Key.StartsWith("-"))
{ {
if (!node.Value.Nodes.Any(a => a.Key == "Weapon")) Console.WriteLine("DamagedWithoutFoundation: Weapon isn't converted. Copy out the appropriate");
node.Value.Nodes.Add(new MiniYamlNode("Weapon", new MiniYaml("weathering"))); Console.WriteLine("weapon's Damage, ReloadDelay and DamageTypes to DamagedByTerrain's Damage,");
Console.WriteLine("DamageInterval and DamageTypes, respectively, then remove the Weapon tag.");
Console.WriteLine("SafeTerrain isn't converted. Setup an inverted check using Terrain."); Console.WriteLine("SafeTerrain isn't converted. Setup an inverted check using Terrain.");