MCPcopy Create free account
hub / github.com/SimHacker/micropolis / doProblems

Method doProblems

MicropolisCore/src/MicropolisEngine/src/evaluate.cpp:231–269  ·  view source on GitHub ↗

* Evaluate problems of the city, take votes, and decide which are the most * important ones. * @param problemTable Storage of how bad each problem is. * @post \a problemTable contains severity of each problem, * #problemVotes contains votes of each problem, * #problemOrder contains (in decreasing order) the worst problems. */

Source from the content-addressed store, hash-verified

229 * #problemOrder contains (in decreasing order) the worst problems.
230 */
231void Micropolis::doProblems(short problemTable[PROBNUM])
232{
233 bool problemTaken[PROBNUM]; // Which problems are taken?
234
235 for (int z = 0; z < PROBNUM; z++) {
236 problemTaken[z] = false;
237 problemTable[z] = 0;
238 }
239
240 problemTable[CVP_CRIME] = crimeAverage; /* Crime */
241 problemTable[CVP_POLLUTION] = pollutionAverage; /* Pollution */
242 problemTable[CVP_HOUSING] = landValueAverage * 7 / 10; /* Housing */
243 problemTable[CVP_TAXES] = cityTax * 10; /* Taxes */
244 problemTable[CVP_TRAFFIC] = getTrafficAverage(); /* Traffic */
245 problemTable[CVP_UNEMPLOYMENT] = getUnemployment(); /* Unemployment */
246 problemTable[CVP_FIRE] = getFireSeverity(); /* Fire */
247 voteProblems(problemTable);
248
249 for (int z = 0; z < CVP_PROBLEM_COMPLAINTS; z++) {
250 // Find biggest problem not taken yet
251 int maxVotes = 0;
252 int bestProblem = CVP_NUMPROBLEMS;
253 for (int i = 0; i < CVP_NUMPROBLEMS; i++) {
254 if ((problemVotes[i] > maxVotes) && (!problemTaken[i])) {
255 bestProblem = i;
256 maxVotes = problemVotes[i];
257 }
258 }
259
260 // bestProblem == CVP_NUMPROBLEMS means no problem found
261 problemOrder[z] = bestProblem;
262 if (bestProblem < CVP_NUMPROBLEMS) {
263 problemTaken[bestProblem] = true;
264 }
265 // else: No problem found.
266 // Repeating the procedure will give the same result.
267 // Optimize by filling all remaining entries, and breaking out
268 }
269}
270
271
272/**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected