Building Levels and Prerequisites
by Dave Young · in RTS Starter Kit · 02/09/2006 (4:29 am) · 4 replies
Now that I have gone through a few minor enhancements, I'm ready to start thinking about the building/tech tree.
It looks like there is really not much support for 'building levels' inside the RTS Pack, except for the multidimension array. Most functions have the building level hardcoded as index 0. Additionally, while there are resources needed to build a building, there isn't any provision for prerequisite buildings or technologies.
Prerequisites can be pretty diverse. For example, to build a level 3 Armory, you might need:
1X Level 3 townCenter
2X Level 2 Barracks
1X The Military Zog Permit
OK, I got a little wacky at the end to illustrate a point.
I think a good way to do this would be to define the prerequisites inside the datablocks of a building.
Some preliminary tests showed that I could do this in startPlaceBuilding, in the same area where a resourcespend check is done.
But that's getting a little ahead, because before we can Place a building, we would need to have an icon button to do it, and that button should only be enabled on a building's Build Menu if the prerequisites have been met.
So I have got to come up with a design that will work both ways, hopefully without reproducing a lot of the same code. It theoretically could be done in one place, before the button click, but that would introduce a window of time where the resources or prerequisites could drop below required amounts and we would still build the building. Not too cool, especially with a lot of reource traffic.
I am thinking about a data structure that would contain provisions for a good diverse bunch of prerequisites:
Element 0 = "BuildingName Datablockname BuildingLevel NumPrereqs"
Element 1..n = "prereqtype prereqname prereqlevel prereqamount"
Prereq[0] = "Armory ArmoryDataBlock 3 3"
Prereq[1] = "Building TownCenter 3 1"
Prereq[2] = "Building Barracks 2 2"
Prereq[3] = "Item MilitaryZogPermit 1 1"
In the gui side, where we build the BuildingMenu, we would look at the ActionList to see if the building could build any buildings (have to implement an 'upgrade', right now only 'hire' is really done) and run through the building datablock's prerequisite check to see if we even show the Upgrade button.
Note that the ActionType is defined on the client AND the server, and is kind of only geared towards one action with many arguments:
CLIENT: $BD_ActionType[1] = "Hire bonecracker shocker rifleman";
SERVER: $Buildings::ActionType[2,0] = "Hire bonecracker shocker rifleman";
Yargh! note that these are both for the same building, the indexes are not the same. So we've got to be extra careful not to mix things up later.
So we will need to be able to extend that a little to add more actions, so I would look more like:
"Hire bonecracker shocker rifleman upgrade armory"
Hmm. I dunno if that would work so well
I only want to extend this so I could make use of the existing actionicons code, but this might not be the best approach. That's it for now, I'm going to let it mull for awhile.
Please weigh in for implementation ideas!
It looks like there is really not much support for 'building levels' inside the RTS Pack, except for the multidimension array. Most functions have the building level hardcoded as index 0. Additionally, while there are resources needed to build a building, there isn't any provision for prerequisite buildings or technologies.
Prerequisites can be pretty diverse. For example, to build a level 3 Armory, you might need:
1X Level 3 townCenter
2X Level 2 Barracks
1X The Military Zog Permit
OK, I got a little wacky at the end to illustrate a point.
I think a good way to do this would be to define the prerequisites inside the datablocks of a building.
Some preliminary tests showed that I could do this in startPlaceBuilding, in the same area where a resourcespend check is done.
But that's getting a little ahead, because before we can Place a building, we would need to have an icon button to do it, and that button should only be enabled on a building's Build Menu if the prerequisites have been met.
So I have got to come up with a design that will work both ways, hopefully without reproducing a lot of the same code. It theoretically could be done in one place, before the button click, but that would introduce a window of time where the resources or prerequisites could drop below required amounts and we would still build the building. Not too cool, especially with a lot of reource traffic.
I am thinking about a data structure that would contain provisions for a good diverse bunch of prerequisites:
Element 0 = "BuildingName Datablockname BuildingLevel NumPrereqs"
Element 1..n = "prereqtype prereqname prereqlevel prereqamount"
Prereq[0] = "Armory ArmoryDataBlock 3 3"
Prereq[1] = "Building TownCenter 3 1"
Prereq[2] = "Building Barracks 2 2"
Prereq[3] = "Item MilitaryZogPermit 1 1"
In the gui side, where we build the BuildingMenu, we would look at the ActionList to see if the building could build any buildings (have to implement an 'upgrade', right now only 'hire' is really done) and run through the building datablock's prerequisite check to see if we even show the Upgrade button.
Note that the ActionType is defined on the client AND the server, and is kind of only geared towards one action with many arguments:
CLIENT: $BD_ActionType[1] = "Hire bonecracker shocker rifleman";
SERVER: $Buildings::ActionType[2,0] = "Hire bonecracker shocker rifleman";
Yargh! note that these are both for the same building, the indexes are not the same. So we've got to be extra careful not to mix things up later.
So we will need to be able to extend that a little to add more actions, so I would look more like:
"Hire bonecracker shocker rifleman upgrade armory"
Hmm. I dunno if that would work so well
I only want to extend this so I could make use of the existing actionicons code, but this might not be the best approach. That's it for now, I'm going to let it mull for awhile.
Please weigh in for implementation ideas!
#2
02/10/2006 (4:32 am)
Yes, that's exactly what I'm doing, bearing much fruit.
#3
02/10/2006 (6:22 am)
Nice. How much pain was it to do? I was going to start on my tech tree this weekend and was going to do try what I mentioned above. Good to see it is working though :)
#4
Otherwise, it's pretty flexible where you put things, I have the info in the datablocks. I am finding that I wish it was easier to define units in general, the multiple locations and lookups for names/IDs is a little cumbersome, you can't define a unit in one place and leave it at that.
But then again, I don't have it in me to rewrite it, and I am too new to pull it off without more pain than it is worth. ;)
02/10/2006 (6:43 am)
It's working out pretty good so far, I'm doing it pretty much exactly as described so far, I haven't started on the interface part yet, but the loop is running and detecting buildings that meet requirements, separate loop for units. I am working on making it a little smarter so that the loop doesn't pick up the same building twice. If there are 2 of the same requirement, it needs to know that there are 2 separate occurences of the requirement for the connection. I plan on using a temporary array to store object IDs, whenever a requirement is met, it searches the temporary array to see if it is already being used to meet a requirement.Otherwise, it's pretty flexible where you put things, I have the info in the datablocks. I am finding that I wish it was easier to define units in general, the multiple locations and lookups for names/IDs is a little cumbersome, you can't define a unit in one place and leave it at that.
But then again, I don't have it in me to rewrite it, and I am too new to pull it off without more pain than it is worth. ;)
Associate Chip Lambert
Crusader Games