Esempio n. 1
0
    // - - - - - - - - - - - - - - - - - PERFORM WORKSHOP TASK
    void Perform_task()
    {
        if (purgingPartsToSharedStorage)
        {
            Do_purge();
            return;
        }

        CurrentChassisRequest = new VehicleChassiRequest(
            currentTask.design.chassisType.partConfig,
            currentTask.design.chassisType.partConfig.partVersion,
            currentTask.requiredParts,
            REG,
            factoryMode);

        if (
            REG.currentState == StorageState.IDLE ||
            (REG.currentState == StorageState.WAITING && L1.currentState == StorageState.IDLE))
        {
            if (REG.currentState == StorageState.IDLE && L1.currentState == StorageState.WAITING)
            {
                L1.Clear_all_requests();
                L1.Change_state(StorageState.IDLE);
            }
            if (L2.currentState == StorageState.WAITING && Factory.INSTANCE.L3.currentState == StorageState.IDLE)
            {
                L2.Clear_all_requests();
                L2.Change_state(StorageState.IDLE);
            }
            // REG is able to request
            REG_viableChassis = Get_chassis(REG);

            if (REG_viableChassis.Count > 0)
            {
                // HAS CHASSIS
                Update_REG_ViableParts();

                if (REG_viableParts.Count > 0)
                {
                    // HAS PARTS
                    Attach_parts();
                    Remove_completed_chassis();
                }
                else
                {
                    // NO PARTS
                    bool REG_IS_FULL = REG.freeSpace == 0;
                    switch (factoryMode)
                    {
                    case FactoryMode.OOP:

                        if (REG_IS_FULL)
                        {
                            REG.Dump_from_line_exceptType(0, Vehicle_PartType.CHASSIS, 1);
                        }
                        else
                        {
                            Request_viable_parts(REG_viableChassis[0]);
                        }

                        break;

                    case FactoryMode.DOD:

                        if (REG_IS_FULL)
                        {
                            REG.Dump_nonViable_chassis(CurrentChassisRequest, 0);
                        }
                        else
                        {
                            Request_currentTask_part(REG);
                        }
                        break;
                    }
                }
            }
            else
            { // NO CHASSIS
                if (REG.freeSpace > 0)
                {
                    REG.waitingForPartType = CurrentChassisRequest.part;
                    REG.Change_state(StorageState.WAITING);
                    L1.Request_chassis(CurrentChassisRequest);
                }
                else
                { // NO ROOM, DUMP
                    REG.Dump_from_line_exceptType(0, Vehicle_PartType.CHASSIS, 1);
                }
            }
        }

        if (factoryMode == FactoryMode.DOD)
        {
            Push_nonViable_chassis_to_shared_storage();
            Push_nonViable_parts_to_shared_storage();

            // if we're waiting for occupied parts, try to purge nonViable parts
            if (REG.currentState == StorageState.WAITING &&
                L1.currentState == StorageState.WAITING &&
                L2.currentState == StorageState.WAITING
                )
            {
                REG.Change_state(StorageState.IDLE);
                L1.Change_state(StorageState.IDLE);
                L2.Change_state(StorageState.IDLE);
            }

            if (L2.currentState == StorageState.IDLE)
            {
                Request_currentTask_part(L2);
            }
        }
    }