// 负责建筑数量多、能力种类少、厢房等级低的优先 private static int GetBedroomPriority(int partId, int placeId, int bedroomIndex, BedroomInfo bedroomInfo, Dictionary <int, BuildingWorkInfo> buildings) { // nbuildingsNeedBedroom: [1, 4] int nbuildingsNeedBedroom = bedroomInfo.buildingsNeedBedroom.Count; // nRequiredAttrIds: [1, 4] var requiredAttrIds = new HashSet <int>(); foreach (int buildingIndex in bedroomInfo.buildingsNeedBedroom) { var info = buildings[buildingIndex]; requiredAttrIds.Add(info.requiredAttrId); } int nRequiredAttrIds = requiredAttrIds.Count; // bedroomLevel: [1, 20] int[] building = DateFile.instance.homeBuildingsDate[partId][placeId][bedroomIndex]; int bedroomLevel = building[1]; // 4 buildings: 8+1, 8+2, 8+3, 8+4 // 3 buildings: 6+2, 6+3, 6+4 // 2 buildings: 4+3, 4+4 // 1 buildings: 2+4 int priority = nbuildingsNeedBedroom * 200 + // [200, 800] (5 - nRequiredAttrIds) * 100 + // [100, 400] (21 - bedroomLevel) * 1; // [1, 20] return(priority); }
// 对于每个需要厢房才能满效率的建筑,尝试找到邻接厢房,生成建筑列表和候选厢房列表 private static void GetBedroomsForWork_PrepareData(int partId, int placeId, Dictionary <int, BuildingWorkInfo> buildings, Dictionary <int, List <int> > attrCandidates, Dictionary <int, Dictionary <int, int> > workerAttrs, Dictionary <int, BuildingInfo> buildingsNeedBedroom, Dictionary <int, BedroomInfo> bedroomCandidates) { // 遍历所有建筑 foreach (var info in buildings.Values) { // 排除厢房 if (info.requiredAttrId == 0) { continue; } // 如果没有候选人,则不寻找邻接厢房 var sortedWorkerIds = attrCandidates[info.requiredAttrId]; if (sortedWorkerIds.Any()) { int workerId = sortedWorkerIds[0]; int attrMaxValue = workerAttrs[workerId][info.requiredAttrId]; // 凭单个候选人无法满效率 if (attrMaxValue < info.fullWorkingAttrValue) { // 找到邻接厢房,并创建供之后使用的数据结构 var adjacentBedrooms = Bedroom.GetAdjacentBedrooms(partId, placeId, info.buildingIndex); // 记录需要厢房的建筑信息 buildingsNeedBedroom[info.buildingIndex] = new BuildingInfo { buildingWorkInfo = info, adjacentBedrooms = adjacentBedrooms, }; // 记录候选厢房的信息 foreach (int bedroomBuildingIndex in adjacentBedrooms) { if (!bedroomCandidates.ContainsKey(bedroomBuildingIndex)) { bedroomCandidates[bedroomBuildingIndex] = new BedroomInfo { buildingIndex = bedroomBuildingIndex, buildingsNeedBedroom = new List <int>(), }; } bedroomCandidates[bedroomBuildingIndex].buildingsNeedBedroom.Add(info.buildingIndex); } } } } }