top | item 14997725

Motive.c: The Soul of the Sims (1997)

255 points| mountainplus | 8 years ago |donhopkins.com | reply

41 comments

order
[+] blixt|8 years ago|reply
I wanted to get a feel for the logic so I made a quick carbon copy in JavaScript with a simple UI to play with:

https://codepen.io/blixt/pen/ayyjpZ

[+] DaiPlusPlus|8 years ago|reply
I noticed this (the original code, and your implementation) seems to only describe the "state of feelings" for a simulant and how they generally only get worse over time. I'm now keen to see the code that then provides direction and action for the sim based on this state; e.g. "I'm feeling hungry, I should eat, what should I eat?" and the process that determines what it should eat - and how to go about it. I know The Sims employed more than just A*-towards-nearest-unoccupied-food-source, but what makes a Sim choose hamburgers from the outdoor grill over making dinner in the kitchen?
[+] pavlov|8 years ago|reply
Something about this program reminds me of the text-mode BASIC games that used to be published in books and magazines in the 1980s.

I remember typing the programs and simultaneously trying to imagine how the simple logic I was entering might build up to something awesome that could be lurking there, just out of my sight between the numbered lines. Most of the time it was a disappointment, but a few of those games did manage to elevate themselves to some kind of unexpected, exciting life that I couldn't have known from just reading the program.

(Of course my standard for excitement was very low.)

[+] yawaramin|8 years ago|reply
You have a point. In a certain light, The Sims is a more complex version of Conway's Game of Life, with its simple life-or-death rules for the cells in the game.
[+] asciimo|8 years ago|reply
I had a revelation while playing the Sims, and this code lays it bare. I found I was spending more time managing these values for my Sim than I was for myself. I have not enjoyed most single player games since.
[+] seanp2k2|8 years ago|reply
Realizing that Sims games are really meta-games about life is how you actually win any Sims game. The only winning move is not to play.
[+] wolco|8 years ago|reply
Love how simple it is. A good lesson for anyone trying to kaie a gake. Make the core simple and that will allow complex interactions hetween them.
[+] pavel_lishin|8 years ago|reply
> kaie a gake

What does that mean?

[+] fastball|8 years ago|reply

  Make the core simple --> complex interactions
So.. microservices!
[+] bluejekyll|8 years ago|reply
Is there an advantage to storing this as an array, indexed by enum, rather than a strict of 16 floats?

I can't think of a reason. Having to index by enum seems like it could be error prone.

Also, in the init(), instead of looping over all indexes of the array and setting 0, couldn't a memset be used?

[+] buzzybee|8 years ago|reply
It enables the coder to engage in some late binding without engaging in a lot of casts or more elaborate metaprogramming: the enum index used for assignment is itself an assignable value and therefore can be passed around and manipulated if the algorithm needs it. It's a very intentional tradeoff of structure and long-term clarity for a faster turnaround to make design changes.

I haven't even checked to see if the final program uses it. It's the kind of thing, though, that you might go in thinking, "maybe I will need that", and it doesn't add too much overhead to your prototype.

[+] georgeecollins|8 years ago|reply
OMG - I am so old school I can tell you!

You can have functions iterate through the array. You may want have special functions for each indexed item, but if there is something you want to do for all of them -- say save or load, you can iterate through the list.

[+] taneq|8 years ago|reply
It gives a consistent layout in memory, meaning you can save/load very simply. Using a struct puts you at the mercy of the compiler's struct packing and alignment settings.

The other stuff is more stylistic but I'd guess he writes a lot of assembly code, and the enum style translates easily to asm.

[+] DSMan195276|8 years ago|reply
I would agree with you. Stuff like `changeMotive` could just take a pointer rather then an index and then you wouldn't need it to be an array. More-over, if you still want to be able to do that loop to check for underflow/overflow at the end, you could just `union` it with an array - use the regular member variables throughout the code, and then use array at the end.

But it was written in 97 so personally I'd give him a break. It might be a style he picked-up from coding on some earlier projects where it made sense (Say, for speed, or because the compiler was garbage).

[+] mjbellantoni|8 years ago|reply
Is there a bug in the line computing Motive[mHappyWeek]? It seems like it should have Motive[mHappyDay] instead of Motive[mHappyNow] on the right hand side.
[+] Dowwie|8 years ago|reply
What would this look like if it were using behavior trees, hierarchical fsm, or whatever the prevailing pattern is used today?
[+] DonHopkins|8 years ago|reply
That code is just a prototype, the seed around which the rest of the game nucleated. There is a big thick layer of behavior trees, hierarchal state machines and lots of whatever layered on top, including a visual behavior tree programming language called "SimAntics" and an editing tool called "Edith", which is described and demonstrated here (starting at 11:20):

https://www.youtube.com/watch?v=-exdu4ETscs

Here's another demo of some tools for making and managing user created content for The Sims, and SimSlices's amazing version of SimCity embedded in The Sims!

https://www.youtube.com/watch?v=Imu1v3GecB8

[+] rburhum|8 years ago|reply
The simplicity makes it beautiful.
[+] frik|8 years ago|reply
Could be one of the few lines of source code survived, as an small office fire in 2001 caused troubles.

Basically the predecessor of The Sims was SimTown (also by Maxis). It was a smaller scale SimCity meets The Sims gameplay. https://en.wikipedia.org/wiki/SimTown

Later SimsVille was meant to evolve the gameplay in the same direction again, though it go canceled (source code lost due office fire). https://en.wikipedia.org/wiki/SimsVille

Almost all the [Maxis] games development data was lost during a small office server room fire [in 2001], that resulted in most of the game being developed again from scratch, according to this source: https://www.unseen64.net/tag/maxis/

[+] brian-armstrong|8 years ago|reply
The formatting in this code is atrocious. It's so much harder to find bugs when the code itself is so disorganized
[+] blixt|8 years ago|reply
This code was not made for bug fixing though, it’s just a prototype - the expression of an idea. The accompanying text even says as much - of course the final game couldn’t possibly have a single sim’s mood in a global variable.