Gamestate and World simulation (part 2) - Data driven model?

You watch your colonies form the orbital view, click on a location and you can quickly see what it's happening there: you have a base, inhabited by 10 astronauts, most of them are working on maintaining systems healthy, they are also gathering resources for later expansion of the colony. You connect to a satellite and access a global view where you can see how many resources are available on a certain location, you know where to send your next drone to explore and confirm that data. You connect to another satellite, that is forecasting a storm in a region where another of your colonies is, solar power won't work, you may need to install a fusion generator there, just in case the storm will last too long.



That's what I'll be trying to create in the next weeks (months?), let's get into some details.

Research

This week I've spent far less time than the previous on this project (personal life took away some dev time), but still, I've done something, let's start with the theory.



What I want to achieve is a "background" simulation of Mars that hopefully will include:

weather, Mars changes a lot, you can have planetary sandstorms covering everything for months. Poles dry ice amount varies over the year, and more.

Resources, it may not look like, but the planet offers different resources depending on where you are.

Your bases and units should continue doing what you've asked them to do, allowing you to focus on the overall result of your actions and not micro-managing everything.

Space can throw at you, literally, asteroids, in most cases without any issue to you or your economy, but eventually a bigger one may need some attention.

How to build all of it in code?

That was my question, and even tho I already had a vague idea, I made some research before going too deep into the rabbit hole.

Let's list ad resume some interesting resources I've found out.

I first discovered some sparse articles on Gamasutra:



A not so large article describing the overall method used to simulate economy: BazaarBot: An Open-Source Economics Engine

This one does not describe a technique either, but points out that super detailed realism is not good for games: The Simulation Dream

A series of articles that had some interesting information especially I found useful the first and the last of the series: Building Simulations, Part 1 - An introduction to simulation-heavy games, what are common design patterns and why the do not work with this kind of games. Building Simulations, Part 5 - Tools you should build, how you should structure your code, fine-tuning is really a thing here.







After that I decided to search among GDC talks, I was sure I'd found something useful, and this one was pretty good:



Download video Download video

This last video, was particularly interesting, Maxis' Dan Moskowitz mentioned, and explained 2 terms:

Units - the basic block representing things like buildings, as well as electricity, pedestrians, and so on, they are just holding data

Agents - modify the unit parameters, say a new amusement park is built, an agent irradiates happiness to the neighbor home Units.

This kind of architecture is similar to what I was thinking about. To my understanding this is called Data Driven, some others call it ECS (entity component system).

Another thing that I'm trying to understand is the Composition over inheritance paradigm. And of course if it's something I should try to use or not.

Oh, and about composition, here an interesting article: A hybrid Entity-System-Component architecture, that seems to support Godot's philosophy and my approach.



To add a little more to this argument, I think Godot's philosophy is the best approach, you can create a scene, with basic functions, than create one that inherits from that one with added features. Somehow, I think the "added features" should be the component part, meaning that I can have a vehicle, that moves, and have a wheels component, that adds the behavior or driving a wheeled one, but you can also add a fly component that makes it behave differently.



Into Godot

My first attempt into simulations

As I mentioned in the previous devlog, I've decided to use resources (I actually switched to Objects, or better, References) to represent everything in the game.

Each class, belonging to a type of entity in the simulation.

For example, a rover, an astronaut or a drone they all belong to one class, the "unit" (to not be confused with the GDC talk definition of it).

Another class contains all the data a rock can have, composition, size, and whatever needed.



In each resource I can store things like:

Health status

Energy level

current crew and/or cargo

current position

current path followed

the task is performing

This resource can then be attached to the actual unit, say a rover, and while you control it, it just updates those values, instead of being something embedded into the unit itself, being a resource to me looks like a good approach because it can be "detached" and attached to the "world simulator", that could be non visual, and just changing those values as needed. Another free bonus is that being a referenced object, I can share that between the Unit scene/object, the world simulator and the save system.

this lonely unit only show up at Arena Colles, as per global data.

After a lot of attempts I was able to do that in code, I created a series of objects, all deriving from one or 2, In some cases certain Entities will contain nested objects.

Let's take as an example the astronaut in the picture above, it has a "GameDataUnit" class, that contains several properties, included a (path) reference to a Resource (unit_type) that provides him with certain max-health, speed, and autonomy. But has a property "position" that is another class containing the coordinates of this particular location and the relative position.

the unit's custom data (GameDataUnit) contains a property "position" that is another "GameDataPosition" object

In the end I was able to instance and connect the Astronaut (the unit node), to it's relative data, and make it spawn only at the desired location. Cool!

As a final note, I encountered a couple of problems that slowed me down:

I tried initially to use resources, but I realized it's better to use Object or it's derived class Reference .

or it's derived class . objects not being assigned or loosing reference unexpectedly, I've figured out what the problem was, so I will probably be able to continue with this approach.





I will go under a minor surgery in a few days, so I'll see you as soon as I will be able to work again.