Exemplo n.º 1
0
        public void AddFloodGlowFor(CompGlower theGlower, Color32[] glowGrid)
        {
            cellIndices      = map.cellIndices;
            this.glowGrid    = glowGrid;
            glower           = theGlower;
            attenLinearSlope = -1f / theGlower.Props.glowRadius;
            Building[] innerArray = map.edificeGrid.InnerArray;
            IntVec3    position   = theGlower.parent.Position;
            int        num        = Mathf.RoundToInt(glower.Props.glowRadius * 100f);
            int        curIndex   = cellIndices.CellToIndex(position);

            InitStatusesAndPushStartNode(ref curIndex, position);
            while (openSet.Count != 0)
            {
                curIndex = openSet.Pop();
                IntVec3 intVec = cellIndices.IndexToCell(curIndex);
                calcGrid[curIndex].status = statusFinalizedValue;
                SetGlowGridFromDist(curIndex);
                for (int i = 0; i < 8; i++)
                {
                    uint num2 = (uint)(intVec.x + Directions[i, 0]);
                    uint num3 = (uint)(intVec.z + Directions[i, 1]);
                    if (num2 >= mapSizeX || num3 >= mapSizeZ)
                    {
                        continue;
                    }
                    int x    = (int)num2;
                    int z    = (int)num3;
                    int num4 = cellIndices.CellToIndex(x, z);
                    if (calcGrid[num4].status == statusFinalizedValue)
                    {
                        continue;
                    }
                    blockers[i] = innerArray[num4];
                    if (blockers[i] != null)
                    {
                        if (blockers[i].def.blockLight)
                        {
                            continue;
                        }
                        blockers[i] = null;
                    }
                    int num5 = ((i >= 4) ? 141 : 100);
                    int num6 = calcGrid[curIndex].intDist + num5;
                    if (num6 > num)
                    {
                        continue;
                    }
                    switch (i)
                    {
                    case 4:
                        if (blockers[0] != null && blockers[1] != null)
                        {
                            continue;
                        }
                        break;

                    case 5:
                        if (blockers[1] != null && blockers[2] != null)
                        {
                            continue;
                        }
                        break;

                    case 6:
                        if (blockers[2] != null && blockers[3] != null)
                        {
                            continue;
                        }
                        break;

                    case 7:
                        if (blockers[0] != null && blockers[3] != null)
                        {
                            continue;
                        }
                        break;
                    }
                    if (calcGrid[num4].status <= statusUnseenValue)
                    {
                        calcGrid[num4].intDist = 999999;
                        calcGrid[num4].status  = statusOpenValue;
                    }
                    if (num6 < calcGrid[num4].intDist)
                    {
                        calcGrid[num4].intDist = num6;
                        calcGrid[num4].status  = statusOpenValue;
                        openSet.Push(num4);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void Run(IEnumerable <T> startingNodes, Func <T, IEnumerable <T> > neighborsGetter, Func <T, T, float> distanceGetter, List <KeyValuePair <T, float> > outDistances, Dictionary <T, T> outParents = null)
        {
            outDistances.Clear();
            distances.Clear();
            queue.Clear();
            outParents?.Clear();
            IList <T> list = startingNodes as IList <T>;

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    T key = list[i];
                    if (!distances.ContainsKey(key))
                    {
                        distances.Add(key, 0f);
                        queue.Push(new KeyValuePair <T, float>(key, 0f));
                    }
                }
            }
            else
            {
                foreach (T startingNode in startingNodes)
                {
                    if (!distances.ContainsKey(startingNode))
                    {
                        distances.Add(startingNode, 0f);
                        queue.Push(new KeyValuePair <T, float>(startingNode, 0f));
                    }
                }
            }
            while (queue.Count != 0)
            {
                KeyValuePair <T, float> node = queue.Pop();
                float num = distances[node.Key];
                if (node.Value != num)
                {
                    continue;
                }
                IEnumerable <T> enumerable = neighborsGetter(node.Key);
                if (enumerable == null)
                {
                    continue;
                }
                IList <T> list2 = enumerable as IList <T>;
                if (list2 != null)
                {
                    for (int j = 0; j < list2.Count; j++)
                    {
                        HandleNeighbor(list2[j], num, node, distanceGetter, outParents);
                    }
                }
                else
                {
                    foreach (T item in enumerable)
                    {
                        HandleNeighbor(item, num, node, distanceGetter, outParents);
                    }
                }
            }
            foreach (KeyValuePair <T, float> distance in distances)
            {
                outDistances.Add(distance);
            }
            distances.Clear();
        }
Exemplo n.º 3
0
        public void AddFloodGlowFor(CompGlower theGlower, Color32[] glowGrid)
        {
            cellIndices      = map.cellIndices;
            this.glowGrid    = glowGrid;
            glower           = theGlower;
            attenLinearSlope = -1f / theGlower.Props.glowRadius;
            Building[] innerArray = map.edificeGrid.InnerArray;
            IntVec3    position   = theGlower.parent.Position;
            int        num        = Mathf.RoundToInt(glower.Props.glowRadius * 100f);
            int        curIndex   = cellIndices.CellToIndex(position);
            int        num2       = 0;
            bool       flag       = UnityData.isDebugBuild && DebugViewSettings.drawGlow;

            InitStatusesAndPushStartNode(ref curIndex, position);
            while (openSet.Count != 0)
            {
                curIndex = openSet.Pop();
                IntVec3 c = cellIndices.IndexToCell(curIndex);
                calcGrid[curIndex].status = statusFinalizedValue;
                SetGlowGridFromDist(curIndex);
                if (flag)
                {
                    map.debugDrawer.FlashCell(c, (float)calcGrid[curIndex].intDist / 10f, calcGrid[curIndex].intDist.ToString("F2"));
                    num2++;
                }
                for (int i = 0; i < 8; i++)
                {
                    uint num3 = (uint)(c.x + Directions[i, 0]);
                    uint num4 = (uint)(c.z + Directions[i, 1]);
                    if (num3 < mapSizeX && num4 < mapSizeZ)
                    {
                        int x    = (int)num3;
                        int z    = (int)num4;
                        int num5 = cellIndices.CellToIndex(x, z);
                        if (calcGrid[num5].status != statusFinalizedValue)
                        {
                            blockers[i] = innerArray[num5];
                            if (blockers[i] != null)
                            {
                                if (blockers[i].def.blockLight)
                                {
                                    continue;
                                }
                                blockers[i] = null;
                            }
                            int num6 = (i >= 4) ? 141 : 100;
                            int num7 = calcGrid[curIndex].intDist + num6;
                            if (num7 <= num)
                            {
                                switch (i)
                                {
                                case 4:
                                    if (blockers[0] != null && blockers[1] != null)
                                    {
                                        break;
                                    }
                                    goto default;

                                case 5:
                                    if (blockers[1] != null && blockers[2] != null)
                                    {
                                        break;
                                    }
                                    goto default;

                                case 6:
                                    if (blockers[2] != null && blockers[3] != null)
                                    {
                                        break;
                                    }
                                    goto default;

                                case 7:
                                    if (blockers[0] != null && blockers[3] != null)
                                    {
                                        break;
                                    }
                                    goto default;

                                default:
                                    if (calcGrid[num5].status <= statusUnseenValue)
                                    {
                                        calcGrid[num5].intDist = 999999;
                                        calcGrid[num5].status  = statusOpenValue;
                                    }
                                    if (num7 < calcGrid[num5].intDist)
                                    {
                                        calcGrid[num5].intDist = num7;
                                        calcGrid[num5].status  = statusOpenValue;
                                        openSet.Push(num5);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }