Based on the information from my previous post, here are a few methods of determining the index of units created mid-game. These can be combined in various ways to be used in the same map.
Attached below is a map demonstrating a unit index tracking system, using Method A as described below. The map constantly respawns Goliaths, which are killed by lockdown. The physical indicators checked are unit coordinates, and unit health (to differentiate the Goliath from its turret).
Method A: Create the unit, and then use physical indicators to find its index. The physical indicators can be anything unique to the unit which is checked by its index, such as unit coordinates, unit health, unit energy, and unit status.
As an example, a small square in a corner of the map can be set aside for this purpose. Every time a unit will be created, create it in the corner of the map, and then check each index to see if it is at those coordinates. Since that is the only unit at those coordinates, only one index will be found there. After determining the index, the unit can be immediately moved to where it's needed, and any number of additional units can be created the same way during the same cycle.
The only downside to this method is the necessity of unique physical indicators.
This is the primary method which should be considered for most systems. It's flexible, intuitive, and reliable.
Method B: Change the unit settings for map revealers to a health higher than any other unit, such as 100000. When it is time to create a unit, instead create a map revealer with 98% health, and remove it. For any additional units which will be made during the same cycle, create a map revealer at 97% health, then 96%, and so on, removing each one afterwards and recording the index that changes via death counts. After all units which are desired have had their respective map revealer created, then create a map revealer with 99% health. At the beginning of the next cycle, begin creating map revealers with 100% health until the index at 99% health changes to 100% health (this is to take into account units which were killed during the first cycle or between the two cycles). At this point, you will know the order of all the indexes after that, as they will be ordered from least to greatest health (if there were three units, then they will be 96%, then 97%, then 98%).
There are a few downsides to this. One issue is that players cannot create units from factory buildings, as they would use up the stored unit indexes. It could be detected that the indexes were compromised, and the process started over each cycle until it is successful.
Another potential problem is that the act of creating map revealers at 100% health until the 99% index changes will add a large number of triggers to the system (1700 additional triggers for every unit which may have died during or since the previous cycle). However, these are optional, assuming that you could ensure no units could die during or since the previous cycle. For stopping units from dying during the cycle (by triggers), you could make all triggers with kill actions delayed via a switch which is set whenever tracked units need to be created. As for preventing units from dying between the cycles, if the map requires players to be able to kill units, it could make all units invincible during the first trigger cycle and make them vulnerable again during the second one.
Ideally, this system would be used in a map specially tailored for it. For example, if the players cannot create or kill other units outside of triggers, or if units were always killed in predictable amounts, this system would be easier to setup.
A benefit of this method would be that it does not require any unique physical indicators to differentiate the units, since it is determining the index each unit will have before they are created.
Method C: This is a one-shot system which can produce a large number of unit indexes to be used on the next trigger cycle. When the units are to be made, 1700 map revealers are created and removed. This will result in the list of available indexes being reversed, putting 1699 at the top, followed by 1698, then 1697, and so on. The NAIID will be something unknown (whatever the bottom index would have been in the available list), so at the beginning of the next cycle, a single map revealer should be created. The rest of the indexes will be used in a predictable sequence.
The main downside of this system is, as stated, that it is geared toward a single use. It can be modified to be used repeatedly, keeping track of which indexes have been used and then flipping the stack again in a similar method to preserve the order of the highest indexes. This would require a map specifically designed to accomplish this, and would have to restrict the player's ability to create or kill units (or have additional systems safeguarding against this activity).
Another potential problem is, in the case of creating a large number of units, there are only a finite number of indexes that can be used in this way, as indexes are counted down, not recycled. In most maps this number of uses isn't likely to be reached, unless the tracked units respawn infinitely. Even in this case, an additional system can be put into place to make sure the expected indexes are being used in the anticipated order, and stopping the tracking of indexes in this way if the ordered set is used up.
As with the previous method, since there are two cycles involved, if any units are killed during or after the first cycle, the system will be offset on the second cycle. However, this can easily be checked by creating a single map revealer (with a reduced percentage of health) repeatedly until the index 1699 has its health changed to that of the damaged map revealer. A similar concept would be used if players can create units from factory buildings, detecting the highest index with the health of a map revealer (as they were created to flip the available list), and starting the unit index distribution from there.
This method is exceptional at what it does, with a huge benefit being the relatively low number of triggers required to make it functional. There is no need for triggers that determine the index of a unit before or after its creation, as you know in advance the order of all the indexes and how they will be used. This works well in conjunction with both of the previous two methods.
Attachments:
Post has been edited 4 time(s), last time on May 24 2012, 8:46 pm by Azrael. Reason: Update.