コード例 #1
0
        public static Job MakeReloadJob(Pawn pawn, Building_Turret turret)
        {
            var compAmmo = turret.GetAmmo();

            if (compAmmo == null)
            {
                CELogger.Error($"{pawn} tried to create a reload job on a thing ({turret}) that's not reloadable.");
                return(null);
            }

            if (!compAmmo.UseAmmo)
            {
                return(MakeReloadJobNoAmmo(turret));
            }

            var ammo = FindBestAmmo(pawn, turret);

            if (ammo == null)
            {
                CELogger.Error($"{pawn} tried to create a reload job without ammo. This should have been checked earlier.");
                return(null);
            }
            CELogger.Message($"Making a reload job for {pawn}, {turret} and {ammo}");

            Job job = JobMaker.MakeJob(CE_JobDefOf.ReloadTurret, turret, ammo);

            job.count = Mathf.Min(ammo.stackCount, compAmmo.MissingToFullMagazine);
            return(job);
        }
コード例 #2
0
        public override bool TryMakePreToilReservations(bool errorOnFailed)
        {
            if (!pawn.Reserve(TargetA, job))
            {
                CELogger.Message("Combat Extended: Could not reserve turret for reloading job.");
                return(false);
            }

            var compAmmo = turret?.CompAmmo;

            if (compAmmo == null)
            {
                CELogger.Error($"{TargetA} has no CompAmmo, this should not have been reached.");
                return(false);
            }

            if (!compAmmo.UseAmmo)
            {
                return(true);
            }

            if (ammo == null)
            {
                CELogger.Message("Combat Extended: Ammo is null");
                return(false);
            }
            if (!pawn.Reserve(TargetB, job, Mathf.Max(1, TargetThingB.stackCount - job.count), job.count))
            {
                CELogger.Message("Combat Extended: Could not reserve " + Mathf.Max(1, TargetThingB.stackCount - job.count) + " of ammo.");
                return(false);
            }
            CELogger.Message("Combat Extended: Managed to reserve everything successfully.");
            return(true);
        }
コード例 #3
0
        public static bool CanReload(Pawn pawn, Thing hopefullyTurret, bool forced = false, bool emergency = false)
        {
            if (pawn == null || hopefullyTurret == null)
            {
                CELogger.Error($"{pawn?.ToString() ?? "null pawn"} could not reload {hopefullyTurret?.ToString() ?? "null thing"} one of the two was null.");
                return(false);
            }
            if (!(hopefullyTurret is Building_TurretGunCE))
            {
                CELogger.Error($"{pawn} could not reload {hopefullyTurret} because {hopefullyTurret} is not a Combat Extended Turret. If you are a modder, make sure to use {nameof(CombatExtended)}.{nameof(Building_TurretGunCE)} for your turret's compClass.");
                return(false);
            }
            var turret   = hopefullyTurret as Building_TurretGunCE;
            var compAmmo = turret.CompAmmo;

            if (compAmmo == null)
            {
                CELogger.Error($"{pawn} could not reload {turret} because turret has no {nameof(CompAmmoUser)}.");
                return(false);
            }
            if (turret.isReloading)
            {
                CELogger.Message($"{pawn} could not reload {turret} because turret is already reloading.");
                JobFailReason.Is("CE_TurretAlreadyReloading".Translate());
                return(false);
            }
            if (turret.IsBurning() && !emergency)
            {
                CELogger.Message($"{pawn} could not reload {turret} because turret is on fire.");
                JobFailReason.Is("CE_TurretIsBurning".Translate());
            }
            if (compAmmo.FullMagazine)
            {
                CELogger.Message($"{pawn} could not reload {turret} because it is full of ammo.");
                JobFailReason.Is("CE_TurretFull".Translate());
                return(false);
            }
            if (turret.IsForbidden(pawn) || !pawn.CanReserve(turret, 1, -1, null, forced))
            {
                CELogger.Message($"{pawn} could not reload {turret} because it is forbidden or otherwise busy.");
                return(false);
            }
            if (turret.Faction != pawn.Faction && (turret.Faction != null && pawn.Faction != null && turret.Faction.RelationKindWith(pawn.Faction) != FactionRelationKind.Ally))
            {
                CELogger.Message($"{pawn} could not reload {turret} because the turret is hostile to them.");
                JobFailReason.Is("CE_TurretNonAllied".Translate());
                return(false);
            }
            if ((turret.MannableComp?.ManningPawn != pawn) && !pawn.CanReserveAndReach(turret, PathEndMode.ClosestTouch, forced ? Danger.Deadly : pawn.NormalMaxDanger(), MagicMaxPawns))
            {
                CELogger.Message($"{pawn} could not reload {turret} because turret is manned (or was recently manned) by someone else.");
                return(false);
            }
            if (FindBestAmmo(pawn, turret) == null)
            {
                JobFailReason.Is("CE_NoAmmoAvailable".Translate());
                return(false);
            }
            return(true);
        }
