//CompFacility : ThingComp
 //{
 public static void SteamFacilityCanBeActive(CompFacility __instance, ref bool __result)
 {
     if (!__result && __instance.parent.GetComp <CompSteamTrader>() is CompSteamTrader t)
     {
         __result = t.SteamOn;
     }
 }
        public static IRadiationReciever LinkedRadiationReciever(this ThingWithComps thing)
        {
            CompFacility facility = thing.GetComp <CompFacility>();

            if (facility == null)
            {
                return(null);
            }

            foreach (Thing linkedThing in facility.LinkedBuildings())
            {
                IRadiationReciever res = linkedThing as IRadiationReciever;
                if (res != null)
                {
                    return(res);
                }

                Building linkedBuilding = linkedThing as Building;
                if (linkedBuilding == null)
                {
                    continue;
                }

                foreach (ThingComp comp in linkedBuilding.AllComps)
                {
                    res = comp as IRadiationReciever;
                    if (res != null)
                    {
                        return(res);
                    }
                }
            }

            return(null);
        }
 public static List <Thing> LinkedBuildings(this CompFacility compFacility)
 {
     if (_linkedBuildings == null)
     {
         _linkedBuildings = typeof(CompFacility).GetField("linkedBuildings", BindingFlags.Instance | BindingFlags.NonPublic);
     }
     return((List <Thing>)_linkedBuildings.GetValue(compFacility));
 }
Esempio n. 4
0
        public static List <Thing> LinkedBuildings(this CompFacility facility)
        {
            if (linkedBuildingsField == null)
            {
                linkedBuildingsField = typeof(CompFacility).GetField("linkedBuildings", BindingFlags.NonPublic | BindingFlags.Instance);
            }

            return(linkedBuildingsField.GetValue(facility) as List <Thing>);
        }
Esempio n. 5
0
        public static T Linked <T>(this ThingWithComps thing) where T : Thing
        {
            CompFacility comp = thing.GetComp <CompFacility>();

            if (comp == null)
            {
                return(null);
            }

            return(comp.Linked <T>());
        }
Esempio n. 6
0
        public static T Linked <T>(this CompFacility facility) where T : Thing
        {
            foreach (var thing in facility.LinkedBuildings())
            {
                T res = thing as T;
                if (res != null)
                {
                    return(res);
                }
            }

            return(null);
        }
Esempio n. 7
0
        public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot, Color ghostCol)
        {
            Map currentMap = Find.CurrentMap;

            if (def.HasComp(typeof(CompAffectedByFacilities)))
            {
                CompAffectedByFacilities.DrawLinesToPotentialThingsToLinkTo(def, center, rot, currentMap);
            }

            if (def.HasComp(typeof(CompFacility)))
            {
                CompFacility.DrawLinesToPotentialThingsToLinkTo(def, center, rot, currentMap);
            }
        }
        // get power comp
        public override void PostSpawnSetup(bool respawningAfterLoad)
        {
            //Building
            building     = (Building)parent;
            buildingPos  = building.DrawPos;
            buildingName = building?.LabelShort;
            TpSpotName   = Tools.LabelByDefName("LTF_TpSpot", prcDebug);
            //Building comp
            compPower    = building?.TryGetComp <CompPowerTrader>();
            compQuality  = building?.TryGetComp <CompQuality>();
            compFacility = building?.TryGetComp <CompFacility>();
            range        = compFacility?.Props.maxDistance ?? 0f;
            SetMoreRange();

            WeightFacilityCapacity(compQuality);
        }
        public void RecalculateStatistics()
        {
            //Log.Message("RecalculateStatistics");

            //Visual Settings
            this.m_ColourRed   = 0.5f;
            this.m_ColourGreen = 0.0f;
            this.m_ColourBlue  = 0.5f;

            //Field Settings
            this.m_FieldIntegrity_Max     = this.Properties.m_FieldIntegrity_Max_Base;
            this.m_FieldIntegrity_Initial = this.Properties.m_FieldIntegrity_Initial;
            this.m_FieldRadius_Avalable   = this.Properties.m_Field_Radius_Base;

            //Mode Settings - Avalable
            this.m_BlockIndirect_Avalable    = this.Properties.m_BlockIndirect_Avalable;
            this.m_BlockDirect_Avalable      = this.Properties.m_BlockDirect_Avalable;
            this.m_InterceptDropPod_Avalable = this.Properties.m_InterceptDropPod_Avalable;

            //Power Settings
            this.m_PowerRequired = this.Properties.m_PowerRequired_Charging;

            //Recovery Settings
            this.m_RechargeTickDelayInterval = this.Properties.m_RechargeTickDelayInterval_Base;
            this.m_RecoverWarmupDelayTicks   = this.Properties.m_RecoverWarmupDelayTicks_Base;

            //Power converter
            this.SlowDischarge_Active = false;

            //IFF
            this.m_IdentifyFriendFoe_Avalable = false;

            //Store the List of Building in initilisation????

            CompFacility _Facility = this.parent.GetComp <CompFacility>();

            Patch.Patcher.LogNULL(_Facility, "_Facility");

            FieldInfo _LinkedBuildingsInfo = typeof(CompFacility).GetField("linkedBuildings", BindingFlags.NonPublic | BindingFlags.Instance);

            Patch.Patcher.LogNULL(_LinkedBuildingsInfo, "_LinkedBuildingsInfo");

            List <Thing> _LinkedBuildings = _LinkedBuildingsInfo.GetValue(_Facility) as List <Thing>;

            Patch.Patcher.LogNULL(_LinkedBuildings, "_LinkedBuildings");

            //Log.Message(_LinkedBuildings.Count.ToString());


            _LinkedBuildings.ForEach(b =>
            {
                Building _Building       = b as Building;
                Comp_ShieldUpgrade _Comp = _Building.GetComp <Comp_ShieldUpgrade>();

                Patch.Patcher.LogNULL(_Comp, "_Comp");
                Patch.Patcher.LogNULL(_Comp.Properties, "_Comp.Properties");

                this.AddStatsFromUpgrade(_Comp);
            });

            this.m_Power.powerOutputInt = -this.m_PowerRequired;
        }
