示例#1
0
        public static int CostToMove(List <Pawn> pawns, int start, int end, float yearPercent)
        {
            //This part makes sure the static tile costs are also decreased by mount usage
            int tileCost = WorldPathGrid.CalculatedCostAt(end, false, yearPercent);

            tileCost = Mathf.RoundToInt((float)tileCost);

            int adjustedTicksPerMove = CaravanTicksPerMoveUtility.GetTicksPerMove(pawns);
            int result = adjustedTicksPerMove + Utilities.CaravanUtility.applySpeedBonus(tileCost, pawns);

            result = Mathf.RoundToInt((float)result * Find.WorldGrid.GetRoadMovementMultiplierFast(start, end));

            return(result);
        }
示例#2
0
        private void SelectApproximateBestFoodAndMedicine()
        {
            IEnumerable <TransferableOneWay> enumerable  = transferables.Where((TransferableOneWay x) => x.ThingDef.category != ThingCategory.Pawn && !x.ThingDef.thingCategories.NullOrEmpty() && x.ThingDef.thingCategories.Contains(ThingCategoryDefOf.Medicine));
            IEnumerable <TransferableOneWay> enumerable2 = transferables.Where((TransferableOneWay x) => x.ThingDef.IsIngestible && !x.ThingDef.IsDrug && !x.ThingDef.IsCorpse);

            tmpBeds.Clear();
            for (int i = 0; i < transferables.Count; i++)
            {
                for (int j = 0; j < transferables[i].things.Count; j++)
                {
                    Thing thing = transferables[i].things[j];
                    for (int k = 0; k < thing.stackCount; k++)
                    {
                        Building_Bed building_Bed;
                        if ((building_Bed = thing.GetInnerIfMinified() as Building_Bed) != null && building_Bed.def.building.bed_caravansCanUse)
                        {
                            for (int l = 0; l < building_Bed.SleepingSlotsCount; l++)
                            {
                                tmpBeds.Add(transferables[i]);
                            }
                        }
                    }
                }
            }
            tmpBeds.SortByDescending((TransferableOneWay x) => x.AnyThing.GetStatValue(StatDefOf.BedRestEffectiveness));
            foreach (TransferableOneWay item in enumerable)
            {
                item.AdjustTo(0);
            }
            foreach (TransferableOneWay item2 in enumerable2)
            {
                item2.AdjustTo(0);
            }
            foreach (TransferableOneWay tmpBed in tmpBeds)
            {
                tmpBed.AdjustTo(0);
            }
            List <Pawn> pawnsFromTransferables = TransferableUtility.GetPawnsFromTransferables(transferables);

            if (!pawnsFromTransferables.Any())
            {
                return;
            }
            foreach (Pawn item3 in pawnsFromTransferables)
            {
                TransferableOneWay transferableOneWay = BestBedFor(item3);
                if (transferableOneWay != null)
                {
                    tmpBeds.Remove(transferableOneWay);
                    if (transferableOneWay.CanAdjustBy(1).Accepted)
                    {
                        AddOneIfMassAllows(transferableOneWay);
                    }
                }
                if (item3.AnimalOrWildMan() || item3.guest.IsPrisoner)
                {
                    continue;
                }
                for (int m = 0; m < 2; m++)
                {
                    Transferable transferable = BestMedicineItemFor(item3, enumerable);
                    if (transferable != null)
                    {
                        AddOneIfMassAllows(transferable);
                    }
                }
            }
            if (destinationTile == -1 || !DaysWorthOfFoodCalculator.AnyFoodEatingPawn(pawnsFromTransferables) || !enumerable2.Any())
            {
                return;
            }
            try
            {
                using WorldPath path = Find.WorldPathFinder.FindPath(CurrentTile, destinationTile, null);
                int ticksPerMove = CaravanTicksPerMoveUtility.GetTicksPerMove(new CaravanTicksPerMoveUtility.CaravanInfo(this));
                CaravanArrivalTimeEstimator.EstimatedTicksToArriveToEvery(CurrentTile, destinationTile, path, 0f, ticksPerMove, Find.TickManager.TicksAbs, tmpTicksToArrive);
                float num = (float)tmpTicksToArrive.Last().Second / 60000f + 4f;
                float num2;
                bool  flag;
                do
                {
                    num2 = DaysWorthOfFoodCalculator.ApproxDaysWorthOfFood(transferables, CurrentTile, IgnoreInventoryMode, Faction.OfPlayer, path, 0f, ticksPerMove);
                    if (num2 >= num)
                    {
                        break;
                    }
                    flag = false;
                    foreach (Pawn item4 in pawnsFromTransferables)
                    {
                        Transferable transferable2 = BestFoodItemFor(item4, enumerable2, tmpTicksToArrive);
                        if (transferable2 != null && AddOneIfMassAllows(transferable2))
                        {
                            flag = true;
                        }
                    }
                }while (flag && num2 < num && MassUsage < MassCapacity);
            }
            finally
            {
                tmpTicksToArrive.Clear();
                daysWorthOfFoodDirty = true;
                massUsageDirty       = true;
            }
        }