Merge pull request #11407 from reaperrr/ts-infantry-tweaks

Various TS infantry fixes
This commit is contained in:
abcdefg30
2016-06-12 14:42:12 +02:00
committed by GitHub
16 changed files with 405 additions and 1405 deletions

View File

@@ -332,6 +332,7 @@
<Compile Include="Traits\EmitInfantryOnSell.cs" />
<Compile Include="Traits\EngineerRepair.cs" />
<Compile Include="Traits\Explodes.cs" />
<Compile Include="Traits\ExplosionOnDamageTransition.cs" />
<Compile Include="Traits\ExternalCapturable.cs" />
<Compile Include="Traits\ExternalCapturableBar.cs" />
<Compile Include="Traits\ExternalCaptures.cs" />

View File

@@ -0,0 +1,70 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Mods.Common.Warheads;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("This actor triggers an explosion on itself when transitioning to a specific damage state.")]
public class ExplosionOnDamageTransitionInfo : ITraitInfo, IRulesetLoaded, Requires<HealthInfo>
{
[WeaponReference, FieldLoader.Require, Desc("Weapon to use for explosion.")]
public readonly string Weapon = null;
[Desc("At which damage state explosion will trigger.")]
public readonly DamageState DamageState = DamageState.Heavy;
[Desc("Should the explosion only be triggered once?")]
public readonly bool TriggerOnlyOnce = false;
public WeaponInfo WeaponInfo { get; private set; }
public object Create(ActorInitializer init) { return new ExplosionOnDamageTransition(this, init.Self); }
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
WeaponInfo = string.IsNullOrEmpty(Weapon) ? null : rules.Weapons[Weapon.ToLowerInvariant()];
}
}
public class ExplosionOnDamageTransition : INotifyDamageStateChanged
{
readonly ExplosionOnDamageTransitionInfo info;
bool triggered;
public ExplosionOnDamageTransition(ExplosionOnDamageTransitionInfo info, Actor self)
{
this.info = info;
}
public void DamageStateChanged(Actor self, AttackInfo e)
{
if (!self.IsInWorld)
return;
if (triggered)
return;
if (e.DamageState >= info.DamageState && e.PreviousDamageState < info.DamageState)
{
if (info.TriggerOnlyOnce)
triggered = true;
// Use .FromPos since the actor might have been killed, don't use Target.FromActor
info.WeaponInfo.Impact(Target.FromPos(self.CenterPosition), e.Attacker, Enumerable.Empty<int>());
}
}
}
}

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits.Render
[FieldLoader.LoadUsing("LoadDeathTypes")]
[Desc("Death animation to use for each damage type (defined on the warheads).",
"Is only used if UseDeathTypeSuffix is `True`.")]
public readonly Dictionary<string, int> DeathTypes = new Dictionary<string, int>();
public readonly Dictionary<string, string> DeathTypes = new Dictionary<string, string>();
[Desc("Sequence to use when the actor is killed by some non-standard means (e.g. suicide).")]
[SequenceReference] public readonly string FallbackSequence = null;
@@ -54,8 +54,8 @@ namespace OpenRA.Mods.Common.Traits.Render
var md = yaml.ToDictionary();
return md.ContainsKey("DeathTypes")
? md["DeathTypes"].ToDictionary(my => FieldLoader.GetValue<int>("(value)", my.Value))
: new Dictionary<string, int>();
? md["DeathTypes"].ToDictionary(my => FieldLoader.GetValue<string>("(value)", my.Value))
: new Dictionary<string, string>();
}
public object Create(ActorInitializer init) { return new WithDeathAnimation(init.Self, this); }

View File

@@ -29,6 +29,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Levels of damage at which to grant upgrades.")]
public readonly DamageState ValidDamageStates = DamageState.Heavy | DamageState.Critical;
[Desc("Are upgrades irrevocable once the conditions have been met?")]
public readonly bool GrantPermanently = false;
public object Create(ActorInitializer init) { return new UpgradeOnDamage(init.Self, this); }
}
@@ -36,6 +39,7 @@ namespace OpenRA.Mods.Common.Traits
{
readonly UpgradeOnDamageInfo info;
readonly UpgradeManager um;
bool granted;
public UpgradeOnDamage(Actor self, UpgradeOnDamageInfo info)
{
@@ -43,12 +47,14 @@ namespace OpenRA.Mods.Common.Traits
um = self.TraitOrDefault<UpgradeManager>();
}
bool granted;
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{
if (um == null)
return;
if (granted && info.GrantPermanently)
return;
var rand = Game.CosmeticRandom;
if (!granted && info.ValidDamageStates.HasFlag(e.DamageState) && !info.ValidDamageStates.HasFlag(e.PreviousDamageState))
{