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)) 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) foreach (var actor in data.Objects)
_state.ReapplyState(actor, forcedRedraw, StateSource.Fixed); _state.ReapplyState(actor, forcedRedraw, StateSource.Fixed);
} }
@ -164,7 +164,7 @@ public sealed class AutoDesignApplier : IDisposable
var specificId = actor.GetIdentifier(_actors); var specificId = actor.GetIdentifier(_actors);
if (_state.GetOrCreate(specificId, actor, out var state)) 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); _state.ReapplyState(actor, forcedRedraw, StateSource.Fixed);
} }
} }
@ -212,7 +212,7 @@ public sealed class AutoDesignApplier : IDisposable
var respectManual = state.LastJob == newJob.Id; var respectManual = state.LastJob == newJob.Id;
state.LastJob = actor.Job; 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); _state.ReapplyState(actor, forcedRedraw, StateSource.Fixed);
} }
@ -226,7 +226,7 @@ public sealed class AutoDesignApplier : IDisposable
_state.ResetState(state, StateSource.Game); _state.ResetState(state, StateSource.Game);
if (GetPlayerSet(identifier, out var set)) 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) 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; var respectManual = !state.UpdateTerritory(_clientState.TerritoryType) || !_config.RevertManualChangesOnZoneChange;
if (!respectManual) if (!respectManual)
_state.ResetState(state, StateSource.Game); _state.ResetState(state, StateSource.Game);
Reduce(actor, state, set, respectManual, false, out _); Reduce(actor, state, set, respectManual, false, false, out _);
return true; 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) if (set.BaseState is AutoDesignSet.Base.Game)
{ {
@ -284,7 +284,7 @@ public sealed class AutoDesignApplier : IDisposable
var mergedDesign = _designMerger.Merge( var mergedDesign = _designMerger.Merge(
set.Designs.Where(d => d.IsActive(actor)) 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.ModelData.Customize, state.BaseData, true, _config.AlwaysApplyAssociatedMods);
_state.ApplyDesign(state, mergedDesign, new ApplySettings(0, StateSource.Fixed, respectManual, fromJobChange, false, false, false)); _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; var respectManual = prior == id;
NewGearsetId = 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; NewGearsetId = -1;
foreach (var actor in data.Objects) foreach (var actor in data.Objects)
_state.ReapplyState(actor, forcedRedraw, StateSource.Fixed); _state.ReapplyState(actor, forcedRedraw, StateSource.Fixed);

View file

@ -58,7 +58,7 @@ public sealed class Design : DesignBase, ISavable, IDesignStandIn
public string Incognito public string Incognito
=> Identifier.ToString()[..8]; => 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)); => LinkContainer.GetAllLinks(this).Select(t => ((IDesignStandIn)t.Link.Link, t.Link.Type, JobFlag.All));
#endregion #endregion

View file

@ -16,7 +16,7 @@ public interface IDesignStandIn : IEquatable<IDesignStandIn>
public string SerializeName(); public string SerializeName();
public StateSource AssociatedSource(); 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); public void AddData(JObject jObj);

View file

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

View file

@ -46,17 +46,17 @@ public class RandomDesign(RandomDesignGenerator rng) : IDesignStandIn
public StateSource AssociatedSource() public StateSource AssociatedSource()
=> StateSource.Manual; => 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); _currentDesign = rng.Design(Predicates);
if (_currentDesign == null) else
yield break; _currentDesign ??= rng.Design(Predicates);
if (_currentDesign == null)
yield break;
foreach (var (link, type, jobs) in _currentDesign.AllLinks) foreach (var (link, type, jobs) in _currentDesign.AllLinks(newApplication))
yield return (link, type, jobs); yield return (link, type, jobs);
}
} }
public void AddData(JObject jObj) public void AddData(JObject jObj)

View file

@ -29,9 +29,9 @@ public class RevertDesign : IDesignStandIn
public StateSource AssociatedSource() public StateSource AssociatedSource()
=> StateSource.Game; => 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) public void AddData(JObject jObj)

View file

@ -437,7 +437,7 @@ public class StateEditor(
if (!settings.MergeLinks || design is not Design d) if (!settings.MergeLinks || design is not Design d)
merged = new MergedDesign(design); merged = new MergedDesign(design);
else 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); false, Config.AlwaysApplyAssociatedMods);
ApplyDesign(data, merged, settings with ApplyDesign(data, merged, settings with