/// <summary>
 ///     For migrating junctions and segments to a new network on merging
 /// </summary>
 /// <param name="oldnetwork"></param>
 /// <param name="newnetwork"></param>
 public void TransferOwnership(FreightTrackNetwork oldnetwork, FreightTrackNetwork newnetwork)
 {
     if (oldnetwork == null || newnetwork == null)
     {
         return;
     }
     //Debug.LogWarning("FTSeg oldnetwork: " + oldnetwork.NetworkID.ToString() + " junction count: " + oldnetwork.TrackJunctions.Count.ToString() + " newnetwork ID: " + newnetwork.NetworkID.ToString() + " junction count: " + newnetwork.TrackJunctions.Count.ToString());
     for (int n = 0; n < oldnetwork.TrackJunctions.Count; n++)
     {
         oldnetwork.TrackJunctions[n].TrackNetwork = newnetwork;
         if (!newnetwork.TrackJunctions.Contains(oldnetwork.TrackJunctions[n]))
         {
             newnetwork.TrackJunctions.Add(oldnetwork.TrackJunctions[n]);
         }
     }
     for (int n = 0; n < oldnetwork.TrackSegments.Count; n++)
     {
         oldnetwork.TrackSegments[n].TrackNetwork = newnetwork;
         //if (!newnetwork.TrackSegments.Contains(oldnetwork.TrackSegments[n]))
         newnetwork.TrackSegments.Add(oldnetwork.TrackSegments[n]);
     }
     newnetwork.ResetJunctionIndices();
     newnetwork.ReassignTourCartStations(oldnetwork);
     oldnetwork.TrackJunctions.Clear();
     oldnetwork.TrackSegments.Clear();
     if (FreightCartManager.instance != null)
     {
         FreightCartManager.instance.GlobalTrackNetworks.Remove(oldnetwork);
     }
     else
     {
         Debug.LogWarning("FreightCartManager is null! Old network couldn't be registered anyway so no network to remove...");
     }
     oldnetwork = null;
 }
    /// <summary>
    ///     Reassigns tour carts to new track network based on connected junctions
    /// </summary>
    /// <param name="original">Track network to transfer the stations from</param>
    public void ReassignTourCartStations(FreightTrackNetwork original)
    {
        if (original == null || original.TourCartStations.Count == 0)
        {
            return;
        }
        List <string> keys  = original.TourCartStations.Keys.ToList();
        int           count = keys.Count;

        for (int n = 0; n < count; n++)
        {
            if (string.IsNullOrEmpty(keys[n]) || !original.TourCartStations.ContainsKey(keys[n]))
            {
                continue;
            }
            TourCartStation station = original.TourCartStations[keys[n]];
            if (station.ClosestJunction == null || station.TrackNetwork == null)
            {
                continue;
            }
            if (station.ClosestJunction.TrackNetwork == this && station.TrackNetwork.TourCartStations.ContainsKey(keys[n]) && !this.TourCartStations.ContainsKey(keys[n]))
            {
                station.TrackNetwork.TourCartStations.Remove(keys[n]);
                this.TourCartStations.Add(keys[n], station);
            }
        }
    }
示例#3
0
 public void ResetJunction()
 {
     this.ClearConnections();
     Array.Clear(this.ConnectedJunctions, 0, 4);
     Array.Clear(this.ConnectedSegments, 0, 4);
     Array.Clear(this.SegmentDistances, 0, 4);
     this.TrackNetwork = new FreightTrackNetwork(this);
 }
