Exemplo n.º 1
0
 protected override Job TryGiveJob(Pawn pawn)
 {
     if (HiveUtility.JobGivenRecentTick(pawn, "AttackMelee"))
     {
         return null;
     }
     if (BetterInfestationsMod.settings == null)
     {
         return null;
     }
     if (!BetterInfestationsMod.settings.allowHuntingJob)
     {
         return null;
     }
     if (pawn.GetRoom() != null && pawn.GetRoom().Fogged)
     {
         return null;
     }
     Queen queen = HiveUtility.FindQueen(pawn);
     if (queen == null)
     {
         return null;
     }
     Insect insect = pawn as Insect;
     if (insect == null && queen != null && queen.spawnedInsects != null && queen.spawnedInsects.Count > 1)
     {
         return null;
     }
     int foodAmount = HiveUtility.HiveFoodCount(queen);
     if (foodAmount >= BetterInfestationsMod.settings.foodStorage && insect != null && !insect.stealFood)
     {
         return null;
     }
     Region region = pawn.GetRegion(RegionType.Set_Passable);
     if (region == null)
     {
         return null;
     }
     Thing target = FindTarget(pawn);
     if (target != null)
     {
         Thing gatherTarget = JobGiver_InsectGather.FindTarget(pawn, false);
         if (gatherTarget != null)
         {
             if (JobGiver_InsectGather.FindCloserTarget(pawn, target, gatherTarget))
             {
                 return JobGiver_InsectGather.ForceJob(pawn, gatherTarget);
             }
         }
         if (JobGiver_InsectHarvest.CanHarvest(pawn) && BetterInfestationsMod.settings.allowHarvestJob)
         {
             Thing harvestTarget = JobGiver_InsectHarvest.FindTarget(pawn);
             if (harvestTarget != null)
             {
                 if (JobGiver_InsectGather.FindCloserTarget(pawn, target, harvestTarget))
                 {
                     return JobGiver_InsectHarvest.ForceJob(pawn, harvestTarget);
                 }
             }
         }
         if (Rand.Range(1, 25) == 1 && BetterInfestationsMod.settings.allowSapperJob)
         {
             Thing sapperTarget = JobGiver_InsectSapper.FindTarget(pawn);
             if (sapperTarget != null && sapperTarget != queen as Thing)
             {
                 if (JobGiver_InsectGather.FindCloserTarget(pawn, target, sapperTarget))
                 {
                     return JobGiver_InsectSapper.ForceJob(pawn, sapperTarget);
                 }
             }
         }
     }
     if (target == null)
     {
         return null;
     }
     return MeleeAttackJob(pawn, target);
 }
