Пример #1
0
        public static int LeftNonRestTicksAt(int tile, long ticksAbs)
        {
            if (CaravanRestUtility.WouldBeRestingAt(tile, ticksAbs))
            {
                return(0);
            }
            float num = GenDate.HourFloat(ticksAbs, Find.WorldGrid.LongLatOf(tile).x);

            return(Mathf.CeilToInt((22f - num) * 2500f));
        }
        public static int LeftNonRestTicksAt(int tile, long ticksAbs)
        {
            if (CaravanRestUtility.WouldBeRestingAt(tile, ticksAbs))
            {
                return(0);
            }
            Vector2 vector = Find.WorldGrid.LongLatOf(tile);
            float   num    = GenDate.HourFloat(ticksAbs, vector.x);

            return(Mathf.CeilToInt((float)((22.0 - num) * 2500.0)));
        }
Пример #3
0
        public static int LeftRestTicksAt(int tile, long ticksAbs)
        {
            int result;

            if (!CaravanRestUtility.WouldBeRestingAt(tile, ticksAbs))
            {
                result = 0;
            }
            else
            {
                float num = GenDate.HourFloat(ticksAbs, Find.WorldGrid.LongLatOf(tile).x);
                if (num < 6f)
                {
                    result = Mathf.CeilToInt((6f - num) * 2500f);
                }
                else
                {
                    result = Mathf.CeilToInt((24f - num + 6f) * 2500f);
                }
            }
            return(result);
        }
 public static int LeftNonRestTicksAt(int tile)
 {
     return(CaravanRestUtility.LeftNonRestTicksAt(tile, GenTicks.TicksAbs));
 }
 public static bool RestingNowAt(int tile)
 {
     return(CaravanRestUtility.WouldBeRestingAt(tile, GenTicks.TicksAbs));
 }
        public static int EstimatedTicksToArrive(int from, int to, WorldPath path, float nextTileCostLeft, int caravanTicksPerMove, int curTicksAbs)
        {
            int num  = 0;
            int num2 = from;
            int num3 = 0;
            int num4 = Mathf.CeilToInt(20000f) - 1;
            int num5 = 60000 - num4;
            int num6 = 0;
            int num7 = 0;
            int num8;

            if (CaravanRestUtility.WouldBeRestingAt(from, (long)curTicksAbs))
            {
                num += CaravanRestUtility.LeftRestTicksAt(from, (long)curTicksAbs);
                num8 = num5;
            }
            else
            {
                num8 = CaravanRestUtility.LeftNonRestTicksAt(from, (long)curTicksAbs);
            }
            while (true)
            {
                num7++;
                if (num7 >= 10000)
                {
                    break;
                }
                if (num6 <= 0)
                {
                    if (num2 == to)
                    {
                        return(num);
                    }
                    bool flag  = num3 == 0;
                    int  start = num2;
                    num2 = path.Peek(num3);
                    num3++;
                    float num9;
                    if (flag)
                    {
                        num9 = nextTileCostLeft;
                    }
                    else
                    {
                        int   num10       = curTicksAbs + num;
                        float yearPercent = (float)GenDate.DayOfYear((long)num10, 0f) / 60f;
                        num9 = (float)Caravan_PathFollower.CostToMove(caravanTicksPerMove, start, num2, yearPercent);
                    }
                    num6 = Mathf.CeilToInt(num9 / 1f);
                }
                if (num8 < num6)
                {
                    num  += num8;
                    num6 -= num8;
                    num  += num4;
                    num8  = num5;
                }
                else
                {
                    num  += num6;
                    num8 -= num6;
                    num6  = 0;
                }
            }
            Log.ErrorOnce("Could not calculate estimated ticks to arrive. Too many iterations.", 1837451324);
            return(num);
        }
