예제 #1
0
        public void BeltItemSlotProcessorCheck()
        {
            // Arrange
            List <List <BeltItemSlot> > dummyBeltItemSlotGroup = new List <List <BeltItemSlot> >();

            dummyBeltItemSlotGroup.Add(new List <BeltItemSlot>());
            dummyBeltItemSlotGroup[0].Add(new BeltItemSlot(Vector3.zero));
            dummyBeltItemSlotGroup[0].Add(new BeltItemSlot(Vector3.zero));
            BeltItemSlot.ConnectBeltItemSlots(dummyBeltItemSlotGroup[0][0], dummyBeltItemSlotGroup[0][1]);

            ObjectPoolSimple <BeltItem> dummyItemPool = new ObjectPoolSimple <BeltItem>(1, 1);

            dummyItemPool.SetUp();
            dummyBeltItemSlotGroup[0][0].myItem = dummyItemPool.Spawn();


            List <BeltPreProcessor.BeltGroup> dummyBeltGroup = new List <BeltPreProcessor.BeltGroup>();

            BeltPreProcessor.BeltGroup newGroup = new BeltPreProcessor.BeltGroup();
            newGroup.beltItemSlotGroups = dummyBeltItemSlotGroup;
            dummyBeltGroup.Add(newGroup);

            BeltItemSlotUpdateProcessor myBeltItemSlotUpdateProcessor = new BeltItemSlotUpdateProcessor(dummyItemPool, dummyBeltGroup);

            // Act
            myBeltItemSlotUpdateProcessor.UpdateBeltItemSlots();

            // Assert
            Assert.IsNull(dummyBeltItemSlotGroup[0][0].myItem);
            Assert.IsNotNull(dummyBeltItemSlotGroup[0][1].myItem);
        }
예제 #2
0
        public void BeltItemSlotProcessorCheck()
        {
            // Arrange
            List <List <BeltItemSlot> > dummyBeltItemSlotGroup = new List <List <BeltItemSlot> >();

            dummyBeltItemSlotGroup.Add(new List <BeltItemSlot>());
            dummyBeltItemSlotGroup[0].Add(new BeltItemSlot(Vector3.zero));
            dummyBeltItemSlotGroup[0].Add(new BeltItemSlot(Vector3.zero));
            BeltItemSlot.ConnectBeltItemSlots(dummyBeltItemSlotGroup[0][0], dummyBeltItemSlotGroup[0][1]);

            List <BeltItem> beltItems = new List <BeltItem>();

            beltItems.Add(new GameObject().AddComponent <BeltItem>().GetComponent <BeltItem>());
            dummyBeltItemSlotGroup[0][0].myItem = beltItems[0];
            beltItems[0].mySlot = dummyBeltItemSlotGroup[0][0];

            List <BeltPreProcessor.BeltGroup> dummyBeltGroup = new List <BeltPreProcessor.BeltGroup>();

            BeltPreProcessor.BeltGroup newGroup = new BeltPreProcessor.BeltGroup();
            newGroup.beltItemSlotGroups = dummyBeltItemSlotGroup;
            dummyBeltGroup.Add(newGroup);
            BeltItemSlotUpdateProcessor myBeltItemSlotUpdateProcessor = new BeltItemSlotUpdateProcessor(beltItems, dummyBeltGroup);

            // Act
            myBeltItemSlotUpdateProcessor.UpdateBeltItemSlots();

            // Assert
            Assert.IsNull(dummyBeltItemSlotGroup[0][0].myItem);
            Assert.IsNotNull(dummyBeltItemSlotGroup[0][1].myItem);
        }
예제 #3
0
    public static void ConnectBelts(BeltObject from, BeltObject to, int connectionSide)
    {
        if (from == null || to == null)
        {
            return;
        }

        switch (connectionSide)
        {
        case 0:
            for (int x = 1; x < 3; x++)
            {
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[x, 0], to.myBeltItemSlots[x, 3]);
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[x, 0], to.myBeltItemSlots[x, 3]);
            }
            break;

        case 1:
            for (int y = 1; y < 3; y++)
            {
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[3, y], to.myBeltItemSlots[0, y]);
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[3, y], to.myBeltItemSlots[0, y]);
            }
            break;

        case 2:
            for (int x = 1; x < 3; x++)
            {
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[x, 3], to.myBeltItemSlots[x, 0]);
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[x, 3], to.myBeltItemSlots[x, 0]);
            }
            break;

        case 3:
            for (int y = 1; y < 3; y++)
            {
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[0, y], to.myBeltItemSlots[3, y]);
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[0, y], to.myBeltItemSlots[3, y]);
            }
            break;
        }
    }
