public WorkshopTask(VehicleDesign _design, Dictionary <VehiclePart_Config, int> _requiredParts, int _totalRequired = 0) { design = _design; requiredParts = _requiredParts; totalRequired = _totalRequired; tasksCompleted = 0; int partCount = 0; foreach (KeyValuePair <VehiclePart_Config, int> _PAIR in requiredParts) { if (_PAIR.Key.partType != Vehicle_PartType.CHASSIS) { partCount++; } } ratio_chassis_to_parts = 1 / (float)partCount; }
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()); } } }
private void ScheduleTasks() { // STEP ONE - order all the required parts VehicleDesign _DESIGN = vehicleOrder.Keys.First(); List <VehiclePart_Assignment> _PARTS = new List <VehiclePart_Assignment>(); foreach (VehiclePart_Assignment _REQUIRED_PART in _DESIGN.requiredParts) { _PARTS.Add(_REQUIRED_PART); } workshopTasks = new List <WorkshopTask>(); // STEP TWO - Depending on the approach (OOP / DOD), setup workshop tasks foreach (Workshop _WORKSHOP in workshops) { _WORKSHOP.Init(factoryMode); } switch (factoryMode) { case FactoryMode.OOP: // for each design - make a single workshop task to tackle it foreach (VehicleDesign _VEHICLE_DESIGN in vehicleOrder.Keys) { workshopTasks.Add(new WorkshopTask(_VEHICLE_DESIGN, _VEHICLE_DESIGN.quantities)); } foreach (Workshop _WORKSHOP in workshops) { _WORKSHOP.Set_current_task(workshopTasks[0]); } break; case FactoryMode.DOD: // for each design, add tasks to a macro list Dictionary <VehiclePart_Config, int> taskGroups = new Dictionary <VehiclePart_Config, int>(); List <VehiclePart_Config> _uniqueTasks = new List <VehiclePart_Config>(); foreach (VehicleDesign _VEHICLE_DESIGN in vehicleOrder.Keys) { foreach (var _DESIGN_PART in _VEHICLE_DESIGN.quantities.Keys) { if (_DESIGN_PART.partType != Vehicle_PartType.CHASSIS) { if (!_uniqueTasks.Contains(_DESIGN_PART)) { _uniqueTasks.Add(_DESIGN_PART); Dictionary <VehiclePart_Config, int> _targetPart = new Dictionary <VehiclePart_Config, int>(); _targetPart.Add(_DESIGN_PART, 1); workshopTasks.Add(new WorkshopTask(_VEHICLE_DESIGN, _targetPart, requiredParts[_DESIGN_PART])); Debug.Log("DOD: ADDED WORKSHOP TASK: " + _DESIGN_PART); } } } } for (int _workshopIndex = 0; _workshopIndex < workshops.Count; _workshopIndex++) { Workshop _W = workshops[_workshopIndex]; _W.Set_current_task(workshopTasks[_workshopIndex % workshopTasks.Count]); } break; } }