In terms of artificial intelligence, simulation games are often a step ahead of the mainstream. The actors interact with the players for much longer periods of time, and must find original ways keep their attention.
As the archetypal sim-game, The Sims revolutionized the industry by creating an interactive doll house, becoming the best selling PC game of all time in the process. The Sims is among Top 10 Most Influential AI Games for these reasons.
This technical review from AiGameDev.com looks into the technology behind this prolific franchise: things to adopt as well as what to avoid.
Objects play a very important part in the interactive doll house. Not only do they provide goals for the materialist gameplay, but they also create a rich environment for the AI actors to interact with. Implementing a system to handle large numbers of games is not an easy task.
Screenshot 1: A suburban household from The Sims 2.
1) Make Your Objects Self-Contained
In The Sims 2, all the data relating to objects is stored together. According to Jake Simpson , Lead Simulation Engineer, this includes:
“Localized string lists, executable scripts, common definition meta data, animation lists, routing information, advertising information, interaction definitions, model information.”
A one-stop resource for any information relating to objects is very useful to have both during development and at runtime. It makes the whole game much more modular, which explains how easy it is for EA to build expansion packs!
2) Use Micro-Threads for Objects
Because there are so many objects collaborating together to form the gameplay, it’s important to make sure they all get a share of the computation time if necessary. In The Sims, this is done using cooperative scheduling.
Each object has its own micro-thread for execution which gets updated each frame if necessary. The scripting language supports features to help these threads cooperate with the game engine, for example a yield instruction to wait for the path-finder, animation system, or even a timer.
3) Automate Handling of Objects
Because there are so many objects and they are usable modularly, the game engine must handle them automatically without any special instructions. When a new object is inserted into the game:
The initialization function of the object is executed.
Each frame, the object’s main update function is called.
This differs from the majority of games where objects either contain no logic, or the functionality is implemented centrally in the engine. The advantage of this approach is that extending the game requires fewer changes to the engine (if any).
4) Use Objects Uniformly Everywhere
With an object model as powerful as the one in The Sims, it makes sense to use it extensively throughout the game. And indeed, objects are used practically everywhere. They fall into two categories:
Physical — Cars, chairs, electronics, gadgets, toys, toilets, etc.
Abstract — Objects to handle visitors arriving on the lot, change the weather, track time of day, etc.
The only requirement for an “object” is that it conforms to the common API, so its code is executed every frame.
5) Add Advertising Data to Objects
Each object has a public interface that broadcasts its functionality to actors in the game. This is called advertising data in The Sims, and contains a list of possible actions and what motives they satisfy.
Using the toilet satisfies the bladder and increases comfort.
Cleaning the toilet improves the atmosphere in the room.
This information is used by the decision-making code (discussed below) to pick the next object an actor uses autonomously.
6) Store Assets Separately
Despite objects being self-contained, certain assets are stored separately when necessary. Specifically, this prevents duplication of animation data, textures, or models. The references to these assets are still contained in the object itself, but they are saved in a common location.
7) Use an Excel Sheet to Store Properties Centrally
This is another exception to the objects being self-contained, but it makes things more convenient. When tweaking the game, whether in the final stages before shipping or during prototyping, it’s convenient to have a complete overview of the game in one place.
In The Sims, a large Excel sheet is used to store the properties of the objects. When the game is built, the information is copied over to each object individually, but the values can be adjusted centrally without having to search for each object.
With a franchise as prolific as The Sims, there are certainly lessons to be drawn from the development methodologies. If anything, this may allow you to develop more smart objects for your game, and increase the realism of your actors.
Screenshot 2: The average living room in The Sims 2.
8) Formalize the Development Process
When you have a modular object system, it becomes possible to treat new features one object at a time. During the development of The Sims 2 and its expansion pack, there was a very clear development process :
Design meeting about the object to decide what motives it satisfies, if it needs repairing, if there are other similar objects in a group, how it fits with the theme.
Technical meeting to define the scope of the object, what’s necessary to implement it (in terms of art assets and scripts), and also if additional engine support is required.
Scheduling can take place to plan the workload required to get the asset into the game. This is typically a collaboration between script engineers and artists.
This process makes it much more predictable to build smart objects, so the environments are more likely to be interesting and varied.
9) Invest in Home Grown Tools
The custom tool behind the smart objects in The Sims is known as Edith. The developers decided it was worth the trade-off to invest in their own technology.
Advantages — It’s easier to make changes to suit the gameplay and workflow.
Disadvantages — It takes more time, skills are not transferable.
These days, most developers prefer reusing an existing language, but for very specific problems it still makes sense to roll your own.
10) Focus on Powerful Development Tools
Regardless of whether they are made in-house or not, it’s important to have a good set of tools for working with the scripts. Edith provides the developers with:
Code and data breakpoints.
Edit and continue.
Having a home grown toolset makes it easier to implement these features, which decreases turn around times. It’d be much harder to build these features on top of an existing language.
11) Make the Editor In-Game
The Edith editor is completely in-game. This has the advantage that scripts can be updated in real-time and the changes are visible immediately. This not only helps improve turn-around times, but the behaviors of the objects are also better tweaked.
The disadvantage of this approach is that it relies on a working build. If the build breaks, the editor is no longer functional, and progress on the game stops. Extra precautions must be taken to assure this doesn’t happen.
12) Create Audio After the Animations
In most games, the sound effects are annotated onto the animations. There are markers in the animation data that indicate when a sound should be played.
The Sims apparently uses one sound per animation. Since the timing is important, the audio can only be created after the animation.
Custom Scripting Language
In The Sims 2, the developers decided to implement a custom scripting language, specifically tuned to the kind of game they were making. Compared to using Lua, this has some advantages…
Screenshot 3: A house in the original Sims game.
13) Use an Interpreted Language
The script data is loaded up and executed by an interpreter, as opposed to natively compiled code that is run on the processor directly. This is an interesting compromise:
Speed: It’s much slower to parse at runtime but it avoids the need for compilation during the build.
Extensibility: It’s easier to extend an interpreter than to rework a compiler.
Interactivity: The interpreter is required to implement edit and continue.
In The Sims, the developers decided to implement only an interpreter (a closer fit to their requirements), rather than maintain a separate compiler as well.
14) Use a Binary File Format for Scripts
The advantage of having a custom interpreted language is that it’s much harder to reverse-engineer. The Sims tries to take this even further by storing the scripts in a binary format, similarly to byte-code rather than providing the whole source code for the scripts to the end user.
15) Optimize the Scripting Language API
The custom language developed by EA/Maxis was specifically tailored for realtime performance. Specifically:
There are no heavy trigonometry functions.
All computations are done relatively to the object in space.
The scripts rely on the engine for the heavy calculations.
There are time limits on the computation of each object per frame.
These restrictions make it easier to guarantee good performance with the cooperative scheduling despite potential problems with isolated scripts.
16) Integrate the Scripts into the Engine Tightly
In many games, the scripting engine serves as a high-level logic that controls actors in the game. However, for The Sims, the scripting functionality is very tightly integrated into the engine itself.
For example, script functions in the objects can be called by the core decision-making system. This allows the actors to take into account the properties of each object according to their own properties (e.g. a toy is only fun if you’re not very old).
17) Implement Error Recovery Mechanisms
When a script crashes or a problem is detected by the interpreter, the object is reset to a known state (e.g. the initial state). This means the game can continue without affecting the player’s experience.
The scripts for the actors are handled similarly. When a problem occurs, the actor is reloaded from the last save, and repositioned in the world.
18) Inherit Scripts Hierarchically
The Sims uses a form of inheritance to help reuse code. This is done according to the file system: the closer towards the root directory the more general the code (e.g. global scripts), and specific objects are in the leaves.
This helps create expansion packs, as different directories may override the base file system. Any game with a Quake-like PAK archiving system supports file system extensions, but this needs to be integrated with the scripting engine.
The characters in The Sims game are becoming increasingly sophisticated over the evolution of the franchise, but there are only few details about the inner workings of the AI.
19) Use Response Curves to Model Emotions
A form of fuzzy logic is used to model the emotions of the actors. Each of them have basic feelings measured in the range [-100,100], specifically:
Physical: Hunger, comfort, hygiene, and bladder.
Emotional: Energy, fun, social, and room.
Each of these are mapped to a mood/happiness value using a response curve. Some functions are linear mappings, e.g. hygiene and energy to happiness, but others are polynomial functions. For example, the more hungry actors get the less they care about anything else!
20) Try Greedy Decision Making
Given these basic feelings, the decision-making part of the AI is responsible for finding objects that fulfill their current needs. This is done based on multiple factors:
The actions possible based on the objects that are available.
The reward that each action provides to the current actor.
The distance of the object to the current location.
The level of need felt by the actor at the time.
This can be implemented using a voting system, whereby the most valuable object according to all feelings is used next by the autonomous behaviors.
21) Make Canned Plans
The behavior of the actors in The Sims is very much a by-product of the decision making and the smart objects. As such, they don’t really do much intelligent reasoning. In fact all their plans are “canned,” meaning they are specified manually using scripts.
For example, the process of preparing lunch may require multiple steps, but each of them is specified via a script attached to the fridge. In a sense, there is very little intelligence in the actors themselves, hence the “smart object” terminology!
 Scripting and Sims2: Coding the Psychology of Little People Jake Simpson Game Developer's Conference 2005 Download (PPT, 72Kb)
 Under the Hood of the Sims Kenneth D. Forbus CS 395 Game Design, 2002