当前位置: 首页>>代码示例>>C#>>正文


C# IntVec3.GetPlant方法代码示例

本文整理汇总了C#中IntVec3.GetPlant方法的典型用法代码示例。如果您正苦于以下问题:C# IntVec3.GetPlant方法的具体用法?C# IntVec3.GetPlant怎么用?C# IntVec3.GetPlant使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IntVec3的用法示例。


在下文中一共展示了IntVec3.GetPlant方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsCellOpenForSowingPlantOfType

        public static bool IsCellOpenForSowingPlantOfType(IntVec3 cell, ThingDef plantDef)
        {
            IPlantToGrowSettable plantToGrowSettable = GetPlayerSetPlantForCell(cell);
            if (plantToGrowSettable == null || !plantToGrowSettable.CanAcceptSowNow())
                return false;

            ThingDef plantDefToGrow = plantToGrowSettable.GetPlantDefToGrow();
            if (plantDefToGrow == null || plantDefToGrow != plantDef)
                return false;

            // check if there's already a plant occupying the cell
            if (cell.GetPlant() != null)
                return false;

            // check if there are nearby cells which block growth
            if (GenPlant.AdjacentSowBlocker(plantDefToGrow, cell) != null)
                return false;

            // check through all the things in the cell which might block growth
            foreach (Thing tempThing in Find.ThingGrid.ThingsListAt(cell))
                if (tempThing.def.BlockPlanting)
                    return false;

            if (!plantDefToGrow.CanEverPlantAt(cell) || !GenPlant.GrowthSeasonNow(cell))
                return false;

            return true;
        }
开发者ID:skyarkhangel,项目名称:Enviro-AI,代码行数:28,代码来源:Utils_Plants.cs

示例2: JobOnCell

        public override Job JobOnCell(Pawn pawn, IntVec3 cell)
        {
            if (WorkGiver_Grower.wantedPlantDef == null)
            {
                base.DetermineWantedPlantDef(cell);
                if (WorkGiver_Grower.wantedPlantDef == null)
                {
                    return null;
                }
            }

            Plant plant = cell.GetPlant() as Plant;
            if (plant == null)
            {
                return null;
            }
            if (plant.def != WorkGiver_Grower.wantedPlantDef)
            {
                return null;
            }
            if (!plant.def.plant.Harvestable || plant.LifeStage != PlantLifeStage.Growing ||
                !plant.NeedsWatering)
            {
                return null;
            }

            if (!pawn.CanReserve(plant, 1))
            {
                return null;
            }

            // Got a plant we want to water. Do we have a watering tool?
            Thing tool = WaterUtility.HaulingToolInInventory(pawn);
            if (tool == null)
            {
                tool = WaterUtility.NearestHaulingTool(pawn);
                if (tool == null)
                {
                    ConceptDecider.TeachOpportunity(DefDatabase<ConceptDef>.GetNamedSilentFail("Dehydration_HaulWaterTool"),
                                                    OpportunityType.Important);
                    JobFailReason.Is("nothing to haul with");
                    return null;
                }
            }

            var toolWc = tool.TryGetComp<CompWaterContainer>();

            // If we already have enough water in the tool, can just haul it now.
            // TODO: use water-per-plant from JobDriver
            if (toolWc.StoredLitres >= JobDriver_WaterPlant.waterPerPlant)
            {
                return MakeWaterPlantJob(TargetInfo.NullThing, plant, tool);
            }
            // Otherwise we need to find more.
            else
            {
                float collectLitres = toolWc.FreeSpaceLitres;
                IntVec3 waterNear = pawn.Position;

                // Wells, water carriers on the ground, etc.
                Predicate<Thing> validator = (Thing candidate) =>
                {
                    var candidateWc = candidate.TryGetComp<CompWaterContainer>();
                    if (candidateWc == null) { return false; }

                    // Don't haul if the source has too little water.
                    return candidateWc.StoredLitres >= JobDriver_WaterPlant.waterPerPlant;
                };
                var thingWater = WaterUtility.BestWaterSpawnedFor(pawn, collectLitres, validator, waterNear);

                // Rivers, lakes, other terrain-based water sources.
                var terrainWaterVec = WaterUtility.BestTerrainWaterFor(pawn, waterNear);

                // Pick the nearest of the water sources.
                if (thingWater != null && terrainWaterVec != null)
                {
                    float thingDist = (pawn.Position - thingWater.Position).LengthHorizontalSquared;
                    float terrainDist = (pawn.Position - terrainWaterVec.Value).LengthHorizontalSquared;
                    if (thingDist <= terrainDist)
                    {
                        terrainWaterVec = null;
                    }
                    else
                    {
                        thingWater = null;
                    }
                }

                if (thingWater != null)
                {
                    return MakeWaterPlantJob(thingWater, plant, tool);
                }
                else if (terrainWaterVec != null)
                {
                    return MakeWaterPlantJob(terrainWaterVec.Value, plant, tool);
                }
                else
                {
                    JobFailReason.Is("no water nearby");
                    return null;
//.........这里部分代码省略.........
开发者ID:achan1989,项目名称:Dehydration,代码行数:101,代码来源:WorkGiver_GrowerWater.cs


注:本文中的IntVec3.GetPlant方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。