public void Dump_first_nonViable_part(VehiclePart_Config _targetPart) { if (getsPartsFrom.currentState != StorageState.FETCHING) { bool foundOnLine = false; int targetLine = -1; List <VehiclePart> dumpList = new List <VehiclePart>(); for (int _lineIndex = 0; _lineIndex < storageLines.Count; _lineIndex++) { for (int _slotIndex = 0; _slotIndex < lineLength; _slotIndex++) { VehiclePart _SLOT = Get_data_slot(_lineIndex, _slotIndex); if (_SLOT != null) { if (_SLOT.partConfig != _targetPart && _SLOT.partConfig.partType != Vehicle_PartType.CHASSIS) { dumpList.Add(_SLOT); targetLine = _lineIndex; foundOnLine = true; } } } if (foundOnLine) { break; } } sendingLineTo = getsPartsFrom; if (dumpList.Count > 0) { Change_state(StorageState.DUMP); Set_outgoing_parts(targetLine, dumpList.ToArray(), sendingLineTo); } } }
public void ALERT_WorkshopPartUnavailable(VehiclePart_Config _part) { L3.Clear_all_requests(); RAM.Clear_all_requests(); HD.Clear_all_requests(); L3.Change_state(StorageState.IDLE); RAM.Change_state(StorageState.IDLE); HD.Change_state(StorageState.IDLE); if (factoryMode == FactoryMode.OOP) { Workshop _purgeMe = null; int _leastUsedSpace = 999999; foreach (Workshop _WORKSHOP in workshops) { if (_WORKSHOP.usedSpace > 0 && _WORKSHOP.usedSpace < _leastUsedSpace) { _purgeMe = _WORKSHOP; _leastUsedSpace = _WORKSHOP.usedSpace; _WORKSHOP.Clear_all_requests_then_idle(); } } if (_purgeMe != null) { Debug.Log("PART SHORTAGE: " + _part); _purgeMe.Purge_parts_to_shared_storage(); } } }
public VehiclePart_Assignment(string _name, VehiclePart_Config _partConfig, Vector3 _position, Quaternion _rotation) { name = _name; partConfig = _partConfig; position = _position; rotation = _rotation; }
public void PartAttached(VehiclePart_Config _part, Workshop _workshop) { attachedParts[_part]++; //Debug.Log(_workshop.workshopIndex + " attached " + _part + " " + attachedParts[_part] + " / " + requiredParts[_part]); if (attachedParts[_part] == requiredParts[_part]) { if (factoryMode == FactoryMode.DOD) { workshopTasks.Remove(_workshop.currentTask); if (workshopTasks.Count > 0) { WorkshopTask _NEXT_TASK = Get_inactive_workshop_task(); if (_NEXT_TASK != null) { _workshop.Set_current_task(_NEXT_TASK); } else { _workshop.gameObject.active = false; } Debug.Log(_workshop.workshopIndex + " TASK COMPLETE: " + _part + ", new task: " + _workshop.currentTask.requiredParts.First().Key); } } } }
public void Request_viable_parts(VehiclePart_CHASSIS _chassis) { foreach (KeyValuePair <VehiclePart_Config, int> _PAIR in currentTask.requiredParts) { VehiclePart_Config _PART = _PAIR.Key; int _QUANTITY = _PAIR.Value; if (_PART.partType != Vehicle_PartType.CHASSIS) { if (currentTask.requiredParts.ContainsKey(_PAIR.Key)) { if (factoryMode == FactoryMode.OOP) { if (_chassis.partsFitted.ContainsKey(_PART)) { if (_chassis.partsFitted[_PART] >= _QUANTITY) { continue; } } } L1.Request_part(new VehiclePartRequest(_PAIR.Key, REG)); REG.waitingForPartType = _chassis.partsNeeded[0].partConfig; if (!purgingPartsToSharedStorage) { REG.Change_state(StorageState.WAITING); } return; } } } }
public VehicleChassiRequest(VehiclePart_Config _part, int _chassisVersion, Dictionary <VehiclePart_Config, int> _requiredParts, Storage _deliverTo, FactoryMode _factoryMode) : base(_part, _deliverTo) { part = _part; chassisVersion = _chassisVersion; requiredParts = _requiredParts; deliverTo = _deliverTo; factoryMode = _factoryMode; }
public void Set_current_task(WorkshopTask _task) { if (_task != null) { currentTask = _task; if (factoryMode == FactoryMode.DOD) { currentTaskPart = currentTask.requiredParts.First().Key; } } }
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); }
public bool Contains_nonViablePart(VehiclePart_Config _targetPart) { 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 && _PART.partConfig != _targetPart) { return(true); } } } } return(false); }
private void OnValidate() { Vector3 ChassisOffset = Vector3.zero; quantities = new Dictionary <VehiclePart_Config, int>(); if (designPrefab != null) { designName = designPrefab.name; requiredParts = new List <VehiclePart_Assignment>(); foreach (VehiclePart _PART in designPrefab.GetComponentsInChildren <VehiclePart>()) { if (_PART.partConfig.partType == Vehicle_PartType.CHASSIS) { ChassisOffset = _PART.transform.localPosition; break; } } foreach (VehiclePart _PART in designPrefab.GetComponentsInChildren <VehiclePart>()) { VehiclePart_Config _CONFIG = _PART.partConfig; Vector3 storedPos = (_CONFIG.partType == Vehicle_PartType.CHASSIS) ? _PART.transform.localPosition : _PART.transform.localPosition - ChassisOffset; VehiclePart_Assignment _temp = new VehiclePart_Assignment( _PART.name, _CONFIG, storedPos, _PART.transform.localRotation); requiredParts.Add(_temp); if (quantities.ContainsKey(_CONFIG)) { quantities[_CONFIG]++; } else { quantities.Add(_CONFIG, 1); } } } }
public bool AttachPart(VehiclePart_Config _part, GameObject _obj) { VehiclePart_Assignment _ASSIGNMENT = null; //Debug.Log("Trying to attach " + _part); foreach (VehiclePart_Assignment _PART_NEEDED in partsNeeded) { if (_PART_NEEDED.partConfig == _part) { _ASSIGNMENT = _PART_NEEDED; break; } } if (_ASSIGNMENT != null) { Transform _T = _obj.transform; _T.SetParent(transform); _T.localPosition = _ASSIGNMENT.position; _T.localRotation = _ASSIGNMENT.rotation; partsNeeded.Remove(_ASSIGNMENT); vehicleIsComplete = (partsNeeded.Count == 0); if (!partsFitted.ContainsKey(_ASSIGNMENT.partConfig)) { partsFitted[_ASSIGNMENT.partConfig] = 1; } else { partsFitted[_ASSIGNMENT.partConfig]++; } return(true); } else { return(false); } }
public VehiclePartRequest(VehiclePart_Config _part, Storage _deliverTo) { part = _part; deliverTo = _deliverTo; }
private void Get_RequiredParts() { // get total number of parts required foreach (KeyValuePair <VehicleDesign, int> _DESIGN_PAIR in vehicleOrder) { VehicleDesign _DESIGN = _DESIGN_PAIR.Key; int _TOTAL = _DESIGN_PAIR.Value; // Set number of completed vehicles to zero CompletedVehicles[_DESIGN] = 0; Debug.Log(_DESIGN.designName + " -- " + _TOTAL); foreach (KeyValuePair <VehiclePart_Config, int> _PartCount in _DESIGN.quantities) { VehiclePart_Config _partType = _PartCount.Key; if (requiredParts.ContainsKey(_partType)) { Debug.Log("req: " + _partType + " x " + _TOTAL); requiredParts[_partType] += _DESIGN.quantities[_partType] * _TOTAL; } else { Debug.Log("req: " + _partType + " x " + _TOTAL); requiredParts.Add(_partType, _DESIGN.quantities[_partType] * _TOTAL); attachedParts.Add(_partType, 0); } } } // summarise order and sling it into RAM Debug.Log("Part totals..."); foreach (KeyValuePair <VehiclePart_Config, int> _PAIR in requiredParts) { VehiclePart_Config _PART = _PAIR.Key; int _TOTAL = _PAIR.Value; GameObject _PART_PREFAB = _PART.prefab_part; Debug.Log(_PART.name + " x " + _TOTAL); List <VehiclePart_CHASSIS> _LIST_CHASSIS = new List <VehiclePart_CHASSIS>(); List <VehiclePart> _LIST_PARTS = new List <VehiclePart>(); for (int i = 0; i < _TOTAL; i++) { GameObject _part_OBJ = (GameObject)Instantiate(_PART_PREFAB, Vector3.zero, Quaternion.identity); if (_PART.partType == Vehicle_PartType.CHASSIS) { _LIST_CHASSIS.Add(_part_OBJ.GetComponent <VehiclePart_CHASSIS>()); var _TEMP_CHASSIS = _LIST_CHASSIS.Last(); _TEMP_CHASSIS.id = i; _TEMP_CHASSIS.name = _TEMP_CHASSIS.partConfig.partType + "_" + _TEMP_CHASSIS.id; } else { _LIST_PARTS.Add(_part_OBJ.GetComponent <VehiclePart>()); var _TEMP_PART = _LIST_PARTS.Last(); _TEMP_PART.id = i; _TEMP_PART.name = _TEMP_PART.partConfig.partType + "_" + _TEMP_PART.id; } } // parts are instantiated - now lets force_quickSave them into "PartsDeliveredTo" (usually RAM) if (_LIST_CHASSIS.Count > 0) { PartsDeliveredTo.Force_data_into_storage(_LIST_CHASSIS.ToArray()); } if (_LIST_PARTS.Count > 0) { PartsDeliveredTo.Force_data_into_storage(_LIST_PARTS.ToArray()); } } }