Exemplo n.º 1
0
        /// <summary>
        /// This finds the best suitable sprite to use when presenting this actor to the user.
        /// </summary>
        public StateStructure.FrameInfo FindSuitableSprite()
        {
            // Info: actual sprites are resolved in ThingTypeInfo.SetupSpriteFrame() - mxd
            // Sprite forced?
            if (HasPropertyWithValue("$sprite"))
            {
                string sprite = GetPropertyValueString("$sprite", 0, true);                 //mxd

                //mxd. Valid when internal or exists
                if (sprite.StartsWith(DataManager.INTERNAL_PREFIX, StringComparison.OrdinalIgnoreCase) || General.Map.Data.GetSpriteExists(sprite))
                {
                    return new StateStructure.FrameInfo {
                               Sprite = sprite
                    }
                }
                ;

                //mxd. Bitch and moan
                General.ErrorLogger.Add(ErrorType.Warning, "DECORATE warning in " + classname + ":" + doomednum + ". The sprite \"" + sprite + "\" assigned by the \"$sprite\" property does not exist.");
            }

            //mxd. Try to get a suitable sprite from our hardcoded states list
            foreach (string state in SPRITE_CHECK_STATES)
            {
                if (!HasState(state))
                {
                    continue;
                }

                StateStructure           s    = GetState(state);
                StateStructure.FrameInfo info = s.GetSprite(0);
                if (!string.IsNullOrEmpty(info.Sprite))
                {
                    return(info);
                }
            }

            // Still no sprite found? then just pick the first we can find
            Dictionary <string, StateStructure> list = GetAllStates();

            foreach (StateStructure s in list.Values)
            {
                StateStructure.FrameInfo info = s.GetSprite(0);
                if (!string.IsNullOrEmpty(info.Sprite))
                {
                    return(info);
                }
            }

            //mxd. No dice...
            return(null);
        }

        #endregion
    }
Exemplo n.º 2
0
        // This version of GetSprite uses a callstack to check if it isn't going into an endless loop
        private FrameInfo GetSprite(int index, HashSet <StateStructure> prevstates)
        {
            // If we have sprite of our own, see if we can return this index
            if (index < sprites.Count)
            {
                return(sprites[index]);
            }

            // Otherwise, continue searching where goto tells us to go
            if (gotostate != null)
            {
                // Find the class
                ActorStructure a = parser.GetArchivedActorByName(gotostate.ClassName);
                if (a != null)
                {
                    StateStructure s = a.GetState(gotostate.StateName);
                    if ((s != null) && !prevstates.Contains(s))
                    {
                        prevstates.Add(this);
                        return(s.GetSprite(gotostate.SpriteOffset, prevstates));
                    }
                }
            }

            // If there is no goto keyword used, just give us one of our sprites if we can
            if (sprites.Count > 0)
            {
                // The following behavior should really depend on the flow control keyword (loop or stop) but who cares.
                return(sprites[0]);
            }

            return(new FrameInfo());
        }
