protected override IntVec3 GetFlagPosition(Pawn pawn)
        {
            MotherAmbrosiaLGE hive = pawn.mindState.duty.focus.Thing as MotherAmbrosiaLGE;

            if (hive != null && hive.Spawned)
            {
                return(hive.Position);
            }
            return(pawn.Position);
        }
        protected override IntVec3 GetWanderRoot(Pawn pawn)
        {
            MotherAmbrosiaLGE hive = pawn.mindState.duty.focus.Thing as MotherAmbrosiaLGE;

            if (hive == null || !hive.Spawned)
            {
                return(pawn.Position);
            }
            return(hive.Position);
        }
 public override void UpdateAllDuties()
 {
     this.FilterOutUnspawnedHives();
     for (int i = 0; i < this.lord.ownedPawns.Count; i++)
     {
         MotherAmbrosiaLGE hiveFor = this.GetHiveFor(this.lord.ownedPawns[i]);
         PawnDuty          duty    = new PawnDuty(DefsOfLGE.DefendAmbrosiaSproutLGE, hiveFor, this.distToHiveToAttack);
         this.lord.ownedPawns[i].mindState.duty = duty;
     }
 }
        public override void Resolve(ResolveParams rp)
        {
            Map     map  = BaseGen.globalSettings.map;
            IntVec3 root = IntVec3Utility.ToIntVec3(rp.rect.CenterVector3);
            IntVec3 motherVec;

            CellFinder.TryFindRandomCellNear(root, map, 3, (IntVec3 x) => x.Standable(map) && map.fertilityGrid.FertilityAt(x) > ThingDefOf.Plant_Ambrosia.plant.fertilityMin, out motherVec);
            float eventPoints = StorytellerUtility.DefaultThreatPointsNow(Find.World) * 0.6f;

            if (eventPoints > 4000f)
            {
                eventPoints *= 0.9f;
                if (eventPoints > 7000f)
                {
                    eventPoints = 7000f;
                }
            }
            if (eventPoints < 400f)
            {
                eventPoints = 400f;
            }

            foreach (IntVec3 vec in rp.rect)
            {
                if (map.terrainGrid.TerrainAt(vec).fertility < 0.7f)
                {
                    if (Rand.Chance(0.5f))
                    {
                        map.terrainGrid.SetTerrain(vec, TerrainDefOf.Gravel);
                    }
                }
            }

            //spawn mother plant
            MotherAmbrosiaLGE motherAmbrosia = (MotherAmbrosiaLGE)GenSpawn.Spawn(DefsOfLGE.Plant_MotherAmbrosiaLGE, motherVec, map, WipeMode.Vanish);

            motherAmbrosia.Growth = Rand.Range(0.9f, 0.98f);

            PawnKindDef animalKind;

            (from k in map.Biome.AllWildAnimals
             where Find.World.tileTemperatures.SeasonAndOutdoorTemperatureAcceptableFor(map.Tile, k.race)
             select k).TryRandomElement(out animalKind);
            if (animalKind == null)
            {
                animalKind = ThingDefOfVanilla.Warg;
            }
            motherAmbrosia.SpawnAnimals(animalKind, eventPoints);


            int randomInRange = (int)(eventPoints / 80);//SymbolResolver_AmbrosiaAnimalsLGE.CountRange.RandomInRange;

            for (int i = 0; i < randomInRange; i++)
            {
                IntVec3 intVec;
                if (!CellFinder.TryRandomClosewalkCellNear(motherVec, map, SpawnRadius, out intVec, (IntVec3 x) => this.CanSpawnAt(x, map)))
                {
                    break;
                }
                Plant plant = intVec.GetPlant(map);
                if (plant != null)
                {
                    plant.Destroy(DestroyMode.Vanish);
                }
                Plant ambrosia = (Plant)GenSpawn.Spawn(ThingDefOf.Plant_Ambrosia, intVec, map, WipeMode.Vanish);
                ambrosia.Growth = Rand.Range(0.6f, 0.95f);
            }

            //Spawn ambrosia reward
            ResolveParams resolveParamsReward = rp;

            resolveParamsReward.rect = CellRect.CenteredOn(motherVec, SpawnRadius - 2);
            resolveParamsReward.stockpileConcreteContents = RewardGeneratorUtilityLGE.GenerateAmbrosia((int)(eventPoints / 150f));
            BaseGen.symbolStack.Push("spawnStockpileLGE", resolveParamsReward);
        }