Add TurnOnIdle.
This commit is contained in:
committed by
abcdefg30
parent
9195356e3a
commit
f33feafd0e
1
AUTHORS
1
AUTHORS
@@ -147,6 +147,7 @@ Also thanks to:
|
|||||||
* Tristan Mühlbacher (MicroBit)
|
* Tristan Mühlbacher (MicroBit)
|
||||||
* UnknownProgrammer
|
* UnknownProgrammer
|
||||||
* Vladimir Komarov (VrKomarov)
|
* Vladimir Komarov (VrKomarov)
|
||||||
|
* Wojciech Walaszek (Voidwalker)
|
||||||
* Wuschel
|
* Wuschel
|
||||||
|
|
||||||
Using GNU FreeFont distributed under the GNU GPL
|
Using GNU FreeFont distributed under the GNU GPL
|
||||||
|
|||||||
62
OpenRA.Mods.Common/Traits/TurnOnIdle.cs
Normal file
62
OpenRA.Mods.Common/Traits/TurnOnIdle.cs
Normal file
@@ -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<MobileInfo>
|
||||||
|
{
|
||||||
|
[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<TurnOnIdleInfo>, 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<Mobile>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -556,6 +556,7 @@
|
|||||||
Voice: Move
|
Voice: Move
|
||||||
Speed: 71
|
Speed: 71
|
||||||
Locomotor: foot
|
Locomotor: foot
|
||||||
|
TurnOnIdle:
|
||||||
Selectable:
|
Selectable:
|
||||||
DecorationBounds: 15,23,0,-9
|
DecorationBounds: 15,23,0,-9
|
||||||
Bounds: 24,24,0,-9
|
Bounds: 24,24,0,-9
|
||||||
|
|||||||
Reference in New Issue
Block a user