/// <summary> /// 为所有厢房安排工作人员 /// /// 建筑类型优先级因子中的厢房因子不能控制此处的厢房指派优先级,此处所有厢房必定优先于其他建筑指派。 /// </summary> private void AssignBedroomWorkers() { // 厢房 ID -> 该厢房辅助的建筑信息列表 // bedroomIndex -> [BuildingWorkInfo, ] var bedroomsForWork = Bedroom.GetBedroomsForWork(this.partId, this.placeId, this.buildings, this.attrCandidates, this.workerAttrs); // 更新辅助类厢房的优先级 // 辅助类厢房优先级 = SUM(相关建筑优先级) // bedroomIndex -> priority var auxiliaryBedroomsPriorities = new Dictionary <int, float>(); foreach (var entry in bedroomsForWork) { int bedroomIndex = entry.Key; var relatedBuildings = entry.Value; float priority = relatedBuildings.Select(info => info.priority).Sum(); auxiliaryBedroomsPriorities[bedroomIndex] = priority; } // 对于辅助类厢房,按优先级依次分配合适的人选 MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派辅助类厢房……")); var sortedAuxiliaryBedrooms = auxiliaryBedroomsPriorities.OrderByDescending(entry => entry.Value).Select(entry => entry.Key); foreach (int bedroomIndex in sortedAuxiliaryBedrooms) { int selectedWorkerId = this.SelectAuxiliaryBedroomWorker(bedroomIndex, bedroomsForWork[bedroomIndex]); if (selectedWorkerId >= 0) { Original.SetBuildingWorker(this.partId, this.placeId, bedroomIndex, selectedWorkerId); } Output.LogAuxiliaryBedroomAndWorker(bedroomIndex, bedroomsForWork[bedroomIndex], auxiliaryBedroomsPriorities[bedroomIndex], selectedWorkerId, this.partId, this.placeId, this.currDate, this.workerAttrs); } // 对于一般厢房,按优先级依次分配合适的人选 MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST, TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派一般厢房……")); var sortedBedrooms = this.buildings.Where(entry => entry.Value.IsBedroom()) .OrderByDescending(entry => entry.Value.priority).Select(entry => entry.Value); foreach (var info in sortedBedrooms) { if (this.excludedBuildings.Contains(info.buildingIndex)) { continue; } int selectedWorkerId = this.SelectBuildingWorker(info.buildingIndex, info.requiredAttrId); if (selectedWorkerId >= 0) { Original.SetBuildingWorker(this.partId, this.placeId, info.buildingIndex, selectedWorkerId); } Output.LogBuildingAndWorker(info, selectedWorkerId, this.partId, this.placeId, this.currDate, this.workerAttrs, suppressNoWorkerWarnning: true); } }