Exemplo n.º 1
0
 public GlowerPorperties(CompGlower glower)
 {
     this.glower     = glower;
     this.indices    = new HashSet <int>();
     this.position   = glower.parent.positionInt.ToVector3();
     this.position.y = 0.0f;
 }
        private void FindNearbyGlowers(CellRect rect)
        {
            Map map = BaseGen.globalSettings.map;

            SymbolResolver_OutdoorLighting.nearbyGlowers.Clear();
            rect = rect.ExpandedBy(4);
            rect = rect.ClipInsideMap(map);
            CellRect.CellRectIterator iterator = rect.GetIterator();
            while (!iterator.Done())
            {
                Region region = iterator.Current.GetRegion(map, RegionType.Set_Passable);
                if (region != null && region.Room.PsychologicallyOutdoors)
                {
                    List <Thing> thingList = iterator.Current.GetThingList(map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        CompGlower compGlower = thingList[i].TryGetComp <CompGlower>();
                        if (compGlower != null)
                        {
                            SymbolResolver_OutdoorLighting.nearbyGlowers.Add(compGlower);
                        }
                    }
                }
                iterator.MoveNext();
            }
        }
        public override void Tick()
        {
            base.Tick();

            bool isRunning = GetShouldBeRunning();

            if (isRunning)
            {
                ProductionTicks++;
                if (ProductionTicks >= TicksToProduceOutput)
                {
                    ProductionTicks = 0;

                    // Delete fuel from comps.
                    GetFuelComp(1).SetFuelLevel(0);
                    GetFuelComp(2).SetFuelLevel(0);

                    PlaceOutput(OutputAmount);
                }
            }

            if (lastFrameRunning != isRunning)
            {
                CompGlower?.ReceiveCompSignal("PowerTurnedOn"); // Obviously the power hasn't actually just been turned on, but it's just a way to trigger UpdateLit to be called.
            }
            lastFrameRunning = isRunning;
        }
        public void UpdateGlower(int colorOptionInd)
        {
            RemoveGlower();
            var colorOption = Props.colorOptions[colorOptionInd];

            this.currentColor    = colorOption;
            this.currentColorInd = colorOptionInd;
            this.compGlower      = new CompGlower();
            Thing dummyThing = null;

            if (Props.spawnGlowerInFacedCell)
            {
                dummyThing = ThingMaker.MakeThing(ThingDef.Named("RE_WallLightDummyWorkaround"));
                var cellGlower = this.parent.Position + base.parent.Rotation.FacingCell;
                GenSpawn.Spawn(dummyThing, cellGlower, this.parent.Map);
                this.compGlower.parent = dummyThing as ThingWithComps;
            }
            else
            {
                this.compGlower.parent = this.parent;
            }
            this.compGlower.Initialize(new CompProperties_Glower()
            {
                glowColor       = colorOption.glowColor,
                glowRadius      = colorOption.glowRadius,
                overlightRadius = colorOption.overlightRadius
            });
            base.parent.Map.mapDrawer.MapMeshDirty(base.parent.Position, MapMeshFlag.Things);
            base.parent.Map.glowGrid.RegisterGlower(this.compGlower);
            if (Props.spawnGlowerInFacedCell)
            {
                dummyThing.DeSpawn();
            }
        }
Exemplo n.º 5
0
        // ===================== Setup Work =====================
        /// <summary>
        /// Initialize instance variables.
        /// </summary>
        ///
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);

            this.glowerComp = this.GetComp <CompGlower>();
            this.powerComp  = this.GetComp <CompPowerTrader>();
        }
Exemplo n.º 6
0
        public override void Tick()
        {
            base.Tick();

            tickCount++;

            // Change power draw based on active status.
            UpdatePowerDraw();

            // Update active/running state.
            bool oldActive = this.IsActive;

            UpdateActiveState();
            if (oldActive != this.IsActive)
            {
                CompGlower?.ReceiveCompSignal("PowerTurnedOn"); // Obviously the power hasn't actually just been turned on, but it's just a way to trigger UpdateLit to be called.
            }

            if (!IsActive)
            {
                frameNumber   = 0;
                activeGraphic = base.DefaultGraphic;
                return;
            }

            // Update output.
            UpdateOutput();

            // Update active state visuals.
            UpdateActiveGraphics();
        }
