A question about the CySelectionGroup method pushMission

General Tso

Panzer General
Joined
Oct 12, 2007
Messages
1,547
Location
U. S. of A.
I have a question regarding my use of the Python method pushMission that may require some knowledge of the SDK which I do not have.

I am currently using the pushMission method to control the "AI" units in my mod and for the most part it works great. I have the little buggers running around the screen doing all kinds of smart stuff. :)

However....
I can't find a way to prioritize units so that I can control when a unit moves relative to the rest of the current player's units. For example I would like to ensure that artillery bombards before the infantry units advance to attack, but move after the infantry.

From my testing in Python it appears that the game creates a list of the AI player's units at the beginning of the turn. It then cycles through the list handling each unit until its turn is finished before continuing to the next unit. I need to have the ability to skip the current unit and have it move to the end of the list so that it gets reprocessed after the rest of the units have been given a shot. Basically the same thing that happens when the human player presses the "W" key. Does anyone have any ideas on how to do this?

If not could anyone with some knowledge of the SDK either explain how the SDK handles this unit list or where the code is located, so that I can look at it myself (I understand a little bit about C++)
 
Ideally you would do this in the SDK, as it sets up a priority for order of selecting actions in there, and you are overriding that. But if you don't have a custom DLL yet, why bother?

Set up a global variable in python which you will set equal to the type of unit you wish to move first, in your routine, if the unit asking for orders is NOT this unit type, pass them a WAIT command, the DLL (as I recall) will come back to them after all other units are done. If they do match your unit type, give them an order. The tricky bit is to decide when/how to change the variable to the next unit type, so I would say store the Unit ID of the first unit which fails the test, and if you see him again, move the unit type variable to the next desired type.

Repeat that process (always storing the first ID which is told to wait) until the player number changes, at which point you reset back to the first type you wanted to take orders (so you also need to store the player number as a global)
 
Thanks for the quick response xienwolf. I already have the code set up to track units by their id number, so I'm good to go with that. The problem is I can't figure out how to send a WAIT command. I'm guessing that I should use the CvUnit.doCommand function, but CommandTypes doesn't appear to have a COMMAND_WAIT attribute.
 
What I use is to make a unit push Missions for other units. So a settler for example tells nearby units that don't have a job currently to move to it and join it's group.

You could write a function like callbombardcity or something and let that function cycle through all nearby plots and give bombarb commands to units)

From my experience, telling units to wait for other units can cause real slowdown.
 
I already have code in place for artillery units so that they look in a given area for the best target. About 90% of the AI units are controlled by Python in my mod. The problem is that with Python I'm limited to handling the unit AI in CvGameUtils.AI_unitUpdate and the game just keeps passing a single unit to me until it uses up all of it's moves or times out which it does after 100 or so calls to AI_unitUpdate. I want the unit to "wait" while all the other units are processed then be available after that. I have found ways to cause a unit to skip the rest of the turn, but I can't get it to just wait and then be available again later in the same turn.
 
Ok, had some time to open the DLL now, I think the main function you want is void CvPlayerAI::AI_unitUpdate(), with the important part for setting the order being int CvPlayerAI::AI_movementPriority(CvSelectionGroup* pGroup) const. The second function is where you would change things to choose the order you think is better.
 
I'll check it out. That info won't directly help me since I'm not familiar with making changes in the SDK, but I'd like to gain some insite on how the game does things in Python and it should help with that. I'm holding out hope that I can find a way to do what I want through Python, but it's not looking good at the moment.
 
Personally I think you should make the step into SDK modding. Especially for something like this; having complex AI logic being done in a Python shell has to cause a significant performance hit; the code would likely run much faster and more efficiently in the dll.
 
The problem is that with Python I'm limited to handling the unit AI in CvGameUtils.AI_unitUpdate and the game just keeps passing a single unit to me until it uses up all of it's moves or times out which it does after 100 or so calls to AI_unitUpdate. I want the unit to "wait" while all the other units are processed then be available after that. I have found ways to cause a unit to skip the rest of the turn, but I can't get it to just wait and then be available again later in the same turn.
you would have to do a little SDK modification as there is no way to let python return true for CvUnitAI::AI_unitupdate

In CvUnitAI::AI_unitupdate the gameutils callback is run. Right now the only return value that is handled is 1 which return false. You would have to add another value X that returns true and then when you return X in python, the unit would wait.
 
Thanks for the answers everybody. I'm currently spending all my time getting my mod to an alpha version (I'm almost there). The mod currently uses the version 2.51 RevDCM dll for 3.19 compatibility + DCM. If anybody is interested in modifying the dll in the manner that Sephi mentions above that would be great. Otherwise I may put it off until after I release the alpha since the current Pyton code is ready to handle units that "wait".
 
phungus420,
I forgot to mention in the post above that Python AI should work in my mod because the number of units available for each map is limited. All units are either created by the current scenario map when it loads or via Python while the current map is being played.
 
Top Bottom