예제 #1
0
 public StationStats(FreightCartStation station)
 {
     StationName    = station.StationName;
     NetworkID      = station.NetworkID;
     StationFull    = station.StationFull;
     AssignedCarts  = station.AssignedCarts;
     AvailableCarts = station.AvailableCarts;
 }
예제 #2
0
 public void RemoveNetwork(FreightCartStation station, string networkid)
 {
     this.ConnectedStations.Remove(station);
     if (!this.ConnectedStations.Exists(x => x.NetworkID == networkid))
     {
         FreightCartManager.instance.RemoveExtraNetwork(networkid);
     }
 }
예제 #3
0
    //Copy and paste is currently global for all players - one players copy will overwrite the last
    //This may lead to unintuitive results where two players try to copy and paste freight entries
    //In the future I could build a dictionary in FreightCartManager to store the copied freight for each player so they have their own instance that is also network sync'd

    public static void CopyFreight(FreightCartStation source)
    {
        FreightCartManager.instance.CopyFreightEntries(source);
        if (!WorldScript.mbIsServer)
        {
            NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceCopyFreight, null, null, source, 0f);
        }
        FreightCartWindow.networkredraw = true;
    }
예제 #4
0
 public static void ToggleOfferAll(FreightCartStation station, string offerall)
 {
     station.OfferAll = offerall == "All" ? true : false;
     if (!WorldScript.mbIsServer)
     {
         NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceToggleOffer, offerall, null, station, 0f);
     }
     FreightCartWindow.dirty = true;
     station.MarkDirtyDelayed();
 }
예제 #5
0
 public static void ToggleCartTier(FreightCartStation station, int carttier)
 {
     station.CartTier = carttier + 1 <= 5 ? carttier + 1 : 0;
     if (!WorldScript.mbIsServer)
     {
         NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceCartTier, carttier.ToString(), null, station, 0f);
     }
     FreightCartWindow.dirty = true;
     station.MarkDirtyDelayed();
 }
예제 #6
0
 public static void ToggleLoadStatus(FreightCartStation station, string loadwhenfull)
 {
     station.mbWaitForFullLoad = loadwhenfull == "Full" ? true : false;
     if (!WorldScript.mbIsServer)
     {
         NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceToggleLoad, loadwhenfull, null, station, 0f);
     }
     FreightCartWindow.dirty = true;
     station.MarkDirtyDelayed();
 }
예제 #7
0
 public static void SetStationName(FreightCartStation station, string stationname)
 {
     station.StationName = stationname;
     if (!WorldScript.mbIsServer)
     {
         NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceSetName, stationname, null, station, 0f);
     }
     FreightCartWindow.networkredraw = true;
     station.MarkDirtyDelayed();
     station.RequestImmediateNetworkUpdate();
 }
예제 #8
0
 public static void PasteFreight(FreightCartStation destination)
 {
     FreightCartManager.instance.PasteFreightEntries(destination, destination.NetworkID, destination.massStorageCrate);
     if (!WorldScript.mbIsServer)
     {
         NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfacePasteFreight, null, null, destination, 0f);
     }
     FreightCartWindow.networkredraw = true;
     destination.MarkDirtyDelayed();
     destination.RequestImmediateNetworkUpdate();
 }
예제 #9
0
 public static void NameInventory(FreightCartStation station, string inventoryname)
 {
     if (station.ConnectedInventory != null)
     {
         station.ConnectedInventory.Name = inventoryname;
         if (!WorldScript.mbIsServer)
         {
             NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceSetInventoryName, inventoryname, null, station, 0f);
         }
         FreightCartWindow.networkredraw = true;
         station.MarkDirtyDelayed();
         station.RequestImmediateNetworkUpdate();
     }
 }
예제 #10
0
    public void GetNetworkStats(out int assignedcarts, out int availcarts)
    {
        List <FreightCartStation> stations = this.GetNetworkStations();
        int count = stations.Count;

        assignedcarts = 0;
        availcarts    = 0;
        for (int n = 0; n < count; n++)
        {
            FreightCartStation station = stations[n];
            assignedcarts += station.AssignedCarts;
            availcarts    += station.AvailableCarts;
        }
    }
예제 #11
0
 public static void AddRegistry(FreightCartStation station, ItemBase item)
 {
     if (item == null)
     {
         Debug.LogWarning("Freight cart window trying to add registry for null item!");
     }
     FreightCartManager.instance.AddRegistry(station.NetworkID, station.massStorageCrate, item, 0, 0);
     if (!WorldScript.mbIsServer)
     {
         NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceAddReg, null, item, station, 0f);
     }
     FreightCartWindow.networkredraw = true;
     station.MarkDirtyDelayed();
     station.RequestImmediateNetworkUpdate();
 }
예제 #12
0
 public static void SetCartAssignment(FreightCartStation station, int assignedcarts)
 {
     if (assignedcarts < 0)
     {
         return;
     }
     station.AssignedCarts = assignedcarts;
     if (!WorldScript.mbIsServer)
     {
         NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceAssignedCarts, assignedcarts.ToString(), null, station, 0f);
     }
     FreightCartWindow.dirty = true;
     station.MarkDirtyDelayed();
     station.RequestImmediateNetworkUpdate();
 }
예제 #13
0
 public static void SetHopperRequest(FreightCartStation station, int request)
 {
     if (station.HopperInterface == null || request < 0)
     {
         return;
     }
     station.HopperInterface.RequestLimit = request;
     if (!WorldScript.mbIsServer)
     {
         NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceHopperLow, request.ToString(), null, station, 0f);
     }
     FreightCartWindow.dirty = true;
     station.MarkDirtyDelayed();
     station.RequestImmediateNetworkUpdate();
 }
예제 #14
0
 public static void SetHopperOfferItem(FreightCartStation station, ItemBase item)
 {
     if (station.HopperInterface == null)
     {
         return;
     }
     station.HopperInterface.OfferItem = item;
     if (!WorldScript.mbIsServer)
     {
         NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceHopperOffer, null, item, station, 0f);
     }
     FreightCartWindow.networkredraw = true;
     station.MarkDirtyDelayed();
     station.RequestImmediateNetworkUpdate();
 }
예제 #15
0
    public static void SetLowStock(FreightCartStation station, ItemBase item, int stock)
    {
        if (item == null)
        {
            Debug.LogWarning("Freight cart window trying to set low stock for null item!");
        }
        int highstock = FreightCartManager.instance.GetHighStock(station.NetworkID, station.massStorageCrate, item);

        FreightCartManager.instance.UpdateRegistry(station.NetworkID, station.massStorageCrate, item, stock, stock > highstock ? stock : -1);
        if (!WorldScript.mbIsServer)
        {
            NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceSetLowStock, stock.ToString(), item, station, 0f);
        }
        FreightCartWindow.dirty = true;
        station.MarkDirtyDelayed();
        station.RequestImmediateNetworkUpdate();
    }
예제 #16
0
    public List <FreightCartStation> GetNetworkStations()
    {
        List <FreightCartStation> stations = new List <FreightCartStation>();
        int count = this.TrackSegments.Count;

        for (int n = 0; n < count; n++)
        {
            int stationcount = this.TrackSegments[n].Stations.Count;
            for (int m = 0; m < stationcount; m++)
            {
                FreightCartStation station = this.TrackSegments[n].Stations[m];
                if (!stations.Contains(station))
                {
                    stations.Add(station);
                }
            }
        }
        return(stations);
    }
예제 #17
0
    public override void HandleItemDrag(string name, ItemBase draggedItem, DragAndDropManager.DragRemoveItem dragDelegate, SegmentEntity targetEntity)
    {
        FreightCartStation station = targetEntity as FreightCartStation;

        if (station.massStorageCrate == null)
        {
            return;
        }

        if (name.Contains("registry")) // drag drop to a slot
        {
            int slotNum = -1;
            int.TryParse(name.Replace("registry", ""), out slotNum); //Get slot name as number

            if (slotNum == -1)                                       // valid slot
            {
                if (this.manager.mWindowLookup[name + "_icon"].GetComponent <UISprite>().spriteName == "empty")
                {
                    FreightCartWindow.AddRegistry(station, draggedItem);
                }
            }
        }
        else if (name == "hopitemoffer")
        {
            if (this.manager.mWindowLookup["hopitemoffer"].GetComponent <UISprite>().spriteName == "empty")
            {
                FreightCartWindow.SetHopperOfferItem(station, draggedItem);
            }
        }
        else if (name == "hopitemrequest")
        {
            if (this.manager.mWindowLookup["hopitemrequest"].GetComponent <UISprite>().spriteName == "empty")
            {
                FreightCartWindow.SetHopperRequestItem(station, draggedItem);
            }
        }

        return;
    }
