Esempio n. 1
0
        /// <summary>
        /// 指派完厢房之后,继续指派其他建筑
        ///
        /// 其实本轮指派开始时仍有可能包含厢房,本轮临近结束时也仍有可能尚未指派厢房。
        /// 本轮最后厢房指派,不考虑是否达到心情好感阈值,只要还有人就往里放。
        /// 上次分配后还有厢房剩下的原因:人太少,辅助性厢房装不满;心情都挺好,一般厢房装不满。
        /// 本次分配后还有厢房剩下的原因:人太少。
        ///
        /// 建筑类型优先级因子中的厢房因子依然不能控制此处的厢房指派优先级,所有厢房在最后阶段指派。
        /// </summary>
        private void AssignLeftBuildings()
        {
            MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST,
                                                   TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派主要建筑……"));

            var sortedBuildings = this.buildings.OrderByDescending(entry => entry.Value.priority).Select(entry => entry.Value);

            foreach (var info in sortedBuildings)
            {
                if (this.excludedBuildings.Contains(info.buildingIndex))
                {
                    continue;
                }
                if (info.IsBedroom())
                {
                    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: false);
            }

            // 最后指派尚未指派的厢房
            MajordomoWindow.instance.AppendMessage(this.currDate, Message.IMPORTANCE_LOWEST,
                                                   TaiwuCommon.SetColor(TaiwuCommon.COLOR_DARK_GRAY, "开始指派尚未指派的厢房……"));

            sortedBuildings = this.buildings.OrderByDescending(entry => entry.Value.priority).Select(entry => entry.Value);
            foreach (var info in sortedBuildings)
            {
                if (this.excludedBuildings.Contains(info.buildingIndex))
                {
                    continue;
                }
                if (!info.IsBedroom())
                {
                    continue;
                }

                int selectedWorkerId = this.SelectLeftBedroomWorker(info.buildingIndex);
                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: false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 指派完厢房之后,继续指派其他建筑
        ///
        /// 其实本轮指派开始时仍有可能包含厢房,本轮临近结束时也仍有可能尚未指派厢房。
        /// 本轮开始的厢房指派按一般厢房指派规则进行。
        /// 本轮最后厢房指派,不考虑是否达到心情好感阈值,只要还有人就往里放。
        /// 第一次分配完后还有厢房剩下的原因:人太少,辅助性厢房装不满;心情都挺好,一般厢房装不满。
        /// 第二次分配完后还有厢房剩下的原因:人太少。
        /// </summary>
        private void AssignLeftBuildings()
        {
            Main.Logger.Log("开始指派主要建筑……");

            var sortedBuildings = this.buildings.OrderByDescending(entry => entry.Value.priority).Select(entry => entry.Value);

            foreach (var info in sortedBuildings)
            {
                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.workerAttrs);
            }

            // 最后指派尚未指派的厢房
            Main.Logger.Log("开始指派尚未指派的厢房……");

            sortedBuildings = this.buildings.OrderByDescending(entry => entry.Value.priority).Select(entry => entry.Value);
            foreach (var info in sortedBuildings)
            {
                if (this.excludedBuildings.Contains(info.buildingIndex))
                {
                    continue;
                }
                if (!info.IsBedroom())
                {
                    continue;
                }

                int selectedWorkerId = this.SelectLeftBedroomWorker(info.buildingIndex);
                if (selectedWorkerId >= 0)
                {
                    Original.SetBuildingWorker(this.partId, this.placeId, info.buildingIndex, selectedWorkerId);
                }

                Output.LogBuildingAndWorker(info, selectedWorkerId, this.partId, this.placeId, this.workerAttrs);
            }
        }
Esempio n. 3
0
        /// <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, int>();

            foreach (var entry in bedroomsForWork)
            {
                int bedroomIndex     = entry.Key;
                var relatedBuildings = entry.Value;

                int basePriority = 7;
                int priority     = basePriority * WORKING_PRIORITY_STEP_SIZE + 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);
            }
        }