public int RemoveCompletedConditions(GoapState other, int stopAt = int.MaxValue) { lock (m_values) { int count = 0; var buffer = m_values; m_values = (m_values == m_bufferA) ? m_bufferB : m_bufferA; m_values.Clear(); foreach (var pair in buffer) { object otherValue; other.m_values.TryGetValue(pair.Key, out otherValue); if (!Equals(pair.Value, otherValue)) { m_values[pair.Key] = pair.Value; count++; if (count >= stopAt) { break; } } } return(count); } }
public void AddFromState(GoapState other) { lock (m_values) lock (other.m_values) { foreach (var pair in other.m_values) { m_values[pair.Key] = pair.Value; } } }
public static GoapState Instantiate(GoapState old = null) { GoapState state; if (m_cachedStates == null) { m_cachedStates = new Stack <GoapState>(); } state = (m_cachedStates.Count > 0) ? m_cachedStates.Pop() : new GoapState(); state.Init(old); return(state); }
public void Init(GoapState old = null) { m_values.Clear(); if (old != null) { lock (old.m_values) { foreach (var pair in old.m_values) { m_values[pair.Key] = pair.Value; } } } }
public bool HasAny(GoapState other) { lock (m_values) { lock (other.m_values) { foreach (var pair in other.m_values) { object thisValue; m_values.TryGetValue(pair.Key, out thisValue); if (Equals(pair.Value, thisValue)) { return(true); } } } } return(false); }
public void CreateStateWithMissingDifferences(GoapState other, ref GoapState differenceOutput) { if (differenceOutput == null) { Debug.Assert(differenceOutput != null, "GoapState :: CreateStaeWithMissingDifferences :: Input Reference was null!"); } lock (m_values) { foreach (var pair in m_values) { object otherValue; other.m_values.TryGetValue(pair.Key, out otherValue); if (!Equals(pair.Value, otherValue)) { differenceOutput.m_values[pair.Key] = pair.Value; } } } }
public bool HasAnyConflict(GoapState other) { lock (m_values) lock (other.m_values) { foreach (var pair in other.m_values) { object thisValue; m_values.TryGetValue(pair.Key, out thisValue); object otherValue = pair.Value; if (otherValue == null || Equals(otherValue, false)) { continue; } if (thisValue != null && !Equals(thisValue, otherValue)) { return(true); } } return(false); } }