예제 #18
0
    public static void SetNetwork(FreightCartStation station, string networkid)
    {
        string oldid = station.NetworkID;

        if (!string.IsNullOrEmpty(networkid))
        {
            if (!string.IsNullOrEmpty(oldid))
            {
                FreightCartManager.instance.RemoveStationReg(station);
            }
            station.NetworkID = networkid;
            FreightCartManager.instance.TryRegisterStation(station);
        }
        FreightCartManager.instance.AddNetwork(station.NetworkID);
        if (!WorldScript.mbIsServer)
        {
            NetworkManager.instance.SendInterfaceCommand(InterfaceName, InterfaceSetNetwork, networkid, null, station, 0f);
        }
        FreightCartWindow.networkredraw = true;
        station.MarkDirtyDelayed();
        station.RequestImmediateNetworkUpdate();
    }
예제 #19
0
    private void GetStationGoods(FreightCartStation 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());
        }
        this.StationDeficits = LocalDeficits;
        this.StationSurplus  = LocalSurplus;
    }
예제 #20
0
 public HopperFreightContainer(StorageMachineInterface machine, FreightCartStation station)
 {
     this.Machine = machine;
     this.Station = station;
 }
예제 #21
0
    /// <summary>
    ///     Follows a track segment to find all containing stations until it reaches another junction or determines track is invalid
    /// </summary>
    /// <param name="direction">0 - 3 representing the four directions out of the junction</param>
    /// <returns>True if it found complete segment</returns>
    public bool TrackFollow(int direction)
    {
        //Initialize the check from the junction
        long    nextX  = this.mnX;
        long    nextY  = this.mnY;
        long    nextZ  = this.mnZ;
        Vector3 dirvec = new Vector3();

        //Store the initial junction direction for later recording which direction the connected junction is associated with
        int initialdirection = direction;

        //List of freight cart stations found on this segment -> to be written to the final constructed FreightTrackSegment
        List <FreightCartStation> SegmentStations = new List <FreightCartStation>();

        //Store visited track pieces for catching when the segment enters a closed loop
        List <TrackPiece> VisitedTracks = new List <TrackPiece>();

        //Add a penalty for pathfinding in certain directions to avoid stations and other undesirable routes
        int PathfindPenalty = 0;

        //Begin loop here.  Direction can be set and used to check the next location each time through the loop
        //Allow segments only up to 2048 long due to cost of loop checking - may revise after testing
        for (int n = 0; n < 2048; n++)
        {
            switch (direction)
            {
            case 0:
                nextX++;
                dirvec = Vector3.right;
                break;

            case 1:
                nextZ++;
                dirvec = Vector3.forward;
                break;

            case 2:
                nextX--;
                dirvec = Vector3.left;
                break;

            case 3:
                nextZ--;
                dirvec = Vector3.back;
                break;

            default:
                nextX++;
                break;
            }

            ushort lValue1 = 0;
            byte   lFlags1 = 0;
            ushort type    = this.GetCube(nextX, nextY, nextZ, out lValue1, out lFlags1);
            this.mUnderSegment = this.mPrevGetSeg;
            //Debug.LogWarning("GetCube type: " + type.ToString() + " value: " + lValue1);
            bool foundslope = false;

            //Found air and need to check for a downward slope under it
            if (type == 1)
            {
                ushort  lValue2 = 0;
                byte    lFlags2 = 0;
                ushort  cube    = this.GetCube(nextX, nextY - 1L, nextZ, out lValue2, out lFlags2);
                Segment segment = this.mPrevGetSeg;
                type    = cube;
                lFlags1 = lFlags2;
                lValue1 = lValue2;
                if ((type == 538 && lValue1 == 2) || (type == ScrapTrackType && lValue1 == ScrapSlopeVal))
                {
                    foundslope = true;
                    nextY--; //decrement Y level for next loop through!
                }
                else
                {
                    if (type == 0)
                    {
                        Debug.LogError("Error, track follower has null under segment!");
                    }
                    if (this.mPrevGetSeg == null)
                    {
                        Debug.LogError("Error, prevseg was null!");
                    }
                    if (segment == null)
                    {
                        Debug.LogError("Error, old was null!");
                    }
                    if (this.mPrevGetSeg != segment)
                    {
                        Debug.LogWarning(("Track follower is looking for a slope, and has had to check across segment boundaries for this![Old/New" + segment.GetName() + " -> " + this.mPrevGetSeg.GetName()));
                    }
                    return(false);
                }
            }

            Vector3 trackvec = SegmentCustomRenderer.GetRotationQuaternion(lFlags1) * Vector3.forward;
            bool    oneway   = false;
            trackvec.Normalize();
            trackvec.x = trackvec.x >= -0.5 ? (trackvec.x <= 0.5 ? 0.0f : 1f) : -1f;
            trackvec.y = trackvec.y >= -0.5 ? (trackvec.y <= 0.5 ? 0.0f : 1f) : -1f;
            trackvec.z = trackvec.z >= -0.5 ? (trackvec.z <= 0.5 ? 0.0f : 1f) : -1f;
            //Begin checking track type
            if (type == TRACKTYPE || type == ScrapTrackType)
            {
                if ((type == TRACKTYPE && (lValue1 == TRACKSTRAIGHT || lValue1 == TRACKEMPTY || lValue1 == TRACKFULL)) || (type == ScrapTrackType && lValue1 == ScrapStraightVal))
                {
                    if (trackvec.y > 0.5 || trackvec.y < -0.5)
                    {
                        return(false);
                    }
                    else if (!(trackvec == dirvec) && !(trackvec == -dirvec))
                    {
                        dirvec = new Vector3(trackvec.x, 0f, trackvec.z);
                        oneway = true; // Can't set return path as the same -> they're different!
                    }
                }
                if ((type == TRACKTYPE && lValue1 == TRACKCORNER) || (type == ScrapTrackType && lValue1 == ScrapCornerVal))
                {
                    if (dirvec == new Vector3(-trackvec.z, 0.0f, trackvec.x))
                    {
                        dirvec = new Vector3(dirvec.z, 0.0f, -dirvec.x);
                    }
                    else if (trackvec == -dirvec)
                    {
                        dirvec = new Vector3(-dirvec.z, 0.0f, dirvec.x);
                    }
                    else
                    {
                        return(false);
                    }
                }
                if ((type == TRACKTYPE && lValue1 == TRACKSLOPE) || (type == ScrapTrackType && lValue1 == ScrapSlopeVal))
                {
                    Vector3 vector3_2 = trackvec;
                    dirvec.y = 0.0f;
                    dirvec.Normalize();
                    if (dirvec == trackvec)
                    {
                        if (foundslope)
                        {
                            return(false);
                        }
                        else
                        {
                            nextY++;
                        }
                    }
                    else if (dirvec == -trackvec)
                    {
                        ;
                    }
                }
                if (type == TRACKTYPE && lValue1 == TRACKBUFFER)
                {
                    dirvec = new Vector3(-dirvec.x, 0f, -dirvec.z);
                }
            }
            //Begin checking special types
            else if (type == CONTROLTYPE)
            {
                if (lValue1 == CONTROLLOAD || lValue1 == CONTROLUNLOAD || lValue1 == CONTROLTURBO)
                {
                    if ((trackvec == dirvec) || (trackvec == -dirvec))
                    {
                        //Do nothing... direction doesn't change
                        //Except turbo... reduce the penalty for this path!
                        if (lValue1 == CONTROLTURBO)
                        {
                            PathfindPenalty--;
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            //Check for freight stations
            else if (type == FREIGHTSTATIONTYPE)
            {
                if ((trackvec == dirvec) || (trackvec == -dirvec))
                {
                    Segment segment = this.AttemptGetSegment(nextX, nextY, nextZ);
                    if (segment == null)
                    {
                        segment = WorldScript.instance.GetSegment(nextX, nextY, nextZ);
                        if (segment == null)
                        {
                            Debug.Log((object)"Track junction track follower did not find segment");
                            return(false);
                        }
                    }
                    FreightCartStation fcs = segment.FetchEntity(eSegmentEntity.Mod, nextX, nextY, nextZ) as FreightCartStation;
                    if (fcs == null)
                    {
                        Debug.LogWarning("Track Junction Track Follower tried to get a freight cart station but got other mod machine instead?");
                        return(false);
                    }
                    if (!SegmentStations.Contains(fcs))
                    {
                        SegmentStations.Add(fcs);
                    }
                    fcs.ClosestJunction   = this;
                    fcs.JunctionDirection = initialdirection;
                    // Penalize this route for multidirection pathfinding due to the station
                    PathfindPenalty += 5;
                }
                else
                {
                    return(false);
                }
            }
            //Is it a junction?
            else if (type == JUNCTIONTYPE)
            {
                //Debug.LogWarning("Track follower success!  Found another junction!");
                Segment segment = this.AttemptGetSegment(nextX, nextY, nextZ);
                if (segment == null)
                {
                    segment = WorldScript.instance.GetSegment(nextX, nextY, nextZ);
                    if (segment == null)
                    {
                        Debug.Log((object)"Track junction track follower did not find segment");
                        return(false);
                    }
                }
                FreightTrackJunction junction = segment.FetchEntity(eSegmentEntity.Mod, nextX, nextY, nextZ) as FreightTrackJunction;
                if (junction == null)
                {
                    Debug.LogWarning("Track Junction Track Follower tried to get a track junction but got other mod machine instead?");
                    return(false);
                }
                this.ConnectedJunctions[initialdirection] = junction;
                //Don't let segment distance be negative just to be safe!  This should rarely happen...
                if (PathfindPenalty < 0 && Math.Abs(PathfindPenalty) > n)
                {
                    PathfindPenalty = -n;
                }
                FreightTrackSegment tracksegment = new FreightTrackSegment(this, junction, n + 1 + PathfindPenalty);
                tracksegment.Stations = SegmentStations;
                //Debug.LogWarning("trackseg station count: " + tracksegment.Stations.Count);
                this.ConnectedSegments[initialdirection] = tracksegment;
                this.SegmentDistances[initialdirection]  = n + 1;
                this.LinkStatusDirty = true;

                //handle the connection for the other junction so we don't need to double the work - only if return path is valid!
                //Mirror the direction to reflect the correct side of the connecting junction
                if (!oneway)
                {
                    int mirroreddir = direction += 2;
                    if (mirroreddir > 3)
                    {
                        mirroreddir -= 4;
                    }
                    junction.ConnectedJunctions[mirroreddir] = this;
                    junction.ConnectedSegments[mirroreddir]  = tracksegment;
                    junction.SegmentDistances[mirroreddir]   = n + 1;
                    junction.LinkStatusDirty = true;
                }
                return(true);
            }
            else if (type == TOURSTATIONTYPE)
            {
                if (trackvec != -dirvec)
                {
                    return(false);
                }
                Segment segment = this.AttemptGetSegment(nextX, nextY, nextZ);
                if (segment == null)
                {
                    segment = WorldScript.instance.GetSegment(nextX, nextY, nextZ);
                    if (segment == null)
                    {
                        Debug.Log((object)"Track junction track follower did not find segment");
                        return(false);
                    }
                }
                TourCartStation station = segment.FetchEntity(eSegmentEntity.Mod, nextX, nextY, nextZ) as TourCartStation;
                station.TrackNetwork      = this.TrackNetwork;
                station.ClosestJunction   = this;
                station.JunctionDirection = initialdirection;
                this.ConnectedJunctions[initialdirection] = this;
                FreightTrackSegment tracksegment = new FreightTrackSegment(this, this, 2 * n + 1);
                this.SegmentDistances[initialdirection]  = 2 * n + 1;
                this.ConnectedSegments[initialdirection] = tracksegment;
                this.LinkStatusDirty = true;
                if (!string.IsNullOrEmpty(station.StationName) && !this.TrackNetwork.TourCartStations.ContainsKey(station.StationName))
                {
                    this.TrackNetwork.TourCartStations.Add(station.StationName, station);
                }
                return(true);
            }
            else
            {
                return(false);   //Not a track type
            }
            //Update the direction int based on the changed direction vector
            if (dirvec == Vector3.right)
            {
                direction = 0;
            }
            else if (dirvec == Vector3.forward)
            {
                direction = 1;
            }
            else if (dirvec == Vector3.left)
            {
                direction = 2;
            }
            else if (dirvec == Vector3.back)
            {
                direction = 3;
            }

            TrackPiece visitedpiece = new TrackPiece(new Vector3(nextX - this.mnX, nextY - this.mnY, nextZ - this.mnZ), direction);
            //Debug.LogWarning("Visited track piece: " + new Vector4(nextX - this.mnX, nextY - mnY, nextZ - mnZ, direction).ToString());
            //Store every track piece and check every 10th for monitoring for closed, endless loops of track
            if (n % 10 == 0)
            {
                int count = VisitedTracks.Count;
                for (int m = 0; m < count; m++)
                {
                    TrackPiece piece = VisitedTracks[m];
                    if (piece.Position == visitedpiece.Position && piece.Direction == visitedpiece.Direction)
                    {
                        //Debug.LogWarning("piece position: " + piece.Position.ToString() + " visited: " + visitedpiece.Position.ToString());
                        Debug.LogWarning("TrackJunction followed track route and found a closed loop.  Ending search.");
                        return(false);
                    }
                }
            }
            VisitedTracks.Add(visitedpiece);
            if (n == 2047)
            {
                Debug.LogWarning("Track Junction Found track length > 2048m -> ending search.");
            }
        }
        return(false);
    }
 public FreightInterfaceContainer(FreightCartStation station, FreightSystemInterface inter)
 {
     this.Station    = station;
     this.Interface  = inter;
     this.Registries = new List <FreightRegistry>();
 }
예제 #23
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
                }
            }
        }
    }
