Esempio n. 1
0
        public void DrawPath(Caravan pathingCaravan)
        {
            if (!Found || NodesLeftCount <= 0)
            {
                return;
            }
            WorldGrid worldGrid = Find.WorldGrid;
            float     d         = 0.05f;

            for (int i = 0; i < NodesLeftCount - 1; i++)
            {
                Vector3 tileCenter  = worldGrid.GetTileCenter(Peek(i));
                Vector3 tileCenter2 = worldGrid.GetTileCenter(Peek(i + 1));
                tileCenter  += tileCenter.normalized * d;
                tileCenter2 += tileCenter2.normalized * d;
                GenDraw.DrawWorldLineBetween(tileCenter, tileCenter2);
            }
            if (pathingCaravan != null)
            {
                Vector3 drawPos     = pathingCaravan.DrawPos;
                Vector3 tileCenter3 = worldGrid.GetTileCenter(Peek(0));
                drawPos     += drawPos.normalized * d;
                tileCenter3 += tileCenter3.normalized * d;
                if ((drawPos - tileCenter3).sqrMagnitude > 0.005f)
                {
                    GenDraw.DrawWorldLineBetween(drawPos, tileCenter3);
                }
            }
        }
        public static Vector3 PatherTweenedPosRoot(Caravan caravan)
        {
            WorldGrid worldGrid = Find.WorldGrid;

            if (!caravan.Spawned)
            {
                return(worldGrid.GetTileCenter(caravan.Tile));
            }
            if (caravan.pather.Moving)
            {
                float num;
                if (!caravan.pather.IsNextTilePassable())
                {
                    num = 0f;
                }
                else
                {
                    num = 1f - caravan.pather.nextTileCostLeft / caravan.pather.nextTileCostTotal;
                }
                int tileID;
                if (caravan.pather.nextTile == caravan.Tile && caravan.pather.previousTileForDrawingIfInDoubt != -1)
                {
                    tileID = caravan.pather.previousTileForDrawingIfInDoubt;
                }
                else
                {
                    tileID = caravan.Tile;
                }
                return(worldGrid.GetTileCenter(caravan.pather.nextTile) * num + worldGrid.GetTileCenter(tileID) * (1f - num));
            }
            return(worldGrid.GetTileCenter(caravan.Tile));
        }
Esempio n. 3
0
 public void DrawPath(Caravan pathingCaravan)
 {
     if (!this.Found)
     {
         return;
     }
     if (this.NodesLeftCount > 0)
     {
         WorldGrid worldGrid = Find.WorldGrid;
         float     d         = 0.05f;
         for (int i = 0; i < this.NodesLeftCount - 1; i++)
         {
             Vector3 a      = worldGrid.GetTileCenter(this.Peek(i));
             Vector3 vector = worldGrid.GetTileCenter(this.Peek(i + 1));
             a      += a.normalized * d;
             vector += vector.normalized * d;
             GenDraw.DrawWorldLineBetween(a, vector);
         }
         if (pathingCaravan != null)
         {
             Vector3 a2      = pathingCaravan.DrawPos;
             Vector3 vector2 = worldGrid.GetTileCenter(this.Peek(0));
             a2      += a2.normalized * d;
             vector2 += vector2.normalized * d;
             if ((a2 - vector2).sqrMagnitude > 0.005f)
             {
                 GenDraw.DrawWorldLineBetween(a2, vector2);
             }
         }
     }
 }
        public void FlashLine(int tileA, int tileB, int duration = 50)
        {
            WorldGrid      worldGrid      = Find.WorldGrid;
            Vector3        tileCenter     = worldGrid.GetTileCenter(tileA);
            Vector3        tileCenter2    = worldGrid.GetTileCenter(tileB);
            DebugWorldLine debugWorldLine = new DebugWorldLine(tileCenter, tileCenter2, true);

            debugWorldLine.TicksLeft = duration;
            this.debugLines.Add(debugWorldLine);
        }
        public static Vector3 PatherTweenedPosRoot(Caravan caravan)
        {
            WorldGrid worldGrid = Find.WorldGrid;

            if (!caravan.Spawned)
            {
                return(worldGrid.GetTileCenter(caravan.Tile));
            }
            if (caravan.pather.Moving)
            {
                float num = (float)(caravan.pather.IsNextTilePassable() ? (1.0 - caravan.pather.nextTileCostLeft / caravan.pather.nextTileCostTotal) : 0.0);
                return(worldGrid.GetTileCenter(caravan.pather.nextTile) * num + worldGrid.GetTileCenter(caravan.Tile) * (float)(1.0 - num));
            }
            return(worldGrid.GetTileCenter(caravan.Tile));
        }
        public static Vector3 PatherTweenedPosRoot(Caravan caravan)
        {
            WorldGrid worldGrid = Find.WorldGrid;

            if (!caravan.Spawned)
            {
                return(worldGrid.GetTileCenter(caravan.Tile));
            }
            if (caravan.pather.Moving)
            {
                float num    = (caravan.pather.IsNextTilePassable() ? (1f - caravan.pather.nextTileCostLeft / caravan.pather.nextTileCostTotal) : 0f);
                int   tileID = ((caravan.pather.nextTile != caravan.Tile || caravan.pather.previousTileForDrawingIfInDoubt == -1) ? caravan.Tile : caravan.pather.previousTileForDrawingIfInDoubt);
                return(worldGrid.GetTileCenter(caravan.pather.nextTile) * num + worldGrid.GetTileCenter(tileID) * (1f - num));
            }
            return(worldGrid.GetTileCenter(caravan.Tile));
        }
        public void RenderMote()
        {
            float num = (Time.time - this.lastOrderedToTileTime) / 0.5f;

            if (num > 1f)
            {
                return;
            }
            if (Caravan_GotoMoteRenderer.cachedMaterial == null)
            {
                Caravan_GotoMoteRenderer.cachedMaterial = MaterialPool.MatFrom((Texture2D)Caravan_GotoMoteRenderer.FeedbackGoto.mainTexture, Caravan_GotoMoteRenderer.FeedbackGoto.shader, Color.white, WorldMaterials.DynamicObjectRenderQueue);
            }
            WorldGrid worldGrid  = Find.WorldGrid;
            Vector3   tileCenter = worldGrid.GetTileCenter(this.tile);
            Color     value      = new Color(1f, 1f, 1f, 1f - num);

            Caravan_GotoMoteRenderer.propertyBlock.SetColor(ShaderPropertyIDs.Color, value);
            Vector3  pos       = tileCenter;
            float    size      = 0.8f * worldGrid.averageTileSize;
            float    altOffset = 0.018f;
            Material material  = Caravan_GotoMoteRenderer.cachedMaterial;
            MaterialPropertyBlock materialPropertyBlock = Caravan_GotoMoteRenderer.propertyBlock;

            WorldRendererUtility.DrawQuadTangentialToPlanet(pos, size, altOffset, material, false, false, materialPropertyBlock);
        }
