Exemplo n.º 1
0
    public bool IsConnectedToNetworks(ICollection <UtilityNetwork> networks)
    {
        bool flag = false;
        IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(type);

        return(flag || networks.Contains(networkManager.GetNetworkForCell(inputCell)) || networks.Contains(networkManager.GetNetworkForCell(outputCell)));
    }
Exemplo n.º 2
0
        protected override void OnSpawn()
        {
            base.OnSpawn();

            oxygenOutputCell = building.GetUtilityOutputCell();

            int        cell          = Grid.PosToCell(transform.GetPosition());
            CellOffset rotatedOffset = building.GetRotatedOffset(portInfo.offset);

            hydrogenOutputCell = Grid.OffsetCell(cell, rotatedOffset);

            IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(portInfo.conduitType);

            hydrogenOutputItem = new FlowUtilityNetwork.NetworkItem(portInfo.conduitType, Endpoint.Source, hydrogenOutputCell, gameObject);
            networkManager.AddToNetworks(hydrogenOutputCell, hydrogenOutputItem, true);

            WaterAccumulator    = Game.Instance.accumulators.Add("ElementsConsumed", this);
            OxygenAccumulator   = Game.Instance.accumulators.Add("OutputElements", this);
            HydrogenAccumulator = Game.Instance.accumulators.Add("OutputElements", this);

            KBatchedAnimController batchedAnimController = GetComponent <KBatchedAnimController>();

            if (hasMeter)
            {
                meter = new MeterController(batchedAnimController, "U2H_meter_target", "meter", Meter.Offset.Behind, Grid.SceneLayer.NoLayer, new Vector3(-0.4f, 0.5f, -0.1f), "U2H_meter_target", "U2H_meter_tank", "U2H_meter_waterbody", "U2H_meter_level");
            }
            smi.StartSM();
            UpdateMeter();
            Tutorial.Instance.oxygenGenerators.Add(gameObject);
        }
    protected override void OnActivateTool()
    {
        base.OnActivateTool();
        Vector3    cursorPos       = PlayerController.GetCursorPos(KInputManager.GetMousePos());
        GameObject buildingPreview = def.BuildingPreview;
        Vector3    position        = cursorPos;

        Grid.SceneLayer sceneLayer = Grid.SceneLayer.Ore;
        int             gameLayer  = LayerMask.NameToLayer("Place");

        visualizer = GameUtil.KInstantiate(buildingPreview, position, sceneLayer, null, gameLayer);
        KBatchedAnimController component = visualizer.GetComponent <KBatchedAnimController>();

        if ((Object)component != (Object)null)
        {
            component.visibilityType = KAnimControllerBase.VisibilityType.Always;
            component.isMovable      = true;
            component.SetDirty();
        }
        visualizer.SetActive(true);
        Play(visualizer, "None_Place");
        BuildToolHoverTextCard component2 = GetComponent <BuildToolHoverTextCard>();

        component2.currentDef = def;
        ResourceRemainingDisplayScreen.instance.ActivateDisplay(visualizer);
        IHaveUtilityNetworkMgr component3 = def.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>();

        conduitMgr = component3.GetNetworkManager();
    }
    protected override void OnSpawn()
    {
        base.OnSpawn();
        fuel_tag                           = SimHashes.Petroleum.CreateTag();
        fuel_consumer                      = base.gameObject.AddComponent <ConduitConsumer>();
        fuel_consumer.conduitType          = portInfo.conduitType;
        fuel_consumer.consumptionRate      = 10f;
        fuel_consumer.capacityTag          = fuel_tag;
        fuel_consumer.wrongElementResult   = ConduitConsumer.WrongElementResult.Dump;
        fuel_consumer.forceAlwaysSatisfied = true;
        fuel_consumer.capacityKG           = 100f;
        fuel_consumer.useSecondaryInput    = true;
        RequireInputs requireInputs = base.gameObject.AddComponent <RequireInputs>();

        requireInputs.conduitConsumer = fuel_consumer;
        requireInputs.SetRequirements(false, true);
        int        cell          = Grid.PosToCell(base.transform.GetPosition());
        CellOffset rotatedOffset = building.GetRotatedOffset(portInfo.offset);

        secondaryInputCell = Grid.OffsetCell(cell, rotatedOffset);
        IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(portInfo.conduitType);

        flowNetworkItem = new FlowUtilityNetwork.NetworkItem(portInfo.conduitType, Endpoint.Sink, secondaryInputCell, base.gameObject);
        networkManager.AddToNetworks(secondaryInputCell, flowNetworkItem, true);
        fuel_meter = new MeterController(GetComponent <KBatchedAnimController>(), "meter_target_1", "meter_petrol", Meter.Offset.Infront, Grid.SceneLayer.NoLayer, Vector3.zero, "meter_target_1");
        o2_meter   = new MeterController(GetComponent <KBatchedAnimController>(), "meter_target_2", "meter_oxygen", Meter.Offset.Infront, Grid.SceneLayer.NoLayer, Vector3.zero, "meter_target_2");
        base.smi.StartSM();
    }