예제 #4
0
    // belt item slot coordinates start from top left corner

    /* The Logic goes like this:
     * 1. check and connect all the middle belts if and only if there is a 'running line' through them, ie behind them is an input and front is output
     * 2. connect all the edge connections to all the middle pieces
     * 3. this leaves 3 edge cases out, later correct them
     *		the edges cases are:
     *			-corners
     *			-1 out 2 split in '>v<' and reverse of that
     *			-2 in 2 out, ins and outs are next to each other - is an overpass
     */
    public void CreateBeltItemSlots()
    {
        myBeltItemSlots       = new BeltItemSlot[4, 4];
        myBeltItemSlotsLayer2 = new BeltItemSlot[4, 4];
        allBeltItemSlots.Clear();

        // populate the center
        for (int x = 1; x < 3; x++)
        {
            for (int y = 1; y < 3; y++)
            {
                myBeltItemSlots[x, y] = new BeltItemSlot(GetBeltItemSlotPos(x, y));
                allBeltItemSlots.Add(myBeltItemSlots[x, y]);
            }
        }

        // run lines through
        runningLineCount = 0;
        for (int x = 1; x < 3; x++)
        {
            for (int y = 1; y < 3; y++)
            {
                if (beltInputs[0] && beltOutputs[2])
                {
                    runningLineCount++;
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[x, y], myBeltItemSlots[x, y + 1]);
                }
                if (beltInputs[1] && beltOutputs[3])
                {
                    runningLineCount++;
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[x, y], myBeltItemSlots[x - 1, y]);
                }
                if (beltInputs[2] && beltOutputs[0])
                {
                    runningLineCount++;
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[x, y], myBeltItemSlots[x, y - 1]);
                }
                if (beltInputs[3] && beltOutputs[1])
                {
                    runningLineCount++;
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[x, y], myBeltItemSlots[x + 1, y]);
                }
            }
        }
        runningLineCount /= 4;

        // connect edges to the center
        if (beltInputs[0] || beltOutputs[0])
        {
            for (int x = 1; x < 3; x++)
            {
                myBeltItemSlots[x, 0] = new BeltItemSlot(GetBeltItemSlotPos(x, 0));
                allBeltItemSlots.Add(myBeltItemSlots[x, 0]);
                if (beltInputs[0])                 // spawn the connection around if input or output
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[x, 0], myBeltItemSlots[x, 1]);
                }
                else
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[x, 1], myBeltItemSlots[x, 0]);
                }
            }
        }
        if (beltInputs[1] || beltOutputs[1])
        {
            for (int y = 1; y < 3; y++)
            {
                myBeltItemSlots[3, y] = new BeltItemSlot(GetBeltItemSlotPos(3, y));
                allBeltItemSlots.Add(myBeltItemSlots[3, y]);
                if (beltInputs[1])                 // spawn the connection around if input or output
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[3, y], myBeltItemSlots[2, y]);
                }
                else
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, y], myBeltItemSlots[3, y]);
                }
            }
        }
        if (beltInputs[2] || beltOutputs[2])
        {
            for (int x = 1; x < 3; x++)
            {
                myBeltItemSlots[x, 3] = new BeltItemSlot(GetBeltItemSlotPos(x, 3));
                allBeltItemSlots.Add(myBeltItemSlots[x, 3]);
                if (beltInputs[2])                 // spawn the connection around if input or output
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[x, 3], myBeltItemSlots[x, 2]);
                }
                else
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[x, 2], myBeltItemSlots[x, 3]);
                }
            }
        }
        if (beltInputs[3] || beltOutputs[3])
        {
            for (int y = 1; y < 3; y++)
            {
                myBeltItemSlots[0, y] = new BeltItemSlot(GetBeltItemSlotPos(0, y));
                allBeltItemSlots.Add(myBeltItemSlots[0, y]);
                if (beltInputs[3])                 // spawn the connection around if input or output
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[0, y], myBeltItemSlots[1, y]);
                }
                else
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, y], myBeltItemSlots[0, y]);
                }
            }
        }

        // this part is pretty much the hardcoded way of how belts interlock.
        // check the design document to see what exactly this is doing
        // it is pretty much checking if the input/outputs match some of the 'templates' and acts accordingly
        totalEdgeCount = 0;
        for (int i = 0; i < 4; i++)
        {
            totalEdgeCount += (beltInputs[i] || beltOutputs[i]) ? 1 : 0;
        }

        if (runningLineCount == 2 && totalEdgeCount == 4)
        {
            for (int x = 1; x < 3; x++)
            {
                for (int y = 1; y < 3; y++)
                {
                    BeltItemSlot.RemoveAllConnectionsFromBeltItemSlot(myBeltItemSlots[x, y]);
                }
            }

            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 4; y++)
                {
                    myBeltItemSlotsLayer2[x, y] = myBeltItemSlots[x, y];
                }
            }
            for (int x = 1; x < 3; x++)
            {
                for (int y = 1; y < 3; y++)
                {
                    myBeltItemSlotsLayer2[x, y] = new BeltItemSlot(GetBeltItemSlotPos(x, y));
                    allBeltItemSlots.Add(myBeltItemSlotsLayer2[x, y]);
                }
            }

            if (beltInputs[0] && beltInputs[1])
            {
                for (int y = 0; y < 3; y++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, y], myBeltItemSlots[1, y + 1]);
                }
                for (int y = 0; y < 3; y++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, y], myBeltItemSlots[2, y + 1]);
                }

                for (int x = 0; x < 3; x++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlotsLayer2[x + 1, 1], myBeltItemSlotsLayer2[x, 1]);
                }
                for (int x = 0; x < 3; x++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlotsLayer2[x + 1, 2], myBeltItemSlotsLayer2[x, 2]);
                }
            }
            else if (beltInputs[1] && beltInputs[2])
            {
                for (int x = 0; x < 3; x++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlotsLayer2[x + 1, 1], myBeltItemSlotsLayer2[x, 1]);
                }
                for (int x = 0; x < 3; x++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlotsLayer2[x + 1, 2], myBeltItemSlotsLayer2[x, 2]);
                }

                for (int y = 0; y < 3; y++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, y + 1], myBeltItemSlots[1, y]);
                }
                for (int y = 0; y < 3; y++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, y + 1], myBeltItemSlots[2, y]);
                }
            }
            else if (beltInputs[2] && beltInputs[3])
            {
                for (int y = 0; y < 3; y++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, y + 1], myBeltItemSlots[1, y]);
                }
                for (int y = 0; y < 3; y++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, y + 1], myBeltItemSlots[2, y]);
                }

                for (int x = 0; x < 3; x++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlotsLayer2[x, 1], myBeltItemSlotsLayer2[x + 1, 1]);
                }
                for (int x = 0; x < 3; x++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlotsLayer2[x, 2], myBeltItemSlotsLayer2[x + 1, 2]);
                }
            }
            else if (beltInputs[3] && beltInputs[0])
            {
                for (int x = 0; x < 3; x++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlotsLayer2[x, 1], myBeltItemSlotsLayer2[x + 1, 1]);
                }
                for (int x = 0; x < 3; x++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlotsLayer2[x, 2], myBeltItemSlotsLayer2[x + 1, 2]);
                }

                for (int y = 0; y < 3; y++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, y], myBeltItemSlots[1, y + 1]);
                }
                for (int y = 0; y < 3; y++)
                {
                    BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, y], myBeltItemSlots[2, y + 1]);
                }
            }
        }
        else if (runningLineCount == 0 && totalEdgeCount == 2)
        {
            if (beltInputs[0] && beltOutputs[1])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 1], myBeltItemSlots[1, 2]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 2], myBeltItemSlots[2, 2]);
            }
            else if (beltInputs[1] && beltOutputs[2])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 1], myBeltItemSlots[1, 1]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 1], myBeltItemSlots[1, 2]);
            }
            else if (beltInputs[2] && beltOutputs[3])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 2], myBeltItemSlots[2, 1]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 1], myBeltItemSlots[1, 1]);
            }
            else if (beltInputs[3] && beltOutputs[0])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 2], myBeltItemSlots[2, 2]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 2], myBeltItemSlots[2, 1]);
            }

            if (beltInputs[1] && beltOutputs[0])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 2], myBeltItemSlots[1, 2]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 2], myBeltItemSlots[1, 1]);
            }
            else if (beltInputs[2] && beltOutputs[1])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 2], myBeltItemSlots[1, 1]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 1], myBeltItemSlots[2, 1]);
            }
            else if (beltInputs[3] && beltOutputs[2])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 1], myBeltItemSlots[2, 1]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 1], myBeltItemSlots[2, 2]);
            }
            else if (beltInputs[0] && beltOutputs[3])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 1], myBeltItemSlots[2, 2]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 2], myBeltItemSlots[1, 2]);
            }
        }
        else if (runningLineCount == 0 && totalEdgeCount == 3)
        {
            if (beltInputs[0] && beltOutputs[1] && beltOutputs[3])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 1], myBeltItemSlots[2, 2]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 2], myBeltItemSlots[3, 2]);

                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 1], myBeltItemSlots[1, 2]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 2], myBeltItemSlots[0, 2]);
            }
            else if (beltInputs[1] && beltOutputs[2] && beltOutputs[0])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 1], myBeltItemSlots[1, 1]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 1], myBeltItemSlots[1, 0]);

                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 2], myBeltItemSlots[1, 2]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 2], myBeltItemSlots[1, 3]);
            }
            else if (beltInputs[2] && beltOutputs[3] && beltOutputs[1])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 2], myBeltItemSlots[2, 1]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 1], myBeltItemSlots[3, 1]);

                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 2], myBeltItemSlots[1, 1]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 1], myBeltItemSlots[0, 1]);
            }
            else if (beltInputs[3] && beltOutputs[0] && beltOutputs[2])
            {
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 2], myBeltItemSlots[2, 2]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 2], myBeltItemSlots[2, 3]);

                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[1, 1], myBeltItemSlots[2, 1]);
                BeltItemSlot.ConnectBeltItemSlots(myBeltItemSlots[2, 1], myBeltItemSlots[2, 0]);
            }
        }

        allBeltItemSlotsArray = allBeltItemSlots.ToArray();
    }