Esempio n. 1
0
        public override BuildingDef CreateBuildingDef()
        {
            BuildingDef buildingDef = BuildingTemplates.CreateBuildingDef(
                id: ID,
                width: 1,
                height: 2,
                anim: "wireless_receiver_kanim",
                hitpoints: 30,
                construction_time: WirelessPowerConfigChecker.SenderReceiverBuildTime,
                construction_mass: new float[] { WirelessPowerConfigChecker.SenderReceiverMaterialCost },
                construction_materials: WirelessPowerConfigChecker.BuildUsesOnlySteel ? new string[] { "Steel" } : MATERIALS.REFINED_METALS,
                melting_point: 400f,
                build_location_rule: BuildLocationRule.OnFloor,
                decor: TUNING.BUILDINGS.DECOR.PENALTY.TIER1,
                noise: TUNING.NOISE_POLLUTION.NONE,
                temperature_modification_mass_scale: 0.2f
                );

            buildingDef.Floodable                   = false;
            buildingDef.AudioCategory               = "Metal";
            buildingDef.GeneratorWattageRating      = WirelessPowerBattery.CalculateEnergyAfterFalloff(WirelessPowerConfigChecker.DefaultTransfer);
            buildingDef.GeneratorBaseCapacity       = 2 * WirelessPowerConfigChecker.MaxTransfer;
            buildingDef.ExhaustKilowattsWhenActive  = 0.25f;
            buildingDef.SelfHeatKilowattsWhenActive = 0.25f;
            buildingDef.ViewMode          = OverlayModes.Power.ID;
            buildingDef.AudioCategory     = "Metal";
            buildingDef.PowerOutputOffset = new CellOffset(0, 0);
            buildingDef.LogicInputPorts   = LogicOperationalController.CreateSingleInputPortList(new CellOffset(0, 0));
            return(buildingDef);
        }
Esempio n. 2
0
        public bool ChangeBatteryChannel(WirelessPowerBattery battery, int channel)
        {
            if (!this.batteries.ContainsKey(battery))
            {
                return(false);
            }

            int batteryChannel = this.batteries[battery];

            this.batteries[battery]              = channel;
            this.channelCapacity[channel]        = this.channelCapacity.ContainsKey(channel) ? this.channelCapacity[channel] - battery.Capacity : 0f;
            this.channelCapacity[batteryChannel] = this.channelCapacity.ContainsKey(batteryChannel) ? this.channelCapacity[batteryChannel] + battery.Capacity : battery.Capacity;
            this.UpdateOtherOnChannel(batteryChannel);
            return(true);
        }
Esempio n. 3
0
        public bool RegisterBattery(WirelessPowerBattery battery, int channel)
        {
            if (battery == null || channel <= 0)
            {
                return(false);
            }
            if (this.batteries.ContainsKey(battery))
            {
                return(false);
            }

            this.batteries.Add(battery, channel);
            this.channelCapacity[channel] = this.channelCapacity.ContainsKey(channel) ? this.channelCapacity[channel] + battery.Capacity : battery.Capacity;
            this.UpdateOtherOnChannel(channel);
            return(true);
        }
Esempio n. 4
0
        public bool UnregisterBattery(WirelessPowerBattery battery)
        {
            if (!this.batteries.ContainsKey(battery))
            {
                return(false);
            }

            int batteryChannel = this.batteries[battery];

            if (!this.batteries.Remove(battery))
            {
                return(false);
            }

            this.channelCapacity[batteryChannel] = this.channelCapacity.ContainsKey(batteryChannel) ? this.channelCapacity[batteryChannel] - battery.Capacity : 0f;
            this.UpdateOtherOnChannel(batteryChannel);
            return(true);
        }