Esempio n. 8
0
        public override IEnumerable Regenerate()
        {
            foreach (object result in base.Regenerate())
            {
                yield return(result);
            }
            Rand.PushState();
            Rand.Seed = Find.World.info.Seed;
            WorldGrid grid       = Find.WorldGrid;
            int       tilesCount = grid.TilesCount;
            int       i          = 0;

            while (i < tilesCount)
            {
                Tile       tile = grid[i];
                Material   material;
                FloatRange floatRange;
                switch (tile.hilliness)
                {
                case Hilliness.SmallHills:
                    material   = WorldMaterials.SmallHills;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_SmallHills;
                    goto IL_180;

                case Hilliness.LargeHills:
                    material   = WorldMaterials.LargeHills;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_LargeHills;
                    goto IL_180;

                case Hilliness.Mountainous:
                    material   = WorldMaterials.Mountains;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_Mountains;
                    goto IL_180;

                case Hilliness.Impassable:
                    material   = WorldMaterials.ImpassableMountains;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_ImpassableMountains;
                    goto IL_180;
                }
IL_25C:
                i++;
                continue;
IL_180:
                LayerSubMesh subMesh = base.GetSubMesh(material);
                Vector3 vector         = grid.GetTileCenter(i);
                Vector3 posForTangents = vector;
                float   magnitude      = vector.magnitude;
                vector = (vector + Rand.UnitVector3 * floatRange.RandomInRange * grid.averageTileSize).normalized * magnitude;
                WorldRendererUtility.PrintQuadTangentialToPlanet(vector, posForTangents, WorldLayer_Hills.BaseSizeRange.RandomInRange * grid.averageTileSize, 0.005f, subMesh, false, true, false);
                WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, WorldLayer_Hills.TexturesInAtlas.x), Rand.Range(0, WorldLayer_Hills.TexturesInAtlas.z), WorldLayer_Hills.TexturesInAtlas.x, WorldLayer_Hills.TexturesInAtlas.z, subMesh);
                goto IL_25C;
            }
            Rand.PopState();
            base.FinalizeMesh(MeshParts.All);
        }
Esempio n. 9
0
        public override IEnumerable Regenerate()
        {
            foreach (object item in base.Regenerate())
            {
                yield return(item);
            }
            Rand.PushState();
            Rand.Seed = Find.World.info.Seed;
            WorldGrid worldGrid  = Find.WorldGrid;
            int       tilesCount = worldGrid.TilesCount;

            for (int i = 0; i < tilesCount; i++)
            {
                Material   material;
                FloatRange floatRange;
                switch (worldGrid[i].hilliness)
                {
                case Hilliness.SmallHills:
                    material   = WorldMaterials.SmallHills;
                    floatRange = BasePosOffsetRange_SmallHills;
                    break;

                case Hilliness.LargeHills:
                    material   = WorldMaterials.LargeHills;
                    floatRange = BasePosOffsetRange_LargeHills;
                    break;

                case Hilliness.Mountainous:
                    material   = WorldMaterials.Mountains;
                    floatRange = BasePosOffsetRange_Mountains;
                    break;

                case Hilliness.Impassable:
                    material   = WorldMaterials.ImpassableMountains;
                    floatRange = BasePosOffsetRange_ImpassableMountains;
                    break;

                default:
                    continue;
                }
                LayerSubMesh subMesh        = GetSubMesh(material);
                Vector3      tileCenter     = worldGrid.GetTileCenter(i);
                Vector3      posForTangents = tileCenter;
                float        magnitude      = tileCenter.magnitude;
                tileCenter = (tileCenter + Rand.UnitVector3 * floatRange.RandomInRange * worldGrid.averageTileSize).normalized * magnitude;
                WorldRendererUtility.PrintQuadTangentialToPlanet(tileCenter, posForTangents, BaseSizeRange.RandomInRange * worldGrid.averageTileSize, 0.005f, subMesh, counterClockwise: false, randomizeRotation: true, printUVs: false);
                WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, TexturesInAtlas.x), Rand.Range(0, TexturesInAtlas.z), TexturesInAtlas.x, TexturesInAtlas.z, subMesh);
            }
            Rand.PopState();
            FinalizeMesh(MeshParts.All);
        }
        public static Vector3 PatherTweenedPosRoot(Caravan caravan)
        {
            WorldGrid worldGrid = Find.WorldGrid;

            if (!caravan.Spawned)
            {
                return(worldGrid.GetTileCenter(caravan.Tile));
            }
            if (caravan.pather.Moving)
            {
                float num;
                if (!caravan.pather.IsNextTilePassable())
                {
                    num = 0f;
                }
                else
                {
                    num = 1f - caravan.pather.nextTileCostLeft / caravan.pather.nextTileCostTotal;
                }
                return(worldGrid.GetTileCenter(caravan.pather.nextTile) * num + worldGrid.GetTileCenter(caravan.Tile) * (1f - num));
            }
            return(worldGrid.GetTileCenter(caravan.Tile));
        }
