AI Wander & Barker (#286)

* Retrofit the AI system with new IoC features.
Fixed bug with turret rotation.

* Added new AI WanderProcessor, and it works.

* RNG walking directions are a bit more random now.

* Wander now actually uses the MoverSystem to move.
Wander now talks when he reaches his destination.

* Adds a new Static Barker AI for vending machines, so that they periodically advertise their brand.

* Barker now says some generic slogans.
Misc bug cleanup.

* Removed useless UsedImplicitly attribute from AI dependencies, suppressed unused variable warnings instead.
This commit is contained in:
Acruid
2019-08-10 05:19:52 -07:00
committed by Pieter-Jan Briers
parent 4b30c7e710
commit 8b593d28c6
8 changed files with 464 additions and 26 deletions

View File

@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Content.Server.Interfaces.Chat;
using JetBrains.Annotations;
using Robust.Server.AI;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Utility;
namespace Content.Server.AI
{
/// <summary>
/// Designed for a a stationary entity that regularly advertises things (vending machine).
/// </summary>
[AiLogicProcessor("StaticBarker")]
class StaticBarkerProcessor : AiLogicProcessor
{
#pragma warning disable 649
[Dependency] private readonly IGameTiming _timeMan;
[Dependency] private readonly IChatManager _chatMan;
#pragma warning restore 649
private static readonly TimeSpan MinimumDelay = TimeSpan.FromSeconds(15);
private TimeSpan _nextBark;
private static List<string> slogans = new List<string>
{
"Come try my great products today!",
"More value for the way you live.",
"Quality you'd expect at prices you wouldn't.",
"The right stuff. The right price.",
};
public override void Update(float frameTime)
{
if(_timeMan.CurTime < _nextBark)
return;
var rngState = GenSeed();
_nextBark = _timeMan.CurTime + MinimumDelay + TimeSpan.FromSeconds(Random01(ref rngState) * 10);
var pick = (int)Math.Round(Random01(ref rngState) * (slogans.Count - 1));
_chatMan.EntitySay(SelfEntity, slogans[pick]);
}
private uint GenSeed()
{
return RotateRight((uint)_timeMan.CurTick.GetHashCode(), 11) ^ (uint)SelfEntity.Uid.GetHashCode();
}
private uint RotateRight(uint n, int s)
{
return (n << (32 - s)) | (n >> s);
}
private float Random01(ref uint state)
{
DebugTools.Assert(state != 0);
//xorshift32
state ^= state << 13;
state ^= state >> 17;
state ^= state << 5;
return state / (float)uint.MaxValue;
}
}
}