Skip to content

updateMap()

Jodoin, Nathan edited this page Nov 5, 2022 · 4 revisions

Update Map:

The Update Map function returns true or false depending on whether a change has been made to the map data. This boolean value is calculated true if any of the type-specific growth functions that are called within the update map function return true. If all subroutines of this function return false, then this function also returns false.

The Update Map function itself takes a list of all of the populated zones and iterates through each type of zone with its respective growth function.

The function consists of three subroutines for residential zone growth, commercial zone growth, and industrial zone growth.

The first list to be passed through a growth function is the commercial zone list. The commercial growth function takes a passed commercial zone and uses a switch taking the population of the passed zone to set the case which contains the current rules for growth.
The growth function will then compare the population to the population requirements for the current growth case, and track how many zones meet the population requirement. If the number of adjacent zones that meet the current case requirements the passed zone will then check for available goods from the connected industrial district and available workers from connected residential zones. If all of the criteria are met the passed zone will increase population by 1 and take goods and workers from the connected zones. The function will then return true to the update map function. If the function does not meet the requirements to grow at any point it will return false to the update map function.

The next list to be iterated through its growth function is the industrial zones. The growth function takes a passed industrial zone and uses a switch which takes the passed zone's current population to determine the case which contains the current rules for growth. The case will iterate through the passed zone's adjacent zones tracking how many of the adjacent populations meet the current growth requirement. If the population requirements are met then the function then looks to the adjacent residential zone checking for how many workers are available to the current industrial zone. If all requirements are met the industrial zone will increase its population by 1, its goods by 1, and take required workers from connected residential zones. If industrial zone grows in this time step it returns true to the update map function. If the requirements to grow at any point are not met then the function will return false.

The last list to be iterated is the residential list. The residential growth function contains a switch that takes the current population of the zone being passed and compares the population through cases containing the rules for growth of that zone on that current time step.
The function will then go to the respective case and compare the adjacent populated zones to the population required and track how many times the population requirement has been met.
If the growth requirements have been met then the population of the passed residential zone will be increased along with the worker count of that zone. The function then returns true to the update map function. If the growth function does not meet the requirements to grow at any point the function will return false.

Clone this wiki locally