Beispiel #1
0
        public int GetScentByOdorAt(Odor odor, Point position)
        {
            if (!IsInBounds(position))
            {
                return(0);
            }

            OdorScent scent = GetScentByOdor(odor, position);

            return(scent == null ? 0 : scent.Strength);
        }
Beispiel #2
0
        public void RemoveScent(OdorScent scent)
        {
            // list.
            m_Scents.Remove(scent);

            // hash.
            List <OdorScent> scentsThere;

            if (m_aux_ScentsByPosition.TryGetValue(scent.Position, out scentsThere))
            {
                scentsThere.Remove(scent);
                if (scentsThere.Count == 0)
                {
                    m_aux_ScentsByPosition.Remove(scent.Position);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds or merge a scent.
        /// </summary>
        /// <param name="odor"></param>
        /// <param name="strengthChange"></param>
        /// <param name="position"></param>
        public void ModifyScentAt(Odor odor, int strengthChange, Point position)
        {
            if (!IsInBounds(position))
            {
                throw new ArgumentOutOfRangeException("position");
            }

            OdorScent oldScent = GetScentByOdor(odor, position);

            if (oldScent == null)
            {
                // new odor there.
                OdorScent newScent = new OdorScent(odor, strengthChange, position);
                AddNewScent(newScent);
            }
            else
            {
                // existing odor here.
                oldScent.Change(strengthChange);
            }
        }
Beispiel #4
0
        void AddNewScent(OdorScent scent)
        {
            // list
            if (!m_Scents.Contains(scent))
            {
                m_Scents.Add(scent);
            }

            // hash
            List <OdorScent> scentsThere;

            if (m_aux_ScentsByPosition.TryGetValue(scent.Position, out scentsThere))
            {
                scentsThere.Add(scent);
            }
            else
            {
                scentsThere = new List <OdorScent>(2);
                scentsThere.Add(scent);
                m_aux_ScentsByPosition.Add(scent.Position, scentsThere);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Sets odor strength to new strength if is it stronger (more "fresh").
        /// </summary>
        /// <param name="odor"></param>
        /// <param name="freshStrength"></param>
        /// <param name="position"></param>
        public void RefreshScentAt(Odor odor, int freshStrength, Point position)
        {
            if (!IsInBounds(position))
            {
                throw new ArgumentOutOfRangeException(String.Format("position; ({0},{1}) map {2} odor {3}", position.X, position.Y, this.m_Name, odor.ToString()));
            }

            OdorScent oldScent = GetScentByOdor(odor, position);

            if (oldScent == null)
            {
                // new odor there.
                OdorScent newScent = new OdorScent(odor, freshStrength, position);
                AddNewScent(newScent);
            }
            else
            {
                // existing odor here.
                if (oldScent.Strength < freshStrength)
                {
                    oldScent.Set(freshStrength);
                }
            }
        }