public static int EstimatedTicksToArrive(Caravan caravan, bool allowCaching)
        {
            if (allowCaching && caravan == CaravanArrivalTimeEstimator.cachedForCaravan && caravan.pather.Destination == CaravanArrivalTimeEstimator.cachedForDest && Find.TickManager.TicksGame - CaravanArrivalTimeEstimator.cacheTicks < 100)
            {
                return(CaravanArrivalTimeEstimator.cachedResult);
            }
            int to;
            int result;

            if (!caravan.Spawned || !caravan.pather.Moving || caravan.pather.curPath == null)
            {
                to     = -1;
                result = 0;
            }
            else
            {
                to     = caravan.pather.Destination;
                result = CaravanArrivalTimeEstimator.EstimatedTicksToArrive(caravan.Tile, to, caravan.pather.curPath, caravan.pather.nextTileCostLeft, caravan.TicksPerMove, Find.TickManager.TicksAbs);
            }
            if (allowCaching)
            {
                CaravanArrivalTimeEstimator.cacheTicks       = Find.TickManager.TicksGame;
                CaravanArrivalTimeEstimator.cachedForCaravan = caravan;
                CaravanArrivalTimeEstimator.cachedForDest    = to;
                CaravanArrivalTimeEstimator.cachedResult     = result;
            }
            return(result);
        }
Beispiel #2
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());
        }
Beispiel #3
0
        private void RecreatePaths()
        {
            ReleasePaths();
            WorldPathFinder worldPathFinder = Find.WorldPathFinder;

            for (int i = 1; i < waypoints.Count; i++)
            {
                paths.Add(worldPathFinder.FindPath(waypoints[i - 1].Tile, waypoints[i].Tile, null));
            }
            cachedTicksToWaypoint.Clear();
            int num = 0;
            int caravanTicksPerMove = CaravanTicksPerMove;

            for (int j = 0; j < waypoints.Count; j++)
            {
                if (j == 0)
                {
                    cachedTicksToWaypoint.Add(0);
                }
                else
                {
                    num += CaravanArrivalTimeEstimator.EstimatedTicksToArrive(waypoints[j - 1].Tile, waypoints[j].Tile, paths[j - 1], 0f, caravanTicksPerMove, GenTicks.TicksAbs + num);
                    cachedTicksToWaypoint.Add(num);
                }
            }
        }
 public static int EstimatedTicksToArrive(int from, int to, Caravan caravan)
 {
     using (WorldPath worldPath = Find.WorldPathFinder.FindPath(from, to, caravan, null))
     {
         if (worldPath == WorldPath.NotFound)
         {
             return(0);
         }
         return(CaravanArrivalTimeEstimator.EstimatedTicksToArrive(from, to, worldPath, 0f, CaravanTicksPerMoveUtility.GetTicksPerMove(caravan), Find.TickManager.TicksAbs));
     }
 }
        public static int EstimatedTicksToArrive(int from, int to, Caravan caravan)
        {
            int result;

            using (WorldPath worldPath = Find.WorldPathFinder.FindPath(from, to, caravan, null))
            {
                if (!worldPath.Found)
                {
                    result = 0;
                }
                else
                {
                    result = CaravanArrivalTimeEstimator.EstimatedTicksToArrive(from, to, worldPath, 0f, (caravan == null) ? 3300 : caravan.TicksPerMove, Find.TickManager.TicksAbs);
                }
            }
            return(result);
        }
Beispiel #6
0
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            if (!caravan.Spawned)
            {
                return(new GizmoResult(GizmoState.Clear));
            }
            Rect rect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), 75f);

            Widgets.DrawWindowBackground(rect);
            GUI.BeginGroup(rect);
            Rect          rect2         = rect.AtZero();
            int?          ticksToArrive = (caravan.pather.Moving ? new int?(CaravanArrivalTimeEstimator.EstimatedTicksToArrive(caravan, allowCaching: true)) : null);
            StringBuilder stringBuilder = new StringBuilder();

            CaravanUIUtility.DrawCaravanInfo(new CaravanUIUtility.CaravanInfo(tilesPerDay: TilesPerDayCalculator.ApproxTilesPerDay(caravan, stringBuilder), massUsage: caravan.MassUsage, massCapacity: caravan.MassCapacity, massCapacityExplanation: caravan.MassCapacityExplanation, tilesPerDayExplanation: stringBuilder.ToString(), daysWorthOfFood: caravan.DaysWorthOfFood, foragedFoodPerDay: caravan.forage.ForagedFoodPerDay, foragedFoodPerDayExplanation: caravan.forage.ForagedFoodPerDayExplanation, visibility: caravan.Visibility, visibilityExplanation: caravan.VisibilityExplanation), null, caravan.Tile, ticksToArrive, -9999f, rect2, lerpMassColor: true, null, multiline: true);
            GUI.EndGroup();
            GenUI.AbsorbClicksInRect(rect);
            return(new GizmoResult(GizmoState.Clear));
        }
