Manages dialogue history and usage statistics for a match. It tracks the total number of lines spoken and records the usage count and last occurrence for each dialogue ID.
using System;
using System.Collections.Generic;
namespace Socer;
// One shared rotation for everyone in the match, independent of football RNG.
public sealed class DialogueMemory
{
readonly Dictionary<int,int> counts=new(),last=new();
int sequence;
public int TotalLines=>sequence;
public int UniqueLines=>counts.Count;
public int Uses(int id)=>counts.TryGetValue(id,out var value)?value:0;
public int Last(int id)=>last.TryGetValue(id,out var value)?value:-1000000;
public bool Recent(int id,int gap=32)=>sequence-Last(id)<gap;
public void Record(int id){counts[id]=Uses(id)+1;last[id]=++sequence;}
public static int PersonalAge(Footballer p,int id)
{
for(int ago=0;ago<p.RecentSpeechIds.Length && ago<p.SpeechHistoryCursor;ago++)
{int index=(p.SpeechHistoryCursor-1-ago)%p.RecentSpeechIds.Length;if(p.RecentSpeechIds[index]==id)return ago;}
return 1000000;
}
}