[General] Adding another resource to the game

Level 9
Joined
Sep 25, 2013
Messages
479
So i wanted to add another resource to my rts map. I know Warcraft only has gold and lumber (and food). Gold is being used for basic units, lumber for more elite units and upgrades, and food for unit limiting. I want to add stone or something like that, similar to age of empires. I know a basic way to do this but its crude.

My way would be to create a bunch of stone nodes which are actually neutral hostile structures throughout the map that only workers can attack because they will be considered debris or something. Then, when you destroy one you gain a stone point on a leaderboard. If you want to build a structure that requires stone a trigger will check how much stone you have a determine whether are not you can start building it.

The trouble i have is that if you cancel the unit or structure i don't know a way to make it so you get that much stone back. So instead i make so the unit is built in 1 second so you have no time to cancel it.

Is there a better way to do a system like this? I would really like to have another resource, it would add a lot of depth to my game.

Thanks for your time, and ideas are appreciated! :)
 
Level 36
Joined
Jul 22, 2015
Messages
3,491
I would store the amount of stone refunded into an index that is the same as its unit-type. So maybe something like this:
  • Set StructureType[0] = Farm
  • Set StructureType[1] = Barracks
  • -------- --------
  • Set RefundAmount[0] = 2
  • Set RefundAmount[1] = 6
  • [/STABLE]
The only downside to this is that you will have to loop through all the unit-types until you find the right one. This can be avoided by using a Unit Indexer and just storing an integer to the custom value of the unit. Whenever a strucure is cancelled, just find its custom value, refer to the integer variable you stored its index into and then, voila!
 
Level 36
Joined
Jul 22, 2015
Messages
3,491
I don't think Unit Indexer can really help for this situation. A hashtable would be a better aproach for this type of "system". You need to store these values into the unit-type id, not into the unit itself xP

How would a Unit Indexer not help? It's basically the same approach. If anything, storing values into arrays of a unit's custom value is much faster than hashtable lookups.

Regardless, a hashtable would work. I just find it senseless to use something so powerful it if all you're doing is storing integers.
 
Level 12
Joined
Jan 2, 2016
Messages
973
Well, I just woke up, and I may think about something completely different than what you are, but with a hashtable - you can save the unit-TYPE's stone cost into a hashtable with parent - the unit-TYPE id. So when a structure begins construction - you get its unit-TYPE id, and load the stone cost from there.
While unit indexer works with UNIT's custom values. Each unit has unique "id", and it's NOT related to the unit-TYPE in any way.
With Unit Indexer you could make different buildings of the same type cost different amount(s) of stone, but why would you want to do that? :p
 
Level 36
Joined
Jul 22, 2015
Messages
3,491
While unit indexer works with UNIT's custom values. Each unit has unique "id", and it's NOT related to the unit-TYPE in any way.
With Unit Indexer you could make different buildings of the same type cost different amount(s) of stone, but why would you want to do that? :p

Yeah you definitely misunderstood me. I suggested the unit indexer so that he didn't have to loop through all the indexes to find out which one he needed so that he can properly refund resources from RefundAmount[]. Using the Unit Indexer is practically the same concept: storing the index of the structure into it's custom value so that you don't have to loop through anything. Using a hashtable would make it easier. Every map should have a Unit Indexer anyway :3
 
Top