예제 #24
0
    public static NetworkInterfaceResponse HandleNetworkCommand(Player player, NetworkInterfaceCommand nic)
    {
        FreightCartStation station = nic.target as FreightCartStation;

        string command = nic.command;

        if (command != null)
        {
            if (command == InterfaceRemoveReg)
            {
                FreightCartWindow.RemoveRegistry(station, nic.itemContext);
            }
            else if (command == InterfaceSetLowStock)
            {
                int stock = -1;
                int.TryParse(nic.payload ?? "-1", out stock);
                FreightCartWindow.SetLowStock(station, nic.itemContext, stock);
            }
            else if (command == InterfaceSetHighStock)
            {
                int stock = -1;
                int.TryParse(nic.payload ?? "-1", out stock);
                FreightCartWindow.SetHighStock(station, nic.itemContext, stock);
            }
            else if (command == InterfaceAssignedCarts)
            {
                int carts = 0;
                int.TryParse(nic.payload ?? "-1", out carts);
                FreightCartWindow.SetCartAssignment(station, carts);
            }
            else if (command == InterfaceCartTier)
            {
                int carttier = 0;
                int.TryParse(nic.payload ?? "2", out carttier);
                FreightCartWindow.ToggleCartTier(station, carttier);
            }
            else if (command == InterfaceHopperHigh)
            {
                int offer = -1;
                int.TryParse(nic.payload ?? "-1", out offer);
                FreightCartWindow.SetHopperOffer(station, offer);
            }
            else if (command == InterfaceHopperLow)
            {
                int request = -1;
                int.TryParse(nic.payload ?? "-1", out request);
                FreightCartWindow.SetHopperRequest(station, request);
            }
            else if (command == InterfaceToggleLoad)
            {
                FreightCartWindow.ToggleLoadStatus(station, nic.payload);
            }
            else if (command == InterfaceToggleOffer)
            {
                FreightCartWindow.ToggleOfferAll(station, nic.payload);
            }
            else if (command == InterfaceAddReg)
            {
                FreightCartWindow.AddRegistry(station, nic.itemContext);
            }
            else if (command == InterfaceSetNetwork)
            {
                FreightCartWindow.SetNetwork(station, nic.payload);
            }
            else if (command == InterfaceSetName)
            {
                FreightCartWindow.SetStationName(station, nic.payload);
            }
            else if (command == InterfaceSetInventoryName)
            {
                FreightCartWindow.NameInventory(station, nic.payload);
            }
            else if (command == InterfaceCopyFreight)
            {
                FreightCartWindow.CopyFreight(station);
            }
            else if (command == InterfacePasteFreight)
            {
                FreightCartWindow.PasteFreight(station);
            }
            else if (command == InterfaceHopperOffer)
            {
                FreightCartWindow.SetHopperOfferItem(station, nic.itemContext);
            }
            else if (command == InterfaceHopperRequest)
            {
                FreightCartWindow.SetHopperRequestItem(station, nic.itemContext);
            }
        }

        return(new NetworkInterfaceResponse
        {
            entity = station,
            inventory = player.mInventory
        });
    }
