Flexible upgrades system for an RTS?

Started by
4 comments, last by TechnoGoth 11 years, 10 months ago
Hi everyone!

I'm trying to come up with a nice and flexible way to manage upgrades in my RTS. There are multiple races with different units and buildings, as well as different upgrades. Each upgrade can modify one or more attribute (cost, range, attack speed, damage, ..) on one or more unit/building type. There can also be unit type groups (cavalery, ranged, ..). The game shall be moddable, so modders should be able to add new units and buildings which should work with these upgrades.

Players can form teams which may share upgrades.

Example upgrades:

  • Horse Armors: Cavalery +10% armor
  • Military training: All Units +20% damage, Recruit Time +10%
  • Sharp Arrows: Archer +15% damage

I though about using some form of tree:

[indent=1][HorseArmors]
[indent=1]Armor/Units/Cavalery/*: +15%

[indent=1][MilitaryTraining]
[indent=1]Damage/Units/*: +20%
[indent=1]RecruitTime/Units/*: +10%

[indent=1][SharpArrows]
[indent=1]Damage/Units/Ranged/Archer: +15%

Each player would then store his tree of upgrades and whenever a stat was needed, the tree would be traversed and any upgrades encountered would be applied. I see a few problems with this. First, there'll be ALOT of upgrade tree traversal. Second, what about Cavalery Archers?

How would you structure it?
Advertisement
I always found that Blizzard's World Editor (the Editor for Warcraft 3) handled upgrades very well. Each upgrade was able to change various properties of a unit, as well has enable / disable abilities. This system was pretty flexible.

One upgrade could be attached to more than one unit class. The upgrade had no idea which units it was affecting. it would just act on the "object". It was the unit's responsibility to list which upgrades it required / used. Thus, a single upgrade could be used to improve multiple unit types, such as increasing the range of an archer as well as another ranged unit , much as you described.

for Cavalry Archers, they would list both the "archer" upgrade as well as the "cavalry" upgrade in their tech tree, thus allowing them to benefit from both of these. Warcraft 3 has ~20 baked upgrades which did most of what you wanted for a normal game mode (range, health, health regen, mana regen...). If you wanted custom upgrades, you could script them with the built in scripting language, JASS.

I found the system very elegant. I imagine it would be trivial to check if an upgrade has been researched or not, a simple hash based on it's name would suffice. I'm not really sure if this model appeals to you, but I encourage you to go ahead and give it a try :)

a WIP 2d game engine: https://code.google.com/p/modulusengine/

English is not my first language, so do feel free to correct me :)

I thought about that (letting units list which upgrades they are affected by) but I'm not really sold. In WC3 there's pretty few upgrades, usually 1-5 per unit/building with pretty low overlap. That won't really be the case in my game. I will have several (20+) upgrades which affect all units and/or all air units (for example). I'm currently thinking about letting all units define a list of 'groups' they belong to ('air', 'land', 'ranged', 'cavalery', 'melee', ..) and allow upgrades to specify a group of affected units.
I personally think your trees are a bit shuffled. Beyond that, I think the basic idea would work readonably well:

[indent=1]# Upgrade All the units!
[indent=1][YayHealth]
[indent=1]Units/*/Health: +10%

[indent=1]#Reinforce the castle walls w/ 5 dmg resist
[indent=1][Architecture]
[indent=1]Buildings/Castle/DmgResist: +5

[indent=1]#Archers get bracers:
[indent=1][ArcherBracers]
[indent=1]Units/Ranged/Archer/*/Speed: +5%

[indent=1]#Only this one guy gets to fly
[indent=1][OPguyIsEvenBetter]
[indent=1]Units/Overpowered/"That One Guy"/Flight: =true

[indent=1]#Give the Town Center the ability to upgrade tech level
[indent=1]#Take away tech level 2 'cause that's where we are
[indent=1][UpgradeToTL3]
[indent=1]Buildings/"Town Center"/Abilities: -TechLevel2, +TechLevel3

Of course you'll have to describe abilities separately...
There was actually a reason for that shuffling even though it indeed felt slightly backwards/wierd. Wildcards are nice and easy to place in a resource file/config file/whatever file, but a bit nasty to work with while doing the lookups. With the wierd shuffled way, I could just traverse the tree from root to leaf and apply any found upgrades/values. If a leaf wasn't found, no harm was done. Adding wildcards to that mix makes the lookup much more complex, and I would probably need to store every combination of units/stats where I currently only need to store those actually used.
The approach I've used is what I call delta mapping. When an upgrade is unlocked each unit or in your case unit template gets assigned that upgrade, and when making a call to get value for a unit I resolve its current value by taking the base value and apply any deltas that are applicable.

So one way it could work is that you have
Horse Archer -> Types {Unit,Archer,Cavalry}
Calvary -> Upgrades {Horse Armor}
Archer -> Upgrades {Sharp Arrows}

When getting the armor value for a horse archer it would apply any bonuses to armor available to units, archers, and cavalry and then return the final value.

This topic is closed to new replies.

Advertisement