What does 'SetDeployFromOperationTurn' and 'AddTemporaryDominanceZone' actually do?

Sorry for a delayed response. I've instituted some of the ideas suggested. I usually do use print to find errors, however, I am not certain how to use print to determine if "SetDeployFromOperationTurn(1); " or "AddTemporaryDominanceZone" are working properly. In any case, I have used "unit:SetXY()" to good effect... if the units teleport to where I intend, the code for other elements is likely working... and they do... I have also rationalized the if/for tabs. Not certain if I'm following the standard operational procedure for this... I simply matched the ends to the proper if/for statements.

So, I have set up code to jump a random number of combat units to a designated hex, and apply "SetDeployFromOperationTurn(1) " to each unit.

I have revealed the terrain and a clear path from those units to the target hex for "AddTemporaryDominanceZone".

I'm pretty certain the functions are being applied to the unit and player appropriately.

Only problem is... my units all head back home and not to the designated hex (which is a city).

Here is the code...

Code:
function HladirAttackOnBamborough()
	
	if Game.GetGameTurn() == 0 then

		--set Hladir as player
		local pHladir
	
		for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

		local pHladir = Players[iPlayer]
	
			if (pHladir:IsAlive() and not pHladir:IsHuman()) then
				if (GameInfo.Civilizations.CIVILIZATION_SONGHAI.ID == pHladir:GetCivilizationType()) then
			
			-- loop through Hladir units and find combaat units
			-- select half of those units, embark, and teleport them				
			-- add that unit to operation
					for unit in pHladir:Units() do
			
						if (unit:IsCombatUnit()) then
							if (Game.Rand(100, "Selecting attack unit") < 100) then
							unit:SetEmbarked(true);
							unit:SetXY(58, 39)
							unit:SetDeployFromOperationTurn(1);
				
							end
						end
					end				
			
			pHladir:AddTemporaryDominanceZone (53, 48);

				end
			end
		end
	end
end

Events.ActivePlayerTurnEnd.Add(HladirAttackOnBamborough)

So why are the intended effects not occurring:

1) is a DoW necessary?
2) should the target hex not be a city?
3) should the units start closer to the target hex?
4) is "unit:SetDeployFromOperationTurn(1)" not in the correct sequence?
5) is "pHladir:AddTemporaryDominanceZone (53, 48);" not being applied correctly?

I'm going to continue to experiment with this code. I'll shuffle the order of application of unit characteristics and teleportation. I'll change the teleport hex to see if distance is a factor. I'll experiment with larger numbers of units. I hope I can see some unit movement towards the target hex.

I'll keep posted if I make some progress.
 
1) You want them to attack a city? Yes, they need to be at war for that. Setting a city as a target will not make them go to war. That is decided on a player/team level, not on a city or targeting level.

2) It doesn't have to be a city but given how AddTemporaryDominanceZone work when called from lua it's probably for the best that the target always is a city.

3) and 4) In SetDeployFromOperationTurn(1) the 1 is the turn the unit start to deploy from the operation. Currently you have it set to 1. That's ok if it's starting the operation on turn 1. If it's starting on turn 10 it will be as if you never set it. If you find out the units are closing in on the city, but then start doing something else instead, you can try increasing this number (possibly even beyond the current turn).

This number work very closely with the AI_TACTICAL_MAP_TEMP_ZONE_TURNS XML define. The unit will stop being a part of the operation the turn it was started plus this value. "the turn it was started" is whatever you tell it when you call SetDeployFromOperationTurn. You can likely even tell it a turn in the future, to make it continue longer than otherwise.


Using SetDeployFromOperationTurn is very clunky. The AI use armies to carry out operations. SetDeployFromOperationTurn is what it calls when this is finished. It's basically "ok we're done here but let's stick around for a while to keep control of the place". I would recommend you avoid using it unless absolutely necessary. I don't think you can manipulate AI armies in lua, which is why you might have to use SetDeployFromOperationTurn, but it still isn't optimal.

5) It probably is being applied. But that doesn't mean the AI will for sure go for it. The AI might have other priorities for the moment.
 
Thank you for all that info snarko :goodjob:. This has clarified quite a bit on my end as well. Everything I assume to know about these two functions has been gathered through my crude interpretation (I know nothing of C++ :( ) of what the DLL code is trying to do.

In my case, I am using it as a temporary measure to get units to go towards certain targets. What the AI does once it gets there is up to it as I have permanent war switched on.

Craig - I don't think I can add anything more than what snarko has replied.
 
Yes, thank-you very much for that explanation. I was really hoping to use the functions to encourage more aggression in attacks overseas but that seems less likely now.

I'll try experimenting and see if I can get some sort of consistency in the way the AI reacts to how the AddTemporaryDominanceZone function works in concert with DoWs or varying the number of units or distance from the target hex or any other element.

I'll post to this thread should I find out anything from my experiments.
 
Thanks for looking into this further Craig :).

Look forward to any findings.
 
Back
Top Bottom