Ejemplo n.º 1
0
    public void RefreshValidGridView(BuildingKey buildingKey)
    {
        void SetAllGridValid(bool valid)
        {
            for (int col = 0; col < CityInventory.Columns; col++)
            {
                for (int row = 0; row < CityInventory.Rows; row++)
                {
                    CityInventory.InventoryValidMatrix[col, row] = valid;
                }
            }
        }

        SetAllGridValid(false);
        for (int col = 0; col < CityInventory.Columns; col++)
        {
            for (int row = 0; row < CityInventory.Rows; row++)
            {
                bool valid = false;
                if (buildingKey != BuildingKey.None)
                {
                    BuildingCoverMaskGroup mask = CityInventory.BuildingCoverMaskMatrix[col, row];
                    BuildingInfo           bi   = LevelManager.Instance.BuildingInfoDict[buildingKey];
                    if ((mask & bi.forbidBuildingCover) == BuildingCoverMaskGroup.None)
                    {
                        foreach (BuildingCoverMaskGroup requireMask in bi.requireBuildingCoverList)
                        {
                            if (mask.HasFlag(requireMask))
                            {
                                valid = true;
                                CityInventory.InventoryValidMatrix[col, row] = true;
                                break;
                            }
                        }
                    }
                }

                cityInventoryGirdMatrix[col, row].SetValidOccupationPreview(valid);
            }
        }
    }
Ejemplo n.º 2
0
    public void RefreshBuildingRangeGridView(BuildingKey buildingKey)
    {
        void SetAllRangeGrids(CityInventoryGrid.PreviewBuildingRangeGridType showType)
        {
            for (int col = 0; col < CityInventory.Columns; col++)
            {
                for (int row = 0; row < CityInventory.Rows; row++)
                {
                    cityInventoryGirdMatrix[col, row].SetPreviewBuildingRange(showType);
                }
            }
        }

        SetAllRangeGrids(CityInventoryGrid.PreviewBuildingRangeGridType.None);
        // outer Range
        for (int col = 0; col < CityInventory.Columns; col++)
        {
            for (int row = 0; row < CityInventory.Rows; row++)
            {
                if (buildingKey != BuildingKey.None)
                {
                    BuildingCoverMaskGroup mask = CityInventory.BuildingCoverMaskMatrix_IncludingPreview[col, row];
                    BuildingInfo           bi   = LevelManager.Instance.BuildingInfoDict[buildingKey];
                    if (bi.provideBuildingCoverOuterRange != BuildingCoverMaskGroup.None && (mask.HasFlag(bi.provideBuildingCoverOuterRange)))
                    {
                        cityInventoryGirdMatrix[col, row].SetPreviewBuildingRange(CityInventoryGrid.PreviewBuildingRangeGridType.Outer);
                    }
                }
            }
        }

        // inner Range
        for (int col = 0; col < CityInventory.Columns; col++)
        {
            for (int row = 0; row < CityInventory.Rows; row++)
            {
                if (buildingKey != BuildingKey.None)
                {
                    BuildingCoverMaskGroup mask = CityInventory.BuildingCoverMaskMatrix_IncludingPreview[col, row];
                    BuildingInfo           bi   = LevelManager.Instance.BuildingInfoDict[buildingKey];
                    if (bi.provideBuildingCoverInnerRange != BuildingCoverMaskGroup.None && (mask.HasFlag(bi.provideBuildingCoverInnerRange)))
                    {
                        cityInventoryGirdMatrix[col, row].SetPreviewBuildingRange(CityInventoryGrid.PreviewBuildingRangeGridType.Inner);
                    }
                }
            }
        }

        // occupation
        for (int col = 0; col < CityInventory.Columns; col++)
        {
            for (int row = 0; row < CityInventory.Rows; row++)
            {
                if (buildingKey != BuildingKey.None)
                {
                    BuildingCoverMaskGroup mask = CityInventory.BuildingCoverMaskMatrix_IncludingPreview[col, row];
                    BuildingInfo           bi   = LevelManager.Instance.BuildingInfoDict[buildingKey];
                    if (bi.provideBuildingCoverByOccupation != BuildingCoverMaskGroup.None && (mask.HasFlag(bi.provideBuildingCoverByOccupation)))
                    {
                        cityInventoryGirdMatrix[col, row].SetPreviewBuildingRange(CityInventoryGrid.PreviewBuildingRangeGridType.Occupation);
                    }
                }
            }
        }

        // previewing invalid occupation
        for (int col = 0; col < CityInventory.Columns; col++)
        {
            for (int row = 0; row < CityInventory.Rows; row++)
            {
                if (buildingKey != BuildingKey.None)
                {
                    InventoryItem item = CityInventory.InventoryItemMatrix[col, row];
                    if (CityInventory.InventoryInfo.HasPreviewItem(item))
                    {
                        BuildingInfo bi = LevelManager.Instance.BuildingInfoDict[buildingKey];
                        bool         needAllOccupationValid = bi.NeedAllOccupationValid;
                        bool         valid = false;
                        if (needAllOccupationValid)
                        {
                            valid = true;
                            foreach (GridPos gp in item.OccupiedGridPositions_Matrix)
                            {
                                if (CityInventory.ContainsGP(gp))
                                {
                                    if (!CityInventory.InventoryValidMatrix[gp.x, gp.z])
                                    {
                                        valid = false;
                                    }
                                }
                                else
                                {
                                    valid = false;
                                }
                            }
                        }
                        else
                        {
                            if (CityInventory.ContainsGP(item.GridPos_Matrix))
                            {
                                if (CityInventory.InventoryValidMatrix[item.GridPos_Matrix.x, item.GridPos_Matrix.z])
                                {
                                    valid = true;
                                }
                            }
                            else
                            {
                                valid = false;
                            }
                        }

                        if (!valid)
                        {
                            cityInventoryGirdMatrix[col, row].SetPreviewBuildingRange(CityInventoryGrid.PreviewBuildingRangeGridType.Forbid);
                        }
                    }
                }
            }
        }
    }