Hey guys, I am planning out a survival game system where you can pickup items, these items refer to a data table which holds their unique parameters, and then for whatever type of item it is, you may be able to do different behaviors with it.
My question is about clarifying some ideas shared here:
No hardcoded classesPermalink
However as a programmer you might decide to write all of the logic for each of the buildings in their own classes.
Farm.cpp
,Windmill.cpp
,House.cpp
etc. Maybe you use inheritance to share common code, and seems pretty simple.But what if a designer wants to create a new type of building? They have to come to you, the programmer and ask you to create it. Being a programmer is about being intelligently lazy, so how can we improve this?
Stepping back, what is a building? What can it do? We can see a building as a set of behaviours that can be mixed and matched:
- Create resource behaviour. A farm creates wheat, a fisher hut creates fish.
- Convert resource behaviour. A windmill takes wheat and converts it to flour.
- Store resource behaviour. A windmill can store a small amount of flour that it creates, a barn can store many resources of any type.
- Require Worker behaviour. The building will not work unless all the worker requirements are met.
- etc.
By decomposing a building into a collection of behaviours, designers will be able to create new types of buildings without programmer intervention. Modders will be able to create new building types very easily, too.
Programmers are only required to create new behaviours. For example designers might want buildings to be able to catch fire. In that case then the programmer can create this new behaviour and let designers add it to the buildings they want to be flammable.
This idea that programmers are only programming the behaviors… where does that happen? I think if I can envision one example, I could extrapolate from there.
Say you have a meat item and you want a “cook meat” behavior. The meat item can exist just as a string variable on the player character, or where ever inventory data is held.
The cook behavior would do a couple things:
- remove meat item from players inventory
- add cooked meat item to players inventory
- run some other logic like play sfx, etc
The question is, where do I define this behavior? In an actor component? Does that scale well if you have like, 100 different behaviors that are possible? In a single player game is there any benefit to separate behaviors into components when there is only one player character class? I could just as use separate graphs in the blueprint editor for organizational purposes, and then I don’t have the added verbosity of passing data from one place to another, right?
I know there is know right answer and everything depends on project - just looking for any general advices, ideas, thoughts, etc.