Exemplo n.º 5
0
        protected override void OnSpawn()
        {
            base.OnSpawn();
            _spawned = true;
            Debug.Log($"[MultiIO] ConduitIO.OnSpawn() -> ConduitType: {ConduitType.ToString()}  CellOffset: {CellOffset.x + "," + CellOffset.y}");
            portCell = GetPortCell();
            MultiIOExtensions.RegisterPort(portCell, this);
            //Register an event listener for any changes to the grid at the location of this port.
            ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[(int)GetConduitObjectLayer()];

            partitionerEntry = GameScenePartitioner.Instance.Add("ConduitIO.OnSpawn", _parent, portCell, layer, delegate
            {
                UpdateConduitExistsStatus();
            });
            //Register this conduit to the relevant network. Allows the network to determine flow direction.
            IUtilityNetworkMgr networkManager = GetNetworkManager();

            _networkItem = new FlowUtilityNetwork.NetworkItem(ConduitType, EndpointType, portCell, _parent);
            networkManager.AddToNetworks(portCell, _networkItem, EndpointType != Endpoint.Conduit);

            if (UseConduitUpdater)
            {
                GetConduitManager().AddConduitUpdater(ConduitTick, FlowPriority);
            }

            UpdateConduitExistsStatus(true);
        }
    protected override void OnCleanUp()
    {
        IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(portInfo.conduitType);

        networkManager.RemoveFromNetworks(secondaryInputCell, flowNetworkItem, true);
        base.OnCleanUp();
    }
    protected override void OnCleanUp()
    {
        IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(portInfo.conduitType);

        networkManager.RemoveFromNetworks(secondaryInput.Cell, secondaryInput, true);
        Conduit.GetFlowManager(portInfo.conduitType).RemoveConduitUpdater(ConduitUpdate);
        base.OnCleanUp();
    }
    public bool IsConnectedToNetworks(ICollection <UtilityNetwork> networks)
    {
        GetCells(out int linked_cell, out int _);
        IUtilityNetworkMgr networkManager = GetNetworkManager();
        UtilityNetwork     networkForCell = networkManager.GetNetworkForCell(linked_cell);

        return(networks.Contains(networkForCell));
    }
Exemplo n.º 9
0
        protected override void OnCleanUp()
        {
            MultiIOExtensions.UnregisterPort(portCell);
            GetConduitManager().RemoveConduitUpdater(ConduitTick);
            GameScenePartitioner.Instance.Free(ref partitionerEntry);
            IUtilityNetworkMgr networkManager = GetNetworkManager();

            networkManager.RemoveFromNetworks(portCell, _networkItem, EndpointType != Endpoint.Conduit);
        }