Exemplo n.º 2
0
        public override void Tick()
        {
            if (Spawned)
            {
                sustainer.Maintain();
                Vector3 vector = Position.ToVector3Shifted();
                IntVec3 c;
                if (Rand.MTBEventOccurs(FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(Position, Map, FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), null, null, out c, 999999))
                {
                    FilthMaker.MakeFilth(c, Map, filthTypes.RandomElement(), 1);
                }
                if (Rand.MTBEventOccurs(DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
                {
                    MoteMaker.ThrowDustPuffThick(new Vector3(vector.x, 0f, vector.z)
                    {
                        y = AltitudeLayer.MoteOverhead.AltitudeFor()
                    }, Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
                }
                if (secondarySpawnTick <= Find.TickManager.TicksGame)
                {
                    sustainer.End();
                    Map     map      = Map;
                    IntVec3 position = Position;
                    Destroy(DestroyMode.Vanish);

                    PawnKindDef kindDef = HiveUtility.GetFactionKindDef(PawnKindDef.Named("BI_Queen_Brown"), queenFaction);
                    Queen       queen   = PawnGenerator.GeneratePawn(kindDef, queenFaction) as Queen;
                    queen.hiveLocation = position;
                    if (hiveLocation != null)
                    {
                        queen.hiveLocation = hiveLocation;
                    }
                    GenSpawn.Spawn(queen, CellFinder.RandomClosewalkCellNear(position, map, 4, null), map);
                    if (insectsPoints > 0f)
                    {
                        List <PawnKindDef> spawnablePawnKinds = HiveUtility.GetFactionKindDefs(queenFaction);
                        insectsPoints = Mathf.Max(insectsPoints, spawnablePawnKinds.Min((PawnKindDef x) => x.combatPower));
                        float       pointsLeft = insectsPoints;
                        List <Pawn> list       = new List <Pawn>();
                        int         num        = 0;
                        while (pointsLeft > 0f)
                        {
                            num++;
                            if (num > 1000)
                            {
                                Log.Error("Too many iterations.", false);
                                break;
                            }
                            IEnumerable <PawnKindDef> source = from x in spawnablePawnKinds
                                                               where x.combatPower <= pointsLeft
                                                               select x;
                            PawnKindDef pawnKindDef;
                            if (!source.TryRandomElement(out pawnKindDef))
                            {
                                break;
                            }
                            PawnGenerationRequest request = new PawnGenerationRequest(pawnKindDef, queenFaction, PawnGenerationContext.NonPlayer, -1, true, true, false, false, false, false, 1f, false, false, true, false, false, false, false, null, null, null, null, null, null, null, null);
                            Pawn pawn = PawnGenerator.GeneratePawn(request);
                            GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2, null), map, WipeMode.Vanish);
                            queen.spawnedInsects.Add(pawn);
                            Lord lord = queen.Lord;
                            if (lord == null)
                            {
                                lord = queen.CreateNewLord();
                            }
                            lord.AddPawn(pawn);
                            list.Add(pawn);
                            pointsLeft -= pawnKindDef.combatPower;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (HiveUtility.JobGivenRecentTick(pawn, "Mine"))
            {
                return(null);
            }
            if (BetterInfestationsMod.settings == null)
            {
                return(null);
            }
            if (!BetterInfestationsMod.settings.allowSapperJob)
            {
                return(null);
            }
            if (pawn.GetRoom() != null && pawn.GetRoom().Fogged)
            {
                return(null);
            }
            Queen queen = HiveUtility.FindQueen(pawn);

            if (queen == null)
            {
                return(null);
            }
            Insect insect = pawn as Insect;

            if (insect == null && queen != null && queen.spawnedInsects != null && queen.spawnedInsects.Count > 1)
            {
                return(null);
            }
            int foodAmount = HiveUtility.HiveFoodCount(queen);

            if (foodAmount >= BetterInfestationsMod.settings.foodStorage && insect != null && !insect.stealFood)
            {
                return(null);
            }
            Region region = pawn.GetRegion(RegionType.Set_Passable);

            if (region == null)
            {
                return(null);
            }
            Thing target = FindTarget(pawn);

            if (target != null && target != queen as Thing)
            {
                Thing gatherTarget = JobGiver_InsectGather.FindTarget(pawn, false);
                if (gatherTarget != null)
                {
                    if (JobGiver_InsectGather.FindCloserTarget(pawn, target, gatherTarget))
                    {
                        return(JobGiver_InsectGather.ForceJob(pawn, gatherTarget));
                    }
                }
                if (JobGiver_InsectHunt.CanHunt(pawn) && BetterInfestationsMod.settings.allowHuntingJob)
                {
                    Thing huntTarget = JobGiver_InsectHunt.FindTarget(pawn);
                    if (huntTarget != null)
                    {
                        if (JobGiver_InsectGather.FindCloserTarget(pawn, target, huntTarget))
                        {
                            return(JobGiver_InsectHunt.ForceJob(pawn, huntTarget));
                        }
                    }
                }
                if (JobGiver_InsectHarvest.CanHarvest(pawn) && BetterInfestationsMod.settings.allowHarvestJob)
                {
                    Thing harvestTarget = JobGiver_InsectHarvest.FindTarget(pawn);
                    if (harvestTarget != null)
                    {
                        if (JobGiver_InsectGather.FindCloserTarget(pawn, target, harvestTarget))
                        {
                            return(JobGiver_InsectHarvest.ForceJob(pawn, harvestTarget));
                        }
                    }
                }
            }
            if (target == null)
            {
                return(null);
            }
            if (!pawn.CanReach(target, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.PassAllDestroyableThings))
            {
                return(null);
            }
            using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, target, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell))
            {
                List <IntVec3> cells = pawnPath.NodesReversed;
                if (cells != null && cells.Any())
                {
                    foreach (IntVec3 cell in cells)
                    {
                        Building b = cell.GetEdifice(pawn.Map);
                        if (b != null && b.def != null)
                        {
                            if (b.def.passability != Traversability.Impassable)
                            {
                                return(null);
                            }
                            if (b.def.size != IntVec2.One)
                            {
                                return(null);
                            }
                            if (b.Faction == null || (b.Faction != null && !b.Faction.IsPlayer))
                            {
                                return(null);
                            }
                        }
                    }
                }
                IntVec3 cellBeforeBlocker;
                Thing   thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                if (thing != null && pawn.CanReserve(thing) && pawn.CanReach(thing, PathEndMode.Touch, Danger.Deadly, true, TraverseMode.PassDoors))
                {
                    return(new Job(JobDefOf.Mine, thing)
                    {
                        ignoreDesignations = true,
                        expiryInterval = 6000
                    });
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        private void TrySpawnHive(Map map)
        {
            IntVec3 intVec;

            if (!TryFindQueenSpawnCell(map, out intVec))
            {
                return;
            }
            possibleSpawnCells.Remove(intVec);

            Faction     faction = HiveUtility.GetRandomInsectFaction();
            PawnKindDef kindDef = HiveUtility.GetFactionKindDef(PawnKindDef.Named("BI_Queen_Brown"), faction);
            Queen       queen   = PawnGenerator.GeneratePawn(kindDef, faction) as Queen;

            queen.hiveLocation = intVec;
            GenSpawn.Spawn(queen, CellFinder.RandomClosewalkCellNear(intVec, map, 4, null), map);
            spawnedQueens.Add(queen);
            Lord lord = queen.Lord;

            if (lord == null)
            {
                lord = queen.CreateNewLord();
            }
            int count = Rand.Range(4, 5);

            for (int i = 0; i < count; i++)
            {
                kindDef = HiveUtility.GetFactionKindDef(PawnKindDef.Named("BI_Megascarab_Brown"), faction);
                Pawn pawn = PawnGenerator.GeneratePawn(kindDef, faction);
                GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(intVec, map, 4, null), map);
                queen.spawnedInsects.Add(pawn);
                lord.AddPawn(pawn);
            }
            IntVec3 c;
            int     foodAmt = 0;

            for (int i = 0; i < Rand.Range(4, 7); i++)
            {
                if (CellFinder.TryFindRandomReachableCellNear(intVec, map, 8, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 x) => x.Walkable(map), (Region x) => true, out c, 999999))
                {
                    Egg egg = ThingMaker.MakeThing(HiveUtility.ThingDefOfEgg, null) as Egg;
                    egg.SetFaction(queen.Faction, null);
                    egg.eggLayer = queen;
                    GenPlace.TryPlaceThing(egg, c, map, ThingPlaceMode.Direct, out Thing t, null, null);
                    queen.spawnedEggs.Add(egg);
                    CompInsectSpawner comp = egg.TryGetComp <CompInsectSpawner>();
                    if (comp != null)
                    {
                        comp.jellyStores = Rand.Range(50, comp.jellyMax);
                    }
                    if (Rand.Range(1, 4) < 4)
                    {
                        CompSpawner comp2 = egg.TryGetComp <CompSpawner>();
                        if (comp2 != null)
                        {
                            comp2.TryDoSpawn();
                        }
                    }
                    if (foodAmt < (BetterInfestationsMod.settings.foodStorage + 100))
                    {
                        IntVec3 c2;
                        if (CellFinder.TryFindRandomReachableCellNear(intVec, map, 2, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 x) => x.Walkable(map), (Region x) => true, out c2, 999999))
                        {
                            Thing thing2 = ThingMaker.MakeThing(ThingDefOf.InsectJelly, null);
                            thing2.stackCount = Rand.Range(15, 75);
                            GenPlace.TryPlaceThing(thing2, c2, map, ThingPlaceMode.Direct, out Thing food, null);
                            if (food != null)
                            {
                                food.SetForbidden(true);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (HiveUtility.JobGivenRecentTick(pawn, "BI_HaulToCell"))
            {
                return(null);
            }
            if (BetterInfestationsMod.settings == null)
            {
                return(null);
            }
            if (pawn.GetRoom() != null && pawn.GetRoom().Fogged)
            {
                return(null);
            }
            Queen queen = HiveUtility.FindQueen(pawn);

            if (queen == null)
            {
                return(null);
            }
            Insect insect = pawn as Insect;

            if (insect == null && queen != null && queen.spawnedInsects != null && queen.spawnedInsects.Count > 1)
            {
                return(null);
            }
            int foodAmount = HiveUtility.HiveFoodCount(queen);

            if (foodAmount >= BetterInfestationsMod.settings.foodStorage && insect != null && !insect.stealFood)
            {
                return(null);
            }
            Region region = pawn.GetRegion(RegionType.Set_Passable);

            if (region == null)
            {
                return(null);
            }
            Thing target = FindTarget(pawn, false);

            if (target != null)
            {
                if (JobGiver_InsectHunt.CanHunt(pawn) && BetterInfestationsMod.settings.allowHuntingJob)
                {
                    Thing huntTarget = JobGiver_InsectHunt.FindTarget(pawn);
                    if (huntTarget != null)
                    {
                        if (FindCloserTarget(pawn, target, huntTarget))
                        {
                            return(JobGiver_InsectHunt.ForceJob(pawn, huntTarget));
                        }
                    }
                }
                if (JobGiver_InsectHarvest.CanHarvest(pawn) && BetterInfestationsMod.settings.allowHarvestJob)
                {
                    Thing harvestTarget = JobGiver_InsectHarvest.FindTarget(pawn);
                    if (harvestTarget != null)
                    {
                        if (FindCloserTarget(pawn, target, harvestTarget))
                        {
                            return(JobGiver_InsectHarvest.ForceJob(pawn, harvestTarget));
                        }
                    }
                }
                if (Rand.Range(1, 25) == 1 && BetterInfestationsMod.settings.allowSapperJob)
                {
                    Thing sapperTarget = JobGiver_InsectSapper.FindTarget(pawn);
                    if (sapperTarget != null && sapperTarget != queen as Thing)
                    {
                        if (FindCloserTarget(pawn, target, sapperTarget))
                        {
                            return(JobGiver_InsectSapper.ForceJob(pawn, sapperTarget));
                        }
                    }
                }
            }
            if (target == null)
            {
                return(null);
            }
            IntVec3 cell = FindCell(pawn);

            if (cell == IntVec3.Invalid)
            {
                return(null);
            }
            return(new Job(DefDatabase <JobDef> .GetNamed("BI_HaulToCell"), target, cell)
            {
                canBash = true,
                haulOpportunisticDuplicates = false,
                haulMode = HaulMode.ToCellNonStorage,
                expiryInterval = 480,
                ignoreForbidden = true,
                count = 99999
            });
        }