|
- using System;
- using System.Collections.Generic;
- using CIG3.ExtensionMethods;
- using SUISSEngine;
-
- public class CIGIslandStats
- {
- public CIGIslandStats(Dictionary<string, object> storage)
- {
- this._data = storage;
- }
-
- public void PopuplateStats(CityIsland island)
- {
- this.RoadCount = this.CountRoadsOn(island);
- this.DecorationsCount = this.CountDecorationsOn(island);
- this.MaxLevelBuildingCount = this.CountMaxLevelBuildings(island);
- }
-
- public int RoadCount
- {
- get
- {
- return this._data.GetValue("roads", 0);
- }
- set
- {
- this._data["roads"] = value;
- }
- }
-
- public int DecorationsCount
- {
- get
- {
- return this._data.GetValue("decorations", 0);
- }
- set
- {
- this._data["decorations"] = value;
- }
- }
-
- public int MaxLevelBuildingCount
- {
- get
- {
- return this._data.GetValue("maxLevelBuildings", 0);
- }
- set
- {
- this._data["maxLevelBuildings"] = value;
- }
- }
-
- private int CountDecorationsOn(CityIsland island)
- {
- if (island == null || island.isometricIsland == null)
- {
- return 0;
- }
- IsometricIsland isometricIsland = island.isometricIsland;
- int num = 0;
- List<Building> buildingsOnIsland = isometricIsland.BuildingsOnIsland;
- int count = buildingsOnIsland.Count;
- for (int i = 0; i < count; i++)
- {
- if (buildingsOnIsland[i] is CIGDecoration)
- {
- num++;
- }
- }
- return num;
- }
-
- private int CountMaxLevelBuildings(CityIsland island)
- {
- if (island == null || island.isometricIsland == null)
- {
- return 0;
- }
- IsometricIsland isometricIsland = island.isometricIsland;
- int num = 0;
- List<Building> buildingsOnIsland = isometricIsland.BuildingsOnIsland;
- int count = buildingsOnIsland.Count;
- for (int i = 0; i < count; i++)
- {
- CIGBuilding cigbuilding = buildingsOnIsland[i] as CIGBuilding;
- if (cigbuilding != null && cigbuilding.GetMaxLevel() > 1 && cigbuilding.GetMaxLevel() == cigbuilding.CurrentLevel)
- {
- num++;
- }
- }
- return num;
- }
-
- private int CountRoadsOn(CityIsland island)
- {
- if (island == null || island.isometricIsland == null || island.isometricIsland.grid == null)
- {
- return 0;
- }
- IsometricGrid grid = island.isometricIsland.grid;
- int num = 0;
- GridSize size = grid.Size;
- for (int i = 0; i < size.v; i++)
- {
- for (int j = 0; j < size.u; j++)
- {
- GridTile tile = grid[j, i].Tile;
- if (tile != null)
- {
- Road component = tile.GetComponent<Road>();
- if (component != null)
- {
- num++;
- }
- }
- }
- }
- return num;
- }
-
- private const string RoadCountKey = "roads";
-
- private const string MaxLevelBuildingCountKey = "maxLevelBuildings";
-
- private const string DecorationCountKey = "decorations";
-
- private Dictionary<string, object> _data;
- }
|