Exemplo n.º 10
0
        protected override void OnCleanUp()
        {
            IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(this.conduitType);

            networkManager.RemoveFromNetworks(this.utilityCell, this.networkItem, true);

            this.GetConduitManager().RemoveConduitUpdater(new Action <float>(this.ConduitUpdate));
            GameScenePartitioner.Instance.Free(ref this.partitionerEntry);
            base.OnCleanUp();
        }
    protected override void OnCleanUp()
    {
        IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(this.portInfo.conduitType);

        networkManager.RemoveFromNetworks(this.sInputCell, this.itemSInput, true);
        ConduitFlow flowManager = Conduit.GetFlowManager(this.portInfo.conduitType);

        flowManager.RemoveConduitUpdater(this.OnConduitTick);
        base.OnCleanUp();
    }
    public void AddNetworks(ICollection <UtilityNetwork> networks)
    {
        GetCells(out int linked_cell, out int _);
        IUtilityNetworkMgr networkManager = GetNetworkManager();
        UtilityNetwork     networkForCell = networkManager.GetNetworkForCell(linked_cell);

        if (networkForCell != null)
        {
            networks.Add(networkForCell);
        }
    }
    protected override void OnSpawn()
    {
        base.OnSpawn();
        connectionManager = ConnectionManager;
        int cell = Grid.PosToCell(base.transform.GetPosition());

        connectionManager.SetConnections(Connections, cell, isPhysicalBuilding);
        Building component = GetComponent <Building>();

        TileVisualizer.RefreshCell(cell, component.Def.TileLayer, component.Def.ReplacementLayer);
    }
Exemplo n.º 14
0
        protected override void OnCleanUp()
        {
            Tutorial.Instance.oxygenGenerators.Remove(gameObject);
            IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(portInfo.conduitType);

            networkManager.RemoveFromNetworks(hydrogenOutputCell, hydrogenOutputItem, true);

            Game.Instance.accumulators.Remove(WaterAccumulator);
            Game.Instance.accumulators.Remove(OxygenAccumulator);
            Game.Instance.accumulators.Remove(HydrogenAccumulator);

            base.OnCleanUp();
        }
Exemplo n.º 15
0
    protected override void OnCleanUp()
    {
        IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(portInfo.conduitType);

        networkManager.RemoveFromNetworks(filteredCell, itemFilter, true);
        ConduitFlow flowManager = Conduit.GetFlowManager(portInfo.conduitType);

        flowManager.RemoveConduitUpdater(OnConduitTick);
        if (partitionerEntry.IsValid() && (UnityEngine.Object)GameScenePartitioner.Instance != (UnityEngine.Object)null)
        {
            GameScenePartitioner.Instance.Free(ref partitionerEntry);
        }
        base.OnCleanUp();
    }
Exemplo n.º 16
0
    public void AddNetworks(ICollection <UtilityNetwork> networks)
    {
        IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(type);
        UtilityNetwork     networkForCell = networkManager.GetNetworkForCell(inputCell);

        if (networkForCell != null)
        {
            networks.Add(networkForCell);
        }
        networkForCell = networkManager.GetNetworkForCell(outputCell);
        if (networkForCell != null)
        {
            networks.Add(networkForCell);
        }
    }
