Esempio n. 1
0
        public static int CalculatedCostAt(int tile, bool perceivedStatic, float yearPercent = -1f)
        {
            int  num   = 0;
            Tile tile2 = Find.WorldGrid[tile];

            if (tile2.biome.impassable)
            {
                return(1000000);
            }
            if (yearPercent < 0.0)
            {
                yearPercent = (float)((float)WorldPathGrid.DayOfYearAt0Long / 60.0);
            }
            float   yearPct = yearPercent;
            Vector2 vector  = Find.WorldGrid.LongLatOf(tile);
            float   num2    = default(float);
            float   num3    = default(float);
            float   num4    = default(float);
            float   num5    = default(float);
            float   num6    = default(float);
            float   num7    = default(float);

            SeasonUtility.GetSeason(yearPct, vector.y, out num2, out num3, out num4, out num5, out num6, out num7);
            num += Mathf.RoundToInt((float)tile2.biome.pathCost_spring * num2 + (float)tile2.biome.pathCost_summer * num3 + (float)tile2.biome.pathCost_fall * num4 + (float)tile2.biome.pathCost_winter * num5 + (float)tile2.biome.pathCost_summer * num6 + (float)tile2.biome.pathCost_winter * num7);
            if (tile2.hilliness == Hilliness.Impassable)
            {
                return(1000000);
            }
            return(num + WorldPathGrid.CostFromTileHilliness(tile2.hilliness));
        }
        public static int CostToMove(int caravanTicksPerMove, int start, int end, int?ticksAbs = null, bool perceivedStatic = false, StringBuilder explanation = null, string caravanTicksPerMoveExplanation = null)
        {
            int result;

            if (start == end)
            {
                result = 0;
            }
            else
            {
                if (explanation != null)
                {
                    explanation.Append(caravanTicksPerMoveExplanation);
                    explanation.AppendLine();
                }
                StringBuilder stringBuilder = (explanation == null) ? null : new StringBuilder();
                float         num;
                if (perceivedStatic && explanation == null)
                {
                    num = Find.WorldPathGrid.PerceivedMovementDifficultyAt(end);
                }
                else
                {
                    num = WorldPathGrid.CalculatedMovementDifficultyAt(end, perceivedStatic, ticksAbs, stringBuilder);
                }
                float roadMovementDifficultyMultiplier = Find.WorldGrid.GetRoadMovementDifficultyMultiplier(start, end, stringBuilder);
                if (explanation != null)
                {
                    explanation.AppendLine();
                    explanation.Append("TileMovementDifficulty".Translate() + ":");
                    explanation.AppendLine();
                    explanation.Append(stringBuilder.ToString().Indented("  "));
                    explanation.AppendLine();
                    explanation.Append("  = " + (num * roadMovementDifficultyMultiplier).ToString("0.#"));
                }
                int num2 = (int)((float)caravanTicksPerMove * num * roadMovementDifficultyMultiplier);
                num2 = Mathf.Clamp(num2, 1, 120000);
                if (explanation != null)
                {
                    explanation.AppendLine();
                    explanation.AppendLine();
                    explanation.Append("FinalCaravanMovementSpeed".Translate() + ":");
                    int num3 = Mathf.CeilToInt((float)num2 / 1f);
                    explanation.AppendLine();
                    explanation.Append(string.Concat(new string[]
                    {
                        "  ",
                        (60000f / (float)caravanTicksPerMove).ToString("0.#"),
                        " / ",
                        (num * roadMovementDifficultyMultiplier).ToString("0.#"),
                        " = ",
                        (60000f / (float)num3).ToString("0.#"),
                        " ",
                        "TilesPerDay".Translate()
                    }));
                }
                result = num2;
            }
            return(result);
        }
