void ConnectTile(Point P) { //Check all tiles in range of 4 if (_city.CityArea.Contains(P)) { Listof_BuildTypes type = _e.Dictionaryof_BuildItems[_city.TileMap[P.X, P.Y].Type].BuildingType; for (int x = P.X + 1; x <= P.X + 4; x++) //x> { if (CheckTile(x, P.Y, P.X, P.Y, type)) { break; } } for (int x = P.X - 1; x >= P.X - 4; x--) //x< { if (CheckTile(x, P.Y, P.X, P.Y, type)) { break; } } for (int y = P.Y + 1; y <= P.Y + 4; y++) //y> { if (CheckTile(P.X, y, P.X, P.Y, type)) { break; } } for (int y = P.Y - 1; y >= P.Y - 4; y--) //y< { if (CheckTile(P.X, y, P.X, P.Y, type)) { break; } } } bool CheckTile(int x, int y, int Sx, int Sy, Listof_BuildTypes SType) { City_Tyle tile = _city.TileMap[Sx, Sy]; if (_city.CityArea.Contains(new Point(x, y))) { if (SType == Listof_BuildTypes.Zone || SType == Listof_BuildTypes.Structure) { if (_e.Dictionaryof_BuildItems[_city.TileMap[x, y].Type].BuildingType == Listof_BuildTypes.Road) { _city.TileMap[x, y].ConnectTile(tile); return(true); } } if (SType == Listof_BuildTypes.Road) { if (_e.Dictionaryof_BuildItems[_city.TileMap[x, y].Type].BuildingType == Listof_BuildTypes.Structure || _e.Dictionaryof_BuildItems[_city.TileMap[x, y].Type].BuildingType == Listof_BuildTypes.Zone) { tile.ConnectTile(_city.TileMap[x, y]); } else if (_e.Dictionaryof_BuildItems[_city.TileMap[x, y].Type].BuildingType == Listof_BuildTypes.Road) { return(true); } } } return(false); } }
void CheckBuildable(Listof_BuildTypes B) { BuildCost = 0; Buildable = true; Typeof_BuildItems BuildData = _e.Dictionaryof_BuildItems[Building]; if (B == Listof_BuildTypes.Road) { Point P1, P2, P3; //Set building points X and Y if (BuildPoint1.X <= BuildPoint2.X) { P1.X = BuildPoint1.X; P2.X = BuildPoint2.X; } else { P1.X = BuildPoint2.X; P2.X = BuildPoint1.X; } if (BuildPoint1.Y <= BuildPoint2.Y) { P1.Y = BuildPoint1.Y; P2.Y = BuildPoint2.Y; } else { P1.Y = BuildPoint2.Y; P2.Y = BuildPoint1.Y; } //Set shortest angle int ShortX = Math.Abs(BuildPoint1.X - BuildPoint2.X), ShortY = Math.Abs(BuildPoint1.Y - BuildPoint2.Y), Temp; if (Keyboard.GetState().IsKeyUp(Keys.LeftControl)) { Temp = ShortX; ShortX = ShortY; ShortY = Temp; } if (ShortY >= ShortX) { P3.X = BuildPoint2.X; P3.Y = BuildPoint1.Y; } else { P3.X = BuildPoint1.X; P3.Y = BuildPoint2.Y; } District district = _city.GetDistrictByPoint(P1); if (district != null) { for (int x = P1.X; x <= P2.X - 1; x++) { if (!district.Area.Contains(new Point(x, P3.Y))) { Buildable = false; return; } } for (int y = P1.Y; y <= P2.Y; y++) { if (!district.Area.Contains(new Point(P3.X, y))) { Buildable = false; return; } } } else { Buildable = false; return; } //Check cost for (int x = P1.X; x <= P2.X - 1; x++) { if (_city.TileMap[x, P3.Y].Type != Building) { BuildCost += _e.Dictionaryof_BuildItems[Building].Cost; } } for (int y = P1.Y; y <= P2.Y; y++) { if (_city.TileMap[P3.X, y].Type != Building) { BuildCost += _e.Dictionaryof_BuildItems[Building].Cost; } } } if (B == Listof_BuildTypes.Zone) { Point P1, P2; //Set building points X and Y if (BuildPoint1.X <= BuildPoint2.X) { P1.X = BuildPoint1.X; P2.X = BuildPoint2.X; } else { P1.X = BuildPoint2.X; P2.X = BuildPoint1.X; } if (BuildPoint1.Y <= BuildPoint2.Y) { P1.Y = BuildPoint1.Y; P2.Y = BuildPoint2.Y; } else { P1.Y = BuildPoint2.Y; P2.Y = BuildPoint1.Y; } Rectangle buildzone = new Rectangle(P1.X, P1.Y, (P2.X - P1.X) + 1, (P2.Y - P1.Y) + 1); District district1 = _city.GetDistrictByPoint(P1); District district2 = _city.GetDistrictByPoint(P2); if (district1 != null && district2 != null && district1 == district2) { } else { Buildable = false; return; } //Add Cost for (int x = buildzone.Left; x < buildzone.Right; x++) { for (int y = buildzone.Top; y < buildzone.Bottom; y++) { if (_city.TileMap[x, y].Buildable == true && (_city.TileMap[x, y].Type != Building)) { BuildCost += _e.Dictionaryof_BuildItems[Building].Cost; } } } } if (B == Listof_BuildTypes.CityCenter) { Rectangle area = new Rectangle(BuildPoint1.X, BuildPoint1.Y, 1, 1); area.Inflate(20, 20); if (IntersectsDistrict(area)) { Buildable = false; } if (!_city.CityArea.Contains(area)) { Buildable = false; } BuildCost = BuildData.Cost; } if (B == Listof_BuildTypes.Structure) { for (int y = 0; y < BuildData.Size.Y; y++) { for (int x = 0; x < BuildData.Size.X; x++) { if (!_city.TileMap[BuildPoint1.X - x, BuildPoint1.Y - y].Buildable) { Buildable = false; } } } BuildCost = BuildData.Cost; } //No more Money :( if (BuildCost > Currency) { Buildable = false; } }