|
楼主 |
发表于 2012-3-8 16:19
|
显示全部楼层
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 1People 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 10global 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 200map 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.5sample 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 Roadlocal 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.
(原文...) |
|