Пример #1
0
 public static bool GetReloading(this Building_Turret turret)
 {
     if (turret is Building_TurretGunCE ceturret)
     {
         return(ceturret.isReloading);
     }
     if (enabled)
     {
         GetReloadingFunction func;
         if (getReloading.TryGetValue(turret.GetType(), out func))
         {
             return(func(turret));
         }
     }
     CELogger.Warn("Asked to get reloading on an unknown turret type: " + turret);
     return(false);
 }
Пример #2
0
 public static Thing GetGun(this Building_Turret turret)
 {
     if (turret is Building_TurretGunCE ceturret)
     {
         return(ceturret.Gun);
     }
     if (enabled)
     {
         GetGunFunction gfunc;
         if (getGun.TryGetValue(turret.GetType(), out gfunc))
         {
             return(gfunc(turret));
         }
     }
     CELogger.Warn("Asked to get gun on an unknown turret type: " + turret);
     return(null);
 }
Пример #3
0
 public static void SetReloading(this Building_Turret turret, bool reloading)
 {
     if (turret is Building_TurretGunCE ceturret)
     {
         ceturret.isReloading = reloading;
         return;
     }
     if (enabled)
     {
         SetReloadingFunction func;
         if (setReloading.TryGetValue(turret.GetType(), out func))
         {
             func(turret, reloading);
             return;
         }
     }
     CELogger.Warn("Asked to set reloading on an unknown turret type: " + turret);
 }
Пример #4
0
 public static CompAmmoUser GetAmmo(this Building_Turret turret)
 {
     if (turret is Building_TurretGunCE ceturret)
     {
         return(ceturret.CompAmmo);
     }
     if (enabled)
     {
         GetAmmoFunction func;
         if (getAmmo.TryGetValue(turret.GetType(), out func))
         {
             return(func(turret));
         }
         GetGunFunction gfunc;
         if (getGun.TryGetValue(turret.GetType(), out gfunc))
         {
             return(gfunc(turret)?.TryGetComp <CompAmmoUser>());
         }
     }
     CELogger.Warn("Asked to get ammo on an unknown turret type: " + turret);
     return(null);
 }
        public static bool CanReload(Pawn pawn, Thing thing, bool forced = false, bool emergency = false)
        {
            if (pawn == null || thing == null)
            {
                CELogger.Warn($"{pawn?.ToString() ?? "null pawn"} could not reload {thing?.ToString() ?? "null thing"} one of the two was null.");
                return(false);
            }

            if (!(thing is Building_Turret turret))
            {
                CELogger.Warn($"{pawn} could not reload {thing} because {thing} is not a Turret. If you are a modder, make sure to use {nameof(CombatExtended)}.{nameof(Building_TurretGunCE)} for your turret's compClass.");
                return(false);
            }
            var compAmmo = turret.GetAmmo();

            if (compAmmo == null)
            {
                CELogger.Warn($"{pawn} could not reload {turret} because turret has no {nameof(CompAmmoUser)}.");
                return(false);
            }
            if (turret.GetReloading())
            {
                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());
                return(false);
            }
            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.GetMannable()?.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 (compAmmo.UseAmmo && FindBestAmmo(pawn, turret) == null)
            {
                JobFailReason.Is("CE_NoAmmoAvailable".Translate());
                return(false);
            }
            return(true);
        }