Beispiel #7
0
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(base.GetInspectString());
            if (stringBuilder.Length != 0)
            {
                stringBuilder.AppendLine();
            }
            int num  = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;
            int num5 = 0;

            for (int i = 0; i < pawns.Count; i++)
            {
                if (pawns[i].IsColonist)
                {
                    num++;
                }
                else if (pawns[i].RaceProps.Animal)
                {
                    num2++;
                }
                else if (pawns[i].IsPrisoner)
                {
                    num3++;
                }
                if (pawns[i].Downed)
                {
                    num4++;
                }
                if (pawns[i].InMentalState)
                {
                    num5++;
                }
            }
            stringBuilder.Append("CaravanColonistsCount".Translate(num, (num != 1) ? Faction.OfPlayer.def.pawnsPlural : Faction.OfPlayer.def.pawnSingular));
            if (num2 == 1)
            {
                stringBuilder.Append(", " + "CaravanAnimal".Translate());
            }
            else if (num2 > 1)
            {
                stringBuilder.Append(", " + "CaravanAnimalsCount".Translate(num2));
            }
            if (num3 == 1)
            {
                stringBuilder.Append(", " + "CaravanPrisoner".Translate());
            }
            else if (num3 > 1)
            {
                stringBuilder.Append(", " + "CaravanPrisonersCount".Translate(num3));
            }
            stringBuilder.AppendLine();
            if (num5 > 0)
            {
                stringBuilder.Append("CaravanPawnsInMentalState".Translate(num5));
            }
            if (num4 > 0)
            {
                if (num5 > 0)
                {
                    stringBuilder.Append(", ");
                }
                stringBuilder.Append("CaravanPawnsDowned".Translate(num4));
            }
            if (num5 > 0 || num4 > 0)
            {
                stringBuilder.AppendLine();
            }
            if (pather.Moving)
            {
                if (pather.ArrivalAction != null)
                {
                    stringBuilder.Append(pather.ArrivalAction.ReportString);
                }
                else
                {
                    stringBuilder.Append("CaravanTraveling".Translate());
                }
            }
            else
            {
                SettlementBase settlementBase = CaravanVisitUtility.SettlementVisitedNow(this);
                if (settlementBase != null)
                {
                    stringBuilder.Append("CaravanVisiting".Translate(settlementBase.Label));
                }
                else
                {
                    stringBuilder.Append("CaravanWaiting".Translate());
                }
            }
            if (pather.Moving)
            {
                float num6 = (float)CaravanArrivalTimeEstimator.EstimatedTicksToArrive(this, allowCaching: true) / 60000f;
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanEstimatedTimeToDestination".Translate(num6.ToString("0.#")));
            }
            if (AllOwnersDowned)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("AllCaravanMembersDowned".Translate());
            }
            else if (AllOwnersHaveMentalBreak)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("AllCaravanMembersMentalBreak".Translate());
            }
            else if (ImmobilizedByMass)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanImmobilizedByMass".Translate());
            }
            if (needs.AnyPawnOutOfFood(out string malnutritionHediff))
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanOutOfFood".Translate());
                if (!malnutritionHediff.NullOrEmpty())
                {
                    stringBuilder.Append(" ");
                    stringBuilder.Append(malnutritionHediff);
                    stringBuilder.Append(".");
                }
            }
            if (!pather.MovingNow)
            {
                int usedBedCount = beds.GetUsedBedCount();
                stringBuilder.AppendLine();
                stringBuilder.Append(CaravanBedUtility.AppendUsingBedsLabel("CaravanResting".Translate(), usedBedCount));
            }
            else
            {
                string inspectStringLine = carryTracker.GetInspectStringLine();
                if (!inspectStringLine.NullOrEmpty())
                {
                    stringBuilder.AppendLine();
                    stringBuilder.Append(inspectStringLine);
                }
                string inBedForMedicalReasonsInspectStringLine = beds.GetInBedForMedicalReasonsInspectStringLine();
                if (!inBedForMedicalReasonsInspectStringLine.NullOrEmpty())
                {
                    stringBuilder.AppendLine();
                    stringBuilder.Append(inBedForMedicalReasonsInspectStringLine);
                }
            }
            return(stringBuilder.ToString());
        }
 public static int EstimatedTicksToArrive(int from, int to, WorldPath path, float nextTileCostLeft, int caravanTicksPerMove, int curTicksAbs)
 {
     CaravanArrivalTimeEstimator.tmpTicksToArrive.Clear();
     CaravanArrivalTimeEstimator.EstimatedTicksToArriveToEvery(from, to, path, nextTileCostLeft, caravanTicksPerMove, curTicksAbs, CaravanArrivalTimeEstimator.tmpTicksToArrive);
     return(CaravanArrivalTimeEstimator.EstimatedTicksToArrive(to, CaravanArrivalTimeEstimator.tmpTicksToArrive));
 }
