private static int BestEverGetWaterIndexFor(List <ThingDefCount> water)
        {
            var num  = -1;
            var num2 = 0f;

            for (var i = 0; i < water.Count; i++)
            {
                if (water[i].Count <= 0)
                {
                    continue;
                }

                var thingDef = water[i].ThingDef;
                if (!MizuCaravanUtility.CanEverGetWater(thingDef))
                {
                    continue;
                }

                var waterScore = MizuCaravanUtility.GetWaterScore(thingDef);
                if (num >= 0 && !(waterScore > num2))
                {
                    continue;
                }

                num  = i;
                num2 = waterScore;
            }

            return(num);
        }
Пример #2
0
        public static bool TryGetBestWater(Caravan caravan, Pawn forPawn, out Thing water, out Pawn owner)
        {
            List <Thing> inventoryThings = CaravanInventoryUtility.AllInventoryItems(caravan);
            Thing        foundThing      = null;
            float        bestScore       = float.MinValue;

            // キャラバンの全所持品をチェック
            foreach (var thing in inventoryThings)
            {
                // それが飲めるものかどうか
                if (!MizuCaravanUtility.CanNowGetWater(thing, forPawn))
                {
                    continue;
                }

                float waterScore = MizuCaravanUtility.GetWaterScore(thing, forPawn);

                // 今まで見つけたベストスコアを超えたか
                if (bestScore >= waterScore)
                {
                    continue;
                }

                foundThing = thing;
                bestScore  = waterScore;
            }

            if (foundThing != null)
            {
                // 何かしらの水が見つかった
                water = foundThing;
                // 水が個人の所持品に含まれている場合は持ち主が誰かを調べておく
                owner = CaravanInventoryUtility.GetOwnerOf(caravan, foundThing);
                return(true);
            }

            water = null;
            owner = null;
            return(false);
        }
        private static int BestEverGetWaterIndexFor(Pawn pawn, List <ThingCount> water)
        {
            int   num  = -1;
            float num2 = 0f;

            for (int i = 0; i < water.Count; i++)
            {
                if (water[i].Count > 0)
                {
                    ThingDef thingDef = water[i].ThingDef;
                    if (MizuCaravanUtility.CanEverGetWater(thingDef, pawn))
                    {
                        float waterScore = MizuCaravanUtility.GetWaterScore(thingDef, pawn);
                        if (num < 0 || waterScore > num2)
                        {
                            num  = i;
                            num2 = waterScore;
                        }
                    }
                }
            }
            return(num);
        }