Exemplo n.º 7
0
            internal static void Prefix(GlowGrid __instance, CompGlower oldGlow)
            {
                Map map = __instance.map;

                deregister = true;
                TryRegisterMap(map);

                GlowerPorperties prop;

                if (Finder.debug)
                {
                    Log.Message(string.Format("ROCKETMAN: Removed {0}", oldGlow));
                }
                if (!props.ContainsKey(oldGlow))
                {
                    if (Finder.debug && !removedProps[map.Index].Any(p => p.glower == oldGlow))
                    {
                        Log.Warning(string.Format("ROCKETMAN: Found an unregisterd {0}:{1}", oldGlow, oldGlow.parent));
                    }
                    return;
                }
                prop = props[oldGlow];

                if (Finder.debug)
                {
                    Log.Message(string.Format("ROCKETMAN: Queued {0} for removal", oldGlow.parent));
                }
                removedProps[map.Index].Add(prop);
            }
Exemplo n.º 8
0
        public static void ShouldBeLitNow_Postfix(ref bool __result, CompGlower __instance)
        {
            if (__result)
            {
                return;
            }

            if (!__instance.parent.Spawned)
            {
                return;
            }
            if (!FlickUtility.WantsToBeOn(__instance.parent))
            {
                return;
            }
            Comp.VoidNetPort compPowerTrader = __instance.parent.TryGetComp <Comp.VoidNetPort>();
            if (compPowerTrader != null && !compPowerTrader.PowerOn)
            {
                __result = true;
                return;
            }
            CompRefuelable compRefuelable = __instance.parent.TryGetComp <CompRefuelable>();

            if (compRefuelable != null && !compRefuelable.HasFuel)
            {
                return;
            }
            CompSendSignalOnCountdown compSendSignalOnCountdown = __instance.parent.TryGetComp <CompSendSignalOnCountdown>();

            if (compSendSignalOnCountdown != null && compSendSignalOnCountdown.ticksLeft <= 0)
            {
                return;
            }
            return;
        }
Exemplo n.º 9
0
        private void DespawnGlower(Building glower)
        {
            CompGlower glowComp = glower.GetComp <CompGlower>();

            Map.glowGrid.DeRegisterGlower(glowComp);
            glower.Destroy();
        }
Exemplo n.º 10
0
        // ===================== Setup Work =====================
        /// <summary>
        /// Initialize instance variables.
        /// </summary>
        ///
        public override void SpawnSetup(Map map)
        {
            base.SpawnSetup(map);

            glowerComp = this.GetComp <CompGlower>();
            powerComp  = this.GetComp <CompPowerTrader>();
        }
Exemplo n.º 11
0
        public override void PostSpawnSetup()
        {
            fuelContainer = new ThingContainer(this, false);

            // internal temperature initialize
            internalTemp = parent.Position.GetTemperature();

            // required comps initialize
            compFueled = parent.TryGetComp<CompFueled>();
            compFlickable = parent.TryGetComp<CompFlickable>();
            compHeatPusher = parent.TryGetComp<CompHeatPusher>();
            heatPerSecond_fromXML = compHeatPusher.Props.heatPerSecond;
            compGlower = parent.TryGetComp<CompGlower>();
            glowRadius_fromXML = compGlower.Props.glowRadius;

            // initialize glower and heater
            AdjustGlowerAndHeater();

            // filters initialize
            filterFuelPossible.SetDisallowAll();
            filterFuelPossible.allowedQualitiesConfigurable = false;
            filterFuelPossible.allowedHitPointsConfigurable = false;
            foreach (var thingDef in DefDatabase<ThingDef>.AllDefs.Where(def => !def.statBases.NullOrEmpty() && def.statBases.Exists(stat => stat.stat.defName == "MaxBurningTempCelsius" && stat.value > 0)))
            {
                filterFuelPossible.SetAllow(thingDef, true);
            }
            filterFuelCurrent.CopyAllowancesFrom(filterFuelPossible);
        }
