Exemplo n.º 1
0
            public static bool Prefix(Wire.WattageRating rating, ref float __result)
            {
                if (rating < Wire.WattageRating.NumRatings)
                {
                    return(true);
                }

                switch (rating.ToExtendedWireWattageRating())
                {
                case WattageRating.Max1MW:
                    __result = 1e6f;
                    break;

                case WattageRating.Max1GW:
                    __result = 1e9f;
                    break;

                case WattageRating.Max5kW:
                    __result = 5e3f;
                    break;

                default:
                    __result = 0;
                    break;
                }

                return(false);
            }
Exemplo n.º 2
0
        static void Postfix(ref float __result, Wire.WattageRating rating)
        {
            switch (rating)
            {
            case Wire.WattageRating.Max500:
                __result = 500f;
                break;

            case Wire.WattageRating.Max1000:
                __result = 1000f;
                break;

            case Wire.WattageRating.Max2000:
                __result = 20000f;
                break;

            case Wire.WattageRating.Max20000:
                __result = 20000f;
                break;

            case Wire.WattageRating.Max50000:
                __result = 100000f;
                break;

            default:
                __result = 100000f;
                break;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Triggered when overload occurs on a wire. Updates the result of this requirement if
 /// it is tracking that wire type.
 /// </summary>
 /// <param name="type">The type of wire that overloaded.</param>
 public void CheckOverload(Wire.WattageRating type)
 {
     if (this.type == type)
     {
         overloaded = true;
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Triggered when a wire overloads.
        /// </summary>
        /// <param name="rating">The rating of the overloaded wire.</param>
        public static void OnOverload(Wire.WattageRating rating)
        {
            var asc = Instance;

            if (asc != null)
            {
                foreach (var requirement in asc.overloadRequirements)
                {
                    requirement.CheckOverload(rating);
                }
            }
        }
 public float GetMaxSafeWattage()
 {
     for (int i = 0; i < wireGroups.Length; i++)
     {
         List <Wire> list = wireGroups[i];
         if (list != null && list.Count > 0)
         {
             Wire.WattageRating rating = (Wire.WattageRating)i;
             return(Wire.GetMaxWattageAsFloat(rating));
         }
     }
     return(0f);
 }
    public override void AddItem(int cell, object item)
    {
        Wire wire = (Wire)item;

        Wire.WattageRating maxWattageRating = wire.MaxWattageRating;
        List <Wire>        list             = wireGroups[(int)maxWattageRating];

        if (list == null)
        {
            list = new List <Wire>();
            wireGroups[(int)maxWattageRating] = list;
        }
        list.Add(wire);
        timeOverloaded = Mathf.Max(timeOverloaded, wire.circuitOverloadTime);
    }
Exemplo n.º 7
0
        static void Postfix(BaseWireConfig __instance, Wire.WattageRating rating, GameObject go)
        {
            Wire component = go.GetComponent <Wire>();

            switch (rating)
            {
            case Wire.WattageRating.Max500:
                break;

            case Wire.WattageRating.Max1000:
                break;

            case Wire.WattageRating.Max2000:
                break;

            case Wire.WattageRating.Max20000:
                break;

            case Wire.WattageRating.Max50000:
                break;

            default:
                rating = Wire.WattageRating.Max50000;
                break;
            }

            component.MaxWattageRating = rating;
            float      maxWattageAsFloat = Wire.GetMaxWattageAsFloat(rating);
            Descriptor item = default(Descriptor);

            item.SetupDescriptor(
                string.Format(UI.BUILDINGEFFECTS.MAX_WATTAGE,
                              GameUtil.GetFormattedWattage(maxWattageAsFloat, GameUtil.WattageFormatterUnit.Automatic)),
                string.Format(UI.BUILDINGEFFECTS.TOOLTIPS.MAX_WATTAGE, new object[0]),
                Descriptor.DescriptorType.Effect);
            Building    component2 = go.GetComponent <Building>();
            BuildingDef def        = component2.Def;

            if (def.EffectDescription == null)
            {
                def.EffectDescription = new List <Descriptor>();
            }

            def.EffectDescription.Add(item);
        }
Exemplo n.º 8
0
    protected void DoPostConfigureComplete(Wire.WattageRating rating, GameObject go)
    {
        Wire component = go.GetComponent <Wire>();

        component.MaxWattageRating = rating;
        float      maxWattageAsFloat = Wire.GetMaxWattageAsFloat(rating);
        Descriptor item = default(Descriptor);

        item.SetupDescriptor(string.Format(UI.BUILDINGEFFECTS.MAX_WATTAGE, GameUtil.GetFormattedWattage(maxWattageAsFloat, GameUtil.WattageFormatterUnit.Automatic)), string.Format(UI.BUILDINGEFFECTS.TOOLTIPS.MAX_WATTAGE), Descriptor.DescriptorType.Effect);
        Building    component2 = go.GetComponent <Building>();
        BuildingDef def        = component2.Def;

        if (def.EffectDescription == null)
        {
            def.EffectDescription = new List <Descriptor>();
        }
        def.EffectDescription.Add(item);
    }
Exemplo n.º 9
0
        private static void Postfix(Wire.WattageRating rating, ref float __result)
        {
            if (CustomizeBuildingsState.StateManager.State.WireSmallWatts == 1000 &&
                CustomizeBuildingsState.StateManager.State.WireRefinedWatts == 2000 &&
                CustomizeBuildingsState.StateManager.State.WireHeavyWatts == 20000 &&
                CustomizeBuildingsState.StateManager.State.WireRefinedHeavyWatts == 50000)
            {
                return;
            }

            switch (rating)
            {
            case Wire.WattageRating.Max500:
                __result = 500f;
                break;

            case Wire.WattageRating.Max1000:
                __result = CustomizeBuildingsState.StateManager.State.WireSmallWatts;
                break;

            case Wire.WattageRating.Max2000:
                __result = CustomizeBuildingsState.StateManager.State.WireRefinedWatts;
                break;

            case Wire.WattageRating.Max20000:
                __result = CustomizeBuildingsState.StateManager.State.WireHeavyWatts;
                break;

            case Wire.WattageRating.Max50000:
                __result = CustomizeBuildingsState.StateManager.State.WireRefinedHeavyWatts;
                break;

            default:
                __result = 0.0f;
                break;
            }
        }
Exemplo n.º 10
0
 public static GameUtil.WattageFormatterUnit GetFormatterUnit(this Wire.WattageRating rating) => rating.ToExtendedWireWattageRating().GetFormatterUnit();
Exemplo n.º 11
0
 public override void Deserialize(IReader reader)
 {
     type       = (Wire.WattageRating)reader.ReadInt32();
     overloaded = false;
 }
Exemplo n.º 12
0
 public static WattageRating ToExtendedWireWattageRating(this Wire.WattageRating rating) => (WattageRating)(int)rating;
Exemplo n.º 13
0
 /// <summary>
 /// Triggered when a wire overloads.
 /// </summary>
 /// <param name="rating">The rating of the overloaded wire.</param>
 public static void OnOverload(Wire.WattageRating rating)
 {
     Trigger(OverloadWire.PREFIX + rating.ToString());
 }
Exemplo n.º 14
0
 /// <summary>
 /// Retrieves the wattage rating of an electrical network, with a slight margin to
 /// avoid overloading on rounding issues.
 /// </summary>
 /// <param name="rating">The wattage rating of the wire.</param>
 /// <returns>The wattage the wire can handle before overloading.</returns>
 private static float GetRoundedMaxWattage(Wire.WattageRating rating)
 {
     return(Wire.GetMaxWattageAsFloat(rating) + 0.4f);
 }
Exemplo n.º 15
0
 public void Deserialize(IReader reader)
 {
     // Needs special case deserialization for save file migration
     type = (Wire.WattageRating)reader.ReadInt32();
 }
Exemplo n.º 16
0
 public OverloadWire(Wire.WattageRating type)
 {
     this.type = type;
 }
Exemplo n.º 17
0
            public static bool Prefix(ElectricalUtilityNetwork __instance, float dt, float watts_used, List <WireUtilityNetworkLink>[] bridgeGroups, ref float ___timeOverloaded, ref GameObject ___targetOverloadedWire, ref Notification ___overloadedNotification, ref float ___timeOverloadNotificationDisplayed, List <Wire>[] ___wireGroups)
            {
                Log.Spam($"UpdateOverloadTime: {___wireGroups.Length}, {bridgeGroups.Length}");

                bool        wattage_rating_exceeded = false;
                List <Wire> overloaded_wires        = null;
                List <WireUtilityNetworkLink> overloaded_bridges = null;

                for (int rating_idx = 0; rating_idx < ___wireGroups.Length; rating_idx++)
                {
                    List <Wire> wires = ___wireGroups[rating_idx];
                    List <WireUtilityNetworkLink> bridges = bridgeGroups[rating_idx];
                    Wire.WattageRating            rating  = (Wire.WattageRating)rating_idx;
                    float max_wattage = Wire.GetMaxWattageAsFloat(rating);
                    if (watts_used > max_wattage && ((bridges != null && bridges.Count > 0) || (wires != null && wires.Count > 0)))
                    {
                        wattage_rating_exceeded = true;
                        overloaded_wires        = wires;
                        overloaded_bridges      = bridges;
                        break;
                    }
                }
                overloaded_wires?.RemoveAll((Wire x) => x == null);
                overloaded_bridges?.RemoveAll((WireUtilityNetworkLink x) => x == null);
                if (wattage_rating_exceeded)
                {
                    ___timeOverloaded += dt;
                    if (!(___timeOverloaded > 6f))
                    {
                        return(false);
                    }
                    ___timeOverloaded = 0f;
                    if (___targetOverloadedWire == null)
                    {
                        if (overloaded_bridges != null && overloaded_bridges.Count > 0)
                        {
                            int random_bridge_idx = Random.Range(0, overloaded_bridges.Count);
                            ___targetOverloadedWire = overloaded_bridges[random_bridge_idx].gameObject;
                        }
                        else if (overloaded_wires != null && overloaded_wires.Count > 0)
                        {
                            int random_wire_idx = Random.Range(0, overloaded_wires.Count);
                            ___targetOverloadedWire = overloaded_wires[random_wire_idx].gameObject;
                        }
                    }
                    if (___targetOverloadedWire != null)
                    {
                        ___targetOverloadedWire.Trigger(-794517298, new BuildingHP.DamageSourceInfo
                        {
                            damage               = 1,
                            source               = STRINGS.BUILDINGS.DAMAGESOURCES.CIRCUIT_OVERLOADED,
                            popString            = STRINGS.UI.GAMEOBJECTEFFECTS.DAMAGE_POPS.CIRCUIT_OVERLOADED,
                            takeDamageEffect     = SpawnFXHashes.BuildingSpark,
                            fullDamageEffectName = "spark_damage_kanim",
                            statusItemID         = Db.Get().BuildingStatusItems.Overloaded.Id
                        });
                    }
                    if (___overloadedNotification == null)
                    {
                        ___timeOverloadNotificationDisplayed = 0f;
                        ___overloadedNotification            = new Notification(STRINGS.MISC.NOTIFICATIONS.CIRCUIT_OVERLOADED.NAME, NotificationType.BadMinor, HashedString.Invalid, null, null, true, 0f, null, null, ___targetOverloadedWire.transform);
                        GameScheduler.Instance.Schedule("Power Tutorial", 2f, delegate
                        {
                            Tutorial.Instance.TutorialMessage(Tutorial.TutorialMessages.TM_Power);
                        });
                        Notifier notifier = Game.Instance.FindOrAdd <Notifier>();
                        notifier.Add(___overloadedNotification);
                    }
                }
                else
                {
                    ___timeOverloaded = Mathf.Max(0f, ___timeOverloaded - dt * 0.95f);
                    ___timeOverloadNotificationDisplayed += dt;
                    if (___timeOverloadNotificationDisplayed > 5f)
                    {
                        Traverse.Create(__instance).Method("RemoveOverloadedNotification").GetValue();
                    }
                }

                return(false);
            }
 public void Rebuild()
 {
     for (int i = 0; i < this.circuitInfo.Count; i++)
     {
         CircuitInfo value = this.circuitInfo[i];
         value.generators.Clear();
         value.consumers.Clear();
         value.batteries.Clear();
         value.inputTransformers.Clear();
         value.outputTransformers.Clear();
         value.minBatteryPercentFull = 1f;
         for (int j = 0; j < value.bridgeGroups.Length; j++)
         {
             value.bridgeGroups[j].Clear();
         }
         this.circuitInfo[i] = value;
     }
     consumersShadow.AddRange(consumers);
     List <IEnergyConsumer> .Enumerator enumerator = consumersShadow.GetEnumerator();
     while (enumerator.MoveNext())
     {
         IEnergyConsumer current   = enumerator.Current;
         int             powerCell = current.PowerCell;
         ushort          circuitID = GetCircuitID(powerCell);
         if (circuitID != 65535)
         {
             Battery battery = current as Battery;
             if ((Object)battery != (Object)null)
             {
                 Operational component = battery.GetComponent <Operational>();
                 if ((Object)component == (Object)null || component.IsOperational)
                 {
                     CircuitInfo      value2           = this.circuitInfo[circuitID];
                     PowerTransformer powerTransformer = battery.powerTransformer;
                     if ((Object)powerTransformer != (Object)null)
                     {
                         value2.inputTransformers.Add(battery);
                     }
                     else
                     {
                         value2.batteries.Add(battery);
                         CircuitInfo circuitInfo = this.circuitInfo[circuitID];
                         value2.minBatteryPercentFull = Mathf.Min(circuitInfo.minBatteryPercentFull, battery.PercentFull);
                     }
                     this.circuitInfo[circuitID] = value2;
                 }
             }
             else
             {
                 CircuitInfo circuitInfo2 = this.circuitInfo[circuitID];
                 circuitInfo2.consumers.Add(current);
             }
         }
     }
     consumersShadow.Clear();
     for (int k = 0; k < this.circuitInfo.Count; k++)
     {
         CircuitInfo circuitInfo3 = this.circuitInfo[k];
         circuitInfo3.consumers.Sort((IEnergyConsumer a, IEnergyConsumer b) => a.WattsNeededWhenActive.CompareTo(b.WattsNeededWhenActive));
     }
     HashSet <Generator> .Enumerator enumerator2 = generators.GetEnumerator();
     while (enumerator2.MoveNext())
     {
         Generator current2   = enumerator2.Current;
         int       powerCell2 = current2.PowerCell;
         ushort    circuitID2 = GetCircuitID(powerCell2);
         if (circuitID2 != 65535)
         {
             if (current2.GetType() == typeof(PowerTransformer))
             {
                 CircuitInfo circuitInfo4 = this.circuitInfo[circuitID2];
                 circuitInfo4.outputTransformers.Add(current2);
             }
             else
             {
                 CircuitInfo circuitInfo5 = this.circuitInfo[circuitID2];
                 circuitInfo5.generators.Add(current2);
             }
         }
     }
     HashSet <WireUtilityNetworkLink> .Enumerator enumerator3 = bridges.GetEnumerator();
     while (enumerator3.MoveNext())
     {
         WireUtilityNetworkLink current3 = enumerator3.Current;
         current3.GetCells(out int linked_cell, out int _);
         ushort circuitID3 = GetCircuitID(linked_cell);
         if (circuitID3 != 65535)
         {
             Wire.WattageRating maxWattageRating = current3.GetMaxWattageRating();
             CircuitInfo        circuitInfo6     = this.circuitInfo[circuitID3];
             circuitInfo6.bridgeGroups[(int)maxWattageRating].Add(current3);
         }
     }
     dirty = false;
 }
    public void UpdateOverloadTime(float dt, float watts_used, List <WireUtilityNetworkLink>[] bridgeGroups)
    {
        bool        flag = false;
        List <Wire> list = null;
        List <WireUtilityNetworkLink> list2 = null;

        for (int i = 0; i < 5; i++)
        {
            List <Wire> list3 = wireGroups[i];
            List <WireUtilityNetworkLink> list4  = bridgeGroups[i];
            Wire.WattageRating            rating = (Wire.WattageRating)i;
            float maxWattageAsFloat = Wire.GetMaxWattageAsFloat(rating);
            if (watts_used > maxWattageAsFloat && ((list4 != null && list4.Count > 0) || (list3 != null && list3.Count > 0)))
            {
                flag  = true;
                list  = list3;
                list2 = list4;
                break;
            }
        }
        list?.RemoveAll((Wire x) => (Object)x == (Object)null);
        list2?.RemoveAll((WireUtilityNetworkLink x) => (Object)x == (Object)null);
        if (flag)
        {
            timeOverloaded += dt;
            if (timeOverloaded > 6f)
            {
                timeOverloaded = 0f;
                if ((Object)targetOverloadedWire == (Object)null)
                {
                    if (list2 != null && list2.Count > 0)
                    {
                        int index = Random.Range(0, list2.Count);
                        targetOverloadedWire = list2[index].gameObject;
                    }
                    else if (list != null && list.Count > 0)
                    {
                        int index2 = Random.Range(0, list.Count);
                        targetOverloadedWire = list[index2].gameObject;
                    }
                }
                if ((Object)targetOverloadedWire != (Object)null)
                {
                    targetOverloadedWire.Trigger(-794517298, new BuildingHP.DamageSourceInfo
                    {
                        damage               = 1,
                        source               = (string)BUILDINGS.DAMAGESOURCES.CIRCUIT_OVERLOADED,
                        popString            = (string)UI.GAMEOBJECTEFFECTS.DAMAGE_POPS.CIRCUIT_OVERLOADED,
                        takeDamageEffect     = SpawnFXHashes.BuildingSpark,
                        fullDamageEffectName = "spark_damage_kanim",
                        statusItemID         = Db.Get().BuildingStatusItems.Overloaded.Id
                    });
                }
                if (overloadedNotification == null)
                {
                    timeOverloadNotificationDisplayed = 0f;
                    string           title     = MISC.NOTIFICATIONS.CIRCUIT_OVERLOADED.NAME;
                    NotificationType type      = NotificationType.BadMinor;
                    HashedString     invalid   = HashedString.Invalid;
                    Transform        transform = targetOverloadedWire.transform;
                    overloadedNotification = new Notification(title, type, invalid, null, null, true, 0f, null, null, transform);
                    Notifier notifier = Game.Instance.FindOrAdd <Notifier>();
                    notifier.Add(overloadedNotification, string.Empty);
                }
            }
        }
        else
        {
            timeOverloaded = Mathf.Max(0f, timeOverloaded - dt * 0.95f);
            timeOverloadNotificationDisplayed += dt;
            if (timeOverloadNotificationDisplayed > 5f)
            {
                RemoveOverloadedNotification();
            }
        }
    }