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 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);
        }
Пример #3
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);
        }
        private static Job MakeReloadJobNoAmmo(Building_Turret turret)
        {
            var compAmmo = turret.GetAmmo();

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

            return(JobMaker.MakeJob(CE_JobDefOf.ReloadTurret, turret, null));
        }
Пример #5
0
        public static Job MakeReloadJobNoAmmo(Building_TurretGunCE turret)
        {
            var compAmmo = turret.TryGetComp <CompAmmoUser>();

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

            return(JobMaker.MakeJob(CE_JobDefOf.ReloadTurret, turret, null));
        }
Пример #6
0
        //Checks before called (ONLY when in SCANNER):
        // - PawnCanUseWorkGiver(pawn, this)
        //      - nonColonistCanDo || isColonist
        //      - !WorkTagIsDisabled(def.workTags)
        //      - !ShouldSkip(pawn, false)
        //      - MissingRequiredCapacity(pawn) == null
        // - !t.IsForbidden(pawn)
        // - this.PotentialWorkThingRequest.Accepts(t),
        /// <summary>
        /// Called after HasJobOnThing by WorkGiver_Scanner, or by Building_TurretGunCE when turret tryReload with manningPawn
        /// </summary>
        /// <param name="pawn"></param>
        /// <param name="t"></param>
        /// <param name="forced"></param>
        /// <returns></returns>
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_TurretGunCE turret = t as Building_TurretGunCE;

            if (turret == null)
            {
                CELogger.Error($"{pawn} tried to make a reload job on a {t} which isn't a turret. This should never be reached.");
            }

            // NOTE: The removal of the code that used to be here disables reloading turrets directly from one's inventory.
            // The player would need to drop the ammo the pawn is holding first.

            return(JobGiverUtils_Reload.MakeReloadJob(pawn, turret));
        }