Esempio n. 11
0
        public void RenderMote()
        {
            float num = (Time.time - lastOrderedToTileTime) / 0.5f;

            if (!(num > 1f))
            {
                if (cachedMaterial == null)
                {
                    cachedMaterial = MaterialPool.MatFrom((Texture2D)FeedbackGoto.mainTexture, FeedbackGoto.shader, Color.white, WorldMaterials.DynamicObjectRenderQueue);
                }
                WorldGrid worldGrid  = Find.WorldGrid;
                Vector3   tileCenter = worldGrid.GetTileCenter(tile);
                Color     value      = new Color(1f, 1f, 1f, 1f - num);
                propertyBlock.SetColor(ShaderPropertyIDs.Color, value);
                WorldRendererUtility.DrawQuadTangentialToPlanet(tileCenter, 0.8f * worldGrid.averageTileSize, 0.018f, cachedMaterial, counterClockwise: false, useSkyboxLayer: false, propertyBlock);
            }
        }
Esempio n. 12
0
        public WorldPath FindPath(int startTile, int destTile, Caravan caravan, Func <float, bool> terminator = null)
        {
            WorldPath notFound;

            if (startTile < 0)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindPath with invalid start tile ",
                    startTile,
                    ", caravan= ",
                    caravan
                }), false);
                notFound = WorldPath.NotFound;
            }
            else if (destTile < 0)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindPath with invalid dest tile ",
                    destTile,
                    ", caravan= ",
                    caravan
                }), false);
                notFound = WorldPath.NotFound;
            }
            else
            {
                if (caravan != null)
                {
                    if (!caravan.CanReach(destTile))
                    {
                        return(WorldPath.NotFound);
                    }
                }
                else if (!Find.WorldReachability.CanReach(startTile, destTile))
                {
                    return(WorldPath.NotFound);
                }
                World      world = Find.World;
                WorldGrid  grid  = world.grid;
                List <int> tileIDToNeighbors_offsets = grid.tileIDToNeighbors_offsets;
                List <int> tileIDToNeighbors_values  = grid.tileIDToNeighbors_values;
                Vector3    normalized         = grid.GetTileCenter(destTile).normalized;
                float[]    movementDifficulty = world.pathGrid.movementDifficulty;
                int        num  = 0;
                int        num2 = (caravan == null) ? 3500 : caravan.TicksPerMove;
                int        num3 = this.CalculateHeuristicStrength(startTile, destTile);
                this.statusOpenValue   += 2;
                this.statusClosedValue += 2;
                if (this.statusClosedValue >= 65435)
                {
                    this.ResetStatuses();
                }
                this.calcGrid[startTile].knownCost     = 0;
                this.calcGrid[startTile].heuristicCost = 0;
                this.calcGrid[startTile].costNodeCost  = 0;
                this.calcGrid[startTile].parentTile    = startTile;
                this.calcGrid[startTile].status        = this.statusOpenValue;
                this.openList.Clear();
                this.openList.Push(new WorldPathFinder.CostNode(startTile, 0));
                while (this.openList.Count > 0)
                {
                    WorldPathFinder.CostNode costNode = this.openList.Pop();
                    if (costNode.cost == this.calcGrid[costNode.tile].costNodeCost)
                    {
                        int tile = costNode.tile;
                        if (this.calcGrid[tile].status != this.statusClosedValue)
                        {
                            if (DebugViewSettings.drawPaths)
                            {
                                Find.WorldDebugDrawer.FlashTile(tile, (float)this.calcGrid[tile].knownCost / 375000f, this.calcGrid[tile].knownCost.ToString(), 50);
                            }
                            if (tile == destTile)
                            {
                                return(this.FinalizedPath(tile));
                            }
                            if (num > 500000)
                            {
                                Log.Warning(string.Concat(new object[]
                                {
                                    caravan,
                                    " pathing from ",
                                    startTile,
                                    " to ",
                                    destTile,
                                    " hit search limit of ",
                                    500000,
                                    " tiles."
                                }), false);
                                return(WorldPath.NotFound);
                            }
                            int num4 = (tile + 1 >= tileIDToNeighbors_offsets.Count) ? tileIDToNeighbors_values.Count : tileIDToNeighbors_offsets[tile + 1];
                            for (int i = tileIDToNeighbors_offsets[tile]; i < num4; i++)
                            {
                                int num5 = tileIDToNeighbors_values[i];
                                if (this.calcGrid[num5].status != this.statusClosedValue)
                                {
                                    if (!world.Impassable(num5))
                                    {
                                        int    num6   = (int)((float)num2 * movementDifficulty[num5] * grid.GetRoadMovementDifficultyMultiplier(tile, num5, null));
                                        int    num7   = num6 + this.calcGrid[tile].knownCost;
                                        ushort status = this.calcGrid[num5].status;
                                        if ((status != this.statusClosedValue && status != this.statusOpenValue) || this.calcGrid[num5].knownCost > num7)
                                        {
                                            Vector3 tileCenter = grid.GetTileCenter(num5);
                                            if (status != this.statusClosedValue && status != this.statusOpenValue)
                                            {
                                                float num8 = grid.ApproxDistanceInTiles(GenMath.SphericalDistance(tileCenter.normalized, normalized));
                                                this.calcGrid[num5].heuristicCost = Mathf.RoundToInt((float)num2 * num8 * (float)num3 * 0.5f);
                                            }
                                            int num9 = num7 + this.calcGrid[num5].heuristicCost;
                                            this.calcGrid[num5].parentTile   = tile;
                                            this.calcGrid[num5].knownCost    = num7;
                                            this.calcGrid[num5].status       = this.statusOpenValue;
                                            this.calcGrid[num5].costNodeCost = num9;
                                            this.openList.Push(new WorldPathFinder.CostNode(num5, num9));
                                        }
                                    }
                                }
                            }
                            num++;
                            this.calcGrid[tile].status = this.statusClosedValue;
                            if (terminator != null && terminator((float)this.calcGrid[tile].costNodeCost))
                            {
                                return(WorldPath.NotFound);
                            }
                        }
                    }
                }
                Log.Warning(string.Concat(new object[]
                {
                    caravan,
                    " pathing from ",
                    startTile,
                    " to ",
                    destTile,
                    " ran out of tiles to process."
                }), false);
                notFound = WorldPath.NotFound;
            }
            return(notFound);
        }
