"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
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
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 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 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 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 are just a set of resource bins. For example: the amount of money in a town, the amount of electricity being used.
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:
Money in 10
Wood out 2
People in 1
People out 1
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.
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
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:
map Soil atLeast 20
map water in 10
map Nutrients in 1
map Grass out 5
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:
timeTrigger Day 0.5
sample random -count 3
test global Builders greater 5
test map Forest is 0
createUnit -id Bungalows
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:
options -sendTo Work -via Car -using Road
local People in 2
agent People out 2
Each agent is given a destination: people may go home or to work, firemen may go to a fire, pollution may go into people.