Esempio n. 3
0
        private string GetTileTip(int tile, int pathIndex)
        {
            int           num           = paths[pathIndex].NodesReversed.IndexOf(tile);
            int           num2          = ((num > 0) ? paths[pathIndex].NodesReversed[num - 1] : ((pathIndex >= paths.Count - 1 || paths[pathIndex + 1].NodesReversed.Count < 2) ? (-1) : paths[pathIndex + 1].NodesReversed[paths[pathIndex + 1].NodesReversed.Count - 2]));
            int           num3          = cachedTicksToWaypoint[pathIndex] + CaravanArrivalTimeEstimator.EstimatedTicksToArrive(paths[pathIndex].FirstNode, tile, paths[pathIndex], 0f, CaravanTicksPerMove, GenTicks.TicksAbs + cachedTicksToWaypoint[pathIndex]);
            int           num4          = GenTicks.TicksAbs + num3;
            StringBuilder stringBuilder = new StringBuilder();

            if (num3 != 0)
            {
                stringBuilder.AppendLine("EstimatedTimeToTile".Translate(num3.ToStringTicksToDays("0.##")));
            }
            stringBuilder.AppendLine("ForagedFoodAmount".Translate() + ": " + Find.WorldGrid[tile].biome.forageability.ToStringPercent());
            stringBuilder.Append(VirtualPlantsUtility.GetVirtualPlantsStatusExplanationAt(tile, num4));
            if (num2 != -1)
            {
                stringBuilder.AppendLine();
                stringBuilder.AppendLine();
                StringBuilder stringBuilder2 = new StringBuilder();
                float         num5           = WorldPathGrid.CalculatedMovementDifficultyAt(num2, perceivedStatic: false, num4, stringBuilder2);
                float         roadMovementDifficultyMultiplier = Find.WorldGrid.GetRoadMovementDifficultyMultiplier(tile, num2, stringBuilder2);
                stringBuilder.Append("TileMovementDifficulty".Translate() + ":\n" + stringBuilder2.ToString().Indented("  "));
                stringBuilder.AppendLine();
                stringBuilder.Append("  = ");
                stringBuilder.Append((num5 * roadMovementDifficultyMultiplier).ToString("0.#"));
            }
            return(stringBuilder.ToString());
        }
        public static int CostToMove(int caravanTicksPerMove, int start, int end, float yearPercent = -1f)
        {
            int num = caravanTicksPerMove + WorldPathGrid.CalculatedCostAt(end, false, yearPercent);

            num = Mathf.RoundToInt((float)num * Find.WorldGrid.GetRoadMovementMultiplierFast(start, end));
            return(Mathf.Clamp(num, 1, 120000));
        }
Esempio n. 5
0
        public static float CalculatedMovementDifficultyAt(int tile, bool perceivedStatic, int?ticksAbs = null, StringBuilder explanation = null)
        {
            Tile tile2 = Find.WorldGrid[tile];

            if (explanation != null && explanation.Length > 0)
            {
                explanation.AppendLine();
            }
            if (tile2.biome.impassable || tile2.hilliness == Hilliness.Impassable)
            {
                if (explanation != null)
                {
                    explanation.Append("Impassable".Translate());
                }
                return(1000f);
            }
            float num = 0f;

            num += tile2.biome.movementDifficulty;
            if (explanation != null)
            {
                explanation.Append(tile2.biome.LabelCap + ": " + tile2.biome.movementDifficulty.ToStringWithSign("0.#"));
            }
            float num2 = WorldPathGrid.HillinessMovementDifficultyOffset(tile2.hilliness);

            num += num2;
            if (explanation != null && num2 != 0f)
            {
                explanation.AppendLine();
                explanation.Append(tile2.hilliness.GetLabelCap() + ": " + num2.ToStringWithSign("0.#"));
            }
            return(num + WorldPathGrid.GetCurrentWinterMovementDifficultyOffset(tile, new int?((!ticksAbs.HasValue) ? GenTicks.TicksAbs : ticksAbs.Value), explanation));
        }
Esempio n. 6
0
 public void RecalculatePerceivedPathCostAt(int tile, float yearPercent = -1f)
 {
     if (Find.WorldGrid.InBounds(tile))
     {
         bool flag = this.PassableFast(tile);
         this.pathGrid[tile] = WorldPathGrid.CalculatedCostAt(tile, true, yearPercent);
         if (flag != this.PassableFast(tile))
         {
             Find.WorldReachability.ClearCache();
         }
     }
 }
 public void RecalculatePerceivedMovementDifficultyAt(int tile, int?ticksAbs = null)
 {
     if (Find.WorldGrid.InBounds(tile))
     {
         bool flag = this.PassableFast(tile);
         this.movementDifficulty[tile] = WorldPathGrid.CalculatedMovementDifficultyAt(tile, true, ticksAbs, null);
         if (flag != this.PassableFast(tile))
         {
             Find.WorldReachability.ClearCache();
         }
     }
 }
        public static int CostToDisplay(Caravan caravan, int start, int end, float yearPercent = -1f)
        {
            if (start != end && end != -1)
            {
                return(Caravan_PathFollower.CostToMove(caravan.TicksPerMove, start, end, yearPercent));
            }
            int num = caravan.TicksPerMove;

            num += WorldPathGrid.CalculatedCostAt(start, false, yearPercent);
            Tile  tile = Find.WorldGrid[start];
            float num2 = 1f;

            if (tile.roads != null)
            {
                for (int i = 0; i < tile.roads.Count; i++)
                {
                    num2 = Mathf.Min(num2, tile.roads[i].road.movementCostMultiplier);
                }
            }
            return(Mathf.RoundToInt((float)num * num2));
        }
