Exemplo n.º 1
0
    void LoadToWarehouse()
    {
        if (BeltActCall.GoodsOnBelt != null)
        {
            ObjectActCall.IsWorking = true;

            if (GoodsValueCall.CheckMovingState(int.Parse(BeltActCall.GoodsOnBelt.name)) == 0)
            {
                SalesValueCall.UpdateItemCount(CompanyManagerCall.PlayerCompanyName, GoodsValueCall.FindGoodsName(BeltActCall.GoodsOnBelt));

                GoodsValueCall.ChangeInMapState(int.Parse(BeltActCall.GoodsOnBelt.name), false, null);
                Destroy(BeltActCall.GoodsOnBelt);
                BeltActCall.GoodsOnBelt = null;
            }
        }
        else
        {
            ObjectActCall.IsWorking = false;
        }
    }
Exemplo n.º 2
0
    void ProcessingGoods()
    {
        for (int i = 0; i < InputNumber; i++)
        {
            // Check the belt has correct object
            if (Mover[i].GetComponent <BeltAct>().GoodsOnBelt != null)
            {
                for (int j = 0; j < InputNumber; j++)
                {
                    if (RegisteredInput[j] == -1)
                    {
                        if (GoodsValueCall.FindGoodsName(int.Parse(Mover[i].GetComponent <BeltAct>().GoodsOnBelt.name)) == TargetGoodsRecipe.InputName[j])
                        {
                            // Write belt's index to RegisteredInput
                            RegisteredInput[j] = i;
                            break;
                        }
                        else
                        {
                            RegisteredInput[j] = -1;
                        }
                    }
                }
            }
        }

        for (int i = 0; i < InputNumber; i++)
        {
            if (Mover[i].GetComponent <BeltAct>().GoodsOnBelt != null)
            {
                PrevBelt[i].GetComponent <BeltAct>().ChangeNeedStop(true, gameObject);
            }
        }

        // Input check routine
        for (int i = 0; i < InputNumber; i++)
        {
            if (Mover[i].GetComponent <BeltAct>().GoodsOnBelt != null)
            {
                if (!Mover[i].GetComponent <BeltAct>().isCenter(-1))
                {
                    return;
                }
                else if (Mover[i].GetComponent <BeltAct>().isCenter(-1))
                {
                    for (int j = 0; j < InputNumber;)
                    {
                        // Check all RegisteredInput
                        if (RegisteredInput[j] == i)
                        {
                            // Correct input. break the check routine
                            break;
                        }
                        j++;
                        if (j == InputNumber)
                        {
                            // Wrong input. Object will be destroy
                            GoodsValueCall.DeleteGoodsArray(int.Parse(Mover[i].GetComponent <BeltAct>().GoodsOnBelt.name));
                            Destroy(Mover[i].GetComponent <BeltAct>().GoodsOnBelt);
                            PrevBelt[i].GetComponent <BeltAct>().ChangeNeedStop(false, gameObject);
                            Mover[i].GetComponent <BeltAct>().GoodsOnBelt = null;
                            return;
                        }
                    }
                }
            }
        }

        // Now processing
        if (Mover[0].GetComponent <BeltAct>().GoodsOnBelt != null && ProcessedGoods == null)
        {
            Mover[0].GetComponent <BeltAct>().ChangeNeedStop(true, gameObject);

            for (int i = 0; i < InputNumber; i++)
            {
                if (Mover[i].GetComponent <BeltAct>().GoodsOnBelt == null)
                {
                    // If there is empty belt, wait for that
                    return;
                }
            }

            // If there is something one belt and no previous processed object
            // Start processing
            if (!isWaiting)
            {
                if (ObjectActCall.WorkSpeed == 0)
                {
                    return;
                }
                StartCoroutine(Waiter());
            }
            else
            {
                return;
            }
        }
        else if (Mover[0].GetComponent <BeltAct>().GoodsOnBelt != null && ProcessedGoods != null)
        {
            // If there is something on belt and previous processed object
            // Waiting object must not come in processor
            Mover[0].GetComponent <BeltAct>().ChangeNeedStop(false, gameObject);
        }
        else if (Mover[0].GetComponent <BeltAct>().GoodsOnBelt == null && ProcessedGoods != null)
        {
            // If there is nothing on belt but previous processed object
            // Clear the processed object info
            ProcessedGoods = null;
            for (int i = 0; i < InputNumber; i++)
            {
                // Now waiting object can come in
                Mover[0].GetComponent <BeltAct>().ChangeNeedStop(true, gameObject);
                // Clear the RegisteredInput
                RegisteredInput[i] = -1;
            }
        }
        else
        {
            // If there is nothing
            Mover[0].GetComponent <BeltAct>().ChangeNeedStop(true, gameObject);
            for (int i = 0; i < InputNumber; i++)
            {
                // Processor is ready for object
                PrevBelt[i].GetComponent <BeltAct>().ChangeNeedStop(false, gameObject);
            }
        }
    }