private bool DrawGrazeability(Rect rect, TransferableOneWay trad)
        {
            if (!trad.HasAnyThing)
            {
                return(false);
            }
            Pawn pawn = trad.AnyThing as Pawn;

            if (pawn == null || !VirtualPlantsUtility.CanEverEatVirtualPlants(pawn))
            {
                return(false);
            }
            rect.width = 40f;
            Rect position = new Rect(rect.x + (float)(int)((rect.width - 28f) / 2f), rect.y + (float)(int)((rect.height - 28f) / 2f), 28f, 28f);

            Widgets.DrawHighlightIfMouseover(rect);
            GUI.DrawTexture(position, CanGrazeIcon);
            if (Mouse.IsOver(rect))
            {
                TooltipHandler.TipRegion(rect, delegate
                {
                    TaggedString taggedString = "AnimalCanGrazeTip".Translate();
                    if (tile != -1)
                    {
                        taggedString += "\n\n" + VirtualPlantsUtility.GetVirtualPlantsStatusExplanationAt(tile, Find.TickManager.TicksAbs);
                    }
                    return(taggedString);
                }, trad.GetHashCode() ^ 0x7424D7F2);
            }
            return(true);
        }
        private bool DrawGrazeability(Rect rect, TransferableOneWay trad)
        {
            bool result;

            if (!trad.HasAnyThing)
            {
                result = false;
            }
            else
            {
                Pawn pawn = trad.AnyThing as Pawn;
                if (pawn == null || !VirtualPlantsUtility.CanEverEatVirtualPlants(pawn))
                {
                    result = false;
                }
                else
                {
                    rect.width = 40f;
                    Rect position = new Rect(rect.x + (float)((int)((rect.width - 28f) / 2f)), rect.y + (float)((int)((rect.height - 28f) / 2f)), 28f, 28f);
                    Widgets.DrawHighlightIfMouseover(rect);
                    GUI.DrawTexture(position, TransferableOneWayWidget.CanGrazeIcon);
                    TooltipHandler.TipRegion(rect, delegate()
                    {
                        string text = "AnimalCanGrazeTip".Translate();
                        if (this.tile != -1)
                        {
                            text = text + "\n\n" + VirtualPlantsUtility.GetVirtualPlantsStatusExplanationAt(this.tile, Find.TickManager.TicksAbs);
                        }
                        return(text);
                    }, trad.GetHashCode() ^ 1948571634);
                    result = true;
                }
            }
            return(result);
        }
Beispiel #3
0
 protected override bool CanFireNowSub(IncidentParms parms)
 {
     return(base.CanFireNowSub(parms) && TryGetRandomAvailableTargetMap(out var map) &&
            RandomNearbyGrowerSettlement(map.Tile) != null &&
            VirtualPlantsUtility.EnvironmentAllowsEatingVirtualPlantsNowAt(
                RandomNearbyGrowerSettlement(map.Tile).Tile));
 }
Beispiel #4
0
        // RimWorld.Planet.CaravanPawnsNeedsUtility
        public static void TrySatisfyFoodNeed(Pawn pawn, Need_Food food, Pawn vehicle)
        {
            if (food.CurCategory < HungerCategory.Hungry)
            {
                return;
            }
            Thing thing;
            Pawn  pawn2;

            if (VirtualPlantsUtility.CanEatVirtualPlantsNow(pawn))
            {
                VirtualPlantsUtility.EatVirtualPlants(pawn);
            }
            else if (CompVehicleUtility.TryGetBestFood(vehicle, pawn, out thing, out pawn2))
            {
                food.CurLevel += thing.Ingested(pawn, food.NutritionWanted);
                if (thing.Destroyed)
                {
                    if (pawn2 != null)
                    {
                        vehicle.inventory.innerContainer.Remove(thing);
                        //caravan.RecacheImmobilizedNow();
                        //caravan.RecacheDaysWorthOfFood();
                    }
                    //if (!CompVehicleUtility.TryGetBestFood(vehicle, pawn, out thing, out pawn2))
                    //{
                    //    Messages.Message("MessageCaravanRunOutOfFood".Translate(new object[]
                    //    {
                    //caravan.LabelCap,
                    //pawn.Label
                    //    }), caravan, MessageSound.SeriousAlert);
                    //}
                }
            }
        }
Beispiel #5
0
        private string <DrawGrazeability> m__4()
        {
            string text = "AnimalCanGrazeTip".Translate();

            if (this.tile != -1)
            {
                text = text + "\n\n" + VirtualPlantsUtility.GetVirtualPlantsStatusExplanationAt(this.tile, Find.TickManager.TicksAbs);
            }
            return(text);
        }
        public bool AnyPawnOutOfFood(out string malnutritionHediff)
        {
            tmpInvFood.Clear();
            List <Thing> list = CaravanInventoryUtility.AllInventoryItems(caravan);

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].def.IsNutritionGivingIngestible)
                {
                    tmpInvFood.Add(list[i]);
                }
            }
            List <Pawn> pawnsListForReading = caravan.PawnsListForReading;

            for (int j = 0; j < pawnsListForReading.Count; j++)
            {
                Pawn pawn = pawnsListForReading[j];
                if (!pawn.RaceProps.EatsFood || VirtualPlantsUtility.CanEatVirtualPlantsNow(pawn))
                {
                    continue;
                }
                bool flag = false;
                for (int k = 0; k < tmpInvFood.Count; k++)
                {
                    if (CaravanPawnsNeedsUtility.CanEatForNutritionEver(tmpInvFood[k].def, pawn))
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    continue;
                }
                int    num  = -1;
                string text = null;
                for (int l = 0; l < pawnsListForReading.Count; l++)
                {
                    Hediff firstHediffOfDef = pawnsListForReading[l].health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition);
                    if (firstHediffOfDef != null && (text == null || firstHediffOfDef.CurStageIndex > num))
                    {
                        num  = firstHediffOfDef.CurStageIndex;
                        text = firstHediffOfDef.LabelCap;
                    }
                }
                malnutritionHediff = text;
                tmpInvFood.Clear();
                return(true);
            }
            malnutritionHediff = null;
            tmpInvFood.Clear();
            return(false);
        }