Esempio n. 9
0
        protected override void FillTab()
        {
            Rect outRect = new Rect(0f, 0f, WITab_Terrain.WinSize.x, WITab_Terrain.WinSize.y).ContractedBy(10f);
            Rect rect    = new Rect(0f, 0f, outRect.width - 16f, Mathf.Max(this.lastDrawnHeight, outRect.height));

            Widgets.BeginScrollView(outRect, ref this.scrollPosition, rect, true);
            Rect rect2 = rect;
            Rect rect3 = rect2;

            Text.Font = GameFont.Medium;
            Widgets.Label(rect3, base.SelTile.biome.LabelCap);
            Rect rect4 = rect2;

            rect4.yMin  += 35f;
            rect4.height = 99999f;
            Text.Font    = GameFont.Small;
            Listing_Standard listing_Standard = new Listing_Standard();

            listing_Standard.verticalSpacing = 0f;
            listing_Standard.Begin(rect4);
            Tile selTile   = base.SelTile;
            int  selTileID = base.SelTileID;

            listing_Standard.Label(selTile.biome.description, -1f, null);
            listing_Standard.Gap(8f);
            listing_Standard.GapLine(12f);
            if (!selTile.biome.implemented)
            {
                listing_Standard.Label(selTile.biome.LabelCap + " " + "BiomeNotImplemented".Translate(), -1f, null);
            }
            listing_Standard.LabelDouble("Terrain".Translate(), selTile.hilliness.GetLabelCap(), null);
            if (selTile.Roads != null)
            {
                listing_Standard.LabelDouble("Road".Translate(), (from roadlink in selTile.Roads
                                                                  select roadlink.road.label).Distinct <string>().ToCommaList(true).CapitalizeFirst(), null);
            }
            if (selTile.Rivers != null)
            {
                listing_Standard.LabelDouble("River".Translate(), selTile.Rivers.MaxBy((Tile.RiverLink riverlink) => riverlink.river.degradeThreshold).river.LabelCap, null);
            }
            if (!Find.World.Impassable(selTileID))
            {
                StringBuilder stringBuilder   = new StringBuilder();
                int           tile            = selTileID;
                bool          perceivedStatic = false;
                StringBuilder explanation     = stringBuilder;
                string        rightLabel      = (WorldPathGrid.CalculatedMovementDifficultyAt(tile, perceivedStatic, null, explanation) * Find.WorldGrid.GetRoadMovementDifficultyMultiplier(selTileID, -1, stringBuilder)).ToString("0.#");
                if (WorldPathGrid.WillWinterEverAffectMovementDifficulty(selTileID) && WorldPathGrid.GetCurrentWinterMovementDifficultyOffset(selTileID, null, null) < 2f)
                {
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine();
                    stringBuilder.Append(" (");
                    stringBuilder.Append("MovementDifficultyOffsetInWinter".Translate(new object[]
                    {
                        "+" + 2f.ToString("0.#")
                    }));
                    stringBuilder.Append(")");
                }
                listing_Standard.LabelDouble("MovementDifficulty".Translate(), rightLabel, stringBuilder.ToString());
            }
            if (selTile.biome.canBuildBase)
            {
                listing_Standard.LabelDouble("StoneTypesHere".Translate(), (from rt in Find.World.NaturalRockTypesIn(selTileID)
                                                                            select rt.label).ToCommaList(true).CapitalizeFirst(), null);
            }
            listing_Standard.LabelDouble("Elevation".Translate(), selTile.elevation.ToString("F0") + "m", null);
            listing_Standard.GapLine(12f);
            listing_Standard.LabelDouble("AvgTemp".Translate(), GenTemperature.GetAverageTemperatureLabel(selTileID), null);
            listing_Standard.LabelDouble("OutdoorGrowingPeriod".Translate(), Zone_Growing.GrowingQuadrumsDescription(selTileID), null);
            listing_Standard.LabelDouble("Rainfall".Translate(), selTile.rainfall.ToString("F0") + "mm", null);
            if (selTile.biome.foragedFood != null && selTile.biome.forageability > 0f)
            {
                listing_Standard.LabelDouble("Forageability".Translate(), selTile.biome.forageability.ToStringPercent() + " (" + selTile.biome.foragedFood.label + ")", null);
            }
            else
            {
                listing_Standard.LabelDouble("Forageability".Translate(), "0%", null);
            }
            listing_Standard.LabelDouble("AnimalsCanGrazeNow".Translate(), (!VirtualPlantsUtility.EnvironmentAllowsEatingVirtualPlantsNowAt(selTileID)) ? "No".Translate() : "Yes".Translate(), null);
            listing_Standard.GapLine(12f);
            listing_Standard.LabelDouble("AverageDiseaseFrequency".Translate(), string.Format("{0} {1}", (60f / selTile.biome.diseaseMtbDays).ToString("F1"), "PerYear".Translate()), null);
            listing_Standard.LabelDouble("TimeZone".Translate(), GenDate.TimeZoneAt(Find.WorldGrid.LongLatOf(selTileID).x).ToStringWithSign(), null);
            StringBuilder stringBuilder2 = new StringBuilder();
            Rot4          rot            = Find.World.CoastDirectionAt(selTileID);

            if (rot.IsValid)
            {
                stringBuilder2.AppendWithComma(("HasCoast" + rot.ToString()).Translate());
            }
            if (Find.World.HasCaves(selTileID))
            {
                stringBuilder2.AppendWithComma("HasCaves".Translate());
            }
            if (stringBuilder2.Length > 0)
            {
                listing_Standard.LabelDouble("SpecialFeatures".Translate(), stringBuilder2.ToString().CapitalizeFirst(), null);
            }
            if (Prefs.DevMode)
            {
                listing_Standard.LabelDouble("Debug world tile ID", selTileID.ToString(), null);
            }
            this.lastDrawnHeight = rect4.y + listing_Standard.CurHeight;
            listing_Standard.End();
            Widgets.EndScrollView();
        }
