Here is an example of a unit rule, showing a chaining effect: as a sim consumes mustard, they create an empty bottle, which then adds to a city's pollution. If mustard is unavailable, they then go buy more mustard.
rule harvestWood
Money in 10
Wood out 2
People in 1
People out 1
end
Map rules are simpler than that. In this example, grass will grow only where there's soil, water and nutrients, which are all depletable resources:
unitRule mustardFactory
rate 10
global Simoleans in 1
local YellowMustard in 6
local EmptyBottle in 1
local BottleOfMustard out 1
map Pollution out 5
successEvent effect smokePuff
successEvent audio chugAndSlurp
onFail buyMoreMustard
end
Zones Zones are well-defined areas, and a staple to Maxis games. Here's another code example, with a housing zone developing houses at a rate of 3 a day if there are enough builders available, and only where allowed:
mapRule growGrass
rate 200
map Soil atLeast 20
map water in 10
map Nutrients in 1
map Grass out 5
end
zoneRule developHouses
timeTrigger Day 0.5
sample random -count 3
test global Builders greater 5
test map Forest is 0
createUnit -id Bungalows
end
Agents
Agents are mobile things: they carry resources from one unit to another. They do not run rules -- Maxis says they want 10,000+ agents running around at once, so they keep them simple to allow that. Agents can be people, cars, or even units of water running through a pipe. Here's a code example of a car driving two people to work on roads:
timeTrigger Day 0.5
sample random -count 3
test global Builders greater 5
test map Forest is 0
createUnit -id Bungalows
end
unitRule goToWork
options -sendTo Work -via Car -using Road
local People in 2
agent People out 2
end
Each agent is given a destination: people may go home or to work, firemen may go to a fire, pollution may go into people.options -sendTo Work -via Car -using Road
local People in 2
agent People out 2
end