Exemplo n.º 12
0
        // Token: 0x06000191 RID: 401 RVA: 0x0000F4CC File Offset: 0x0000D6CC
        private void FindNearbyGlowers(CellRect rect)
        {
            Map map = BaseGen.globalSettings.map;

            SymbolResolver_OutdoorLightingHivebase.nearbyGlowers.Clear();
            rect = rect.ExpandedBy(4);
            rect = rect.ClipInsideMap(map);
            foreach (IntVec3 intVec in rect)
            {
                Region region = intVec.GetRegion(map, RegionType.Set_Passable);
                bool   flag   = region != null && region.Room.PsychologicallyOutdoors;
                if (flag)
                {
                    List <Thing> thingList = intVec.GetThingList(map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        CompGlower compGlower = thingList[i].TryGetComp <CompGlower>();
                        bool       flag2      = compGlower != null;
                        if (flag2)
                        {
                            SymbolResolver_OutdoorLightingHivebase.nearbyGlowers.Add(compGlower);
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
        public void changeColourTest()
        {
            // new glower
            CompGlower myThingComp = new CompGlower();

            myThingComp.parent = this.parent;
            CompProperties_Glower compProps = new CompProperties_Glower();

            // color init
            curIndex = ((curIndex + 1) > 7) ? (0) : (curIndex + 1);
            newcolor = colors[curIndex];

            // setting props
            compProps.glowColor  = newcolor;
            compProps.glowRadius = glowRadius;
            // init
            myThingComp.Initialize(compProps);

            // applying to map
            Map     myMap = parent.Map;
            IntVec3 myPos = parent.Position;

            myMap.mapDrawer.MapMeshDirty(myPos, MapMeshFlag.Things);
            myMap.glowGrid.RegisterGlower(myThingComp);

            // removing old glow
            parent.AllComps.Remove(glowComp);
            myMap.glowGrid.DeRegisterGlower(glowComp);

            // remembering what you did last summer
            glowComp = myThingComp;
        }
Exemplo n.º 14
0
        // Stone camp fire
        public static void SetCompGlower(Thing t, Map map, bool burning = true)
        {
            //Tools.Warn("Trying to set glow:"+burning, true);
            CompGlower comp = t.TryGetComp <CompGlower>();

            if (comp is CompGlower)
            {
                /*
                 * CompGlower myThingComp = new CompGlower();
                 * myThingComp.parent = (ThingWithComps)t;
                 *
                 * CompProperties compProps = new CompProperties();
                 * compProps.compClass = typeof(CompGlower);
                 *
                 * ColorInt newcolor = (burning)?(new ColorInt(252, 187, 113, 0) * 1.45f):( new ColorInt(255, 50, 0, 0) * 1.45f);
                 * compProps.compClass.GetProperties.
                 * compProps.glow = newcolor;
                 * compProps.glowRadius = glowRadius;
                 */
                //myThingComp.Initialize(compProps);
                comp.Props.glowColor  = (burning) ? (new ColorInt(252, 187, 113, 0) * 1.45f) : (new ColorInt(255, 50, 0, 0) * 1.45f);
                comp.Props.glowRadius = (burning) ? 10f : 2f;

                //Tools.Warn(" glow rad:" + comp.Props.glowRadius, true);
                comp.Initialize(comp.Props);
                comp.UpdateLit(map);
                map.glowGrid.RegisterGlower(comp);
                comp.UpdateLit(map);
            }
            else
            {
                Tools.Warn("should have found a CompGlower but no CompGlower found", true);
            }
        }
Exemplo n.º 15
0
        public void UnsetGlow(Map forcedMap = null)
        {
            if (glowComp == null)
            {
                if (MyDebug)
                {
                    Log.Warning("cant unset null glow");
                }
                return;
            }
            Map myMap;

            if (forcedMap != null)
            {
                myMap = parent.Map;
                if (myMap == null)
                {
                    if (MyDebug)
                    {
                        Log.Warning("cant unset null map glow");
                    }
                    return;
                }
            }
            else
            {
                myMap = forcedMap;
            }

            // removing old glow
            parent.AllComps.Remove(glowComp);
            myMap.glowGrid.DeRegisterGlower(glowComp);

            glowComp = null;
        }
        private void FindNearbyGlowers(CellRect rect)
        {
            Map map = BaseGen.globalSettings.map;

            nearbyGlowers.Clear();
            rect = rect.ExpandedBy(4);
            rect = rect.ClipInsideMap(map);
            foreach (IntVec3 item in rect)
            {
                Region region = item.GetRegion(map);
                if (region == null || !region.Room.PsychologicallyOutdoors)
                {
                    continue;
                }
                List <Thing> thingList = item.GetThingList(map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    CompGlower compGlower = thingList[i].TryGetComp <CompGlower>();
                    if (compGlower != null)
                    {
                        nearbyGlowers.Add(compGlower);
                    }
                }
            }
        }
Exemplo n.º 17
0
        private void SetGlow(ColorInt glowColor, float glowRadius)
        {
            // new glower
            CompGlower myThingComp = new CompGlower();

            myThingComp.parent = parent;
            CompProperties_Glower compProps = new CompProperties_Glower
            {
                // setting props
                glowColor  = glowColor,
                glowRadius = glowRadius
            };

            // init
            myThingComp.Initialize(compProps);

            // applying to map
            Map     myMap = parent.Map;
            IntVec3 myPos = parent.Position;

            myMap.mapDrawer.MapMeshDirty(myPos, MapMeshFlag.Things);
            myMap.glowGrid.RegisterGlower(myThingComp);

            // removing old glow
            // AZAAAAARG
            UnsetGlow();

            // remembering what you did last summer
            glowComp = myThingComp;
        }
Exemplo n.º 18
0
 public override void SpawnSetup()
 {
     base.SpawnSetup();
     power          = base.GetComp <CompPowerTrader>();
     glower         = base.GetComp <CompGlower>();
     powerOutputInt = power.powerOutputInt;
 }
Exemplo n.º 19
0
 public override void SpawnSetup()
 {
     base.SpawnSetup();
     this.Glower = base.GetComp<CompGlower>();
     this.powerComp = base.GetComp<CompPowerTrader>();
     ChangeColour(this.green);
     CurrentColour = this.green;
 }
Exemplo n.º 20
0
        // ===================== Setup Work =====================
        /// <summary>
        /// Initialize instance variables.
        /// </summary>
        ///
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);

            randomTickOffset = Rand.Range(0, GenTicks.TicksPerRealSecond);
            this.glowerComp  = this.GetComp <CompGlower>();
            this.powerComp   = this.GetComp <CompPowerTrader>();
        }
Exemplo n.º 21
0
        public override void SpawnSetup()
        {
            base.SpawnSetup();

            this.powerComp             = base.GetComp <CompPowerTrader>();
            this.glowerComp            = base.GetComp <CompGlower>();
            this.powerComp.powerOutput = 0;
        }
 public void RemoveGlower()
 {
     if (this.compGlower != null)
     {
         base.parent.Map.glowGrid.DeRegisterGlower(this.compGlower);
         this.compGlower = null;
     }
 }
 public void RemoveGlower(Map map)
 {
     if (this.compGlower != null)
     {
         map.glowGrid?.DeRegisterGlower(this.compGlower);
         this.compGlower = null;
     }
 }
        private void StopFireLaser()
        {
            beam.IsActive = false;
            soundSustainer?.End();

            // Turn off glow.
            CompGlower?.ReceiveCompSignal("PowerTurnedOn");
        }
Exemplo n.º 25
0
 public override void SpawnSetup()
 {
     base.SpawnSetup();
     this.Glower    = base.GetComp <CompGlower>();
     this.powerComp = base.GetComp <CompPowerTrader>();
     ChangeColour(this.green);
     CurrentColour = this.green;
 }
Exemplo n.º 26
0
 public static void Prefix(string signal, CompGlower __instance)
 {
     // should react to gas on/off signals
     if (signal == CompGasTrader.Signal_GasOn || signal == CompGasTrader.Signal_GasOff)
     {
         __instance.UpdateLit(__instance.parent.Map);
     }
 }
 public Dialog_FloatColorPicker(CompGlower compGlower)
 {
     this.CompGlower            = compGlower;
     this.layer                 = WindowLayer.Super;
     this.closeOnClickedOutside = true;
     this.doWindowBackground    = false;
     this.drawShadow            = false;
 }
        public override void                PostSpawnSetup()
        {
            base.PostSpawnSetup();

            // Get the default glower
            CompGlower = parent.TryGetComp <CompGlower>();
#if DEBUG
            if (CompGlower == null)
            {
                CCL_Log.TraceMod(
                    parent.def,
                    Verbosity.FatalErrors,
                    "Missing CompGlower"
                    );
                return;
            }
#endif

            // Get the color properties
            ColorProps = this.CompProperties_ColoredLight();
#if DEBUG
            if (ColorProps == null)
            {
                CCL_Log.TraceMod(
                    parent.def,
                    Verbosity.FatalErrors,
                    "Missing CompProperties_ColoredLight"
                    );
                return;
            }
#endif

            // Set default palette if none is specified
            if (ColorProps.color == null)
            {
                ColorProps.color = Light.Color;
            }

            // Set default
            if ((ColorIndex < 0) ||
                (ColorIndex >= ColorProps.color.Count))
            {
                ColorIndex = ColorProps.Default;
            }

            // Get the glow radius
            lightRadius = CompGlower.Props.glowRadius;

            // Set the light color
            if (ColorProps.useColorPicker)
            {
                ChangeColor(Color, false);
            }
            else
            {
                ChangeColor(ColorIndex);
            }
        }
Exemplo n.º 29
0
 public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish)
 {
     base.DeSpawn(mode);
     heatPusherComp    = null;
     flickableComp     = null;
     glowerComp        = null;
     refuelableComp    = null;
     breakdownableComp = null;
 }
        /// <summary>
        /// Find the PowerComp and GlowerComp
        /// </summary>
        private void SetPowerGlower()
        {
            // Get refferences to the components CompPowerTrader and CompGlower
            powerComp  = base.GetComp <CompPowerTrader>();
            glowerComp = base.GetComp <CompGlower>();

            // Preset the PowerOutput to 0 (negative values will draw power from the powernet)
            powerComp.PowerOutput = 0;
        }
Exemplo n.º 31
0
 public override void SpawnSetup(Map map, bool bla)
 {
     base.SpawnSetup(map, bla);
     heatPusherComp    = base.GetComp <CompHeatPusher>();
     flickableComp     = base.GetComp <CompFlickable>();
     glowerComp        = base.GetComp <CompGlower>();
     refuelableComp    = base.GetComp <CompRefuelable>();
     breakdownableComp = base.GetComp <CompBreakdownable>();
 }
Exemplo n.º 32
0
 public override void PostInitialize()
 {
     this.glower           = new CompGlower();
     this.hediffActionRate = 10;
     gProps.glowColor      = glowColor;
     gProps.glowRadius     = 1.4f;
     glower.parent         = this.Pawn;
     glower.Initialize(gProps);
 }
        public override void SpawnSetup()
        {
            base.SpawnSetup();
            vecNorth = Position + IntVec3.North.RotatedBy( Rotation );

            glower = GenSpawn.Spawn( ThingDef.Named( "RedistHeat_HeaterGlower" ), vecNorth );
            compGlower = glower.TryGetComp< CompGlower >();
            compGlower.Lit = false;
        }
        // ===================== Setup Work =====================
        /// <summary>
        /// Initializes instance variables.
        /// </summary>
        /// 
        public override void SpawnSetup()
        {
            base.SpawnSetup();

            numberOfAlertSpeakers++;
            glowerComp = base.GetComp<CompGlower>();
            powerComp = base.GetComp<CompPowerTrader>();

            sirenSoundEnabledIcon = ContentFinder<Texture2D>.Get("Ui/Commands/CommandButton_SirenSoundEnabled");
            sirenSoundDisabledIcon = ContentFinder<Texture2D>.Get("Ui/Commands/CommandButton_SirenSoundDisabled");
        }
Exemplo n.º 35
0
        //provides a new Compglower
        public static CompGlower newCompGlower(ThingWithComps parent, ColorInt glowColour, float glowRadius)
        {
            CompGlower Comp_NewGlower = new CompGlower();
            Comp_NewGlower.parent = parent;


            CompProperties CompProp_New = new CompProperties();
            CompProp_New.compClass = typeof(CompGlower);
            CompProp_New.glowColor = glowColour;
            CompProp_New.glowRadius = glowRadius;

            Comp_NewGlower.Initialize(CompProp_New);

            return Comp_NewGlower;
        }
Exemplo n.º 36
0
 public override void SpawnSetup()
 {
     base.SpawnSetup();
     power = base.GetComp<CompPowerTrader>();
     glower = base.GetComp<CompGlower>();
     powerOutputInt = power.powerOutputInt;
 }
 public override void SpawnSetup()
 {
     base.SpawnSetup();
     glowerComp = base.GetComp<CompGlower>();
     glowerComp.Lit = true;
 }
Exemplo n.º 38
0
 public override void SpawnSetup()
 {
     base.SpawnSetup();
     powerComp = base.GetComp<CompPowerTrader>();
     glowerComp = base.GetComp<CompGlower>();
     LampDetect();
 }
Exemplo n.º 39
0
        public override void PostSpawnSetup()
        {
            base.PostSpawnSetup();

            // Get the default glower
            CompGlower = parent.TryGetComp< CompGlower >();
            #if DEBUG
            if( CompGlower == null )
            {
                CCL_Log.TraceMod(
                    parent.def,
                    Verbosity.FatalErrors,
                    "Missing CompGlower"
                );
                return;
            }
            #endif

            // Get the color properties
            ColorProps = this.CompProperties_ColoredLight();
            #if DEBUG
            if( ColorProps == null )
            {
                CCL_Log.TraceMod(
                    parent.def,
                    Verbosity.FatalErrors,
                    "Missing CompProperties_ColoredLight"
                );
                return;
            }
            #endif

            // Set default palette if none is specified
            if( ColorProps.color == null )
            {
                ColorProps.color = Light.Color;
            }

            // Set default
            if( ( ColorIndex < 0 )||
                ( ColorIndex >= ColorProps.color.Count ) )
            {
                ColorIndex = ColorProps.Default;
            }

            // Get the glow radius
            lightRadius = CompGlower.Props.glowRadius;

            // Set the light color
            if ( ColorProps.useColorPicker )
            {
                ChangeColor( Color, false );
            }
            else
            {
                ChangeColor( ColorIndex );
            }
        }
        public override void PostSpawnSetup()
        {
            //Log.Message( parent.def.defName + " - PostSpawnSetup()" );
            base.PostSpawnSetup();

            // Get this building
            thisBuilding = (Building)parent;
            if( thisBuilding == null ) {
                Log.Message( "Community Core Library :: CompPowerLowIdleDraw :: Unable to cast '" + parent.def.defName + "' to Building" );
                return;
            }

            // Get the power comp
            compPower = parent.GetComp<CompPowerTrader>();
            if( compPower == null )
            {
                Log.Message( "Community Core Library :: CompPowerLowIdleDraw :: '" + parent.def.defName + "' needs compPowerTrader!" );
                return;
            }

            // Get the idle properties
            if( IdleProps == null )
            {
                Log.Message( "Community Core Library :: CompPowerLowIdleDraw :: '" + parent.def.defName + "' unable to get properties of CompProperties_LowIdleDraw!" );
                return;
            }

            // Get the glower (optional)
            compGlower = parent.GetComp<CompGlower>();

            // Generate the list of cells to check
            BuildScanList();

            // Calculate low-power mode consumption
            idlePower = IdleProps.idlePowerFactor * -compPower.props.basePowerConsumption;
            if( idlePower > minIdleDraw )
                idlePower = minIdleDraw;
            //Log.Message( parent.def.defName + " - " + idlePower + " - " + compPower.props.basePowerConsumption + " - " + IdleProps.idlePowerFactor );

            // Initial state...

            if( curPower > idlePower ){
                // ...Default off...
                curPower = idlePower;
            }

            // Set power usage
            compPower.PowerOutput = curPower;
        }
Exemplo n.º 41
0
 public override void SpawnSetup()
 {
     base.SpawnSetup();
     hopperUserComp = this.TryGetComp<CompHopperUser>();
     glowerComp = this.TryGetComp<CompGlower>();
 }
        public override void PostSpawnSetup()
        {
            //Log.Message( def.defName + " - SpawnSetup()" );
            base.PostSpawnSetup();

            // Get power comp
            compPower = parent.GetComp<CompPowerTrader>();
            if( compPower == null ){
                Log.Message( parent.def.defName + " - Needs compPowerTrader!" );
                return;
            }

            // Get the default glower
            oldGlower = parent.GetComp<CompGlower>();
            if( oldGlower == null )
            {
                Log.Message( parent.def.defName + " - Needs compGlower!" );
                return;
            }

            // Get the colour palette
            if( compProps == null )
            {
                Log.Message( parent.def.defName + " - Needs CompProperties_ColoredLight!" );
                return;
            }

            // Set default palette if none is specified
            if( compProps.color == null )
                compProps.color = Light.Color;

            // Set default
            if( ( ColorIndex < 0 )||
                ( ColorIndex >= compProps.color.Count ) )
                ColorIndex = compProps.Default;

            // Get the glow radius
            lightRadius = oldGlower.props.glowRadius;

            // Set the light colour
            changeColor( ColorIndex );
        }
        public void changeColor( int index )
        {
            ColorInt colour = compProps.color[ index ].value;
            ColorIndex = index;
            GizmoChangeColor.defaultDesc = GizmoChangeColor.Desc;

            // Current lit state from base compGlower
            bool wasLit = oldGlower.Lit;

            // Turn off old glower
            oldGlower.Lit = false;

            // Turn off replaced glower
            if( compGlower != null )
            {
                // Current lit state from base replacement compGlower
                wasLit = compGlower.Lit;

                // Turn off replacement compGlower
                compGlower.Lit = false;
            }

            // New glower
            CompGlower newGlower = new CompGlower();
            if( newGlower == null )
            {
                Log.Message( parent.def.defName + " - Unable to create new compGlower!" );
                return;
            }
            newGlower.parent = parent;

            // Glower properties
            CompProperties newProps = new CompProperties();
            if( newProps == null )
            {
                Log.Message( parent.def.defName + " - Unable to create new compProperties!" );
                return;
            }
            newProps.compClass = typeof( CompGlower );
            newProps.glowColor = colour;
            newProps.glowRadius = lightRadius;

            // Add properties to glower
            newGlower.Initialize( newProps );

            // Fetch the comps list
            List<ThingComp> allComps = typeof( ThingWithComps ).GetField( "comps", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ).GetValue( parent ) as List<ThingComp>;
            if( allComps == null )
            {
                Log.Message( parent.def.defName + " - Could not get list of comps!" );
                return;
            }

            // Remove default glower
            allComps.Remove( oldGlower );

            // Remove current glower
            if( compGlower != null )
            {
                allComps.Remove( compGlower );
            }

            // Add new glower
            allComps.Add( newGlower );
            compGlower = newGlower;

            // Store comps list
            typeof( ThingWithComps ).GetField( "comps", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ).SetValue( parent, allComps );

            // Update glow grid
            compGlower.Lit = false;
            Find.GlowGrid.MarkGlowGridDirty( parent.Position );
            Find.MapDrawer.MapMeshDirty( parent.Position, MapMeshFlag.GroundGlow );
            Find.MapDrawer.MapMeshDirty( parent.Position, MapMeshFlag.Things );

            if( ( wasLit )&&( compPower.PowerOn ) )
            {
                // Turn it on if it the old glower was on
                compGlower.Lit = true;
            }
        }
        public void ChangeColor( int index )
        {
            ColorInt colour = ColorProps.color[ index ].value;
            ColorIndex = index;
            GizmoChangeColor.defaultDesc = GizmoChangeColor.Desc;

            var currentGlower = CompGlower;

            // Current lit state from existing glower
            bool wasLit = currentGlower.Lit;

            // Turn off glower
            currentGlower.Lit = false;

            // New glower
            var newGlower = new CompGlower();
            if( newGlower == null )
            {
                Log.Error( "Community Core Library :: CompColoredLight :: " + parent.def.defName + " unable to create new CompGlower!" );
                return;
            }
            newGlower.parent = parent;

            // Glower properties
            var newProps = new CompProperties();
            if( newProps == null )
            {
                Log.Error( "Community Core Library :: CompColoredLight :: " + parent.def.defName + " unable to create new CompProperties!" );
                return;
            }
            newProps.compClass = typeof( CompGlower );
            newProps.glowColor = colour;
            newProps.glowRadius = lightRadius;

            // Add properties to glower
            newGlower.Initialize( newProps );

            // Fetch the comps list
            var allComps = parent.GetComps();
            if( allComps == null )
            {
                Log.Error( "Community Core Library :: CompColoredLight :: " + parent.def.defName + " unable to get list of comps!" );
                return;
            }

            // Remove existing glower
            allComps.Remove( currentGlower );

            // Add new glower
            allComps.Add( newGlower );

            // Store comps list
            parent.SetComps( allComps );

            // Update glow grid
            newGlower.Lit = false;
            Find.GlowGrid.MarkGlowGridDirty( parent.Position );
            Find.MapDrawer.MapMeshDirty( parent.Position, MapMeshFlag.GroundGlow );
            Find.MapDrawer.MapMeshDirty( parent.Position, MapMeshFlag.Things );

            // Turn light on if appropriate
            newGlower.Lit |= ( wasLit ) && ( PowerTrader.PowerOn );
        }
 public Building_AIManager()
 {
     _powerTrader = PowerComp as CompPowerTrader;
     _glower = GetComp<CompGlower>();
 }
 public override void SpawnSetup()
 {
     base.SpawnSetup();
     powerComp = base.GetComp<CompPowerTrader>();
     glowerComp = base.GetComp<CompGlower>();
     glowerComp.Lit = false;
 }