Пример #1
0
    public static BuildingCoverMaskGroup operator &(BuildingCoverMaskGroup a, BuildingCoverMaskGroup b)
    {
        BuildingCoverMaskGroup res = new BuildingCoverMaskGroup();

        res.Mask_Part1 = a.Mask_Part1 & b.Mask_Part1;
        res.Mask_Part2 = a.Mask_Part2 & b.Mask_Part2;
        res.Mask_Part3 = a.Mask_Part3 & b.Mask_Part3;
        return(res);
    }
Пример #2
0
    public override bool Equals(object obj)
    {
        if (obj == null)
        {
            return(false);
        }
        BuildingCoverMaskGroup objMask = obj is BuildingCoverMaskGroup ? (BuildingCoverMaskGroup)obj : default;

        return(this == objMask);
    }
Пример #3
0
    void Tick()
    {
        RefreshResourcesInfo();
        LevelManager.Instance.Budget     += LevelManager.Instance.BudgetNetIncrease;
        LevelManager.Instance.Oxygen     += LevelManager.Instance.OxygenNetIncrease;
        LevelManager.Instance.Population += LevelManager.Instance.PopulationNetIncrease;

        // calculate gold value decrease
        foreach (KeyValuePair <uint, Building> kv in BuildingDict)
        {
            if (CityInventory.InventoryInfo.HasPreviewItem(kv.Value.InventoryItem))
            {
                continue;
            }
            float budgetProduction = kv.Value.BuildingInfo.BudgetProduction * LevelManager.Instance.WorkingEfficiency;
            if (budgetProduction > 0)
            {
                float radius = kv.Value.BuildingInfo.provideBuildingCoverOuterRange_Radius; // treasure hunter radius
                for (int col_delta = Mathf.CeilToInt(-radius); col_delta <= Mathf.FloorToInt(radius); col_delta++)
                {
                    for (int row_delta = Mathf.CeilToInt(-radius); row_delta <= Mathf.FloorToInt(radius); row_delta++)
                    {
                        int final_col = kv.Value.InventoryItem.GridPos_Matrix.x + col_delta;
                        int final_row = kv.Value.InventoryItem.GridPos_Matrix.z + row_delta;
                        if (CityInventory.ContainsIndex(final_col, final_row))
                        {
                            if (col_delta * col_delta + row_delta * row_delta <= radius * radius)
                            {
                                BuildingCoverMaskGroup mask = CityInventory.BuildingCoverMaskMatrix[final_col, final_row];
                                if ((mask.Mask_Part2 & BuildingCoverMask_Part2.Gold) != BuildingCoverMask_Part2.None)
                                {
                                    float remainGold = cityInventoryGirdMatrix[final_col, final_row].GoldValue;
                                    budgetProduction = Mathf.Min(budgetProduction, remainGold);
                                    cityInventoryGirdMatrix[final_col, final_row].GoldValue -= budgetProduction;
                                    if (cityInventoryGirdMatrix[final_col, final_row].GoldValue <= 0)
                                    {
                                        CityInventory.BuildingCoverMaskMatrix[final_col, final_row].Mask_Part2 &= ~BuildingCoverMask_Part2.Gold;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Пример #4
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);
            }
        }
    }
Пример #5
0
    public static BuildingCoverMaskGroup TerrainTypeToMask(TerrainType tt)
    {
        switch (tt)
        {
        case TerrainType.None:
        {
            return(BuildingCoverMaskGroup.None);
        }

        case TerrainType.Gold_1:
        {
            BuildingCoverMaskGroup mask = new BuildingCoverMaskGroup();
            mask.Mask_Part2 = BuildingCoverMask_Part2.Gold_1;
            return(mask);
        }

        case TerrainType.Gold_2:
        {
            BuildingCoverMaskGroup mask = new BuildingCoverMaskGroup();
            mask.Mask_Part2 = BuildingCoverMask_Part2.Gold_2;
            return(mask);
        }

        case TerrainType.Gold_3:
        {
            BuildingCoverMaskGroup mask = new BuildingCoverMaskGroup();
            mask.Mask_Part2 = BuildingCoverMask_Part2.Gold_3;
            return(mask);
        }

        case TerrainType.Rock:
        {
            BuildingCoverMaskGroup mask = new BuildingCoverMaskGroup();
            mask.Mask_Part2 = BuildingCoverMask_Part2.Rock;
            return(mask);
        }
        }

        return(BuildingCoverMaskGroup.None);
    }
Пример #6
0
 public bool HasFlag(BuildingCoverMaskGroup target)
 {
     return(Mask_Part1.HasFlag(target.Mask_Part1) && Mask_Part2.HasFlag(target.Mask_Part2) && Mask_Part3.HasFlag(target.Mask_Part3));
 }
Пример #7
0
    public void RefreshResourcesInfo()
    {
        float budgetProductionTotal = 0;
        int   peopleDemandForBudgetProductionTotal = 0;
        int   budgetConsumptionTotal            = 0;
        int   oxygenProductionTotal             = 0;
        int   oxygenConsumptionCommonTotal      = 0;
        int   oxygenConsumptionForTreasureTotal = 0;
        int   oxygenCapacityTotal     = 1000;
        int   populationCapacityTotal = 0;

        foreach (KeyValuePair <uint, Building> kv in BuildingDict)
        {
            if (CityInventory.InventoryInfo.HasPreviewItem(kv.Value.InventoryItem))
            {
                continue;
            }
            budgetConsumptionTotal  += kv.Value.BuildingInfo.BudgetConsumption;
            oxygenProductionTotal   += kv.Value.BuildingInfo.OxygenProduction;
            oxygenCapacityTotal     += kv.Value.BuildingInfo.OxygenCapacity;
            populationCapacityTotal += kv.Value.BuildingInfo.PopulationCapacity;

            // calculate budget increase
            float budgetProduction = kv.Value.BuildingInfo.BudgetProduction;
            if (budgetProduction > 0)
            {
                oxygenConsumptionForTreasureTotal += kv.Value.BuildingInfo.OxygenConsumption;
                float radius = kv.Value.BuildingInfo.provideBuildingCoverOuterRange_Radius; // treasure hunter radius
                for (int col_delta = Mathf.CeilToInt(-radius); col_delta <= Mathf.FloorToInt(radius); col_delta++)
                {
                    for (int row_delta = Mathf.CeilToInt(-radius); row_delta <= Mathf.FloorToInt(radius); row_delta++)
                    {
                        int final_col = kv.Value.InventoryItem.GridPos_Matrix.x + col_delta;
                        int final_row = kv.Value.InventoryItem.GridPos_Matrix.z + row_delta;
                        if (CityInventory.ContainsIndex(final_col, final_row))
                        {
                            if (col_delta * col_delta + row_delta * row_delta <= radius * radius)
                            {
                                BuildingCoverMaskGroup mask = CityInventory.BuildingCoverMaskMatrix[final_row, final_row];
                                if ((mask.Mask_Part2 & BuildingCoverMask_Part2.Gold) != BuildingCoverMask_Part2.None)
                                {
                                    float remainGold = cityInventoryGirdMatrix[final_row, final_row].GoldValue;
                                    budgetProduction       = Mathf.Min(budgetProduction, remainGold);
                                    budgetProductionTotal += budgetProduction;
                                    peopleDemandForBudgetProductionTotal += kv.Value.BuildingInfo.PeopleDemandForBudgetProduction;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                oxygenConsumptionCommonTotal += kv.Value.BuildingInfo.OxygenConsumption;
            }
        }

        oxygenConsumptionCommonTotal += LevelManager.Instance.Population;

        LevelManager.Instance.PeopleDemandForBudgetProduction = peopleDemandForBudgetProductionTotal;
        LevelManager.Instance.BudgetProduction             = Mathf.RoundToInt(budgetProductionTotal * LevelManager.Instance.WorkingEfficiency);
        LevelManager.Instance.BudgetConsumption            = budgetConsumptionTotal;
        LevelManager.Instance.OxygenProduction             = oxygenProductionTotal;
        LevelManager.Instance.OxygenConsumptionCommon      = oxygenConsumptionCommonTotal;
        LevelManager.Instance.OxygenConsumptionForTreasure = Mathf.RoundToInt(oxygenConsumptionForTreasureTotal * LevelManager.Instance.WorkingEfficiency);
        LevelManager.Instance.OxygenCapacity     = oxygenCapacityTotal;
        LevelManager.Instance.PopulationCapacity = populationCapacityTotal;

        if (LevelManager.Instance.Population > LevelManager.Instance.Oxygen && (LevelManager.Instance.OxygenNetIncrease) < 0)
        {
            LevelManager.Instance.PopulationNetIncrease = LevelManager.Instance.Oxygen - LevelManager.Instance.Population;
        }
        else if (LevelManager.Instance.Population < LevelManager.Instance.PopulationCapacity && LevelManager.Instance.PopulationCapacity > 0)
        {
            float increaseFactor_Capacity          = (float)(LevelManager.Instance.PopulationCapacity - LevelManager.Instance.Population) / LevelManager.Instance.PopulationCapacity;
            float increaseFactor_OxygenNetIncrease = ((float)LevelManager.Instance.OxygenNetIncrease / (LevelManager.Instance.Population + 100));
            LevelManager.Instance.PopulationNetIncrease = Mathf.RoundToInt(LevelManager.Instance.PopulationCapacity * increaseFactor_Capacity * increaseFactor_OxygenNetIncrease * 0.1f);
        }
        else
        {
            LevelManager.Instance.PopulationNetIncrease = 0;
        }
    }
Пример #8
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);
                        }
                    }
                }
            }
        }
    }
Пример #9
0
    public void RefreshBuildingCoverMaskMatrix(bool includingPreview)
    {
        BuildingCoverMaskGroup[,] matrix = includingPreview ? CityInventory.BuildingCoverMaskMatrix_IncludingPreview : CityInventory.BuildingCoverMaskMatrix;

        void BatchSetRadiusGridCoverMask(BuildingCoverMaskGroup mask, int col, int row, float radius)
        {
            for (int col_delta = Mathf.CeilToInt(-radius); col_delta <= Mathf.FloorToInt(radius); col_delta++)
            {
                for (int row_delta = Mathf.CeilToInt(-radius); row_delta <= Mathf.FloorToInt(radius); row_delta++)
                {
                    int final_col = col + col_delta;
                    int final_row = row + row_delta;
                    if (CityInventory.ContainsIndex(final_col, final_row))
                    {
                        if (col_delta * col_delta + row_delta * row_delta <= radius * radius)
                        {
                            matrix[final_col, final_row] |= mask;
                        }
                    }
                }
            }
        }

        void ResetAllCoverMask()
        {
            for (int col = 0; col < CityInventory.Columns; col++)
            {
                for (int row = 0; row < CityInventory.Rows; row++)
                {
                    matrix[col, row] = BuildingCoverMaskGroup.None;
                }
            }
        }

        ResetAllCoverMask();
        for (int col = 0; col < CityInventory.Columns; col++)
        {
            for (int row = 0; row < CityInventory.Rows; row++)
            {
                CityInventoryGrid      terrainGrid = cityInventoryGirdMatrix[col, row];
                BuildingCoverMaskGroup terrainMask = CityInventoryGrid.TerrainTypeToMask(terrainGrid.TerrainType);
                matrix[col, row] |= terrainMask;

                InventoryItem item = CityInventory.InventoryItemMatrix[col, row];
                if (!includingPreview && CityInventory.InventoryInfo.HasPreviewItem(item))
                {
                    continue;
                }

                BuildingInfo buildingInfo = (BuildingInfo)item?.ItemContentInfo;
                if (buildingInfo != null)
                {
                    BatchSetRadiusGridCoverMask(buildingInfo.provideBuildingCoverInnerRange, item.GridPos_Matrix.x, item.GridPos_Matrix.z, buildingInfo.provideBuildingCoverInnerRange_Radius);
                    BatchSetRadiusGridCoverMask(buildingInfo.provideBuildingCoverOuterRange, item.GridPos_Matrix.x, item.GridPos_Matrix.z, buildingInfo.provideBuildingCoverOuterRange_Radius);
                    matrix[col, row] |= buildingInfo.provideBuildingCoverByOccupation;
                }

                if (!includingPreview)
                {
                    cityInventoryGirdMatrix[col, row].Mask = matrix[col, row];
                }
            }
        }
    }