Exemple #1
0
 public bool Has_viable_chassis(VehicleChassiRequest _request)
 {
     for (int _lineIndex = 0; _lineIndex < storageLines.Count; _lineIndex++)
     {
         for (int _slotIndex = 0; _slotIndex < lineLength; _slotIndex++)
         {
             if (Is_chassis_viable(_lineIndex, _slotIndex, _request))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #2
0
    public bool Is_chassis_viable(int _lineIndex, int _slotIndex, VehicleChassiRequest _request)
    {
        VehiclePart         _SLOT    = Get_data_slot(_lineIndex, _slotIndex);
        VehiclePart_CHASSIS _CHASSIS = null;

        if (_SLOT != null)
        {
            if (_SLOT.partConfig.partType == Vehicle_PartType.CHASSIS)
            {     // part IS a chassis
                if (_SLOT.partConfig.partVersion == _request.chassisVersion || _request.factoryMode == FactoryMode.DOD)
                { // is Correct chassis type
                    _CHASSIS = _SLOT as VehiclePart_CHASSIS;
                }
            }
        }

        if (_CHASSIS != null)
        {
            if (_CHASSIS.partsNeeded.Count > 0)
            {
                var _PARTS_FITTED = _CHASSIS.partsFitted;

                // If chassis has less a defecit of our required parts, grab it
                foreach (KeyValuePair <VehiclePart_Config, int> _PAIR in _request.requiredParts)
                {
                    VehiclePart_Config _REQ_PART = _PAIR.Key;
                    if (_CHASSIS.design.quantities.ContainsKey(_REQ_PART))
                    {
                        int _QUANTITY = _CHASSIS.design.quantities[_REQ_PART];
                        if (_REQ_PART.partType != Vehicle_PartType.CHASSIS)
                        {
                            if (_CHASSIS.partsFitted.ContainsKey(_REQ_PART))
                            {
                                if (_CHASSIS.partsFitted[_REQ_PART] < _QUANTITY)
                                {
                                    return(true);
                                }
                            }
                            else
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
        }
        return(false);
    }
Exemple #3
0
    public void Change_state(StorageState _newState)
    {
        if (currentState != _newState)
        {
            taskStep     = 0;
            currentState = _newState;
            //Debug.Log(storageName + ": " + currentState);
            switch (currentState)
            {
            case StorageState.IDLE:
                // grab chassis / part if a request is pending
                if (current_CHASSIS_request != null)
                {
                    Request_chassis(current_CHASSIS_request);
                }
                else if (current_PART_request != null)
                {
                    Request_part(current_PART_request);
                }
                else if (next_CHASSIS_request != null)
                {
                    Debug.Log(storageName + " found NEXT CHASSIS req");
                    current_CHASSIS_request = next_CHASSIS_request;
                    next_CHASSIS_request    = null;
                    Request_chassis(current_CHASSIS_request);
                }
                else if (next_PART_request != null)
                {
                    current_PART_request = next_PART_request;
                    next_PART_request    = null;
                    Request_part(current_PART_request);
                }

                break;

            case StorageState.WAITING:
                break;

            case StorageState.FETCHING:
                break;
            }
        }
    }
Exemple #4
0
 public bool Has_nonViable_chassis(VehicleChassiRequest _request)
 {
     for (int _lineIndex = 0; _lineIndex < storageLines.Count; _lineIndex++)
     {
         for (int _slotIndex = 0; _slotIndex < lineLength; _slotIndex++)
         {
             VehiclePart _PART = Get_data_slot(_lineIndex, _slotIndex);
             if (_PART != null)
             {
                 if (_PART.partConfig.partType == Vehicle_PartType.CHASSIS)
                 {
                     if (!Is_chassis_viable(_lineIndex, _slotIndex, _request))
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
Exemple #5
0
    public void Request_chassis(VehicleChassiRequest _request)
    {
        if (currentState == StorageState.IDLE)
        {
            sendingLineTo = _request.deliverTo;
            sendingLineTo.waitingForPartType = _request.part;

            current_CHASSIS_request = null;

            if (freeSpace > 0)
            {
                // HAS SPACE
                Do_chassis_request(_request);
            }
            else
            {
                // NO SPACE
                current_CHASSIS_request = _request;
                Dump_line();
            }
        }
    }
Exemple #6
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);
            }
        }
    }