Beispiel #9
0
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(base.GetInspectString());
            if (stringBuilder.Length != 0)
            {
                stringBuilder.AppendLine();
            }
            if (this.Resting)
            {
                stringBuilder.Append("CaravanResting".Translate());
            }
            else if (this.AnyPawnHasExtremeMentalBreak)
            {
                stringBuilder.Append("CaravanMemberMentalBreak".Translate(new object[]
                {
                    this.FirstPawnWithExtremeMentalBreak.LabelShort
                }));
            }
            else if (this.AllOwnersDowned)
            {
                stringBuilder.Append("AllCaravanMembersDowned".Translate());
            }
            else if (this.AllOwnersHaveMentalBreak)
            {
                stringBuilder.Append("AllCaravanMembersMentalBreak".Translate());
            }
            else if (this.pather.Moving)
            {
                if (this.pather.arrivalAction != null)
                {
                    stringBuilder.Append(this.pather.arrivalAction.ReportString);
                }
                else
                {
                    stringBuilder.Append("CaravanTraveling".Translate());
                }
            }
            else
            {
                Settlement settlement = CaravanVisitUtility.SettlementVisitedNow(this);
                if (settlement != null)
                {
                    stringBuilder.Append("CaravanVisiting".Translate(new object[]
                    {
                        settlement.Label
                    }));
                }
                else
                {
                    stringBuilder.Append("CaravanWaiting".Translate());
                }
            }
            if (this.pather.Moving)
            {
                float num = (float)CaravanArrivalTimeEstimator.EstimatedTicksToArrive(this, true) / 60000f;
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanEstimatedTimeToDestination".Translate(new object[]
                {
                    num.ToString("0.#")
                }));
            }
            if (this.ImmobilizedByMass)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanImmobilizedByMass".Translate());
            }
            string text;

            if (CaravanPawnsNeedsUtility.AnyPawnOutOfFood(this, out text))
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanOutOfFood".Translate());
                if (!text.NullOrEmpty())
                {
                    stringBuilder.Append(" ");
                    stringBuilder.Append(text);
                    stringBuilder.Append(".");
                }
            }
            else if (this.DaysWorthOfFood.First < 1000f)
            {
                Pair <float, float> daysWorthOfFood = this.DaysWorthOfFood;
                stringBuilder.AppendLine();
                if (daysWorthOfFood.Second < 1000f)
                {
                    stringBuilder.Append("CaravanDaysOfFoodRot".Translate(new object[]
                    {
                        daysWorthOfFood.First.ToString("0.#"),
                        daysWorthOfFood.Second.ToString("0.#")
                    }));
                }
                else
                {
                    stringBuilder.Append("CaravanDaysOfFood".Translate(new object[]
                    {
                        daysWorthOfFood.First.ToString("0.#")
                    }));
                }
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine(string.Concat(new string[]
            {
                "CaravanBaseMovementTime".Translate(),
                ": ",
                ((float)this.TicksPerMove / 2500f).ToString("0.##"),
                " ",
                "CaravanHoursPerTile".Translate()
            }));
            stringBuilder.AppendLine("CurrentTileMovementTime".Translate() + ": " + Caravan_PathFollower.CostToDisplay(this, base.Tile, this.pather.nextTile, -1f).ToStringTicksToPeriod(true, false, true));
            stringBuilder.Append("StealthFactor".Translate() + ": " + CaravanIncidentUtility.CalculateCaravanStealthFactor(this.PawnsListForReading.Count).ToString("F1"));
            return(stringBuilder.ToString());
        }
Beispiel #10
0
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            if (!this.caravan.Spawned)
            {
                return(new GizmoResult(GizmoState.Clear));
            }
            Rect rect = new Rect(topLeft.x, topLeft.y, this.GetWidth(maxWidth), 75f);

            Widgets.DrawWindowBackground(rect);
            GUI.BeginGroup(rect);
            Rect          rect2         = rect.AtZero();
            int?          ticksToArrive = (!this.caravan.pather.Moving) ? null : new int?(CaravanArrivalTimeEstimator.EstimatedTicksToArrive(this.caravan, true));
            StringBuilder stringBuilder = new StringBuilder();
            float         tilesPerDay   = TilesPerDayCalculator.ApproxTilesPerDay(this.caravan, stringBuilder);

            CaravanUIUtility.DrawCaravanInfo(new CaravanUIUtility.CaravanInfo(this.caravan.MassUsage, this.caravan.MassCapacity, this.caravan.MassCapacityExplanation, tilesPerDay, stringBuilder.ToString(), this.caravan.DaysWorthOfFood, this.caravan.forage.ForagedFoodPerDay, this.caravan.forage.ForagedFoodPerDayExplanation, this.caravan.Visibility, this.caravan.VisibilityExplanation, -1f, -1f, null), null, this.caravan.Tile, ticksToArrive, -9999f, rect2, true, null, true);
            GUI.EndGroup();
            GenUI.AbsorbClicksInRect(rect);
            return(new GizmoResult(GizmoState.Clear));
        }