예제 #25
0
    public TrackNetworksWrapper(int tracknetwork, int station, int cart)
    {
        // This shouldn't happen but just in case...
        if (FreightCartManager.instance == null)
        {
            return;
        }

        // Track Networks
        this.NetworkCount = FreightCartManager.instance.GlobalTrackNetworks.Count;
        this.NetworkStats = new List <TrackNetworkStats>(this.NetworkCount);
        for (int n = 0; n < this.NetworkCount; n++)
        {
            this.NetworkStats.Add(new TrackNetworkStats(n));
        }

        // Freight Cart Stations
        if (tracknetwork != -1 && tracknetwork < this.NetworkCount)
        {
            List <FreightCartStation> stations = FreightCartManager.instance.GlobalTrackNetworks[tracknetwork].GetNetworkStations();
            stations          = stations.OrderBy(x => x.StationName).ToList();
            this.StationCount = stations.Count;
            this.Stations     = new List <StationStats>(this.StationCount);
            foreach (FreightCartStation sta in stations)
            {
                this.Stations.Add(new StationStats(sta));
            }

            if (station != -1 && station < this.StationCount)
            {
                FreightCartStation Station = stations[station];

                // Station details
                this.GetStationGoods(Station);

                // Carts
                this.CartCount = Station.CartList.Count;
                this.Carts     = new List <CartStats>(this.CartCount);
                foreach (FreightCartMob mob in Station.CartList)
                {
                    this.Carts.Add(new CartStats(mob));
                }

                // Displayed Cart
                if (cart != -1 && cart < this.CartCount)
                {
                    FreightCartMob Cart = Station.CartList[cart];
                    if (!string.IsNullOrEmpty(Station.NetworkID) && Cart.LocalInventory.ContainsKey(Station.NetworkID))
                    {
                        CartInventory = Cart.LocalInventory[Station.NetworkID].Inventory;
                    }
                }
            }
            else
            {
                this.CartCount = 0;
            }
        }
        else
        {
            this.StationCount = 0;
            this.CartCount    = 0;
        }
    }