Пример #7
0
        public static void EstimatedTicksToArriveToEvery(int from, int to, WorldPath path, float nextTileCostLeft, int caravanTicksPerMove, int curTicksAbs, List <Pair <int, int> > outTicksToArrive)
        {
            outTicksToArrive.Clear();
            outTicksToArrive.Add(new Pair <int, int>(from, 0));
            if (from == to)
            {
                outTicksToArrive.Add(new Pair <int, int>(to, 0));
            }
            else
            {
                int num  = 0;
                int num2 = from;
                int num3 = 0;
                int num4 = Mathf.CeilToInt(20000f) - 1;
                int num5 = 60000 - num4;
                int num6 = 0;
                int num7 = 0;
                int num9;
                if (CaravanRestUtility.WouldBeRestingAt(from, (long)curTicksAbs))
                {
                    if (Caravan_PathFollower.IsValidFinalPushDestination(to) && (path.Peek(0) == to || (nextTileCostLeft <= 0f && path.NodesLeftCount >= 2 && path.Peek(1) == to)))
                    {
                        float costToMove = CaravanArrivalTimeEstimator.GetCostToMove(nextTileCostLeft, path.Peek(0) == to, curTicksAbs, num, caravanTicksPerMove, from, to);
                        int   num8       = Mathf.CeilToInt(costToMove / 1f);
                        if (num8 <= 10000)
                        {
                            num += num8;
                            outTicksToArrive.Add(new Pair <int, int>(to, num));
                            return;
                        }
                    }
                    num += CaravanRestUtility.LeftRestTicksAt(from, (long)curTicksAbs);
                    num9 = num5;
                }
                else
                {
                    num9 = CaravanRestUtility.LeftNonRestTicksAt(from, (long)curTicksAbs);
                }
                for (;;)
                {
                    num7++;
                    if (num7 >= 10000)
                    {
                        break;
                    }
                    if (num6 <= 0)
                    {
                        if (num2 == to)
                        {
                            goto Block_10;
                        }
                        bool firstInPath = num3 == 0;
                        int  num10       = num2;
                        num2 = path.Peek(num3);
                        num3++;
                        outTicksToArrive.Add(new Pair <int, int>(num10, num));
                        float costToMove2 = CaravanArrivalTimeEstimator.GetCostToMove(nextTileCostLeft, firstInPath, curTicksAbs, num, caravanTicksPerMove, num10, num2);
                        num6 = Mathf.CeilToInt(costToMove2 / 1f);
                    }
                    if (num9 < num6)
                    {
                        num  += num9;
                        num6 -= num9;
                        if (num2 == to && num6 <= 10000 && Caravan_PathFollower.IsValidFinalPushDestination(to))
                        {
                            goto Block_14;
                        }
                        num += num4;
                        num9 = num5;
                    }
                    else
                    {
                        num  += num6;
                        num9 -= num6;
                        num6  = 0;
                    }
                }
                Log.ErrorOnce("Could not calculate estimated ticks to arrive. Too many iterations.", 1837451324, false);
                outTicksToArrive.Add(new Pair <int, int>(to, num));
                return;

Block_10:
                outTicksToArrive.Add(new Pair <int, int>(to, num));
                return;

Block_14:
                num += num6;
                outTicksToArrive.Add(new Pair <int, int>(to, num));
            }
        }
        private static float ApproxDaysWorthOfFood(List <Pawn> pawns, List <ThingDefCount> extraFood, int tile, IgnorePawnsInventoryMode ignoreInventory, Faction faction, WorldPath path = null, float nextTileCostLeft = 0f, int caravanTicksPerMove = 3500, bool assumeCaravanMoving = true)
        {
            float result;

            if (!DaysWorthOfFoodCalculator.AnyFoodEatingPawn(pawns))
            {
                result = 600f;
            }
            else
            {
                if (!assumeCaravanMoving)
                {
                    path = null;
                }
                DaysWorthOfFoodCalculator.tmpFood.Clear();
                if (extraFood != null)
                {
                    int i     = 0;
                    int count = extraFood.Count;
                    while (i < count)
                    {
                        ThingDefCount item = extraFood[i];
                        if (item.ThingDef.IsNutritionGivingIngestible && item.Count > 0)
                        {
                            DaysWorthOfFoodCalculator.tmpFood.Add(item);
                        }
                        i++;
                    }
                }
                int j      = 0;
                int count2 = pawns.Count;
                while (j < count2)
                {
                    Pawn pawn = pawns[j];
                    if (!InventoryCalculatorsUtility.ShouldIgnoreInventoryOf(pawn, ignoreInventory))
                    {
                        ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;
                        int k      = 0;
                        int count3 = innerContainer.Count;
                        while (k < count3)
                        {
                            Thing thing = innerContainer[k];
                            if (thing.def.IsNutritionGivingIngestible)
                            {
                                DaysWorthOfFoodCalculator.tmpFood.Add(new ThingDefCount(thing.def, thing.stackCount));
                            }
                            k++;
                        }
                    }
                    j++;
                }
                DaysWorthOfFoodCalculator.tmpFood2.Clear();
                DaysWorthOfFoodCalculator.tmpFood2.AddRange(DaysWorthOfFoodCalculator.tmpFood);
                DaysWorthOfFoodCalculator.tmpFood.Clear();
                int l      = 0;
                int count4 = DaysWorthOfFoodCalculator.tmpFood2.Count;
                while (l < count4)
                {
                    ThingDefCount item2  = DaysWorthOfFoodCalculator.tmpFood2[l];
                    bool          flag   = false;
                    int           m      = 0;
                    int           count5 = DaysWorthOfFoodCalculator.tmpFood.Count;
                    while (m < count5)
                    {
                        ThingDefCount thingDefCount = DaysWorthOfFoodCalculator.tmpFood[m];
                        if (thingDefCount.ThingDef == item2.ThingDef)
                        {
                            DaysWorthOfFoodCalculator.tmpFood[m] = thingDefCount.WithCount(thingDefCount.Count + item2.Count);
                            flag = true;
                            break;
                        }
                        m++;
                    }
                    if (!flag)
                    {
                        DaysWorthOfFoodCalculator.tmpFood.Add(item2);
                    }
                    l++;
                }
                DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodForPawn.Clear();
                int n      = 0;
                int count6 = pawns.Count;
                while (n < count6)
                {
                    DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodForPawn.Add(0f);
                    n++;
                }
                int ticksAbs = Find.TickManager.TicksAbs;
                DaysWorthOfFoodCalculator.tmpTicksToArrive.Clear();
                if (path != null && path.Found)
                {
                    CaravanArrivalTimeEstimator.EstimatedTicksToArriveToEvery(tile, path.LastNode, path, nextTileCostLeft, caravanTicksPerMove, ticksAbs, DaysWorthOfFoodCalculator.tmpTicksToArrive);
                }
                DaysWorthOfFoodCalculator.cachedNutritionBetweenHungryAndFed.Clear();
                DaysWorthOfFoodCalculator.cachedTicksUntilHungryWhenFed.Clear();
                DaysWorthOfFoodCalculator.cachedMaxFoodLevel.Clear();
                int num    = 0;
                int count7 = pawns.Count;
                while (num < count7)
                {
                    Pawn      pawn2 = pawns[num];
                    Need_Food food  = pawn2.needs.food;
                    DaysWorthOfFoodCalculator.cachedNutritionBetweenHungryAndFed.Add(food.NutritionBetweenHungryAndFed);
                    DaysWorthOfFoodCalculator.cachedTicksUntilHungryWhenFed.Add(food.TicksUntilHungryWhenFed);
                    DaysWorthOfFoodCalculator.cachedMaxFoodLevel.Add(food.MaxLevel);
                    num++;
                }
                float     num2      = 0f;
                float     num3      = 0f;
                float     num4      = 0f;
                bool      flag2     = false;
                WorldGrid worldGrid = Find.WorldGrid;
                bool      flag3;
                do
                {
                    flag3 = false;
                    int   num5            = ticksAbs + (int)(num3 * 60000f);
                    int   num6            = (path == null) ? tile : CaravanArrivalTimeEstimator.TileIllBeInAt(num5, DaysWorthOfFoodCalculator.tmpTicksToArrive, ticksAbs);
                    bool  flag4           = CaravanRestUtility.WouldBeRestingAt(num6, (long)num5);
                    float progressPerTick = ForagedFoodPerDayCalculator.GetProgressPerTick(assumeCaravanMoving && !flag4, flag4, null);
                    float num7            = 1f / progressPerTick;
                    bool  flag5           = VirtualPlantsUtility.EnvironmentAllowsEatingVirtualPlantsAt(num6, num5);
                    float num8            = num3 - num2;
                    if (num8 > 0f)
                    {
                        num4 += num8 * 60000f;
                        if (num4 >= num7)
                        {
                            BiomeDef biome       = worldGrid[num6].biome;
                            int      num9        = Mathf.RoundToInt(ForagedFoodPerDayCalculator.GetForagedFoodCountPerInterval(pawns, biome, faction, null));
                            ThingDef foragedFood = biome.foragedFood;
                            while (num4 >= num7)
                            {
                                num4 -= num7;
                                if (num9 > 0)
                                {
                                    bool flag6 = false;
                                    for (int num10 = DaysWorthOfFoodCalculator.tmpFood.Count - 1; num10 >= 0; num10--)
                                    {
                                        ThingDefCount thingDefCount2 = DaysWorthOfFoodCalculator.tmpFood[num10];
                                        if (thingDefCount2.ThingDef == foragedFood)
                                        {
                                            DaysWorthOfFoodCalculator.tmpFood[num10] = thingDefCount2.WithCount(thingDefCount2.Count + num9);
                                            flag6 = true;
                                            break;
                                        }
                                    }
                                    if (!flag6)
                                    {
                                        DaysWorthOfFoodCalculator.tmpFood.Add(new ThingDefCount(foragedFood, num9));
                                    }
                                }
                            }
                        }
                    }
                    num2 = num3;
                    int num11  = 0;
                    int count8 = pawns.Count;
                    while (num11 < count8)
                    {
                        Pawn pawn3 = pawns[num11];
                        if (pawn3.RaceProps.EatsFood)
                        {
                            if (flag5 && VirtualPlantsUtility.CanEverEatVirtualPlants(pawn3))
                            {
                                if (DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodForPawn[num11] < num3)
                                {
                                    DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodForPawn[num11] = num3;
                                }
                                else
                                {
                                    List <float> list;
                                    int          index;
                                    (list = DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodForPawn)[index = num11] = list[index] + 0.45f;
                                }
                                flag3 = true;
                            }
                            else
                            {
                                float num12 = DaysWorthOfFoodCalculator.cachedNutritionBetweenHungryAndFed[num11];
                                int   num13 = DaysWorthOfFoodCalculator.cachedTicksUntilHungryWhenFed[num11];
                                do
                                {
                                    int num14 = DaysWorthOfFoodCalculator.BestEverEdibleFoodIndexFor(pawn3, DaysWorthOfFoodCalculator.tmpFood);
                                    if (num14 < 0)
                                    {
                                        goto Block_27;
                                    }
                                    ThingDefCount thingDefCount3 = DaysWorthOfFoodCalculator.tmpFood[num14];
                                    float         num15          = Mathf.Min(thingDefCount3.ThingDef.ingestible.CachedNutrition, num12);
                                    float         num16          = num15 / num12 * (float)num13 / 60000f;
                                    int           num17          = Mathf.Min(Mathf.CeilToInt(Mathf.Min(0.2f, DaysWorthOfFoodCalculator.cachedMaxFoodLevel[num11]) / num15), thingDefCount3.Count);
                                    List <float>  list;
                                    int           index2;
                                    (list = DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodForPawn)[index2 = num11] = list[index2] + num16 * (float)num17;
                                    DaysWorthOfFoodCalculator.tmpFood[num14] = thingDefCount3.WithCount(thingDefCount3.Count - num17);
                                    flag3 = true;
                                }while (DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodForPawn[num11] < num3);
                                goto IL_633;
Block_27:
                                if (DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodForPawn[num11] < num3)
                                {
                                    flag2 = true;
                                }
                            }
IL_633:
                            if (flag2)
                            {
                                break;
                            }
                            num3 = Mathf.Max(num3, DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodForPawn[num11]);
                        }
                        num11++;
                    }
                }while (flag3 && !flag2 && num3 <= 601f);
                float num18  = 600f;
                int   num19  = 0;
                int   count9 = pawns.Count;
                while (num19 < count9)
                {
                    if (pawns[num19].RaceProps.EatsFood)
                    {
                        num18 = Mathf.Min(num18, DaysWorthOfFoodCalculator.tmpDaysWorthOfFoodForPawn[num19]);
                    }
                    num19++;
                }
                result = num18;
            }
            return(result);
        }