static List <SimObjectType> DoGuessWork(Primitive.ObjectProperties props, SimObject obj, List <SimObjectType> possibles) { { { List <SimObjectType> objectTypesLocally = new List <SimObjectType>(); lock (SimTypeSystem.objectTypes) objectTypesLocally.AddRange(SimTypeSystem.objectTypes); foreach (SimObjectType otype in objectTypesLocally) { foreach (Regex smatch in otype.NoMatch) { // NoMatch if (smatch.IsMatch(props.Name.ToLower()) && smatch.IsMatch(props.Description.ToLower())) { goto nextOType; } } foreach (Object smatch in otype.CodeMatch) { // CodeMatch if (IsCodeMatch(obj, smatch)) { if (!possibles.Contains(otype)) { possibles.Add(otype); goto nextOType; } } else { possibles.Remove(otype); } } foreach (Regex smatch in otype.Match) { // Match if (smatch.IsMatch(props.Name.ToLower()) && smatch.IsMatch(props.Description.ToLower())) { if (!possibles.Contains(otype)) { possibles.Add(otype); SetNames(props, otype); } break; } } nextOType: { } } if (!String.IsNullOrEmpty(props.TouchName)) { string verb = props.TouchName; possibles.Add(SimTypeSystem.CreateObjectUse(verb, new object[] { "UseGrab", true , "TextName", verb })); } if (!String.IsNullOrEmpty(props.SitName)) { string verb = props.SitName; possibles.Add(SimTypeSystem.CreateObjectUse(verb, new object[] { "UseSit", true, "TextName", verb })); } return(possibles); } } }
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 + "'"); } }