예제 #26
0
    /// <summary>
    ///     Follows a track segment to find all containing stations until it reaches another junction or determines track is invalid
    /// </summary>
    /// <param name="direction">0 - 3 representing the four directions out of the junction</param>
    /// <returns>True if it found complete segment</returns>
    public bool TrackFollow(int direction)
    {
        //Initialize the check from the junction
        long    nextX    = this.mnX;
        long    nextY    = this.mnY;
        long    nextZ    = this.mnZ;
        Vector3 dirvec   = new Vector3();
        bool    mirrorOk = true;

        //Store the initial junction direction for later recording which direction the connected junction is associated with
        int initialdirection = direction;

        //There are many ways to derail, so set that result now, and assume it later. Saves much repeat of these lines.
        this.DirectionResults [initialdirection]   = FreightTrackDirectionResults.Bad;
        this.ConnectedJunctions [initialdirection] = null;
        this.ConnectedSegments [initialdirection]  = null;

        //List of freight cart stations found on this segment -> to be written to the final constructed FreightTrackSegment
        List <FreightCartStation> SegmentStations = new List <FreightCartStation>();

        //Store visited track pieces for catching when the segment enters a closed loop
        //We're only testing for a unique key here, so no Tvalue will be used.
        StringDictionary VisitedTracks = new StringDictionary();

        //Begin loop here.  Direction can be set and used to check the next location each time through the loop
        //Allow segments only up to 512m long due to cost of loop checking - may revise after testing
        for (this.SegmentDistances[initialdirection] = 0; this.SegmentDistances[initialdirection] < 2048; this.SegmentDistances[initialdirection]++)
        {
            switch (direction)
            {
            case 0:
                nextX++;
                dirvec = Vector3.right;
                break;

            case 1:
                nextZ++;
                dirvec = Vector3.forward;
                break;

            case 2:
                nextX--;
                dirvec = Vector3.left;
                break;

            case 3:
                nextZ--;
                dirvec = Vector3.back;
                break;

            default:
                nextX++;
                break;
            }

            ushort lValue1 = 0;
            byte   lFlags1 = 0;
            ushort type    = this.GetCube(nextX, nextY, nextZ, out lValue1, out lFlags1);
            this.mUnderSegment = this.mPrevGetSeg;
            //Debug.LogWarning("GetCube type: " + type.ToString() + " value: " + lValue1);
            bool foundslope = false;

            //Found air and need to check for a downward slope under it
            if (type == 1)
            {
                ushort  lValue2 = 0;
                byte    lFlags2 = 0;
                ushort  cube    = this.GetCube(nextX, nextY - 1L, nextZ, out lValue2, out lFlags2);
                Segment segment = this.mPrevGetSeg;
                type    = cube;
                lFlags1 = lFlags2;
                lValue1 = lValue2;
                if ((type == 538 && lValue1 == 2) || (type == ScrapTrackType && lValue1 == ScrapSlopeVal))
                {
                    foundslope = true;
                    nextY--; //decrement Y level for next loop through!
                }
                else
                {
                    if (type == 0)
                    {
                        Debug.LogError("Error, track follower has null under segment!");
                    }
                    if (this.mPrevGetSeg == null)
                    {
                        Debug.LogError("Error, prevseg was null!");
                    }
                    if (segment == null)
                    {
                        Debug.LogError("Error, old was null!");
                    }
                    if (this.mPrevGetSeg != segment)
                    {
                        Debug.LogWarning(("Track follower is looking for a slope, and has had to check across segment boundaries for this![Old/New" + segment.GetName() + " -> " + this.mPrevGetSeg.GetName()));
                    }
                    return(false);
                }
            }

            Vector3 trackvec = SegmentCustomRenderer.GetRotationQuaternion(lFlags1) * Vector3.forward;
            trackvec.Normalize();
            trackvec.x = trackvec.x >= -0.5 ? (trackvec.x <= 0.5 ? 0.0f : 1f) : -1f;
            trackvec.y = trackvec.y >= -0.5 ? (trackvec.y <= 0.5 ? 0.0f : 1f) : -1f;
            trackvec.z = trackvec.z >= -0.5 ? (trackvec.z <= 0.5 ? 0.0f : 1f) : -1f;
            //Begin checking track type
            if (type == TRACKTYPE || type == ScrapTrackType)
            {
                if ((type == TRACKTYPE && (lValue1 == TRACKSTRAIGHT || lValue1 == TRACKEMPTY || lValue1 == TRACKFULL)) || (type == ScrapTrackType && lValue1 == ScrapStraightVal))
                {
                    if (trackvec.y > 0.5 || trackvec.y < -0.5)
                    {
                        return(false);
                    }
                    else if (!(trackvec == dirvec) && !(trackvec == -dirvec))
                    {
                        // Came in from the side, this path is one-way.
                        mirrorOk = false;
                        dirvec   = new Vector3(trackvec.x, 0f, trackvec.z);
                    }
                }
                if ((type == TRACKTYPE && lValue1 == TRACKCORNER) || (type == ScrapTrackType && lValue1 == ScrapCornerVal))
                {
                    if (dirvec == new Vector3(-trackvec.z, 0.0f, trackvec.x))
                    {
                        dirvec = new Vector3(dirvec.z, 0.0f, -dirvec.x);
                    }
                    else if (trackvec == -dirvec)
                    {
                        dirvec = new Vector3(-dirvec.z, 0.0f, dirvec.x);
                    }
                    else
                    {
                        return(false);
                    }
                }
                if ((type == TRACKTYPE && lValue1 == TRACKSLOPE) || (type == ScrapTrackType && lValue1 == ScrapSlopeVal))
                {
                    Vector3 vector3_2 = trackvec;
                    dirvec.y = 0.0f;
                    dirvec.Normalize();
                    if (dirvec == trackvec)
                    {
                        if (foundslope)
                        {
                            return(false);
                        }
                        else
                        {
                            nextY++;
                        }
                    }
                    else if (dirvec == -trackvec)
                    {
                        ;
                    }
                }
                if (type == TRACKTYPE && lValue1 == TRACKBUFFER)
                {
                    dirvec = new Vector3(-dirvec.x, 0f, -dirvec.z);
                }
            }
            //Begin checking special types
            else if (type == CONTROLTYPE)
            {
                if (lValue1 == CONTROLLOAD || lValue1 == CONTROLUNLOAD || lValue1 == CONTROLTURBO)
                {
                    if ((trackvec == dirvec) || (trackvec == -dirvec))
                    {
                        //Do nothing... direction doesn't change
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            //Check for freight stations
            else if (type == FREIGHTSTATIONTYPE)
            {
                if ((trackvec == dirvec) || (trackvec == -dirvec))
                {
                    Segment segment = this.AttemptGetSegment(nextX, nextY, nextZ);
                    if (segment == null)
                    {
                        segment = WorldScript.instance.GetSegment(nextX, nextY, nextZ);
                        if (segment == null)
                        {
                            Debug.Log((object)"Track junction track follower did not find segment");
                            return(false);
                        }
                    }
                    FreightCartStation fcs = segment.FetchEntity(eSegmentEntity.Mod, nextX, nextY, nextZ) as FreightCartStation;
                    if (fcs == null)
                    {
                        Debug.LogWarning("Track Junction Track Follower tried to get a freight cart station but got other mod machine instead?");
                        return(false);
                    }
                    if (!SegmentStations.Contains(fcs))
                    {
                        SegmentStations.Add(fcs);
                    }
                    fcs.ClosestJunction   = this;
                    fcs.JunctionDirection = initialdirection;
                }
                else
                {
                    return(false);
                }
            }
            //Is it a junction?
            else if (type == JUNCTIONTYPE)
            {
                //Debug.LogWarning("Track follower success!  Found another junction!");
                Segment segment = this.AttemptGetSegment(nextX, nextY, nextZ);
                if (segment == null)
                {
                    segment = WorldScript.instance.GetSegment(nextX, nextY, nextZ);
                    if (segment == null)
                    {
                        Debug.Log((object)"Track junction track follower did not find segment");
                        return(false);
                    }
                }
                FreightTrackJunction junction = segment.FetchEntity(eSegmentEntity.Mod, nextX, nextY, nextZ) as FreightTrackJunction;
                if (junction == null)
                {
                    Debug.LogWarning("Track Junction Track Follower tried to get a track junction but got other mod machine instead?");
                    return(false);
                }

                //Mark this segment as a loop coming back to ourselves.
                if (junction == this)
                {
                    this.DirectionResults[initialdirection] = FreightTrackDirectionResults.Self;
                }
                else
                {
                    this.DirectionResults[initialdirection] = FreightTrackDirectionResults.Good;
                }

                this.SegmentDistances[initialdirection]  += 1; // We're going to exit the loop here, messing with loop variable OK'd.
                this.ConnectedJunctions[initialdirection] = junction;
                FreightTrackSegment tracksegment = new FreightTrackSegment(this, junction, this.SegmentDistances[initialdirection]);
                tracksegment.Stations = SegmentStations;
                //Debug.LogWarning("trackseg station count: " + tracksegment.Stations.Count);
                this.ConnectedSegments[initialdirection] = tracksegment;
                this.LinkStatusDirty = true;

                //If path is bi-directional, handle the connection for the other junction so we don't need to double the work
                if (mirrorOk)
                {
                    //Mirror the direction to reflect the correct side of the connecting junction
                    int mirroreddir = direction += 2;
                    if (mirroreddir > 3)
                    {
                        mirroreddir -= 4;
                    }
                    junction.ConnectedJunctions [mirroreddir] = this;
                    junction.ConnectedSegments [mirroreddir]  = tracksegment;
                    junction.SegmentDistances [mirroreddir]   = this.SegmentDistances[initialdirection];
                    junction.DirectionResults[mirroreddir]    = this.DirectionResults[initialdirection];//Either "Good
                    junction.LinkStatusDirty = true;
                }
                return(true);
            }
            else if (type == TOURSTATIONTYPE)
            {
                if (trackvec != -dirvec)
                {
                    return(false);
                }
                Segment segment = this.AttemptGetSegment(nextX, nextY, nextZ);
                if (segment == null)
                {
                    segment = WorldScript.instance.GetSegment(nextX, nextY, nextZ);
                    if (segment == null)
                    {
                        Debug.Log((object)"Track junction track follower did not find segment");
                        return(false);
                    }
                }
                TourCartStation station = segment.FetchEntity(eSegmentEntity.Mod, nextX, nextY, nextZ) as TourCartStation;
                station.TrackNetwork      = this.TrackNetwork;
                station.ClosestJunction   = this;
                station.JunctionDirection = initialdirection;
                this.ConnectedJunctions[initialdirection] = this;
                FreightTrackSegment tracksegment = new FreightTrackSegment(this, this, 2 * this.SegmentDistances[initialdirection] + 1);
                this.SegmentDistances[initialdirection] *= 2;
                this.SegmentDistances[initialdirection] += 1;
                this.ConnectedSegments[initialdirection] = tracksegment;
                this.LinkStatusDirty = true;
                if (!string.IsNullOrEmpty(station.StationName) && !this.TrackNetwork.TourCartStations.ContainsKey(station.StationName))
                {
                    this.TrackNetwork.TourCartStations.Add(station.StationName, station);
                }
                return(true);
            }
            else
            {
                return(false);   //Not a track type
            }
            //Update the direction int based on the changed direction vector
            if (dirvec == Vector3.right)
            {
                direction = 0;
            }
            else if (dirvec == Vector3.forward)
            {
                direction = 1;
            }
            else if (dirvec == Vector3.left)
            {
                direction = 2;
            }
            else if (dirvec == Vector3.back)
            {
                direction = 3;
            }

            //Store a hash of every track piece to check for getting stuck in endless loops.
            //HACK Construct a string to be our HashTable Key.
            //We could implement a fancy struct or something, but this works, and we don't have to make a custom GetHashTag function
            //(Struct.gethash() is apparently very inefficient)
            //And the try/catch construct means we only do one hash lookup even.
            try{
                //Build a string which will be unique for this particular track segment and travel direction. Lots and Lots of implicit casting to string on this line.
                VisitedTracks.Add((nextX - this.mnX) + "," + (nextY - this.mnY) + "," + (nextZ - this.mnZ) + "," + direction, null);
            }
            catch {
                Debug.LogWarning("TrackJunction followed track route and found an infinite loop. Ending search.");
                this.DirectionResults [initialdirection] = FreightTrackDirectionResults.Trap;
                return(false);
            }
        }
        Debug.LogWarning("Track Junction Found track length > 512m -> ending search.");
        return(false);
    }
예제 #27
0
    public override void SpawnWindow(SegmentEntity targetEntity)
    {
        FreightCartStation station = targetEntity as FreightCartStation;

        //Catch for when the window is called on an inappropriate machine
        if (station == null)
        {
            //GenericMachinePanelScript.instance.Hide();
            UIManager.RemoveUIRules("Machine");
            return;
        }


        if (!SetFreightItems && !ItemSearchWindow && !SetNetworkID && !SetName && !SetInventoryName && !string.IsNullOrEmpty(station.NetworkID))
        {
            this.manager.SetTitle("Freight Cart Station");
            this.manager.AddButton("stationname", "Set Name", 15, 0);
            this.manager.AddBigLabel("namelabel", string.IsNullOrEmpty(station.StationName) ? "UNNAMED" : station.StationName, Color.white, 165, 0);
            this.manager.AddButton("namenetwork", "Change Network", 15, 55);
            this.manager.AddBigLabel("networkid", station.NetworkID, Color.white, 165, 55);
            this.manager.AddButton("namestorage", "Name Storage", 15, 110);
            this.manager.AddBigLabel("storagename", station.ConnectedInventory != null ? station.ConnectedInventory.Name : "Connect Mass Storage", Color.white, 165, 110);
            this.manager.AddButton("setfreight", "Set Freight Goods", 100, 165);
            this.manager.AddBigLabel("assignedcarts", "Assigned Carts: " + station.AssignedCarts.ToString(), Color.white, 15, 215);
            this.manager.AddButton("decreasecarts", "Remove Cart", 25, 260);
            this.manager.AddButton("increasecarts", "Add Cart", 175, 260);
            this.manager.AddButton("toggleload", "Toggle Load", 25, 315);
            this.manager.AddButton("toggleoffer", "Toggle Offers", 25, 370);
            this.manager.AddButton("togglecarttier", "Toggle Tier", 100, 425);
            this.manager.AddBigLabel("loadstatus", "Wait for " + (station.mbWaitForFullLoad ? "Full" : "Any"), Color.white, 165, 315);
            this.manager.AddBigLabel("offerlabel", (station.OfferAll ? "Offer All" : "Use Offer List"), Color.white, 165, 370);
            this.manager.AddBigLabel("carttier", "Cart Tier: " + station.CartTierLabel(), Color.white, 25, 480);
        }
        else if (SetFreightItems && !ItemSearchWindow && !SetNetworkID && !SetName && !SetInventoryName && !string.IsNullOrEmpty(station.NetworkID))
        {
            this.manager.SetTitle("Freight Cart Station - Register Freight");
            this.manager.AddButton("freightdone", "Done", 100, 0);

            int count = 0;
            if (station.massStorageCrate != null)
            {
                count = FreightCartManager.instance.GetFreightEntries(station.NetworkID, station.massStorageCrate).Count;
                this.manager.AddTabButton("switchlowstock", "Edit Requests", !this.ChooseLowStock, 25, 50);
                this.manager.AddTabButton("switchhighstock", "Edit Offers", this.ChooseLowStock, 175, 50);

                int spacing = 175;
                int offset  = 50 + 50;

                for (int n = 0; n < count + 1; n++)
                {
                    int suffix = n;
                    if (n == count)
                    {
                        suffix = -1;
                    }
                    this.manager.AddIcon("registry" + suffix, "empty", Color.white, 0, offset + (spacing * n));
                    this.manager.AddBigLabel("registrytitle" + suffix, "Add New Freight", Color.white, 60, offset + (spacing * n));
                    if (suffix != -1)
                    {
                        this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "lowstocktitle" + n, "Request if below", this.ChooseLowStock == true ? Color.white : Color.gray, false, 0, offset + (spacing * n + 40));
                        this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "highstocktitle" + n, "Offer if above", this.ChooseLowStock == false ? Color.white : Color.gray, false, 150, offset + (spacing * n + 40));
                        this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "lowstock" + n, "Request if below", this.ChooseLowStock == true ? Color.white : Color.gray, false, 0, offset + (spacing * n + 60));
                        this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "highstock" + n, "Offer if above", this.ChooseLowStock == false ? Color.white : Color.gray, false, 150, offset + (spacing * n + 60));
                        this.manager.AddButton("decreasestock" + n, "Decrease Stock", 25, offset + (spacing * n + 100));
                        this.manager.AddButton("increasestock" + n, "Increase Stock", 175, offset + (spacing * n + 100));
                    }
                }
            }
            else if (station.AttachedInterface != null)
            {
                this.manager.AddBigLabel("interfacetext", "Servicing freight for:", Color.white, 0, 225);
                this.manager.AddBigLabel("interfacename", station.AttachedInterface.ToString(), Color.cyan, 0, 275);
            }
            else if (station.HopperInterface != null)
            {
                this.manager.AddIcon("hopitemoffer", "empty", Color.white, 0, 50);
                this.manager.AddBigLabel("registrytitle0", "Item to Offer", Color.white, 60, 50);
                this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "highstock", "Offer if above", Color.white, false, 150, 90);
                this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "highstocktitle", "Offer if above", Color.white, false, 50, 90);
                this.manager.AddButton("hopofferdown", "Decrease Stock", 25, 150);
                this.manager.AddButton("hopofferup", "Increase Stock", 175, 150);

                this.manager.AddIcon("hopitemrequest", "empty", Color.white, 0, 225);
                this.manager.AddBigLabel("registrytitle1", "Request Item", Color.white, 60, 225);
                this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "lowstock", "Request if below", Color.white, false, 150, 265);
                this.manager.AddLabel(GenericMachineManager.LabelType.OneLineHalfWidth, "lowstocktitle", "Request if below", Color.white, false, 50, 265);
                this.manager.AddButton("hoprequestdown", "Decrease Stock", 25, 325);
                this.manager.AddButton("hoprequestup", "Increase Stock", 175, 325);
            }
        }
        else if (ItemSearchWindow)
        {
            this.manager.SetTitle("Freight Cart Station - Item Search");
            this.manager.AddButton("searchcancel", "Cancel", 100, 0);
            this.manager.AddBigLabel("searchtitle", "Enter Item Search Term", Color.white, 50, 40);
            this.manager.AddBigLabel("searchtext", "_", Color.cyan, 50, 65);
            if (this.SearchResults != null)
            {
                int count       = this.SearchResults.Count;
                int spacing     = 60;  //Spacing between each registry line
                int yoffset     = 100; //Offset below button row
                int labeloffset = 60;  //x offset for label from icon

                for (int n = 0; n < count; n++)
                {
                    this.manager.AddIcon("itemicon" + n, "empty", Color.white, 0, yoffset + (spacing * n));
                    this.manager.AddBigLabel("iteminfo" + n, "Inventory Item", Color.white, labeloffset, yoffset + (spacing * n));
                }
            }
        }
        else if (SetNetworkID || string.IsNullOrEmpty(station.NetworkID) || SetName || SetInventoryName)
        {
            if (SetName)
            {
                this.manager.SetTitle("Freight Cart Station - Set Name");
                this.manager.AddBigLabel("networktitle", "Enter Station Name", Color.white, 50, 40);
            }
            else if (SetInventoryName)
            {
                this.manager.SetTitle("Set Mass Storage Name");
                this.manager.AddBigLabel("networktitle", "Enter Storage Name", Color.white, 50, 40);
            }
            else
            {
                this.manager.SetTitle("Freight Cart Station - Set Network");
                this.manager.AddBigLabel("networktitle", "Enter Network ID", Color.white, 50, 40);
            }
            UIManager.mbEditingTextField = true;
            UIManager.AddUIRules("TextEntry", UIRules.RestrictMovement | UIRules.RestrictLooking | UIRules.RestrictBuilding | UIRules.RestrictInteracting | UIRules.SetUIUpdateRate);
            GenericMachinePanelScript.instance.Scroll_Bar.GetComponent <UIScrollBar>().scrollValue = 0.0f;

            this.manager.AddButton("networkidcancel", "Cancel", 100, 0);
            this.manager.AddBigLabel("networkentry", "_", Color.cyan, 50, 65);
        }
        dirty         = true;
        networkredraw = false;
    }
