informa
3 MIN READ
News

GDC 2012: Breaking down SimCity's Glassbox engine

Maxis' new Glassbox engine is being future-proofed to make all of its future simulation games, not just the upcoming SimCity. We did into how the engine works, with simple code samples.
"You should be surprised by how simple this is, and frankly skeptical of how you can build a SimCity game out of this," joked Glassbox system designer Andrew Willmott at GDC on Wednesday. Willmott broke down how the Glassbox engine works on a basic level. Glassbox was built with all future Maxis-made simulations in mind (classics SimTower and SimCopter were namedropped as possible directions to go, though these are obviously not announced products), though for now it's being utilized just for the upcoming SimCity revival. The meat of a Glassbox-powered game is split into four object types: Resources, Units, Maps and Globals. These are tied together by Rules that are dictated by game scripts. Resources Resources are the basic currency in the game: oil, coal, crops, wood, water, electricity, etc. Resources come in bins: resource R has a capacity of C. Units Units represent things in the game, such as houses, factories, and people. Each unit has a state, which is a collection of resource bins. As an example, a house may have 20/30 units of food in its bin, and 4/10 people. A gas pump would only have bins of petrol, and a petrol station would have both petrol and cars. Maps Maps represent depletable resources in an environment: coal, oil, forest, but also air pollution, land value, desirability, etc. As an example, a map may have oil underground, that is being sucked out by a pump into its own local bin. Globals Globals are just a set of resource bins. For example: the amount of money in a town, the amount of electricity being used. Rules Rules provide the verbs in a game to handle the nouns provided by the above. Rules operate on resources: they move them from one place to another, or possibly combine them into other resources. They have inputs and outputs. This simple code example shows money being converted into wood if a person is available to make that transaction:

rule harvestWood
Money in 10
Wood out 2
People in 1

People out 1
end
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.

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
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:

mapRule growGrass
rate 200

map Soil atLeast 20

map water in 10
map Nutrients in 1

map Grass out 5
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:
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:
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.

Latest Jobs

Manticore Games

San Mateo, California
8.23.22
Senior Software Engineer - Mobile

Sony PlayStation

San Diego, California
6.23.22
Sr. Online Programmer

The Walt Disney Company

Glendale, California
8.1.22
Associate Marketing Manager - Walt Disney Games

Insomniac Games

Burbank, California
8.26.22
Accessibility Design Researcher
More Jobs   

CONNECT WITH US

Explore the
Subscribe to
Follow us

Game Developer Job Board

Game Developer Newsletter

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Subscribe
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more