Exemplo n.º 17
0
        public UtilityVisual(BuildingConfig buildingConfig, int cell)
        {
            Offset = buildingConfig.Offset;
            this.buildingConfig = buildingConfig;
            this.cell           = cell;

            Vector3 positionCBC = Grid.CellToPosCBC(cell, buildingConfig.BuildingDef.SceneLayer);

            Visualizer = GameUtil.KInstantiate(buildingConfig.BuildingDef.BuildingPreview, positionCBC, Grid.SceneLayer.Ore, "BlueprintModUtilityVisualizer", LayerMask.NameToLayer("Place"));
            Visualizer.transform.SetPosition(positionCBC);
            Visualizer.SetActive(true);

            if (Visualizer.GetComponent <Rotatable>() != null)
            {
                Visualizer.GetComponent <Rotatable>().SetOrientation(buildingConfig.Orientation);
            }

            KBatchedAnimController batchedAnimController = Visualizer.GetComponent <KBatchedAnimController>();

            if (batchedAnimController != null)
            {
                IUtilityNetworkMgr utilityNetworkManager = buildingConfig.BuildingDef.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>().GetNetworkManager();

                if (utilityNetworkManager != null)
                {
                    string animation = utilityNetworkManager.GetVisualizerString((UtilityConnections)buildingConfig.Flags) + "_place";

                    if (batchedAnimController.HasAnimation(animation))
                    {
                        batchedAnimController.Play(animation);
                    }
                }

                batchedAnimController.visibilityType = KAnimControllerBase.VisibilityType.Always;
                batchedAnimController.isMovable      = true;
                batchedAnimController.Offset         = buildingConfig.BuildingDef.GetVisualizerOffset() + buildingConfig.BuildingDef.placementPivot;
                batchedAnimController.TintColour     = GetVisualizerColor(cell);

                batchedAnimController.SetLayer(LayerMask.NameToLayer("Place"));
            }

            else
            {
                Visualizer.SetLayerRecursively(LayerMask.NameToLayer("Place"));
            }

            VisualsUtilities.SetVisualizerColor(cell, GetVisualizerColor(cell), Visualizer, buildingConfig);
        }
        protected override void OnSpawn()
        {
            base.OnSpawn();
            this.utilityCell = this.GetInputCell();

            IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(this.conduitType);

            this.networkItem = new FlowUtilityNetwork.NetworkItem(this.conduitType, Endpoint.Sink, this.utilityCell, base.gameObject);
            networkManager.AddToNetworks(this.utilityCell, this.networkItem, true);

            ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[(this.conduitType != ConduitType.Gas) ? 16 : 12];

            this.partitionerEntry = GameScenePartitioner.Instance.Add("ConduitConsumer.OnSpawn", base.gameObject, this.utilityCell, layer, new Action <object>(this.OnConduitConnectionChanged));
            this.GetConduitManager().AddConduitUpdater(new Action <float>(this.ConduitUpdate), ConduitFlowPriority.Default);
            this.OnConduitConnectionChanged(null);
        }
    protected override void OnSpawn()
    {
        base.OnSpawn();
        Building component = GetComponent <Building>();

        inputCell  = component.GetUtilityInputCell();
        outputCell = component.GetUtilityOutputCell();
        int        cell          = Grid.PosToCell(base.transform.GetPosition());
        CellOffset rotatedOffset = component.GetRotatedOffset(portInfo.offset);
        int        cell2         = Grid.OffsetCell(cell, rotatedOffset);

        Conduit.GetFlowManager(portInfo.conduitType).AddConduitUpdater(ConduitUpdate, ConduitFlowPriority.Default);
        IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(portInfo.conduitType);

        secondaryInput = new FlowUtilityNetwork.NetworkItem(portInfo.conduitType, Endpoint.Sink, cell2, base.gameObject);
        networkManager.AddToNetworks(secondaryInput.Cell, secondaryInput, true);
    }
Exemplo n.º 20
0
        protected override void OnSpawn()
        {
            base.OnSpawn();
            Building component = GetComponent <Building>();

            inputCell  = component.GetUtilityInputCell();
            outputCell = component.GetUtilityOutputCell();

            secondaryOutputCell = Grid.OffsetCell(Grid.PosToCell(transform.GetPosition()), component.GetRotatedOffset(SecondaryPort.offset));
            var secondOutput = new FlowUtilityNetwork.NetworkItem(SecondaryPort.conduitType, Endpoint.Source, secondaryOutputCell, gameObject);

            IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(SecondaryPort.conduitType);

            networkManager.AddToNetworks(secondaryOutputCell, (object)secondOutput, true);

            Conduit.GetFlowManager(type).AddConduitUpdater(ConduitUpdate);
        }
