public override void Construction() { AllDistrictDataList = new List <DistrictData>(); for (int i = 0; i < 2; i++) { DistrictData data = new DistrictData(); data.DistrictID = i; data.DistrictName = ""; data.DistrictDesc = ""; data.Type = i; data.Level = (ushort)i; data.CurrencyCost = i; data.MaterialCostList = ""; data.TimeCost = i; data.EffectList = ""; AllDistrictDataList.Add(data); } AllDistrictTypeList = new List <DistrictType>(); for (int i = 0; i < 2; i++) { DistrictType type = new DistrictType(); type.TypeID = i; type.TypeShape = ""; type.Icon = ""; type.ModelPath = ""; AllDistrictTypeList.Add(type); } }
public void BuildDistrict(int a) { DistrictType type = (DistrictType)a; Action OnTimerEnded = () => _AddSquare(type); planet.StartConstruction(type, OnTimerEnded); UpdateButtonStatus(); resourceUIManager.UpdateResourceUI(); switch (type) { case DistrictType.Electricity: electricityNum.text = (planet.currentElectricityDistrictNum + planet.plannedElectricityDistrictNum) + "/" + planet.resourcesDistrictsMaxNum.maxElectricity; housingNum.text = (planet.currentHouseDistrictNum + planet.plannedHouseDistrictNum) + "/" + planet.availableHouseDistrictNum; break; case DistrictType.Mineral: mineralNum.text = (planet.currentMineralDistrictNum + planet.plannedMineralDistrictNum) + "/" + planet.resourcesDistrictsMaxNum.maxMineral; housingNum.text = (planet.currentHouseDistrictNum + planet.plannedHouseDistrictNum) + "/" + planet.availableHouseDistrictNum; break; case DistrictType.Food: foodNum.text = (planet.currentFoodDistrictNum + planet.plannedFoodDistrictNum) + "/" + planet.resourcesDistrictsMaxNum.maxFood; housingNum.text = (planet.currentHouseDistrictNum + planet.plannedHouseDistrictNum) + "/" + planet.availableHouseDistrictNum; break; case DistrictType.House: housingNum.text = (planet.currentHouseDistrictNum + planet.plannedHouseDistrictNum) + "/" + planet.availableHouseDistrictNum; break; } constructionQueue.PutElementOnQueue(planet); }
public void ErectMainBuilding(DistrictType dType) { mainBuilding = Instantiate(MainBuildings[(int)dType], this.transform.position, Quaternion.identity) as GameObject; mainBuilding.transform.Rotate(new Vector3(0f, Random.Range(0f, 360f), 0f)); mainBuilding.transform.SetParent(this.transform); }
public DistrictData(DistrictType type, Polygon shape) { Shape = shape; Type = type; Neigborhoods = new List <Polygon>(); BorderEdges = new List <HalfEdge>(); }
void RedesignDistrict(DistrictType districtType) { int designerId = (int)districtType; if (designerId > designers.Length) { Debug.LogError("No style found!", gameObject); return; } designers[designerId].Design(styleHolder); }
public static DistrictType GetDistrictType(DistrictData data) { DistrictType type = null; DistrictTypeDic.TryGetValue(data.Type, out type); if (type == null) { Debug.LogError("Can not Get districtType ID=" + data.Type); } return(type); }
public bool HasDistrictType(DistrictType type) { foreach (DistrictTile tile in DistrictList) { if (tile.Type == type && tile.State == DistrictState.Fine) { return(true); } } return(false); }
private bool UnlockDistrictType(DistrictType type) { foreach (DistrictTile tile in DistrictList) { if (tile.Type == DistrictType.Normal && tile.State == DistrictState.Fine) { tile.ChangeDistrictType(type); _completedType.Add(type); return(true); } } return(false); }
public void ExpandRandomDir(DistrictType districtType) { var neighbouring = HexGridHelper.FindAllNeighbours(this.TileRef.Coord).Select(x => BoardManager.FindTile(x)).Where(y => y != null && y.Feature == TileFeature.Village); if (neighbouring.Any()) { var candidate = neighbouring.PickOne(); var district = Instantiate(DistrictPrefab, candidate.transform.position, Quaternion.identity) as GameObject; district.GetComponent <DistrictTileMaster>().ErectMainBuilding(districtType); district.GetComponent <MapReference>().TileRef = candidate; candidate.CityRef = district; } }
public void ChangeDistrictType(DistrictType type) { Type = type; foreach (DistrictTypeImage districtTypeImage in DistrictTypeImageArray) { districtTypeImage.Image.gameObject.SetActive(false); } if (_districtTypeDictionary.ContainsKey(type)) { var districtStateImage = _districtTypeDictionary[type]; districtStateImage.gameObject.SetActive(true); } }
public District() { if (rand == null) { rand = new System.Random(); } cells = new List <DistrictCell>(); type = DistrictType.RESIDENTIAL; edgeTypeLeft = DistrictType.UNKNOWN; edgeTypeRight = DistrictType.UNKNOWN; edgeTypeUp = DistrictType.UNKNOWN; edgeTypeBottom = DistrictType.UNKNOWN; distancesCache = new Dictionary <District, float>(); relatedRoadSegments = null; }
private double GetPercentageOfCitizenLevel(DistrictType level) { double pm = random.NextDouble() * levelPlusMinus * 2.0 - levelPlusMinus; Debug.Assert(pm <= levelPlusMinus && pm >= -levelPlusMinus); if (level == DistrictType.Suburb) { return(levelOnePer + pm); } else if (level == DistrictType.Business) { return(levelThreePer + pm); } else { return(0.0); } }
public static List <Vector2> GetDistrictTypeArea(int DistrictID) { List <Vector2> result = new List <Vector2>(); DistrictType type = GetDistrictType(DistrictID); List <string> vectorList = Utility.TryParseStringList(type.TypeShape, ';'); for (int i = 0; i < vectorList.Count; i++) { List <int> vector = Utility.TryParseIntList(vectorList[i], ','); if (vector.Count != 2) { Debug.LogError("district type parse error ,vector=" + vector); return(result); } Vector2 v2 = new Vector2(vector[0], vector[1]); result.Add(v2); } return(result); }
public DistrictConfig GetDefinitionFor(DistrictType type) { if (!_typeConfigMap.TryGetValue(type, out DistrictConfig config)) { foreach (var cfg in DistrictConfigs) { if (type != cfg.DistrictType) { continue; } config = cfg; _typeConfigMap.Add(type, config); return(config); } throw new Exception($"{name} does not contain a definition for type {type}"); } return(config); }
public District GetDistrict(DistrictType type, Planet_Inhabitable planet) { switch (type) { case DistrictType.Electricity: return(new ElectricityDistrict(planet)); case DistrictType.Mineral: return(new MineralDistrict(planet)); case DistrictType.Food: return(new FoodDistrict(planet)); case DistrictType.House: return(new HouseDistrict(planet)); default: throw new NotImplementedException("Wait"); } }
public List <WardType> GetTypesFor(DistrictType districtType) { if (!_districtTypeToWardTypeMap.TryGetValue(districtType, out List <WardType> types)) { types = new List <WardType>(); foreach (var cfg in WardConfig) { if (!cfg.DistrictTypes.Contains(districtType)) { continue; } types.Add(cfg.WardType); } _districtTypeToWardTypeMap[districtType] = types; } return(types); }
public int GetConstructionCost(DistrictType type) { int result; switch (type) { case DistrictType.Food: case DistrictType.Electricity: case DistrictType.Mineral: result = 150; break; case DistrictType.House: result = 200; break; default: throw new InvalidOperationException("Invalid DistrictType detected!"); } return((int)(result / planet.game.constructionCostModifier)); }
/// <summary> /// Assigns district types by the direct neighbors /// </summary> private void GenerateDistricts() { if (Polygons.Count == 0) { return; } DistrictType type = DistrictType.TownSqaure; // TODO : having this here again is ugly, refactor later! var config = DefinitionContainer.GetDefinitionFor(type); var townSquare = new DistrictData(type, Polygons[0]); townSquare.InitialType = config.InitialSpawnType; PolygonIdToDistrictMap[Polygons[0]] = townSquare; for (int i = 1; i < Polygons.Count; i++) { var region = Polygons[i]; if (region.IsBorderPolygon()) { type = DistrictType.Farmland; } else { type = GetDistrictTypeForRegion(region); } config = DefinitionContainer.GetDefinitionFor(type); DistrictData district = new DistrictData(type, region); district.InitialType = config.InitialSpawnType; PolygonIdToDistrictMap[region] = district; } }
private void _AddSquare(DistrictType type) { switch (type) { case DistrictType.House: housingSqrs.GetChild(planet.currentHouseDistrictNum - 1).GetChild(0).gameObject.SetActive(true); break; case DistrictType.Electricity: electricitySqrs.GetChild(planet.currentElectricityDistrictNum - 1).GetChild(0).gameObject.SetActive(true); break; case DistrictType.Mineral: mineralSqrs.GetChild(planet.currentMineralDistrictNum - 1).GetChild(0).gameObject.SetActive(true); break; case DistrictType.Food: foodSqrs.GetChild(planet.currentFoodDistrictNum - 1).GetChild(0).gameObject.SetActive(true); break; default: throw new InvalidOperationException("Invalid District: " + type); } }
public Sprite GetHouseSprite(DistrictType level, int index) { return(houseBuildings[(int)level][index]); }
public int GetNumberOfCitizensOfLevel(DistrictType lvl) { return(citizenLevels[(int)lvl - 1]); }
public static bool IsACityTile(DistrictType districtType) { return(districtType == DistrictType.Extension || districtType == DistrictType.Center); }
public District(DistrictType type, int level) { this.Type = type; this.Level = level; }
public void SetCitizenLevel(DistrictType level) { this.citizenLevel = level; }
public bool IsMineralEnough(DistrictType type) { return(planet.planetaryResources.mineral >= GetConstructionCost(type)); }
public int GetRandomHouseIndex(DistrictType district, Random r) { Debug.Assert(district != DistrictType.None); Sprite[] array = houseBuildings[(int)district]; return(r.Next(array.Length)); }
public Tileset(XmlNode def, ContentManager Content) { XmlNodeList tiles = def.SelectNodes("normal/t"); Texture2D tex = Content.Load <Texture2D>(def.Attributes["atlas"].Value); sprites = new Sprite[(int)TileType.Count][]; name = def.Attributes["name"].Value; sprites[(int)TileType.Nothing] = new Sprite[16]; foreach (XmlNode t in tiles) { int slopeIndex = int.Parse(t.Attributes["slope"].Value); int x = int.Parse(t.Attributes["x"].Value); int y = int.Parse(t.Attributes["y"].Value); int w = int.Parse(t.Attributes["w"].Value); int h = int.Parse(t.Attributes["h"].Value); sprites[(int)TileType.Nothing][slopeIndex] = new Sprite(tex, new Rectangle(x, y, w, h), Color.White); } sprites[(int)TileType.Water] = new Sprite[16]; tiles = def.SelectNodes("water/t"); foreach (XmlNode t in tiles) { int slopeIndex = int.Parse(t.Attributes["slope"].Value); int x = int.Parse(t.Attributes["x"].Value); int y = int.Parse(t.Attributes["y"].Value); int w = int.Parse(t.Attributes["w"].Value); int h = int.Parse(t.Attributes["h"].Value); sprites[(int)TileType.Water][slopeIndex] = new Sprite(tex, new Rectangle(x, y, w, h), Color.White); } int c = 0; XmlNodeList houseLevels = def.SelectNodes("houses/district"); houseBuildings = new Sprite[5][]; for (int i = 0; i < 4; i++) { c = 0; DistrictType type = (DistrictType)Enum.Parse(typeof(DistrictType), houseLevels[i].Attributes["type"].Value); tiles = houseLevels[i].SelectNodes("t"); houseBuildings[(int)type] = new Sprite[tiles.Count]; foreach (XmlNode t in tiles) { int x = int.Parse(t.Attributes["x"].Value); int y = int.Parse(t.Attributes["y"].Value); int w = int.Parse(t.Attributes["w"].Value); int h = int.Parse(t.Attributes["h"].Value); houseBuildings[(int)type][c++] = new Sprite(tex, new Rectangle(x, y, w, h), Color.White); } } tiles = def.SelectNodes("pizzaBuildings/t"); sprites[(int)TileType.Pizza] = new Sprite[tiles.Count]; c = 0; foreach (XmlNode t in tiles) { int x = int.Parse(t.Attributes["x"].Value); int y = int.Parse(t.Attributes["y"].Value); int w = int.Parse(t.Attributes["w"].Value); int h = int.Parse(t.Attributes["h"].Value); sprites[(int)TileType.Pizza][c++] = new Sprite(tex, new Rectangle(x, y, w, h), Color.White); } tiles = def.SelectNodes("forest/t"); sprites[(int)TileType.Forest] = new Sprite[tiles.Count]; c = 0; foreach (XmlNode t in tiles) { int x = int.Parse(t.Attributes["x"].Value); int y = int.Parse(t.Attributes["y"].Value); int w = int.Parse(t.Attributes["w"].Value); int h = int.Parse(t.Attributes["h"].Value); sprites[(int)TileType.Forest][c++] = new Sprite(tex, new Rectangle(x, y, w, h), Color.White); } tiles = def.SelectNodes("stone/t"); sprites[(int)TileType.Stone] = new Sprite[tiles.Count]; c = 0; foreach (XmlNode t in tiles) { int x = int.Parse(t.Attributes["x"].Value); int y = int.Parse(t.Attributes["y"].Value); int w = int.Parse(t.Attributes["w"].Value); int h = int.Parse(t.Attributes["h"].Value); sprites[(int)TileType.Stone][c++] = new Sprite(tex, new Rectangle(x, y, w, h), Color.White); } tiles = def.SelectNodes("coal/t"); sprites[(int)TileType.Coal] = new Sprite[tiles.Count]; c = 0; foreach (XmlNode t in tiles) { int x = int.Parse(t.Attributes["x"].Value); int y = int.Parse(t.Attributes["y"].Value); int w = int.Parse(t.Attributes["w"].Value); int h = int.Parse(t.Attributes["h"].Value); sprites[(int)TileType.Coal][c++] = new Sprite(tex, new Rectangle(x, y, w, h), Color.White); } tiles = def.SelectNodes("ore/t"); sprites[(int)TileType.Ore] = new Sprite[tiles.Count]; c = 0; foreach (XmlNode t in tiles) { int x = int.Parse(t.Attributes["x"].Value); int y = int.Parse(t.Attributes["y"].Value); int w = int.Parse(t.Attributes["w"].Value); int h = int.Parse(t.Attributes["h"].Value); sprites[(int)TileType.Ore][c++] = new Sprite(tex, new Rectangle(x, y, w, h), Color.White); } tiles = def.SelectNodes("oil/t"); sprites[(int)TileType.Oil] = new Sprite[tiles.Count]; c = 0; foreach (XmlNode t in tiles) { int x = int.Parse(t.Attributes["x"].Value); int y = int.Parse(t.Attributes["y"].Value); int w = int.Parse(t.Attributes["w"].Value); int h = int.Parse(t.Attributes["h"].Value); sprites[(int)TileType.Oil][c++] = new Sprite(tex, new Rectangle(x, y, w, h), Color.White); } tiles = def.SelectNodes("roads/t"); roadSprites = new Dictionary <Tuple <int, int>, Sprite>(tiles.Count); c = 0; foreach (XmlNode t in tiles) { int roadDir = int.Parse(t.Attributes["roadDir"].Value); int slope = int.Parse(t.Attributes["slope"].Value); int x = int.Parse(t.Attributes["x"].Value); int y = int.Parse(t.Attributes["y"].Value); int w = int.Parse(t.Attributes["w"].Value); int h = int.Parse(t.Attributes["h"].Value); roadSprites.Add(new Tuple <int, int>(slope, roadDir), new Sprite(tex, new Rectangle(x, y, w, h), Color.White)); } tiles = def.SelectNodes("bridges/t"); bridgeSprites = new Dictionary <Tuple <int, int>, Sprite>(tiles.Count); c = 0; foreach (XmlNode t in tiles) { int roadDir = int.Parse(t.Attributes["roadDir"].Value); int slope = int.Parse(t.Attributes["slope"].Value); int x = int.Parse(t.Attributes["x"].Value); int y = int.Parse(t.Attributes["y"].Value); int w = int.Parse(t.Attributes["w"].Value); int h = int.Parse(t.Attributes["h"].Value); bridgeSprites.Add(new Tuple <int, int>(slope, roadDir), new Sprite(tex, new Rectangle(x, y, w, h), Color.White)); } tiles = def.SelectNodes("highlightSprites/s"); hightlightSprites = new Dictionary <string, Sprite>(); foreach (XmlNode s in tiles) { string name = s.Attributes["name"].Value; int x = int.Parse(s.Attributes["x"].Value); int y = int.Parse(s.Attributes["y"].Value); int w = int.Parse(s.Attributes["w"].Value); int h = int.Parse(s.Attributes["h"].Value); Rectangle rect = new Rectangle(x, y, w, h); Animation anim = new Animation(6, new double[] { 112, 96, 80, 64, 80, 96 }, new[] { rect }, new[] { new Point(0, 0), new Point(0, 2), new Point(0, 4), new Point(0, 6), new Point(0, 4), new Point(0, 2) }); hightlightSprites.Add(name, new Sprite(tex, rect, Color.White, anim)); } }
public DistrictFillInfo(Point p, DistrictType level) { startPoint = p; citizenLevel = level; }
private void CreateCitiesCellularAutomata(GeneratorParameter param, Tile[,] tiles) { var rooms = GeneratorHelper.GetCellularAutomataAsRooms(6, 53, true); HashSet <Room> toRemove = new HashSet <Room>(); int count = 7; foreach (Room room in rooms) { int size = room.Tiles.Count; if (size < 15) { toRemove.Add(room); continue; } int modX = 3; int modY = 3; if (random.NextDouble() < 0.5) { modX = random.Next(3, 6); } else { modY = random.Next(3, 6); } cities.Add(room); count += 7; double levelThree = GetPercentageOfCitizenLevel(DistrictType.Business); double levelOne = GetPercentageOfCitizenLevel(DistrictType.Suburb); foreach (Point p in room.Tiles) { Tile t = tiles[p.X, p.Y]; double prob = random.NextDouble(); DistrictType lvl = DistrictType.None; if (prob <= levelOne) { lvl = DistrictType.Suburb; } else if (prob <= levelOne + levelThree) { lvl = DistrictType.Business; } else { lvl = DistrictType.City; } if (t.type == TileType.Nothing && t.AllHeightsAreSame()) { if ((p.X % modX) == 0 || (p.Y % modY) == 0) { t.type = TileType.Road; } else { t.SetCitizenLevel(lvl); t.type = TileType.House; t.onTopIndex = param.tileset.GetRandomHouseIndex(t.citizenLevel); } } } room.Tiles.RemoveWhere((p) => tiles[p.X, p.Y].type == TileType.Water || tiles[p.X, p.Y].type == TileType.Forest); if (room.Tiles.Count < 15) { toRemove.Add(room); continue; } } cities.RemoveAll((r) => toRemove.Contains(r)); }
private void MakeCityDistricts(Room cityRoom, float avgCitySize) { HashSet <Point> totalVisitedPoints = new HashSet <Point>(); int size = cityRoom.Tiles.Count; float totalPoints = size / TILES_PER_DISTRICT; int suburbPoints = 0; int cityPoints = 0; int businessPoints = 0; int industryPoints = 0; //set number of points in fixed proportion, sizes of districts will vary based on point placement, so this shouldn't be noticable. suburbPoints = (int)(totalPoints * PROP_SUBURB); cityPoints = (int)(totalPoints * PROP_CITY); businessPoints = (int)(totalPoints * PROP_BUSINESS); industryPoints = (int)(totalPoints * PROP_INDUSTRY); //if city is small, but not very small and has no business/industry, put one point in. if (size < avgCitySize && size > avgCitySize / 2 && industryPoints == 0 && businessPoints == 0) { if (random.NextDouble() < 0.5) { businessPoints = 1; } else { industryPoints = 1; } } //due to int casting the number of points will not match totalPoints, so add suburb or city. while (suburbPoints + cityPoints + businessPoints + industryPoints < (int)totalPoints) { if (random.NextDouble() < 0.5) { suburbPoints += 1; } else { cityPoints += 1; } } //for very small cities, just set one suburb point. if (suburbPoints + cityPoints + businessPoints + industryPoints >= cityRoom.Tiles.Count) { suburbPoints = 1; cityPoints = 0; businessPoints = 0; industryPoints = 0; } //create the fill info for all the districts, generate random point. // +1 because later a city point is added in middle DistrictFillInfo[] fillInfos = new DistrictFillInfo[suburbPoints + cityPoints + businessPoints + industryPoints + 1]; for (int i = 0; i < suburbPoints + cityPoints + businessPoints + industryPoints; i++) { DistrictType lvl = DistrictType.None; if (i < suburbPoints) { lvl = DistrictType.Suburb; } else if (i < suburbPoints + cityPoints) { lvl = DistrictType.City; } else if (i < suburbPoints + cityPoints + businessPoints) { lvl = DistrictType.Business; } else if (i < suburbPoints + cityPoints + businessPoints + industryPoints) { lvl = DistrictType.Industry; } int index = random.Next(cityRoom.Tiles.Count - i); Point position = new Point(); int counter = 0; foreach (Point p in cityRoom.Tiles) { if (counter >= index && !totalVisitedPoints.Contains(p)) { position = p; break; } counter++; } fillInfos[i] = new DistrictFillInfo(position, lvl); } //add aditional city point in the mid point of the room, for possibility of Point mid = cityRoom.MiddlePoint; fillInfos[fillInfos.Length - 1] = new DistrictFillInfo(mid, DistrictType.City); //fill the city from the points, save nearest point and distance to it per Tile Dictionary <Tile, int> tileFillPairing = new Dictionary <Tile, int>(cityRoom.Tiles.Count); Dictionary <Tile, float> distToCenter = new Dictionary <Tile, float>(cityRoom.Tiles.Count); //init dictionaries foreach (Point p in cityRoom.Tiles) { Tile t = tiles[p.X, p.Y]; tileFillPairing.Add(t, 0); distToCenter.Add(t, float.MaxValue); } //fill city from each point and save the point to a tile if it is shorter than the points that filled before. for (int i = 0; i < fillInfos.Length; i++) { Point start = fillInfos[i].startPoint; Queue <Point> toVisit = new Queue <Point>(cityRoom.Tiles.Count); HashSet <Point> visited = new HashSet <Point>(); toVisit.Enqueue(start); visited.Add(start); while (toVisit.Count > 0) { Point p = toVisit.Dequeue(); Tile t = tiles[p.X, p.Y]; float dist = (p - start).ToVector2().LengthSquared(); if (dist < distToCenter[t]) { distToCenter[t] = dist; tileFillPairing[t] = i; } foreach (Point n in GeneratorHelper.IterateNeighboursFourDir(p.X, p.Y)) { if (cityRoom.Tiles.Contains(n) && !visited.Contains(n)) { toVisit.Enqueue(n); visited.Add(n); } } } } //decide based on nearest point, which house is what district type. foreach (Point p in cityRoom.Tiles) { Tile t = tiles[p.X, p.Y]; if (t.type == TileType.House) { int index = tileFillPairing[t]; DistrictType lvl = fillInfos[index].citizenLevel; t.SetCitizenLevel(lvl); t.onTopIndex = param.tileset.GetRandomHouseIndex(lvl, random); } } }