Try to make random designs in automation stick around when redrawing/changing zone.

This commit is contained in:
Ottermandias 2024-11-30 22:11:06 +01:00
parent 467dc2c22f
commit c9febe2c74
7 changed files with 23 additions and 23 deletions

View file

@ -152,7 +152,7 @@ public sealed class AutoDesignApplier : IDisposable
{
if (_state.GetOrCreate(id, data.Objects[0], out var state))
{
Reduce(data.Objects[0], state, newSet, _config.RespectManualOnAutomationUpdate, false, out var forcedRedraw);
Reduce(data.Objects[0], state, newSet, _config.RespectManualOnAutomationUpdate, false, true, out var forcedRedraw);
foreach (var actor in data.Objects)
_state.ReapplyState(actor, forcedRedraw, StateSource.Fixed);
}
@ -164,7 +164,7 @@ public sealed class AutoDesignApplier : IDisposable
var specificId = actor.GetIdentifier(_actors);
if (_state.GetOrCreate(specificId, actor, out var state))
{
Reduce(actor, state, newSet, _config.RespectManualOnAutomationUpdate, false, out var forcedRedraw);
Reduce(actor, state, newSet, _config.RespectManualOnAutomationUpdate, false, true, out var forcedRedraw);
_state.ReapplyState(actor, forcedRedraw, StateSource.Fixed);
}
}
@ -212,7 +212,7 @@ public sealed class AutoDesignApplier : IDisposable
var respectManual = state.LastJob == newJob.Id;
state.LastJob = actor.Job;
Reduce(actor, state, set, respectManual, true, out var forcedRedraw);
Reduce(actor, state, set, respectManual, true, true, out var forcedRedraw);
_state.ReapplyState(actor, forcedRedraw, StateSource.Fixed);
}
@ -226,7 +226,7 @@ public sealed class AutoDesignApplier : IDisposable
_state.ResetState(state, StateSource.Game);
if (GetPlayerSet(identifier, out var set))
Reduce(actor, state, set, false, false, out forcedRedraw);
Reduce(actor, state, set, false, false, false, out forcedRedraw);
}
public bool Reduce(Actor actor, ActorIdentifier identifier, [NotNullWhen(true)] out ActorState? state)
@ -253,11 +253,11 @@ public sealed class AutoDesignApplier : IDisposable
var respectManual = !state.UpdateTerritory(_clientState.TerritoryType) || !_config.RevertManualChangesOnZoneChange;
if (!respectManual)
_state.ResetState(state, StateSource.Game);
Reduce(actor, state, set, respectManual, false, out _);
Reduce(actor, state, set, respectManual, false, false, out _);
return true;
}
private unsafe void Reduce(Actor actor, ActorState state, AutoDesignSet set, bool respectManual, bool fromJobChange, out bool forcedRedraw)
private unsafe void Reduce(Actor actor, ActorState state, AutoDesignSet set, bool respectManual, bool fromJobChange, bool newApplication, out bool forcedRedraw)
{
if (set.BaseState is AutoDesignSet.Base.Game)
{
@ -284,7 +284,7 @@ public sealed class AutoDesignApplier : IDisposable
var mergedDesign = _designMerger.Merge(
set.Designs.Where(d => d.IsActive(actor))
.SelectMany(d => d.Design.AllLinks.Select(l => (l.Design, l.Flags & d.Type, d.Jobs.Flags))),
.SelectMany(d => d.Design.AllLinks(newApplication).Select(l => (l.Design, l.Flags & d.Type, d.Jobs.Flags))),
state.ModelData.Customize, state.BaseData, true, _config.AlwaysApplyAssociatedMods);
_state.ApplyDesign(state, mergedDesign, new ApplySettings(0, StateSource.Fixed, respectManual, fromJobChange, false, false, false));
@ -337,7 +337,7 @@ public sealed class AutoDesignApplier : IDisposable
var respectManual = prior == id;
NewGearsetId = id;
Reduce(data.Objects[0], state, set, respectManual, job != state.LastJob, out var forcedRedraw);
Reduce(data.Objects[0], state, set, respectManual, job != state.LastJob, prior == id, out var forcedRedraw);
NewGearsetId = -1;
foreach (var actor in data.Objects)
_state.ReapplyState(actor, forcedRedraw, StateSource.Fixed);

View file

@ -58,7 +58,7 @@ public sealed class Design : DesignBase, ISavable, IDesignStandIn
public string Incognito
=> Identifier.ToString()[..8];
public IEnumerable<(IDesignStandIn Design, ApplicationType Flags, JobFlag Jobs)> AllLinks
public IEnumerable<(IDesignStandIn Design, ApplicationType Flags, JobFlag Jobs)> AllLinks(bool newApplication)
=> LinkContainer.GetAllLinks(this).Select(t => ((IDesignStandIn)t.Link.Link, t.Link.Type, JobFlag.All));
#endregion

View file

@ -16,7 +16,7 @@ public interface IDesignStandIn : IEquatable<IDesignStandIn>
public string SerializeName();
public StateSource AssociatedSource();
public IEnumerable<(IDesignStandIn Design, ApplicationType Flags, JobFlag Jobs)> AllLinks { get; }
public IEnumerable<(IDesignStandIn Design, ApplicationType Flags, JobFlag Jobs)> AllLinks(bool newApplication);
public void AddData(JObject jObj);

View file

@ -39,8 +39,8 @@ public class QuickSelectedDesign(QuickDesignCombo combo) : IDesignStandIn, IServ
public StateSource AssociatedSource()
=> StateSource.Manual;
public IEnumerable<(IDesignStandIn Design, ApplicationType Flags, JobFlag Jobs)> AllLinks
=> combo.Design?.AllLinks ?? [];
public IEnumerable<(IDesignStandIn Design, ApplicationType Flags, JobFlag Jobs)> AllLinks(bool newApplication)
=> combo.Design?.AllLinks(newApplication) ?? [];
public void AddData(JObject jObj)
{ }

View file

@ -46,17 +46,17 @@ public class RandomDesign(RandomDesignGenerator rng) : IDesignStandIn
public StateSource AssociatedSource()
=> StateSource.Manual;
public IEnumerable<(IDesignStandIn Design, ApplicationType Flags, JobFlag Jobs)> AllLinks
public IEnumerable<(IDesignStandIn Design, ApplicationType Flags, JobFlag Jobs)> AllLinks(bool newApplication)
{
get
{
if (newApplication)
_currentDesign = rng.Design(Predicates);
if (_currentDesign == null)
yield break;
else
_currentDesign ??= rng.Design(Predicates);
if (_currentDesign == null)
yield break;
foreach (var (link, type, jobs) in _currentDesign.AllLinks)
yield return (link, type, jobs);
}
foreach (var (link, type, jobs) in _currentDesign.AllLinks(newApplication))
yield return (link, type, jobs);
}
public void AddData(JObject jObj)

View file

@ -29,9 +29,9 @@ public class RevertDesign : IDesignStandIn
public StateSource AssociatedSource()
=> StateSource.Game;
public IEnumerable<(IDesignStandIn Design, ApplicationType Flags, JobFlag Jobs)> AllLinks
public IEnumerable<(IDesignStandIn Design, ApplicationType Flags, JobFlag Jobs)> AllLinks(bool _)
{
get { yield return (this, ApplicationType.All, JobFlag.All); }
yield return (this, ApplicationType.All, JobFlag.All);
}
public void AddData(JObject jObj)

View file

@ -437,7 +437,7 @@ public class StateEditor(
if (!settings.MergeLinks || design is not Design d)
merged = new MergedDesign(design);
else
merged = merger.Merge(d.AllLinks, state.ModelData.IsHuman ? state.ModelData.Customize : CustomizeArray.Default, state.BaseData,
merged = merger.Merge(d.AllLinks(true), state.ModelData.IsHuman ? state.ModelData.Customize : CustomizeArray.Default, state.BaseData,
false, Config.AlwaysApplyAssociatedMods);
ApplyDesign(data, merged, settings with