Esempio n. 10
0
        void PowerLevelToggle(int thisTickCount)
        {
            // If it's on, don't recheck until it times out
            keepOnTicks -= thisTickCount;
            if (keepOnTicks > 0)
            {
                return;
            }

            // Basic decision, turn on if someone is on it, only if it turns
            // on when someone is on it (duh?), otherwise turn on if someone is
            // on it's interaction cell AND is using it.  Failing all that, go
            // to low power mode.
            bool turnItOn = false;

            // Should it...?
            if (!onIfOn)
            {
                switch (IdleProps.operationalMode)
                {
                case LowIdleDrawMode.InUse:
                    // This building has an interaction cell or CompAffectedByFacilities,
                    // this means it has jobs associated with it.  Only go to full-power
                    // if the pawn standing there has a job using the building.

                    if (CompFacility != null)
                    {
                        foreach (var linked in CompFacility.LinkedBuildings())
                        {
                            if (linked.def.hasInteractionCell)
                            {
                                // Look for a user at interaction cell...
                                Pawn pUser = Find.ThingGrid.ThingAt <Pawn>(linked.InteractionCell);
                                if (pUser != null)
                                {
                                    // ...A pawn is here!...
                                    if (HasJobOnTarget(pUser, linked))
                                    {
                                        // ..Using linked building!
                                        turnItOn = true;
                                    }
                                }
                            }
                            else
                            {
                                // look for a user at any occupied cell
                                var occupiedRect = linked.OccupiedRect();
                                foreach (var cell in occupiedRect)
                                {
                                    Pawn pUser = Find.ThingGrid.ThingAt <Pawn>(cell);
                                    if (pUser != null)
                                    {
                                        // ...A pawn is here!...
                                        if (HasJobOnTarget(pUser, linked))
                                        {
                                            // ..Using linked building!
                                            turnItOn = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            if (turnItOn)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        while (true)
                        {
                            // Quickly check the last user is still using...
                            if (
                                (curUser != null) &&
                                (curUser.Position == scanPosition[0])
                                )
                            {
                                // They're here...
                                if (
                                    (curUser.CurJob != null) &&
                                    (curUser.CurJob == curJob)
                                    )
                                {
                                    // ...they're using!
                                    turnItOn = true;
                                    break;
                                }
                            }

                            // Look for a new user...
                            Pawn pUser = Find.ThingGrid.ThingAt <Pawn>(scanPosition[0]);
                            if (pUser != null)
                            {
                                // ...A pawn is here!...
                                if (HasJobOnTarget(pUser, parent))
                                {
                                    // ..Using this building!...
                                    curUser  = pUser;
                                    curJob   = pUser.CurJob;
                                    turnItOn = true;
                                }
                            }

                            // Exit loop
                            break;
                        }
                    }

                    break;

                case LowIdleDrawMode.Cycle:
                    // Power cycler

                    if (LowPowerMode)
                    {
                        // Going to full power cycle
                        turnItOn = true;
                    }
                    break;

                case LowIdleDrawMode.Factory:
                    // Automated Factory production
                    if (AutomatedFactory.CurrentRecipe != null)
                    {
                        turnItOn = true;
                    }
                    break;
                }
            }
            else
            {
                var joyGiverDefs = parent.def.GetJoyGiverDefsUsing();
                var isJoyJob     = !joyGiverDefs.NullOrEmpty();

                // Full-power when any pawn is standing on any monitored cell...
                foreach (IntVec3 curPos in scanPosition)
                {
                    var pawn = Find.ThingGrid.ThingAt <Pawn>(curPos);
                    if (pawn != null)
                    {
                        if (
                            (!isJoyJob) ||
                            (HasJobOnTarget(pawn, parent))
                            )
                        {
                            // Found a pawn, turn it on and early out
                            turnItOn = true;
                            break;
                        }
                    }
                }
            }

            // Do?...
            if (turnItOn)
            {
                // ...Turn on...
                if (LowPowerMode)
                {
                    // ...because it is idle
                    TogglePower();
                }
                else
                {
                    // ..maintain the current state
                    keepOnTicks = IdleProps.cycleHighTicks;
                }
            }
            else if (!LowPowerMode)
            {
                // ...Is not idle, go to idle mode
                TogglePower();
            }
            else
            {
                // ..maintain idle state
                keepOnTicks = IdleProps.cycleLowTicks;
            }

            if (
                (LowPowerMode) &&
                (CompGlower != null)
                )
            {
                // Glower on while idle???
                ToggleGlower(false);
            }
        }
            public static void CanBeActivePostfix(ref bool __result, ref CompFacility __instance)
            {
                CompRefuelable fuel = __instance.parent.TryGetComp <CompRefuelable>();

                __result &= (fuel == null || fuel.HasFuel);
            }