Warning: file_get_contents(http://s4p.us/a/api/?method=generateUrl&param=http%3A%2F%2Fpaste4.us%2Fview_paste%2F48%2F) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /home/content/82/8776282/html/evbpc.com/paste_system/code/view_paste.php on line 21
Simulate City Version 2
Fullscreen Options: With Syntax Highlighting | Plain Text | Design View
Short Link:
Simulate City Version 2
By EBrown
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
         #region Simulate City
        void SimulateCity(object sender, ElapsedEventArgs e)
        {
            day += 1;
            if (day == 29)
            {
                day = 1;
                month += 1;

                int rCashFlow = (int)(rPopulation * 500 * rTax);
                int cCashFlow = (int)(cPopulation * 300 * cTax);
                int iCashFlow = (int)(iPopulation * 200 * iTax);
                funds += rCashFlow + cCashFlow + iCashFlow;

                int powerCashFlow = (from building
                                     in buildings
                                     where building.type == BuildingType.PowerStation
                                     select building).Count<Building>() * 40000;
                int policeCashFlow = (from building
                                      in buildings
                                      where building.type == BuildingType.PoliceDepartment &&
                                           building.hasPower
                                      select building).Count<Building>() * 2500;
                int parkCashFlow = (from building
                                    in buildings
                                    where building.type == BuildingType.Park
                                    select building).Count<Building>() * 5;

                funds -= (powerCashFlow + policeCashFlow + parkCashFlow);
            }
            if (month == 13)
            {
                month = 1;
                year += 1;
            }

            rPopulation = 0;
            cPopulation = 0;
            iPopulation = 0;
            cityAmenities = 97;

            for (int i = 0; i < buildings.Count; i++)
            {
                if (buildings[i].hasPower)
                {
                    if (buildings[i].type == BuildingType.Residential)
                        rPopulation += buildings[i].population;
                    else if (buildings[i].type == BuildingType.Commercial)
                        cPopulation += buildings[i].population;
                    else if (buildings[i].type == BuildingType.Industrial)
                        iPopulation += buildings[i].population;
                    else if (buildings[i].type == BuildingType.PoliceDepartment)
                        cityAmenities += 50;
                }
                else if (buildings[i].type == BuildingType.Park)
                    cityAmenities += 5;
            }

            if (rPopulation > 0 || cPopulation > 0 || iPopulation > 0)
            {
                int totalWorkers = rPopulation;
                int totalJobs = cPopulation + iPopulation;
                int jobsAvailable = totalJobs - totalWorkers;
                int workersAvailable = totalWorkers - totalJobs;
                int totalAmenities = cityAmenities;

                if (jobsAvailable == 0)
                    jobsAvailable = 1;

                float amenitiesNeeded = rPopulation * 0.05f - totalAmenities;

                rDemand = jobsAvailable * (0.07f / rTax) - amenitiesNeeded;
                cDemand = (workersAvailable - ((float)cPopulation - (iPopulation > 0 ? iPopulation : 1))) * (.07f / cTax);
                iDemand = (workersAvailable - ((float)iPopulation - (cPopulation > 0 ? cPopulation : 1))) * (.07f / iTax);

                float max = Math.Max(Math.Abs(rDemand), Math.Max(Math.Abs(cDemand), Math.Abs(iDemand)));

                rDemand = rDemand / max;
                cDemand = cDemand / max;
                iDemand = iDemand / max;
            }
            else
            {
                rDemand = baseDemand;
                cDemand = 0;
                iDemand = 0;
            }

            if (rDemand >= 0f)
            {
                int popIncrease = (int)(rDemand * rand.Next(1015));

                List<Building> residentialBuildings = (from building
                                                       in buildings
                                                       where building.type == BuildingType.Residential &&
                                                            building.hasPower == true &&
                                                            building.population + popIncrease < building.maxPopulation &&
                                                            building.IsTouchingRoad(mapData, allRoadTiles)
                                                       select building).ToList<Building>();

                int pickedBuilding = rand.Next(0, residentialBuildings.Count);

                if (popIncrease < 1)
                    popIncrease = 1;

                residentialBuildings[pickedBuilding].IncreasePopulation(popIncrease, rand);
            }
            if (cDemand >= 0f)
            {
                int popIncrease = (int)(cDemand * rand.Next(1015));

                List<Building> commercialBuildings = (from building
                                                      in buildings
                                                      where building.type == BuildingType.Commercial &&
                                                           building.hasPower == true &&
                                                           building.population + popIncrease < building.maxPopulation &&
                                                           building.IsTouchingRoad(mapData, allRoadTiles)
                                                      select building).ToList<Building>();

                int pickedBuilding = rand.Next(0, commercialBuildings.Count);

                if (popIncrease < 1)
                    popIncrease = 1;

                commercialBuildings[pickedBuilding].IncreasePopulation(popIncrease, rand);
            }
            if (iDemand >= 0f)
            {
                int popIncrease = (int)(iDemand * rand.Next(1015));

                List<Building> industrialBuildings = (from building
                                                      in buildings
                                                      where building.type == BuildingType.Industrial &&
                                                           building.hasPower == true &&
                                                           building.population + popIncrease < building.maxPopulation &&
                                                           building.IsTouchingRoad(mapData, allRoadTiles)
                                                      select building).ToList<Building>();

                int pickedBuilding = rand.Next(0, industrialBuildings.Count);

                if (popIncrease < 1)
                    popIncrease = 1;

                industrialBuildings[pickedBuilding].IncreasePopulation(popIncrease, rand);
            }
        }
        #endregion