Пример #1
0
        private static void Resolve(SymbolStack.Element toResolve)
        {
            string        symbol        = toResolve.symbol;
            ResolveParams resolveParams = toResolve.resolveParams;

            tmpResolvers.Clear();
            if (rulesBySymbol.TryGetValue(symbol, out var value))
            {
                for (int i = 0; i < value.Count; i++)
                {
                    RuleDef ruleDef = value[i];
                    for (int j = 0; j < ruleDef.resolvers.Count; j++)
                    {
                        SymbolResolver symbolResolver = ruleDef.resolvers[j];
                        if (symbolResolver.CanResolve(resolveParams))
                        {
                            tmpResolvers.Add(symbolResolver);
                        }
                    }
                }
            }
            if (!tmpResolvers.Any())
            {
                Log.Warning("Could not find any RuleDef for symbol \"" + symbol + "\" with any resolver that could resolve " + resolveParams);
            }
            else
            {
                tmpResolvers.RandomElementByWeight((SymbolResolver x) => x.selectionWeight).Resolve(resolveParams);
            }
        }
Пример #2
0
 public static void Generate()
 {
     if (working)
     {
         Log.Error("Cannot call Generate() while already generating. Nested calls are not allowed.");
         return;
     }
     working           = true;
     currentSymbolPath = "";
     globalSettings.ClearResult();
     try
     {
         if (symbolStack.Empty)
         {
             Log.Warning("Symbol stack is empty.");
             return;
         }
         if (globalSettings.map == null)
         {
             Log.Error("Called BaseGen.Resolve() with null map.");
             return;
         }
         int num  = symbolStack.Count - 1;
         int num2 = 0;
         while (!symbolStack.Empty)
         {
             num2++;
             if (num2 > 100000)
             {
                 Log.Error("Error in BaseGen: Too many iterations. Infinite loop?");
                 break;
             }
             SymbolStack.Element toResolve = symbolStack.Pop();
             currentSymbolPath = toResolve.symbolPath;
             if (symbolStack.Count == num)
             {
                 globalSettings.mainRect = toResolve.resolveParams.rect;
                 num--;
             }
             try
             {
                 Resolve(toResolve);
             }
             catch (Exception ex)
             {
                 Log.Error(string.Concat("Error while resolving symbol \"", toResolve.symbol, "\" with params=", toResolve.resolveParams, "\n\nException: ", ex));
             }
         }
     }
     catch (Exception arg)
     {
         Log.Error("Error in BaseGen: " + arg);
     }
     finally
     {
         globalSettings.landingPadsGenerated = globalSettings.basePart_landingPadsResolved;
         working = false;
         symbolStack.Clear();
         globalSettings.Clear();
     }
 }