I’m struggling to put my problem into technical terms that I can search for, so here’s an example of a hypothetical situation that might illustrate it. Apologies if it turns out to be rediculously simple, I’m just trying to figure out an elegant way to do this now, rather than causing myself a ton of work later if I do it in an extremely suboptimal way.
Imagine a game in which the player can turn into other creatures. Every creature has their own set of base stats that determine how they work.
For example;
Human - Strength 50 / Speed 50 / Constitution 50
Rabbit - 5 / 65 / 10
Horse - 130 / 70 / 80
etc.
There are many species, and there are many stats for each species, with each stat representing the same thing as its counterpart for any other species, except with a different value assigned. These stats will remain a constant that will never change outside of the game editor, but which will need to be easily and individually tweaked whilst testing game balance.
Simultaneously, every creature in the game also has their own, variable set of stats, based on levelling, experience of whatever. These will not change when you turn into a different animal, but are used to modify the base stats of whatever animal you turn into. This results in a really strong player turning into a really strong rabbit, relatively speaking (ie. compared to the average rabbit), even if being a strong rabbit isn’t terribly impressive.
So, the question is - how can I lay out my code to best handle a situation such as this (at least without it turning into a bloated mess once there are very many ‘stats’ and ‘species’)?
The nearest thing I’ve currently got to a solution is still messy and a pain in the arse to work with, but so far I’ve essentially got a couple of enumerations that would look sort of like this;
public enum Species { Human, Sheep, Horse, Rabbit, Tardigrade, etc }
public enum Stats { Strength, Speed, Constitution }
I also have a function that basically acts as an intermediary, and uses the two above overloads. Whenever you need to look at anything related to a stat, you’d chuch them in this;
GetBaseStat(Stat inputStat, Species inputSpecies)
and after far too many if or switch statements it’d return the variable you’re looking for from a sprawling mega-class. It started out small and easy to modify, but now it’s a massive mess and I hate working with it. It’s just got me thinking that, being informally self taught, surely there’s some super easy way to do this without all the heart ache, that I’ve naively gone and overlooked?