Main sort criteria on the deployment tab ...
Currently, the main sort criteria is unitcombattype. Non combat units (workers, settlers, etc) have a combat type of 0. The other units have a combat type of 1, 2, etc. This makes it really easy to use the combat type as an index (0, 1, 2, 3, ...) and that is the way the code has been set up.
I want to free up the main index (leave the other 3 as they are - which are unit, array of all units, unit count). There are also some sub-routines (is that the right name) that control if you select a group, then you also select the subsets of that group. The parameters are very inconsistent in that some take the unit id, some take the unit type, others take the unit pointer. I want to consolidate all of those items and make it a single type ... unit pointer.
Now, if python was like C, or Visual VB, we could use a text value as a pointer to an array value (or the key to a member of a class). However, to the best of my knowledge, we cannot do that. So - here is what I am thinking regarding the main index ...
- it needs to be a number .. 0, 1, 2, 3, ...
- it should be open ended and anything could be it
So, in my advanced programing skill (HAHA!), here is the method that I developed that will do this ...
create an array called PrimaryIndexKey. Use that index to hold the values that reflect the main index and use the array index for that value as the index for the unitlist index. Maybe an example would be clearer ...
Example
Say you want to use the following as your main index ...
- Own City
- Own Territory
- Foreign City
- Foreign Territory
- Other
... then you would need to execute the following code (pseudo) ...
PrimaryIndexKey = []
call getPrimaryIndexValue (pUnit) which does the following:
- determine the type of key you are looking for (in this case, one that is unit location based)
- check PrimaryIndexKey to see if the value this unit has (ie Own City) is in the array (loop over the PrimaryIndexKey array
- if it is, just return the index and the fact that you found the index and you are done
- if it isn't, append the value and return the index and the fact that you had to append the value.
... now, back to the calling subroutine, then you get back a true / false and a number. If the boolean value is true, then you need to append an array to the unitlist array (I think it is [0,0,[],0 but check the code). Then use the number you get back from getPrimaryIndexValue to add that unit to the unitlist array.
The following is the code that zero-ises the unit list array ...
Code:
for iUnit in range(gc.getNumUnitInfos()):
self.unitsList[iUnit] = (gc.getUnitInfo(iUnit).getUnitCombatType(), iUnit, [], 0)
obviously, we cannot use this, thus we need to go with ...
self.unitList = [[]]
... and when we append a unit, we add something like this ...
x = getprimarykeyindex
self.unitlist.append(x, unit.unittype, [], 0)
Well - that was my thoughts but feel free to laugh and tell me the right way to do it. When we do it, I thing that the first that we should code up is the type of key = unitcombattype (ie what it is now) and then we should have the code exactly replicate what you currently see.