diff --git a/AUTHORS b/AUTHORS index 723ecb8a09..aee8fcc5f1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -147,6 +147,7 @@ Also thanks to: * Tristan Mühlbacher (MicroBit) * UnknownProgrammer * Vladimir Komarov (VrKomarov) + * Wojciech Walaszek (Voidwalker) * Wuschel Using GNU FreeFont distributed under the GNU GPL diff --git a/OpenRA.Mods.Common/Traits/TurnOnIdle.cs b/OpenRA.Mods.Common/Traits/TurnOnIdle.cs new file mode 100644 index 0000000000..c3ed48c3fe --- /dev/null +++ b/OpenRA.Mods.Common/Traits/TurnOnIdle.cs @@ -0,0 +1,62 @@ +#region Copyright & License Information +/* + * Copyright 2007-2020 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 OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Turns actor randomly when idle.")] + class TurnOnIdleInfo : ConditionalTraitInfo, Requires + { + [Desc("Minimum amount of ticks the actor will wait before the turn.")] + public readonly int MinDelay = 400; + + [Desc("Maximum amount of ticks the actor will wait before the turn.")] + public readonly int MaxDelay = 800; + + public override object Create(ActorInitializer init) { return new TurnOnIdle(init, this); } + } + + class TurnOnIdle : ConditionalTrait, INotifyIdle + { + int currentDelay; + int targetFacing; + readonly Mobile mobile; + + public TurnOnIdle(ActorInitializer init, TurnOnIdleInfo info) + : base(info) + { + currentDelay = init.World.SharedRandom.Next(Info.MinDelay, Info.MaxDelay); + mobile = init.Self.Trait(); + targetFacing = mobile.Facing; + } + + void INotifyIdle.TickIdle(Actor self) + { + if (IsTraitDisabled) + return; + + if (mobile.IsTraitDisabled || mobile.IsTraitPaused) + return; + + if (--currentDelay > 0) + return; + + if (targetFacing == mobile.Facing) + { + targetFacing = self.World.SharedRandom.Next(256); + currentDelay = self.World.SharedRandom.Next(Info.MinDelay, Info.MaxDelay); + } + + mobile.Facing = Util.TickFacing(mobile.Facing, targetFacing, mobile.TurnSpeed); + } + } +} diff --git a/mods/ts/rules/defaults.yaml b/mods/ts/rules/defaults.yaml index cd2d6482ef..c2bb51ace8 100644 --- a/mods/ts/rules/defaults.yaml +++ b/mods/ts/rules/defaults.yaml @@ -556,6 +556,7 @@ Voice: Move Speed: 71 Locomotor: foot + TurnOnIdle: Selectable: DecorationBounds: 15,23,0,-9 Bounds: 24,24,0,-9