Esempio n. 10
0
        public static int CostToMove(int caravanTicksPerMove, int start, int end, int?ticksAbs = null, bool perceivedStatic = false, StringBuilder explanation = null, string caravanTicksPerMoveExplanation = null)
        {
            if (start == end)
            {
                return(0);
            }
            if (explanation != null)
            {
                explanation.Append(caravanTicksPerMoveExplanation);
                explanation.AppendLine();
            }
            StringBuilder stringBuilder = ((explanation != null) ? new StringBuilder() : null);
            float         num           = ((!perceivedStatic || explanation != null) ? WorldPathGrid.CalculatedMovementDifficultyAt(end, perceivedStatic, ticksAbs, stringBuilder) : Find.WorldPathGrid.PerceivedMovementDifficultyAt(end));
            float         roadMovementDifficultyMultiplier = Find.WorldGrid.GetRoadMovementDifficultyMultiplier(start, end, stringBuilder);

            if (explanation != null)
            {
                explanation.AppendLine();
                explanation.Append("TileMovementDifficulty".Translate() + ":");
                explanation.AppendLine();
                explanation.Append(stringBuilder.ToString().Indented("  "));
                explanation.AppendLine();
                explanation.Append("  = " + (num * roadMovementDifficultyMultiplier).ToString("0.#"));
            }
            int value = (int)((float)caravanTicksPerMove * num * roadMovementDifficultyMultiplier);

            value = Mathf.Clamp(value, 1, 30000);
            if (explanation != null)
            {
                explanation.AppendLine();
                explanation.AppendLine();
                explanation.Append("FinalCaravanMovementSpeed".Translate() + ":");
                int num2 = Mathf.CeilToInt((float)value / 1f);
                explanation.AppendLine();
                explanation.Append("  " + (60000f / (float)caravanTicksPerMove).ToString("0.#") + " / " + (num * roadMovementDifficultyMultiplier).ToString("0.#") + " = " + (60000f / (float)num2).ToString("0.#") + " " + "TilesPerDay".Translate());
            }
            return(value);
        }