Exemplo n.º 21
0
    protected override void OnSpawn()
    {
        base.OnSpawn();
        inputCell  = building.GetUtilityInputCell();
        outputCell = building.GetUtilityOutputCell();
        int        cell          = Grid.PosToCell(base.transform.GetPosition());
        CellOffset rotatedOffset = building.GetRotatedOffset(portInfo.offset);

        filteredCell = Grid.OffsetCell(cell, rotatedOffset);
        IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(portInfo.conduitType);

        itemFilter = new FlowUtilityNetwork.NetworkItem(portInfo.conduitType, Endpoint.Source, filteredCell, base.gameObject);
        networkManager.AddToNetworks(filteredCell, itemFilter, true);
        GetComponent <ConduitConsumer>().isConsuming = false;
        OnFilterChanged(filterable.SelectedTag);
        filterable.onFilterChanged += OnFilterChanged;
        ConduitFlow flowManager = Conduit.GetFlowManager(portInfo.conduitType);

        flowManager.AddConduitUpdater(OnConduitTick, ConduitFlowPriority.Default);
        GetComponent <KSelectable>().SetStatusItem(Db.Get().StatusItemCategories.Main, filterStatusItem, this);
        UpdateConduitExistsStatus();
        UpdateConduitBlockedStatus();
        ScenePartitionerLayer scenePartitionerLayer = null;

        switch (portInfo.conduitType)
        {
        case ConduitType.Gas:
            scenePartitionerLayer = GameScenePartitioner.Instance.gasConduitsLayer;
            break;

        case ConduitType.Liquid:
            scenePartitionerLayer = GameScenePartitioner.Instance.liquidConduitsLayer;
            break;

        case ConduitType.Solid:
            scenePartitionerLayer = GameScenePartitioner.Instance.solidConduitsLayer;
            break;
        }
        if (scenePartitionerLayer != null)
        {
            partitionerEntry = GameScenePartitioner.Instance.Add("ElementFilterConduitExists", base.gameObject, filteredCell, scenePartitionerLayer, delegate
            {
                UpdateConduitExistsStatus();
            });
        }
    }
Exemplo n.º 22
0
        protected override void OnSpawn()
        {
            base.OnSpawn();

            var building = base.GetComponent <Building>();

            this.utilityCell = building.GetCellWithOffset(building.Orientation == Orientation.Neutral ? this.conduitOffset : this.conduitOffsetFlipped);
            IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(this.conduitType);

            this.networkItem = new FlowUtilityNetwork.NetworkItem(this.conduitType, Endpoint.Source, this.utilityCell, base.gameObject);
            networkManager.AddToNetworks(this.utilityCell, this.networkItem, true);

            ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[(this.conduitType != ConduitType.Gas) ? 16 : 12];

            this.partitionerEntry = GameScenePartitioner.Instance.Add("ConduitConsumer.OnSpawn", base.gameObject, this.utilityCell, layer, new Action <object>(this.OnConduitConnectionChanged));
            this.GetConduitManager().AddConduitUpdater(new Action <float>(this.ConduitUpdate), ConduitFlowPriority.Default);
            this.OnConduitConnectionChanged(null);
        }
Exemplo n.º 23
0
        public override bool Success()
        {
            float num = 0f;
            IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(ConduitType.Gas);

            foreach (UtilityNetwork network in networkManager.GetNetworks())
            {
                FlowUtilityNetwork flowUtilityNetwork = network as FlowUtilityNetwork;
                if (flowUtilityNetwork != null)
                {
                    foreach (FlowUtilityNetwork.IItem sink in flowUtilityNetwork.sinks)
                    {
                        Vent component = sink.GameObject.GetComponent <Vent>();
                        if ((Object)component != (Object)null)
                        {
                            num += component.GetVentedMass(element);
                        }
                    }
                }
            }
            return(num >= kilogramsToVent);
        }