Exemplo n.º 3
0
        /// <summary>
        /// This finds the best suitable sprite to use when presenting this actor to the user.
        /// </summary>
        public string FindSuitableSprite()
        {
            string result = "";

            // Sprite forced?
            if (HasPropertyWithValue("$sprite"))
            {
                return(GetPropertyValueString("$sprite", 0));
            }
            else
            {
                // Try the idle state
                if (HasState("idle"))
                {
                    StateStructure s          = GetState("idle");
                    string         spritename = s.GetSprite(0);
                    if (!string.IsNullOrEmpty(spritename))
                    {
                        result = spritename;
                    }
                }

                // Try the see state
                if (string.IsNullOrEmpty(result) && HasState("see"))
                {
                    StateStructure s          = GetState("see");
                    string         spritename = s.GetSprite(0);
                    if (!string.IsNullOrEmpty(spritename))
                    {
                        result = spritename;
                    }
                }

                // Try the inactive state
                if (string.IsNullOrEmpty(result) && HasState("inactive"))
                {
                    StateStructure s          = GetState("inactive");
                    string         spritename = s.GetSprite(0);
                    if (!string.IsNullOrEmpty(spritename))
                    {
                        result = spritename;
                    }
                }

                // Try the spawn state
                if (string.IsNullOrEmpty(result) && HasState("spawn"))
                {
                    StateStructure s          = GetState("spawn");
                    string         spritename = s.GetSprite(0);
                    if (!string.IsNullOrEmpty(spritename))
                    {
                        result = spritename;
                    }
                }

                // Still no sprite found? then just pick the first we can find
                if (string.IsNullOrEmpty(result))
                {
                    Dictionary <string, StateStructure> list = GetAllStates();
                    foreach (StateStructure s in list.Values)
                    {
                        string spritename = s.GetSprite(0);
                        if (!string.IsNullOrEmpty(spritename))
                        {
                            result = spritename;
                            break;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(result))
                {
                    // The sprite name is not actually complete, we still have to append
                    // the direction characters to it. Find an existing sprite with direction.
                    foreach (string postfix in SPRITE_POSTFIXES)
                    {
                        if (General.Map.Data.GetSpriteExists(result + postfix))
                        {
                            return(result + postfix);
                        }
                    }
                }
            }

            // No sprite found
            return("");
        }
Exemplo n.º 4
0
        /// <summary>
        /// This finds the best suitable sprite to use when presenting this actor to the user.
        /// </summary>
        public StateStructure.FrameInfo FindSuitableSprite()
        {
            // Info: actual sprites are resolved in ThingTypeInfo.SetupSpriteFrame() - mxd
            // Sprite forced?
            if (HasPropertyWithValue("$sprite"))
            {
                string sprite = GetPropertyValueString("$sprite", 0, true);                 //mxd

                //mxd. Valid when internal or exists
                if (sprite.StartsWith(DataManager.INTERNAL_PREFIX, StringComparison.OrdinalIgnoreCase) || General.Map.Data.GetSpriteExists(sprite))
                {
                    return new StateStructure.FrameInfo {
                               Sprite = sprite
                    }
                }
                ;

                //mxd. Bitch and moan
                General.ErrorLogger.Add(ErrorType.Warning, "DECORATE warning in " + classname + ":" + doomednum + ". The sprite \"" + sprite + "\" assigned by the \"$sprite\" property does not exist.");
            }

            StateStructure.FrameInfo firstNonTntInfo = null;
            StateStructure.FrameInfo firstInfo       = null;
            // Pick the first we can find (including and not including TNT1)
            Dictionary <string, StateStructure> list = GetAllStates();

            foreach (StateStructure s in list.Values)
            {
                StateStructure.FrameInfo info = s.GetSprite(0);
                if (string.IsNullOrEmpty(info.Sprite))
                {
                    continue;
                }

                if (!info.IsEmpty())
                {
                    firstNonTntInfo = info;
                }
                if (firstInfo == null)
                {
                    firstInfo = info;
                }

                if (firstNonTntInfo != null)
                {
                    break;
                }
            }

            //mxd. Try to get a suitable sprite from our hardcoded states list
            StateStructure.FrameInfo lastNonTntInfo = null;
            StateStructure.FrameInfo lastInfo       = null;
            foreach (string state in SPRITE_CHECK_STATES)
            {
                if (!HasState(state))
                {
                    continue;
                }

                StateStructure           s    = GetState(state);
                StateStructure.FrameInfo info = s.GetSprite(0);
                //if(!string.IsNullOrEmpty(info.Sprite)) return info;
                if (string.IsNullOrEmpty(info.Sprite))
                {
                    continue;
                }

                if (!info.IsEmpty())
                {
                    lastNonTntInfo = info;
                }
                if (lastInfo == null)
                {
                    lastInfo = info;
                }

                if (lastNonTntInfo != null)
                {
                    break;
                }
            }

            // [ZZ] return whatever is there by priority. try to pick non-TNT1 frames.
            StateStructure.FrameInfo[] infos = new StateStructure.FrameInfo[] { lastNonTntInfo, lastInfo, firstNonTntInfo, firstInfo };
            foreach (StateStructure.FrameInfo info in infos)
            {
                if (info != null)
                {
                    return(info);
                }
            }

            //mxd. No dice...
            return(null);
        }