private void TickInterval(int interval) { if (!parent.Spawned) { return; } CompCanBeDormant comp = parent.GetComp <CompCanBeDormant>(); if (comp != null) { if (!comp.Awake) { return; } } else if (parent.Position.Fogged(parent.Map)) { return; } if (!PropsSpawner.requiresPower || PowerOn) { ticksUntilSpawn -= interval; CheckShouldSpawn(); } }
public bool ThreatDisabled(IAttackTargetSearcher disabledFor) { CompPowerTrader comp = GetComp <CompPowerTrader>(); if (comp != null && !comp.PowerOn) { return(true); } CompMannable comp2 = GetComp <CompMannable>(); if (comp2 != null && !comp2.MannedNow) { return(true); } CompCanBeDormant comp3 = GetComp <CompCanBeDormant>(); if (comp3 != null && !comp3.Awake) { return(true); } CompInitiatable comp4 = GetComp <CompInitiatable>(); if (comp4 != null && !comp4.Initiated) { return(true); } return(false); }
public static bool IsActiveThreatTo(IAttackTarget target, Faction faction) { if (!target.Thing.HostileTo(faction)) { return(false); } if (!(target.Thing is IAttackTargetSearcher)) { return(false); } if (target.ThreatDisabled(null)) { return(false); } Pawn pawn = target.Thing as Pawn; if (pawn != null) { Lord lord = pawn.GetLord(); if (lord != null && lord.LordJob is LordJob_DefendAndExpandHive && (pawn.mindState.duty == null || pawn.mindState.duty.def != DutyDefOf.AssaultColony)) { return(false); } } Pawn pawn2 = target.Thing as Pawn; if (pawn2 != null && (pawn2.MentalStateDef == MentalStateDefOf.PanicFlee || pawn2.IsPrisoner)) { return(false); } CompCanBeDormant compCanBeDormant = target.Thing.TryGetComp <CompCanBeDormant>(); if (compCanBeDormant != null && !compCanBeDormant.Awake) { return(false); } CompInitiatable compInitiatable = target.Thing.TryGetComp <CompInitiatable>(); if (compInitiatable != null && !compInitiatable.Initiated) { return(false); } if (target.Thing.Spawned) { TraverseParms traverseParms = ((pawn2 != null) ? TraverseParms.For(pawn2) : TraverseParms.For(TraverseMode.PassDoors)); if (!target.Thing.Map.reachability.CanReachUnfogged(target.Thing.Position, traverseParms)) { return(false); } } return(true); }
public override void SpawnSetup(Map map, bool respawningAfterLoad) { base.SpawnSetup(map, respawningAfterLoad); dormantComp = GetComp <CompCanBeDormant>(); initiatableComp = GetComp <CompInitiatable>(); powerComp = GetComp <CompPowerTrader>(); mannableComp = GetComp <CompMannable>(); if (!respawningAfterLoad) { top.SetRotationFromOrientation(); burstCooldownTicksLeft = def.building.turretInitialCooldownTime.SecondsToTicks(); } }
public bool ThreatDisabled(IAttackTargetSearcher disabledFor) { if (!base.Spawned) { return(true); } CompCanBeDormant comp = GetComp <CompCanBeDormant>(); if (comp != null && !comp.Awake) { return(true); } return(false); }
private void SetDormant(Thing thing, bool dormant) { CompCanBeDormant compCanBeDormant = thing.TryGetComp <CompCanBeDormant>(); if (compCanBeDormant != null) { if (dormant) { compCanBeDormant.ToSleep(); } else { compCanBeDormant.WakeUp(); } } }
private bool AffectsStoryDanger(IAttackTarget t) { Pawn pawn = t.Thing as Pawn; if (pawn != null) { Lord lord = pawn.GetLord(); if (lord != null && (lord.LordJob is LordJob_DefendPoint || lord.LordJob is LordJob_MechanoidDefendBase) && pawn.CurJobDef != JobDefOf.AttackMelee && pawn.CurJobDef != JobDefOf.AttackStatic) { return(false); } CompCanBeDormant comp = pawn.GetComp <CompCanBeDormant>(); if (comp != null && !comp.Awake) { return(false); } } return(GenHostility.IsActiveThreatToPlayer(t)); }
public static bool AnyHostileActiveThreatTo(Map map, Faction faction, bool countDormantPawnsAsHostile = false) { foreach (IAttackTarget item in map.attackTargetsCache.TargetsHostileToFaction(faction)) { if (IsActiveThreatTo(item, faction)) { return(true); } Pawn pawn; if (countDormantPawnsAsHostile && item.Thing.HostileTo(faction) && !item.Thing.Fogged() && !item.ThreatDisabled(null) && (pawn = (item.Thing as Pawn)) != null) { CompCanBeDormant comp = pawn.GetComp <CompCanBeDormant>(); if (comp != null && !comp.Awake) { return(true); } } } return(false); }
public override void CompTick() { base.CompTick(); CompCanBeDormant comp = parent.GetComp <CompCanBeDormant>(); if ((comp?.Awake ?? true) && !wasActivated) { CalculateNextHiveSpawnTick(); wasActivated = true; } if ((comp == null || comp.Awake) && Find.TickManager.TicksGame >= nextHiveSpawnTick) { if (TrySpawnChildHive(ignoreRoofedRequirement: false, out Hive newHive)) { Messages.Message("MessageHiveReproduced".Translate(), newHive, MessageTypeDefOf.NegativeEvent); } else { CalculateNextHiveSpawnTick(); } }
public static void SendMechanoidsToSleepImmediately(List <Pawn> spawnedMechanoids) { for (int i = 0; i < spawnedMechanoids.Count; i++) { spawnedMechanoids[i].jobs.EndCurrentJob(JobCondition.InterruptForced); JobDriver curDriver = spawnedMechanoids[i].jobs.curDriver; if (curDriver != null) { curDriver.asleep = true; } CompCanBeDormant comp = spawnedMechanoids[i].GetComp <CompCanBeDormant>(); if (comp != null) { comp.ToSleep(); } else { Log.ErrorOnce(string.Concat("Tried spawning sleeping mechanoid ", spawnedMechanoids[i], " without CompCanBeDormant!"), 0x12EA9A79 ^ spawnedMechanoids[i].def.defName.GetHashCode()); } } }
public static bool ShouldTrashBuilding(Pawn pawn, Building b, bool attackAllInert = false) { if (!b.def.useHitPoints || (b.def.building != null && b.def.building.ai_neverTrashThis)) { return(false); } if (pawn.mindState.spawnedByInfestationThingComp && b.GetComp <CompCreatesInfestations>() != null) { return(false); } if (((b.def.building.isInert || b.def.IsFrame) && !attackAllInert) || b.def.building.isTrap) { int num = GenLocalDate.HourOfDay(pawn) / 3; int specialSeed = (b.GetHashCode() * 612361) ^ (pawn.GetHashCode() * 391) ^ (num * 73427324); if (!Rand.ChanceSeeded(0.008f, specialSeed)) { return(false); } } if (b.def.building.isTrap) { return(false); } CompCanBeDormant comp = b.GetComp <CompCanBeDormant>(); if (comp != null && !comp.Awake) { return(false); } if (b.Faction == Faction.OfMechanoids) { return(false); } if (!CanTrash(pawn, b) || !pawn.HostileTo(b)) { return(false); } return(true); }
public static List <Thing> SpawnCluster(IntVec3 center, Map map, MechClusterSketch sketch, bool dropInPods = true, bool canAssaultColony = false, string questTag = null) { List <Thing> spawnedThings = new List <Thing>(); Sketch.SpawnMode spawnMode = (!dropInPods) ? Sketch.SpawnMode.Normal : Sketch.SpawnMode.TransportPod; sketch.buildingsSketch.Spawn(map, center, Faction.OfMechanoids, Sketch.SpawnPosType.Unchanged, spawnMode, wipeIfCollides : false, clearEdificeWhereFloor : false, spawnedThings, sketch.startDormant, buildRoofsInstantly : false, null, delegate(IntVec3 spot, SketchEntity entity) { SketchThing sketchThing; if ((sketchThing = (entity as SketchThing)) != null && sketchThing.def != ThingDefOf.Wall && sketchThing.def != ThingDefOf.Barricade) { entity.SpawnNear(spot, map, 12f, Faction.OfMechanoids, spawnMode, wipeIfCollides: false, spawnedThings, sketch.startDormant); } }); float defendRadius = Mathf.Sqrt(sketch.buildingsSketch.OccupiedSize.x * sketch.buildingsSketch.OccupiedSize.x + sketch.buildingsSketch.OccupiedSize.z * sketch.buildingsSketch.OccupiedSize.z) / 2f + 6f; LordJob_MechanoidDefendBase lordJob_MechanoidDefendBase = null; lordJob_MechanoidDefendBase = ((!sketch.startDormant) ? ((LordJob_MechanoidDefendBase) new LordJob_MechanoidsDefend(spawnedThings, Faction.OfMechanoids, defendRadius, center, canAssaultColony, isMechCluster: true)) : ((LordJob_MechanoidDefendBase) new LordJob_SleepThenMechanoidsDefend(spawnedThings, Faction.OfMechanoids, defendRadius, center, canAssaultColony, isMechCluster: true))); Lord lord = LordMaker.MakeNewLord(Faction.OfMechanoids, lordJob_MechanoidDefendBase, map); QuestUtility.AddQuestTag(lord, questTag); bool flag = Rand.Chance(0.6f); float randomInRange = InitiationDelay.RandomInRange; int num = (int)(MechAssemblerInitialDelayDays.RandomInRange * 60000f); for (int i = 0; i < spawnedThings.Count; i++) { Thing thing = spawnedThings[i]; thing.TryGetComp <CompSpawnerPawn>()?.CalculateNextPawnSpawnTick(num); if (thing.TryGetComp <CompProjectileInterceptor>() != null) { lordJob_MechanoidDefendBase.AddThingToNotifyOnDefeat(thing); } if (flag) { CompInitiatable compInitiatable = thing.TryGetComp <CompInitiatable>(); if (compInitiatable != null) { compInitiatable.initiationDelayTicksOverride = (int)(60000f * randomInRange); } } Building b; if ((b = (thing as Building)) != null && IsBuildingThreat(b)) { lord.AddBuilding(b); } thing.SetFaction(Faction.OfMechanoids); } if (!sketch.pawns.NullOrEmpty()) { foreach (MechClusterSketch.Mech pawn2 in sketch.pawns) { IntVec3 result = pawn2.position + center; if (result.Standable(map) || CellFinder.TryFindRandomCellNear(result, map, 12, (IntVec3 x) => x.Standable(map), out result)) { Pawn pawn = PawnGenerator.GeneratePawn(pawn2.kindDef, Faction.OfMechanoids); CompCanBeDormant compCanBeDormant = pawn.TryGetComp <CompCanBeDormant>(); if (compCanBeDormant != null) { if (sketch.startDormant) { compCanBeDormant.ToSleep(); } else { compCanBeDormant.WakeUp(); } } lord.AddPawn(pawn); spawnedThings.Add(pawn); if (dropInPods) { ActiveDropPodInfo activeDropPodInfo = new ActiveDropPodInfo(); activeDropPodInfo.innerContainer.TryAdd(pawn, 1); activeDropPodInfo.openDelay = 60; activeDropPodInfo.leaveSlag = false; activeDropPodInfo.despawnPodBeforeSpawningThing = true; activeDropPodInfo.spawnWipeMode = WipeMode.Vanish; DropPodUtility.MakeDropPodAt(result, map, activeDropPodInfo); } else { GenSpawn.Spawn(pawn, result, map); } } } } foreach (Thing item in spawnedThings) { if (!sketch.startDormant) { item.TryGetComp <CompWakeUpDormant>()?.Activate(sendSignal: true, silent: true); } } return(spawnedThings); }