Esempio n. 13
0
        public override IEnumerable Regenerate()
        {
            IEnumerator enumerator = this.< Regenerate > __BaseCallProxy0().GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object result = enumerator.Current;
                    yield return(result);
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            Rand.PushState();
            Rand.Seed = Find.World.info.Seed;
            WorldGrid grid       = Find.WorldGrid;
            int       tilesCount = grid.TilesCount;
            int       i          = 0;

            while (i < tilesCount)
            {
                Tile       tile = grid[i];
                Material   material;
                FloatRange floatRange;
                switch (tile.hilliness)
                {
                case Hilliness.SmallHills:
                    material   = WorldMaterials.SmallHills;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_SmallHills;
                    goto IL_185;

                case Hilliness.LargeHills:
                    material   = WorldMaterials.LargeHills;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_LargeHills;
                    goto IL_185;

                case Hilliness.Mountainous:
                    material   = WorldMaterials.Mountains;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_Mountains;
                    goto IL_185;

                case Hilliness.Impassable:
                    material   = WorldMaterials.ImpassableMountains;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_ImpassableMountains;
                    goto IL_185;
                }
IL_262:
                i++;
                continue;
IL_185:
                LayerSubMesh subMesh = base.GetSubMesh(material);
                Vector3 vector         = grid.GetTileCenter(i);
                Vector3 posForTangents = vector;
                float   magnitude      = vector.magnitude;
                vector = (vector + Rand.UnitVector3 * floatRange.RandomInRange * grid.averageTileSize).normalized * magnitude;
                WorldRendererUtility.PrintQuadTangentialToPlanet(vector, posForTangents, WorldLayer_Hills.BaseSizeRange.RandomInRange * grid.averageTileSize, 0.005f, subMesh, false, true, false);
                WorldRendererUtility.PrintTextureAtlasUVs(Rand.Range(0, WorldLayer_Hills.TexturesInAtlas.x), Rand.Range(0, WorldLayer_Hills.TexturesInAtlas.z), WorldLayer_Hills.TexturesInAtlas.x, WorldLayer_Hills.TexturesInAtlas.z, subMesh);
                goto IL_262;
            }
            Rand.PopState();
            base.FinalizeMesh(MeshParts.All);
            yield break;
        }
