Example #1
0
        static public SimObjectType SetSimType(string aspectName, Cons cons)
        {
            object[]      parseStr = ConsParams(cons);
            SimObjectType type     = GetObjectType(aspectName);
            SimTypeUsage  usage    = null;

            if (type.IsUseType)
            {
                usage = type.CreateObjectUsage(aspectName);
            }
            type.ParseAffect(usage, parseStr);
            return(type);
        }
Example #2
0
        static public SimTypeUsage CreateTypeUsage(string classname, params object[] parseStr)
        {
            if (parseStr.Length == 1 && parseStr[0] is object[])
            {
                parseStr = (object[])parseStr[0];
            }
            SimObjectType type = GetObjectType(classname);

            type.AddSuperType(USEABLE);
            type.IsUseType = true;
            SimTypeUsage usage = type.CreateObjectUsage(classname);

            type.ParseAffect(usage, parseStr);
            return(usage);
        }
Example #3
0
        public void ParseAffect(SimTypeUsage usage, object[] parseStr)
        {
            SimObjectType type = this;
            int           i    = 0;

            while (i < parseStr.Length)
            {
                if (parseStr[i] == null)
                {
                    i++;
                    continue;
                }
                string s = (string)parseStr[i++];//.ToString();

                if (s == "SuperType")
                {
                    String        arg  = parseStr[i++].ToString();
                    SimObjectType test = SimTypeSystem.FindObjectType(arg);
                    if (test == null)
                    {
                        throw new Exception("unknown super type " + arg + " for " + type);
                    }
                    AddSuperType(test);
                    //Not all types need to be by default usage types - was causing problems
                    // use types are fined by "Verb"
                    // usage = type.CreateObjectUsage(arg);
                    continue;
                }
                //if (s == "Match")
                //{
                //    String arg = parseStr[i++].ToString();
                //    arg = SimTypeSystem.MakeRegExpression(arg);
                //    type.Match.Add(new Regex(arg));
                //    continue;
                //}
                //if (s == "NoMatch")
                //{
                //    String arg = parseStr[i++].ToString();
                //    arg = SimTypeSystem.MakeRegExpression(arg);
                //    type.NoMatch.Add(new Regex(arg));
                //    continue;
                //}
                if (s == "Verb")
                {
                    String arg = parseStr[i++].ToString();
                    // TODO make sure creation order internalizes correctly
                    SimObjectType superType = SimTypeSystem.CreateObjectUse(arg, new object[0]);
                    AddSuperType(superType);
                    usage = type.CreateObjectUsage(arg);
                    continue;
                }
                // usage / distanceToExcite / etc
                FieldInfo fi = type.GetType().GetField(s);
                if (fi != null)
                {
                    type.SpecifiedProperties.AddTo(fi.Name);
                    SimTypeSystem.SetValue(fi, type, parseStr[i++]);
                    continue;
                }

                fi = type.GetType().GetField(s + "s");
                if (fi != null)
                {
                    type.SpecifiedProperties.AddTo(fi.Name);
                    SimTypeSystem.SetValue(fi, type, parseStr[i++]);
                    continue;
                }

                if (usage == null)
                {
                    if (type.IsUseType)
                    {
                        usage = type.CreateObjectUsage(type.GetTypeName());
                    }
                }
                fi = usage.GetType().GetField(s);
                if (fi != null)
                {
                    usage.SpecifiedProperties.Add(fi.Name);
                    SimTypeSystem.SetValue(fi, usage, parseStr[i++]);
                    continue;
                }

                fi = usage.GetType().GetField(s + "s");
                if (fi != null)
                {
                    usage.SpecifiedProperties.Add(fi.Name);
                    SimTypeSystem.SetValue(fi, usage, parseStr[i++]);
                    continue;
                }

                // Hygiene / Hunger
                fi = typeof(BotNeeds).GetField(s);
                if (fi != null)
                {
                    float ff = Single.Parse(parseStr[i++].ToString());
                    fi.SetValue(usage.ChangePromise, ff);
                    ff = Single.Parse(parseStr[i++].ToString());
                    fi.SetValue(usage.ChangeActual, ff);
                    continue;
                }
                DLRConsole.DebugWriteLine("ERROR: SimBots.ini-like dirrective unknown: '" + s + "'");
            }
        }