示例#4
0
    public TrackNetworkStats(int networkindex)
    {
        FreightTrackNetwork network = FreightCartManager.instance.GlobalTrackNetworks[networkindex];

        JunctionCount = network.TrackJunctions.Count;
        NetworkID     = network.NetworkID;
        network.GetNetworkStats(out AssignedCarts, out AvailableCarts, out NetworkClosed);
    }
 public void MergeNetworks(FreightTrackJunction junction1, FreightTrackJunction junction2)
 {
     //Debug.LogWarning("FTSeg junction1 ID: " + junction1.JunctionID.ToString() + " junction2 ID: " + junction2.JunctionID.ToString());
     if (junction1.TrackNetwork != junction2.TrackNetwork)
     {
         //Merge in smaller network into the larger one for efficiency
         FreightTrackNetwork oldnetwork = junction1.TrackNetwork.TrackJunctions.Count > junction2.TrackNetwork.TrackJunctions.Count ? junction2.TrackNetwork : junction1.TrackNetwork;
         FreightTrackNetwork newnetwork = junction1.TrackNetwork.TrackJunctions.Count > junction2.TrackNetwork.TrackJunctions.Count ? junction1.TrackNetwork : junction2.TrackNetwork;
         this.TransferOwnership(oldnetwork, newnetwork);
     }
     this.TrackNetwork = junction1.TrackNetwork;
     this.TrackNetwork.TrackSegments.Add(this);
 }
示例#6
0
    /// <summary>
    ///     Construct a network from a list of junctions (for when a network is found to have been broken)
    ///     Includes only the segments valid for the list of junctions
    /// </summary>
    /// <param name="junctions">List of juctions to build the new network</param>
    public void ReconstructNetwork(List <FreightTrackJunction> junctions)
    {
        if (junctions == null || junctions.Count == 0)
        {
            return;
        }
        FreightTrackNetwork network = new FreightTrackNetwork(junctions[0]);

        for (int n = 0; n < junctions.Count; n++)
        {
            FreightTrackJunction junction = junctions[n];
            for (int m = 0; m < 4; m++)
            {
                FreightTrackSegment trackseg = junction.ConnectedSegments[m];
                if (trackseg == null)
                {
                    continue;
                }
                if (!network.ContainsTrackSegment(trackseg))
                {
                    network.TrackSegments.Add(trackseg);
                    trackseg.TrackNetwork = network;
                }
            }
            lock (JunLock)
            {
                junction.TrackNetwork.TrackJunctions.Remove(junction);
            }
            if (junction.TrackNetwork.TrackJunctions.Count == 0)
            {
                FreightCartManager.instance.GlobalTrackNetworks.Remove(junction.TrackNetwork);
            }
            junction.TrackNetwork = network;
            lock (JunLock)
            {
                if (!network.TrackJunctions.Contains(junction))
                {
                    network.TrackJunctions.Add(junction);
                }
            }
        }
        network.ResetJunctionIndices();
        network.ReassignTourCartStations(this);
        if (!FreightCartManager.instance.GlobalTrackNetworks.Contains(network))
        {
            FreightCartManager.instance.GlobalTrackNetworks.Add(network);
        }
    }