Esempio n. 5
0
        private static void AddStrings()
        {
            Strings.Add(SideScreenKey + ".TITLE", SideScreenTitleText);
            Strings.Add(ChannelTitleKey + ".NAME", ChannelTitleName);
            Strings.Add(ChannelTitleKey + ".TOOLTIP", ChannelTitleTooltip);
            Strings.Add(JoulesToTransferTitleKey + ".NAME", JoulesToTransferTitleName);
            Strings.Add(JoulesToTransferTitleKey + ".TOOLTIP", JoulesToTransferTitleTooltip);
            Strings.Add(WirelessBatteryThresholdTitleKey + ".NAME", WirelessBatteryThresholdTitleName);
            Strings.Add(WirelessBatteryThresholdTitleKey + ".TOOLTIP", WirelessBatteryThresholdTitleTooltip);
            Strings.Add(InternalBatteryThresholdTitleKey + ".NAME", InternalBatteryThresholdTitleName);
            Strings.Add(InternalBatteryThresholdTitleKey + ".TOOLTIP", InternalBatteryThresholdTitleTooltip);


            Strings.Add(ConnectionStatusKey + ".NAME", ConnectionStatusName);
            Strings.Add(ConnectionStatusKey + ".TOOLTIP", ConnectionStatusTooltip);

            WirelessPowerStrings.ConnectionStatus = (StatusItem)Traverse.Create(Db.Get().BuildingStatusItems).Method("CreateStatusItem", new object[] {
                "WirelessPower.Connection",
                "BUILDING",
                string.Empty,
                StatusItem.IconType.Info,
                NotificationType.Neutral,
                false,
                OverlayModes.Power.ID,
                true,
                129022
            }).GetValue();

            WirelessPowerStrings.ConnectionStatus.resolveStringCallback = (Func <string, object, string>)((str, data) =>
            {
                if ((UnityEngine.Object)data == null || (IWirelessConnecter)data == null)
                {
                    return(str);
                }

                IWirelessConnecter wirelessConnector = (IWirelessConnecter)data;
                bool isConnected = wirelessConnector.IsConnectedToGrid;

                if (str.Contains("{Status}"))
                {
                    str = !isConnected ? str.Replace("{Status}", FormatColour("Offline", StringColour.Red)) : str.Replace("{Status}", FormatColour("Online", StringColour.Green));
                }
                else if (str.Contains("{Explanation}"))
                {
                    if (data is WirelessPowerSender && isConnected)
                    {
                        str = str.Replace("{Explanation}", "Sender is connected to the " + FormatColour("Wireless Power Grid") + ".");
                    }
                    else if (data is WirelessPowerSender)
                    {
                        str = str.Replace("{Explanation}", "Sender is disconnected and non-operational.\n\nBuild a <b>" + FormatColour(WirelessPowerStrings.WirelessPowerBatteryName) + "</b> to make this sender operational.");
                    }
                    else if (data is WirelessPowerReceiver && isConnected)
                    {
                        str = str.Replace("{Explanation}", "Receiver is connected to the " + FormatColour("Wireless Power Grid") + ".");
                    }
                    else if (data is WirelessPowerReceiver)
                    {
                        str = str.Replace("{Explanation}", "Receiver is disconnected and non-operational.\n\nBuild a <b>" + FormatColour(WirelessPowerStrings.WirelessPowerBatteryName) + "</b> to make this receiver operational.");
                    }
                    else if (data is WirelessPowerBattery && isConnected)
                    {
                        str = str.Replace("{Explanation}", "Battery is connected to the " + FormatColour("Wireless Power Grid") + ".");
                    }
                    else if (data is WirelessPowerBattery)
                    {
                        str = str.Replace("{Explanation}", "Battery is disconnected and non-operational.\n\nBuild either a <b>" + FormatColour(WirelessPowerStrings.WirelessPowerReceiverName) + "</b> or <b>" + FormatColour(WirelessPowerStrings.WirelessPowerSenderName) + "</b> to make this battery operational.");
                    }
                }

                return(str);
            });


            Strings.Add(ChannelStatusKey + ".NAME", ChannelStatusName);
            Strings.Add(ChannelStatusKey + ".TOOLTIP", ChannelStatusTooltip);

            WirelessPowerStrings.ChannelStatus = (StatusItem)Traverse.Create(Db.Get().BuildingStatusItems).Method("CreateStatusItem", new object[] {
                "WirelessPower.Channel",
                "BUILDING",
                string.Empty,
                StatusItem.IconType.Info,
                NotificationType.Neutral,
                false,
                OverlayModes.Power.ID,
                true,
                129022
            }).GetValue();

            WirelessPowerStrings.ChannelStatus.resolveStringCallback = (Func <string, object, string>)((str, data) =>
            {
                if ((UnityEngine.Object)data == null || (IWirelessConnecter)data == null)
                {
                    return(str);
                }

                IWirelessConnecter wirelessConnector = (IWirelessConnecter)data;
                int channel = wirelessConnector.Channel;

                if (str.Contains("{Channel}"))
                {
                    str = str.Replace("{Channel}", FormatColour(channel.ToString()));
                }
                else if (str.Contains("{Explanation}"))
                {
                    str = str.Replace("{Explanation}", "This building is currently connected to channel " + FormatColour(channel.ToString()) + " on the " + FormatColour("Wireless Power Grid") + ".");
                }

                return(str);
            });


            Strings.Add(TransferStatusKey + ".NAME", TransferStatusName);
            Strings.Add(TransferStatusKey + ".TOOLTIP", TransferStatusTooltip);

            WirelessPowerStrings.TransferStatus = (StatusItem)Traverse.Create(Db.Get().BuildingStatusItems).Method("CreateStatusItem", new object[] {
                "WirelessPower.Transfer",
                "BUILDING",
                string.Empty,
                StatusItem.IconType.Info,
                NotificationType.Neutral,
                false,
                OverlayModes.Power.ID,
                true,
                129022
            }).GetValue();

            WirelessPowerStrings.TransferStatus.resolveStringCallback = (Func <string, object, string>)((str, data) =>
            {
                if ((UnityEngine.Object)data == null || (IWirelessTransferer)data == null)
                {
                    return(str);
                }

                IWirelessTransferer trans = (IWirelessTransferer)data;

                string setJoules          = GameUtil.GetFormattedWattage(trans.JoulesToTransfer);
                string falloffJoules      = GameUtil.GetFormattedWattage(trans.FalloffJoulesToTransfer);
                string falloffAmount      = !WirelessPowerConfigChecker.UseEnergyFalloff ? FormatColour(falloffJoules, StringColour.Blue) : FormatColour(falloffJoules, StringColour.Blue) + " (" + setJoules + ")";
                string falloffExplanation = !WirelessPowerConfigChecker.UseEnergyFalloff ? "" : ", due to wireless energy falloff,";

                string actualPowerTransfer = trans.IsConnectedToGrid
                                            ? (trans.IsOperational ? FormatColour(falloffJoules, StringColour.Green) : FormatColour("Standby"))
                                            : FormatColour("N/A", StringColour.Red);


                if (data is WirelessPowerSender)
                {
                    if (str.Contains("{Status}"))
                    {
                        str = str.Replace("{Status}", "Sending Power: " + actualPowerTransfer);
                    }
                    else if (str.Contains("{Explanation}") && trans.IsOperational)
                    {
                        str = str.Replace("{Explanation}", "Sender is beaming " + falloffAmount + " of " + FormatColour("Power") + falloffExplanation + " to the " + FormatColour("Wireless Power Grid") + ".");
                    }
                    else if (str.Contains("{Explanation}"))
                    {
                        str = str.Replace("{Explanation}", "Sender is non-operational.\n\nOnce operational: it will send " + falloffAmount + " of " + FormatColour("Power") + falloffExplanation + " from the " + FormatColour("Wireless Power Grid") + ".");
                    }
                }
                else if (data is WirelessPowerReceiver)
                {
                    if (str.Contains("{Status}"))
                    {
                        str = str.Replace("{Status}", "Receiving Power: " + actualPowerTransfer);
                    }
                    else if (data is WirelessPowerReceiver && str.Contains("{Explanation}") && trans.IsOperational)
                    {
                        str = str.Replace("{Explanation}", "Receiver is drawing " + falloffAmount + " of " + FormatColour("Power") + falloffExplanation + " from the " + FormatColour("Wireless Power Grid") + ".");
                    }
                    else if (data is WirelessPowerReceiver && str.Contains("{Explanation}"))
                    {
                        str = str.Replace("{Explanation}", "Receiver is non-operational.\n\nOnce operational: it will draw " + falloffAmount + " of " + FormatColour("Power") + falloffExplanation + " from the " + FormatColour("Wireless Power Grid") + ".");
                    }
                }
                return(str);
            });


            Strings.Add(BatteryCapacityStatusKey + ".NAME", BatteryCapacityStatusName);
            Strings.Add(BatteryCapacityStatusKey + ".TOOLTIP", BatteryCapacityStatusTooltip);

            WirelessPowerStrings.BatteryCapacityStatus = (StatusItem)Traverse.Create(Db.Get().BuildingStatusItems).Method("CreateStatusItem", new object[] {
                "WirelessPower.BatteryCapacity",
                "BUILDING",
                string.Empty,
                StatusItem.IconType.Info,
                NotificationType.Neutral,
                false,
                OverlayModes.Power.ID,
                true,
                129022
            }).GetValue();

            WirelessPowerStrings.BatteryCapacityStatus.resolveStringCallback = (Func <string, object, string>)((str, data) =>
            {
                if ((UnityEngine.Object)data == null || (WirelessPowerBattery)data == null)
                {
                    return(str);
                }

                WirelessPowerBattery bat = (WirelessPowerBattery)data;

                str = str.Replace("{Available}", GameUtil.GetFormattedJoules(bat.JoulesAvailable));
                if (str.Contains("{Percentage}"))
                {
                    str = str.Replace("{Capacity}", GameUtil.GetFormattedJoules(bat.Capacity)).Replace("{Percentage}", "(" + Util.FormatWholeNumber(bat.PercentFull * 100) + "%)");
                    str = str.Split(':')[0] + ":" + FormatColour(str.Split(':')[1]);
                }

                return(str);
            });


            Strings.Add(BatteryNetStatusKey + ".NAME", BatteryNetStatusName);
            Strings.Add(BatteryNetStatusKey + ".TOOLTIP", BatteryNetStatusTooltip);

            WirelessPowerStrings.BatteryNetStatus = (StatusItem)Traverse.Create(Db.Get().BuildingStatusItems).Method("CreateStatusItem", new object[] {
                "WirelessPower.BatteryNet",
                "BUILDING",
                string.Empty,
                StatusItem.IconType.Info,
                NotificationType.Neutral,
                false,
                OverlayModes.Power.ID,
                true,
                129022
            }).GetValue();

            WirelessPowerStrings.BatteryNetStatus.resolveStringCallback = (Func <string, object, string>)((str, data) =>
            {
                if ((UnityEngine.Object)data == null || (WirelessPowerBattery)data == null)
                {
                    return(str);
                }

                WirelessPowerBattery bat = (WirelessPowerBattery)data;
                float net = bat.CalculateNetTotal();
                if (str.Contains("{Last}"))
                {
                    str = str.Replace("{Last}", net >= 0f
                        ? FormatColour(" + " + GameUtil.GetFormattedJoules(net), StringColour.Green)
                        : FormatColour(" - " + GameUtil.GetFormattedJoules(Math.Abs(net)), StringColour.Red));
                }
                return(str);
            });


            Strings.Add(GridStatusKey + ".NAME", GridStatusName);
            Strings.Add(GridStatusKey + ".TOOLTIP", GridStatusTooltip);

            WirelessPowerStrings.GridStatus = (StatusItem)Traverse.Create(Db.Get().BuildingStatusItems).Method("CreateStatusItem", new object[] {
                "WirelessPower.GridStatus",
                "BUILDING",
                string.Empty,
                StatusItem.IconType.Info,
                NotificationType.Neutral,
                false,
                OverlayModes.Power.ID,
                true,
                129022
            }).GetValue();

            WirelessPowerStrings.GridStatus.resolveStringCallback = (Func <string, object, string>)((str, data) =>
            {
                if ((UnityEngine.Object)data == null || (WirelessPowerBattery)data == null)
                {
                    return(str);
                }

                WirelessPowerBattery bat = (WirelessPowerBattery)data;

                if (!bat.IsConnectedToGrid)
                {
                    if (str.Contains("{Status}"))
                    {
                        str = str.Replace("{Status}", FormatColour("Offline", StringColour.Red));
                    }
                    else if (str.Contains("{Explanation}"))
                    {
                        str = str.Replace("{Explanation}", FormatColour("Offline", StringColour.Red)).Replace("{End}", "for this battery");
                    }
                }
                else if (bat.LastSent > 0f && bat.LastReceived > 0f)
                {
                    if (str.Contains("{Status}"))
                    {
                        str = str.Replace("{Status}", FormatColour("Sending & Receiving", StringColour.Green));
                    }
                    else if (str.Contains("{Explanation}"))
                    {
                        str = str.Replace("{Explanation}", "both " + FormatColour("Sending & Receiving", StringColour.Green)).Replace("{End}", "energy to/from this battery");
                    }
                }
                else if (bat.LastSent > 0f)
                {
                    if (str.Contains("{Status}"))
                    {
                        str = str.Replace("{Status}", FormatColour("Sending", StringColour.Green));
                    }
                    else if (str.Contains("{Explanation}"))
                    {
                        str = str.Replace("{Explanation}", FormatColour("Sending", StringColour.Green)).Replace("{End}", "energy to this battery");
                    }
                }
                else if (bat.LastReceived > 0f)
                {
                    if (str.Contains("{Status}"))
                    {
                        str = str.Replace("{Status}", FormatColour("Receiving", StringColour.Green));
                    }
                    else if (str.Contains("{Explanation}"))
                    {
                        str = str.Replace("{Explanation}", FormatColour("Receiving", StringColour.Green)).Replace("{End}", "energy from this battery");
                    }
                }
                else
                {
                    if (str.Contains("{Status}"))
                    {
                        str = str.Replace("{Status}", FormatColour("Standby"));
                    }
                    else if (str.Contains("{Explanation}"))
                    {
                        str = str.Replace("{Explanation}", FormatColour("Standby")).Replace("{End}", "for this battery to be needed");
                    }
                }

                return(str);
            });


            Strings.Add(GridCapacityStatusKey + ".NAME", GridCapacityStatusName);
            Strings.Add(GridCapacityStatusKey + ".TOOLTIP", GridCapacityStatusTooltip);

            WirelessPowerStrings.GridCapacityStatus = (StatusItem)Traverse.Create(Db.Get().BuildingStatusItems).Method("CreateStatusItem", new object[] {
                "WirelessPower.GridCapacity",
                "BUILDING",
                string.Empty,
                StatusItem.IconType.Info,
                NotificationType.Neutral,
                false,
                OverlayModes.Power.ID,
                true,
                129022
            }).GetValue();

            WirelessPowerStrings.GridCapacityStatus.resolveStringCallback = (Func <string, object, string>)((str, data) =>
            {
                if ((UnityEngine.Object)data == null || (IWirelessConnecter)data == null || WirelessPowerGrid.Instance == null)
                {
                    return(str);
                }

                IWirelessConnecter wireless = (IWirelessConnecter)data;

                float channelAvailable = WirelessPowerGrid.Instance.GetChannelJoulesAvailable(wireless.Channel);
                float channelCapacity  = WirelessPowerGrid.Instance.GetChannelCapacity(wireless.Channel);

                str = str.Replace("{Available}", GameUtil.GetFormattedJoules(channelAvailable));
                str = str.Replace("{Capacity}", GameUtil.GetFormattedJoules(channelCapacity));
                if (str.Contains("{Percentage}"))
                {
                    str = str.Replace("{Percentage}", "(" + Util.FormatWholeNumber((channelAvailable / channelCapacity) * 100) + "%)");
                    str = str.Split(':')[0] + ":" + FormatColour(str.Split(':')[1]);
                }

                return(str);
            });
        }