Esempio n. 11
0
        protected override void FillTab()
        {
            Rect rect  = new Rect(0f, 0f, WITab_Terrain.WinSize.x, WITab_Terrain.WinSize.y).ContractedBy(10f);
            Rect rect2 = rect;

            Text.Font = GameFont.Medium;
            Widgets.Label(rect2, base.SelTile.biome.LabelCap);
            Rect rect3 = rect;

            rect3.yMin += 35f;
            Text.Font   = GameFont.Small;
            Listing_Standard listing_Standard = new Listing_Standard();

            listing_Standard.verticalSpacing = 0f;
            listing_Standard.Begin(rect3);
            Tile  selTile   = base.SelTile;
            int   selTileID = base.SelTileID;
            float y         = Find.WorldGrid.LongLatOf(selTileID).y;

            listing_Standard.Label(selTile.biome.description, -1f);
            listing_Standard.Gap(8f);
            listing_Standard.GapLine(12f);
            if (!selTile.biome.implemented)
            {
                listing_Standard.Label(selTile.biome.LabelCap + " " + "BiomeNotImplemented".Translate(), -1f);
            }
            listing_Standard.LabelDouble("Terrain".Translate(), selTile.hilliness.GetLabelCap());
            if (selTile.VisibleRoads != null)
            {
                listing_Standard.LabelDouble("Road".Translate(), GenText.ToCommaList((from roadlink in selTile.VisibleRoads
                                                                                      select roadlink.road.label).Distinct <string>(), true).CapitalizeFirst());
            }
            if (selTile.VisibleRivers != null)
            {
                listing_Standard.LabelDouble("River".Translate(), selTile.VisibleRivers.MaxBy((Tile.RiverLink riverlink) => riverlink.river.degradeThreshold).river.LabelCap);
            }
            if (!Find.World.Impassable(selTileID))
            {
                int num      = 2500;
                int numTicks = Mathf.Min(num + WorldPathGrid.CalculatedCostAt(selTileID, false, -1f), 120000);
                listing_Standard.LabelDouble("MovementTimeNow".Translate(), numTicks.ToStringTicksToPeriod(true, false, true));
                int numTicks2 = Mathf.Min(num + WorldPathGrid.CalculatedCostAt(selTileID, false, Season.Summer.GetMiddleYearPct(y)), 120000);
                listing_Standard.LabelDouble("MovementTimeSummer".Translate(), numTicks2.ToStringTicksToPeriod(true, false, true));
                int numTicks3 = Mathf.Min(num + WorldPathGrid.CalculatedCostAt(selTileID, false, Season.Winter.GetMiddleYearPct(y)), 120000);
                listing_Standard.LabelDouble("MovementTimeWinter".Translate(), numTicks3.ToStringTicksToPeriod(true, false, true));
            }
            if (selTile.biome.canBuildBase)
            {
                listing_Standard.LabelDouble("StoneTypesHere".Translate(), GenText.ToCommaList(from rt in Find.World.NaturalRockTypesIn(selTileID)
                                                                                               select rt.label, true).CapitalizeFirst());
            }
            listing_Standard.LabelDouble("Elevation".Translate(), selTile.elevation.ToString("F0") + "m");
            listing_Standard.GapLine(12f);
            listing_Standard.LabelDouble("AvgTemp".Translate(), selTile.temperature.ToStringTemperature("F1"));
            float celsiusTemp = GenTemperature.AverageTemperatureAtTileForTwelfth(selTileID, Season.Winter.GetMiddleTwelfth(y));

            listing_Standard.LabelDouble("AvgWinterTemp".Translate(), celsiusTemp.ToStringTemperature("F1"));
            float celsiusTemp2 = GenTemperature.AverageTemperatureAtTileForTwelfth(selTileID, Season.Summer.GetMiddleTwelfth(y));

            listing_Standard.LabelDouble("AvgSummerTemp".Translate(), celsiusTemp2.ToStringTemperature("F1"));
            listing_Standard.LabelDouble("OutdoorGrowingPeriod".Translate(), Zone_Growing.GrowingQuadrumsDescription(selTileID));
            listing_Standard.LabelDouble("Rainfall".Translate(), selTile.rainfall.ToString("F0") + "mm");
            listing_Standard.LabelDouble("AnimalsCanGrazeNow".Translate(), (!VirtualPlantsUtility.EnvironmentAllowsEatingVirtualPlantsNowAt(selTileID)) ? "No".Translate() : "Yes".Translate());
            listing_Standard.GapLine(12f);
            listing_Standard.LabelDouble("AverageDiseaseFrequency".Translate(), string.Format("{0} {1}", (60f / selTile.biome.diseaseMtbDays).ToString("F1"), "PerYear".Translate()));
            listing_Standard.LabelDouble("TimeZone".Translate(), GenDate.TimeZoneAt(Find.WorldGrid.LongLatOf(selTileID).x).ToStringWithSign());
            StringBuilder stringBuilder = new StringBuilder();
            Rot4          rot           = Find.World.CoastDirectionAt(selTileID);

            if (rot.IsValid)
            {
                stringBuilder.AppendWithComma(("HasCoast" + rot.ToString()).Translate());
            }
            if (Find.World.HasCaves(selTileID))
            {
                stringBuilder.AppendWithComma("HasCaves".Translate());
            }
            if (stringBuilder.Length > 0)
            {
                listing_Standard.LabelDouble("SpecialFeatures".Translate(), stringBuilder.ToString().CapitalizeFirst());
            }
            if (Prefs.DevMode)
            {
                listing_Standard.LabelDouble("Debug world tile ID", selTileID.ToString());
            }
            listing_Standard.End();
        }