public void RemoveTile(City_Tyle tile) { //Remove us from there list tile.RemoveRoadConnection(this); //Remove them from our list RemoveRoadConnection(tile); }
public void ConnectTile(City_Tyle tile) { //Add tile to our list AddRoadConnection(tile); //Add us to there list tile.AddRoadConnection(this); }
void AddRoadConnection(City_Tyle tile) { bool AlreadyAdded = false; foreach (var item in RoadContacts) { if (item == tile) { AlreadyAdded = true; } } if (ConnectedItems < 16 && !AlreadyAdded) { for (int n = 0; n <= 15; n++) { if (RoadContacts[n] == null) { RoadContacts[n] = tile; ConnectedItems++; break; } } } }
void RemoveRoadConnection(City_Tyle tile) { for (int n = 0; n <= 15; n++) { if (RoadContacts[n] != null) { if (RoadContacts[n] == tile) { RoadContacts[n] = null; ConnectedItems--; } } } }
public City(Point CitySize, Encyclopedia _e) { CityArea = new Rectangle(new Point(0, 0), CitySize); TileMap = new City_Tyle[CitySize.X, CitySize.Y]; districts = new HashSet <District>(); this._e = _e; for (int x = 0; x < CitySize.X; x++) { for (int y = 0; y < CitySize.Y; y++) { TileMap[x, y] = new City_Tyle(); } } }
public void Traffic_IO() { //First Pass set's all the traffic second pass adds traffic to roads Projected_Traffic.Clear(); foreach (var district in districts) { /* * for (int x = district.Area.Left; x < district.Area.Right; x++) * for (int y = district.Area.Top; y < district.Area.Bottom; y++) * TileMap[x, y].Traffic.Clear(); */ //Add traffic and get ConnectedList for (int x = district.Area.Left; x < district.Area.Right; x++) { for (int y = district.Area.Top; y < district.Area.Bottom; y++) { City_Tyle T = TileMap[x, y]; //Check and add Traffic Value to Tile //T.Traffic.AddTrafficFrom(T.Traffic); if (T.Constructing) { Projected_Traffic.AddTrafficFrom(_e.Dictionaryof_BuildItems[T.Type].Traffic); //T.Traffic.Clear(); } } } //Add all traffic to roads for (int x = district.Area.Left; x < district.Area.Right; x++) { for (int y = district.Area.Top; y < district.Area.Bottom; y++) { City_Tyle T = TileMap[x, y]; if (_e.Dictionaryof_BuildItems[T.Type].BuildingType == Listof_BuildTypes.Road) { T.TrafficByConnection(); } } } } }
public void Calculate_Power() { foreach (var district in districts) { district.PowerDrain = 0; district.PowerSupply = 0; for (int x = district.Area.Left; x < district.Area.Right; x++) { for (int y = district.Area.Top; y < district.Area.Bottom; y++) { //Temp setup City_Tyle T = TileMap[x, y]; district.PowerDrain += _e.Dictionaryof_BuildItems[T.Type].PowerDrain; district.PowerSupply += _e.Dictionaryof_BuildItems[T.Type].PowerSupply; } } } }
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); } }
public void Calculate_Growth() { //Grow constructed buildings based on time. foreach (var district in districts) { for (int v = 255; v >= 0; v--) { if (district.ValueList[v].Count > 0) { foreach (var t in district.ValueList[v]) { City_Tyle tile = TileMap[t.X, t.Y]; //Resadential if (_e.Dictionaryof_BuildItems[tile.Type].BuildingType == Listof_BuildTypes.Structure && _e.Dictionaryof_BuildItems[tile.Type].ZoneType == Listof_ZoneType.Residential) { if (tile.Constructing) { tile.Growth++; } if (tile.Growth == 4 && tile.SpriteIndex == 0) { tile.SpriteIndex = 1; tile.Constructing = false; } if (tile.Growth == 8 && tile.SpriteIndex == 2) { tile.SpriteIndex = 3; tile.Constructing = false; } if (tile.Growth == 12 && tile.SpriteIndex == 4) { tile.SpriteIndex = 5; tile.Constructing = false; } if (tile.Growth == 16 && tile.SpriteIndex == 6) { tile.SpriteIndex = 7; tile.Constructing = false; } if (tile.Growth == 20 && tile.SpriteIndex == 8) { tile.SpriteIndex = 9; tile.Constructing = false; } } //Commercial if (_e.Dictionaryof_BuildItems[tile.Type].BuildingType == Listof_BuildTypes.Structure && _e.Dictionaryof_BuildItems[tile.Type].ZoneType == Listof_ZoneType.Commercial) { if (tile.Constructing) { tile.Growth++; } if (tile.Growth == 8 && tile.SpriteIndex == 0) { tile.SpriteIndex = 1; tile.Constructing = false; } if (tile.Growth == 16 && tile.SpriteIndex == 2) { tile.SpriteIndex = 3; tile.Constructing = false; } if (tile.Growth == 20 && tile.SpriteIndex == 4) { tile.SpriteIndex = 5; tile.Constructing = false; } if (tile.Growth == 24 && tile.SpriteIndex == 6) { tile.SpriteIndex = 7; tile.Constructing = false; } if (tile.Growth == 30 && tile.SpriteIndex == 8) { tile.SpriteIndex = 9; tile.Constructing = false; } } //Industrial if (_e.Dictionaryof_BuildItems[tile.Type].BuildingType == Listof_BuildTypes.Structure && _e.Dictionaryof_BuildItems[tile.Type].ZoneType == Listof_ZoneType.Industrial) { if (tile.Constructing) { tile.Growth++; } if (tile.Growth == 12 && tile.SpriteIndex == 0) { tile.SpriteIndex = 1; tile.Constructing = false; } if (tile.Growth == 20 && tile.SpriteIndex == 2) { tile.SpriteIndex = 3; tile.Constructing = false; } if (tile.Growth == 30 && tile.SpriteIndex == 4) { tile.SpriteIndex = 5; tile.Constructing = false; } if (tile.Growth == 40 && tile.SpriteIndex == 6) { tile.SpriteIndex = 7; tile.Constructing = false; } if (tile.Growth == 50 && tile.SpriteIndex == 8) { tile.SpriteIndex = 9; tile.Constructing = false; } } } } } } foreach (var district in districts) { bool Built = false; int RGrowthLimit = 0, CGrowthLimit = 0, IGrowthLimit = 0; for (int v = 255; v >= 0; v--) { //One at a time //Check all tiles in the district based on value highest to lowest if (district.ValueList[v].Count > 0) { foreach (var t in district.ValueList[v]) { City_Tyle Tile = TileMap[t.X, t.Y]; if (ResidentialDemand > 0 && RGrowthLimit <= MaxGrowthRate) { if (Grow_Residential()) { ResidentialDemand -= _e.Dictionaryof_BuildItems[TileMap[t.X, t.Y].Type].Traffic.OriginJobsWorker; RGrowthLimit++; } } if (CommercialDemandWorker > 0 && CGrowthLimit <= MaxGrowthRate) { if (Grow_Commercial()) { CommercialDemandWorker -= _e.Dictionaryof_BuildItems[TileMap[t.X, t.Y].Type].Traffic.OriginCommerceWorker; CGrowthLimit++; } } if (IndustrialDemandBasic > 0 && IGrowthLimit <= MaxGrowthRate) { if (Grow_Industrial()) { IndustrialDemandBasic -= _e.Dictionaryof_BuildItems[TileMap[t.X, t.Y].Type].Traffic.OriginProducts; IGrowthLimit++; } } if (IndustrialDemandIntermediate > 0 && IGrowthLimit <= MaxGrowthRate) { if (Grow_Industrial()) { IndustrialDemandIntermediate -= _e.Dictionaryof_BuildItems[TileMap[t.X, t.Y].Type].Traffic.DestJobsCommoner; IGrowthLimit++; } } // If a worker can move in to the building and there is residential growth add a basic a worker class citizen if (Tile.Traffic.OriginJobsWorker + Tile.Traffic.OriginJobsCommoner + Tile.Traffic.OriginJobsElite < _e.Dictionaryof_BuildItems[Tile.Type].Traffic.Housing && Tile.Constructing == false && ResidentialGrowth > 0) { Tile.Traffic.OriginJobsWorker++; ResidentialGrowth--; } //If the district has enough education growth, upgrade the education of a pop. //Because of highest land value first growth, the high value areas will have the most educated workers first if (district.EducationGrowth[0] >= 10 && _e.Dictionaryof_BuildItems[Tile.Type].ZoneType == Listof_ZoneType.Residential && Tile.Traffic.OriginJobsWorker >= 1) { Tile.Traffic.OriginJobsWorker--; Tile.Traffic.OriginJobsCommoner++; district.EducationGrowth[0] -= 10; } //If constructing don't update Traffic. if (Tile.Constructing == false) { Tile.Traffic.Housing = _e.Dictionaryof_BuildItems[Tile.Type].Traffic.Housing; Tile.Traffic.OriginCommerceWorker = _e.Dictionaryof_BuildItems[Tile.Type].Traffic.OriginCommerceWorker; Tile.Traffic.OriginProducts = _e.Dictionaryof_BuildItems[Tile.Type].Traffic.OriginProducts; Tile.Traffic.DestJobsWorker = _e.Dictionaryof_BuildItems[Tile.Type].Traffic.DestJobsWorker; Tile.Traffic.DestCommerceWorker = _e.Dictionaryof_BuildItems[Tile.Type].Traffic.DestCommerceWorker; Tile.Traffic.DestProducts = _e.Dictionaryof_BuildItems[Tile.Type].Traffic.DestProducts; } bool Grow_Residential() { //**********Residential********** if (TileMap[t.X, t.Y].Type == Listof_Structures.ZoneResidential && ResidentialDemand >= 4) { TileMap[t.X, t.Y].Type = Listof_Structures.Residential_1; TileMap[t.X, t.Y].Constructing = true; Built = true; return(true); } if (TileMap[t.X, t.Y].Type == Listof_Structures.Residential_1 && ResidentialGrowth > 40) { TileMap[t.X, t.Y].Type = Listof_Structures.Residential_2; TileMap[t.X, t.Y].SpriteIndex = 2; TileMap[t.X, t.Y].Constructing = true; Built = true; return(true); } if (TileMap[t.X, t.Y].Type == Listof_Structures.Residential_2 && ResidentialGrowth > 400) { TileMap[t.X, t.Y].Type = Listof_Structures.Residential_3; TileMap[t.X, t.Y].SpriteIndex = 4; TileMap[t.X, t.Y].Constructing = true; Built = true; return(true); } /* * if (TileMap[t.X, t.Y].Type == Listof_Structures.Residential_4 && v > 16 && ResidentialDemand > 64) * { * TileMap[t.X, t.Y].Type = Listof_Structures.Residential_5; * TileMap[t.X, t.Y].SpriteIndex = 8; * TileMap[t.X, t.Y].Constructing = true; * Built = true; * return true; * } * * if (TileMap[t.X, t.Y].Type == Listof_Structures.Residential_3 && v > 14 && ResidentialDemand > 32) * { * TileMap[t.X, t.Y].Type = Listof_Structures.Residential_4; * TileMap[t.X, t.Y].SpriteIndex = 6; * TileMap[t.X, t.Y].Constructing = true; * Built = true; * return true; * } * * if (TileMap[t.X, t.Y].Type == Listof_Structures.Residential_2 && v > 12 && ResidentialDemand > 16) * { * TileMap[t.X, t.Y].Type = Listof_Structures.Residential_3; * TileMap[t.X, t.Y].SpriteIndex = 4; * TileMap[t.X, t.Y].Constructing = true; * Built = true; * return true; * } */ return(false); } //TODO Reverse flow bool Grow_Commercial() { //**********Commercial********** if (TileMap[t.X, t.Y].Type == Listof_Structures.ZoneCommercial && CommercialDemandWorker >= 8) { TileMap[t.X, t.Y].Type = Listof_Structures.Commercial_1; TileMap[t.X, t.Y].Constructing = true; Built = true; return(true); } if (TileMap[t.X, t.Y].Type == Listof_Structures.Commercial_1 && CommercialDemandWorker >= 80) { TileMap[t.X, t.Y].Type = Listof_Structures.Commercial_2; TileMap[t.X, t.Y].SpriteIndex = 2; TileMap[t.X, t.Y].Constructing = true; Built = true; return(true); } /* * if (TileMap[t.X, t.Y].Type == Listof_Structures.Commercial_2 && v > 40) * { * TileMap[t.X, t.Y].Type = Listof_Structures.Commercial_3; * TileMap[t.X, t.Y].SpriteIndex = 4; * TileMap[t.X, t.Y].Constructing = true; * Built = true; * return true; * } * if (TileMap[t.X, t.Y].Type == Listof_Structures.Commercial_3 && v > 40) * { * TileMap[t.X, t.Y].Type = Listof_Structures.Commercial_4; * TileMap[t.X, t.Y].SpriteIndex = 4; * TileMap[t.X, t.Y].Constructing = true; * Built = true; * return true; * } * if (TileMap[t.X, t.Y].Type == Listof_Structures.Commercial_5 && v > 40) * { * TileMap[t.X, t.Y].Type = Listof_Structures.Commercial_5; * TileMap[t.X, t.Y].SpriteIndex = 4; * TileMap[t.X, t.Y].Constructing = true; * Built = true; * return true; * } */ return(false); } bool Grow_Industrial() { //**********Industrial********** if (TileMap[t.X, t.Y].Type == Listof_Structures.Industrial_4 && v > 400000) { TileMap[t.X, t.Y].Type = Listof_Structures.Industrial_5; TileMap[t.X, t.Y].SpriteIndex = 8; TileMap[t.X, t.Y].Constructing = true; Built = true; return(true); } if (TileMap[t.X, t.Y].Type == Listof_Structures.Industrial_3 && v > 400000) { TileMap[t.X, t.Y].Type = Listof_Structures.Industrial_4; TileMap[t.X, t.Y].SpriteIndex = 6; TileMap[t.X, t.Y].Constructing = true; Built = true; return(true); } if (TileMap[t.X, t.Y].Type == Listof_Structures.Industrial_2 && v > 400000) { TileMap[t.X, t.Y].Type = Listof_Structures.Industrial_3; TileMap[t.X, t.Y].SpriteIndex = 4; TileMap[t.X, t.Y].Constructing = true; Built = true; return(true); } if (TileMap[t.X, t.Y].Type == Listof_Structures.Industrial_1 && IndustrialDemandIntermediate >= 20) { TileMap[t.X, t.Y].Type = Listof_Structures.Industrial_2; TileMap[t.X, t.Y].SpriteIndex = 2; TileMap[t.X, t.Y].Constructing = true; Built = true; return(true); } if (TileMap[t.X, t.Y].Type == Listof_Structures.ZoneIndustrial && IndustrialDemandBasic >= 10) { TileMap[t.X, t.Y].Type = Listof_Structures.Industrial_1; TileMap[t.X, t.Y].Constructing = true; Built = true; return(true); } return(false); } } } } } /* * if (ResidentialGrowth > 0 && WorkersSupply > 0 && WorkersDemand > 0) * ResidentialGrowthOverflow += ResidentialGrowth; * * if (ResidentialGrowthOverflow > WorkersSupply * 0.1) * ResidentialGrowthOverflow = WorkersSupply * 0.1; */ }
public void Calculate_JPC() { //ResidentialDemand = 0; //CommercialDemand = 0; //IndustrialDemand = 0; ResidentialDemandCap = 0; CommercialDemandCap = 0; IndustrialDemandCap = 0; foreach (var district in districts) { //Add Traffic district.ClearJPC(); Tile_Traffic Traff = new Tile_Traffic(); for (int x = district.Area.Left; x < district.Area.Right; x++) { for (int y = district.Area.Top; y < district.Area.Bottom; y++) { //Temp setup City_Tyle T = TileMap[x, y]; if (_e.Dictionaryof_BuildItems[T.Type].BuildingType == Listof_BuildTypes.Road) { Traff.AddTrafficFrom(T.Traffic); } //Add Education if (_e.Dictionaryof_BuildItems[T.Type].BuildingType == Listof_BuildTypes.Structure) { district.Education[0] += _e.Dictionaryof_BuildItems[T.Type].Education[0]; district.Education[1] += _e.Dictionaryof_BuildItems[T.Type].Education[1]; district.Education[2] += _e.Dictionaryof_BuildItems[T.Type].Education[2]; district.Education[3] += _e.Dictionaryof_BuildItems[T.Type].Education[3]; } } } //Education Growth district.EducationGrowth[0] += (int)Math.Floor(district.Education[0] * 0.1); //int WorkersSupply = 0, ProductsSupply = 0, CommerceSupply = 0; //int WorkersDemand = 0, ProductsDemand = 0, CommerceDemand = 0; //int ProductsAfterCommerce = 0; //float MaxGrowthRate = 5; //double WorkerMarket = 0, ProductsMarket = 0, CommerceMarket = 0; WorkersSupply = Convert.ToInt32(Traff.OriginJobsWorker); WorkersDemand = Convert.ToInt32(Traff.DestJobsWorker); CommonerSupply = Convert.ToInt32(Traff.OriginJobsCommoner); //WorkersDemand = Convert.ToInt32(Traff.DestJobsWorker); //Worker to Job Ratio if (WorkersDemand > 0) { WorkerMarket = (double)WorkersSupply / WorkersDemand; } else { WorkerMarket = 0; } //Job market ratio cap if (WorkerMarket > 1) { WorkerMarket = 1; } ProductsSupply = Convert.ToInt32(Math.Floor(Traff.OriginProducts * WorkerMarket)); ProductsDemand = Convert.ToInt32(Math.Floor(Traff.DestProducts * WorkerMarket)); ExcessProducts = ProductsSupply - ProductsDemand; ExcessCommerce = CommerceSupply - CommerceDemand; double CommerceBoost = 0; double IndustryBoost = 0; //Industry To Commerce if (ProductsDemand > 0) { ProductsMarket = (double)ProductsSupply / ProductsDemand; if (ProductsMarket > 1) { ProductsMarket = 1; } CommerceSupply = Convert.ToInt32(Math.Floor(Traff.OriginCommerceWorker * ProductsMarket)); IndustryBoost = WorkerMarket; } else { CommerceSupply = 0; } CommerceDemand = Convert.ToInt32(Math.Floor(Traff.DestCommerceWorker)); //Commerce To Residential if (CommerceDemand > 0) { CommerceMarket = (double)CommerceSupply / CommerceDemand; if (CommerceMarket > 1) { CommerceMarket = 1; } CommerceBoost = 0.5 + (0.5 * CommerceMarket); } else { CommerceMarket = 0; } district.Workers = WorkersSupply; district.Jobs[0] = WorkersDemand; district.JobMarket = WorkerMarket; district.Products = ExcessProducts; district.Commerce[0] = CommerceSupply; //ResidentialDemand = WorkersDemand - (WorkersSupply * CommerceBoost); //ResidentialDemand += (Traff.DestJobs * 1.15) - Traff.OriginJobs - Projected_Traffic.OriginJobs; //CommercialDemand += (Traff.DestCommerce * 1.10) - Traff.OriginCommerce - Projected_Traffic.OriginCommerce; //IndustrialDemand += (Traff.DestProducts * 1.10) - Traff.OriginProducts - Projected_Traffic.OriginProducts; //(CommerceMarket - 0.5) double Unemployment = 0; if (WorkersSupply > 0) { Unemployment = 1 - (double)WorkersDemand / (double)WorkersSupply; } else { Unemployment = 0; } Unemployment *= 100; // WorkerHappiness sets move in rates, they will move in based on the job market up to 10 + 1% of population over the jobs available. double WorkerHappiness = ((100 + Traff.DestJobsWorker) * 1.1) / (100 + Traff.OriginJobsWorker); if (WorkerHappiness > 1) { WorkerHappiness = 1; } WorkerHappiness -= 0.9; WorkerHappiness *= 100; if (WorkerHappiness > 10 + Traff.OriginJobsWorker * 0.001) { WorkerHappiness = 10 + Traff.OriginJobsWorker * 0.001; } //10% unemployment if (Unemployment > 10) { WorkerHappiness = 0; } else { WorkerHappiness = Math.Floor((10 + Traff.OriginJobsWorker * 0.001)); } if (Traff.Housing == 0) { WorkerHappiness = 0; } ResidentialGrowth += Math.Floor(WorkerHappiness); //if (ResidentialGrowth > 0 && WorkersSupply > 0 && WorkersDemand > 0) //ResidentialGrowthOverflow += ResidentialGrowth; if (WorkersSupply > 0 && ResidentialGrowth > WorkersSupply * 0.1) { ResidentialGrowth = WorkersSupply * 0.1; } //1 - (decimal)_city.WorkersDemand / (decimal)_city.WorkersSupply, //ResidentialGrowth = Math.Floor((10 + Traff.OriginJobsWorker * 0.001)); //ResidentialDemand = 40 + (100 * CommerceMarket) + (Traff.OriginJobsWorker * 0.01) + (Traff.DestJobsWorker * CommerceMarket) - Traff.Housing - Projected_Traffic.Housing; //6% unemployment is max until it slows population growth ResidentialDemand = 1000; //128 + (Traff.OriginJobsWorker * 0.01) + Traff.DestJobsWorker - Traff.Housing - Projected_Traffic.Housing; CommercialDemandWorker = (Traff.DestCommerceWorker * 1.1 - Traff.OriginCommerceWorker) - Projected_Traffic.OriginCommerceWorker; IndustrialDemandBasic = (Traff.DestProducts * 1.1 - Traff.OriginProducts) - Projected_Traffic.OriginProducts; IndustrialDemandIntermediate = (Traff.OriginJobsCommoner - Traff.DestJobsCommoner) - Projected_Traffic.DestJobsCommoner; //IndustrialDemandAdvanced = (Traff.DestProducts - Traff.OriginProducts) - Projected_Traffic.OriginProducts; //if (ResidentialDemand > ResidentialDemandCap) ResidentialDemand = ResidentialDemandCap; //if (CommercialDemand > CommercialDemandCap) CommercialDemand = CommercialDemandCap; //if (IndustrialDemand > IndustrialDemandCap) IndustrialDemand = IndustrialDemandCap; } }
void ClearRoadConnection() { City_Tyle[] RoadContacts = new City_Tyle[16]; ConnectedItems = 0; }