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

Method crimeScan

MicropolisCore/src/MicropolisEngine/src/scan.cpp:403–450  ·  view source on GitHub ↗

Smooth police station map and compute crime rate */

Source from the content-addressed store, hash-verified

401
402/** Smooth police station map and compute crime rate */
403void Micropolis::crimeScan()
404{
405 smoothStationMap(&policeStationMap);
406 smoothStationMap(&policeStationMap);
407 smoothStationMap(&policeStationMap);
408
409 Quad totz = 0;
410 int numz = 0;
411 int cmax = 0;
412
413 for (int x = 0; x < WORLD_W; x += crimeRateMap.MAP_BLOCKSIZE) {
414 for (int y = 0; y < WORLD_H; y += crimeRateMap.MAP_BLOCKSIZE) {
415 int z = landValueMap.worldGet(x, y);
416 if (z > 0) {
417 ++numz;
418 z = 128 - z;
419 z += populationDensityMap.worldGet(x, y);
420 z = min(z, 300);
421 z -= policeStationMap.worldGet(x, y);
422 z = clamp(z, 0, 250);
423 crimeRateMap.worldSet(x, y, (Byte)z);
424 totz += z;
425
426 // Update new crime hot-spot
427 if (z > cmax || (z == cmax && (getRandom16() & 3) == 0)) {
428 cmax = z;
429 crimeMaxX = x;
430 crimeMaxY = y;
431 }
432
433 } else {
434 crimeRateMap.worldSet(x, y, 0);
435 }
436 }
437 }
438
439 if (numz > 0) {
440 crimeAverage = (short)(totz / numz);
441 } else {
442 crimeAverage = 0;
443 }
444
445 policeStationEffectMap = policeStationMap;
446
447 newMapFlags[MAP_TYPE_CRIME] = 1;
448 newMapFlags[MAP_TYPE_POLICE_RADIUS] = 1;
449 newMapFlags[MAP_TYPE_DYNAMIC] = 1;
450}
451
452
453/* comefrom: pollutionTerrainLandValueScan */

Callers

nothing calls this directly

Calls 5

smoothStationMapFunction · 0.85
minFunction · 0.85
clampFunction · 0.85
worldGetMethod · 0.80
worldSetMethod · 0.80

Tested by

no test coverage detected