コード例 #4
0
 public override bool ShouldSkip(Pawn pawn, bool forced = false)
 {
     if (forced)
     {
         CELogger.Message("Job is forced. Not skipping.");
         return(false);
     }
     if (pawn.CurJob == null)
     {
         CELogger.Message($"Pawn {pawn.ThingID} has no job. Not skipping.");
         return(false);
     }
     if (pawn.CurJobDef == JobDefOf.ManTurret)
     {
         CELogger.Message($"Pawn {pawn.ThingID}'s current job is {nameof(JobDefOf.ManTurret)}. Not skipping.");
         return(false);
     }
     if (pawn.CurJob.playerForced)
     {
         CELogger.Message($"Pawn {pawn.ThingID}'s current job is forced by the player. Skipping.");
         return(true);
     }
     CELogger.Message($"Pawn {pawn.ThingID}'s current job is {pawn.CurJobDef.reportString}. Skipping");
     return(pawn.CurJobDef == CE_JobDefOf.ReloadTurret || pawn.CurJobDef == CE_JobDefOf.ReloadWeapon);
 }
コード例 #5
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)      //Add mannableComp, ticksUntilAutoReload, register to GenClosestAmmo
        {
            base.SpawnSetup(map, respawningAfterLoad);
            dormantComp  = GetComp <CompCanBeDormant>();
            powerComp    = GetComp <CompPowerTrader>();
            mannableComp = GetComp <CompMannable>();
            if (!respawningAfterLoad)
            {
                CELogger.Message($"top is {top?.ToString() ?? "null"}");
                top.SetRotationFromOrientation();
                burstCooldownTicksLeft = def.building.turretInitialCooldownTime.SecondsToTicks();

                //Delay auto-reload for a few seconds after spawn, so player can operate the turret right after placing it, before other colonists start reserving it for reload jobs
                if (mannableComp != null)
                {
                    ticksUntilAutoReload = minTicksBeforeAutoReload;
                }
            }

            // if (CompAmmo == null || CompAmmo.Props == null || CompAmmo.Props.ammoSet == null || CompAmmo.Props.ammoSet.ammoTypes.NullOrEmpty())
            //     return;

            // //"Subscribe" turret to GenClosestAmmo
            // foreach (var ammo in CompAmmo.Props.ammoSet.ammoTypes.Select(x => x.ammo))
            // {
            //     if (!GenClosestAmmo.listeners.ContainsKey(ammo))
            //         GenClosestAmmo.listeners.Add(ammo, new List<Building_TurretGunCE>() { this });
            //     else
            //         GenClosestAmmo.listeners[ammo].Add(this);

            //     if (!GenClosestAmmo.latestAmmoUpdate.ContainsKey(ammo))
            //         GenClosestAmmo.latestAmmoUpdate.Add(ammo, 0);
            // }
        }
コード例 #6
0
        private static bool ImpactSomething(ProjectileCE projectile, Thing launcher)
        {
            var     map           = projectile.Map;
            Vector3 exactPosition = projectile.ExactPosition;

            refreshShields(map);

            var blocked = shields.Any(building => ShieldInterceptsProjectile(building as Building_Shield, projectile, launcher));

            CELogger.Message($"Blocked {projectile}? -- {blocked}");
            return(blocked);
        }
コード例 #7
0
        private float GetThingPriority(Pawn pawn, Thing t, bool forced = false)
        {
            CELogger.Message($"pawn: {pawn}. t: {t}. forced: {forced}");
            Building_TurretGunCE turret = t as Building_TurretGunCE;

            if (!turret.Active)
            {
                return(1f);
            }
            if (turret.EmptyMagazine)
            {
                return(9f);
            }
            if (turret.AutoReloadableMagazine)
            {
                return(5f);
            }
            return(1f);
        }
コード例 #8
0
        /// <summary>
        /// Called as a scanner
        /// </summary>
        /// <param name="pawn">Never null</param>
        /// <param name="t">Can be non-turret</param>
        /// <param name="forced">Generally not true</param>
        /// <returns></returns>

        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            // Should never happen anymore, as only TurretGunCEs should be returned from PotentialWorkThingsGlobal
            if (!(t is Building_TurretGunCE))
            {
                return(false);
            }

            var priority = GetThingPriority(pawn, t, forced);

            CELogger.Message($"Priority check completed. Got {priority}");

            Building_TurretGunCE turret = t as Building_TurretGunCE;

            CELogger.Message($"Turret uses ammo? {turret.CompAmmo.UseAmmo}");

            CELogger.Message($"Total magazine size: {turret.CompAmmo.Props.magazineSize}. Needed: {turret.CompAmmo.MissingToFullMagazine}");

            return(JobGiverUtils_Reload.CanReload(pawn, turret, forced));
        }
コード例 #9
0
 public override bool TryMakePreToilReservations(bool errorOnFailed)
 {
     if (!pawn.Reserve(TargetA, job))
     {
         CELogger.Message("Combat Extended: Could not reserve turret for reloading job.");
         return(false);
     }
     if (ammo == null)
     {
         CELogger.Message("Combat Extended: Ammo is null");
         return(false);
     }
     if (!pawn.Reserve(TargetB, job, Mathf.Max(1, TargetThingB.stackCount - job.count), job.count))
     {
         CELogger.Message("Combat Extended: Could not reserve " + Mathf.Max(1, TargetThingB.stackCount - job.count) + " of ammo.");
         return(false);
     }
     CELogger.Message("Combat Extended: Managed to reserve everything successfully.");
     return(true);
 }
コード例 #10
0
        private float GetThingPriority(Pawn pawn, Thing t, bool forced = false)
        {
            CELogger.Message($"pawn: {pawn}. t: {t}. forced: {forced}");
            Building_Turret turret = t as Building_Turret;



            if (!((turret as Building_TurretGunCE)?.Active ?? true))
            {
                return(1f);
            }
            if (turret.GetAmmo()?.EmptyMagazine ?? false)
            {
                return(9f);
            }
            if (turret.GetMannable() == null)
            {
                return(5f);
            }
            return(1f);
        }
コード例 #11
0
        /// <summary>
        /// Called as a scanner
        /// </summary>
        /// <param name="pawn">Never null</param>
        /// <param name="t">Can be non-turret</param>
        /// <param name="forced">Generally not true</param>
        /// <returns></returns>

        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            if (!(t is Building_TurretGunCE))
            {
                return(false);
            }
            var priority = GetThingPriority(pawn, t, forced);

            CELogger.Message($"Priority check completed. Got {priority}");

            Building_TurretGunCE turret = t as Building_TurretGunCE;

            CELogger.Message($"Turret uses ammo? {turret.CompAmmo.UseAmmo}");
            if (!turret.CompAmmo.UseAmmo)
            {
                return(true);
            }

            CELogger.Message($"Total magazine size: {turret.CompAmmo.Props.magazineSize}. Needed: {turret.CompAmmo.MissingToFullMagazine}");

            return(JobGiverUtils_Reload.CanReload(pawn, turret, forced));
        }