Esempio n. 14
0
        public WorldPath FindPath(int startTile, int destTile, Caravan caravan, Func <float, bool> terminator = null)
        {
            if (startTile < 0)
            {
                Log.Error("Tried to FindPath with invalid start tile " + startTile + ", caravan= " + caravan);
                return(WorldPath.NotFound);
            }
            if (destTile < 0)
            {
                Log.Error("Tried to FindPath with invalid dest tile " + destTile + ", caravan= " + caravan);
                return(WorldPath.NotFound);
            }
            if (caravan != null)
            {
                if (!caravan.CanReach(destTile))
                {
                    return(WorldPath.NotFound);
                }
            }
            else if (!Find.WorldReachability.CanReach(startTile, destTile))
            {
                return(WorldPath.NotFound);
            }
            World      world = Find.World;
            WorldGrid  grid  = world.grid;
            List <int> tileIDToNeighbors_offsets = grid.tileIDToNeighbors_offsets;
            List <int> tileIDToNeighbors_values  = grid.tileIDToNeighbors_values;
            Vector3    normalized = grid.GetTileCenter(destTile).normalized;

            float[] movementDifficulty = world.pathGrid.movementDifficulty;
            int     num  = 0;
            int     num2 = caravan?.TicksPerMove ?? 3300;
            int     num3 = CalculateHeuristicStrength(startTile, destTile);

            statusOpenValue   += 2;
            statusClosedValue += 2;
            if (statusClosedValue >= 65435)
            {
                ResetStatuses();
            }
            calcGrid[startTile].knownCost     = 0;
            calcGrid[startTile].heuristicCost = 0;
            calcGrid[startTile].costNodeCost  = 0;
            calcGrid[startTile].parentTile    = startTile;
            calcGrid[startTile].status        = statusOpenValue;
            openList.Clear();
            openList.Push(new CostNode(startTile, 0));
            while (true)
            {
                if (openList.Count <= 0)
                {
                    Log.Warning(caravan + " pathing from " + startTile + " to " + destTile + " ran out of tiles to process.");
                    return(WorldPath.NotFound);
                }
                CostNode costNode = openList.Pop();
                if (costNode.cost != calcGrid[costNode.tile].costNodeCost)
                {
                    continue;
                }
                int tile = costNode.tile;
                if (calcGrid[tile].status == statusClosedValue)
                {
                    continue;
                }
                if (tile == destTile)
                {
                    return(FinalizedPath(tile));
                }
                if (num > 500000)
                {
                    Log.Warning(caravan + " pathing from " + startTile + " to " + destTile + " hit search limit of " + 500000 + " tiles.");
                    return(WorldPath.NotFound);
                }
                int num4 = (tile + 1 < tileIDToNeighbors_offsets.Count) ? tileIDToNeighbors_offsets[tile + 1] : tileIDToNeighbors_values.Count;
                for (int i = tileIDToNeighbors_offsets[tile]; i < num4; i++)
                {
                    int num5 = tileIDToNeighbors_values[i];
                    if (calcGrid[num5].status == statusClosedValue || world.Impassable(num5))
                    {
                        continue;
                    }
                    int    num6   = (int)((float)num2 * movementDifficulty[num5] * grid.GetRoadMovementDifficultyMultiplier(tile, num5)) + calcGrid[tile].knownCost;
                    ushort status = calcGrid[num5].status;
                    if ((status != statusClosedValue && status != statusOpenValue) || calcGrid[num5].knownCost > num6)
                    {
                        Vector3 tileCenter = grid.GetTileCenter(num5);
                        if (status != statusClosedValue && status != statusOpenValue)
                        {
                            float num7 = grid.ApproxDistanceInTiles(GenMath.SphericalDistance(tileCenter.normalized, normalized));
                            calcGrid[num5].heuristicCost = Mathf.RoundToInt((float)num2 * num7 * (float)num3 * 0.5f);
                        }
                        int num8 = num6 + calcGrid[num5].heuristicCost;
                        calcGrid[num5].parentTile   = tile;
                        calcGrid[num5].knownCost    = num6;
                        calcGrid[num5].status       = statusOpenValue;
                        calcGrid[num5].costNodeCost = num8;
                        openList.Push(new CostNode(num5, num8));
                    }
                }
                num++;
                calcGrid[tile].status = statusClosedValue;
                if (terminator != null && terminator(calcGrid[tile].costNodeCost))
                {
                    break;
                }
            }
            return(WorldPath.NotFound);
        }
        public override IEnumerable Regenerate()
        {
            IEnumerator enumerator = base.Regenerate().GetEnumerator();

            try
            {
                if (enumerator.MoveNext())
                {
                    object result = enumerator.Current;
                    yield return(result);

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            finally
            {
                IDisposable disposable;
                IDisposable disposable2 = disposable = (enumerator as IDisposable);
                if (disposable != null)
                {
                    disposable2.Dispose();
                }
            }
            Rand.PushState();
            Rand.Seed = Find.World.info.Seed;
            WorldGrid grid       = Find.WorldGrid;
            int       tilesCount = grid.TilesCount;

            for (int i = 0; i < tilesCount; i++)
            {
                Tile         tile = grid[i];
                Material     material;
                FloatRange   floatRange;
                LayerSubMesh subMesh;
                Vector3      vector;
                Vector3      posForTangents;
                float        magnitude;
                IntVec2      texturesInAtlas;
                int          indexX;
                IntVec2      texturesInAtlas2;
                int          indexY;
                IntVec2      texturesInAtlas3;
                int          x;
                IntVec2      texturesInAtlas4;
                switch (tile.hilliness)
                {
                case Hilliness.SmallHills:
                    material   = WorldMaterials.SmallHills;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_SmallHills;
                    goto IL_0180;

                case Hilliness.LargeHills:
                    material   = WorldMaterials.LargeHills;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_LargeHills;
                    goto IL_0180;

                case Hilliness.Mountainous:
                    material   = WorldMaterials.Mountains;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_Mountains;
                    goto IL_0180;

                case Hilliness.Impassable:
                {
                    material   = WorldMaterials.ImpassableMountains;
                    floatRange = WorldLayer_Hills.BasePosOffsetRange_ImpassableMountains;
                    goto IL_0180;
                }
IL_0180:
                    subMesh        = base.GetSubMesh(material);
                    vector         = grid.GetTileCenter(i);
                    posForTangents = vector;
                    magnitude      = vector.magnitude;
                    vector        += Rand.UnitVector3 * floatRange.RandomInRange * grid.averageTileSize;
                    vector         = vector.normalized * magnitude;
                    WorldRendererUtility.PrintQuadTangentialToPlanet(vector, posForTangents, WorldLayer_Hills.BaseSizeRange.RandomInRange * grid.averageTileSize, 0.005f, subMesh, false, true, false);
                    texturesInAtlas  = WorldLayer_Hills.TexturesInAtlas;
                    indexX           = Rand.Range(0, texturesInAtlas.x);
                    texturesInAtlas2 = WorldLayer_Hills.TexturesInAtlas;
                    indexY           = Rand.Range(0, texturesInAtlas2.z);
                    texturesInAtlas3 = WorldLayer_Hills.TexturesInAtlas;
                    x = texturesInAtlas3.x;
                    texturesInAtlas4 = WorldLayer_Hills.TexturesInAtlas;
                    WorldRendererUtility.PrintTextureAtlasUVs(indexX, indexY, x, texturesInAtlas4.z, subMesh);
                    break;
                }
            }
            Rand.PopState();
            base.FinalizeMesh(MeshParts.All);
            yield break;
IL_0287:
            /*Error near IL_0288: Unexpected return in MoveNext()*/;
        }
Esempio n. 16
0
        public void GeneratePaths(LayerSubMesh subMesh, int tileID, List <OutputDirection> nodes, Color32 color, bool allowSmoothTransition)
        {
            WorldGrid worldGrid = Find.WorldGrid;

            worldGrid.GetTileVertices(tileID, tmpVerts);
            worldGrid.GetTileNeighbors(tileID, tmpNeighbors);
            if (nodes.Count == 1 && pointyEnds)
            {
                int count = subMesh.verts.Count;
                AddPathEndpoint(subMesh, tmpVerts, tmpNeighbors.IndexOf(nodes[0].neighbor), color, tileID, nodes[0]);
                subMesh.verts.Add(FinalizePoint(worldGrid.GetTileCenter(tileID), nodes[0].distortionFrequency, nodes[0].distortionIntensity));
                subMesh.colors.Add(color.MutateAlpha(0));
                subMesh.tris.Add(count);
                subMesh.tris.Add(count + 3);
                subMesh.tris.Add(count + 1);
                subMesh.tris.Add(count + 1);
                subMesh.tris.Add(count + 3);
                subMesh.tris.Add(count + 2);
                return;
            }
            if (nodes.Count == 2)
            {
                int count2 = subMesh.verts.Count;
                int num    = tmpNeighbors.IndexOf(nodes[0].neighbor);
                int num2   = tmpNeighbors.IndexOf(nodes[1].neighbor);
                if (allowSmoothTransition && Mathf.Abs(num - num2) > 1 && Mathf.Abs((num - num2 + tmpVerts.Count) % tmpVerts.Count) > 1)
                {
                    AddPathEndpoint(subMesh, tmpVerts, num, color, tileID, nodes[0]);
                    AddPathEndpoint(subMesh, tmpVerts, num2, color, tileID, nodes[1]);
                    subMesh.tris.Add(count2);
                    subMesh.tris.Add(count2 + 5);
                    subMesh.tris.Add(count2 + 1);
                    subMesh.tris.Add(count2 + 5);
                    subMesh.tris.Add(count2 + 4);
                    subMesh.tris.Add(count2 + 1);
                    subMesh.tris.Add(count2 + 1);
                    subMesh.tris.Add(count2 + 4);
                    subMesh.tris.Add(count2 + 2);
                    subMesh.tris.Add(count2 + 4);
                    subMesh.tris.Add(count2 + 3);
                    subMesh.tris.Add(count2 + 2);
                    return;
                }
            }
            float num3 = 0f;

            for (int i = 0; i < nodes.Count; i++)
            {
                num3 = Mathf.Max(num3, nodes[i].width);
            }
            Vector3 tileCenter = worldGrid.GetTileCenter(tileID);

            tmpHexVerts.Clear();
            for (int j = 0; j < tmpVerts.Count; j++)
            {
                tmpHexVerts.Add(FinalizePoint(Vector3.LerpUnclamped(tileCenter, tmpVerts[j], num3 * 0.5f * 2f), 0f, 0f));
            }
            tileCenter = FinalizePoint(tileCenter, 0f, 0f);
            int count3 = subMesh.verts.Count;

            subMesh.verts.Add(tileCenter);
            subMesh.colors.Add(color);
            int count4 = subMesh.verts.Count;

            for (int k = 0; k < tmpHexVerts.Count; k++)
            {
                subMesh.verts.Add(tmpHexVerts[k]);
                subMesh.colors.Add(color.MutateAlpha(0));
                subMesh.tris.Add(count3);
                subMesh.tris.Add(count4 + (k + 1) % tmpHexVerts.Count);
                subMesh.tris.Add(count4 + k);
            }
            for (int l = 0; l < nodes.Count; l++)
            {
                if (nodes[l].width != 0f)
                {
                    int count5 = subMesh.verts.Count;
                    int num4   = tmpNeighbors.IndexOf(nodes[l].neighbor);
                    AddPathEndpoint(subMesh, tmpVerts, num4, color, tileID, nodes[l]);
                    subMesh.tris.Add(count5);
                    subMesh.tris.Add(count4 + (num4 + tmpHexVerts.Count - 1) % tmpHexVerts.Count);
                    subMesh.tris.Add(count3);
                    subMesh.tris.Add(count5);
                    subMesh.tris.Add(count3);
                    subMesh.tris.Add(count5 + 1);
                    subMesh.tris.Add(count5 + 1);
                    subMesh.tris.Add(count3);
                    subMesh.tris.Add(count5 + 2);
                    subMesh.tris.Add(count3);
                    subMesh.tris.Add(count4 + (num4 + 2) % tmpHexVerts.Count);
                    subMesh.tris.Add(count5 + 2);
                }
            }
        }
Esempio n. 17
0
        public void GeneratePaths(LayerSubMesh subMesh, int tileID, List <OutputDirection> nodes, Color32 color, bool allowSmoothTransition)
        {
            WorldGrid worldGrid = Find.WorldGrid;

            worldGrid.GetTileVertices(tileID, tmpVerts);
            worldGrid.GetTileNeighbors(tileID, tmpNeighbors);
            if (nodes.Count == 1 && pointyEnds)
            {
                int             count           = subMesh.verts.Count;
                List <Vector3>  verts           = tmpVerts;
                List <int>      list            = tmpNeighbors;
                OutputDirection outputDirection = nodes[0];
                AddPathEndpoint(subMesh, verts, list.IndexOf(outputDirection.neighbor), color, tileID, nodes[0]);
                List <Vector3>  verts2              = subMesh.verts;
                Vector3         tileCenter          = worldGrid.GetTileCenter(tileID);
                OutputDirection outputDirection2    = nodes[0];
                float           distortionFrequency = outputDirection2.distortionFrequency;
                OutputDirection outputDirection3    = nodes[0];
                verts2.Add(FinalizePoint(tileCenter, distortionFrequency, outputDirection3.distortionIntensity));
                subMesh.colors.Add(color.MutateAlpha(0));
                subMesh.tris.Add(count);
                subMesh.tris.Add(count + 3);
                subMesh.tris.Add(count + 1);
                subMesh.tris.Add(count + 1);
                subMesh.tris.Add(count + 3);
                subMesh.tris.Add(count + 2);
            }
            else
            {
                if (nodes.Count == 2)
                {
                    int             count2           = subMesh.verts.Count;
                    List <int>      list2            = tmpNeighbors;
                    OutputDirection outputDirection4 = nodes[0];
                    int             num              = list2.IndexOf(outputDirection4.neighbor);
                    List <int>      list3            = tmpNeighbors;
                    OutputDirection outputDirection5 = nodes[1];
                    int             num2             = list3.IndexOf(outputDirection5.neighbor);
                    if (allowSmoothTransition && Mathf.Abs(num - num2) > 1 && Mathf.Abs((num - num2 + tmpVerts.Count) % tmpVerts.Count) > 1)
                    {
                        AddPathEndpoint(subMesh, tmpVerts, num, color, tileID, nodes[0]);
                        AddPathEndpoint(subMesh, tmpVerts, num2, color, tileID, nodes[1]);
                        subMesh.tris.Add(count2);
                        subMesh.tris.Add(count2 + 5);
                        subMesh.tris.Add(count2 + 1);
                        subMesh.tris.Add(count2 + 5);
                        subMesh.tris.Add(count2 + 4);
                        subMesh.tris.Add(count2 + 1);
                        subMesh.tris.Add(count2 + 1);
                        subMesh.tris.Add(count2 + 4);
                        subMesh.tris.Add(count2 + 2);
                        subMesh.tris.Add(count2 + 4);
                        subMesh.tris.Add(count2 + 3);
                        subMesh.tris.Add(count2 + 2);
                        return;
                    }
                }
                float num3 = 0f;
                for (int i = 0; i < nodes.Count; i++)
                {
                    float           a = num3;
                    OutputDirection outputDirection6 = nodes[i];
                    num3 = Mathf.Max(a, outputDirection6.width);
                }
                Vector3 tileCenter2 = worldGrid.GetTileCenter(tileID);
                tmpHexVerts.Clear();
                for (int j = 0; j < tmpVerts.Count; j++)
                {
                    tmpHexVerts.Add(FinalizePoint(Vector3.LerpUnclamped(tileCenter2, tmpVerts[j], num3 * 0.5f * 2f), 0f, 0f));
                }
                tileCenter2 = FinalizePoint(tileCenter2, 0f, 0f);
                int count3 = subMesh.verts.Count;
                subMesh.verts.Add(tileCenter2);
                subMesh.colors.Add(color);
                int count4 = subMesh.verts.Count;
                for (int k = 0; k < tmpHexVerts.Count; k++)
                {
                    subMesh.verts.Add(tmpHexVerts[k]);
                    subMesh.colors.Add(color.MutateAlpha(0));
                    subMesh.tris.Add(count3);
                    subMesh.tris.Add(count4 + (k + 1) % tmpHexVerts.Count);
                    subMesh.tris.Add(count4 + k);
                }
                for (int l = 0; l < nodes.Count; l++)
                {
                    OutputDirection outputDirection7 = nodes[l];
                    if (outputDirection7.width != 0f)
                    {
                        int             count5           = subMesh.verts.Count;
                        List <int>      list4            = tmpNeighbors;
                        OutputDirection outputDirection8 = nodes[l];
                        int             num4             = list4.IndexOf(outputDirection8.neighbor);
                        AddPathEndpoint(subMesh, tmpVerts, num4, color, tileID, nodes[l]);
                        subMesh.tris.Add(count5);
                        subMesh.tris.Add(count4 + (num4 + tmpHexVerts.Count - 1) % tmpHexVerts.Count);
                        subMesh.tris.Add(count3);
                        subMesh.tris.Add(count5);
                        subMesh.tris.Add(count3);
                        subMesh.tris.Add(count5 + 1);
                        subMesh.tris.Add(count5 + 1);
                        subMesh.tris.Add(count3);
                        subMesh.tris.Add(count5 + 2);
                        subMesh.tris.Add(count3);
                        subMesh.tris.Add(count4 + (num4 + 2) % tmpHexVerts.Count);
                        subMesh.tris.Add(count5 + 2);
                    }
                }
            }
        }
Esempio n. 18
0
        public WorldPath FindPath(int startTile, int destTile, Caravan caravan, Func <float, bool> terminator = null)
        {
            if (startTile < 0)
            {
                Log.Error("Tried to FindPath with invalid start tile " + startTile + ", caravan= " + caravan);
                return(WorldPath.NotFound);
            }
            if (destTile < 0)
            {
                Log.Error("Tried to FindPath with invalid dest tile " + destTile + ", caravan= " + caravan);
                return(WorldPath.NotFound);
            }
            if (caravan != null)
            {
                if (!caravan.CanReach(destTile))
                {
                    return(WorldPath.NotFound);
                }
            }
            else if (!Find.WorldReachability.CanReach(startTile, destTile))
            {
                return(WorldPath.NotFound);
            }
            World      world = Find.World;
            WorldGrid  grid  = world.grid;
            List <int> tileIDToNeighbors_offsets = grid.tileIDToNeighbors_offsets;
            List <int> tileIDToNeighbors_values  = grid.tileIDToNeighbors_values;
            Vector3    normalized = grid.GetTileCenter(destTile).normalized;

            int[] pathGrid = world.pathGrid.pathGrid;
            int   num      = 0;
            int   num2     = (caravan == null) ? 2500 : caravan.TicksPerMove;
            int   num3     = this.CalculateHeuristicStrength(startTile, destTile);

            this.statusOpenValue   += 2;
            this.statusClosedValue += 2;
            if (this.statusClosedValue >= 65435)
            {
                this.ResetStatuses();
            }
            this.calcGrid[startTile].knownCost     = 0;
            this.calcGrid[startTile].heuristicCost = 0;
            this.calcGrid[startTile].costNodeCost  = 0;
            this.calcGrid[startTile].parentTile    = startTile;
            this.calcGrid[startTile].status        = this.statusOpenValue;
            this.openList.Clear();
            this.openList.Push(new CostNode(startTile, 0));
            while (true)
            {
                if (this.openList.Count <= 0)
                {
                    Log.Warning(caravan + " pathing from " + startTile + " to " + destTile + " ran out of tiles to process.");
                    return(WorldPath.NotFound);
                }
                CostNode costNode = this.openList.Pop();
                if (costNode.cost == this.calcGrid[costNode.tile].costNodeCost)
                {
                    int tile = costNode.tile;
                    if (this.calcGrid[tile].status != this.statusClosedValue)
                    {
                        if (DebugViewSettings.drawPaths)
                        {
                            Find.WorldDebugDrawer.FlashTile(tile, (float)((float)this.calcGrid[tile].knownCost / 375000.0), this.calcGrid[tile].knownCost.ToString(), 50);
                        }
                        if (tile == destTile)
                        {
                            return(this.FinalizedPath(tile));
                        }
                        if (num > 500000)
                        {
                            Log.Warning(caravan + " pathing from " + startTile + " to " + destTile + " hit search limit of " + 500000 + " tiles.");
                            return(WorldPath.NotFound);
                        }
                        int num4 = (tile + 1 >= tileIDToNeighbors_offsets.Count) ? tileIDToNeighbors_values.Count : tileIDToNeighbors_offsets[tile + 1];
                        for (int i = tileIDToNeighbors_offsets[tile]; i < num4; i++)
                        {
                            int    num5 = tileIDToNeighbors_values[i];
                            int    num7;
                            ushort status;
                            if (this.calcGrid[num5].status != this.statusClosedValue && !world.Impassable(num5))
                            {
                                int num6 = num2;
                                num6  += pathGrid[num5];
                                num6   = (int)((float)num6 * grid.GetRoadMovementMultiplierFast(tile, num5));
                                num7   = num6 + this.calcGrid[tile].knownCost;
                                status = this.calcGrid[num5].status;
                                if (status != this.statusClosedValue && status != this.statusOpenValue)
                                {
                                    goto IL_041e;
                                }
                                if (this.calcGrid[num5].knownCost > num7)
                                {
                                    goto IL_041e;
                                }
                            }
                            continue;
IL_041e:
                            Vector3 tileCenter = grid.GetTileCenter(num5);
                            if (status != this.statusClosedValue && status != this.statusOpenValue)
                            {
                                float num8 = grid.ApproxDistanceInTiles(GenMath.SphericalDistance(tileCenter.normalized, normalized));
                                this.calcGrid[num5].heuristicCost = Mathf.RoundToInt((float)((float)num2 * num8 * (float)num3 * 0.5));
                            }
                            int num9 = num7 + this.calcGrid[num5].heuristicCost;
                            this.calcGrid[num5].parentTile   = tile;
                            this.calcGrid[num5].knownCost    = num7;
                            this.calcGrid[num5].status       = this.statusOpenValue;
                            this.calcGrid[num5].costNodeCost = num9;
                            this.openList.Push(new CostNode(num5, num9));
                        }
                        num++;
                        this.calcGrid[tile].status = this.statusClosedValue;
                        if (terminator != null && terminator((float)this.calcGrid[tile].costNodeCost))
                        {
                            break;
                        }
                    }
                }
            }
            return(WorldPath.NotFound);
        }