# Upgrade system for tower defence?

What is the best way to create a rather dynamic upgrade system for a tower defence game? I thought of two possibilities:

• Create enums for stats and math operation (latter could be just a char as well), and use the following function:

Upgrade (Stat, Value, Operation);


Like:

Upgrade (STAT_HEALTH, 2, OP_MULT);


would double health.

• (Using an entity system with each one having an ID) Every tower, and its possible upgrades, are different entities, so:

Upgrade(int id);


would upgrade the entity to entity of ID id. This one doesn't look very good for me, as it looks like a waste of memory. This also makes me think of a system using a tree of stats nodes to define their dependencies, but I'm not sure what to do exactly.

Just started learning about JSON so the information needed would be available through it.

This depends on a few factors:

• Do you actually need to worry about memory? Unless you're dealing with a top-of-the-line 3D tower defense game, I doubt it's an issue you should be worried about.
• By "dynamic", you clearly mean that upgrades can change their value. Do you also mean that upgrades can combine to form others (ex: +5 Attack and +3 Explosiveness could be upgraded to +10 Splash)? If they are this dynamic, I would recommend using your second system, an entity system, because you'd have more flexibility. If not, I'd lean towards an enum-based system.
• Will different upgrade types be similar or drastically different? If you have upgrades varying from "Randomly grants a boost nearby towers!" to +2 Attack, you should probably use an entity system. With enums, you don't have as much room to work with these differences.

When it comes down to it, it's really a matter of simplicity v. flexibility. Which of these you choose should be determined by the scope/complexity of your game.