예제 #28
0
    public override bool ButtonClicked(string name, SegmentEntity targetEntity)
    {
        FreightCartStation station = targetEntity as FreightCartStation;

        if (name.Contains("registry")) // drag drop to a slot
        {
            int slotNum = -1;
            int.TryParse(name.Replace("registry", ""), out slotNum); //Get slot name as number
            List <FreightRegistry> registries = FreightCartManager.instance.GetFreightEntries(station.NetworkID, station.massStorageCrate);

            if (slotNum > -1) // valid slot
            {
                FreightCartWindow.RemoveRegistry(station, registries[slotNum].FreightItem);
            }
            return(true);
        }
        else if (name == "hopitemoffer")
        {
            if (station.HopperInterface.OfferItem == null)
            {
                return(true);
            }
            FreightCartWindow.SetHopperOfferItem(station, null);
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "hopitemrequest")
        {
            if (station.HopperInterface.RequestItem == null)
            {
                return(true);
            }
            FreightCartWindow.SetHopperRequestItem(station, null);
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name.Contains("switchlowstock"))
        {
            this.ChooseLowStock = true;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name.Contains("switchhighstock"))
        {
            this.ChooseLowStock = false;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name.Contains("decreasestock"))
        {
            int slotNum = -1;
            int.TryParse(name.Replace("decreasestock", ""), out slotNum); //Get slot name as number
            List <FreightRegistry> registries = FreightCartManager.instance.GetFreightEntries(station.NetworkID, station.massStorageCrate);

            if (slotNum > -1) // valid slot
            {
                int amount = 100;
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    amount = 10;
                }
                if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                {
                    amount = 1;
                }
                if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
                {
                    amount = 1000;
                }

                int stock;
                if (this.ChooseLowStock)
                {
                    stock = registries[slotNum].LowStock - amount;
                    if (stock < 0)
                    {
                        stock = 0;
                    }
                    FreightCartWindow.SetLowStock(station, registries[slotNum].FreightItem, stock);
                    return(true);
                }
                else
                {
                    stock = registries[slotNum].HighStock - amount;
                    if (stock < 0)
                    {
                        stock = 0;
                    }
                    FreightCartWindow.SetHighStock(station, registries[slotNum].FreightItem, stock);
                    return(true);
                }
            }
        }
        else if (name.Contains("increasestock"))
        {
            int slotNum = -1;
            int.TryParse(name.Replace("increasestock", ""), out slotNum); //Get slot name as number
            List <FreightRegistry> registries = FreightCartManager.instance.GetFreightEntries(station.NetworkID, station.massStorageCrate);

            if (slotNum > -1) // valid slot
            {
                int amount = this.ModifierItemCount();
                int stock;
                if (this.ChooseLowStock)
                {
                    stock = registries[slotNum].LowStock + amount;
                    FreightCartWindow.SetLowStock(station, registries[slotNum].FreightItem, stock);
                    return(true);
                }
                else
                {
                    stock = registries[slotNum].HighStock + amount;
                    FreightCartWindow.SetHighStock(station, registries[slotNum].FreightItem, stock);
                    return(true);
                }
            }
        }
        else if (name == "hopofferdown")
        {
            int amount = station.HopperInterface.OfferLimit - this.ModifierItemCount();
            if (amount < 0)
            {
                amount = 0;
            }
            FreightCartWindow.SetHopperOffer(station, amount);
            return(true);
        }
        else if (name == "hopofferup")
        {
            int amount = station.HopperInterface.OfferLimit + this.ModifierItemCount();
            if (amount > station.HopperInterface.Machine.TotalCapacity)
            {
                amount = station.HopperInterface.Machine.TotalCapacity;
            }
            FreightCartWindow.SetHopperOffer(station, amount);
            return(true);
        }
        else if (name == "hoprequestdown")
        {
            int amount = station.HopperInterface.RequestLimit - this.ModifierItemCount();
            if (amount < 0)
            {
                amount = 0;
            }
            FreightCartWindow.SetHopperRequest(station, amount);
            return(true);
        }
        else if (name == "hoprequestup")
        {
            int amount = station.HopperInterface.RequestLimit + this.ModifierItemCount();
            FreightCartWindow.SetHopperRequest(station, amount);
            return(true);
        }
        else if (name.Contains("searchcancel"))
        {
            this.ItemSearchWindow        = false;
            this.SearchResults           = null;
            UIManager.mbEditingTextField = false;
            UIManager.RemoveUIRules("TextEntry");
            this.EntryString = "";
            GenericMachinePanelScript.instance.Scroll_Bar.GetComponent <UIScrollBar>().scrollValue = 0.0f;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name.Contains("itemicon"))
        {
            int slotNum = -1;
            int.TryParse(name.Replace("itemicon", ""), out slotNum); //Get slot name as number
            if (slotNum > -1)
            {
                switch (eSearchType)
                {
                case SearchType.Registry:
                    FreightCartWindow.AddRegistry(station, this.SearchResults[slotNum]);
                    break;

                case SearchType.HopperOffer:
                    FreightCartWindow.SetHopperOfferItem(station, this.SearchResults[slotNum]);
                    break;

                case SearchType.HopperRequest:
                    FreightCartWindow.SetHopperRequestItem(station, this.SearchResults[slotNum]);
                    break;
                }
                this.SearchResults    = null;
                this.ItemSearchWindow = false;
                this.EntryString      = "";
                GenericMachinePanelScript.instance.Scroll_Bar.GetComponent <UIScrollBar>().scrollValue = 0.0f;
                return(true);
            }
        }
        else if (name == "namenetwork")
        {
            this.SetNetworkID = true;
            this.Redraw(targetEntity);
            return(true);
        }
        else if (name == "stationname")
        {
            this.SetName = true;
            this.Redraw(targetEntity);
            return(true);
        }
        else if (name == "namestorage")
        {
            this.SetInventoryName = true;
            this.Redraw(targetEntity);
            return(true);
        }
        else if (name == "networkidcancel")
        {
            this.SetNetworkID            = false;
            this.SetName                 = false;
            this.SetInventoryName        = false;
            UIManager.mbEditingTextField = false;
            UIManager.RemoveUIRules("TextEntry");
            this.EntryString = "";
            if (string.IsNullOrEmpty(station.NetworkID))
            {
                GenericMachinePanelScript.instance.Hide();
                return(true);
            }
            this.manager.RedrawWindow();
        }
        else if (name == "setfreight")
        {
            this.SetFreightItems = true;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "freightdone")
        {
            this.SetFreightItems = false;
            this.manager.RedrawWindow();
            return(true);
        }
        else if (name == "increasecarts")
        {
            int amount = 1;
            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                amount = 10;
            }
            FreightCartWindow.SetCartAssignment(station, station.AssignedCarts + amount);
            return(true);
        }
        else if (name == "decreasecarts")
        {
            int amount = 1;
            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                amount = 10;
            }
            FreightCartWindow.SetCartAssignment(station, station.AssignedCarts - amount < 0 ? 0 : station.AssignedCarts - amount);
            return(true);
        }
        else if (name == "toggleload")
        {
            FreightCartWindow.ToggleLoadStatus(station, !station.mbWaitForFullLoad ? "Full" : "Any");
            return(true);
        }
        else if (name == "toggleoffer")
        {
            FreightCartWindow.ToggleOfferAll(station, !station.OfferAll ? "All" : "registry");
            return(true);
        }
        else if (name == "togglecarttier")
        {
            FreightCartWindow.ToggleCartTier(station, station.CartTier);
            return(true);
        }

        return(false);
    }