Beispiel #7
0
        public override void Filter(List <int> inputList)
        {
            base.Filter(inputList);

            if (!IsFilterActive)
            {
                return;
            }

            // partial state means "I don't care if they can graze now or not", so all tiles match
            if (UserData.ChosenAnimalsCanGrazeNowState == MultiCheckboxState.Partial)
            {
                _filteredTiles.AddRange(inputList);
                return;
            }

            try
            {
                GameTicks.PushTickAbs();
                foreach (var tileId in inputList)
                {
                    var canGrazeNow = VirtualPlantsUtility.EnvironmentAllowsEatingVirtualPlantsNowAt(tileId);
                    if (UserData.ChosenAnimalsCanGrazeNowState == MultiCheckboxState.On)
                    {
                        if (canGrazeNow)
                        {
                            _filteredTiles.Add(tileId);
                        }
                    }

                    if (UserData.ChosenAnimalsCanGrazeNowState == MultiCheckboxState.Off)
                    {
                        if (!canGrazeNow)
                        {
                            _filteredTiles.Add(tileId);
                        }
                    }
                }
            }
            finally
            {
                GameTicks.PopTickAbs();
            }
        }
        private string GetTileTip(int tile, int pathIndex)
        {
            int num = paths[pathIndex].NodesReversed.IndexOf(tile);
            int num2;

            if (num > 0)
            {
                num2 = paths[pathIndex].NodesReversed[num - 1];
            }
            else if (pathIndex < paths.Count - 1 && paths[pathIndex + 1].NodesReversed.Count >= 2)
            {
                num2 = paths[pathIndex + 1].NodesReversed[paths[pathIndex + 1].NodesReversed.Count - 2];
            }
            else
            {
                num2 = -1;
            }
            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, false, new int?(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 #9
0
        private void DrawSelectedTileInfo()
        {
            DrawEntryHeader("PLMWFTIL_SelectedTileInfo".Translate(), backgroundColor: Color.yellow);

            var matchingTiles = PrepareLanding.Instance.TileFilter.AllMatchingTiles;

            if (_selectedTileIndex < 0 || _selectedTileIndex >= matchingTiles.Count)
            {
                return;
            }

            ListingStandard.verticalSpacing = 0f;

            var selTileId = matchingTiles[_selectedTileIndex];
            var selTile   = Find.World.grid[selTileId];

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

            if (rot.IsValid)
            {
                stringBuilder2.AppendWithComma(("HasCoast" + rot).Translate());
            }
            if (Find.World.HasCaves(selTileId))
            {
                stringBuilder2.AppendWithComma("HasCaves".Translate());
            }
            if (stringBuilder2.Length > 0)
            {
                ListingStandard.LabelDouble("SpecialFeatures".Translate(), stringBuilder2.ToString().CapitalizeFirst());
            }
            if (Prefs.DevMode)
            {
                ListingStandard.LabelDouble("Debug world tile ID", selTileId.ToString());
            }
        }
Beispiel #10
0
        protected void DrawSelectedTileInfo()
        {
            DrawEntryHeader("Selected Tile Info", backgroundColor: Color.yellow);

            var matchingTiles = PrepareLanding.Instance.TileFilter.AllMatchingTiles;

            if (_selectedTileIndex < 0 || _selectedTileIndex >= matchingTiles.Count)
            {
                return;
            }

            ListingStandard.verticalSpacing = 0f;

            var selTileId = matchingTiles[_selectedTileIndex];
            var selTile   = Find.World.grid[selTileId];

            ListingStandard.Label(selTile.biome.LabelCap);
            var y = Find.WorldGrid.LongLatOf(selTileId).y;

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

            ListingStandard.LabelDouble("AvgWinterTemp".Translate(), celsiusTemp.ToStringTemperature());
            var celsiusTemp2 = GenTemperature.AverageTemperatureAtTileForTwelfth(selTileId, Season.Summer.GetMiddleTwelfth(y));

            ListingStandard.LabelDouble("AvgSummerTemp".Translate(), celsiusTemp2.ToStringTemperature());
            ListingStandard.LabelDouble("OutdoorGrowingPeriod".Translate(), Zone_Growing.GrowingQuadrumsDescription(selTileId));
            ListingStandard.LabelDouble("Rainfall".Translate(), selTile.rainfall.ToString("F0") + "mm");
            ListingStandard.LabelDouble("AnimalsCanGrazeNow".Translate(), (!VirtualPlantsUtility.EnvironmentAllowsEatingVirtualPlantsNowAt(selTileId)) ? "No".Translate() : "Yes".Translate());
            ListingStandard.GapLine();
            ListingStandard.LabelDouble("TimeZone".Translate(), GenDate.TimeZoneAt(Find.WorldGrid.LongLatOf(selTileId).x).ToStringWithSign());
            var rot = Find.World.CoastDirectionAt(selTileId);

            if (rot.IsValid)
            {
                ListingStandard.LabelDouble(string.Empty, ("HasCoast" + rot).Translate());
            }
            if (Prefs.DevMode)
            {
                ListingStandard.LabelDouble("Debug world tile ID", selTileId.ToString());
            }
        }