Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
 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;
             }
         }
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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;
                    }
                }
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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;
                    }
                }
            }
        }
Exemplo n.º 7
0
        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);
                }
        }