Exemplo n.º 24
0
        public override string GetProgress(bool complete)
        {
            float num = 0f;
            IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(ConduitType.Gas);

            foreach (UtilityNetwork network in networkManager.GetNetworks())
            {
                FlowUtilityNetwork flowUtilityNetwork = network as FlowUtilityNetwork;
                if (flowUtilityNetwork != null)
                {
                    foreach (FlowUtilityNetwork.IItem sink in flowUtilityNetwork.sinks)
                    {
                        Vent component = sink.GameObject.GetComponent <Vent>();
                        if ((Object)component != (Object)null)
                        {
                            num += component.GetVentedMass(element);
                        }
                    }
                }
            }
            return(string.Format(COLONY_ACHIEVEMENTS.MISC_REQUIREMENTS.STATUS.VENTED_MASS, GameUtil.GetFormattedMass((!complete) ? num : kilogramsToVent, GameUtil.TimeSlice.None, GameUtil.MetricMassFormat.Kilogram, true, "{0:0.#}"), GameUtil.GetFormattedMass(kilogramsToVent, GameUtil.TimeSlice.None, GameUtil.MetricMassFormat.Kilogram, true, "{0:0.#}")));
        }
Exemplo n.º 25
0
        public void AddNetworks(ICollection <UtilityNetwork> networks)
        {
            IUtilityNetworkMgr networkManager  = Conduit.GetNetworkManager(type);
            UtilityNetwork     networkForCell1 = networkManager.GetNetworkForCell(inputCell);

            if (networkForCell1 != null)
            {
                networks.Add(networkForCell1);
            }
            UtilityNetwork networkForCell2 = networkManager.GetNetworkForCell(outputCell);

            if (networkForCell2 != null)
            {
                networks.Add(networkForCell2);
            }
            UtilityNetwork networkForCell3 = networkManager.GetNetworkForCell(secondaryOutputCell);

            if (networkForCell3 != null)
            {
                networks.Add(networkForCell3);
            }
        }
    protected override void OnSpawn()
    {
        base.OnSpawn();
        //base.smi.StartSM();

        this.inputCell  = this.building.GetUtilityInputCell();
        this.outputCell = this.building.GetUtilityOutputCell();
        int        cell          = Grid.PosToCell(base.transform.GetPosition());
        CellOffset rotatedOffset = this.building.GetRotatedOffset(this.portInfo.offset);

        this.sInputCell = Grid.OffsetCell(cell, rotatedOffset);
        IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(this.portInfo.conduitType);

        this.itemSInput = new FlowUtilityNetwork.NetworkItem(this.portInfo.conduitType, Endpoint.Sink, this.sInputCell, base.gameObject);
        networkManager.AddToNetworks(this.sInputCell, this.itemSInput, true);
        base.GetComponent <ConduitConsumer>().isConsuming = false;
        //this.OnFilterChanged(ElementLoader.FindElementByHash(this.filteredElem).tag);
        //this.filterable.onFilterChanged += this.OnFilterChanged;
        ConduitFlow flowManager = Conduit.GetFlowManager(this.portInfo.conduitType);

        flowManager.AddConduitUpdater(this.OnConduitTick, ConduitFlowPriority.Default);
        //base.GetComponent<KSelectable>().SetStatusItem(Db.Get().StatusItemCategories.Main, ElementFilter.filterStatusItem, this);
    }
Exemplo n.º 27
0
 public static void Prefix(ConduitType conduit_type, int num_cells, IUtilityNetworkMgr network_mgr, ref float max_conduit_mass, float initial_elapsed_time)
 {
     max_conduit_mass = 400;
 }
Exemplo n.º 28
0
 public void AddNetworks(ICollection <UtilityNetwork> networks)
 {
     IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(conduitType);
 }
Exemplo n.º 29
0
 public static void Prefix(ConduitType conduit_type, int num_cells, IUtilityNetworkMgr network_mgr, ref float max_conduit_mass, float initial_elapsed_time)
 {
     max_conduit_mass = DynamicBuildingsState.StateManager.State.liquidandgas;
 }