示例#7
0
    public FreightTrackJunction(ModCreateSegmentEntityParameters parameters)
        : base(parameters)
    {
        this.mbNeedsUnityUpdate        = true;
        this.mbNeedsLowFrequencyUpdate = true;
        if (WorldScript.mbIsServer)
        {
            this.JunctionID = GlobalJunctions;
            this.RequestImmediateNetworkUpdate(); //Is this necessary?
        }
        else
        {
            this.JunctionID = -1;
        }
        GlobalJunctions++;

        this.TrackNetwork = new FreightTrackNetwork(this);
    }
 public override void LowFrequencyUpdate()
 {
     if (this.hopper == null)
     {
         this.UpdateAttachedHoppers();
     }
     if (this.ClosestJunction != null && this.TrackNetwork != null && this.ClosestJunction.TrackNetwork != this.TrackNetwork)
     {
         if (this.TrackNetwork.TourCartStations.ContainsKey(this.StationName))
         {
             this.TrackNetwork.TourCartStations.Remove(this.StationName);
         }
         this.TrackNetwork = null;
         this.ClosestJunction.ConnectedSegments[this.JunctionDirection]  = null;
         this.ClosestJunction.ConnectedJunctions[this.JunctionDirection] = null;
         this.ClosestJunction   = null;
         this.JunctionDirection = -1;
     }
 }
    public void NetworkIntegrityCheck(List <FreightTrackJunction> junctions)
    {
        if (junctions == null || junctions[0] == null)
        {
            return;
        }
        FreightTrackNetwork oldnetwork = junctions[0].TrackNetwork;
        int count = junctions.Count;

        if (count < 2)
        {
            return;
        }
        if (count > 4)
        {
            Debug.LogWarning("FreightTrackNetwork NetworkIntegrityCheck tried to check more than 4 junctions at once!?");
            return;
        }
        switch (count)
        {
        case 2:
            this.NetworkIntegrityCheck(junctions[0], junctions[1], null, null);
            break;

        case 3:
            this.NetworkIntegrityCheck(junctions[0], junctions[1], junctions[2], null);
            break;

        case 4:
            this.NetworkIntegrityCheck(junctions[0], junctions[1], junctions[2], junctions[3]);
            break;
        }
        FreightCartManager.instance.GlobalTrackNetworks.Remove(oldnetwork);
        oldnetwork.TrackJunctions.Clear();
        oldnetwork.TrackSegments.Clear();
        oldnetwork = null;
    }