예제 #29
0
    public override void UpdateMachine(SegmentEntity targetEntity)
    {
        FreightCartStation station = targetEntity as FreightCartStation;

        //Catch for when the window is called on an inappropriate machine
        if (station == null)
        {
            GenericMachinePanelScript.instance.Hide();
            UIManager.RemoveUIRules("Machine");
            return;
        }

        GenericMachinePanelScript.instance.Scroll_Bar.GetComponent <UIScrollBar>().scrollValue -= Input.GetAxis("Mouse ScrollWheel");


        if (networkredraw)
        {
            this.manager.RedrawWindow();
        }
        if (!dirty)
        {
            return;
        }

        if (!SetFreightItems && !ItemSearchWindow && !SetNetworkID && !SetName && !SetInventoryName && !string.IsNullOrEmpty(station.NetworkID))
        {
            this.manager.UpdateLabel("assignedcarts", "Assigned Carts: " + station.AssignedCarts.ToString(), Color.white);
            this.manager.UpdateLabel("loadstatus", "Wait for " + (station.mbWaitForFullLoad ? "Full" : "Any"), Color.white);
            this.manager.UpdateLabel("offerlabel", (station.OfferAll ? "Offer All" : "Use Offer List"), Color.white);
            this.manager.UpdateLabel("carttier", "Cart Tier: " + station.CartTierLabel(), Color.white);
        }
        else if (SetFreightItems && !ItemSearchWindow && !SetNetworkID && !SetName && !SetInventoryName && station.NetworkID != null)
        {
            if (station.massStorageCrate != null)
            {
                List <FreightRegistry> registries = new List <FreightRegistry>();
                registries = FreightCartManager.instance.GetFreightEntries(station.NetworkID, station.massStorageCrate);
                for (int index = 0; index < registries.Count; index++)
                {
                    ItemBase item      = registries[index].FreightItem;
                    int      lowstock  = registries[index].LowStock;
                    int      highstock = registries[index].HighStock;

                    string itemname = ItemManager.GetItemName(item);
                    string iconname = ItemManager.GetItemIcon(item);

                    this.manager.UpdateIcon("registry" + index, iconname, Color.white);
                    this.manager.UpdateLabel("registrytitle" + index, itemname, Color.white);
                    this.manager.UpdateLabel("lowstock" + index, registries[index].LowStock.ToString(), this.ChooseLowStock == true ? Color.white : Color.gray);
                    this.manager.UpdateLabel("highstock" + index, registries[index].HighStock.ToString(), this.ChooseLowStock == false ? Color.white : Color.gray);
                    this.manager.UpdateLabel("lowstocktitle" + index, "Request if below", this.ChooseLowStock == true ? Color.white : Color.gray);
                    this.manager.UpdateLabel("highstocktitle" + index, "Offer if above", this.ChooseLowStock == false ? Color.white : Color.gray);
                }
            }
            else if (station.HopperInterface != null)
            {
                ItemBase item = station.HopperInterface.OfferItem;
                string   itemname;
                string   iconname;
                if (item != null)
                {
                    itemname = ItemManager.GetItemName(item);
                    iconname = ItemManager.GetItemIcon(item);
                    this.manager.UpdateIcon("hopitemoffer", iconname, Color.white);
                    this.manager.UpdateLabel("registrytitle0", itemname, Color.white);
                }
                this.manager.UpdateLabel("highstock", station.HopperInterface.OfferLimit.ToString(), Color.white);

                item = station.HopperInterface.RequestItem;
                if (item != null)
                {
                    itemname = ItemManager.GetItemName(item);
                    iconname = ItemManager.GetItemIcon(item);
                    this.manager.UpdateIcon("hopitemrequest", iconname, Color.white);
                    this.manager.UpdateLabel("registrytitle1", itemname, Color.white);
                }
                this.manager.UpdateLabel("lowstock", station.HopperInterface.RequestLimit.ToString(), Color.white);
            }
            else
            {
                this.manager.UpdateLabel("registrytitle-1", "Connect to Freight provider", Color.red);
                return;
            }
        }
        else if (ItemSearchWindow)
        {
            if (this.SearchResults == null)
            {
                this.Counter++;
                foreach (char c in Input.inputString)
                {
                    if (c == "\b"[0])  //Backspace
                    {
                        if (this.EntryString.Length != 0)
                        {
                            this.EntryString = this.EntryString.Substring(0, this.EntryString.Length - 1);
                        }
                    }
                    else if (c == "\n"[0] || c == "\r"[0]) //Enter or Return
                    {
                        this.SearchResults = new List <ItemBase>();

                        for (int n = 0; n < ItemEntry.mEntries.Length; n++)
                        {
                            if (ItemEntry.mEntries[n] == null)
                            {
                                continue;
                            }
                            if (ItemEntry.mEntries[n].Name.ToLower().Contains(this.EntryString.ToLower()))
                            {
                                this.SearchResults.Add(ItemManager.SpawnItem(ItemEntry.mEntries[n].ItemID));
                            }
                        }
                        for (int n = 0; n < TerrainData.mEntries.Length; n++)
                        {
                            bool             foundvalue = false;
                            TerrainDataEntry entry      = TerrainData.mEntries[n];
                            if (entry == null)
                            {
                                continue;
                            }
                            if (entry.Name.ToLower().Contains(this.EntryString.ToLower()))
                            {
                                int count = entry.Values.Count;
                                for (int m = 0; m < count; m++)
                                {
                                    if (entry.Values[m].Name.ToLower().Contains(this.EntryString.ToLower()))
                                    {
                                        if (string.IsNullOrEmpty(entry.PickReplacement))
                                        {
                                            this.SearchResults.Add(ItemManager.SpawnCubeStack(entry.CubeType, entry.Values[m].Value, 1));
                                            foundvalue = true;
                                        }
                                    }
                                }
                                if (!foundvalue && string.IsNullOrEmpty(entry.PickReplacement))
                                {
                                    this.SearchResults.Add(ItemManager.SpawnCubeStack(entry.CubeType, entry.DefaultValue, 1));
                                }
                            }
                            if ((this.EntryString.ToLower().Contains("component") || this.EntryString.ToLower().Contains("placement") || this.EntryString.ToLower().Contains("multi")) && entry.CubeType == 600)
                            {
                                int count = entry.Values.Count;
                                for (int m = 0; m < count; m++)
                                {
                                    this.SearchResults.Add(ItemManager.SpawnCubeStack(600, entry.Values[m].Value, 1));
                                }
                            }
                        }
                        if (this.SearchResults.Count == 0)
                        {
                            this.SearchResults = null;
                        }

                        UIManager.mbEditingTextField = false;
                        UIManager.RemoveUIRules("TextEntry");

                        this.manager.RedrawWindow();
                        return;
                    }
                    else
                    {
                        this.EntryString += c;
                    }
                }
                this.manager.UpdateLabel("searchtext", this.EntryString + (this.Counter % 20 > 10 ? "_" : ""), Color.cyan);
                dirty = true;
                return;
            }
            else
            {
                this.manager.UpdateLabel("searchtitle", "Searching for:", Color.white);
                this.manager.UpdateLabel("searchtext", this.EntryString, Color.cyan);
                int count = this.SearchResults.Count;
                for (int n = 0; n < count; n++)
                {
                    ItemBase item     = this.SearchResults[n];
                    string   itemname = ItemManager.GetItemName(item);
                    string   iconname = ItemManager.GetItemIcon(item);

                    this.manager.UpdateIcon("itemicon" + n, iconname, Color.white);
                    this.manager.UpdateLabel("iteminfo" + n, itemname, Color.white);
                }
            }
        }
        else if (SetNetworkID || string.IsNullOrEmpty(station.NetworkID) || SetName || SetInventoryName)
        {
            this.Counter++;
            foreach (char c in Input.inputString)
            {
                if (c == "\b"[0])  //Backspace
                {
                    if (this.EntryString.Length != 0)
                    {
                        this.EntryString = this.EntryString.Substring(0, this.EntryString.Length - 1);
                    }
                }
                else if (c == "\n"[0] || c == "\r"[0]) //Enter or Return
                {
                    if (SetName)
                    {
                        FreightCartWindow.SetStationName(station, this.EntryString);
                        this.SetName = false;
                    }
                    else if (SetInventoryName)
                    {
                        FreightCartWindow.NameInventory(station, this.EntryString);
                        this.SetInventoryName = false;
                    }
                    else
                    {
                        FreightCartWindow.SetNetwork(station, this.EntryString);
                        this.SetNetworkID = false;
                    }
                    this.EntryString             = "";
                    UIManager.mbEditingTextField = false;
                    UIManager.RemoveUIRules("TextEntry");
                    return;
                }
                else
                {
                    this.EntryString += c;
                }
            }
            this.manager.UpdateLabel("networkentry", this.EntryString + (this.Counter % 20 > 10 ? "_" : ""), Color.cyan);
            dirty = true;
            return;
        }
        dirty = false;
    }