示例#10
0
    private void SpawnTrackNetworks()
    {
        this.manager.SetTitle("Track Systems");
        this.manager.AddButton("allnetworks", "Global Inventory", buttonx2, 0);
        this.manager.AddButton("selnetwork", "Select Network", buttonx3, 0);
        this.manager.AddButton("tracknetworks", "Network Status", buttonx4, 0);
        this.manager.AddButton("viewinventory", "View Inventory", buttonx5, 0);

        int ycursor      = 65;
        int trackiconx   = globalxoffset + 175;
        int trackxoffset = trackiconx + 65;
        int tracklabel   = trackxoffset + 250;
        int stationxicon = trackiconx + 50;
        int stationlabel = stationxicon + 65;
        int cartxicon    = stationxicon + 50;
        int cartlabel    = cartxicon + 65;
        int invxicon     = cartxicon + 50;
        int invlabel     = invxicon + 65;

        int networkcount = FreightCartManager.instance.GlobalTrackNetworks.Count;

        if (networkcount == 0)
        {
            this.manager.AddBigLabel("notracknetworks", "No track networks found...", Color.red, 225, 150);
        }
        else
        {
            string trackicon   = "Track Straight";
            string stationicon = "Minecart Load";
            for (int n = 0; n < networkcount; n++)
            {
                FreightTrackNetwork network = FreightCartManager.instance.GlobalTrackNetworks[n];
                if (network == null)
                {
                    continue;
                }
                int junctioncount = network.TrackJunctions.Count;
                int networkID     = network.NetworkID;
                int assignedcarts;
                int availcarts;
                network.GetNetworkStats(out assignedcarts, out availcarts);

                this.manager.AddIcon("trackicon" + n, trackicon, Color.white, trackiconx, ycursor);
                this.manager.AddBigLabel("trackjunctions" + n, "ID: " + network.NetworkID.ToString() + "   " + junctioncount.ToString() + " Junctions   Carts: ", Color.white, trackxoffset, ycursor);
                this.manager.AddBigLabel("trackcarts" + n, availcarts.ToString() + " / " + assignedcarts.ToString(), availcarts > assignedcarts ? Color.green : availcarts == assignedcarts ? Color.white : Color.red, tracklabel, ycursor);
                ycursor += 60;
                if (this.TrackNetworkDisplay == n)
                {
                    List <FreightCartStation> stations = network.GetNetworkStations();
                    stations = stations.OrderBy(x => x.StationName).ToList();
                    int stationcount = stations.Count;
                    Debug.LogWarning("FSM Station Count: " + stationcount.ToString());
                    for (int m = 0; m < stationcount; m++)
                    {
                        FreightCartStation station = stations[m];
                        int stationavail           = station.AvailableCarts;
                        int stationassigned        = station.AssignedCarts;
                        this.manager.AddIcon("stationicon" + m, stationicon, Color.white, stationxicon, ycursor);
                        this.manager.AddBigLabel("stationnetwork" + m, (!string.IsNullOrEmpty(station.StationName) ? station.StationName : "UNNAMED") + " - " + station.NetworkID, station.StationFull <= 0 ? Color.white : Color.red, stationlabel, ycursor);
                        this.manager.AddBigLabel("stationcarts" + m, "Carts: " + stationavail.ToString() + " / " + stationassigned.ToString(), stationavail > stationassigned ? Color.green : stationavail == stationassigned ? Color.white : Color.red, stationlabel + 350, ycursor);
                        ycursor += 60;
                        if (this.StationDisplay == m)
                        {
                            this.manager.AddButton("addcart", "Add Cart", stationlabel + 475, ycursor - 60);
                            this.manager.AddButton("removecart", "Remove Cart", stationlabel + 475, ycursor - 10);
                            this.CurrentStation = station;


                            List <FreightRegistry> LocalDeficits = new List <FreightRegistry>();
                            List <FreightRegistry> LocalSurplus  = new List <FreightRegistry>();
                            if (station.massStorageCrate != null)
                            {
                                LocalDeficits = FreightCartManager.instance.GetLocalDeficit(station.NetworkID, station.massStorageCrate);
                                LocalSurplus  = FreightCartManager.instance.GetLocalSurplus(station.NetworkID, station.massStorageCrate);
                            }
                            else if (station.HopperInterface != null)
                            {
                                LocalDeficits = this.FreightListingConversion(station.HopperInterface.FreightRequests.OrderByDescending(x => x.Quantity).Take(3).ToList());
                                LocalSurplus  = this.FreightListingConversion(station.HopperInterface.FreightOfferings.OrderByDescending(x => x.Quantity).Take(3).ToList());
                            }
                            else if (station.AttachedInterface != null)
                            {
                                LocalDeficits = this.FreightListingConversion(station.AttachedInterface.FreightRequests.OrderByDescending(x => x.Quantity).Take(3).ToList());
                                LocalSurplus  = this.FreightListingConversion(station.AttachedInterface.FreightOfferings.OrderByDescending(x => x.Quantity).Take(3).ToList());
                            }
                            ycursor -= 20;
                            string str     = "";
                            int    shifter = 1;
                            int    ind2    = 0;
                            if (LocalDeficits.Count <= 0)
                            {
                                this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localdef", "This storage is fully stocked!", Color.white, false, stationlabel, ycursor);
                            }
                            else
                            {
                                this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localdef", "Top requests for this storage:", Color.white, false, stationlabel, ycursor);
                            }
                            ycursor += 20;
                            for (int index = 0; index < LocalDeficits.Count; index++)
                            {
                                if (LocalDeficits[index].Deficit != 0)
                                {
                                    str = (index + 1).ToString() + ") " + LocalDeficits[index].Deficit.ToString("N0") + "x " + ItemManager.GetItemName(LocalDeficits[index].FreightItem) + "\n";
                                    this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localdef" + index, str, Color.white, false, stationlabel, ycursor);
                                    ycursor += 20;
                                }
                                shifter++;
                            }
                            ycursor -= 20 * shifter;
                            if (LocalSurplus.Count <= 0)
                            {
                                this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localsur", "This storage has nothing to offer!", Color.white, false, stationlabel + 250, ycursor);
                            }
                            else
                            {
                                this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localsur", "Top offerings for this storage:", Color.white, false, stationlabel + 250, ycursor);
                            }
                            ycursor += 20;
                            for (int index = 0; index < LocalSurplus.Count; index++)
                            {
                                if (LocalSurplus[index].Surplus != 0)
                                {
                                    str = (index + 1).ToString() + ") " + LocalSurplus[index].Surplus.ToString("N0") + "x " + ItemManager.GetItemName(LocalSurplus[index].FreightItem) + "\n";
                                    this.manager.AddLabel(GenericMachineManager.LabelType.OneLineFullWidth, "localsur" + index, str, Color.white, false, stationlabel + 250, ycursor);
                                    ycursor += 20;
                                }
                                ind2 = index;
                            }
                            if (ind2 > (shifter - 2))
                            {
                                ycursor += 20;
                            }
                            else
                            {
                                ycursor += (shifter - 1 - ind2) * 20 + 20;
                            }

                            int cartcount = station.CartList.Count;
                            for (int p = 0; p < cartcount; p++)
                            {
                                FreightCartMob cart = station.CartList[p];

                                int itemID = ItemEntries.MineCartT1;
                                if (cart.meType == FreightCartMob.eMinecartType.FreightCartMK1)
                                {
                                    itemID = ModManager.mModMappings.ItemsByKey["steveman0.FreightCartMK1"].ItemId;
                                }
                                else if (cart.meType == FreightCartMob.eMinecartType.FreightCart_T1 || cart.meType == FreightCartMob.eMinecartType.OreFreighter_T1)
                                {
                                    itemID = ItemEntries.MineCartT1;
                                }
                                else if (cart.meType == FreightCartMob.eMinecartType.FreightCart_T2 || cart.meType == FreightCartMob.eMinecartType.OreFreighter_T2)
                                {
                                    itemID = ItemEntries.MineCartT2;
                                }
                                else if (cart.meType == FreightCartMob.eMinecartType.FreightCart_T3 || cart.meType == FreightCartMob.eMinecartType.OreFreighter_T3)
                                {
                                    itemID = ItemEntries.MineCartT3;
                                }
                                else if (cart.meType == FreightCartMob.eMinecartType.FreightCart_T4 || cart.meType == FreightCartMob.eMinecartType.OreFreighter_T4)
                                {
                                    itemID = ItemEntries.MineCartT4;
                                }
                                else if (cart.meType == FreightCartMob.eMinecartType.FreightCartTour)
                                {
                                    itemID = ItemEntries.TourCart;
                                }
                                string carticon = ItemManager.GetItemIcon(itemID);

                                this.manager.AddIcon("carticon" + p, carticon, Color.white, cartxicon, ycursor);
                                this.manager.AddBigLabel("cartlabel" + p, "Inventory: " + cart.mnUsedStorage.ToString() + "/" + cart.mnMaxStorage.ToString(), Color.white, cartlabel, ycursor);
                                ycursor += 60;
                                if (p == CartDisplay)
                                {
                                    MachineInventory inv = null;
                                    if (!string.IsNullOrEmpty(station.NetworkID) && cart.LocalInventory.ContainsKey(station.NetworkID))
                                    {
                                        inv = cart.LocalInventory[station.NetworkID];
                                    }
                                    if (inv == null || inv.ItemCount() == 0)
                                    {
                                        this.manager.AddBigLabel("invlabelempty", "No goods from this station", Color.white, invxicon + 15, ycursor);
                                        ycursor += 60;
                                    }
                                    else
                                    {
                                        int invcount = inv.Inventory.Count;
                                        for (int q = 0; q < invcount; q++)
                                        {
                                            ItemBase item    = inv.Inventory[q];
                                            string   invicon = ItemManager.GetItemIcon(item);
                                            this.manager.AddIcon("invicon" + q, invicon, Color.white, invxicon, ycursor);
                                            this.manager.AddBigLabel("invlabel" + q, item.ToString(), Color.white, invlabel, ycursor);
                                            ycursor += 60;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //Insert Tour cart staion listing here
                }
            }
        }
    }